Skip to content

Commit 94a146d

Browse files
committed
Normative: Allow Atomics methods to work on ArrayBuffers.
Allow Atomics methods to work on ArrayBuffers in a fully deterministic fashion. Atomics.wait still throws when used on ArrayBuffers, while Atomics.notify always returns 0.
1 parent f114433 commit 94a146d

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

spec.html

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36958,23 +36958,26 @@ <h1>SetValueInBuffer ( _arrayBuffer_, _byteIndex_, _type_, _value_, _isTypedArra
3695836958

3695936959
<emu-clause id="sec-getmodifysetvalueinbuffer" aoid="GetModifySetValueInBuffer">
3696036960
<h1>GetModifySetValueInBuffer ( _arrayBuffer_, _byteIndex_, _type_, _value_, _op_ [ , _isLittleEndian_ ] )</h1>
36961-
<p>The abstract operation GetModifySetValueInBuffer takes six parameters, a SharedArrayBuffer _arrayBuffer_, a nonnegative integer _byteIndex_, a TypedArray element type _type_, a Number or BigInt _value_, a read-modify-write modification function _op_, and optionally a Boolean _isLittleEndian_. This operation performs the following steps:</p>
36961+
<p>The abstract operation GetModifySetValueInBuffer takes six parameters, an ArrayBuffer or SharedArrayBuffer _arrayBuffer_, a nonnegative integer _byteIndex_, a TypedArray element type _type_, a Number or BigInt _value_, a read-modify-write modification function _op_, and optionally a Boolean _isLittleEndian_. This operation performs the following steps:</p>
3696236962
<emu-alg>
36963-
1. Assert: IsSharedArrayBuffer(_arrayBuffer_) is *true*.
3696436963
1. Assert: There are sufficient bytes in _arrayBuffer_ starting at _byteIndex_ to represent a value of _type_.
3696536964
1. Assert: ! IsNonNegativeInteger(_byteIndex_) is *true*.
3696636965
1. Assert: Type(_value_) is BigInt if ! IsBigIntElementType(_type_) is *true*; otherwise, Type(_value_) is Number.
3696736966
1. Let _block_ be _arrayBuffer_.[[ArrayBufferData]].
3696836967
1. Let _elementSize_ be the Element Size value specified in <emu-xref href="#table-the-typedarray-constructors"></emu-xref> for Element Type _type_.
3696936968
1. If _isLittleEndian_ is not present, set _isLittleEndian_ to the value of the [[LittleEndian]] field of the surrounding agent's Agent Record.
3697036969
1. Let _rawBytes_ be NumericToRawBytes(_type_, _value_, _isLittleEndian_).
36971-
1. Let _execution_ be the [[CandidateExecution]] field of the surrounding agent's Agent Record.
36972-
1. Let _eventList_ be the [[EventList]] field of the element in _execution_.[[EventsRecords]] whose [[AgentSignifier]] is AgentSignifier().
36973-
1. Let _rawBytesRead_ be a List of length _elementSize_ of nondeterministically chosen byte values.
36974-
1. 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.
36975-
1. Let _rmwEvent_ be ReadModifyWriteSharedMemory { [[Order]]: ~SeqCst~, [[NoTear]]: *true*, [[Block]]: _block_, [[ByteIndex]]: _byteIndex_, [[ElementSize]]: _elementSize_, [[Payload]]: _rawBytes_, [[ModifyOp]]: _op_ }.
36976-
1. Append _rmwEvent_ to _eventList_.
36977-
1. Append Chosen Value Record { [[Event]]: _rmwEvent_, [[ChosenValue]]: _rawBytesRead_ } to _execution_.[[ChosenValues]].
36970+
1. If IsSharedArrayBuffer(_arrayBuffer_) is *true*, then
36971+
1. Let _execution_ be the [[CandidateExecution]] field of the surrounding agent's Agent Record.
36972+
1. Let _eventList_ be the [[EventList]] field of the element in _execution_.[[EventsRecords]] whose [[AgentSignifier]] is AgentSignifier().
36973+
1. Let _rawBytesRead_ be a List of length _elementSize_ of nondeterministically chosen byte values.
36974+
1. 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.
36975+
1. Let _rmwEvent_ be ReadModifyWriteSharedMemory { [[Order]]: ~SeqCst~, [[NoTear]]: *true*, [[Block]]: _block_, [[ByteIndex]]: _byteIndex_, [[ElementSize]]: _elementSize_, [[Payload]]: _rawBytes_, [[ModifyOp]]: _op_ }.
36976+
1. Append _rmwEvent_ to _eventList_.
36977+
1. Append Chosen Value Record { [[Event]]: _rmwEvent_, [[ChosenValue]]: _rawBytesRead_ } to _execution_.[[ChosenValues]].
36978+
1. Else,
36979+
1. Let _rawBytesAtIndex_ be a List of _elementSize_ containing, in order, the _elementSize_ sequence of bytes starting with _block_[_byteIndex_].
36980+
1. Let _rawBytesRead_ be _op_(_rawBytesAtIndex_, _rawBytes_).
3697836981
1. Return RawBytesToNumeric(_type_, _rawBytesRead_, _isLittleEndian_).
3697936982
</emu-alg>
3698036983
</emu-clause>
@@ -37996,6 +37999,7 @@ <h1>Atomics.wait ( _typedArray_, _index_, _value_, _timeout_ )</h1>
3799637999
<p>`Atomics.wait` puts the calling agent in a wait queue and puts it to sleep until it is notified or the sleep times out. The following steps are taken:</p>
3799738000
<emu-alg>
3799838001
1. Let _buffer_ be ? ValidateIntegerTypedArray(_typedArray_, *true*).
38002+
1. If IsSharedArrayBuffer(_buffer_) is *false*, throw a *TypeError* exception.
3799938003
1. Let _i_ be ? ValidateAtomicAccess(_typedArray_, _index_).
3800038004
1. Let _arrayTypeName_ be _typedArray_.[[TypedArrayName]].
3800138005
1. If _arrayTypeName_ is *"BigInt64Array"*, let _v_ be ? ToBigInt64(_value_).
@@ -38042,6 +38046,7 @@ <h1>Atomics.notify ( _typedArray_, _index_, _count_ )</h1>
3804238046
1. Let _arrayTypeName_ be _typedArray_.[[TypedArrayName]].
3804338047
1. Let _elementSize_ be the Element Size value specified in <emu-xref href="#table-the-typedarray-constructors"></emu-xref> for _arrayTypeName_.
3804438048
1. Let _indexedPosition_ be (_i_ &times; _elementSize_) + _offset_.
38049+
1. If IsSharedArrayBuffer(_buffer_) is *false*, return 0.
3804538050
1. Let _WL_ be GetWaiterList(_block_, _indexedPosition_).
3804638051
1. Let _n_ be 0.
3804738052
1. Perform EnterCriticalSection(_WL_).

0 commit comments

Comments
 (0)