8000 [JSC] Atomics.waitAsync should be invocable from the main thread · WebKit/WebKit@9259434 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9259434

Browse files
jjgriegomikhailramalho
authored andcommitted
[JSC] Atomics.waitAsync should be invocable from the main thread
https://bugs.webkit.org/show_bug.cgi?id=250518 Reviewed by Keith Miller. According to the current proposed spec [1], async atomic waits are not restricted to threads with `AgentCanSuspend()`--so, Atomics.waitAsync should not throw a TypeError for this reason. I've added a (very simple) test to this effect. So, we should delay the check for `isAtomicsWaitAllowedOnCurrentThread` until after we know the wait is known to be synchronous. If there's an implementation reason we shouldn't do this, let me know, but I couldn't find one. [1] https://tc39.es/proposal-atomics-wait-async/#sec-dowait * LayoutTests/js/Atomics-waitasync-invocable-on-main-thread-expected.txt: Added. * LayoutTests/js/Atomics-waitasync-invocable-on-main-thread.html: Added. * Source/JavaScriptCore/runtime/AtomicsObject.cpp: (JSC::atomicsWaitImpl): Canonical link: https://commits.webkit.org/258856@main
1 parent 2a6683c commit 9259434

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Test to ensure Atomics.waitAsync is invocable on the main thread
2+
3+
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
4+
5+
6+
PASS successfullyParsed is true
7+
8+
TEST COMPLETE
9+
10+
PASS Atomics.waitAsync can return immediately from the main thread
11+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2+
<html>
3+
<head>
4+
<script src="../resources/js-test-pre.js"></script>
5+
</head>
6+
<body>
7+
<script src =../resources/testharness.js></script>
8+
<script src =../resources/testharnessreport.js></script>
9+
<script>
10+
description("Test to ensure Atomics.waitAsync is invocable on the main thread");
11+
12+
promise_test(async t => {
13+
const buffer = new SharedArrayBuffer(1024);
14+
const array = new Int32Array(buffer);
15+
await Atomics.waitAsync(array, 0, 1).value;
16+
}, "Atomics.waitAsync can return immediately from the main thread");
17+
18+
</script>
19+
<script src="../resources/js-test-post.js"></script>
20+
</body>
21+
</html>

Source/JavaScriptCore/runtime/AtomicsObject.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -449,15 +449,14 @@ JSValue atomicsWaitImpl(JSGlobalObject* globalObject, JSArrayType* typedArray, u
449449
if (!std::isnan(timeoutInMilliseconds))
450450
timeout = std::max(Seconds::fromMilliseconds(timeoutInMilliseconds), 0_s);
451451

452+
if (type == AtomicsWaitType::Async)
453+
return WaiterListManager::singleton().waitAsync(globalObject, vm, ptr, expectedValue, timeout);
454+
452455
if (!vm.m_typedArrayController->isAtomicsWaitAllowedOnCurrentThread()) {
453-
throwTypeError(globalObject, scope, makeString("Atomics."_s,
454-
(type == AtomicsWaitType::Async ? "waitAsync"_s : "wait"_s), " cannot be called from the current thread."_s));
456+
throwTypeError(globalObject, scope, "Atomics.wait cannot be called from the current thread."_s);
455457
return { };
456458
}
457459

458-
if (type == AtomicsWaitType::Async)
459-
return WaiterListManager::singleton().waitAsync(globalObject, vm, ptr, expectedValue, timeout);
460-
461460
auto result = WaiterListManager::singleton().waitSync(vm, ptr, expectedValue, timeout);
462461
switch (result) {
463462
case WaiterListManager::WaitSyncResult::OK:

0 commit comments

Comments
 (0)
0