Skip to content
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

Separate out Atomics.waitAsync polyfill. NFC #20474

Merged
merged 1 commit into from
Oct 19, 2023

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Oct 17, 2023

Split out from #20404.

Rather than adding artificial dependencies on
emscripten_atomic_wait_async we can use the same technique used by $polyfillSetImmediate in library_eventloop.js.

Split out from emscripten-core#20404.

Rather than adding artificial dependencies on
`emscripten_atomic_wait_async` we can use the same technique used by
`$polyfillSetImmediate` in `library_eventloop.js`.
@sbc100 sbc100 requested review from kripken and juj October 17, 2023 16:20
@sbc100 sbc100 merged commit fd0e233 into emscripten-core:main Oct 19, 2023
@sbc100 sbc100 deleted the waitasync_polyfill branch October 19, 2023 16:39
@tlively
Copy link
Member

tlively commented Nov 2, 2023

What are we using this polyfill for?

@sbc100
Copy link
Collaborator Author

sbc100 commented Nov 2, 2023

What are we using this polyfill for?

See the comments:

// Chrome 87 (and hence Edge 87) shipped Atomics.waitAsync (https://www.chromestatus.com/feature/6243382101803008)
// However its implementation is faulty: https://bugs.chromium.org/p/chromium/issues/detail?id=1167541
// Firefox Nightly 86.0a1 (2021-01-15) does not yet have it, https://bugzilla.mozilla.org/show_bug.cgi?id=1467846
// And at the time of writing, no other browser has it either.
#if MIN_EDGE_VERSION < 91 || MIN_CHROME_VERSION < 91 || MIN_SAFARI_VERSION != TARGET_NOT_SUPPORTED || MIN_FIREFOX_VERSION != TARGET_NOT_SUPPORTED || ENVIRONMENT_MAY_BE_NODE
  // Partially polyfill Atomics.waitAsync() if not available in the browser.
  // Also polyfill for old Chrome-based browsers, where Atomics.waitAsync is
  // broken until Chrome 91, see
  // https://bugs.chromium.org/p/chromium/issues/detail?id=1167541
  // https://github.com/tc39/proposal-atomics-wait-async/blob/master/PROPOSAL.md
  // This polyfill performs polling with setTimeout() to observe a change in the
  // target memory location.

@sbc100
Copy link
Collaborator Author

sbc100 commented Nov 2, 2023

What are we using this polyfill for?

In order to make the APIs work on browsers that don't support it I assume?

@tlively
Copy link
Member

tlively commented Nov 6, 2023

When I wrote the proxying code to use Atomics.waitAsync when available, I deliberately did not include a polyfill because falling back to postMessage should be much, much faster than any possible polyfill. Is there a chance that this polyfill is being picked up and accidentally used by the proxying code?

@sbc100
Copy link
Collaborator Author

sbc100 commented Nov 6, 2023

When I wrote the proxying code to use Atomics.waitAsync when available, I deliberately did not include a polyfill because falling back to postMessage should be much, much faster than any possible polyfill. Is there a chance that this polyfill is being picked up and accidentally used by the proxying code?

Hmm.. that is possible. Perhaps we should not actually polyfill via the original name.

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