Skip to content

Commit 82b001a

Browse files
committed
Merge branch 'main' of github.com:justjake/quickjs-emscripten
2 parents 21e6fe2 + fb984a5 commit 82b001a

10 files changed

+355
-341
lines changed

Diff for: Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ CFLAGS_WASM+=-s NODEJS_CATCH_EXIT=0
8585
# https://emscripten.org/docs/porting/asyncify.html
8686
CFLAGS_WASM_ASYNCIFY+=-s ASYNCIFY=1
8787
CFLAGS_WASM_ASYNCIFY+=-DQTS_ASYNCIFY=1
88+
CFLAGS_WASM_ASYNCIFY+=-s ASYNCIFY_STACK_SIZE=81920
8889
CFLAGS_WASM_ASYNCIFY+=-s ASYNCIFY_REMOVE=@$(BUILD_WRAPPER)/asyncify-remove.json
8990
CFLAGS_WASM_ASYNCIFY+=-s ASYNCIFY_IMPORTS=@$(BUILD_WRAPPER)/asyncify-imports.json
9091
CFLAGS_WASM_ASYNCIFY+=-lasync.js

Diff for: c/interface.c

+9
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,19 @@ int QTS_BuildIsSanitizeLeak() {
215215
#endif
216216
}
217217

218+
#ifdef QTS_ASYNCIFY
219+
EM_JS(void, set_asyncify_stack_size, (size_t size), {
220+
Asyncify.StackSize = size || 81920;
221+
});
222+
#endif
223+
218224
/**
219225
* Set the stack size limit, in bytes. Set to 0 to disable.
220226
*/
221227
void QTS_RuntimeSetMaxStackSize(JSRuntime *rt, size_t stack_size) {
228+
#ifdef QTS_ASYNCIFY
229+
set_asyncify_stack_size(stack_size);
230+
#endif
222231
JS_SetMaxStackSize(rt, stack_size);
223232
}
224233

Diff for: ts/generated/emscripten-module.WASM_DEBUG_ASYNCIFY.js

+107-113
Large diffs are not rendered by default.
31 Bytes
Binary file not shown.

Diff for: ts/generated/emscripten-module.WASM_DEBUG_ASYNCIFY.wasm.map

+1-1
Large diffs are not rendered by default.

Diff for: ts/generated/emscripten-module.WASM_DEBUG_SYNC.js

+146-164
Large diffs are not rendered by default.

Diff for: ts/generated/emscripten-module.WASM_DEBUG_SYNC.wasm

-937 Bytes
Binary file not shown.

Diff for: ts/generated/emscripten-module.WASM_RELEASE_ASYNCIFY.js

+38-40
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: ts/generated/emscripten-module.WASM_RELEASE_SYNC.js

+21-23
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: ts/quickjs.test.ts

+32
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,38 @@ function asyncContextTests(getContext: () => Promise<QuickJSAsyncContext>) {
980980
)
981981
})
982982
})
983+
984+
describe("ASYNCIFY_STACK_SIZE", () => {
985+
// | ASYNCIFY_STACK_SIZE | Max Nesting Levels |
986+
// |---------------------|--------------------|
987+
// | 4096 (default) | 12 |
988+
// | 81920 | 297 |
989+
it("is enough to support at least 20 levels of function nesting", async () => {
990+
// The nesting levels of the test cannot be too high, otherwise the
991+
// node.js call stack will overflow when executing `yarn test`
992+
let asyncFunctionCalls = 0
993+
const asyncFn = async () => {
994+
asyncFunctionCalls++
995+
}
996+
vm.newAsyncifiedFunction("asyncFn", asyncFn).consume((fn) =>
997+
vm.setProp(vm.global, "asyncFn", fn)
998+
)
999+
1000+
await vm.evalCodeAsync(`
1001+
let nestingLevels = 0
1002+
function nestingFn() {
1003+
nestingLevels++
1004+
asyncFn()
1005+
if (nestingLevels < 20) {
1006+
nestingFn()
1007+
}
1008+
}
1009+
nestingFn();
1010+
`)
1011+
1012+
assert.equal(asyncFunctionCalls, 20, "20 levels of nesting")
1013+
})
1014+
})
9831015
}
9841016

9851017
describe("QuickJSContext", function () {

0 commit comments

Comments
 (0)