diff --git a/src/library_async.js b/src/library_async.js index 67cde1d4d69bb..6d9473c31a67b 100644 --- a/src/library_async.js +++ b/src/library_async.js @@ -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) { @@ -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); } diff --git a/test/other/test_jspi_wildcard.c b/test/other/test_jspi_wildcard.c new file mode 100644 index 0000000000000..39790d9b141ca --- /dev/null +++ b/test/other/test_jspi_wildcard.c @@ -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; +} diff --git a/test/test_other.py b/test/test_other.py index e6598f80e3d08..3d7f3dbe4d73e 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -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)