Skip to content

Commit

Permalink
Simplify asyncLoad. NFC (emscripten-core#23100)
Browse files Browse the repository at this point in the history
Turns out non of the callers were relying the adding of the run
dependencies here. There are 4 call sites total:

- emscripten_async_wget_data: Explicitly sets noRunDep
- emscripten_wget_data: Explicitly sets noRunDep
- loadDynamicLibrary: The outer loadDylibs already has an explicit calls
to addRunDependency/removeRunDependency.
- FS_createPreloadedFile: Already has an explicit calls to
addRunDependency/removeRunDependency.
  • Loading branch information
sbc100 authored Dec 7, 2024
1 parent f130663 commit 1ddef04
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 9 deletions.
6 changes: 1 addition & 5 deletions src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -2181,18 +2181,14 @@ addToLibrary({
return x.startsWith('dynCall_') ? x : '_' + x;
},

$asyncLoad__docs: '/** @param {boolean=} noRunDep */',
$asyncLoad: (url, noRunDep) => {
$asyncLoad: (url) => {
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);
});
},
Expand Down
2 changes: 1 addition & 1 deletion src/library_async.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ addToLibrary({
emscripten_wget_data: (url, pbuffer, pnum, perror) => {
return Asyncify.handleSleep((wakeUp) => {
/* no need for run dependency, this is async but will not do any prepare etc. step */
asyncLoad(UTF8ToString(url), /*noRunDep=*/true).then((byteArray) => {
asyncLoad(UTF8ToString(url)).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);
Expand Down
2 changes: 1 addition & 1 deletion src/library_wget.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var LibraryWget = {
emscripten_async_wget_data: (url, userdata, onload, onerror) => {
{{{ runtimeKeepalivePush() }}}
/* no need for run dependency, this is async but will not do any prepare etc. step */
asyncLoad(UTF8ToString(url), /*noRunDep=*/true).then((byteArray) => {
asyncLoad(UTF8ToString(url)).then((byteArray) => {
{{{ runtimeKeepalivePop() }}}
callUserCallback(() => {
var buffer = _malloc(byteArray.length);
Expand Down
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_hello_dylink.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6294
6276
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_hello_dylink.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
13863
13831

0 comments on commit 1ddef04

Please sign in to comment.