Skip to content

Commit 10b6dbd

Browse files
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.
1 parent 73b4276 commit 10b6dbd

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

crates/spidermonkey-embedding-splicer/src/stub_wasi.rs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,22 @@ pub fn stub_wasi(
139139
stub_stdio(&mut module)?;
140140
}
141141

142-
if !features.contains(&Features::Http) && !features.contains(&Features::FetchEvent) {
143-
stub_http(&mut module)?;
142+
match (
143+
features.contains(&Features::Http),
144+
features.contains(&Features::FetchEvent),
145+
) {
146+
// If both are disabled, then disable all HTTP related imports
147+
(false, false) => {
148+
stub_http_types(&mut module)?;
149+
stub_http_outgoing(&mut module)?;
150+
}
151+
// If HTTP is disabled but fetch-event is enabled we want to stub only the outgoing-handler import
152+
// as wasi:http/types will be used by the fetch-event export.
153+
(false, true) => {
154+
stub_http_outgoing(&mut module)?;
155+
}
156+
// For all other cases we can avoid stubbing
157+
_ => {}
144158
}
145159

146160
let has_io = features.contains(&Features::Clocks)
@@ -380,7 +394,17 @@ fn stub_stdio(module: &mut Module) -> Result<()> {
380394
Ok(())
381395
}
382396

383-
fn stub_http(module: &mut Module) -> Result<()> {
397+
fn stub_http_outgoing(module: &mut Module) -> Result<()> {
398+
stub_wasi_imports(
399+
module,
400+
"wasi:http/outgoing-handler",
401+
"handle",
402+
unreachable_stub,
403+
)?;
404+
Ok(())
405+
}
406+
407+
fn stub_http_types(module: &mut Module) -> Result<()> {
384408
stub_wasi_imports(
385409
module,
386410
"wasi:http/types",
@@ -753,12 +777,6 @@ fn stub_http(module: &mut Module) -> Result<()> {
753777
"[method]future-incoming-response.get",
754778
unreachable_stub,
755779
)?;
756-
stub_wasi_imports(
757-
module,
758-
"wasi:http/outgoing-handler",
759-
"handle",
760-
unreachable_stub,
761-
)?;
762780
Ok(())
763781
}
764782

0 commit comments

Comments
 (0)