Skip to content

Commit f642503

Browse files
authored
Correctly instrument ASYNCIFY_IMPORTS with a wildcard (#19280)
Wildcard was incorrectly handled, as only verbatim matches were accepted in Asyncify.instrumentWasmImports for imports listed in ASYNCIFY_IMPORTS, even though the collection also contains wildcards. Those were ignored, but are now transformed to suitable RegExes. Also, don't single out __asyncjs__ as __asyncjs__* is already added as a default to ASYNCIFY_IMPORTS by emcc.py. Since now the wildcard will work correctly, there's no need to double-check for the prefix when determining if an import is an asyncify import.
1 parent 29cb1f5 commit f642503

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/library_async.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ mergeInto(LibraryManager.library, {
3838
#if ASYNCIFY_DEBUG
3939
dbg('asyncify instrumenting imports');
4040
#endif
41-
var ASYNCIFY_IMPORTS = {{{ JSON.stringify(ASYNCIFY_IMPORTS.map((x) => x.split('.')[1])) }}};
41+
var importPatterns = [{{{ ASYNCIFY_IMPORTS.map(x => new RegExp('^' + x.split('.')[1].replaceAll('*', '.*') + '$')) }}}];
42+
4243
for (var x in imports) {
4344
(function(x) {
4445
var original = imports[x];
4546
var sig = original.sig;
4647
if (typeof original == 'function') {
4748
var isAsyncifyImport = original.isAsync ||
48-
ASYNCIFY_IMPORTS.indexOf(x) >= 0 ||
49-
x.startsWith('__asyncjs__');
49+
importPatterns.some(pattern => !!x.match(pattern));
5050
#if ASYNCIFY == 2
5151
// Wrap async imports with a suspending WebAssembly function.
5252
if (isAsyncifyImport) {

test/test_browser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3412,6 +3412,7 @@ def test_async_iostream(self):
34123412
# To make the test more precise we also use ASYNCIFY_IGNORE_INDIRECT here.
34133413
@parameterized({
34143414
'normal': (['-sASYNCIFY_IMPORTS=[sync_tunnel, sync_tunnel_bool]'],), # noqa
3415+
'pattern_imports': (['-sASYNCIFY_IMPORTS=[sync_tun*]'],), # noqa
34153416
'response': (['-sASYNCIFY_IMPORTS=@filey.txt'],), # noqa
34163417
'nothing': (['-DBAD'],), # noqa
34173418
'empty_list': (['-DBAD', '-sASYNCIFY_IMPORTS=[]'],), # noqa

0 commit comments

Comments
 (0)