From df83d3018641748b34e3e1fb5cdb9265209a08e4 Mon Sep 17 00:00:00 2001 From: Victor Adossi Date: Tue, 22 Jul 2025 15:37:51 +0900 Subject: [PATCH 1/2] fix: logic for stubbing outgoing http and fetch-event This commit fixes one bug and refactors the code to be more granular in the case of differing feature sets. The reality is more nuanced -- as we must stub wasi:http/types differently depending on whether fetch-event is separately enabled. --- .../src/stub_wasi.rs | 39 ++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/crates/spidermonkey-embedding-splicer/src/stub_wasi.rs b/crates/spidermonkey-embedding-splicer/src/stub_wasi.rs index 91b314e3..89c72344 100644 --- a/crates/spidermonkey-embedding-splicer/src/stub_wasi.rs +++ b/crates/spidermonkey-embedding-splicer/src/stub_wasi.rs @@ -139,8 +139,25 @@ pub fn stub_wasi( stub_stdio(&mut module)?; } - if !features.contains(&Feature::Http) && !features.contains(&Feature::FetchEvent) { - stub_http(&mut module)?; + match ( + features.contains(&Feature::Http), + features.contains(&Feature::FetchEvent), + ) { + // If both are disabled, then disable all HTTP related imports + (false, false) => { + stub_http_types(&mut module)?; + stub_http_outgoing(&mut module)?; + } + // If HTTP is disabled but fetch-event is enabled we want to stub only the wasi:http/outgoing-handler + // import, and leave wasi:http/types will should be used by the fetch-event export. + // + // Note that we cannot *know* that the user will make use of fetch-event, but we must be prepared + // for it, as the feature is enabled. + (false, true) => { + stub_http_outgoing(&mut module)?; + } + // For all other cases we can avoid stubbing + _ => {} } let has_io = features.contains(&Feature::Clocks) @@ -380,7 +397,17 @@ fn stub_stdio(module: &mut Module) -> Result<()> { Ok(()) } -fn stub_http(module: &mut Module) -> Result<()> { +fn stub_http_outgoing(module: &mut Module) -> Result<()> { + stub_wasi_imports( + module, + "wasi:http/outgoing-handler", + "handle", + unreachable_stub, + )?; + Ok(()) +} + +fn stub_http_types(module: &mut Module) -> Result<()> { stub_wasi_imports( module, "wasi:http/types", @@ -753,12 +780,6 @@ fn stub_http(module: &mut Module) -> Result<()> { "[method]future-incoming-response.get", unreachable_stub, )?; - stub_wasi_imports( - module, - "wasi:http/outgoing-handler", - "handle", - unreachable_stub, - )?; Ok(()) } From 44c13efe3c61a3ec0a983688a1cdc40bd8604b2f Mon Sep 17 00:00:00 2001 From: Victor Adossi <123968127+vados-cosmonic@users.noreply.github.com> Date: Wed, 23 Jul 2025 08:13:45 +0900 Subject: [PATCH 2/2] fix: improve comment explaining stubbing Co-authored-by: Till Schneidereit --- crates/spidermonkey-embedding-splicer/src/stub_wasi.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/spidermonkey-embedding-splicer/src/stub_wasi.rs b/crates/spidermonkey-embedding-splicer/src/stub_wasi.rs index 89c72344..9fe125bd 100644 --- a/crates/spidermonkey-embedding-splicer/src/stub_wasi.rs +++ b/crates/spidermonkey-embedding-splicer/src/stub_wasi.rs @@ -148,8 +148,8 @@ pub fn stub_wasi( stub_http_types(&mut module)?; stub_http_outgoing(&mut module)?; } - // If HTTP is disabled but fetch-event is enabled we want to stub only the wasi:http/outgoing-handler - // import, and leave wasi:http/types will should be used by the fetch-event export. + // If HTTP is disabled but fetch-event is enabled we want to stub only the `wasi:http/outgoing-handler` + // and leave the rest of `wasi:http/types` in place for StarlingMonkey's implementation of `FetchEvent` to use. // // Note that we cannot *know* that the user will make use of fetch-event, but we must be prepared // for it, as the feature is enabled.