Skip to content

Conversation

@kleisauke
Copy link
Collaborator

Use a different parameter name to prevent the variable from being incorrectly hoisted in JavaScriptCore-based engines (such as Safari). See: https://bugs.webkit.org/show_bug.cgi?id=223533.

Regressed for multi-environment ES6 builds since commit ce4c405 (Emscripten 3.1.27). -sENVIRONMENT=web is not affected, as that would avoid the emit of this async function altogether.

Resolves: #18357.


Opened as a draft because I do not have access to macOS devices nor have I tested this locally with JSC.

Use a different parameter name to prevent the variable from being
incorrectly hoisted in JavaScriptCore-based engines (such as Safari).
See: https://bugs.webkit.org/show_bug.cgi?id=223533.

Regressed for multi-environment ES6 builds since commit ce4c405
(Emscripten 3.1.27). `-sENVIRONMENT=web` is not affected, as that
would avoid the emit of this async function altogether.

Resolves: emscripten-core#18357.
@kleisauke
Copy link
Collaborator Author

FWIW, as noticed in comment #17915 (comment) this MODULARIZE specific wrapper is emitted after Closure is run, so it doesn't optimize this. Therefore, this change would also be safe when used with Closure.

emcc.py Outdated
%(maybe_async)sfunction(%(EXPORT_NAME)s) {
%(EXPORT_NAME)s = %(EXPORT_NAME)s || {};
%(maybe_async)sfunction(_%(EXPORT_NAME)s) {
%(EXPORT_NAME)s = _%(EXPORT_NAME)s || {};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we completely rename this to something like "params", or "args".

Don't we also then need the var on the next line since its declaring a new var?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should we completely rename this to something like "params", or "args".

Ah, that would probably be neater. Given that this object contains Emscripten-specific configuration (such as settings and/or callbacks), how about naming this config instead? I suppose it could still cause issues when someone uses -sEXPORT_NAME=config, but I'm not sure if that's a valid use-case (since values specified in EXPORT_NAME usually start with a uppercase letter).

Don't we also then need the var on the next line since its declaring a new var?

You're right, let me fix that after the CI finishes on commit ffb8149.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Resolved with commit 0e54be7 and 53274f2.

@kleisauke
Copy link
Collaborator Author

Before marking this as non-draft, I just build a example program with:

$ emcc -O3 test/hello_world.c -o test.html -sEXPORT_ES6

On this PR and published the produced Wasm binary, HTML and JS file in:
https://gist.github.com/kleisauke/08f7e6c2c978e5581f52a40a04225ab0

To test this on Safari, just do:

$ git clone https://gist.github.com/08f7e6c2c978e5581f52a40a04225ab0.git pr-18482-test
$ cd pr-18482-test/
$ emrun --port 8080 --no_browser .
# Visit http://localhost:8080/test.html in Safari

Can anyone verify that this works correctly in Safari? If it works correctly (i.e. the print callback is honored), you should see hello, world! in both the textarea and Javascript console.

@sbc100
Copy link
Collaborator

sbc100 commented Jan 9, 2023

Would be great to get confirmation, but also I think we can land this change regardless as it seems like an simple improvement anyway.

@kleisauke
Copy link
Collaborator Author

Would be great to get confirmation, but also I think we can land this change regardless as it seems like an simple improvement anyway.

Indeed, let me remove the draft status. :)

@kleisauke kleisauke marked this pull request as ready for review January 9, 2023 20:33
@sbc100 sbc100 merged commit 53568c0 into emscripten-core:main Jan 9, 2023
@kleisauke kleisauke deleted the export-es6-jsc-compat branch January 10, 2023 08:54
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.

onRuntimeInitialized called on Chrome but not Safari

3 participants