Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle wildcards in ASYNCIFY_EXPORTS when intrumenting exports #19298

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/library_async.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ mergeInto(LibraryManager.library, {
dbg('asyncify instrumenting exports');
#endif
#if ASYNCIFY == 2
var ASYNCIFY_EXPORTS = {{{ JSON.stringify(ASYNCIFY_EXPORTS) }}};
var exportPatterns = [{{{ ASYNCIFY_EXPORTS.map(x => new RegExp('^' + x.replace(/\*/g, '.*') + '$')) }}}];
#endif
var ret = {};
for (var x in exports) {
Expand All @@ -119,7 +119,7 @@ mergeInto(LibraryManager.library, {
if (typeof original == 'function') {
#if ASYNCIFY == 2
// Wrap all exports with a promising WebAssembly function.
var isAsyncifyExport = ASYNCIFY_EXPORTS.indexOf(x) >= 0;
var isAsyncifyExport = exportPatterns.some(pattern => !!x.match(pattern));
if (isAsyncifyExport) {
original = Asyncify.makeAsyncFunction(original);
}
Expand Down
37 changes: 37 additions & 0 deletions test/other/test_jspi_wildcard.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2023 The Emscripten Authors. All rights reserved.
// Emscripten is available under two separate licenses, the MIT license and the
// University of Illinois/NCSA Open Source License. Both these licenses can be
// found in the LICENSE file.

#include <emscripten.h>
#include <stdio.h>

EM_ASYNC_JS(int, test, (), {
const promise1 = Module._async1();
assert(promise1 instanceof Promise);
await promise1;
const promise2 = Module._async2();
assert(promise2 instanceof Promise);
await promise2;
assert(!(Module._sync() instanceof Promise));
});

EMSCRIPTEN_KEEPALIVE int async1() {
emscripten_sleep(0);
return 99;
}

EMSCRIPTEN_KEEPALIVE int async2() {
emscripten_sleep(0);
return 99;
}

EMSCRIPTEN_KEEPALIVE int sync() {
return 99;
}

int main() {
test();
printf("done\n");
return 0;
}
7 changes: 7 additions & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -2869,6 +2869,13 @@ def test_embind_finalization(self):
self.assertContained('Constructed from JS destructed', output)
self.assertNotContained('Foo* destructed', output)

def test_jspi_wildcard(self):
self.require_v8()
self.v8_args.append('--experimental-wasm-stack-switching')
self.emcc_args += ['-sASYNCIFY=2', '-sASYNCIFY_EXPORTS=async*', '-Wno-experimental']

self.do_runf(test_file('other/test_jspi_wildcard.c'), 'done')

def test_emconfig(self):
output = self.run_process([emconfig, 'LLVM_ROOT'], stdout=PIPE).stdout.strip()
self.assertEqual(output, config.LLVM_ROOT)
Expand Down