Skip to content

Commit

Permalink
deps: update to latest starlingmonkey (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford authored Jun 28, 2024
1 parent 544b4ed commit ca43536
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 113 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion StarlingMonkey
Submodule StarlingMonkey updated 70 files
+47 −0 .github/workflows/main.yml
+5 −0 .gitignore
+4 −2 CMakeLists.txt
+49 −0 CODE_OF_CONDUCT.md
+25 −7 README.md
+2 −1 builtins/web/base64.cpp
+9 −5 builtins/web/console.cpp
+227 −6 builtins/web/crypto/crypto-algorithm.cpp
+3 −2 builtins/web/crypto/crypto-key.cpp
+0 −5 builtins/web/fetch/fetch-api.cpp
+15 −9 builtins/web/fetch/fetch_event.cpp
+22 −14 builtins/web/fetch/request-response.cpp
+7 −1 builtins/web/performance.cpp
+0 −11 builtins/web/streams/native-stream-source.cpp
+1 −2 builtins/web/streams/transform-stream.cpp
+3 −1 builtins/web/text-codec/text-encoder.cpp
+0 −3 builtins/web/timers.cpp
+77 −2 cmake/add_builtin.cmake
+0 −3 cmake/build-crates.cmake
+67 −40 cmake/builtins.cmake
+2 −2 cmake/openssl.cmake
+2 −2 cmake/spidermonkey.cmake
+1 −1 cmake/wasmtime.cmake
+5 −2 componentize.sh
+0 −1 crates/rust-encoding/.gitignore
+0 −34 crates/rust-encoding/Cargo.lock
+0 −17 crates/rust-encoding/Cargo.toml
+0 −54 crates/rust-encoding/cbindgen.toml
+0 −1 crates/rust-encoding/src/lib.rs
+3 −0 deps/include/rust-encoding.h
+0 −5 host-apis/wasi-0.2.0-rc-2023-10-18/host_api.cpp
+0 −5 host-apis/wasi-0.2.0-rc-2023-12-05/host_api.cpp
+0 −5 host-apis/wasi-0.2.0/host_api.cpp
+46 −8 include/extension-api.h
+1 −1 include/host_api.h
+0 −1 runtime/encode.h
+30 −13 runtime/engine.cpp
+48 −27 runtime/event_loop.cpp
+11 −8 runtime/event_loop.h
+6 −11 runtime/js.cpp
+236 −25 runtime/script_loader.cpp
+2 −1 runtime/script_loader.h
+1 −1 rust-toolchain.toml
+46 −0 tests/e2e/smoke/expect_serve_body.txt
+0 −0 tests/e2e/smoke/expect_serve_stderr.txt
+2 −0 tests/e2e/smoke/expect_serve_stdout.txt
+0 −0 tests/e2e/smoke/nested-smoke-dependency.js
+1 −1 tests/e2e/smoke/smoke-dependency.js
+1 −1 tests/e2e/smoke/smoke.js
+0 −0 tests/e2e/syntax-err/expect_wizer_fail
+1 −0 tests/e2e/syntax-err/expect_wizer_stderr.txt
+1 −0 tests/e2e/syntax-err/syntax-err.js
+0 −0 tests/e2e/tla-err/expect_wizer_fail
+1 −0 tests/e2e/tla-err/expect_wizer_stderr.txt
+6 −0 tests/e2e/tla-err/tla-err.js
+1 −0 tests/e2e/tla-runtime-resolve/expect_serve_body.txt
+1 −0 tests/e2e/tla-runtime-resolve/expect_serve_stdout.txt
+18 −0 tests/e2e/tla-runtime-resolve/tla-runtime-resolve.js
+1 −0 tests/e2e/tla/expect_serve_body.txt
+10 −0 tests/e2e/tla/tla.js
+90 −0 tests/integration/assert.js
+378 −0 tests/integration/btoa/btoa.js
+2,028 −0 tests/integration/crypto/crypto.js
+4 −0 tests/integration/handlers.js
+282 −0 tests/integration/performance/performance.js
+72 −0 tests/integration/test-server.js
+285 −0 tests/integration/tests/performance.js
+586 −0 tests/integration/timers/timers.js
+128 −0 tests/test.sh
+41 −0 tests/tests.cmake
88 changes: 25 additions & 63 deletions crates/spidermonkey-embedding-splicer/src/splice.rs
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -39,10 +34,7 @@ pub fn splice(
exports: Vec<(String, CoreFn)>,
debug: bool,
) -> Result<Vec<u8>> {
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,
Expand Down Expand Up @@ -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)?;
Expand All @@ -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<i32>)>,
debug: bool,
) -> Result<()> {
let mut coreabi_get_import: Option<ExportId> = None;
let mut cabi_realloc: Option<ExportId> = None;
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down
7 changes: 3 additions & 4 deletions embedding/embedding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,23 @@ 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;
}

__attribute__((export_name("coreabi_sample_f32"))) bool CoreAbiSampleF32(JSContext *cx, unsigned argc, JS::Value *vp)
{
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
float arg2 = static_cast<float>(args[2].toDouble());
args.rval().setDouble(arg2);
args.rval().setDouble(arg2 * 32771);
return true;
}

__attribute__((export_name("coreabi_sample_f64"))) bool CoreAbiSampleF64(JSContext *cx, unsigned argc, JS::Value *vp)
{
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
double arg3 = args[3].toDouble();
args.rval().setDouble(arg3);
args.rval().setDouble(arg3 * 32771);
return true;
}

Expand Down Expand Up @@ -274,7 +274,6 @@ extern "C"
}
Runtime.free_list.clear();
RootedValue result(Runtime.cx);
Runtime.engine->run_event_loop(&result);
LOG("(post_call) end");
}

Expand Down
17 changes: 1 addition & 16 deletions src/componentize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
6 changes: 5 additions & 1 deletion test/builtins/console-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, '');
}
2 changes: 1 addition & 1 deletion test/builtins/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, '');
}
22 changes: 0 additions & 22 deletions test/builtins/timeout.js

This file was deleted.

0 comments on commit ca43536

Please sign in to comment.