Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,17 +264,27 @@ not a hard disk quota. Only native compilation is shared; each operation creates
a fresh engine, store, instance and WASI context. Use `init_func = "wizer-initialize"`
with source input; custom initializers remain available without source input.

**External I/O during pre-initialization is rejected.** Top-level filesystem
probes (including `existsSync` and module/package lookup), socket/DNS/HTTP/WebSocket
acquisition, SQLite opens (including `:memory:`), execution-job creation, and
`process.chdir()` fail the
build immediately. Catching a JavaScript exception cannot suppress this failure.
**The filesystem is unavailable during pre-initialization.** Path-based file
operations report catchable `ENOENT` errors; existence probes return `false`, and
filesystem-backed module/package lookup follows its normal not-found behavior.
These results are synthesized before touching the build host, WASI preopens,
libc filesystem state or runtime loader caches. Optional imports and file probes
may catch this absence. Pre-initialization now also rejects uncaught deferred
exceptions and unhandled promise rejections, including non-filesystem errors;
it no longer snapshots initialization after silently dropping those failures.
Registered loaders retry synthetic filesystem failures after restoration without
discarding ordinary loader errors or successful modules. Values computed from
caught absence remain frozen in the snapshot, so perform any filesystem-dependent
work again after restoration when needed.

Socket/DNS/HTTP/WebSocket acquisition, SQLite opens (including `:memory:`),
execution-job creation, and `process.chdir()` still fail the build immediately.
Catching a JavaScript exception cannot suppress these policy failures.
The diagnostic identifies the operation and recommends moving it into an exported
function or lazy initialization after restoration. This avoids saving unavailable
build-time capabilities or false filesystem results in the snapshot. The optimizer
function or lazy initialization after restoration. The optimizer
also traps filesystem preopens, network acquisition and outgoing HTTP for older
templates and custom initializers. Rebuild templates to get native guards,
restore-safe pre-init stdio and guest diagnostics.
templates and custom initializers. Rebuild templates to get catchable filesystem
absence, native guards, restore-safe pre-init stdio and guest diagnostics.

Importing these builtins, embedded/data modules and explicitly supplied module
sources remains supported. Logging and pure computation remain available.
Expand All @@ -291,9 +301,8 @@ must implement this standard WASI import; `none` retains `/`. A supplied cwd mus
be an accessible directory, or runtime initialization fails. Owned jobs retain
their separate cwd.

Supplied CommonJS reexports that require filesystem analysis are still rejected
during pre-initialization, even if a loader could supply the child at runtime.
Defer those chains to runtime until loader-aware reexport analysis is supported.
CommonJS named-reexport analysis that depends on filesystem-only children remains
unavailable during pre-initialization. Defer those imports to runtime.
Defer SQLite connections with `new DatabaseSync(path, { open: false })`, then call `.open()` after restoration.
Applications that require top-level external I/O should skip `optimize` and
initialize at runtime instead.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub const CUSTOM_INVOCATION_CONTEXT_JS: &str = include_str!("custom_invocation_c
/// `queueMicrotask` jobs get no promise hook events, so the callback carries its scope itself.
pub const WIRE_JS: &str = r#"
import { capture_for_callback as __wasm_rquickjs_captureScope, enter_callback as __wasm_rquickjs_enterScope, leave_callback as __wasm_rquickjs_leaveScope } from '__wasm_rquickjs_builtin/custom_invocation_context_native';
import { is_preinitializing as __wasm_rquickjs_isPreinitializing, reject_preinit_uncaught_error as __wasm_rquickjs_rejectPreinitUncaughtError } from '__wasm_rquickjs_builtin/process_native';
const __wasm_rquickjs_queueMicrotask = globalThis.queueMicrotask;
globalThis.queueMicrotask = function queueMicrotask(callback) {
if (typeof callback !== 'function') {
Expand All @@ -13,6 +14,15 @@ pub const WIRE_JS: &str = r#"
const previous = __wasm_rquickjs_enterScope(scope);
try {
return callback();
} catch (error) {
// QuickJS's pending-job path discards escaped errors. Make
// initialization fail without changing runtime job policy.
if (!__wasm_rquickjs_isPreinitializing()) throw error;
if (typeof globalThis.__wasm_rquickjs_handleUncaughtError === 'function') {
globalThis.__wasm_rquickjs_handleUncaughtError(error);
} else {
__wasm_rquickjs_rejectPreinitUncaughtError(error);
}
} finally {
__wasm_rquickjs_leaveScope(previous);
}
Expand Down
2 changes: 2 additions & 0 deletions crates/wasm-rquickjs/skeleton/src/builtin/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
describeType,
getSystemErrorDescription,
createSystemError,
markPreinitFilesystemError,
validateInteger,
validateMode,
parseMkdirOptions as _parseMkdirOptions,
Expand Down Expand Up @@ -434,6 +435,7 @@ function createCopyFileError(code, errno, description, src, dest) {
err.syscall = 'copyfile';
err.path = src;
err.dest = dest;
if (code === 'ENOENT') markPreinitFilesystemError(err);
return err;
}

Expand Down
Loading
Loading