Skip to content

Commit 6c6c7c3

Browse files
authored
JSPI - Fix ccall. (#19800)
Add code to handle JSPI for ccall.
1 parent da84fe7 commit 6c6c7c3

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

.circleci/config.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,9 @@ jobs:
655655
other.test_native_call_before_init
656656
other.test_node_unhandled_rejection
657657
core2.test_hello_world
658-
core0.test_pthread_join_and_asyncify"
658+
core0.test_pthread_join_and_asyncify
659+
core0.test_async_ccall_promise_jspi
660+
core0.test_async_ccall_promise_exit_runtime_jspi"
659661
# Run some basic tests with the minimum version of node that we currently
660662
# support.
661663
- install-node-version:

src/library_ccall.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,14 @@ mergeInto(LibraryManager.library, {
8585
if (stack !== 0) stackRestore(stack);
8686
return convertReturnValue(ret);
8787
}
88+
#if ASYNCIFY
89+
var asyncMode = opts && opts.async;
90+
#endif
91+
8892
#if ASYNCIFY == 1
8993
// Keep the runtime alive through all calls. Note that this call might not be
9094
// async, but for simplicity we push and pop in all calls.
9195
runtimeKeepalivePush();
92-
var asyncMode = opts && opts.async;
9396
if (Asyncify.currData != previousAsync) {
9497
#if ASSERTIONS
9598
// A change in async operation happened. If there was already an async
@@ -111,6 +114,10 @@ mergeInto(LibraryManager.library, {
111114
}
112115
#endif
113116

117+
#if ASYNCIFY == 2
118+
if (asyncMode) return ret.then(onDone);
119+
#endif
120+
114121
ret = onDone(ret);
115122
#if ASYNCIFY == 1
116123
// If this is an async ccall, ensure we return a promise

test/common.py

+3
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,9 @@ def require_wasm_eh(self):
656656
self.fail('either d8 or node >= 16 required to run wasm-eh tests. Use EMTEST_SKIP_EH to skip')
657657

658658
def require_jspi(self):
659+
if not self.is_wasm():
660+
self.skipTest('JSPI is not currently supported for WASM2JS')
661+
659662
exp_args = ['--experimental-wasm-stack-switching', '--experimental-wasm-type-reflection']
660663
if config.NODE_JS and config.NODE_JS in self.js_engines:
661664
version = shared.check_node_version()

test/test_core.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -8239,12 +8239,18 @@ def test_async_ccall_good(self):
82398239
self.do_runf('main.c', 'HelloWorld')
82408240

82418241
@parameterized({
8242-
'': (False,),
8243-
'exit_runtime': (True,),
8242+
'asyncify': (False, 1),
8243+
'exit_runtime_asyncify': (True, 1),
8244+
'jspi': (False, 2),
8245+
'exit_runtime_jspi': (True, 2),
82448246
})
82458247
@no_wasm64('TODO: asyncify for wasm64')
8246-
def test_async_ccall_promise(self, exit_runtime):
8247-
self.set_setting('ASYNCIFY')
8248+
def test_async_ccall_promise(self, exit_runtime, asyncify):
8249+
if asyncify == 2:
8250+
self.require_jspi()
8251+
self.emcc_args += ['-Wno-experimental']
8252+
self.set_setting('ASYNCIFY_EXPORTS', ['stringf', 'floatf'])
8253+
self.set_setting('ASYNCIFY', asyncify)
82488254
self.set_setting('EXIT_RUNTIME')
82498255
self.set_setting('ASSERTIONS')
82508256
self.set_setting('INVOKE_RUN', 0)

0 commit comments

Comments
 (0)