From ca435360195b2cfffcd08df4ceb370db0877bc21 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Fri, 28 Jun 2024 17:25:12 +0200 Subject: [PATCH] deps: update to latest starlingmonkey (#111) --- .github/workflows/main.yml | 8 +- StarlingMonkey | 2 +- .../src/splice.rs | 88 ++++++------------- embedding/embedding.cpp | 7 +- src/componentize.js | 17 +--- test/builtins/console-object.js | 6 +- test/builtins/globals.js | 2 +- test/builtins/timeout.js | 22 ----- 8 files changed, 39 insertions(+), 113 deletions(-) delete mode 100644 test/builtins/timeout.js diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 50c022a..20f34b4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -28,12 +28,10 @@ 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 1.77.1 + rustup target add wasm32-wasi --toolchain 1.77.1 - uses: actions/setup-node@v2 with: diff --git a/StarlingMonkey b/StarlingMonkey index c1d7439..aa9ff14 160000 --- a/StarlingMonkey +++ b/StarlingMonkey @@ -1 +1 @@ -Subproject commit c1d7439a3412496db0c5d4004d723396cc46a892 +Subproject commit aa9ff14cd0696877a402435faaf8db486ce0ff89 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 0c0ca59..d4c6688 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; } @@ -274,7 +274,6 @@ extern "C" } Runtime.free_list.clear(); RootedValue result(Runtime.cx); - Runtime.engine->run_event_loop(&result); LOG("(post_call) end"); } 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/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 deleted file mode 100644 index 1f1429a..0000000 --- a/test/builtins/timeout.js +++ /dev/null @@ -1,22 +0,0 @@ -import { strictEqual, ok } from 'node:assert'; - -export const source = ` - let done = false; - export function run () { - console.log(Date.now()); - setTimeout(() => { - console.log(Date.now()); - done = true; - }, 100); - } - export function ready () { - return done; - } -`; - -export async function test(run) { - const { stdout, stderr } = await run(); - const [timestart, timeend] = stdout.split('\n'); - strictEqual(stderr, ''); - ok(Number(timeend) - Number(timestart) >= 100); -}