From 1666b9632db491da58a52e339e9a79402c4678ca Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Tue, 28 May 2024 13:27:52 -0700 Subject: [PATCH 01/41] deps: update to latest starlingmonkey --- StarlingMonkey | 2 +- embedding/embedding.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/StarlingMonkey b/StarlingMonkey index c1d7439..4a76bf0 160000 --- a/StarlingMonkey +++ b/StarlingMonkey @@ -1 +1 @@ -Subproject commit c1d7439a3412496db0c5d4004d723396cc46a892 +Subproject commit 4a76bf0c5130424664e309faac6d434de756a63c diff --git a/embedding/embedding.cpp b/embedding/embedding.cpp index 0c0ca59..b63a7fe 100644 --- a/embedding/embedding.cpp +++ b/embedding/embedding.cpp @@ -274,7 +274,7 @@ extern "C" } Runtime.free_list.clear(); RootedValue result(Runtime.cx); - Runtime.engine->run_event_loop(&result); + Runtime.engine->run_event_loop(); LOG("(post_call) end"); } From 105096f4f2ef4a05354683d6f396aaebe121e8d2 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Wed, 29 May 2024 13:29:37 -0700 Subject: [PATCH 02/41] fixup splicing --- .../src/splice.rs | 88 ++++++------------- embedding/embedding.cpp | 6 +- 2 files changed, 28 insertions(+), 66 deletions(-) diff --git a/crates/spidermonkey-embedding-splicer/src/splice.rs b/crates/spidermonkey-embedding-splicer/src/splice.rs index fd7b354..12c397f 100644 --- a/crates/spidermonkey-embedding-splicer/src/splice.rs +++ b/crates/spidermonkey-embedding-splicer/src/splice.rs @@ -1,15 +1,10 @@ use walrus::{ - ir::{ - BinaryOp, Binop, Const, Instr, LoadKind, LocalGet, LocalSet, LocalTee, MemArg, Store, - StoreKind, UnaryOp, Unop, Value, - }, + ir::{BinaryOp, Binop, Const, Instr, LoadKind, MemArg, Store, StoreKind, UnaryOp, Unop, Value}, ExportId, ExportItem, FunctionBuilder, FunctionId, LocalId, ValType, }; use crate::*; -const DEBUG: bool = false; - // // Parses the Spidermonkey binary into section data for reserialization // into an output binary, and in the process: @@ -39,10 +34,7 @@ pub fn splice( exports: Vec<(String, CoreFn)>, debug: bool, ) -> Result> { - let mut config = walrus::ModuleConfig::new(); - if debug { - config.generate_dwarf(true); - } + let config = walrus::ModuleConfig::new(); let mut module = config.parse(&engine)?; // since StarlingMonkey implements CLI Run and incoming handler, @@ -76,7 +68,7 @@ pub fn splice( // extract the native instructions from sample functions // then inline the imported functions and main import gating function // (erasing sample functions in the process) - synthesize_import_functions(&mut module, &imports)?; + synthesize_import_functions(&mut module, &imports, debug)?; // create the exported functions as wrappers around the "cabi_call" function synthesize_export_functions(&mut module, &exports)?; @@ -94,6 +86,7 @@ fn get_export_fid(module: &walrus::Module, expt_id: &ExportId) -> FunctionId { fn synthesize_import_functions( module: &mut walrus::Module, imports: &Vec<(String, String, CoreFn, Option)>, + debug: bool, ) -> Result<()> { let mut coreabi_get_import: Option = None; let mut cabi_realloc: Option = None; @@ -116,8 +109,26 @@ fn synthesize_import_functions( let cabi_realloc_fid = get_export_fid(module, &cabi_realloc.unwrap()); - let coreabi_sample_fid = get_export_fid(module, coreabi_sample_ids.first().unwrap()); - let coreabi_sample_i32 = module.funcs.get(coreabi_sample_fid).kind.unwrap_local(); + let coreabi_sample_i32 = module + .funcs + .get(get_export_fid(module, &coreabi_sample_ids[0])) + .kind + .unwrap_local(); + let _coreabi_sample_i64 = module + .funcs + .get(get_export_fid(module, &coreabi_sample_ids[1])) + .kind + .unwrap_local(); + let _coreabi_sample_f32 = module + .funcs + .get(get_export_fid(module, &coreabi_sample_ids[2])) + .kind + .unwrap_local(); + let _coreabi_sample_f64 = module + .funcs + .get(get_export_fid(module, &coreabi_sample_ids[3])) + .kind + .unwrap_local(); // These functions retrieve the corresponding type // from a JS::HandleValue @@ -179,7 +190,7 @@ fn synthesize_import_functions( let tmp_local = module.locals.add(ValType::I64); for (impt_specifier, impt_name, impt_sig, retptr_size) in imports.iter() { - if DEBUG { + if debug { println!( "> IMPORT {} {} > {:?}", impt_specifier, impt_name, &impt_sig @@ -226,55 +237,6 @@ fn synthesize_import_functions( let mut func_body = func.func_body(); - // copy the prelude instructions from the sample function (first block) - let coreabi_sample_i32 = module.funcs.get(coreabi_sample_fid).kind.unwrap_local(); - let prelude_block = &coreabi_sample_i32 - .block(coreabi_sample_i32.entry_block()) - .instrs[0] - .0; - let prelude_seq = match prelude_block { - Instr::Block(prelude_block) => prelude_block.seq, - _ => { - eprintln!("Splicer error: unable to read prelude sequence, continuing for debug build but note binding functions will not work!"); - return Ok(()); - } - }; - - let prelude_block = coreabi_sample_i32.block(prelude_seq); - func_body.block(None, |prelude| { - for (instr, _) in &prelude_block.instrs { - match instr { - Instr::LocalGet(LocalGet { local }) => { - if local.eq(&vp_arg) { - prelude.instr(instr.clone()); - } else { - prelude.local_get(tmp_local); - } - } - Instr::LocalSet(LocalSet { local }) => { - if local.eq(&vp_arg) { - prelude.instr(instr.clone()); - } else { - prelude.local_set(tmp_local); - } - } - Instr::LocalTee(LocalTee { local }) => { - if local.eq(&vp_arg) { - prelude.instr(instr.clone()); - } else { - prelude.local_tee(tmp_local); - } - } - Instr::BrIf(_) => { - prelude.br_if(prelude.id()); - } - _ => { - prelude.instr(instr.clone()); - } - }; - } - }); - // stack the return arg now as it chains with the // args we're about to add to the stack if impt_sig.ret.is_some() { diff --git a/embedding/embedding.cpp b/embedding/embedding.cpp index b63a7fe..154327c 100644 --- a/embedding/embedding.cpp +++ b/embedding/embedding.cpp @@ -70,7 +70,7 @@ extern "C" { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); int64_t arg1 = from_bigint64(args[1]); - args.rval().setBigInt(to_bigint64(cx, arg1)); + args.rval().setBigInt(to_bigint64(cx, arg1 * 32771)); return true; } @@ -78,7 +78,7 @@ extern "C" { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); float arg2 = static_cast(args[2].toDouble()); - args.rval().setDouble(arg2); + args.rval().setDouble(arg2 * 32771); return true; } @@ -86,7 +86,7 @@ extern "C" { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); double arg3 = args[3].toDouble(); - args.rval().setDouble(arg3); + args.rval().setDouble(arg3 * 32771); return true; } From 7cf3552a130fe8187a9770319724b638c01e5d7c Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Wed, 29 May 2024 14:59:58 -0700 Subject: [PATCH 03/41] latest starlingmonkey --- StarlingMonkey | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/StarlingMonkey b/StarlingMonkey index 4a76bf0..aa9ff14 160000 --- a/StarlingMonkey +++ b/StarlingMonkey @@ -1 +1 @@ -Subproject commit 4a76bf0c5130424664e309faac6d434de756a63c +Subproject commit aa9ff14cd0696877a402435faaf8db486ce0ff89 From 8a8b7a98073443a745dc620f1486985248cb4367 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Wed, 29 May 2024 15:03:26 -0700 Subject: [PATCH 04/41] update rust toolchain --- .github/workflows/main.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 50c022a..30218c6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -28,12 +28,11 @@ jobs: with: submodules: recursive - - name: Install Rust 1.68.2, 1.76.0 + - name: Install Rust Toolchain run: | - rustup toolchain install 1.68.2 - rustup toolchain install 1.76.0 - rustup target add wasm32-unknown-unknown --toolchain 1.76.0 - rustup target add wasm32-wasi --toolchain 1.68.2 + rustup toolchain install stable + rustup target add wasm32-unknown-unknown --toolchain stable + rustup target add wasm32-wasi --toolchain 1.77.1 - uses: actions/setup-node@v2 with: From 2b79e0dac1097b812eec675f85254eaa08c6dbb1 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Wed, 29 May 2024 15:46:05 -0700 Subject: [PATCH 05/41] fixup tests --- StarlingMonkey | 2 +- test/builtins/console-object.js | 6 +++++- test/builtins/globals.js | 2 +- test/builtins/timeout.js | 2 ++ 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/StarlingMonkey b/StarlingMonkey index aa9ff14..2e23c54 160000 --- a/StarlingMonkey +++ b/StarlingMonkey @@ -1 +1 @@ -Subproject commit aa9ff14cd0696877a402435faaf8db486ce0ff89 +Subproject commit 2e23c54f2a9a51cd846b4007fa9eb31bb04d4e10 diff --git a/test/builtins/console-object.js b/test/builtins/console-object.js index 399ba03..2c7e703 100644 --- a/test/builtins/console-object.js +++ b/test/builtins/console-object.js @@ -53,6 +53,10 @@ export const source = ` export async function test (run) { const { stdout, stderr } = await run(); - strictEqual(stdout, `{ a: { value: "a" }, b: { c: "d" }, e: ["f"], g: [{ g: "i" }], l: [Function l], m: [Getter], n: [Getter], o: [Function], p: [Function], q: 5, s: 29879287298374924, t: Set(3) { 1, 2, 3 }, u: Map(3) { 1 => 2, 3 => 4, [Function foo] => {} }, v: Symbol.for("blah"), w: Symbol(), x: undefined, y: null, z: URL { hash: "", host: "site.com", hostname: "site.com", href: "https://site.com/x?a&b", origin: "https://site.com", password: "", pathname: "/x", port: "", protocol: "https:", search: "?a&b", searchParams: URLSearchParams {}, username: "" }, zz: Uint8Array [1, 2, 3], zzz: Z {} }\n`); + strictEqual(stdout, `{ a: { value: "a" }, b: { c: "d" }, e: ["f"], g: [{ g: "i" }], l: [ l () { + + }], m: [Getter], n: [Getter], o: [ function () { + + }], p: [ () => {}], q: 5, s: 29879287298374924, t: Set(3) { 1, 2, 3 }, u: Map(3) { 1 => 2, 3 => 4, [ function foo () {}] => {} }, v: Symbol.for("blah"), w: Symbol(), x: undefined, y: null, z: URL { hash: "", host: "site.com", hostname: "site.com", href: "https://site.com/x?a&b", origin: "https://site.com", password: "", pathname: "/x", port: "", protocol: "https:", search: "?a&b", searchParams: URLSearchParams {}, username: "" }, zz: Uint8Array [1, 2, 3], zzz: Z {} }\n`); strictEqual(stderr, ''); } diff --git a/test/builtins/globals.js b/test/builtins/globals.js index c26ff28..9395b8c 100644 --- a/test/builtins/globals.js +++ b/test/builtins/globals.js @@ -13,7 +13,7 @@ export async function test(run) { const { stdout, stderr } = await run(); strictEqual( stdout, - `["undefined", "Function", "Object", "eval", "globalThis", "Array", "Boolean", "JSON", "Date", "Math", "isNaN", "isFinite", "parseInt", "parseFloat", "NaN", "Infinity", "Number", "escape", "unescape", "decodeURI", "encodeURI", "decodeURIComponent", "encodeURIComponent", "String", "RegExp", "Error", "InternalError", "AggregateError", "EvalError", "RangeError", "ReferenceError", "SyntaxError", "TypeError", "URIError", "ArrayBuffer", "Int8Array", "Uint8Array", "Int16Array", "Uint16Array", "Int32Array", "Uint32Array", "Float32Array", "Float64Array", "Uint8ClampedArray", "BigInt64Array", "BigUint64Array", "BigInt", "Proxy", "WeakMap", "Map", "Set", "DataView", "Symbol", "Reflect", "WeakSet", "Promise", "FinalizationRegistry", "WeakRef", "ReadableStream", "ReadableStreamBYOBReader", "ReadableStreamBYOBRequest", "ReadableStreamDefaultReader", "ReadableStreamDefaultController", "ReadableByteStreamController", "WritableStream", "ByteLengthQueuingStrategy", "CountQueuingStrategy", "self", "URL", "URLSearchParams", "atob", "btoa", "console", "DOMException", "Performance", "queueMicrotask", "structuredClone", "setInterval", "setTimeout", "clearInterval", "clearTimeout", "WorkerLocation", "location", "TextEncoder", "TextDecoder", "TransformStream", "CompressionStream", "DecompressionStream", "fetch", "Request", "Response", "Headers", "addEventListener", "SubtleCrypto", "Crypto", "crypto", "CryptoKey"]\n` + `["undefined", "Function", "Object", "eval", "globalThis", "Array", "Boolean", "JSON", "Date", "Math", "isNaN", "isFinite", "parseInt", "parseFloat", "NaN", "Infinity", "Number", "escape", "unescape", "decodeURI", "encodeURI", "decodeURIComponent", "encodeURIComponent", "String", "RegExp", "Error", "InternalError", "AggregateError", "EvalError", "RangeError", "ReferenceError", "SyntaxError", "TypeError", "URIError", "ArrayBuffer", "Int8Array", "Uint8Array", "Int16Array", "Uint16Array", "Int32Array", "Uint32Array", "Float32Array", "Float64Array", "Uint8ClampedArray", "BigInt64Array", "BigUint64Array", "BigInt", "Proxy", "WeakMap", "Map", "Set", "DataView", "Symbol", "Reflect", "WeakSet", "Promise", "FinalizationRegistry", "WeakRef", "ReadableStream", "ReadableStreamBYOBReader", "ReadableStreamBYOBRequest", "ReadableStreamDefaultReader", "ReadableStreamDefaultController", "ReadableByteStreamController", "WritableStream", "ByteLengthQueuingStrategy", "CountQueuingStrategy", "self", "queueMicrotask", "structuredClone", "atob", "btoa", "DOMException", "URL", "URLSearchParams", "console", "Performance", "performance", "setInterval", "setTimeout", "clearInterval", "clearTimeout", "WorkerLocation", "location", "TextEncoder", "TextDecoder", "TransformStream", "CompressionStream", "DecompressionStream", "fetch", "Request", "Response", "Headers", "addEventListener", "SubtleCrypto", "Crypto", "crypto", "CryptoKey"]\n` ); strictEqual(stderr, ''); } diff --git a/test/builtins/timeout.js b/test/builtins/timeout.js index 1f1429a..7bbe31a 100644 --- a/test/builtins/timeout.js +++ b/test/builtins/timeout.js @@ -6,10 +6,12 @@ export const source = ` console.log(Date.now()); setTimeout(() => { console.log(Date.now()); + console.log('done'); done = true; }, 100); } export function ready () { + console.log('ready'); return done; } `; From d1e48b3c6848ed440e3d50295eed59a94adff814 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Wed, 29 May 2024 15:49:50 -0700 Subject: [PATCH 06/41] workflow fix --- .github/workflows/main.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 30218c6..20f34b4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -30,8 +30,7 @@ jobs: - name: Install Rust Toolchain run: | - rustup toolchain install stable - rustup target add wasm32-unknown-unknown --toolchain stable + rustup toolchain install 1.77.1 rustup target add wasm32-wasi --toolchain 1.77.1 - uses: actions/setup-node@v2 From 9ece1e4dfed28f414e6acbc9b4b3ee627e806e62 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Wed, 29 May 2024 15:52:51 -0700 Subject: [PATCH 07/41] fix tests --- StarlingMonkey | 2 +- test/builtins/timeout.js | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/StarlingMonkey b/StarlingMonkey index 2e23c54..5bdb946 160000 --- a/StarlingMonkey +++ b/StarlingMonkey @@ -1 +1 @@ -Subproject commit 2e23c54f2a9a51cd846b4007fa9eb31bb04d4e10 +Subproject commit 5bdb946f137e946206fb865cdba92b8fb0654416 diff --git a/test/builtins/timeout.js b/test/builtins/timeout.js index 7bbe31a..1f1429a 100644 --- a/test/builtins/timeout.js +++ b/test/builtins/timeout.js @@ -6,12 +6,10 @@ export const source = ` console.log(Date.now()); setTimeout(() => { console.log(Date.now()); - console.log('done'); done = true; }, 100); } export function ready () { - console.log('ready'); return done; } `; From d166aa1e0755ce801ed06dd752b6ba503a4979e3 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Wed, 29 May 2024 16:57:57 -0700 Subject: [PATCH 08/41] try latest merge --- StarlingMonkey | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/StarlingMonkey b/StarlingMonkey index 5bdb946..82e9b4d 160000 --- a/StarlingMonkey +++ b/StarlingMonkey @@ -1 +1 @@ -Subproject commit 5bdb946f137e946206fb865cdba92b8fb0654416 +Subproject commit 82e9b4d2c4396a645ca25ab79ac12e0d4e43e2ca From 7f7d4b5f524660699aa457e0c6bec04eaf17edbe Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Wed, 29 May 2024 17:15:31 -0700 Subject: [PATCH 09/41] latest --- StarlingMonkey | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/StarlingMonkey b/StarlingMonkey index 82e9b4d..cb7b007 160000 --- a/StarlingMonkey +++ b/StarlingMonkey @@ -1 +1 @@ -Subproject commit 82e9b4d2c4396a645ca25ab79ac12e0d4e43e2ca +Subproject commit cb7b007997c7261ce2b6f132a99b12dec5ed2268 From e12ec9edd8444245f4a66bbbb0005dd6368edec1 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Wed, 29 May 2024 17:30:54 -0700 Subject: [PATCH 10/41] fixup --- StarlingMonkey | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/StarlingMonkey b/StarlingMonkey index cb7b007..0ee0031 160000 --- a/StarlingMonkey +++ b/StarlingMonkey @@ -1 +1 @@ -Subproject commit cb7b007997c7261ce2b6f132a99b12dec5ed2268 +Subproject commit 0ee003193b30c0d7828c0a2d3dd4871207ad173f From 63e3453bab9513296ad3ec65607540288487bf93 Mon Sep 17 00:00:00 2001 From: Karthik Ganeshram Date: Thu, 30 May 2024 20:28:15 +0200 Subject: [PATCH 11/41] do not stub imports that are part of the target world (#109) --- .../spidermonkey-embedding-splicer/src/lib.rs | 10 +- .../src/stub_wasi.rs | 1300 +++++++++-------- .../wit/spidermonkey-embedding-splicer.wit | 2 +- src/componentize.js | 6 +- 4 files changed, 714 insertions(+), 604 deletions(-) diff --git a/crates/spidermonkey-embedding-splicer/src/lib.rs b/crates/spidermonkey-embedding-splicer/src/lib.rs index bf79dce..390cc72 100644 --- a/crates/spidermonkey-embedding-splicer/src/lib.rs +++ b/crates/spidermonkey-embedding-splicer/src/lib.rs @@ -94,8 +94,14 @@ fn parse_wit(path: &Path) -> Result<(Resolve, PackageId)> { } impl Guest for SpidermonkeyEmbeddingSplicerComponent { - fn stub_wasi(wasm: Vec, features: Vec) -> Result, String> { - stub_wasi(wasm, features).map_err(|e| e.to_string()) + fn stub_wasi( + wasm: Vec, + features: Vec, + wit_source: Option, + wit_path: Option, + world_name: Option, + ) -> Result, String> { + stub_wasi(wasm, features, wit_source, wit_path, world_name).map_err(|e| e.to_string()) } fn splice_bindings( diff --git a/crates/spidermonkey-embedding-splicer/src/stub_wasi.rs b/crates/spidermonkey-embedding-splicer/src/stub_wasi.rs index 0f813c0..9760232 100644 --- a/crates/spidermonkey-embedding-splicer/src/stub_wasi.rs +++ b/crates/spidermonkey-embedding-splicer/src/stub_wasi.rs @@ -1,12 +1,17 @@ use anyhow::{bail, Result}; -use std::time::{SystemTime, UNIX_EPOCH}; +use std::{ + collections::HashSet, + path::PathBuf, + time::{SystemTime, UNIX_EPOCH}, +}; use walrus::{ ir::{BinaryOp, MemArg, StoreKind, UnaryOp}, Function, FunctionBuilder, FunctionId, FunctionKind, ImportKind, ImportedFunction, InitExpr, InstrSeqBuilder, LocalId, Module, ValType, }; +use wit_parser::{Resolve, UnresolvedPackage}; -use crate::Features; +use crate::{parse_wit, Features}; fn stub_import( module: &mut Module, @@ -52,12 +57,40 @@ fn unreachable_stub(body: &mut InstrSeqBuilder) -> Result> { Ok(vec![]) } -pub fn stub_wasi(wasm: Vec, features: Vec) -> Result> { +pub fn stub_wasi( + wasm: Vec, + features: Vec, + wit_source: Option, + wit_path: Option, + world_name: Option, +) -> Result> { + let (resolve, id) = if let Some(wit_source) = wit_source { + let mut resolve = Resolve::default(); + let path = PathBuf::from("component.wit"); + let pkg = UnresolvedPackage::parse(&path, &wit_source)?; + + let id = resolve.push(pkg)?; + + (resolve, id) + } else { + parse_wit(&PathBuf::from(wit_path.unwrap()))? + }; + + let world = resolve.select_world(id, world_name.as_deref())?; + + let target_world = &resolve.worlds[world]; + let mut target_world_imports = HashSet::new(); + + for (key, _) in &target_world.imports { + target_world_imports.insert(resolve.name_world_key(key)); + } + let mut module = Module::from_buffer(wasm.as_slice())?; stub_preview1(&mut module)?; - stub_filesystem(&mut module)?; - stub_cli(&mut module)?; + + stub_filesystem(&mut module, &target_world_imports)?; + stub_cli(&mut module, &target_world_imports)?; if !features.contains(&Features::Random) { stub_random(&mut module)?; @@ -77,16 +110,34 @@ pub fn stub_wasi(wasm: Vec, features: Vec) -> Result> { let has_io = features.contains(&Features::Clocks) || features.contains(&Features::Stdio) - || features.contains(&Features::Http); + || features.contains(&Features::Http) + || target_world_requires_io(&target_world_imports); if !has_io { stub_io(&mut module)?; } - stub_sockets(&mut module)?; + stub_sockets(&mut module, &target_world_imports)?; Ok(module.emit_wasm()) } +fn target_world_requires_io(target_world_imports: &HashSet) -> bool { + return target_world_imports.contains("wasi:sockets/instance-network@0.2.0") + || target_world_imports.contains("wasi:sockets/udp@0.2.0") + || target_world_imports.contains("wasi:sockets/udp-create-socket@0.2.0") + || target_world_imports.contains("wasi:sockets/tcp@0.2.0") + || target_world_imports.contains("wasi:sockets/tcp-create-socket@0.2.0") + || target_world_imports.contains("wasi:sockets/ip-name-lookup@0.2.0") + || target_world_imports.contains("wasi:sockets/network@0.2.0") + || target_world_imports.contains("wasi:filesystem/types@0.2.0") + || target_world_imports.contains("wasi:filesystem/preopens@0.2.0") + || target_world_imports.contains("wasi:cli/terminal-stdin@0.2.0") + || target_world_imports.contains("wasi:cli/terminal-stdout@0.2.0") + || target_world_imports.contains("wasi:cli/terminal-stderr@0.2.0") + || target_world_imports.contains("wasi:cli/terminal-input@0.2.0") + || target_world_imports.contains("wasi:cli/terminal-output@0.2.0"); +} + const PREVIEW1: &str = "wasi_snapshot_preview1"; fn stub_preview1(module: &mut Module) -> Result<()> { stub_import(module, PREVIEW1, "environ_get", unreachable_stub)?; @@ -866,603 +917,654 @@ fn stub_io(module: &mut Module) -> Result<()> { Ok(()) } -fn stub_sockets(module: &mut Module) -> Result<()> { - stub_import( - module, - "wasi:sockets/instance-network@0.2.0", - "instance-network", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/udp@0.2.0", - "[method]udp-socket.start-bind", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/udp@0.2.0", - "[method]udp-socket.finish-bind", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/udp@0.2.0", - "[method]udp-socket.stream", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/udp@0.2.0", - "[method]udp-socket.local-address", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/udp@0.2.0", - "[method]udp-socket.remote-address", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/udp@0.2.0", - "[method]udp-socket.address-family", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/udp@0.2.0", - "[method]udp-socket.unicast-hop-limit", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/udp@0.2.0", - "[method]udp-socket.set-unicast-hop-limit", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/udp@0.2.0", - "[method]udp-socket.receive-buffer-size", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/udp@0.2.0", - "[method]udp-socket.set-receive-buffer-size", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/udp@0.2.0", - "[method]udp-socket.send-buffer-size", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/udp@0.2.0", - "[method]udp-socket.set-send-buffer-size", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/udp@0.2.0", - "[method]udp-socket.subscribe", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/udp@0.2.0", - "[method]incoming-datagram-stream.receive", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/udp@0.2.0", - "[method]incoming-datagram-stream.subscribe", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/udp@0.2.0", - "[method]outgoing-datagram-stream.check-send", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/udp@0.2.0", - "[method]outgoing-datagram-stream.send", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/udp@0.2.0", - "[method]outgoing-datagram-stream.subscribe", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/udp-create-socket@0.2.0", - "create-udp-socket", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/tcp@0.2.0", - "[method]tcp-socket.start-bind", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/tcp@0.2.0", - "[method]tcp-socket.finish-bind", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/tcp@0.2.0", - "[method]tcp-socket.start-connect", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/tcp@0.2.0", - "[method]tcp-socket.finish-connect", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/tcp@0.2.0", - "[method]tcp-socket.start-listen", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/tcp@0.2.0", - "[method]tcp-socket.finish-listen", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/tcp@0.2.0", - "[method]tcp-socket.accept", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/tcp@0.2.0", - "[method]tcp-socket.local-address", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/tcp@0.2.0", - "[method]tcp-socket.remote-address", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/tcp@0.2.0", - "[method]tcp-socket.is-listening", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/tcp@0.2.0", - "[method]tcp-socket.address-family", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/tcp@0.2.0", - "[method]tcp-socket.set-listen-backlog-size", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/tcp@0.2.0", - "[method]tcp-socket.keep-alive-enabled", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/tcp@0.2.0", - "[method]tcp-socket.set-keep-alive-enabled", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/tcp@0.2.0", - "[method]tcp-socket.keep-alive-idle-time", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/tcp@0.2.0", - "[method]tcp-socket.set-keep-alive-idle-time", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/tcp@0.2.0", - "[method]tcp-socket.keep-alive-interval", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/tcp@0.2.0", - "[method]tcp-socket.set-keep-alive-interval", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/tcp@0.2.0", - "[method]tcp-socket.keep-alive-count", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/tcp@0.2.0", - "[method]tcp-socket.set-keep-alive-count", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/tcp@0.2.0", - "[method]tcp-socket.hop-limit", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/tcp@0.2.0", - "[method]tcp-socket.set-hop-limit", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/tcp@0.2.0", - "[method]tcp-socket.receive-buffer-size", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/tcp@0.2.0", - "[method]tcp-socket.set-receive-buffer-size", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/tcp@0.2.0", - "[method]tcp-socket.send-buffer-size", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/tcp@0.2.0", - "[method]tcp-socket.set-send-buffer-size", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/tcp@0.2.0", - "[method]tcp-socket.subscribe", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/tcp@0.2.0", - "[method]tcp-socket.shutdown", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/tcp-create-socket@0.2.0", - "create-tcp-socket", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/ip-name-lookup@0.2.0", - "resolve-addresses", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/ip-name-lookup@0.2.0", - "[method]resolve-address-stream.resolve-next-address", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/ip-name-lookup@0.2.0", - "[method]resolve-address-stream.subscribe", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/network@0.2.0", - "[resource-drop]network", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/udp@0.2.0", - "[resource-drop]udp-socket", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/udp@0.2.0", - "[resource-drop]incoming-datagram-stream", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/udp@0.2.0", - "[resource-drop]outgoing-datagram-stream", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/tcp@0.2.0", - "[resource-drop]tcp-socket", - unreachable_stub, - )?; - stub_import( - module, - "wasi:sockets/ip-name-lookup@0.2.0", - "[resource-drop]resolve-address-stream", - unreachable_stub, - )?; +fn stub_sockets(module: &mut Module, world_imports: &HashSet) -> Result<()> { + if !world_imports.contains("wasi:sockets/instance-network@0.2.0") { + stub_import( + module, + "wasi:sockets/instance-network@0.2.0", + "instance-network", + unreachable_stub, + )?; + } + + if !world_imports.contains("wasi:sockets/udp@0.2.0") { + stub_import( + module, + "wasi:sockets/udp@0.2.0", + "[method]udp-socket.start-bind", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/udp@0.2.0", + "[method]udp-socket.finish-bind", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/udp@0.2.0", + "[method]udp-socket.stream", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/udp@0.2.0", + "[method]udp-socket.local-address", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/udp@0.2.0", + "[method]udp-socket.remote-address", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/udp@0.2.0", + "[method]udp-socket.address-family", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/udp@0.2.0", + "[method]udp-socket.unicast-hop-limit", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/udp@0.2.0", + "[method]udp-socket.set-unicast-hop-limit", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/udp@0.2.0", + "[method]udp-socket.receive-buffer-size", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/udp@0.2.0", + "[method]udp-socket.set-receive-buffer-size", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/udp@0.2.0", + "[method]udp-socket.send-buffer-size", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/udp@0.2.0", + "[method]udp-socket.set-send-buffer-size", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/udp@0.2.0", + "[method]udp-socket.subscribe", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/udp@0.2.0", + "[method]incoming-datagram-stream.receive", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/udp@0.2.0", + "[method]incoming-datagram-stream.subscribe", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/udp@0.2.0", + "[method]outgoing-datagram-stream.check-send", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/udp@0.2.0", + "[method]outgoing-datagram-stream.send", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/udp@0.2.0", + "[method]outgoing-datagram-stream.subscribe", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/udp@0.2.0", + "[resource-drop]udp-socket", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/udp@0.2.0", + "[resource-drop]incoming-datagram-stream", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/udp@0.2.0", + "[resource-drop]outgoing-datagram-stream", + unreachable_stub, + )?; + } + + if !world_imports.contains("wasi:sockets/udp-create-socket@0.2.0") { + stub_import( + module, + "wasi:sockets/udp-create-socket@0.2.0", + "create-udp-socket", + unreachable_stub, + )?; + } + + if !world_imports.contains("wasi:sockets/tcp@0.2.0") { + stub_import( + module, + "wasi:sockets/tcp@0.2.0", + "[method]tcp-socket.start-bind", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/tcp@0.2.0", + "[method]tcp-socket.finish-bind", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/tcp@0.2.0", + "[method]tcp-socket.start-connect", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/tcp@0.2.0", + "[method]tcp-socket.finish-connect", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/tcp@0.2.0", + "[method]tcp-socket.start-listen", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/tcp@0.2.0", + "[method]tcp-socket.finish-listen", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/tcp@0.2.0", + "[method]tcp-socket.accept", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/tcp@0.2.0", + "[method]tcp-socket.local-address", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/tcp@0.2.0", + "[method]tcp-socket.remote-address", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/tcp@0.2.0", + "[method]tcp-socket.is-listening", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/tcp@0.2.0", + "[method]tcp-socket.address-family", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/tcp@0.2.0", + "[method]tcp-socket.set-listen-backlog-size", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/tcp@0.2.0", + "[method]tcp-socket.keep-alive-enabled", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/tcp@0.2.0", + "[method]tcp-socket.set-keep-alive-enabled", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/tcp@0.2.0", + "[method]tcp-socket.keep-alive-idle-time", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/tcp@0.2.0", + "[method]tcp-socket.set-keep-alive-idle-time", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/tcp@0.2.0", + "[method]tcp-socket.keep-alive-interval", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/tcp@0.2.0", + "[method]tcp-socket.set-keep-alive-interval", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/tcp@0.2.0", + "[method]tcp-socket.keep-alive-count", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/tcp@0.2.0", + "[method]tcp-socket.set-keep-alive-count", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/tcp@0.2.0", + "[method]tcp-socket.hop-limit", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/tcp@0.2.0", + "[method]tcp-socket.set-hop-limit", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/tcp@0.2.0", + "[method]tcp-socket.receive-buffer-size", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/tcp@0.2.0", + "[method]tcp-socket.set-receive-buffer-size", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/tcp@0.2.0", + "[method]tcp-socket.send-buffer-size", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/tcp@0.2.0", + "[method]tcp-socket.set-send-buffer-size", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/tcp@0.2.0", + "[method]tcp-socket.subscribe", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/tcp@0.2.0", + "[method]tcp-socket.shutdown", + unreachable_stub, + )?; + + stub_import( + module, + "wasi:sockets/tcp@0.2.0", + "[resource-drop]tcp-socket", + unreachable_stub, + )?; + } + + if !world_imports.contains("wasi:sockets/tcp-create-socket@0.2.0") { + stub_import( + module, + "wasi:sockets/tcp-create-socket@0.2.0", + "create-tcp-socket", + unreachable_stub, + )?; + } + + if !world_imports.contains("wasi:sockets/ip-name-lookup@0.2.0") { + stub_import( + module, + "wasi:sockets/ip-name-lookup@0.2.0", + "resolve-addresses", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/ip-name-lookup@0.2.0", + "[method]resolve-address-stream.resolve-next-address", + unreachable_stub, + )?; + stub_import( + module, + "wasi:sockets/ip-name-lookup@0.2.0", + "[method]resolve-address-stream.subscribe", + unreachable_stub, + )?; + + stub_import( + module, + "wasi:sockets/ip-name-lookup@0.2.0", + "[resource-drop]resolve-address-stream", + unreachable_stub, + )?; + } + + if !world_imports.contains("wasi:sockets/network@0.2.0") { + stub_import( + module, + "wasi:sockets/network@0.2.0", + "[resource-drop]network", + unreachable_stub, + )?; + } + Ok(()) } -fn stub_filesystem(module: &mut Module) -> Result<()> { - stub_import( - module, - "wasi:filesystem/types@0.2.0", - "filesystem-error-code", - unreachable_stub, - )?; - stub_import( - module, - "wasi:filesystem/types@0.2.0", - "[method]descriptor.read-via-stream", - unreachable_stub, - )?; - stub_import( - module, - "wasi:filesystem/types@0.2.0", - "[method]descriptor.write-via-stream", - unreachable_stub, - )?; - stub_import( - module, - "wasi:filesystem/types@0.2.0", - "[method]descriptor.append-via-stream", - unreachable_stub, - )?; - stub_import( - module, - "wasi:filesystem/types@0.2.0", - "[method]descriptor.advise", - unreachable_stub, - )?; - stub_import( - module, - "wasi:filesystem/types@0.2.0", - "[method]descriptor.sync-data", - unreachable_stub, - )?; - stub_import( - module, - "wasi:filesystem/types@0.2.0", - "[method]descriptor.get-flags", - unreachable_stub, - )?; - stub_import( - module, - "wasi:filesystem/types@0.2.0", - "[method]descriptor.get-type", - unreachable_stub, - )?; - stub_import( - module, - "wasi:filesystem/types@0.2.0", - "[method]descriptor.set-size", - unreachable_stub, - )?; - stub_import( - module, - "wasi:filesystem/types@0.2.0", - "[method]descriptor.set-times", - unreachable_stub, - )?; - stub_import( - module, - "wasi:filesystem/types@0.2.0", - "[method]descriptor.read", - unreachable_stub, - )?; - stub_import( - module, - "wasi:filesystem/types@0.2.0", - "[method]descriptor.write", - unreachable_stub, - )?; - stub_import( - module, - "wasi:filesystem/types@0.2.0", - "[method]descriptor.sync", - unreachable_stub, - )?; - stub_import( - module, - "wasi:filesystem/types@0.2.0", - "[method]descriptor.create-directory-at", - unreachable_stub, - )?; - stub_import( - module, - "wasi:filesystem/types@0.2.0", - "[method]descriptor.stat", - unreachable_stub, - )?; - stub_import( - module, - "wasi:filesystem/types@0.2.0", - "[method]descriptor.stat-at", - unreachable_stub, - )?; - stub_import( - module, - "wasi:filesystem/types@0.2.0", - "[method]descriptor.set-times-at", - unreachable_stub, - )?; - stub_import( - module, - "wasi:filesystem/types@0.2.0", - "[method]descriptor.link-at", - unreachable_stub, - )?; - stub_import( - module, - "wasi:filesystem/types@0.2.0", - "[method]descriptor.open-at", - unreachable_stub, - )?; - stub_import( - module, - "wasi:filesystem/types@0.2.0", - "[method]descriptor.readlink-at", - unreachable_stub, - )?; - stub_import( - module, - "wasi:filesystem/types@0.2.0", - "[method]descriptor.remove-directory-at", - unreachable_stub, - )?; - stub_import( - module, - "wasi:filesystem/types@0.2.0", - "[method]descriptor.rename-at", - unreachable_stub, - )?; - stub_import( - module, - "wasi:filesystem/types@0.2.0", - "[method]descriptor.symlink-at", - unreachable_stub, - )?; - stub_import( - module, - "wasi:filesystem/types@0.2.0", - "[method]descriptor.unlink-file-at", - unreachable_stub, - )?; - stub_import( - module, - "wasi:filesystem/types@0.2.0", - "[method]descriptor.is-same-object", - unreachable_stub, - )?; - stub_import( - module, - "wasi:filesystem/types@0.2.0", - "[method]descriptor.metadata-hash", - unreachable_stub, - )?; - stub_import( - module, - "wasi:filesystem/types@0.2.0", - "[method]descriptor.metadata-hash-at", - unreachable_stub, - )?; - stub_import( - module, - "wasi:filesystem/types@0.2.0", - "[method]directory-entry-stream.read-directory-entry", - unreachable_stub, - )?; - stub_import( - module, - "wasi:filesystem/types@0.2.0", - "[method]descriptor.read-directory", - unreachable_stub, - )?; - stub_import( - module, - "wasi:filesystem/types@0.2.0", - "[resource-drop]descriptor", - unreachable_stub, - )?; - stub_import( - module, - "wasi:filesystem/preopens@0.2.0", - "get-directories", - unreachable_stub, - )?; - stub_import( - module, - "wasi:filesystem/types@0.2.0", - "[resource-drop]directory-entry-stream", - unreachable_stub, - )?; +fn stub_filesystem(module: &mut Module, world_imports: &HashSet) -> Result<()> { + if !world_imports.contains("wasi:filesystem/types@0.2.0") { + stub_import( + module, + "wasi:filesystem/types@0.2.0", + "filesystem-error-code", + unreachable_stub, + )?; + stub_import( + module, + "wasi:filesystem/types@0.2.0", + "[method]descriptor.read-via-stream", + unreachable_stub, + )?; + stub_import( + module, + "wasi:filesystem/types@0.2.0", + "[method]descriptor.write-via-stream", + unreachable_stub, + )?; + stub_import( + module, + "wasi:filesystem/types@0.2.0", + "[method]descriptor.append-via-stream", + unreachable_stub, + )?; + stub_import( + module, + "wasi:filesystem/types@0.2.0", + "[method]descriptor.advise", + unreachable_stub, + )?; + stub_import( + module, + "wasi:filesystem/types@0.2.0", + "[method]descriptor.sync-data", + unreachable_stub, + )?; + stub_import( + module, + "wasi:filesystem/types@0.2.0", + "[method]descriptor.get-flags", + unreachable_stub, + )?; + stub_import( + module, + "wasi:filesystem/types@0.2.0", + "[method]descriptor.get-type", + unreachable_stub, + )?; + stub_import( + module, + "wasi:filesystem/types@0.2.0", + "[method]descriptor.set-size", + unreachable_stub, + )?; + stub_import( + module, + "wasi:filesystem/types@0.2.0", + "[method]descriptor.set-times", + unreachable_stub, + )?; + stub_import( + module, + "wasi:filesystem/types@0.2.0", + "[method]descriptor.read", + unreachable_stub, + )?; + stub_import( + module, + "wasi:filesystem/types@0.2.0", + "[method]descriptor.write", + unreachable_stub, + )?; + stub_import( + module, + "wasi:filesystem/types@0.2.0", + "[method]descriptor.sync", + unreachable_stub, + )?; + stub_import( + module, + "wasi:filesystem/types@0.2.0", + "[method]descriptor.create-directory-at", + unreachable_stub, + )?; + stub_import( + module, + "wasi:filesystem/types@0.2.0", + "[method]descriptor.stat", + unreachable_stub, + )?; + stub_import( + module, + "wasi:filesystem/types@0.2.0", + "[method]descriptor.stat-at", + unreachable_stub, + )?; + stub_import( + module, + "wasi:filesystem/types@0.2.0", + "[method]descriptor.set-times-at", + unreachable_stub, + )?; + stub_import( + module, + "wasi:filesystem/types@0.2.0", + "[method]descriptor.link-at", + unreachable_stub, + )?; + stub_import( + module, + "wasi:filesystem/types@0.2.0", + "[method]descriptor.open-at", + unreachable_stub, + )?; + stub_import( + module, + "wasi:filesystem/types@0.2.0", + "[method]descriptor.readlink-at", + unreachable_stub, + )?; + stub_import( + module, + "wasi:filesystem/types@0.2.0", + "[method]descriptor.remove-directory-at", + unreachable_stub, + )?; + stub_import( + module, + "wasi:filesystem/types@0.2.0", + "[method]descriptor.rename-at", + unreachable_stub, + )?; + stub_import( + module, + "wasi:filesystem/types@0.2.0", + "[method]descriptor.symlink-at", + unreachable_stub, + )?; + stub_import( + module, + "wasi:filesystem/types@0.2.0", + "[method]descriptor.unlink-file-at", + unreachable_stub, + )?; + stub_import( + module, + "wasi:filesystem/types@0.2.0", + "[method]descriptor.is-same-object", + unreachable_stub, + )?; + stub_import( + module, + "wasi:filesystem/types@0.2.0", + "[method]descriptor.metadata-hash", + unreachable_stub, + )?; + stub_import( + module, + "wasi:filesystem/types@0.2.0", + "[method]descriptor.metadata-hash-at", + unreachable_stub, + )?; + stub_import( + module, + "wasi:filesystem/types@0.2.0", + "[method]directory-entry-stream.read-directory-entry", + unreachable_stub, + )?; + stub_import( + module, + "wasi:filesystem/types@0.2.0", + "[method]descriptor.read-directory", + unreachable_stub, + )?; + stub_import( + module, + "wasi:filesystem/types@0.2.0", + "[resource-drop]descriptor", + unreachable_stub, + )?; + stub_import( + module, + "wasi:filesystem/types@0.2.0", + "[resource-drop]directory-entry-stream", + unreachable_stub, + )?; + } + + if !world_imports.contains("wasi:filesystem/preopens@0.2.0") { + stub_import( + module, + "wasi:filesystem/preopens@0.2.0", + "get-directories", + unreachable_stub, + )?; + } + Ok(()) } -fn stub_cli(module: &mut Module) -> Result<()> { - stub_import( - module, - "wasi:cli/environment@0.2.0", - "get-environment", - unreachable_stub, - )?; - stub_import( - module, - "wasi:cli/environment@0.2.0", - "get-arguments", - unreachable_stub, - )?; - stub_import( - module, - "wasi:cli/environment@0.2.0", - "initial-cwd", - unreachable_stub, - )?; - stub_import(module, "wasi:cli/exit@0.2.0", "exit", unreachable_stub)?; - stub_import( - module, - "wasi:cli/terminal-stdin@0.2.0", - "get-terminal-stdin", - unreachable_stub, - )?; - stub_import( - module, - "wasi:cli/terminal-stdout@0.2.0", - "get-terminal-stdout", - unreachable_stub, - )?; - stub_import( - module, - "wasi:cli/terminal-stderr@0.2.0", - "get-terminal-stderr", - unreachable_stub, - )?; - stub_import( - module, - "wasi:cli/terminal-input@0.2.0", - "[resource-drop]terminal-input", - unreachable_stub, - )?; - stub_import( - module, - "wasi:cli/terminal-output@0.2.0", - "[resource-drop]terminal-output", - unreachable_stub, - )?; +fn stub_cli(module: &mut Module, world_imports: &HashSet) -> Result<()> { + if !world_imports.contains("wasi:cli/environment@0.2.0") { + stub_import( + module, + "wasi:cli/environment@0.2.0", + "get-environment", + unreachable_stub, + )?; + + stub_import( + module, + "wasi:cli/environment@0.2.0", + "get-arguments", + unreachable_stub, + )?; + stub_import( + module, + "wasi:cli/environment@0.2.0", + "initial-cwd", + unreachable_stub, + )?; + } + + if !world_imports.contains("wasi:cli/exit@0.2.0") { + stub_import(module, "wasi:cli/exit@0.2.0", "exit", unreachable_stub)?; + } + + if !world_imports.contains("wasi:cli/terminal-stdin@0.2.0") { + stub_import( + module, + "wasi:cli/terminal-stdin@0.2.0", + "get-terminal-stdin", + unreachable_stub, + )?; + } + + if !world_imports.contains("wasi:cli/terminal-stdout@0.2.0") { + stub_import( + module, + "wasi:cli/terminal-stdout@0.2.0", + "get-terminal-stdout", + unreachable_stub, + )?; + } + + if !world_imports.contains("wasi:cli/terminal-stderr@0.2.0") { + stub_import( + module, + "wasi:cli/terminal-stderr@0.2.0", + "get-terminal-stderr", + unreachable_stub, + )?; + } + + if !world_imports.contains("wasi:cli/terminal-input@0.2.0") { + stub_import( + module, + "wasi:cli/terminal-input@0.2.0", + "[resource-drop]terminal-input", + unreachable_stub, + )?; + } + + if !world_imports.contains("wasi:cli/terminal-output@0.2.0") { + stub_import( + module, + "wasi:cli/terminal-output@0.2.0", + "[resource-drop]terminal-output", + unreachable_stub, + )?; + } + Ok(()) } diff --git a/crates/spidermonkey-embedding-splicer/wit/spidermonkey-embedding-splicer.wit b/crates/spidermonkey-embedding-splicer/wit/spidermonkey-embedding-splicer.wit index 7cde50e..08aa15d 100644 --- a/crates/spidermonkey-embedding-splicer/wit/spidermonkey-embedding-splicer.wit +++ b/crates/spidermonkey-embedding-splicer/wit/spidermonkey-embedding-splicer.wit @@ -31,7 +31,7 @@ world spidermonkey-embedding-splicer { imports: list>, } - export stub-wasi: func(engine: list, features: list) -> result, string>; + 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; } diff --git a/src/componentize.js b/src/componentize.js index d6ae941..52cba5b 100644 --- a/src/componentize.js +++ b/src/componentize.js @@ -24,7 +24,7 @@ const isWindows = platform === 'win32'; const DEBUG_BINDINGS = false; const DEBUG_CALLS = false; -function maybeWindowsPath (path) { +function maybeWindowsPath(path) { if (!path) return path; if (!isWindows) return resolve(path); return '//?/' + resolve(path).replace(/\\/g, '/'); @@ -314,7 +314,9 @@ export async function componentize(jsSource, witWorld, opts) { } // after wizering, stub out the wasi imports depending on what features are enabled - const finalBin = stubWasi(bin, features); + const finalBin = stubWasi(bin, features, witWorld, + maybeWindowsPath(witPath), + worldName,); const component = await metadataAdd( await componentNew( From 30230285f72c599a5aa7ff756b416c0eea6c4e31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Istv=C3=A1n=20B=C3=ADr=C3=B3?= Date: Mon, 3 Jun 2024 17:06:10 +0200 Subject: [PATCH 12/41] test with update-upstream-and-apply-fetch-rework starling --- StarlingMonkey | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/StarlingMonkey b/StarlingMonkey index 0ee0031..b48d4b1 160000 --- a/StarlingMonkey +++ b/StarlingMonkey @@ -1 +1 @@ -Subproject commit 0ee003193b30c0d7828c0a2d3dd4871207ad173f +Subproject commit b48d4b157ad352dfb8e1096b1f941c9763158b2e From aaef119b1d4a6871a816b702d99e97056cf68cc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Istv=C3=A1n=20B=C3=ADr=C3=B3?= Date: Tue, 4 Jun 2024 14:36:49 +0200 Subject: [PATCH 13/41] update StarlingMonkey --- StarlingMonkey | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/StarlingMonkey b/StarlingMonkey index b48d4b1..e8870ef 160000 --- a/StarlingMonkey +++ b/StarlingMonkey @@ -1 +1 @@ -Subproject commit b48d4b157ad352dfb8e1096b1f941c9763158b2e +Subproject commit e8870eff3d5746b8f0e9dcfdecb6232e302e7300 From 544b4edd28cb49d91d88b1abcd333712c65ecf91 Mon Sep 17 00:00:00 2001 From: Karthik Ganeshram Date: Tue, 4 Jun 2024 19:44:19 +0200 Subject: [PATCH 14/41] use the Bytecode Alliance org repository for StarlingMonkey (#115) Signed-off-by: karthik2804 --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index c780d29..89d9501 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "StarlingMonkey"] path = StarlingMonkey - url = git@github.com:fermyon/StarlingMonkey + url = git@github.com:bytecodealliance/StarlingMonkey From 1c92d241fa1f7f7da2d20719e1291aea845bef7a Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Tue, 28 May 2024 13:27:52 -0700 Subject: [PATCH 15/41] deps: update to latest starlingmonkey --- StarlingMonkey | 2 +- embedding/embedding.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/StarlingMonkey b/StarlingMonkey index c1d7439..4a76bf0 160000 --- a/StarlingMonkey +++ b/StarlingMonkey @@ -1 +1 @@ -Subproject commit c1d7439a3412496db0c5d4004d723396cc46a892 +Subproject commit 4a76bf0c5130424664e309faac6d434de756a63c diff --git a/embedding/embedding.cpp b/embedding/embedding.cpp index 0c0ca59..b63a7fe 100644 --- a/embedding/embedding.cpp +++ b/embedding/embedding.cpp @@ -274,7 +274,7 @@ extern "C" } Runtime.free_list.clear(); RootedValue result(Runtime.cx); - Runtime.engine->run_event_loop(&result); + Runtime.engine->run_event_loop(); LOG("(post_call) end"); } From 1a0c843ceea41bc91ac691765685181085b05521 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Wed, 29 May 2024 13:29:37 -0700 Subject: [PATCH 16/41] fixup splicing --- .../src/splice.rs | 88 ++++++------------- embedding/embedding.cpp | 6 +- 2 files changed, 28 insertions(+), 66 deletions(-) diff --git a/crates/spidermonkey-embedding-splicer/src/splice.rs b/crates/spidermonkey-embedding-splicer/src/splice.rs index fd7b354..12c397f 100644 --- a/crates/spidermonkey-embedding-splicer/src/splice.rs +++ b/crates/spidermonkey-embedding-splicer/src/splice.rs @@ -1,15 +1,10 @@ use walrus::{ - ir::{ - BinaryOp, Binop, Const, Instr, LoadKind, LocalGet, LocalSet, LocalTee, MemArg, Store, - StoreKind, UnaryOp, Unop, Value, - }, + ir::{BinaryOp, Binop, Const, Instr, LoadKind, MemArg, Store, StoreKind, UnaryOp, Unop, Value}, ExportId, ExportItem, FunctionBuilder, FunctionId, LocalId, ValType, }; use crate::*; -const DEBUG: bool = false; - // // Parses the Spidermonkey binary into section data for reserialization // into an output binary, and in the process: @@ -39,10 +34,7 @@ pub fn splice( exports: Vec<(String, CoreFn)>, debug: bool, ) -> Result> { - let mut config = walrus::ModuleConfig::new(); - if debug { - config.generate_dwarf(true); - } + let config = walrus::ModuleConfig::new(); let mut module = config.parse(&engine)?; // since StarlingMonkey implements CLI Run and incoming handler, @@ -76,7 +68,7 @@ pub fn splice( // extract the native instructions from sample functions // then inline the imported functions and main import gating function // (erasing sample functions in the process) - synthesize_import_functions(&mut module, &imports)?; + synthesize_import_functions(&mut module, &imports, debug)?; // create the exported functions as wrappers around the "cabi_call" function synthesize_export_functions(&mut module, &exports)?; @@ -94,6 +86,7 @@ fn get_export_fid(module: &walrus::Module, expt_id: &ExportId) -> FunctionId { fn synthesize_import_functions( module: &mut walrus::Module, imports: &Vec<(String, String, CoreFn, Option)>, + debug: bool, ) -> Result<()> { let mut coreabi_get_import: Option = None; let mut cabi_realloc: Option = None; @@ -116,8 +109,26 @@ fn synthesize_import_functions( let cabi_realloc_fid = get_export_fid(module, &cabi_realloc.unwrap()); - let coreabi_sample_fid = get_export_fid(module, coreabi_sample_ids.first().unwrap()); - let coreabi_sample_i32 = module.funcs.get(coreabi_sample_fid).kind.unwrap_local(); + let coreabi_sample_i32 = module + .funcs + .get(get_export_fid(module, &coreabi_sample_ids[0])) + .kind + .unwrap_local(); + let _coreabi_sample_i64 = module + .funcs + .get(get_export_fid(module, &coreabi_sample_ids[1])) + .kind + .unwrap_local(); + let _coreabi_sample_f32 = module + .funcs + .get(get_export_fid(module, &coreabi_sample_ids[2])) + .kind + .unwrap_local(); + let _coreabi_sample_f64 = module + .funcs + .get(get_export_fid(module, &coreabi_sample_ids[3])) + .kind + .unwrap_local(); // These functions retrieve the corresponding type // from a JS::HandleValue @@ -179,7 +190,7 @@ fn synthesize_import_functions( let tmp_local = module.locals.add(ValType::I64); for (impt_specifier, impt_name, impt_sig, retptr_size) in imports.iter() { - if DEBUG { + if debug { println!( "> IMPORT {} {} > {:?}", impt_specifier, impt_name, &impt_sig @@ -226,55 +237,6 @@ fn synthesize_import_functions( let mut func_body = func.func_body(); - // copy the prelude instructions from the sample function (first block) - let coreabi_sample_i32 = module.funcs.get(coreabi_sample_fid).kind.unwrap_local(); - let prelude_block = &coreabi_sample_i32 - .block(coreabi_sample_i32.entry_block()) - .instrs[0] - .0; - let prelude_seq = match prelude_block { - Instr::Block(prelude_block) => prelude_block.seq, - _ => { - eprintln!("Splicer error: unable to read prelude sequence, continuing for debug build but note binding functions will not work!"); - return Ok(()); - } - }; - - let prelude_block = coreabi_sample_i32.block(prelude_seq); - func_body.block(None, |prelude| { - for (instr, _) in &prelude_block.instrs { - match instr { - Instr::LocalGet(LocalGet { local }) => { - if local.eq(&vp_arg) { - prelude.instr(instr.clone()); - } else { - prelude.local_get(tmp_local); - } - } - Instr::LocalSet(LocalSet { local }) => { - if local.eq(&vp_arg) { - prelude.instr(instr.clone()); - } else { - prelude.local_set(tmp_local); - } - } - Instr::LocalTee(LocalTee { local }) => { - if local.eq(&vp_arg) { - prelude.instr(instr.clone()); - } else { - prelude.local_tee(tmp_local); - } - } - Instr::BrIf(_) => { - prelude.br_if(prelude.id()); - } - _ => { - prelude.instr(instr.clone()); - } - }; - } - }); - // stack the return arg now as it chains with the // args we're about to add to the stack if impt_sig.ret.is_some() { diff --git a/embedding/embedding.cpp b/embedding/embedding.cpp index b63a7fe..154327c 100644 --- a/embedding/embedding.cpp +++ b/embedding/embedding.cpp @@ -70,7 +70,7 @@ extern "C" { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); int64_t arg1 = from_bigint64(args[1]); - args.rval().setBigInt(to_bigint64(cx, arg1)); + args.rval().setBigInt(to_bigint64(cx, arg1 * 32771)); return true; } @@ -78,7 +78,7 @@ extern "C" { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); float arg2 = static_cast(args[2].toDouble()); - args.rval().setDouble(arg2); + args.rval().setDouble(arg2 * 32771); return true; } @@ -86,7 +86,7 @@ extern "C" { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); double arg3 = args[3].toDouble(); - args.rval().setDouble(arg3); + args.rval().setDouble(arg3 * 32771); return true; } From 510f96d29e855360cf1429dc8ba3785849da0aed Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Wed, 29 May 2024 14:59:58 -0700 Subject: [PATCH 17/41] latest starlingmonkey --- StarlingMonkey | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/StarlingMonkey b/StarlingMonkey index 4a76bf0..aa9ff14 160000 --- a/StarlingMonkey +++ b/StarlingMonkey @@ -1 +1 @@ -Subproject commit 4a76bf0c5130424664e309faac6d434de756a63c +Subproject commit aa9ff14cd0696877a402435faaf8db486ce0ff89 From 9d6e84e008eb546f26a91fe8a115a9c1a6fb28b4 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Wed, 29 May 2024 15:03:26 -0700 Subject: [PATCH 18/41] update rust toolchain --- .github/workflows/main.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 50c022a..30218c6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -28,12 +28,11 @@ jobs: with: submodules: recursive - - name: Install Rust 1.68.2, 1.76.0 + - name: Install Rust Toolchain run: | - rustup toolchain install 1.68.2 - rustup toolchain install 1.76.0 - rustup target add wasm32-unknown-unknown --toolchain 1.76.0 - rustup target add wasm32-wasi --toolchain 1.68.2 + rustup toolchain install stable + rustup target add wasm32-unknown-unknown --toolchain stable + rustup target add wasm32-wasi --toolchain 1.77.1 - uses: actions/setup-node@v2 with: From 3323f113edbdaa9086c213cca2e0874e6b0ca4b4 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Wed, 29 May 2024 15:46:05 -0700 Subject: [PATCH 19/41] fixup tests --- StarlingMonkey | 2 +- test/builtins/console-object.js | 6 +++++- test/builtins/globals.js | 2 +- test/builtins/timeout.js | 2 ++ 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/StarlingMonkey b/StarlingMonkey index aa9ff14..2e23c54 160000 --- a/StarlingMonkey +++ b/StarlingMonkey @@ -1 +1 @@ -Subproject commit aa9ff14cd0696877a402435faaf8db486ce0ff89 +Subproject commit 2e23c54f2a9a51cd846b4007fa9eb31bb04d4e10 diff --git a/test/builtins/console-object.js b/test/builtins/console-object.js index 399ba03..2c7e703 100644 --- a/test/builtins/console-object.js +++ b/test/builtins/console-object.js @@ -53,6 +53,10 @@ export const source = ` export async function test (run) { const { stdout, stderr } = await run(); - strictEqual(stdout, `{ a: { value: "a" }, b: { c: "d" }, e: ["f"], g: [{ g: "i" }], l: [Function l], m: [Getter], n: [Getter], o: [Function], p: [Function], q: 5, s: 29879287298374924, t: Set(3) { 1, 2, 3 }, u: Map(3) { 1 => 2, 3 => 4, [Function foo] => {} }, v: Symbol.for("blah"), w: Symbol(), x: undefined, y: null, z: URL { hash: "", host: "site.com", hostname: "site.com", href: "https://site.com/x?a&b", origin: "https://site.com", password: "", pathname: "/x", port: "", protocol: "https:", search: "?a&b", searchParams: URLSearchParams {}, username: "" }, zz: Uint8Array [1, 2, 3], zzz: Z {} }\n`); + strictEqual(stdout, `{ a: { value: "a" }, b: { c: "d" }, e: ["f"], g: [{ g: "i" }], l: [ l () { + + }], m: [Getter], n: [Getter], o: [ function () { + + }], p: [ () => {}], q: 5, s: 29879287298374924, t: Set(3) { 1, 2, 3 }, u: Map(3) { 1 => 2, 3 => 4, [ function foo () {}] => {} }, v: Symbol.for("blah"), w: Symbol(), x: undefined, y: null, z: URL { hash: "", host: "site.com", hostname: "site.com", href: "https://site.com/x?a&b", origin: "https://site.com", password: "", pathname: "/x", port: "", protocol: "https:", search: "?a&b", searchParams: URLSearchParams {}, username: "" }, zz: Uint8Array [1, 2, 3], zzz: Z {} }\n`); strictEqual(stderr, ''); } diff --git a/test/builtins/globals.js b/test/builtins/globals.js index c26ff28..9395b8c 100644 --- a/test/builtins/globals.js +++ b/test/builtins/globals.js @@ -13,7 +13,7 @@ export async function test(run) { const { stdout, stderr } = await run(); strictEqual( stdout, - `["undefined", "Function", "Object", "eval", "globalThis", "Array", "Boolean", "JSON", "Date", "Math", "isNaN", "isFinite", "parseInt", "parseFloat", "NaN", "Infinity", "Number", "escape", "unescape", "decodeURI", "encodeURI", "decodeURIComponent", "encodeURIComponent", "String", "RegExp", "Error", "InternalError", "AggregateError", "EvalError", "RangeError", "ReferenceError", "SyntaxError", "TypeError", "URIError", "ArrayBuffer", "Int8Array", "Uint8Array", "Int16Array", "Uint16Array", "Int32Array", "Uint32Array", "Float32Array", "Float64Array", "Uint8ClampedArray", "BigInt64Array", "BigUint64Array", "BigInt", "Proxy", "WeakMap", "Map", "Set", "DataView", "Symbol", "Reflect", "WeakSet", "Promise", "FinalizationRegistry", "WeakRef", "ReadableStream", "ReadableStreamBYOBReader", "ReadableStreamBYOBRequest", "ReadableStreamDefaultReader", "ReadableStreamDefaultController", "ReadableByteStreamController", "WritableStream", "ByteLengthQueuingStrategy", "CountQueuingStrategy", "self", "URL", "URLSearchParams", "atob", "btoa", "console", "DOMException", "Performance", "queueMicrotask", "structuredClone", "setInterval", "setTimeout", "clearInterval", "clearTimeout", "WorkerLocation", "location", "TextEncoder", "TextDecoder", "TransformStream", "CompressionStream", "DecompressionStream", "fetch", "Request", "Response", "Headers", "addEventListener", "SubtleCrypto", "Crypto", "crypto", "CryptoKey"]\n` + `["undefined", "Function", "Object", "eval", "globalThis", "Array", "Boolean", "JSON", "Date", "Math", "isNaN", "isFinite", "parseInt", "parseFloat", "NaN", "Infinity", "Number", "escape", "unescape", "decodeURI", "encodeURI", "decodeURIComponent", "encodeURIComponent", "String", "RegExp", "Error", "InternalError", "AggregateError", "EvalError", "RangeError", "ReferenceError", "SyntaxError", "TypeError", "URIError", "ArrayBuffer", "Int8Array", "Uint8Array", "Int16Array", "Uint16Array", "Int32Array", "Uint32Array", "Float32Array", "Float64Array", "Uint8ClampedArray", "BigInt64Array", "BigUint64Array", "BigInt", "Proxy", "WeakMap", "Map", "Set", "DataView", "Symbol", "Reflect", "WeakSet", "Promise", "FinalizationRegistry", "WeakRef", "ReadableStream", "ReadableStreamBYOBReader", "ReadableStreamBYOBRequest", "ReadableStreamDefaultReader", "ReadableStreamDefaultController", "ReadableByteStreamController", "WritableStream", "ByteLengthQueuingStrategy", "CountQueuingStrategy", "self", "queueMicrotask", "structuredClone", "atob", "btoa", "DOMException", "URL", "URLSearchParams", "console", "Performance", "performance", "setInterval", "setTimeout", "clearInterval", "clearTimeout", "WorkerLocation", "location", "TextEncoder", "TextDecoder", "TransformStream", "CompressionStream", "DecompressionStream", "fetch", "Request", "Response", "Headers", "addEventListener", "SubtleCrypto", "Crypto", "crypto", "CryptoKey"]\n` ); strictEqual(stderr, ''); } diff --git a/test/builtins/timeout.js b/test/builtins/timeout.js index 1f1429a..7bbe31a 100644 --- a/test/builtins/timeout.js +++ b/test/builtins/timeout.js @@ -6,10 +6,12 @@ export const source = ` console.log(Date.now()); setTimeout(() => { console.log(Date.now()); + console.log('done'); done = true; }, 100); } export function ready () { + console.log('ready'); return done; } `; From 0c4ff50d4ad8cdc5c9a50e078f7f3201e7b461a2 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Wed, 29 May 2024 15:49:50 -0700 Subject: [PATCH 20/41] workflow fix --- .github/workflows/main.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 30218c6..20f34b4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -30,8 +30,7 @@ jobs: - name: Install Rust Toolchain run: | - rustup toolchain install stable - rustup target add wasm32-unknown-unknown --toolchain stable + rustup toolchain install 1.77.1 rustup target add wasm32-wasi --toolchain 1.77.1 - uses: actions/setup-node@v2 From 39bb48c95fdfd9da583bbc69247b26b904669ff3 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Wed, 29 May 2024 15:52:51 -0700 Subject: [PATCH 21/41] fix tests --- StarlingMonkey | 2 +- test/builtins/timeout.js | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/StarlingMonkey b/StarlingMonkey index 2e23c54..5bdb946 160000 --- a/StarlingMonkey +++ b/StarlingMonkey @@ -1 +1 @@ -Subproject commit 2e23c54f2a9a51cd846b4007fa9eb31bb04d4e10 +Subproject commit 5bdb946f137e946206fb865cdba92b8fb0654416 diff --git a/test/builtins/timeout.js b/test/builtins/timeout.js index 7bbe31a..1f1429a 100644 --- a/test/builtins/timeout.js +++ b/test/builtins/timeout.js @@ -6,12 +6,10 @@ export const source = ` console.log(Date.now()); setTimeout(() => { console.log(Date.now()); - console.log('done'); done = true; }, 100); } export function ready () { - console.log('ready'); return done; } `; From 566ff29e20283629fba4819ce7c4607d0b03a55f Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Wed, 29 May 2024 16:57:57 -0700 Subject: [PATCH 22/41] try latest merge --- StarlingMonkey | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/StarlingMonkey b/StarlingMonkey index 5bdb946..82e9b4d 160000 --- a/StarlingMonkey +++ b/StarlingMonkey @@ -1 +1 @@ -Subproject commit 5bdb946f137e946206fb865cdba92b8fb0654416 +Subproject commit 82e9b4d2c4396a645ca25ab79ac12e0d4e43e2ca From 816b513351362af01123efad0b067cdd012d210f Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Wed, 29 May 2024 17:15:31 -0700 Subject: [PATCH 23/41] latest --- StarlingMonkey | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/StarlingMonkey b/StarlingMonkey index 82e9b4d..cb7b007 160000 --- a/StarlingMonkey +++ b/StarlingMonkey @@ -1 +1 @@ -Subproject commit 82e9b4d2c4396a645ca25ab79ac12e0d4e43e2ca +Subproject commit cb7b007997c7261ce2b6f132a99b12dec5ed2268 From dd37c60ad7a362afd296f52f9a3c3e4e50429cce Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Wed, 29 May 2024 17:30:54 -0700 Subject: [PATCH 24/41] fixup --- StarlingMonkey | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/StarlingMonkey b/StarlingMonkey index cb7b007..0ee0031 160000 --- a/StarlingMonkey +++ b/StarlingMonkey @@ -1 +1 @@ -Subproject commit cb7b007997c7261ce2b6f132a99b12dec5ed2268 +Subproject commit 0ee003193b30c0d7828c0a2d3dd4871207ad173f From d65e34d1ce08293b97f6e950dca22b624fc643df Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Tue, 4 Jun 2024 11:22:28 -0700 Subject: [PATCH 25/41] latest --- StarlingMonkey | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/StarlingMonkey b/StarlingMonkey index 0ee0031..f9cda7a 160000 --- a/StarlingMonkey +++ b/StarlingMonkey @@ -1 +1 @@ -Subproject commit 0ee003193b30c0d7828c0a2d3dd4871207ad173f +Subproject commit f9cda7ab14b3be026bb1135168feb9bc1af8a6dc From 90ec48ef4dcc1419a10451377126341c0ee141e1 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Tue, 4 Jun 2024 12:08:35 -0700 Subject: [PATCH 26/41] add fetch test --- src/componentize.js | 17 +---------------- test/builtins/fetch.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 16 deletions(-) create mode 100644 test/builtins/fetch.js diff --git a/src/componentize.js b/src/componentize.js index 52cba5b..63b1177 100644 --- a/src/componentize.js +++ b/src/componentize.js @@ -60,29 +60,14 @@ export async function componentize(jsSource, witWorld, opts) { const features = []; if (!disableFeatures.includes('stdio')) { features.push('stdio'); - } else if (imports.some(([module]) => module.startsWith('wasi:cli/std') || module.startsWith('wasi:cli/terminal'))) { - throw new Error( - 'Cannot disable "stdio" as it is already an import in the target world.' - ); } if (!disableFeatures.includes('random')) { features.push('random'); - } else if (imports.some(([module]) => module.startsWith('wasi:random/'))) { - throw new Error( - 'Cannot disable "random" as it is already an import in the target world.' - ); } if (!disableFeatures.includes('clocks')) { features.push('clocks'); - } else if (imports.some(([module]) => module.startsWith('wasi:clocks/'))) { - throw new Error( - 'Cannot disable "clocks" as it is already an import in the target world.' - ); } - if ( - enableFeatures.includes('http') || - imports.some(([module]) => module.startsWith('wasi:http/')) - ) { + if (!disableFeatures.includes('http')) { features.push('http'); } diff --git a/test/builtins/fetch.js b/test/builtins/fetch.js new file mode 100644 index 0000000..7e11164 --- /dev/null +++ b/test/builtins/fetch.js @@ -0,0 +1,28 @@ +import { strictEqual, ok } from 'node:assert'; + +export const source = ` + let val, err, done = false; + export function run () { + (async () => { + const res = await fetch('https://www.google.com'); + return res.text(); + })().then(text => { + console.log(text); + done = true; + }, err => { + console.error(err); + done = true; + }); + } + export function ready () { + return done; + } +`; + +export async function test(run) { + const curNow = Date.now(); + const { stdout, stderr } = await run(); + console.log(stdout); + ok(stdout.includes('google')); + strictEqual(stderr, ''); +} From 1a0568034c9f6a942168d68fcedc218922655fdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Istv=C3=A1n=20B=C3=ADr=C3=B3?= Date: Mon, 10 Jun 2024 14:22:21 +0200 Subject: [PATCH 27/41] update StarlingMonkey --- StarlingMonkey | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/StarlingMonkey b/StarlingMonkey index e8870ef..41a4083 160000 --- a/StarlingMonkey +++ b/StarlingMonkey @@ -1 +1 @@ -Subproject commit e8870eff3d5746b8f0e9dcfdecb6232e302e7300 +Subproject commit 41a4083849bd1dcd2a836ff163ed361cd7f1fe49 From 102c88bc9160600edcae1ce8afd5718a85765bb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Istv=C3=A1n=20B=C3=ADr=C3=B3?= Date: Wed, 12 Jun 2024 12:19:33 +0200 Subject: [PATCH 28/41] update StarlingMonkey --- StarlingMonkey | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/StarlingMonkey b/StarlingMonkey index 41a4083..c35f466 160000 --- a/StarlingMonkey +++ b/StarlingMonkey @@ -1 +1 @@ -Subproject commit 41a4083849bd1dcd2a836ff163ed361cd7f1fe49 +Subproject commit c35f4666da52759b9a2de991d45c46f0dffaa0b8 From fd6ce0cad452446255ee6b7610ff155ddedf7c95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Istv=C3=A1n=20B=C3=ADr=C3=B3?= Date: Wed, 12 Jun 2024 12:20:47 +0200 Subject: [PATCH 29/41] add fetch-sync test runner + some tests --- test/fetch-sync/get-json-big.js | 3 + test/fetch-sync/get-json-small.js | 3 + test/fetch-sync/get-text-big.js | 3 + test/fetch-sync/get-text-small.js | 3 + test/fetch-sync/lib/lib.js | 93 +++++++++++++++++++++++++++++++ test/test.js | 85 ++++++++++++++++++++++++++++ 6 files changed, 190 insertions(+) create mode 100644 test/fetch-sync/get-json-big.js create mode 100644 test/fetch-sync/get-json-small.js create mode 100644 test/fetch-sync/get-text-big.js create mode 100644 test/fetch-sync/get-text-small.js create mode 100644 test/fetch-sync/lib/lib.js diff --git a/test/fetch-sync/get-json-big.js b/test/fetch-sync/get-json-big.js new file mode 100644 index 0000000..2814ea5 --- /dev/null +++ b/test/fetch-sync/get-json-big.js @@ -0,0 +1,3 @@ +export function getResult() { + return testGetJsonArray("https://jsonplaceholder.typicode.com/photos", 5000); +} \ No newline at end of file diff --git a/test/fetch-sync/get-json-small.js b/test/fetch-sync/get-json-small.js new file mode 100644 index 0000000..a7d1889 --- /dev/null +++ b/test/fetch-sync/get-json-small.js @@ -0,0 +1,3 @@ +export function getResult() { + return testGetJsonArray("https://jsonplaceholder.typicode.com/users", 10); +} \ No newline at end of file diff --git a/test/fetch-sync/get-text-big.js b/test/fetch-sync/get-text-big.js new file mode 100644 index 0000000..8d58948 --- /dev/null +++ b/test/fetch-sync/get-text-big.js @@ -0,0 +1,3 @@ +export function getResult() { + return testGetTextArray("https://jsonplaceholder.typicode.com/photos", 5000); +} \ No newline at end of file diff --git a/test/fetch-sync/get-text-small.js b/test/fetch-sync/get-text-small.js new file mode 100644 index 0000000..84a1597 --- /dev/null +++ b/test/fetch-sync/get-text-small.js @@ -0,0 +1,3 @@ +export function getResult() { + return testGetTextArray("https://jsonplaceholder.typicode.com/users", 10); +} \ No newline at end of file diff --git a/test/fetch-sync/lib/lib.js b/test/fetch-sync/lib/lib.js new file mode 100644 index 0000000..7352ebe --- /dev/null +++ b/test/fetch-sync/lib/lib.js @@ -0,0 +1,93 @@ +function assert(cond, msg) { + if (!cond) { + throw new Error('assert: ' + msg); + } +} + +function testAndReturnOK(f) { + try { + f(); + } catch (e) { + console.error(e); + return e.toString(); + } + return 'ok'; +} + +function testGetJsonArray(url, length) { + return testAndReturnOK(() => { + let result = syncGetJson(url); + assert(result != null, 'result is not nullish'); + assert(result['length'] === length, `length == ${length}`); + console.log(`result json size: ${JSON.stringify(result).length}`); + }); +} + +function testGetTextArray(url, length) { + return testAndReturnOK(() => { + let textResult = syncGetText(url); + let result = JSON.parse(textResult); + assert(result != null, 'result is not nullish'); + assert(result['length'] === length, `length == ${length}`); + console.log(`result text size: ${result.length}`); + }); +} + +async function asyncGetJson(url) { + let response = await fetch(url); + let json = response.json(); + return json; +} + +function syncGetJson(url) { + return asyncToSync(asyncGetJson(url)); +} + +async function asyncGetText(url) { + let response = await fetch(url); + let text = response.text(); + return text; +} + +function syncGetText(url) { + return asyncToSync(asyncGetText(url)); +} + +function asyncToSync(promise) { + let success = false; + let done = false; + let result; + let error; + + promise + .then(r => { + result = r; + success = true; + done = true; + }) + .catch(e => { + error = e; + done = true; + }); + + + let i = 0; + while (!done && i < 100) { + console.log('runEventLoop'); + i += 1; + runEventLoop(); + } + + if (!done) { + let error = new Error('asyncToSync: illegal state: not done'); + console.error(error); + throw error; + } + + if (!success) { + console.error('asyncToSync: error: {}', error); + throw error; + } + + return result; +} \ No newline at end of file diff --git a/test/test.js b/test/test.js index b816746..0f29974 100644 --- a/test/test.js +++ b/test/test.js @@ -252,3 +252,88 @@ suite('WASI', () => { strictEqual(result.split(',').length, 3); }); }); + +const fetchSyncCases = await readdir(new URL('./fetch-sync', import.meta.url)); +suite.only('Fetch-Sync', () => { + const libSourcePromise = readFile( + new URL(`./fetch-sync/lib/lib.js`, import.meta.url), + 'utf8' + ); + + + for (const name of fetchSyncCases) { + if (!name.endsWith('.js')) { + continue; + } + test(name, async () => { + let libSource = await libSourcePromise; + let source = await readFile( + new URL(`./fetch-sync/${name}`, import.meta.url), + 'utf8' + ); + + source = libSource + "\n" + source; + + try { + const { component, imports } = await componentize(source, { + sourceName: `${name}`, + witPath: fileURLToPath(new URL('./wit', import.meta.url)), + worldName: 'test2', + enableStdout: true + }); + + const map = { + 'wasi:cli-base/*': '@bytecodealliance/preview2-shim/cli-base#*', + 'wasi:clocks/*': '@bytecodealliance/preview2-shim/clocks#*', + 'wasi:filesystem/*': '@bytecodealliance/preview2-shim/filesystem#*', + 'wasi:http/*': '@bytecodealliance/preview2-shim/http#*', + 'wasi:io/*': '@bytecodealliance/preview2-shim/io#*', + 'wasi:logging/*': '@bytecodealliance/preview2-shim/logging#*', + 'wasi:poll/*': '@bytecodealliance/preview2-shim/poll#*', + 'wasi:random/*': '@bytecodealliance/preview2-shim/random#*', + 'wasi:sockets/*': '@bytecodealliance/preview2-shim/sockets#*' + }; + for (const [impt] of imports) { + if (impt.startsWith('wasi:')) continue; + let importName = impt.split('/').pop(); + if (importName === 'test') importName = 'imports'; + map[impt] = `../../fetch-sync/${importName}.js`; + } + + const { files } = await transpile(component, { + name, + map, + wasiShim: true, + validLiftingOptimization: false + }); + + await mkdir(new URL(`./output/fetch-sync/${name}/interfaces`, import.meta.url), { + recursive: true + }); + + await writeFile( + new URL(`./output/fetch-sync/${name}.component.wasm`, import.meta.url), + component + ); + + for (const file of Object.keys(files)) { + let source = files[file]; + await writeFile( + new URL(`./output/fetch-sync/${name}/${file}`, import.meta.url), + source + ); + } + + var instance = await import(`./output/fetch-sync/${name}/${name}.js`); + } catch (e) { + if (test.err) { + test.err(e); + return; + } + throw e; + } + + strictEqual(instance.getResult(), 'ok'); + }); + } +}); From 5def55114ca4f9ea576fa8ca522d7986d8909cc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Istv=C3=A1n=20B=C3=ADr=C3=B3?= Date: Wed, 12 Jun 2024 12:58:19 +0200 Subject: [PATCH 30/41] increase loop count guard + more fetch sync tests --- test/fetch-sync/get-json-mid-sync-repeated.js | 8 ++++++++ test/fetch-sync/get-json-mid.js | 3 +++ test/fetch-sync/get-json-small-sync-repeated.js | 8 ++++++++ test/fetch-sync/lib/lib.js | 9 ++++----- test/test.js | 11 +++++++++-- 5 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 test/fetch-sync/get-json-mid-sync-repeated.js create mode 100644 test/fetch-sync/get-json-mid.js create mode 100644 test/fetch-sync/get-json-small-sync-repeated.js diff --git a/test/fetch-sync/get-json-mid-sync-repeated.js b/test/fetch-sync/get-json-mid-sync-repeated.js new file mode 100644 index 0000000..3309ead --- /dev/null +++ b/test/fetch-sync/get-json-mid-sync-repeated.js @@ -0,0 +1,8 @@ +export function getResult() { + return testAndReturnOK(() => { + for (let i = 0; i < 100; i++) { + console.log(`repeat: ${i}`); + testGetJsonArray("https://jsonplaceholder.typicode.com/comments", 500); + } + }); +} \ No newline at end of file diff --git a/test/fetch-sync/get-json-mid.js b/test/fetch-sync/get-json-mid.js new file mode 100644 index 0000000..e6be086 --- /dev/null +++ b/test/fetch-sync/get-json-mid.js @@ -0,0 +1,3 @@ +export function getResult() { + return testGetJsonArray("https://jsonplaceholder.typicode.com/comments", 500); +} \ No newline at end of file diff --git a/test/fetch-sync/get-json-small-sync-repeated.js b/test/fetch-sync/get-json-small-sync-repeated.js new file mode 100644 index 0000000..1bbdc14 --- /dev/null +++ b/test/fetch-sync/get-json-small-sync-repeated.js @@ -0,0 +1,8 @@ +export function getResult() { + return testAndReturnOK(() => { + for (let i = 0; i < 100; i++) { + console.log(`repeat: ${i}`); + testGetJsonArray("https://jsonplaceholder.typicode.com/users", 10); + } + }); +} \ No newline at end of file diff --git a/test/fetch-sync/lib/lib.js b/test/fetch-sync/lib/lib.js index 7352ebe..0961b85 100644 --- a/test/fetch-sync/lib/lib.js +++ b/test/fetch-sync/lib/lib.js @@ -35,8 +35,7 @@ function testGetTextArray(url, length) { async function asyncGetJson(url) { let response = await fetch(url); - let json = response.json(); - return json; + return response.json(); } function syncGetJson(url) { @@ -45,8 +44,7 @@ function syncGetJson(url) { async function asyncGetText(url) { let response = await fetch(url); - let text = response.text(); - return text; + return response.text(); } function syncGetText(url) { @@ -72,11 +70,12 @@ function asyncToSync(promise) { let i = 0; - while (!done && i < 100) { + while (!done && i < 10000) { console.log('runEventLoop'); i += 1; runEventLoop(); } + console.log(`eventLoop count: ${i}`); if (!done) { let error = new Error('asyncToSync: illegal state: not done'); diff --git a/test/test.js b/test/test.js index 0f29974..1eaacaa 100644 --- a/test/test.js +++ b/test/test.js @@ -253,6 +253,9 @@ suite('WASI', () => { }); }); +const onlyFetchSyncCases = new Set([ + // "get-json-mid-sync-repeated.js", +]); const fetchSyncCases = await readdir(new URL('./fetch-sync', import.meta.url)); suite.only('Fetch-Sync', () => { const libSourcePromise = readFile( @@ -265,6 +268,11 @@ suite.only('Fetch-Sync', () => { if (!name.endsWith('.js')) { continue; } + + if (onlyFetchSyncCases.size > 0 && !onlyFetchSyncCases.has(name)) { + continue; + } + test(name, async () => { let libSource = await libSourcePromise; let source = await readFile( @@ -278,8 +286,7 @@ suite.only('Fetch-Sync', () => { const { component, imports } = await componentize(source, { sourceName: `${name}`, witPath: fileURLToPath(new URL('./wit', import.meta.url)), - worldName: 'test2', - enableStdout: true + worldName: 'test2' }); const map = { From f042888c056ebd938971da93b5769794e4e4fb01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Istv=C3=A1n=20B=C3=ADr=C3=B3?= Date: Wed, 12 Jun 2024 14:45:58 +0200 Subject: [PATCH 31/41] update StarlingMonkey, use runEventLoopUntilInterest() without loops --- StarlingMonkey | 2 +- test/fetch-sync/lib/lib.js | 9 +-------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/StarlingMonkey b/StarlingMonkey index c35f466..10047a3 160000 --- a/StarlingMonkey +++ b/StarlingMonkey @@ -1 +1 @@ -Subproject commit c35f4666da52759b9a2de991d45c46f0dffaa0b8 +Subproject commit 10047a3ade8fbc9de6c5b88a0fa77a3d68d152d0 diff --git a/test/fetch-sync/lib/lib.js b/test/fetch-sync/lib/lib.js index 0961b85..8245aaa 100644 --- a/test/fetch-sync/lib/lib.js +++ b/test/fetch-sync/lib/lib.js @@ -68,14 +68,7 @@ function asyncToSync(promise) { done = true; }); - - let i = 0; - while (!done && i < 10000) { - console.log('runEventLoop'); - i += 1; - runEventLoop(); - } - console.log(`eventLoop count: ${i}`); + runEventLoopUntilInterest(); if (!done) { let error = new Error('asyncToSync: illegal state: not done'); From f20a43c84d78e0cdb38e06e7319182dca0dcd47f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Istv=C3=A1n=20B=C3=ADr=C3=B3?= Date: Wed, 12 Jun 2024 15:17:51 +0200 Subject: [PATCH 32/41] added test case for patch call with body --- test/fetch-sync/lib/lib.js | 25 +++++++++++++++++++++++++ test/fetch-sync/patch-json-small.js | 7 +++++++ 2 files changed, 32 insertions(+) create mode 100644 test/fetch-sync/patch-json-small.js diff --git a/test/fetch-sync/lib/lib.js b/test/fetch-sync/lib/lib.js index 8245aaa..3d77613 100644 --- a/test/fetch-sync/lib/lib.js +++ b/test/fetch-sync/lib/lib.js @@ -23,6 +23,16 @@ function testGetJsonArray(url, length) { }); } +function testPatch(url, body) { + return testAndReturnOK(() => { + let result = syncPatchJSON(url, body); + for (let key of Object.keys(body)) { + assert(result[key] != null, `result[${key}] is not nullish`); + assert(result[key] == body[key], `result[${key}]: ${result[key]}, body[${key}]: ${body[key]}`); + } + }); +} + function testGetTextArray(url, length) { return testAndReturnOK(() => { let textResult = syncGetText(url); @@ -51,6 +61,21 @@ function syncGetText(url) { return asyncToSync(asyncGetText(url)); } +async function asyncPatchJson(url, body) { + let response = await fetch(url, { + method: 'POST', + headers: { + 'Content-type': 'application/json; charset=UTF-8' + }, + body: JSON.stringify(body) + }); + return response.json(); +} + +function syncPatchJSON(url, body) { + return asyncToSync(asyncPatchJson(url, body)); +} + function asyncToSync(promise) { let success = false; let done = false; diff --git a/test/fetch-sync/patch-json-small.js b/test/fetch-sync/patch-json-small.js new file mode 100644 index 0000000..6723f3c --- /dev/null +++ b/test/fetch-sync/patch-json-small.js @@ -0,0 +1,7 @@ +export function getResult() { + return testPatch('https://jsonplaceholder.typicode.com/posts', { + title: 'dummy-title', + body: 'dummy-body', + userId: 4 + }); +} \ No newline at end of file From 56391a40483d1538c95caf8ef56e60e21ec27b34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Istv=C3=A1n=20B=C3=ADr=C3=B3?= Date: Thu, 13 Jun 2024 21:39:27 +0200 Subject: [PATCH 33/41] update StarlingMonkey --- StarlingMonkey | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/StarlingMonkey b/StarlingMonkey index 10047a3..ef86be3 160000 --- a/StarlingMonkey +++ b/StarlingMonkey @@ -1 +1 @@ -Subproject commit 10047a3ade8fbc9de6c5b88a0fa77a3d68d152d0 +Subproject commit ef86be38a10a12402c544059ff64cbbfd559c4b2 From 775a58cb400bb286fa7cd2fe18cfb6b8d0488b43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Istv=C3=A1n=20B=C3=ADr=C3=B3?= Date: Thu, 13 Jun 2024 21:39:43 +0200 Subject: [PATCH 34/41] remove custom test filter --- test/test.js | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/test/test.js b/test/test.js index 1eaacaa..db50b49 100644 --- a/test/test.js +++ b/test/test.js @@ -253,11 +253,8 @@ suite('WASI', () => { }); }); -const onlyFetchSyncCases = new Set([ - // "get-json-mid-sync-repeated.js", -]); const fetchSyncCases = await readdir(new URL('./fetch-sync', import.meta.url)); -suite.only('Fetch-Sync', () => { +suite('Fetch-Sync', () => { const libSourcePromise = readFile( new URL(`./fetch-sync/lib/lib.js`, import.meta.url), 'utf8' @@ -269,10 +266,6 @@ suite.only('Fetch-Sync', () => { continue; } - if (onlyFetchSyncCases.size > 0 && !onlyFetchSyncCases.has(name)) { - continue; - } - test(name, async () => { let libSource = await libSourcePromise; let source = await readFile( From 25ae60c2690d8ea633694084640df23001b79e7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Istv=C3=A1n=20B=C3=ADr=C3=B3?= Date: Thu, 13 Jun 2024 21:40:25 +0200 Subject: [PATCH 35/41] cleanups / patch text tests --- test/fetch-sync/get-json-mid-sync-repeated.js | 2 +- .../get-json-small-sync-repeated.js | 2 +- test/fetch-sync/lib/lib.js | 46 +++++++++++++++---- test/fetch-sync/patch-json-small.js | 4 +- test/fetch-sync/patch-text-small.js | 7 +++ 5 files changed, 47 insertions(+), 14 deletions(-) create mode 100644 test/fetch-sync/patch-text-small.js diff --git a/test/fetch-sync/get-json-mid-sync-repeated.js b/test/fetch-sync/get-json-mid-sync-repeated.js index 3309ead..36137c5 100644 --- a/test/fetch-sync/get-json-mid-sync-repeated.js +++ b/test/fetch-sync/get-json-mid-sync-repeated.js @@ -1,7 +1,7 @@ export function getResult() { return testAndReturnOK(() => { for (let i = 0; i < 100; i++) { - console.log(`repeat: ${i}`); + // console.log(`repeat: ${i}`); testGetJsonArray("https://jsonplaceholder.typicode.com/comments", 500); } }); diff --git a/test/fetch-sync/get-json-small-sync-repeated.js b/test/fetch-sync/get-json-small-sync-repeated.js index 1bbdc14..4245507 100644 --- a/test/fetch-sync/get-json-small-sync-repeated.js +++ b/test/fetch-sync/get-json-small-sync-repeated.js @@ -1,7 +1,7 @@ export function getResult() { return testAndReturnOK(() => { for (let i = 0; i < 100; i++) { - console.log(`repeat: ${i}`); + // console.log(`repeat: ${i}`); testGetJsonArray("https://jsonplaceholder.typicode.com/users", 10); } }); diff --git a/test/fetch-sync/lib/lib.js b/test/fetch-sync/lib/lib.js index 3d77613..301b219 100644 --- a/test/fetch-sync/lib/lib.js +++ b/test/fetch-sync/lib/lib.js @@ -19,27 +19,38 @@ function testGetJsonArray(url, length) { let result = syncGetJson(url); assert(result != null, 'result is not nullish'); assert(result['length'] === length, `length == ${length}`); - console.log(`result json size: ${JSON.stringify(result).length}`); + // console.log(`result json size: ${JSON.stringify(result).length}`); }); } -function testPatch(url, body) { +function testGetTextArray(url, length) { + return testAndReturnOK(() => { + let textResult = syncGetText(url); + let result = JSON.parse(textResult); + assert(result != null, 'result is not nullish'); + assert(result['length'] === length, `length == ${length}`); + // console.log(`result text size: ${result.length}`); + }); +} + +function testPatchJson(url, body) { return testAndReturnOK(() => { - let result = syncPatchJSON(url, body); + let result = syncPatchJson(url, body); for (let key of Object.keys(body)) { assert(result[key] != null, `result[${key}] is not nullish`); - assert(result[key] == body[key], `result[${key}]: ${result[key]}, body[${key}]: ${body[key]}`); + assert(result[key] === body[key], `result[${key}]: ${result[key]}, body[${key}]: ${body[key]}`); } }); } -function testGetTextArray(url, length) { +function testPatchText(url, body) { return testAndReturnOK(() => { - let textResult = syncGetText(url); + let textResult = syncPatchText(url, body); let result = JSON.parse(textResult); - assert(result != null, 'result is not nullish'); - assert(result['length'] === length, `length == ${length}`); - console.log(`result text size: ${result.length}`); + for (let key of Object.keys(body)) { + assert(result[key] != null, `result[${key}] is not nullish`); + assert(result[key] === body[key], `result[${key}]: ${result[key]}, body[${key}]: ${body[key]}`); + } }); } @@ -72,10 +83,25 @@ async function asyncPatchJson(url, body) { return response.json(); } -function syncPatchJSON(url, body) { +function syncPatchJson(url, body) { return asyncToSync(asyncPatchJson(url, body)); } +async function asyncPatchText(url, body) { + let response = await fetch(url, { + method: 'POST', + headers: { + 'Content-type': 'application/json; charset=UTF-8' + }, + body: JSON.stringify(body) + }); + return response.text(); +} + +function syncPatchText(url, body) { + return asyncToSync(asyncPatchText(url, body)); +} + function asyncToSync(promise) { let success = false; let done = false; diff --git a/test/fetch-sync/patch-json-small.js b/test/fetch-sync/patch-json-small.js index 6723f3c..df4d8d0 100644 --- a/test/fetch-sync/patch-json-small.js +++ b/test/fetch-sync/patch-json-small.js @@ -1,6 +1,6 @@ export function getResult() { - return testPatch('https://jsonplaceholder.typicode.com/posts', { - title: 'dummy-title', + return testPatchJson('https://jsonplaceholder.typicode.com/posts', { + title: 'dummy-title ŰÁÉŐÚŐ', body: 'dummy-body', userId: 4 }); diff --git a/test/fetch-sync/patch-text-small.js b/test/fetch-sync/patch-text-small.js new file mode 100644 index 0000000..deff8fa --- /dev/null +++ b/test/fetch-sync/patch-text-small.js @@ -0,0 +1,7 @@ +export function getResult() { + return testPatchText('https://jsonplaceholder.typicode.com/posts', { + title: 'dummy-title ŰÁÉŐÚŐ', + body: 'dummy-body', + userId: 4 + }); +} \ No newline at end of file From 16a79da715ddeea5977a387007769935418505a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Istv=C3=A1n=20B=C3=ADr=C3=B3?= Date: Thu, 13 Jun 2024 21:54:21 +0200 Subject: [PATCH 36/41] update globals test --- test/builtins/globals.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/builtins/globals.js b/test/builtins/globals.js index 9395b8c..3ffaf8d 100644 --- a/test/builtins/globals.js +++ b/test/builtins/globals.js @@ -13,7 +13,7 @@ export async function test(run) { const { stdout, stderr } = await run(); strictEqual( stdout, - `["undefined", "Function", "Object", "eval", "globalThis", "Array", "Boolean", "JSON", "Date", "Math", "isNaN", "isFinite", "parseInt", "parseFloat", "NaN", "Infinity", "Number", "escape", "unescape", "decodeURI", "encodeURI", "decodeURIComponent", "encodeURIComponent", "String", "RegExp", "Error", "InternalError", "AggregateError", "EvalError", "RangeError", "ReferenceError", "SyntaxError", "TypeError", "URIError", "ArrayBuffer", "Int8Array", "Uint8Array", "Int16Array", "Uint16Array", "Int32Array", "Uint32Array", "Float32Array", "Float64Array", "Uint8ClampedArray", "BigInt64Array", "BigUint64Array", "BigInt", "Proxy", "WeakMap", "Map", "Set", "DataView", "Symbol", "Reflect", "WeakSet", "Promise", "FinalizationRegistry", "WeakRef", "ReadableStream", "ReadableStreamBYOBReader", "ReadableStreamBYOBRequest", "ReadableStreamDefaultReader", "ReadableStreamDefaultController", "ReadableByteStreamController", "WritableStream", "ByteLengthQueuingStrategy", "CountQueuingStrategy", "self", "queueMicrotask", "structuredClone", "atob", "btoa", "DOMException", "URL", "URLSearchParams", "console", "Performance", "performance", "setInterval", "setTimeout", "clearInterval", "clearTimeout", "WorkerLocation", "location", "TextEncoder", "TextDecoder", "TransformStream", "CompressionStream", "DecompressionStream", "fetch", "Request", "Response", "Headers", "addEventListener", "SubtleCrypto", "Crypto", "crypto", "CryptoKey"]\n` + `["undefined", "Function", "Object", "eval", "globalThis", "Array", "Boolean", "JSON", "Date", "Math", "isNaN", "isFinite", "parseInt", "parseFloat", "NaN", "Infinity", "Number", "escape", "unescape", "decodeURI", "encodeURI", "decodeURIComponent", "encodeURIComponent", "String", "RegExp", "Error", "InternalError", "AggregateError", "EvalError", "RangeError", "ReferenceError", "SyntaxError", "TypeError", "URIError", "ArrayBuffer", "Int8Array", "Uint8Array", "Int16Array", "Uint16Array", "Int32Array", "Uint32Array", "Float32Array", "Float64Array", "Uint8ClampedArray", "BigInt64Array", "BigUint64Array", "BigInt", "Proxy", "WeakMap", "Map", "Set", "DataView", "Symbol", "Reflect", "WeakSet", "Promise", "FinalizationRegistry", "WeakRef", "ReadableStream", "ReadableStreamBYOBReader", "ReadableStreamBYOBRequest", "ReadableStreamDefaultReader", "ReadableStreamDefaultController", "ReadableByteStreamController", "WritableStream", "ByteLengthQueuingStrategy", "CountQueuingStrategy", "self", "queueMicrotask", "structuredClone", "atob", "btoa", "DOMException", "URL", "URLSearchParams", "console", "Performance", "performance", "setInterval", "setTimeout", "clearInterval", "clearTimeout", "WorkerLocation", "location", "TextEncoder", "TextDecoder", "TransformStream", "CompressionStream", "DecompressionStream", "fetch", "runEventLoopUntilInterest", "Request", "Response", "Headers", "addEventListener", "SubtleCrypto", "Crypto", "crypto", "CryptoKey"]\n` ); strictEqual(stderr, ''); } From 4a783bb044aa2c52bc92191585ad2c6f21c594e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Istv=C3=A1n=20B=C3=ADr=C3=B3?= Date: Thu, 13 Jun 2024 23:25:51 +0200 Subject: [PATCH 37/41] add fetch-sync tests for array buffer / text --- test/fetch-sync/get-array-buffer-big.js | 3 ++ test/fetch-sync/get-array-buffer-mid.js | 3 ++ test/fetch-sync/get-array-buffer-small.js | 3 ++ .../get-json-small-async-repeated.js | 30 +++++++++++++++++++ test/fetch-sync/get-text-google.js | 7 +++++ test/fetch-sync/lib/lib.js | 24 +++++++++++++-- 6 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 test/fetch-sync/get-array-buffer-big.js create mode 100644 test/fetch-sync/get-array-buffer-mid.js create mode 100644 test/fetch-sync/get-array-buffer-small.js create mode 100644 test/fetch-sync/get-json-small-async-repeated.js create mode 100644 test/fetch-sync/get-text-google.js diff --git a/test/fetch-sync/get-array-buffer-big.js b/test/fetch-sync/get-array-buffer-big.js new file mode 100644 index 0000000..3213110 --- /dev/null +++ b/test/fetch-sync/get-array-buffer-big.js @@ -0,0 +1,3 @@ +export function getResult() { + return testGetArrayBufferArray('https://jsonplaceholder.typicode.com/photos', 5000); +} \ No newline at end of file diff --git a/test/fetch-sync/get-array-buffer-mid.js b/test/fetch-sync/get-array-buffer-mid.js new file mode 100644 index 0000000..f215072 --- /dev/null +++ b/test/fetch-sync/get-array-buffer-mid.js @@ -0,0 +1,3 @@ +export function getResult() { + return testGetArrayBufferArray("https://jsonplaceholder.typicode.com/comments", 500); +} \ No newline at end of file diff --git a/test/fetch-sync/get-array-buffer-small.js b/test/fetch-sync/get-array-buffer-small.js new file mode 100644 index 0000000..3d8ee23 --- /dev/null +++ b/test/fetch-sync/get-array-buffer-small.js @@ -0,0 +1,3 @@ +export function getResult() { + return testGetArrayBufferArray("https://jsonplaceholder.typicode.com/users", 10); +} \ No newline at end of file diff --git a/test/fetch-sync/get-json-small-async-repeated.js b/test/fetch-sync/get-json-small-async-repeated.js new file mode 100644 index 0000000..ffa3c7f --- /dev/null +++ b/test/fetch-sync/get-json-small-async-repeated.js @@ -0,0 +1,30 @@ +export function getResult() { + return testAndReturnOK(() => { + let count = 20; + let doneCounter = 0; + + function getAndAssert() { + return asyncGetJson('https://jsonplaceholder.typicode.com/users/1') + .then((result) => { + console.log(JSON.stringify(result, null, ' ')); + assert(result != null, 'result is not nullish'); + doneCounter++; + }); + } + + let result = null; + + for (let i = 0; i < count; i++) { + if (result == null) { + result = getAndAssert(); + } else { + result = result.then(() => { + return getAndAssert(); + }); + } + } + + asyncToSync(result); + assert(doneCounter === count, 'doneCounter === count'); + }); +} \ No newline at end of file diff --git a/test/fetch-sync/get-text-google.js b/test/fetch-sync/get-text-google.js new file mode 100644 index 0000000..c8d37b3 --- /dev/null +++ b/test/fetch-sync/get-text-google.js @@ -0,0 +1,7 @@ +export function getResult() { + return testAndReturnOK(() => { + let text = syncGetText("https://google.com"); + // console.log(text); + assert(text.includes("google"), "includes google"); + }); +} \ No newline at end of file diff --git a/test/fetch-sync/lib/lib.js b/test/fetch-sync/lib/lib.js index 301b219..1d11b22 100644 --- a/test/fetch-sync/lib/lib.js +++ b/test/fetch-sync/lib/lib.js @@ -9,7 +9,7 @@ function testAndReturnOK(f) { f(); } catch (e) { console.error(e); - return e.toString(); + return "nok: " + e.toString(); } return 'ok'; } @@ -29,7 +29,18 @@ function testGetTextArray(url, length) { let result = JSON.parse(textResult); assert(result != null, 'result is not nullish'); assert(result['length'] === length, `length == ${length}`); - // console.log(`result text size: ${result.length}`); + // console.log(`result text size: ${textResult.length}`); + }); +} + +function testGetArrayBufferArray(url, length) { + return testAndReturnOK(() => { + let arrayBufferResult = syncGetArrayBuffer(url); + let decoder = new TextDecoder(); + let result = JSON.parse(decoder.decode(arrayBufferResult)); + assert(result != null, 'result is not nullish'); + assert(result['length'] === length, `length == ${length}`); + // console.log(`result bytes count: ${arrayBufferResult.length}`); }); } @@ -72,6 +83,15 @@ function syncGetText(url) { return asyncToSync(asyncGetText(url)); } +async function asyncGetArrayBuffer(url) { + let response = await fetch(url); + return response.arrayBuffer(); +} + +function syncGetArrayBuffer(url) { + return asyncToSync(asyncGetArrayBuffer(url)); +} + async function asyncPatchJson(url, body) { let response = await fetch(url, { method: 'POST', From 4c5e19266aeff546ecaf4667c3ba29c557ac6d83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Istv=C3=A1n=20B=C3=ADr=C3=B3?= Date: Thu, 13 Jun 2024 23:30:37 +0200 Subject: [PATCH 38/41] cleanup --- test/fetch-sync/get-json-small-async-repeated.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fetch-sync/get-json-small-async-repeated.js b/test/fetch-sync/get-json-small-async-repeated.js index ffa3c7f..a53f108 100644 --- a/test/fetch-sync/get-json-small-async-repeated.js +++ b/test/fetch-sync/get-json-small-async-repeated.js @@ -6,7 +6,7 @@ export function getResult() { function getAndAssert() { return asyncGetJson('https://jsonplaceholder.typicode.com/users/1') .then((result) => { - console.log(JSON.stringify(result, null, ' ')); + // console.log(JSON.stringify(result, null, ' ')); assert(result != null, 'result is not nullish'); doneCounter++; }); From 9741f63d2ca94fc72aafb1d159c1995777e74b9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Istv=C3=A1n=20B=C3=ADr=C3=B3?= Date: Thu, 13 Jun 2024 23:48:25 +0200 Subject: [PATCH 39/41] change package json for golem npm publish --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 384fcce..10ea503 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { - "name": "@bytecodealliance/componentize-js", - "version": "0.8.3", - "homepage": "https://github.com/bytecodealliance/componentize-js#readme", + "name": "@golemcloud/componentize-js", + "version": "0.8.3-golem.1", + "homepage": "https://github.com/golemcloud/ComponentizeJS", "type": "module", "exports": "./src/componentize.js", "devDependencies": { From cdfca05e15ee73814a93505b0e942c6426f59899 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Istv=C3=A1n=20B=C3=ADr=C3=B3?= Date: Fri, 14 Jun 2024 08:23:19 +0200 Subject: [PATCH 40/41] use golem fork jco --- Makefile | 2 +- package-lock.json | 75 +++++++++++++++++++++++---------------------- package.json | 2 +- src/componentize.js | 2 +- test/test.js | 4 +-- 5 files changed, 44 insertions(+), 41 deletions(-) diff --git a/Makefile b/Makefile index ad850d6..a448837 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ JCO ?= ./node_modules/.bin/jco ifndef JCO - JCO = $(error No jco in PATH. Run npm install -g @bytecodealliance/jco) + JCO = $(error No jco in PATH. Run npm install -g @golemcloud/jco) endif # ifndef WASM_OPT diff --git a/package-lock.json b/package-lock.json index bb8836f..c443d88 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,18 +1,18 @@ { - "name": "@bytecodealliance/componentize-js", - "version": "0.8.3", + "name": "@golemcloud/componentize-js", + "version": "0.8.3-golem.1", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "@bytecodealliance/componentize-js", - "version": "0.8.3", + "name": "@golemcloud/componentize-js", + "version": "0.8.3-golem.1", "workspaces": [ "." ], "dependencies": { - "@bytecodealliance/jco": "1.1.1", "@bytecodealliance/wizer": "^3.0.1", + "@golemcloud/jco": "1.2.4-golem.2", "es-module-lexer": "^1.4.1" }, "devDependencies": { @@ -20,31 +20,10 @@ "mocha": "^10.2.0" } }, - "node_modules/@bytecodealliance/componentize-js": { - "resolved": "", - "link": true - }, - "node_modules/@bytecodealliance/jco": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/@bytecodealliance/jco/-/jco-1.1.1.tgz", - "integrity": "sha512-s8Zz6GFPlo2g+dsGp1OMIWXSZnM4FyIloxNAc4grF5TZwFoD00Gj8b0xvpmFSeZj36X/bJPa7x3za3j7Cfeetw==", - "dependencies": { - "@bytecodealliance/preview2-shim": "^0.16.1", - "binaryen": "^116.0.0", - "chalk-template": "^1", - "commander": "^12", - "mkdirp": "^3", - "ora": "^8", - "terser": "^5" - }, - "bin": { - "jco": "src/jco.js" - } - }, "node_modules/@bytecodealliance/preview2-shim": { - "version": "0.16.1", - "resolved": "https://registry.npmjs.org/@bytecodealliance/preview2-shim/-/preview2-shim-0.16.1.tgz", - "integrity": "sha512-KEzFY1/fSBF0cpUNbG9MdnPNc0gxinBm42HRA9+ENfsticSDjE845bh7Mun0UDD7ga/uWX061qZsfpBXUGEAfg==" + "version": "0.16.2", + "resolved": "https://registry.npmjs.org/@bytecodealliance/preview2-shim/-/preview2-shim-0.16.2.tgz", + "integrity": "sha512-36MwesmbLSf3Y5/OHcS85iBaF0N92CQ4gpjtDVKSbrjxmrBKCWlWVfoQ03F/cqDg8k5K7pzVaVBH0XBIbTCfTQ==" }, "node_modules/@bytecodealliance/wizer": { "version": "3.0.1", @@ -155,6 +134,30 @@ "wizer-win32-x64": "wizer" } }, + "node_modules/@golemcloud/componentize-js": { + "resolved": "", + "link": true + }, + "node_modules/@golemcloud/jco": { + "version": "1.2.4-golem.2", + "resolved": "https://registry.npmjs.org/@golemcloud/jco/-/jco-1.2.4-golem.2.tgz", + "integrity": "sha512-Q49XQLNlqF6ei+I3hJZQDIt14ulvrIqbzcO40LpwusSqwMNd0t+oLOXKWO9NIt22LtapGRZ69IyVodjaKzPUrQ==", + "workspaces": [ + "packages/preview2-shim" + ], + "dependencies": { + "@bytecodealliance/preview2-shim": "^0.16.2", + "binaryen": "^116.0.0", + "chalk-template": "^1", + "commander": "^12", + "mkdirp": "^3", + "ora": "^8", + "terser": "^5" + }, + "bin": { + "jco": "src/jco.js" + } + }, "node_modules/@jridgewell/gen-mapping": { "version": "0.3.5", "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.5.tgz", @@ -309,12 +312,12 @@ } }, "node_modules/braces": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", - "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", "dev": true, "dependencies": { - "fill-range": "^7.0.1" + "fill-range": "^7.1.1" }, "engines": { "node": ">=8" @@ -574,9 +577,9 @@ } }, "node_modules/fill-range": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", - "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", "dev": true, "dependencies": { "to-regex-range": "^5.0.1" diff --git a/package.json b/package.json index 10ea503..0bce3ba 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "mocha": "^10.2.0" }, "dependencies": { - "@bytecodealliance/jco": "1.1.1", + "@golemcloud/jco": "1.2.4-golem.2", "@bytecodealliance/wizer": "^3.0.1", "es-module-lexer": "^1.4.1" }, diff --git a/src/componentize.js b/src/componentize.js index 63b1177..2cece34 100644 --- a/src/componentize.js +++ b/src/componentize.js @@ -3,7 +3,7 @@ import { componentNew, metadataAdd, preview1AdapterReactorPath, -} from '@bytecodealliance/jco'; +} from '@golemcloud/jco'; import { spawnSync } from 'node:child_process'; import { tmpdir } from 'node:os'; import { resolve, join } from 'node:path'; diff --git a/test/test.js b/test/test.js index db50b49..6b885af 100644 --- a/test/test.js +++ b/test/test.js @@ -1,5 +1,5 @@ -import { componentize } from '@bytecodealliance/componentize-js'; -import { transpile } from '@bytecodealliance/jco'; +import { componentize } from '@golemcloud/componentize-js'; +import { transpile } from '@golemcloud/jco'; import { readFile, readdir, mkdir, writeFile } from 'node:fs/promises'; import { spawn } from 'node:child_process'; import { fileURLToPath } from 'node:url'; From 75435d373ced1bc663fb1b98d4ff02e30b43fb8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Istv=C3=A1n=20B=C3=ADr=C3=B3?= Date: Fri, 14 Jun 2024 08:39:59 +0200 Subject: [PATCH 41/41] bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0bce3ba..2f967d5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@golemcloud/componentize-js", - "version": "0.8.3-golem.1", + "version": "0.8.3-golem.2", "homepage": "https://github.com/golemcloud/ComponentizeJS", "type": "module", "exports": "./src/componentize.js",