Skip to content

Commit dc38ad3

Browse files
committed
Fix name mangling issues in optimized build
1 parent 5102327 commit dc38ad3

File tree

6 files changed

+98
-6402
lines changed

6 files changed

+98
-6402
lines changed

c/interface.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -520,16 +520,19 @@ int QTS_BuildIsAsyncify() {
520520

521521
// ----------------------------------------------------------------------------
522522
// C -> Host Callbacks
523+
// Note: inside EM_JS, we need to use ['...'] subscript syntax for accessing JS
524+
// objects, because in optimized builds, Closure compiler will mangle all the
525+
// names.
523526

524527
// -------------------
525528
// function: C -> Host
526529
EM_JS(MaybeAsync(JSValue *), qts_host_call_function, (JSContext * ctx, JSValueConst *this_ptr, int argc, JSValueConst *argv, int magic_func_id), {
527530
#ifdef QTS_ASYNCIFY
528-
const asyncify = Asyncify;
531+
const asyncify = {['handleSleep'] : Asyncify.handleSleep};
529532
#else
530533
const asyncify = undefined;
531534
#endif
532-
return Module.callbacks.callFunction(asyncify, ctx, this_ptr, argc, argv, magic_func_id);
535+
return Module['callbacks']['callFunction'](asyncify, ctx, this_ptr, argc, argv, magic_func_id);
533536
});
534537

535538
// Function: QuickJS -> C
@@ -573,7 +576,7 @@ EM_JS(int, qts_host_interrupt_handler, (JSRuntime * rt), {
573576
// #else
574577
const asyncify = undefined;
575578
// #endif
576-
return Module.callbacks.shouldInterrupt(asyncify, rt);
579+
return Module['callbacks']['shouldInterrupt'](asyncify, rt);
577580
});
578581

579582
// interrupt: QuickJS -> C
@@ -594,11 +597,11 @@ void QTS_RuntimeDisableInterruptHandler(JSRuntime *rt) {
594597
// load module: C -> Host
595598
EM_JS(MaybeAsync(JSModuleDef *), qts_host_load_module, (JSRuntime * rt, JSContext *ctx, const char *module_name), {
596599
#ifdef QTS_ASYNCIFY
597-
const asyncify = Asyncify;
600+
const asyncify = {['handleSleep'] : Asyncify.handleSleep};
598601
#else
599602
const asyncify = undefined;
600603
#endif
601-
return Module.callbacks.loadModule(asyncify, rt, ctx, module_name);
604+
return Module['callbacks']['loadModule'](asyncify, rt, ctx, module_name);
602605
});
603606

604607
// load module: QuickJS -> C

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "quickjs-emscripten",
3-
"version": "0.15.0",
3+
"version": "0.50.0",
44
"main": "dist/quickjs.js",
55
"license": "MIT",
66
"keywords": [

ts/ffi-asyncify.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { JSRuntimePointer, JSContextPointer, JSContextPointerPointer, JSModuleDe
1212
export class QuickJSAsyncFFI {
1313
constructor(private module: QuickJSAsyncEmscriptenModule) {}
1414
/** Set at compile time. */
15-
readonly DEBUG = true
15+
readonly DEBUG = false
1616

1717
QTS_Throw: (ctx: JSContextPointer, error: JSValuePointer | JSValueConstPointer) => JSValuePointer =
1818
this.module.cwrap("QTS_Throw", "number", ["number","number"])
@@ -96,19 +96,19 @@ export class QuickJSAsyncFFI {
9696
assertSync(this.module.cwrap("QTS_ExecutePendingJob", "number", ["number","number","number"]))
9797

9898
QTS_ExecutePendingJob_MaybeAsync: (rt: JSRuntimePointer, maxJobsToExecute: number, lastJobContext: JSContextPointerPointer) => JSValuePointer | Promise<JSValuePointer> =
99-
this.module.cwrap("QTS_ExecutePendingJob", "number", ["number","number","number"], { async: true })
99+
this.module.cwrap("QTS_ExecutePendingJob", "number", ["number","number","number"])
100100

101101
QTS_GetProp: (ctx: JSContextPointer, this_val: JSValuePointer | JSValueConstPointer, prop_name: JSValuePointer | JSValueConstPointer) => JSValuePointer =
102102
assertSync(this.module.cwrap("QTS_GetProp", "number", ["number","number","number"]))
103103

104104
QTS_GetProp_MaybeAsync: (ctx: JSContextPointer, this_val: JSValuePointer | JSValueConstPointer, prop_name: JSValuePointer | JSValueConstPointer) => JSValuePointer | Promise<JSValuePointer> =
105-
this.module.cwrap("QTS_GetProp", "number", ["number","number","number"], { async: true })
105+
this.module.cwrap("QTS_GetProp", "number", ["number","number","number"])
106106

107107
QTS_SetProp: (ctx: JSContextPointer, this_val: JSValuePointer | JSValueConstPointer, prop_name: JSValuePointer | JSValueConstPointer, prop_value: JSValuePointer | JSValueConstPointer) => void =
108108
assertSync(this.module.cwrap("QTS_SetProp", null, ["number","number","number","number"]))
109109

110110
QTS_SetProp_MaybeAsync: (ctx: JSContextPointer, this_val: JSValuePointer | JSValueConstPointer, prop_name: JSValuePointer | JSValueConstPointer, prop_value: JSValuePointer | JSValueConstPointer) => void | Promise<void> =
111-
this.module.cwrap("QTS_SetProp", null, ["number","number","number","number"], { async: true })
111+
this.module.cwrap("QTS_SetProp", null, ["number","number","number","number"])
112112

113113
QTS_DefineProp: (ctx: JSContextPointer, this_val: JSValuePointer | JSValueConstPointer, prop_name: JSValuePointer | JSValueConstPointer, prop_value: JSValuePointer | JSValueConstPointer, get: JSValuePointer | JSValueConstPointer, set: JSValuePointer | JSValueConstPointer, configurable: boolean, enumerable: boolean, has_value: boolean) => void =
114114
this.module.cwrap("QTS_DefineProp", null, ["number","number","number","number","number","number","boolean","boolean","boolean"])
@@ -117,7 +117,7 @@ export class QuickJSAsyncFFI {
117117
assertSync(this.module.cwrap("QTS_Call", "number", ["number","number","number","number","number"]))
118118

119119
QTS_Call_MaybeAsync: (ctx: JSContextPointer, func_obj: JSValuePointer | JSValueConstPointer, this_obj: JSValuePointer | JSValueConstPointer, argc: number, argv_ptrs: JSValueConstPointerPointer) => JSValuePointer | Promise<JSValuePointer> =
120-
this.module.cwrap("QTS_Call", "number", ["number","number","number","number","number"], { async: true })
120+
this.module.cwrap("QTS_Call", "number", ["number","number","number","number","number"])
121121

122122
QTS_ResolveException: (ctx: JSContextPointer, maybe_exception: JSValuePointer) => JSValuePointer =
123123
this.module.cwrap("QTS_ResolveException", "number", ["number","number"])
@@ -126,13 +126,13 @@ export class QuickJSAsyncFFI {
126126
assertSync(this.module.cwrap("QTS_Dump", "string", ["number","number"]))
127127

128128
QTS_Dump_MaybeAsync: (ctx: JSContextPointer, obj: JSValuePointer | JSValueConstPointer) => string | Promise<string> =
129-
this.module.cwrap("QTS_Dump", "string", ["number","number"], { async: true })
129+
this.module.cwrap("QTS_Dump", "string", ["number","number"])
130130

131131
QTS_Eval: (ctx: JSContextPointer, js_code: HeapCharPointer, filename: string, detectModule: EvalDetectModule, evalFlags: EvalFlags) => JSValuePointer =
132132
assertSync(this.module.cwrap("QTS_Eval", "number", ["number","number","string","number","number"]))
133133

134134
QTS_Eval_MaybeAsync: (ctx: JSContextPointer, js_code: HeapCharPointer, filename: string, detectModule: EvalDetectModule, evalFlags: EvalFlags) => JSValuePointer | Promise<JSValuePointer> =
135-
this.module.cwrap("QTS_Eval", "number", ["number","number","string","number","number"], { async: true })
135+
this.module.cwrap("QTS_Eval", "number", ["number","number","string","number","number"])
136136

137137
QTS_Typeof: (ctx: JSContextPointer, value: JSValuePointer | JSValueConstPointer) => string =
138138
this.module.cwrap("QTS_Typeof", "string", ["number","number"])

ts/ffi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { JSRuntimePointer, JSContextPointer, JSContextPointerPointer, JSModuleDe
1212
export class QuickJSFFI {
1313
constructor(private module: QuickJSEmscriptenModule) {}
1414
/** Set at compile time. */
15-
readonly DEBUG = true
15+
readonly DEBUG = false
1616

1717
QTS_Throw: (ctx: JSContextPointer, error: JSValuePointer | JSValueConstPointer) => JSValuePointer =
1818
this.module.cwrap("QTS_Throw", "number", ["number","number"])

0 commit comments

Comments
 (0)