From 3faee41c3a1ff25a3fbcfd42a0286880a44cb851 Mon Sep 17 00:00:00 2001 From: karthik2804 Date: Tue, 18 Jun 2024 13:50:33 +0200 Subject: [PATCH 1/6] treeshake imports based on guest content Signed-off-by: karthik2804 --- .../spidermonkey-embedding-splicer/src/lib.rs | 18 ++++++++++++---- .../wit/spidermonkey-embedding-splicer.wit | 2 +- src/componentize.js | 21 ++++++++++++------- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/crates/spidermonkey-embedding-splicer/src/lib.rs b/crates/spidermonkey-embedding-splicer/src/lib.rs index 390cc722..3d06de67 100644 --- a/crates/spidermonkey-embedding-splicer/src/lib.rs +++ b/crates/spidermonkey-embedding-splicer/src/lib.rs @@ -1,6 +1,9 @@ use anyhow::{bail, Context, Result}; use bindgen::BindingItem; -use std::path::{Path, PathBuf}; +use std::{ + path::{Path, PathBuf}, + vec, +}; mod bindgen; mod splice; @@ -110,6 +113,7 @@ impl Guest for SpidermonkeyEmbeddingSplicerComponent { wit_source: Option, wit_path: Option, world_name: Option, + guest_imports: Vec, debug: bool, ) -> Result { let source_name = source_name.unwrap_or("source.js".to_string()); @@ -326,12 +330,18 @@ impl Guest for SpidermonkeyEmbeddingSplicerComponent { Some(i32::try_from(*return_count).unwrap()), )); } + let mut trimmed_imports: Vec<(String, String, CoreFn, Option)> = Vec::new(); + for (import, b, c, d) in imports { + // List of imports that are actually imported by the guest content + if guest_imports.contains(&import) { + trimmed_imports.push((import, b, c, d)) + } + } - // println!("{:?}", &imports); // println!("{:?}", &componentized.imports); // println!("{:?}", &exports); - let mut wasm = - splice::splice(engine, imports, exports, debug).map_err(|e| format!("{:?}", e))?; + let mut wasm = splice::splice(engine, trimmed_imports, exports, debug) + .map_err(|e| format!("{:?}", e))?; // add the world section to the spliced wasm wasm.push(section.id()); diff --git a/crates/spidermonkey-embedding-splicer/wit/spidermonkey-embedding-splicer.wit b/crates/spidermonkey-embedding-splicer/wit/spidermonkey-embedding-splicer.wit index 08aa15d2..11b46420 100644 --- a/crates/spidermonkey-embedding-splicer/wit/spidermonkey-embedding-splicer.wit +++ b/crates/spidermonkey-embedding-splicer/wit/spidermonkey-embedding-splicer.wit @@ -33,5 +33,5 @@ world spidermonkey-embedding-splicer { export stub-wasi: func(engine: list, features: list, wit-world: option, wit-path: option, world-name: option) -> result, string>; - export splice-bindings: func(source-name: option, spidermonkey-engine: list, wit-world: option, wit-path: option, world-name: option, debug: bool) -> result; + export splice-bindings: func(source-name: option, spidermonkey-engine: list, wit-world: option, wit-path: option, world-name: option, guest-imports: list, debug: bool) -> result; } diff --git a/src/componentize.js b/src/componentize.js index 63b11774..22256dd9 100644 --- a/src/componentize.js +++ b/src/componentize.js @@ -47,12 +47,26 @@ export async function componentize(jsSource, witWorld, opts) { enableFeatures = [], } = opts || {}; + await lexerInit; + let jsImports = []; + try { + [jsImports] = parse(jsSource); + } catch { + // ignore parser errors - will show up as engine parse errors shortly + } + + let guestImports = [] + jsImports.map(k => { + guestImports.push(k.n) + }) + let { wasm, jsBindings, importWrappers, exports, imports } = spliceBindings( sourceName, await readFile(engine), witWorld, maybeWindowsPath(witPath), worldName, + guestImports, false ); @@ -103,13 +117,6 @@ export async function componentize(jsSource, witWorld, opts) { await writeFile(input, Buffer.from(wasm)); // rewrite the JS source import specifiers to reference import wrappers - await lexerInit; - let jsImports = []; - try { - [jsImports] = parse(jsSource); - } catch { - // ignore parser errors - will show up as engine parse errors shortly - } let source = '', curIdx = 0; for (const jsImpt of jsImports) { From ff30f7d186ecb9c96ab24532d33761499af138de Mon Sep 17 00:00:00 2001 From: karthik2804 Date: Sun, 30 Jun 2024 17:59:59 +0200 Subject: [PATCH 2/6] use export to maybe retain fetchEvent Signed-off-by: karthik2804 --- .../src/bindgen.rs | 22 ++++++++++++++++--- .../spidermonkey-embedding-splicer/src/lib.rs | 20 ++++++++--------- .../src/splice.rs | 17 ++++++++------ .../wit/spidermonkey-embedding-splicer.wit | 2 +- src/componentize.js | 9 +++++++- 5 files changed, 48 insertions(+), 22 deletions(-) diff --git a/crates/spidermonkey-embedding-splicer/src/bindgen.rs b/crates/spidermonkey-embedding-splicer/src/bindgen.rs index 11912fd0..9493ec38 100644 --- a/crates/spidermonkey-embedding-splicer/src/bindgen.rs +++ b/crates/spidermonkey-embedding-splicer/src/bindgen.rs @@ -124,7 +124,13 @@ pub struct Componentization { pub resource_imports: Vec<(String, String, u32)>, } -pub fn componentize_bindgen(resolve: &Resolve, id: WorldId, name: &str) -> Componentization { +pub fn componentize_bindgen( + resolve: &Resolve, + id: WorldId, + name: &str, + guest_imports: &Vec, + guest_exports: &Vec, +) -> Componentization { let mut bindgen = JsBindgen { src: Source::default(), esm_bindgen: EsmBindgen::default(), @@ -147,7 +153,7 @@ pub fn componentize_bindgen(resolve: &Resolve, id: WorldId, name: &str) -> Compo .local_names .exclude_globals(Intrinsic::get_global_names()); - bindgen.imports_bindgen(); + bindgen.imports_bindgen(&guest_imports); bindgen.exports_bindgen(); bindgen.esm_bindgen.populate_export_aliases(); @@ -342,6 +348,7 @@ pub fn componentize_bindgen(resolve: &Resolve, id: WorldId, name: &str) -> Compo "$source_mod", &mut bindgen.local_names, name, + &guest_exports, ); let js_intrinsics = render_intrinsics(&mut bindgen.all_intrinsics, false, true); @@ -451,9 +458,12 @@ impl JsBindgen<'_> { } } - fn imports_bindgen(&mut self) { + fn imports_bindgen(&mut self, guest_imports: &Vec) { for (key, impt) in &self.resolve.worlds[self.world].imports { let import_name = self.resolve.name_world_key(key); + if !guest_imports.contains(&import_name) { + continue; + } match &impt { WorldItem::Function(f) => { self.import_bindgen(import_name, f, false, None); @@ -1001,6 +1011,7 @@ impl EsmBindgen { imports_object: &str, _local_names: &mut LocalNames, source_name: &str, + guest_exports: &Vec, ) { // TODO: bring back these validations of imports // including using the flattened bindings @@ -1043,6 +1054,11 @@ impl EsmBindgen { "); } for (export_name, binding) in &self.exports { + if export_name == "wasi:http/incoming-handler@0.2.0" + && !guest_exports.contains(&"incomingHandler".to_string()) + { + continue; + } match binding { Binding::Interface(bindings) => { uwrite!(output, "const "); diff --git a/crates/spidermonkey-embedding-splicer/src/lib.rs b/crates/spidermonkey-embedding-splicer/src/lib.rs index 3d06de67..c527a0b2 100644 --- a/crates/spidermonkey-embedding-splicer/src/lib.rs +++ b/crates/spidermonkey-embedding-splicer/src/lib.rs @@ -114,6 +114,7 @@ impl Guest for SpidermonkeyEmbeddingSplicerComponent { wit_path: Option, world_name: Option, guest_imports: Vec, + guest_exports: Vec, debug: bool, ) -> Result { let source_name = source_name.unwrap_or("source.js".to_string()); @@ -135,7 +136,13 @@ impl Guest for SpidermonkeyEmbeddingSplicerComponent { .map_err(|e| e.to_string())?; let mut wasm_bytes = wit_component::dummy_module(&resolve, world); - let componentized = bindgen::componentize_bindgen(&resolve, world, &source_name); + let componentized = bindgen::componentize_bindgen( + &resolve, + world, + &source_name, + &guest_imports, + &guest_exports, + ); // merge the engine world with the target world, retaining the engine producers let producers = if let Ok(( @@ -330,18 +337,11 @@ impl Guest for SpidermonkeyEmbeddingSplicerComponent { Some(i32::try_from(*return_count).unwrap()), )); } - let mut trimmed_imports: Vec<(String, String, CoreFn, Option)> = Vec::new(); - for (import, b, c, d) in imports { - // List of imports that are actually imported by the guest content - if guest_imports.contains(&import) { - trimmed_imports.push((import, b, c, d)) - } - } // println!("{:?}", &componentized.imports); // println!("{:?}", &exports); - let mut wasm = splice::splice(engine, trimmed_imports, exports, debug) - .map_err(|e| format!("{:?}", e))?; + let mut wasm = + splice::splice(engine, imports, exports, debug).map_err(|e| format!("{:?}", e))?; // add the world section to the spliced wasm wasm.push(section.id()); diff --git a/crates/spidermonkey-embedding-splicer/src/splice.rs b/crates/spidermonkey-embedding-splicer/src/splice.rs index 12c397f9..6e64d783 100644 --- a/crates/spidermonkey-embedding-splicer/src/splice.rs +++ b/crates/spidermonkey-embedding-splicer/src/splice.rs @@ -45,13 +45,16 @@ pub fn splice( module.exports.delete(expt.id()); module.funcs.delete(run); } - if let Ok(serve) = module - .exports - .get_func("wasi:http/incoming-handler@0.2.0#handle") - { - let expt = module.exports.get_exported_func(serve).unwrap(); - module.exports.delete(expt.id()); - module.funcs.delete(serve); + + if exports.iter().any(|(name, _)| name == "incoming-handler") { + if let Ok(serve) = module + .exports + .get_func("wasi:http/incoming-handler@0.2.0#handle") + { + let expt = module.exports.get_exported_func(serve).unwrap(); + module.exports.delete(expt.id()); + module.funcs.delete(serve); + } } // we reencode the WASI world component data, so strip it out from the diff --git a/crates/spidermonkey-embedding-splicer/wit/spidermonkey-embedding-splicer.wit b/crates/spidermonkey-embedding-splicer/wit/spidermonkey-embedding-splicer.wit index 11b46420..af851340 100644 --- a/crates/spidermonkey-embedding-splicer/wit/spidermonkey-embedding-splicer.wit +++ b/crates/spidermonkey-embedding-splicer/wit/spidermonkey-embedding-splicer.wit @@ -33,5 +33,5 @@ world spidermonkey-embedding-splicer { export stub-wasi: func(engine: list, features: list, wit-world: option, wit-path: option, world-name: option) -> result, string>; - export splice-bindings: func(source-name: option, spidermonkey-engine: list, wit-world: option, wit-path: option, world-name: option, guest-imports: list, debug: bool) -> result; + export splice-bindings: func(source-name: option, spidermonkey-engine: list, wit-world: option, wit-path: option, world-name: option, guest-imports: list, guest-exports: list, debug: bool) -> result; } diff --git a/src/componentize.js b/src/componentize.js index 22256dd9..4ff04347 100644 --- a/src/componentize.js +++ b/src/componentize.js @@ -49,8 +49,9 @@ export async function componentize(jsSource, witWorld, opts) { await lexerInit; let jsImports = []; + let jsExports = []; try { - [jsImports] = parse(jsSource); + [jsImports, jsExports] = parse(jsSource); } catch { // ignore parser errors - will show up as engine parse errors shortly } @@ -60,6 +61,11 @@ export async function componentize(jsSource, witWorld, opts) { guestImports.push(k.n) }) + let guestExports = [] + jsExports.map(k => { + guestExports.push(k.n) + }) + let { wasm, jsBindings, importWrappers, exports, imports } = spliceBindings( sourceName, await readFile(engine), @@ -67,6 +73,7 @@ export async function componentize(jsSource, witWorld, opts) { maybeWindowsPath(witPath), worldName, guestImports, + guestExports, false ); From 220068f6f121b35154ac8ff3dfbe62ad488eea26 Mon Sep 17 00:00:00 2001 From: karthik2804 Date: Wed, 10 Jul 2024 19:09:29 +0200 Subject: [PATCH 3/6] merge engine and guest content imports Signed-off-by: karthik2804 --- .../src/bindgen.rs | 10 +++++++-- .../spidermonkey-embedding-splicer/src/lib.rs | 22 ++++++++++++------- .../src/splice.rs | 21 ++++++++++++------ 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/crates/spidermonkey-embedding-splicer/src/bindgen.rs b/crates/spidermonkey-embedding-splicer/src/bindgen.rs index 9493ec38..99766b92 100644 --- a/crates/spidermonkey-embedding-splicer/src/bindgen.rs +++ b/crates/spidermonkey-embedding-splicer/src/bindgen.rs @@ -155,7 +155,7 @@ pub fn componentize_bindgen( bindgen.imports_bindgen(&guest_imports); - bindgen.exports_bindgen(); + bindgen.exports_bindgen(&guest_exports); bindgen.esm_bindgen.populate_export_aliases(); // consolidate import specifiers and generate wrappers @@ -370,9 +370,15 @@ impl JsBindgen<'_> { return intrinsic.name().to_string(); } - fn exports_bindgen(&mut self) { + fn exports_bindgen(&mut self, guest_exports: &Vec) { for (key, export) in &self.resolve.worlds[self.world].exports { let name = self.resolve.name_world_key(key); + // TODO: figure out how to go from "run" -> wasi:cli/run@0.2.0 and + // "incomingHandler" -> wasi:http/incomingHandler@0.2.0 and in + // general go from the sugared up names to explicit name + if !guest_exports.contains(&name) { + continue; + } match export { WorldItem::Function(func) => { let local_name = self.local_names.create_once(&func.name).to_string(); diff --git a/crates/spidermonkey-embedding-splicer/src/lib.rs b/crates/spidermonkey-embedding-splicer/src/lib.rs index c527a0b2..6b8739f1 100644 --- a/crates/spidermonkey-embedding-splicer/src/lib.rs +++ b/crates/spidermonkey-embedding-splicer/src/lib.rs @@ -113,7 +113,7 @@ impl Guest for SpidermonkeyEmbeddingSplicerComponent { wit_source: Option, wit_path: Option, world_name: Option, - guest_imports: Vec, + mut guest_imports: Vec, guest_exports: Vec, debug: bool, ) -> Result { @@ -136,13 +136,6 @@ impl Guest for SpidermonkeyEmbeddingSplicerComponent { .map_err(|e| e.to_string())?; let mut wasm_bytes = wit_component::dummy_module(&resolve, world); - let componentized = bindgen::componentize_bindgen( - &resolve, - world, - &source_name, - &guest_imports, - &guest_exports, - ); // merge the engine world with the target world, retaining the engine producers let producers = if let Ok(( @@ -155,6 +148,11 @@ impl Guest for SpidermonkeyEmbeddingSplicerComponent { }, )) = decode(&engine) { + // merge the imports from the engine with the imports from the guest content. + for (k, _) in &engine_resolve.worlds[engine_world].imports { + guest_imports.push(engine_resolve.name_world_key(k)); + } + // we disable the engine run and incoming handler as we recreate these exports // when needed, so remove these from the world before initiating the merge let maybe_run = engine_resolve.worlds[engine_world] @@ -198,6 +196,14 @@ impl Guest for SpidermonkeyEmbeddingSplicerComponent { None }; + let componentized = bindgen::componentize_bindgen( + &resolve, + world, + &source_name, + &guest_imports, + &guest_exports, + ); + let encoded = wit_component::metadata::encode( &resolve, world, diff --git a/crates/spidermonkey-embedding-splicer/src/splice.rs b/crates/spidermonkey-embedding-splicer/src/splice.rs index 6e64d783..59f4fb47 100644 --- a/crates/spidermonkey-embedding-splicer/src/splice.rs +++ b/crates/spidermonkey-embedding-splicer/src/splice.rs @@ -38,15 +38,22 @@ pub fn splice( let mut module = config.parse(&engine)?; // since StarlingMonkey implements CLI Run and incoming handler, - // we override these in ComponentizeJS, removing them from the - // core function exports - if let Ok(run) = module.exports.get_func("wasi:cli/run@0.2.0#run") { - let expt = module.exports.get_exported_func(run).unwrap(); - module.exports.delete(expt.id()); - module.funcs.delete(run); + // we override them only if the guest content exports those functions + if exports + .iter() + .any(|(name, _)| name == "wasi:cli/run@0.2.0#run") + { + if let Ok(run) = module.exports.get_func("wasi:cli/run@0.2.0#run") { + let expt = module.exports.get_exported_func(run).unwrap(); + module.exports.delete(expt.id()); + module.funcs.delete(run); + } } - if exports.iter().any(|(name, _)| name == "incoming-handler") { + if exports + .iter() + .any(|(name, _)| name == "wasi:http/incoming-handler@0.2.0#handle") + { if let Ok(serve) = module .exports .get_func("wasi:http/incoming-handler@0.2.0#handle") From d1be71623e8e1d0e89fbbca8135577a6f615727d Mon Sep 17 00:00:00 2001 From: karthik2804 Date: Wed, 10 Jul 2024 19:34:31 +0200 Subject: [PATCH 4/6] only filter for incomingHandler and run in exports Signed-off-by: karthik2804 --- .../src/bindgen.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/crates/spidermonkey-embedding-splicer/src/bindgen.rs b/crates/spidermonkey-embedding-splicer/src/bindgen.rs index 99766b92..30538a2d 100644 --- a/crates/spidermonkey-embedding-splicer/src/bindgen.rs +++ b/crates/spidermonkey-embedding-splicer/src/bindgen.rs @@ -375,10 +375,23 @@ impl JsBindgen<'_> { let name = self.resolve.name_world_key(key); // TODO: figure out how to go from "run" -> wasi:cli/run@0.2.0 and // "incomingHandler" -> wasi:http/incomingHandler@0.2.0 and in - // general go from the sugared up names to explicit name - if !guest_exports.contains(&name) { + // general go from the sugared up names to explicit name. This is + // just to make sure some random export does not mess up the exports + // that a components to need to export + if name == "wasi:http/incoming-handler@0.2.0" + && !guest_exports.contains(&"incomingHandler".to_string()) + && !guest_exports.contains(&"wasi:http/incomingHandler@0.2.0".to_string()) + { continue; } + + if name == "wasi:cli/run@0.2.0" + && !guest_exports.contains(&"run".to_string()) + && !guest_exports.contains(&"wasi:cli/run@0.2.0".to_string()) + { + continue; + } + match export { WorldItem::Function(func) => { let local_name = self.local_names.create_once(&func.name).to_string(); From 45bdc550953b189b4da462230b3fbd89de887d00 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Fri, 12 Jul 2024 15:21:39 -0700 Subject: [PATCH 5/6] handle export aliases --- .../src/bindgen.rs | 49 ++++++++++--------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/crates/spidermonkey-embedding-splicer/src/bindgen.rs b/crates/spidermonkey-embedding-splicer/src/bindgen.rs index 30538a2d..0c7c559a 100644 --- a/crates/spidermonkey-embedding-splicer/src/bindgen.rs +++ b/crates/spidermonkey-embedding-splicer/src/bindgen.rs @@ -348,7 +348,6 @@ pub fn componentize_bindgen( "$source_mod", &mut bindgen.local_names, name, - &guest_exports, ); let js_intrinsics = render_intrinsics(&mut bindgen.all_intrinsics, false, true); @@ -373,23 +372,33 @@ impl JsBindgen<'_> { fn exports_bindgen(&mut self, guest_exports: &Vec) { for (key, export) in &self.resolve.worlds[self.world].exports { let name = self.resolve.name_world_key(key); - // TODO: figure out how to go from "run" -> wasi:cli/run@0.2.0 and - // "incomingHandler" -> wasi:http/incomingHandler@0.2.0 and in - // general go from the sugared up names to explicit name. This is - // just to make sure some random export does not mess up the exports - // that a components to need to export - if name == "wasi:http/incoming-handler@0.2.0" - && !guest_exports.contains(&"incomingHandler".to_string()) - && !guest_exports.contains(&"wasi:http/incomingHandler@0.2.0".to_string()) - { - continue; - } - if name == "wasi:cli/run@0.2.0" - && !guest_exports.contains(&"run".to_string()) - && !guest_exports.contains(&"wasi:cli/run@0.2.0".to_string()) - { - continue; + // Do not generate exports when the guest export is not implemented. + // We check both the full interface name - "ns:pkg@v/my-interface" and the + // aliased interface name "myInterface". All other names are always + // camel-case in the check. + match key { + WorldKey::Interface(iface) => { + if !guest_exports.contains(&name) { + let iface = &self.resolve.interfaces[*iface]; + if let Some(name) = iface.name.as_ref() { + let camel_case_name = name.to_lower_camel_case(); + if !guest_exports.contains(&camel_case_name) { + continue; + } + // TODO: move populate_export_aliases to a preprocessing + // step that doesn't require esm_bindgen, so that we can + // do alias deduping here as well. + } else { + continue; + } + } + } + WorldKey::Name(export_name) => { + if !guest_exports.contains(&export_name.to_lower_camel_case()) { + continue; + } + } } match export { @@ -1030,7 +1039,6 @@ impl EsmBindgen { imports_object: &str, _local_names: &mut LocalNames, source_name: &str, - guest_exports: &Vec, ) { // TODO: bring back these validations of imports // including using the flattened bindings @@ -1073,11 +1081,6 @@ impl EsmBindgen { "); } for (export_name, binding) in &self.exports { - if export_name == "wasi:http/incoming-handler@0.2.0" - && !guest_exports.contains(&"incomingHandler".to_string()) - { - continue; - } match binding { Binding::Interface(bindings) => { uwrite!(output, "const "); From 7c5cb0e1c9675cd65d9fe4f40fcbbd5b604956f8 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Fri, 12 Jul 2024 16:36:16 -0700 Subject: [PATCH 6/6] failing test case --- crates/spidermonkey-embedding-splicer/src/lib.rs | 1 + src/componentize.js | 1 + test/cases/smoke/imports.js | 3 --- test/cases/smoke/source.js | 8 ++------ test/cases/smoke/test.js | 6 ++++-- test/test.js | 10 ++++++---- 6 files changed, 14 insertions(+), 15 deletions(-) delete mode 100644 test/cases/smoke/imports.js diff --git a/crates/spidermonkey-embedding-splicer/src/lib.rs b/crates/spidermonkey-embedding-splicer/src/lib.rs index 6b8739f1..eefe3cf7 100644 --- a/crates/spidermonkey-embedding-splicer/src/lib.rs +++ b/crates/spidermonkey-embedding-splicer/src/lib.rs @@ -345,6 +345,7 @@ impl Guest for SpidermonkeyEmbeddingSplicerComponent { } // println!("{:?}", &componentized.imports); + // println!("{:?}", &componentized.resource_imports); // println!("{:?}", &exports); let mut wasm = splice::splice(engine, imports, exports, debug).map_err(|e| format!("{:?}", e))?; diff --git a/src/componentize.js b/src/componentize.js index 4ff04347..d424792d 100644 --- a/src/componentize.js +++ b/src/componentize.js @@ -334,5 +334,6 @@ export async function componentize(jsSource, witWorld, opts) { return { component, imports, + exports: exports.map(([name]) => name) }; } diff --git a/test/cases/smoke/imports.js b/test/cases/smoke/imports.js deleted file mode 100644 index ab6e6c05..00000000 --- a/test/cases/smoke/imports.js +++ /dev/null @@ -1,3 +0,0 @@ -export function y () { - // console.log('y'); -} diff --git a/test/cases/smoke/source.js b/test/cases/smoke/source.js index bfe6bb59..24df9d8d 100644 --- a/test/cases/smoke/source.js +++ b/test/cases/smoke/source.js @@ -1,7 +1,3 @@ -import { y } from 'imports'; - -export const exports = { - hello () { +export function unusedHello () { return 'world (' + getNum('world') + ')'; - } -}; +} diff --git a/test/cases/smoke/test.js b/test/cases/smoke/test.js index e2dfc02c..17f43533 100644 --- a/test/cases/smoke/test.js +++ b/test/cases/smoke/test.js @@ -1,5 +1,7 @@ -import { ok } from 'node:assert'; +import { ok, strictEqual } from 'node:assert'; -export function test (instance) { +export function test (instance, { imports, exports }) { + strictEqual(imports.length, 0); + strictEqual(exports.length, 0); ok(instance); } diff --git a/test/test.js b/test/test.js index b8167465..bbbd4198 100644 --- a/test/test.js +++ b/test/test.js @@ -17,7 +17,7 @@ suite('Builtins', () => { disableFeatures, } = await import(`./builtins/${filename}`); - const { component, imports } = await componentize( + const { component } = await componentize( source, ` package local:runworld; @@ -141,14 +141,16 @@ suite('Bindings', () => { const test = await import(`./cases/${name}/test.js`); + let testArg; try { - const { component, imports } = await componentize(source, { + const { component, imports, exports } = await componentize(source, { sourceName: `${name}.js`, witWorld, witPath, worldName, - disableFeatures: isWasiTarget ? [] : ['random', 'clocks'] + disableFeatures: isWasiTarget ? [] : ['random', 'clocks', 'http', 'stdio'] }); + testArg = { imports, exports }; const map = { 'wasi:cli-base/*': '@bytecodealliance/preview2-shim/cli-base#*', @@ -200,7 +202,7 @@ suite('Bindings', () => { } throw e; } - await test.test(instance); + await test.test(instance, testArg); }); } });