diff --git a/src/library.js b/src/library.js index c7f26d2919a5c..de40788604bf9 100644 --- a/src/library.js +++ b/src/library.js @@ -2182,25 +2182,19 @@ addToLibrary({ }, $asyncLoad__docs: '/** @param {boolean=} noRunDep */', - $asyncLoad: (url, onload, onerror, noRunDep) => { - var dep = !noRunDep ? getUniqueRunDependency(`al ${url}`) : ''; - readAsync(url).then( - (arrayBuffer) => { -#if ASSERTIONS - assert(arrayBuffer, `Loading data file "${url}" failed (no arrayBuffer).`); -#endif - onload(new Uint8Array(arrayBuffer)); - if (dep) removeRunDependency(dep); - }, - (err) => { - if (onerror) { - onerror(); - } else { - throw `Loading data file "${url}" failed.`; - } - } - ); - if (dep) addRunDependency(dep); + $asyncLoad: (url, noRunDep) => { + return new Promise((resolve, reject) => { + var dep = !noRunDep ? getUniqueRunDependency(`al ${url}`) : ''; + if (dep) addRunDependency(dep); + readAsync(url).then( + (arrayBuffer) => { + #if ASSERTIONS + assert(arrayBuffer, `Loading data file "${url}" failed (no arrayBuffer).`); + #endif + resolve(new Uint8Array(arrayBuffer)); + if (dep) removeRunDependency(dep); + }, reject); + }); }, $alignMemory: (size, alignment) => { diff --git a/src/library_async.js b/src/library_async.js index 4ada1dccaa1c5..8d694439e147c 100644 --- a/src/library_async.js +++ b/src/library_async.js @@ -470,7 +470,8 @@ addToLibrary({ emscripten_wget_data__async: true, emscripten_wget_data: (url, pbuffer, pnum, perror) => { return Asyncify.handleSleep((wakeUp) => { - asyncLoad(UTF8ToString(url), (byteArray) => { + /* no need for run dependency, this is async but will not do any prepare etc. step */ + asyncLoad(UTF8ToString(url), /*noRunDep=*/true).then((byteArray) => { // can only allocate the buffer after the wakeUp, not during an asyncing var buffer = _malloc(byteArray.length); // must be freed by caller! HEAPU8.set(byteArray, buffer); @@ -481,7 +482,7 @@ addToLibrary({ }, () => { {{{ makeSetValue('perror', 0, '1', 'i32') }}}; wakeUp(); - }, true /* no need for run dependency, this is async but will not do any prepare etc. step */ ); + }); }); }, diff --git a/src/library_dylink.js b/src/library_dylink.js index dee697661bb66..748468aaebc22 100644 --- a/src/library_dylink.js +++ b/src/library_dylink.js @@ -1024,7 +1024,7 @@ var LibraryDylink = { var libFile = locateFile(libName); if (flags.loadAsync) { - return new Promise((resolve, reject) => asyncLoad(libFile, resolve, reject)); + return asyncLoad(libFile); } // load the binary synchronously diff --git a/src/library_fs_shared.js b/src/library_fs_shared.js index 6f92f1f77a813..1c3c5f9aab310 100644 --- a/src/library_fs_shared.js +++ b/src/library_fs_shared.js @@ -76,7 +76,7 @@ addToLibrary({ } addRunDependency(dep); if (typeof url == 'string') { - asyncLoad(url, processData, onerror); + asyncLoad(url).then(processData, onerror); } else { processData(url); } diff --git a/src/library_wget.js b/src/library_wget.js index e8404cefd0d09..fe6416a7391f0 100644 --- a/src/library_wget.js +++ b/src/library_wget.js @@ -64,7 +64,8 @@ var LibraryWget = { emscripten_async_wget_data__proxy: 'sync', emscripten_async_wget_data: (url, userdata, onload, onerror) => { {{{ runtimeKeepalivePush() }}} - asyncLoad(UTF8ToString(url), (byteArray) => { + /* no need for run dependency, this is async but will not do any prepare etc. step */ + asyncLoad(UTF8ToString(url), /*noRunDep=*/true).then((byteArray) => { {{{ runtimeKeepalivePop() }}} callUserCallback(() => { var buffer = _malloc(byteArray.length); @@ -79,7 +80,7 @@ var LibraryWget = { {{{ makeDynCall('vp', 'onerror') }}}(userdata); }); } - }, true /* no need for run dependency, this is async but will not do any prepare etc. step */ ); + }); }, emscripten_async_wget2__deps: ['$PATH_FS', '$wget', '$stackRestore', '$stringToUTF8OnStack'], diff --git a/test/other/codesize/test_codesize_hello_dylink.gzsize b/test/other/codesize/test_codesize_hello_dylink.gzsize index 97efd5dbc5030..152cf0a87a84f 100644 --- a/test/other/codesize/test_codesize_hello_dylink.gzsize +++ b/test/other/codesize/test_codesize_hello_dylink.gzsize @@ -1 +1 @@ -6339 +6298 diff --git a/test/other/codesize/test_codesize_hello_dylink.jssize b/test/other/codesize/test_codesize_hello_dylink.jssize index 9195b2fc9c83d..6ca7a20bfb1f4 100644 --- a/test/other/codesize/test_codesize_hello_dylink.jssize +++ b/test/other/codesize/test_codesize_hello_dylink.jssize @@ -1 +1 @@ -13936 +13867