Skip to content
Merged
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
39 changes: 30 additions & 9 deletions crates/spidermonkey-embedding-splicer/src/stub_wasi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
// 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.
(false, true) => {
stub_http_outgoing(&mut module)?;
}
// For all other cases we can avoid stubbing
_ => {}
}

let has_io = features.contains(&Feature::Clocks)
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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(())
}

Expand Down
Loading