diff --git a/Makefile b/Makefile index eeeb3737..f50eb9df 100644 --- a/Makefile +++ b/Makefile @@ -57,7 +57,7 @@ lib/spidermonkey_embedding.wasm: $(OBJS) | $(SM_SRC) make --makefile=$(JSCR_SRC)/Makefile -I $(JSCR_SRC) -j16 make --makefile=$(JSCR_SRC)/Makefile -I $(JSCR_SRC) $(abspath $(JSCR_SRC)/build/release/shared.a) -j16 PATH="$(FSM_SRC)/scripts:$$PATH" $(WASI_CXX) $(CXX_FLAGS) $(CXX_OPT) $(DEFINES) $(LD_FLAGS) -o $@ $^ deps/js-compute-runtime/runtime/js-compute-runtime/build/release/*.a $(wildcard $(SM_SRC)/lib/*.a) $(wildcard $(SM_SRC)/lib/*.o) - $(WASM_OPT) --strip-debug $@ -o $@ -O3 + # $(WASM_OPT) --strip-debug $@ -o $@ -O3 obj/%.o: spidermonkey_embedding/%.cpp Makefile | $(SM_SRC) obj obj/builtins $(WASI_CXX) $(CXX_FLAGS) -O2 $(DEFINES) $(INCLUDES) -I $(SM_SRC)/include -MMD -MP -c -o $@ $< diff --git a/crates/spidermonkey-embedding-splicer/src/bindgen.rs b/crates/spidermonkey-embedding-splicer/src/bindgen.rs index d408b124..9f7585b1 100644 --- a/crates/spidermonkey-embedding-splicer/src/bindgen.rs +++ b/crates/spidermonkey-embedding-splicer/src/bindgen.rs @@ -365,7 +365,7 @@ pub fn componentize_bindgen(resolve: &Resolve, id: WorldId, name: &str) -> Compo output.push_str(&bindgen.src); Componentization { - js_bindings: output.to_string(), + js_bindings: output.to_string().replace("const ret = exportsHello();", "console.log('calling hello'); const ret = exportsHello(); console.log('called hello');"), exports: bindgen.exports, imports: bindgen.imports, import_wrappers, diff --git a/crates/spidermonkey-embedding-splicer/src/splice.rs b/crates/spidermonkey-embedding-splicer/src/splice.rs index c5ef6ae2..27ee2f26 100644 --- a/crates/spidermonkey-embedding-splicer/src/splice.rs +++ b/crates/spidermonkey-embedding-splicer/src/splice.rs @@ -669,6 +669,7 @@ fn synthesize_export_functions( } let fid = func.finish(args, &mut module.funcs); + module.funcs.get_mut(fid).name = Some("EXPORT".into()); module.exports.add(&expt_name, ExportItem::Function(fid)); } diff --git a/spidermonkey_embedding/spidermonkey_embedding.cpp b/spidermonkey_embedding/spidermonkey_embedding.cpp index cf72b3d3..bab62239 100644 --- a/spidermonkey_embedding/spidermonkey_embedding.cpp +++ b/spidermonkey_embedding/spidermonkey_embedding.cpp @@ -17,7 +17,7 @@ void builtin_impl_console_log(Console::LogType log_ty, const char *msg) fflush(stdio); } -static bool DEBUG = false; +static bool DEBUG = true; void log(const char *msg) { @@ -256,6 +256,7 @@ __attribute__((export_name("cabi_realloc_adapter"))) void *cabi_realloc_adapter( __attribute__((export_name("cabi_realloc"))) void *cabi_realloc(void *ptr, size_t orig_size, size_t org_align, size_t new_size) { + log("(cabi_realloc) Calling realloc"); void *ret = JS_realloc(R.cx, ptr, orig_size, new_size); // track all allocations during a function "call" for freeing R.free_list.push_back(ret); @@ -983,7 +984,7 @@ __attribute__((export_name("post_call"))) void post_call(uint32_t fn_idx) cabi_free(ptr); } R.free_list.clear(); - js::RunJobs(R.cx); - JS_MaybeGC(R.cx); + // js::RunJobs(R.cx); + // JS_MaybeGC(R.cx); log("(post_call) end"); } diff --git a/src/componentize.js b/src/componentize.js index 5abc5dab..be760e70 100644 --- a/src/componentize.js +++ b/src/componentize.js @@ -20,7 +20,7 @@ export async function componentize( witWorld = opts?.witWorld; } const { - debug = false, + debug = true, sourceName = "source.js", engine = fileURLToPath( new URL('../lib/spidermonkey_embedding.wasm', import.meta.url) diff --git a/test/cases/repeated-calls/source.js b/test/cases/repeated-calls/source.js new file mode 100644 index 00000000..eb3b3f01 --- /dev/null +++ b/test/cases/repeated-calls/source.js @@ -0,0 +1,5 @@ +export const exports = { + hello() { + return "hello"; + } +}; diff --git a/test/cases/repeated-calls/test.js b/test/cases/repeated-calls/test.js new file mode 100644 index 00000000..09f55da1 --- /dev/null +++ b/test/cases/repeated-calls/test.js @@ -0,0 +1,12 @@ +import { strictEqual } from 'node:assert'; + +export function test (instance) { + for (let i = 0; i < 2000; i++) { + try { + strictEqual(instance.exports.hello(), "hello"); + } catch (error) { + error.message = `failed on attempt [${i}]: ` + error.message + throw error; + } + } +} diff --git a/test/cases/repeated-calls/world.wit b/test/cases/repeated-calls/world.wit new file mode 100644 index 00000000..affb2066 --- /dev/null +++ b/test/cases/repeated-calls/world.wit @@ -0,0 +1,7 @@ +package local:hello; + +world hello { + export exports: interface { + hello: func() -> string; + } +}