Skip to content

[file_packager] Convert openDatabase to async/await. NFC #24883

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

Merged
merged 1 commit into from
Aug 8, 2025

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Aug 7, 2025

Followup to #24882

@sbc100
Copy link
Collaborator Author

sbc100 commented Aug 7, 2025

Best viewed with "hide whitespace".

@sbc100
Copy link
Collaborator Author

sbc100 commented Aug 7, 2025

I hope you don't mind me splitting this up into small peices like this. Its easier for me to get my head around each step on its own and I hope its easier to review.

@sbc100 sbc100 requested a review from dschuff August 7, 2025 23:42
Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm % question

+1 for the splitting up!

code += '''
if (isNode) {
return errback();
}'''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like node always errored. Is this fixing that path?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(do we test it?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the typeof indexedDB == 'undefined' just below should be enough to handle the node case.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm.. maybe I should split that out, or at least see why it was added.

sbc100 added a commit to sbc100/emscripten that referenced this pull request Aug 7, 2025
This was added back in emscripten-core#22802 but seems redundant since the check
just below for the indexedDB global should be enough to handle the
node case.

Split out from emscripten-core#24883
sbc100 added a commit to sbc100/emscripten that referenced this pull request Aug 8, 2025
This was added back in emscripten-core#22802 but seems redundant since the check
just below for the indexedDB global should be enough to handle the
node case.

Split out from emscripten-core#24883
@sbc100 sbc100 force-pushed the file_packager_async_part2 branch from fd6035c to c232a88 Compare August 8, 2025 00:21
sbc100 added a commit that referenced this pull request Aug 8, 2025
This was added back in #22802 but seems redundant since the check just
below for the indexedDB global should be enough to handle the node case.

Split out from #24883
@sbc100 sbc100 force-pushed the file_packager_async_part2 branch from c232a88 to 466604a Compare August 8, 2025 00:25
@sbc100 sbc100 merged commit 4c3f383 into emscripten-core:main Aug 8, 2025
4 of 13 checks passed
@sbc100 sbc100 deleted the file_packager_async_part2 branch August 8, 2025 00:26
sbc100 added a commit to sbc100/emscripten that referenced this pull request Aug 8, 2025
@@ -805,34 +805,32 @@ def generate_js(data_target, data_files, metadata):
var DB_VERSION = 1;
var METADATA_STORE_NAME = 'METADATA';
var PACKAGE_STORE_NAME = 'PACKAGES';
function openDatabase(callback, errback) {
async function openDatabase() {
if (typeof indexedDB == 'undefined') {
return errback('using IndexedDB to cache data can only be done on a web page or in a web worker');
Copy link

@lkwinta lkwinta Aug 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sbc100 @kripken I think that this introduces a bug, it should be be throw or promise reject since errback doesn't exist anymore

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! Will fix

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this went unnoticed because the errback is not defined error was caught an the fallback was run anyway:

$ node ./src.js
ReferenceError: errback is not defined
    at openDatabase (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/src.js:173:13)
    at runWithFS (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/src.js:333:9)
    at callRuntimeCallbacks (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/src.js:1164:26)
    at preRun (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/src.js:841:3)
    at run (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/src.js:4658:3)
    at Object.removeRunDependency (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/src.js:950:7)
    at loadPackage (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/src.js:362:34)
    at runMetaWithFS (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/src.js:371:18)
falling back to default preload behavior
done

Still worth fixing though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in #24886

sbc100 added a commit to sbc100/emscripten that referenced this pull request Aug 8, 2025
This went unnoticed by the tests because the calling code has a `.catch`
handler that calls the fallback function.  So the test still passed but
with a bunch of extra output:

```
ReferenceError: errback is not defined
    at openDatabase (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/src.js:173:13)
    at runWithFS (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/src.js:333:9)
    at callRuntimeCallbacks (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/src.js:1164:26)
    at preRun (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/src.js:841:3)
    at run (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/src.js:4658:3)
    at Object.removeRunDependency (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/src.js:950:7)
    at loadPackage (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/src.js:362:34)
    at runMetaWithFS (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/src.js:371:18)
falling back to default preload behavior
done
```

Followup to emscripten-core#24883
sbc100 added a commit to sbc100/emscripten that referenced this pull request Aug 8, 2025
sbc100 added a commit that referenced this pull request Aug 8, 2025
This went unnoticed by the tests because the calling code has a `.catch`
handler that calls the fallback function. So the test still passed but
with a bunch of extra output:

```
ReferenceError: errback is not defined
    at openDatabase (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/src.js:173:13)
    at runWithFS (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/src.js:333:9)
    at callRuntimeCallbacks (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/src.js:1164:26)
    at preRun (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/src.js:841:3)
    at run (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/src.js:4658:3)
    at Object.removeRunDependency (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/src.js:950:7)
    at loadPackage (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/src.js:362:34)
    at runMetaWithFS (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/src.js:371:18)
falling back to default preload behavior
done
```

Followup to #24883
sbc100 added a commit to sbc100/emscripten that referenced this pull request Aug 8, 2025
sbc100 added a commit to sbc100/emscripten that referenced this pull request Aug 8, 2025
sbc100 added a commit to sbc100/emscripten that referenced this pull request Aug 8, 2025
sbc100 added a commit to sbc100/emscripten that referenced this pull request Aug 8, 2025
sbc100 added a commit that referenced this pull request Aug 8, 2025
The 3 functions related to IDB caching of preload data are now marked as
`async`. This means that they return promises instead of using
callbacks.

Followup to #24882 and #24883
sbc100 added a commit to sbc100/emscripten that referenced this pull request Aug 8, 2025
sbc100 added a commit to sbc100/emscripten that referenced this pull request Aug 8, 2025
sbc100 added a commit to sbc100/emscripten that referenced this pull request Aug 8, 2025
sbc100 added a commit to sbc100/emscripten that referenced this pull request Aug 8, 2025
sbc100 added a commit to sbc100/emscripten that referenced this pull request Aug 8, 2025
sbc100 added a commit to sbc100/emscripten that referenced this pull request Aug 8, 2025
sbc100 added a commit to sbc100/emscripten that referenced this pull request Aug 9, 2025
sbc100 added a commit to sbc100/emscripten that referenced this pull request Aug 11, 2025
sbc100 added a commit to sbc100/emscripten that referenced this pull request Aug 12, 2025
sbc100 added a commit that referenced this pull request Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants