25.4 The Atomics Object
The Atomics object:
- is %Atomics%.
- is the initial value of the
"Atomics" property of theglobal object . - is an
ordinary object . - has a [[Prototype]] internal slot whose value is
%Object.prototype% . - does not have a [[Construct]] internal method; it cannot be used as a
constructor with thenew
operator. - does not have a [[Call]] internal method; it cannot be invoked as a function.
The Atomics object provides functions that operate indivisibly (atomically) on shared memory array cells as well as functions that let
For informative guidelines for programming and implementing shared memory in ECMAScript, please see the notes at the end of the
25.4.1 Waiter Record
A Waiter Record is a Atomics.wait
or Atomics.waitAsync
.
A Waiter Record has fields listed in
Field Name | Value | Meaning |
---|---|---|
[[AgentSignifier]] |
an |
The Atomics.wait or Atomics.waitAsync .
|
[[PromiseCapability]] |
a |
If denoting a call to Atomics.waitAsync , the resulting promise, otherwise |
[[TimeoutTime]] |
a non-negative |
The earliest time by which timeout may be triggered; computed using |
[[Result]] |
|
The return value of the call. |
25.4.2 WaiterList Records
A WaiterList Record is used to explain waiting and notification of Atomics.wait
, Atomics.waitAsync
, and Atomics.notify
.
A WaiterList Record has fields listed in
Field Name | Value | Meaning |
---|---|---|
[[Waiters]] |
a |
The calls to Atomics.wait or Atomics.waitAsync that are waiting on the location with which this WaiterList is associated.
|
[[MostRecentLeaveEvent]] |
a |
The event of the most recent leaving of its |
There can be multiple
The
Each WaiterList Record has a critical section that controls exclusive access to that WaiterList Record during evaluation. Only a single
25.4.3 Abstract Operations for Atomics
25.4.3.1 ValidateIntegerTypedArray ( typedArray, waitable )
The abstract operation ValidateIntegerTypedArray takes arguments typedArray (an
- Let taRecord be ?
ValidateTypedArray (typedArray,unordered ). - NOTE: Bounds checking is not a synchronizing operation when typedArray's backing buffer is a
growable SharedArrayBuffer . - If waitable is
true , then- If typedArray.[[TypedArrayName]] is neither
"Int32Array" nor"BigInt64Array" , throw aTypeError exception.
- If typedArray.[[TypedArrayName]] is neither
- Else,
- Let type be
TypedArrayElementType (typedArray). - If
IsUnclampedIntegerElementType (type) isfalse andIsBigIntElementType (type) isfalse , throw aTypeError exception.
- Let type be
- Return taRecord.
25.4.3.2 ValidateAtomicAccess ( taRecord, requestIndex )
The abstract operation ValidateAtomicAccess takes arguments taRecord (a
- Let length be
TypedArrayLength (taRecord). - Let accessIndex be ?
ToIndex (requestIndex). Assert : accessIndex ≥ 0.- If accessIndex ≥ length, throw a
RangeError exception. - Let typedArray be taRecord.[[Object]].
- Let elementSize be
TypedArrayElementSize (typedArray). - Let offset be typedArray.[[ByteOffset]].
- Return (accessIndex × elementSize) + offset.
25.4.3.3 ValidateAtomicAccessOnIntegerTypedArray ( typedArray, requestIndex [ , waitable ] )
The abstract operation ValidateAtomicAccessOnIntegerTypedArray takes arguments typedArray (an
- If waitable is not present, set waitable to
false . - Let taRecord be ?
ValidateIntegerTypedArray (typedArray, waitable). - Return ?
ValidateAtomicAccess (taRecord, requestIndex).
25.4.3.4 RevalidateAtomicAccess ( typedArray, byteIndexInBuffer )
The abstract operation RevalidateAtomicAccess takes arguments typedArray (a
- Let taRecord be
MakeTypedArrayWithBufferWitnessRecord (typedArray,unordered ). - NOTE: Bounds checking is not a synchronizing operation when typedArray's backing buffer is a
growable SharedArrayBuffer . - If
IsTypedArrayOutOfBounds (taRecord) istrue , throw aTypeError exception. Assert : byteIndexInBuffer ≥ typedArray.[[ByteOffset]].- If byteIndexInBuffer ≥ taRecord.[[CachedBufferByteLength]], throw a
RangeError exception. - Return
unused .
25.4.3.5 GetWaiterList ( block, i )
The abstract operation GetWaiterList takes arguments block (a
Assert : i and i + 3 are valid byte offsets within the memory of block.- Return the
WaiterList Record that is referenced by the pair (block, i).
25.4.3.6 EnterCriticalSection ( WL )
The abstract operation EnterCriticalSection takes argument WL (a
Assert : Thesurrounding agent is not in thecritical section for anyWaiterList Record .- Wait until no
agent is in thecritical section for WL, then enter thecritical section for WL (without allowing any otheragent to enter). - If WL.[[MostRecentLeaveEvent]] is not
empty , then- NOTE: A WL whose
critical section has been entered at least once has aSynchronize event set byLeaveCriticalSection . - Let execution be the [[CandidateExecution]] field of the
surrounding agent 'sAgent Record . - Let eventsRecord be the
Agent Events Record of execution.[[EventsRecords]] whose [[AgentSignifier]] isAgentSignifier (). - Let enterEvent be a new
Synchronize event . - Append enterEvent to eventsRecord.[[EventList]].
- Append (WL.[[MostRecentLeaveEvent]], enterEvent) to eventsRecord.[[AgentSynchronizesWith]].
- NOTE: A WL whose
- Return
unused .
EnterCriticalSection has contention when an
25.4.3.7 LeaveCriticalSection ( WL )
The abstract operation LeaveCriticalSection takes argument WL (a
Assert : Thesurrounding agent is in thecritical section for WL.- Let execution be the [[CandidateExecution]] field of the
surrounding agent 'sAgent Record . - Let eventsRecord be the
Agent Events Record of execution.[[EventsRecords]] whose [[AgentSignifier]] isAgentSignifier (). - Let leaveEvent be a new
Synchronize event . - Append leaveEvent to eventsRecord.[[EventList]].
- Set WL.[[MostRecentLeaveEvent]] to leaveEvent.
- Leave the
critical section for WL. - Return
unused .
25.4.3.8 AddWaiter ( WL, waiterRecord )
The abstract operation AddWaiter takes arguments WL (a
Assert : Thesurrounding agent is in thecritical section for WL.Assert : There is noWaiter Record in WL.[[Waiters]] whose [[PromiseCapability]] field is waiterRecord.[[PromiseCapability]] and whose [[AgentSignifier]] field is waiterRecord.[[AgentSignifier]].- Append waiterRecord to WL.[[Waiters]].
- Return
unused .
25.4.3.9 RemoveWaiter ( WL, waiterRecord )
The abstract operation RemoveWaiter takes arguments WL (a
Assert : Thesurrounding agent is in thecritical section for WL.Assert : WL.[[Waiters]] contains waiterRecord.- Remove waiterRecord from WL.[[Waiters]].
- Return
unused .
25.4.3.10 RemoveWaiters ( WL, c )
The abstract operation RemoveWaiters takes arguments WL (a
Assert : Thesurrounding agent is in thecritical section for WL.- Let len be the number of elements in WL.[[Waiters]].
- Let n be
min (c, len). - Let L be a
List whose elements are the first n elements of WL.[[Waiters]]. - Remove the first n elements of WL.[[Waiters]].
- Return L.
25.4.3.11 SuspendThisAgent ( WL, waiterRecord )
The abstract operation SuspendThisAgent takes arguments WL (a
Assert : Thesurrounding agent is in thecritical section for WL.Assert : WL.[[Waiters]] contains waiterRecord.- Let thisAgent be
AgentSignifier (). Assert : waiterRecord.[[AgentSignifier]] is thisAgent.Assert : waiterRecord.[[PromiseCapability]] isblocking .Assert :AgentCanSuspend () istrue .- Perform
LeaveCriticalSection (WL) and suspend thesurrounding agent until the time is waiterRecord.[[TimeoutTime]], performing the combined operation in such a way that a notification that arrives after thecritical section is exited but before the suspension takes effect is not lost. Thesurrounding agent can only wake from suspension due to a timeout or due to anotheragent callingNotifyWaiter with arguments WL and thisAgent (i.e. via a call toAtomics.notify
). - Perform
EnterCriticalSection (WL). - Return
unused .
25.4.3.12 NotifyWaiter ( WL, waiterRecord )
The abstract operation NotifyWaiter takes arguments WL (a
Assert : Thesurrounding agent is in thecritical section for WL.- If waiterRecord.[[PromiseCapability]] is
blocking , then- Wake the
agent whose signifier is waiterRecord.[[AgentSignifier]] from suspension. - NOTE: This causes the
agent to resume execution inSuspendThisAgent .
- Wake the
- Else if
AgentSignifier () is waiterRecord.[[AgentSignifier]], then- Let promiseCapability be waiterRecord.[[PromiseCapability]].
- Perform !
Call (promiseCapability.[[Resolve]],undefined , « waiterRecord.[[Result]] »).
- Else,
- Perform
EnqueueResolveInAgentJob (waiterRecord.[[AgentSignifier]], waiterRecord.[[PromiseCapability]], waiterRecord.[[Result]]).
- Perform
- Return
unused .
25.4.3.13 EnqueueResolveInAgentJob ( agentSignifier, promiseCapability, resolution )
The abstract operation EnqueueResolveInAgentJob takes arguments agentSignifier (an
- Let resolveJob be a new
Job Abstract Closure with no parameters that captures agentSignifier, promiseCapability, and resolution and performs the following steps when called:Assert :AgentSignifier () is agentSignifier.- Perform !
Call (promiseCapability.[[Resolve]],undefined , « resolution »). - Return
unused .
- Let realmInTargetAgent be !
GetFunctionRealm (promiseCapability.[[Resolve]]). Assert : agentSignifier is realmInTargetAgent.[[AgentSignifier]].- Perform
HostEnqueueGenericJob (resolveJob, realmInTargetAgent). - Return
unused .
25.4.3.14 DoWait ( mode, typedArray, index, value, timeout )
The abstract operation DoWait takes arguments mode (
- Let taRecord be ?
ValidateIntegerTypedArray (typedArray,true ). - Let buffer be taRecord.[[Object]].[[ViewedArrayBuffer]].
- If
IsSharedArrayBuffer (buffer) isfalse , throw aTypeError exception. - Let i be ?
ValidateAtomicAccess (taRecord, index). - Let arrayTypeName be typedArray.[[TypedArrayName]].
- If arrayTypeName is
"BigInt64Array" , let v be ?ToBigInt64 (value). - Else, let v be ?
ToInt32 (value). - Let q be ?
ToNumber (timeout). - If q is either
NaN or+∞ 𝔽, let t be +∞; else if q is-∞ 𝔽, let t be 0; else let t bemax (ℝ (q), 0). - If mode is
sync andAgentCanSuspend () isfalse , throw aTypeError exception. - Let block be buffer.[[ArrayBufferData]].
- Let offset be typedArray.[[ByteOffset]].
- Let byteIndexInBuffer be (i × 4) + offset.
- Let WL be
GetWaiterList (block, byteIndexInBuffer). - If mode is
sync , then- Let promiseCapability be
blocking . - Let resultObject be
undefined .
- Let promiseCapability be
- Else,
- Let promiseCapability be !
NewPromiseCapability (%Promise% ). - Let resultObject be
OrdinaryObjectCreate (%Object.prototype% ).
- Let promiseCapability be !
- Perform
EnterCriticalSection (WL). - Let elementType be
TypedArrayElementType (typedArray). - Let w be
GetValueFromBuffer (buffer, byteIndexInBuffer, elementType,true ,seq-cst ). - If v ≠ w, then
- Perform
LeaveCriticalSection (WL). - If mode is
sync , return"not-equal" . - Perform !
CreateDataPropertyOrThrow (resultObject,"async" ,false ). - Perform !
CreateDataPropertyOrThrow (resultObject,"value" ,"not-equal" ). - Return resultObject.
- Perform
- If t is 0 and mode is
async , then- NOTE: There is no special handling of synchronous immediate timeouts. Asynchronous immediate timeouts have special handling in order to fail fast and avoid unnecessary Promise jobs.
- Perform
LeaveCriticalSection (WL). - Perform !
CreateDataPropertyOrThrow (resultObject,"async" ,false ). - Perform !
CreateDataPropertyOrThrow (resultObject,"value" ,"timed-out" ). - Return resultObject.
- Let thisAgent be
AgentSignifier (). - Let now be the
time value (UTC) identifying the current time. - Let additionalTimeout be an
implementation-defined non-negativemathematical value . - Let timeoutTime be
ℝ (now) + t + additionalTimeout. - NOTE: When t is +∞, timeoutTime is also +∞.
- Let waiterRecord be a new
Waiter Record { [[AgentSignifier]]: thisAgent, [[PromiseCapability]]: promiseCapability, [[TimeoutTime]]: timeoutTime, [[Result]]:"ok" }. - Perform
AddWaiter (WL, waiterRecord). - If mode is
sync , then- Perform
SuspendThisAgent (WL, waiterRecord).
- Perform
- Else if timeoutTime is
finite , then- Perform
EnqueueAtomicsWaitAsyncTimeoutJob (WL, waiterRecord).
- Perform
- Perform
LeaveCriticalSection (WL). - If mode is
sync , return waiterRecord.[[Result]]. - Perform !
CreateDataPropertyOrThrow (resultObject,"async" ,true ). - Perform !
CreateDataPropertyOrThrow (resultObject,"value" , promiseCapability.[[Promise]]). - Return resultObject.
additionalTimeout allows implementations to pad timeouts as necessary, such as for reducing power consumption or coarsening timer resolution to mitigate timing attacks. This value may differ from call to call of DoWait.
25.4.3.15 EnqueueAtomicsWaitAsyncTimeoutJob ( WL, waiterRecord )
The abstract operation EnqueueAtomicsWaitAsyncTimeoutJob takes arguments WL (a
- Let timeoutJob be a new
Job Abstract Closure with no parameters that captures WL and waiterRecord and performs the following steps when called:- Perform
EnterCriticalSection (WL). - If WL.[[Waiters]] contains waiterRecord, then
- Let timeOfJobExecution be the
time value (UTC) identifying the current time. Assert :ℝ (timeOfJobExecution) ≥ waiterRecord.[[TimeoutTime]] (ignoring potential non-monotonicity oftime values ).- Set waiterRecord.[[Result]] to
"timed-out" . - Perform
RemoveWaiter (WL, waiterRecord). - Perform
NotifyWaiter (WL, waiterRecord).
- Let timeOfJobExecution be the
- Perform
LeaveCriticalSection (WL). - Return
unused .
- Perform
- Let now be the
time value (UTC) identifying the current time. - Let currentRealm be
the current Realm Record . - Perform
HostEnqueueTimeoutJob (timeoutJob, currentRealm,𝔽 (waiterRecord.[[TimeoutTime]]) - now). - Return
unused .
25.4.3.16 AtomicCompareExchangeInSharedBlock ( block, byteIndexInBuffer, elementSize, expectedBytes, replacementBytes )
The abstract operation AtomicCompareExchangeInSharedBlock takes arguments block (a
- Let execution be the [[CandidateExecution]] field of the
surrounding agent 'sAgent Record . - Let eventsRecord be the
Agent Events Record of execution.[[EventsRecords]] whose [[AgentSignifier]] isAgentSignifier (). - Let rawBytesRead be a
List of length elementSize whose elements are nondeterministically chosenbyte values . - NOTE: In implementations, rawBytesRead is the result of a load-link, of a load-exclusive, or of an operand of a read-modify-write instruction on the underlying hardware. The nondeterminism is a semantic prescription of the
memory model to describe observable behaviour of hardware with weak consistency. - NOTE: The comparison of the expected value and the read value is performed outside of the
read-modify-write modification function to avoid needlessly strong synchronization when the expected value is not equal to the read value. - If
ByteListEqual (rawBytesRead, expectedBytes) istrue , then- Let second be a new
read-modify-write modification function with parameters (oldBytes, newBytes) that captures nothing and performs the following steps atomically when called:- Return newBytes.
- Let event be
ReadModifyWriteSharedMemory { [[Order]]:seq-cst , [[NoTear]]:true , [[Block]]: block, [[ByteIndex]]: byteIndexInBuffer, [[ElementSize]]: elementSize, [[Payload]]: replacementBytes, [[ModifyOp]]: second }.
- Let second be a new
- Else,
- Let event be
ReadSharedMemory { [[Order]]:seq-cst , [[NoTear]]:true , [[Block]]: block, [[ByteIndex]]: byteIndexInBuffer, [[ElementSize]]: elementSize }.
- Let event be
- Append event to eventsRecord.[[EventList]].
- Append
Chosen Value Record { [[Event]]: event, [[ChosenValue]]: rawBytesRead } to execution.[[ChosenValues]]. - Return rawBytesRead.
25.4.3.17 AtomicReadModifyWrite ( typedArray, index, value, op )
The abstract operation AtomicReadModifyWrite takes arguments typedArray (an
- Let byteIndexInBuffer be ?
ValidateAtomicAccessOnIntegerTypedArray (typedArray, index). - If typedArray.[[ContentType]] is
bigint , let v be ?ToBigInt (value). - Otherwise, let v be
𝔽 (?ToIntegerOrInfinity (value)). - Perform ?
RevalidateAtomicAccess (typedArray, byteIndexInBuffer). - Let buffer be typedArray.[[ViewedArrayBuffer]].
- Let elementType be
TypedArrayElementType (typedArray). - Return
GetModifySetValueInBuffer (buffer, byteIndexInBuffer, elementType, v, op).
25.4.3.18 ByteListBitwiseOp ( op, xBytes, yBytes )
The abstract operation ByteListBitwiseOp takes arguments op (&
, ^
, or |
), xBytes (a
Assert : xBytes and yBytes have the same number of elements.- Let result be a new empty
List . - Let i be 0.
- For each element xByte of xBytes, do
- Let yByte be yBytes[i].
- If op is
&
, then- Let resultByte be the result of applying the bitwise AND operation to xByte and yByte.
- Else if op is
^
, then- Let resultByte be the result of applying the bitwise exclusive OR (XOR) operation to xByte and yByte.
- Else,
Assert : op is|
.- Let resultByte be the result of applying the bitwise inclusive OR operation to xByte and yByte.
- Set i to i + 1.
- Append resultByte to result.
- Return result.
25.4.3.19 ByteListEqual ( xBytes, yBytes )
The abstract operation ByteListEqual takes arguments xBytes (a
- If xBytes and yBytes do not have the same number of elements, return
false . - Let i be 0.
- For each element xByte of xBytes, do
- Let yByte be yBytes[i].
- If xByte ≠ yByte, return
false . - Set i to i + 1.
- Return
true .
25.4.4 Atomics.add ( typedArray, index, value )
This function performs the following steps when called:
- Let type be
TypedArrayElementType (typedArray). - Let isLittleEndian be the value of the [[LittleEndian]] field of the
surrounding agent 'sAgent Record . - Let add be a new
read-modify-write modification function with parameters (xBytes, yBytes) that captures type and isLittleEndian and performs the following steps atomically when called:- Let x be
RawBytesToNumeric (type, xBytes, isLittleEndian). - Let y be
RawBytesToNumeric (type, yBytes, isLittleEndian). - If x
is a Number , then- Let sum be
Number::add (x, y).
- Let sum be
- Else,
Assert : xis a BigInt .- Let sum be
BigInt::add (x, y).
- Let sumBytes be
NumericToRawBytes (type, sum, isLittleEndian). Assert : sumBytes, xBytes, and yBytes have the same number of elements.- Return sumBytes.
- Let x be
- Return ?
AtomicReadModifyWrite (typedArray, index, value, add).
25.4.5 Atomics.and ( typedArray, index, value )
This function performs the following steps when called:
- Let and be a new
read-modify-write modification function with parameters (xBytes, yBytes) that captures nothing and performs the following steps atomically when called:- Return
ByteListBitwiseOp (&
, xBytes, yBytes).
- Return
- Return ?
AtomicReadModifyWrite (typedArray, index, value, and).
25.4.6 Atomics.compareExchange ( typedArray, index, expectedValue, replacementValue )
This function performs the following steps when called:
- Let byteIndexInBuffer be ?
ValidateAtomicAccessOnIntegerTypedArray (typedArray, index). - Let buffer be typedArray.[[ViewedArrayBuffer]].
- Let block be buffer.[[ArrayBufferData]].
- If typedArray.[[ContentType]] is
bigint , then - Else,
- Let expected be
𝔽 (?ToIntegerOrInfinity (expectedValue)). - Let replacement be
𝔽 (?ToIntegerOrInfinity (replacementValue)).
- Let expected be
- Perform ?
RevalidateAtomicAccess (typedArray, byteIndexInBuffer). - Let elementType be
TypedArrayElementType (typedArray). - Let elementSize be
TypedArrayElementSize (typedArray). - Let isLittleEndian be the value of the [[LittleEndian]] field of the
surrounding agent 'sAgent Record . - Let expectedBytes be
NumericToRawBytes (elementType, expected, isLittleEndian). - Let replacementBytes be
NumericToRawBytes (elementType, replacement, isLittleEndian). - If
IsSharedArrayBuffer (buffer) istrue , then- Let rawBytesRead be
AtomicCompareExchangeInSharedBlock (block, byteIndexInBuffer, elementSize, expectedBytes, replacementBytes).
- Let rawBytesRead be
- Else,
- Let rawBytesRead be a
List of length elementSize whose elements are the sequence of elementSize bytes starting with block[byteIndexInBuffer]. - If
ByteListEqual (rawBytesRead, expectedBytes) istrue , then- Store the individual bytes of replacementBytes into block, starting at block[byteIndexInBuffer].
- Let rawBytesRead be a
- Return
RawBytesToNumeric (elementType, rawBytesRead, isLittleEndian).
25.4.7 Atomics.exchange ( typedArray, index, value )
This function performs the following steps when called:
- Let second be a new
read-modify-write modification function with parameters (oldBytes, newBytes) that captures nothing and performs the following steps atomically when called:- Return newBytes.
- Return ?
AtomicReadModifyWrite (typedArray, index, value, second).
25.4.8 Atomics.isLockFree ( size )
This function performs the following steps when called:
- Let n be ?
ToIntegerOrInfinity (size). - Let AR be the
Agent Record of thesurrounding agent . - If n = 1, return AR.[[IsLockFree1]].
- If n = 2, return AR.[[IsLockFree2]].
- If n = 4, return
true . - If n = 8, return AR.[[IsLockFree8]].
- Return
false .
This function is an optimization primitive. The intuition is that if the atomic step of an atomic primitive (compareExchange
, load
, store
, add
, sub
, and
, or
, xor
, or exchange
) on a datum of size n bytes will be performed without the Atomics.isLockFree
(n) will return
Atomics.isLockFree
(4) always returns
Regardless of the value returned by this function, all atomic operations are guaranteed to be atomic. For example, they will never have a visible operation take place in the middle of the operation (e.g., "tearing").
25.4.9 Atomics.load ( typedArray, index )
This function performs the following steps when called:
- Let byteIndexInBuffer be ?
ValidateAtomicAccessOnIntegerTypedArray (typedArray, index). - Perform ?
RevalidateAtomicAccess (typedArray, byteIndexInBuffer). - Let buffer be typedArray.[[ViewedArrayBuffer]].
- Let elementType be
TypedArrayElementType (typedArray). - Return
GetValueFromBuffer (buffer, byteIndexInBuffer, elementType,true ,seq-cst ).
25.4.10 Atomics.or ( typedArray, index, value )
This function performs the following steps when called:
- Let or be a new
read-modify-write modification function with parameters (xBytes, yBytes) that captures nothing and performs the following steps atomically when called:- Return
ByteListBitwiseOp (|
, xBytes, yBytes).
- Return
- Return ?
AtomicReadModifyWrite (typedArray, index, value, or).
25.4.11 Atomics.store ( typedArray, index, value )
This function performs the following steps when called:
- Let byteIndexInBuffer be ?
ValidateAtomicAccessOnIntegerTypedArray (typedArray, index). - If typedArray.[[ContentType]] is
bigint , let v be ?ToBigInt (value). - Otherwise, let v be
𝔽 (?ToIntegerOrInfinity (value)). - Perform ?
RevalidateAtomicAccess (typedArray, byteIndexInBuffer). - Let buffer be typedArray.[[ViewedArrayBuffer]].
- Let elementType be
TypedArrayElementType (typedArray). - Perform
SetValueInBuffer (buffer, byteIndexInBuffer, elementType, v,true ,seq-cst ). - Return v.
25.4.12 Atomics.sub ( typedArray, index, value )
This function performs the following steps when called:
- Let type be
TypedArrayElementType (typedArray). - Let isLittleEndian be the value of the [[LittleEndian]] field of the
surrounding agent 'sAgent Record . - Let subtract be a new
read-modify-write modification function with parameters (xBytes, yBytes) that captures type and isLittleEndian and performs the following steps atomically when called:- Let x be
RawBytesToNumeric (type, xBytes, isLittleEndian). - Let y be
RawBytesToNumeric (type, yBytes, isLittleEndian). - If x
is a Number , then- Let difference be
Number::subtract (x, y).
- Let difference be
- Else,
Assert : xis a BigInt .- Let difference be
BigInt::subtract (x, y).
- Let differenceBytes be
NumericToRawBytes (type, difference, isLittleEndian). Assert : differenceBytes, xBytes, and yBytes have the same number of elements.- Return differenceBytes.
- Let x be
- Return ?
AtomicReadModifyWrite (typedArray, index, value, subtract).
25.4.13 Atomics.wait ( typedArray, index, value, timeout )
This function puts the
It performs the following steps when called:
- Return ?
DoWait (sync , typedArray, index, value, timeout).
25.4.14 Atomics.waitAsync ( typedArray, index, value, timeout )
This function returns a Promise that is resolved when the calling
It performs the following steps when called:
- Return ?
DoWait (async , typedArray, index, value, timeout).
25.4.15 Atomics.notify ( typedArray, index, count )
This function notifies some
It performs the following steps when called:
- Let byteIndexInBuffer be ?
ValidateAtomicAccessOnIntegerTypedArray (typedArray, index,true ). - If count is
undefined , then- Let c be +∞.
- Else,
- Let intCount be ?
ToIntegerOrInfinity (count). - Let c be
max (intCount, 0).
- Let intCount be ?
- Let buffer be typedArray.[[ViewedArrayBuffer]].
- Let block be buffer.[[ArrayBufferData]].
- If
IsSharedArrayBuffer (buffer) isfalse , return+0 𝔽. - Let WL be
GetWaiterList (block, byteIndexInBuffer). - Perform
EnterCriticalSection (WL). - Let S be
RemoveWaiters (WL, c). - For each element W of S, do
- Perform
NotifyWaiter (WL, W).
- Perform
- Perform
LeaveCriticalSection (WL). - Let n be the number of elements in S.
- Return
𝔽 (n).
25.4.16 Atomics.xor ( typedArray, index, value )
This function performs the following steps when called:
- Let xor be a new
read-modify-write modification function with parameters (xBytes, yBytes) that captures nothing and performs the following steps atomically when called:- Return
ByteListBitwiseOp (^
, xBytes, yBytes).
- Return
- Return ?
AtomicReadModifyWrite (typedArray, index, value, xor).
25.4.17 Atomics [ @@toStringTag ]
The initial value of the
This property has the attributes { [[Writable]]: