Skip to content

Fixes in various places in existing code - #41

Merged
tschneidereit merged 9 commits into
mainfrom
small-fixes
Sep 30, 2026
Merged

tschneidereit merged 9 commits into
mainfrom
small-fixes

Conversation

@tschneidereit

Copy link
Copy Markdown
Member

This PR introduces yet another round of fixes in existing code. This time, most of this is centered around loading and evaluation of source code/modules during initialization, as well as error handling.

Needed to pull in a newer `wasi-libc`, which fixes `__wasilibc_reset_preopens`
to close open FDs in addition to resetting the preopens.

Without calling that function right before wizening, all FDs opened during init
are retained, including `stdout` and `stderr`. That means printing anything at
wizening time causes a trap when printing post resumption.

This needed light changes to `crown` as well, but nothing major.
The module load hook compiles a request with `with { type: "json" }` as a
JSON module, cached independently of a JavaScript module of the same file, and
refuses every other module type with a message naming the specifier.

For a dynamic `import()`, the hook loads the module's own imports before handing
the module over, and the engine links and evaluates it in a promise job after
`import()` has returned. Before this, every dynamic import failed with "module
record has unexpected status: New".
…first

During `pre_initialize`, the runtime enables recording stacks for the
creation of tasks, timers, interest handles and async-promise futures using
`js::stack::current_origin`. If any of them are still active at snapshot
time, `EventLoop::ensure_idle_for_snapshot` prints errors for them, including
the recorded stacks.

`mark_resumed_from_snapshot` becomes `prepare_for_snapshot`, which also
flushes stdio and calls `__wasilibc_reset_preopens` to close any open FDs,
including those for `stdout` and `stderr`.
Running a module as a command handed its evaluation promise to the event
loop and dropped it, so a top level that rejected after awaiting a timer, or
awaited a promise nothing could settle, exited with status 0 and no message.
`ScriptEvaluation::settled`, called by `core_runtime::run`, the wasm
`libstarling::run` and Wizer pre-initialization, checks both once the loop
has run out of work.
`console.log`, `info` and `debug` print the bare message on stdout, and
`warn` and `error` print it on stderr, prefixed with the level. Every level
used to go to stdout behind a prefix.

`js::jobs` tracks promises that are rejected while no handler is attached,
and `run_microtasks` reports each one still unhandled after the drain on
stderr, as `Uncaught (in promise)` with the reason's message, location and
stack. A module's evaluation promise is marked handled when evaluation
returns it, since the caller reports its rejection itself.

Additionally, report more details, including the stack, on where a top-level
error was thrown.
`heck` and `smallvec` are declared once in the workspace manifest, and
`starling-macro` and `web-streams` refer to those declarations instead of
naming versions of their own.
`platform::http::read_incoming_request` only calls sync host functions,
so can be sync itself as well.
The entry module needs to be registered in the module registry same as any
other module. Otherwise, importing it in other modules creates a second
instance.

This is also meaningfully simplifying module registration.
`core_runtime::module::register_source_module` was used by
SpiderMonkey 147's module resolution hooks, but isn't used at
all anymore.
@tschneidereit
tschneidereit merged commit 78a4608 into main Sep 30, 2026
10 checks passed
@tschneidereit
tschneidereit deleted the small-fixes branch September 30, 2026 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant