You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Normative: Allow Atomics methods to work on ArrayBuffers (tc39#1908)
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.
<p>The abstract operation GetModifySetValueInBuffer takes arguments _arrayBuffer_ (a SharedArrayBuffer object), _byteIndex_ (a non-negative integer), _type_ (a TypedArray element type), _value_ (a Number or a BigInt), and _op_ (a read-modify-write modification function) and optional argument _isLittleEndian_ (a Boolean). It performs the following steps when called:</p>
37490
+
<p>The abstract operation GetModifySetValueInBuffer takes arguments _arrayBuffer_ (an ArrayBuffer object or a SharedArrayBuffer object), _byteIndex_ (a non-negative integer), _type_ (a TypedArray element type), _value_ (a Number or a BigInt), and _op_ (a read-modify-write modification function) and optional argument _isLittleEndian_ (a Boolean). It performs the following steps when called:</p>
37491
37491
<emu-alg>
37492
-
1. Assert: IsSharedArrayBuffer(_arrayBuffer_) is *true*.
37492
+
1. Assert: IsDetachedBuffer(_arrayBuffer_) is *false*.
37493
37493
1. Assert: There are sufficient bytes in _arrayBuffer_ starting at _byteIndex_ to represent a value of _type_.
37494
37494
1. Assert: ! IsNonNegativeInteger(_byteIndex_) is *true*.
37495
37495
1. Assert: Type(_value_) is BigInt if ! IsBigIntElementType(_type_) is *true*; otherwise, Type(_value_) is Number.
37496
37496
1. Let _block_ be _arrayBuffer_.[[ArrayBufferData]].
37497
37497
1. Let _elementSize_ be the Element Size value specified in <emu-xref href="#table-the-typedarray-constructors"></emu-xref> for Element Type _type_.
37498
37498
1. If _isLittleEndian_ is not present, set _isLittleEndian_ to the value of the [[LittleEndian]] field of the surrounding agent's Agent Record.
37499
37499
1. Let _rawBytes_ be NumericToRawBytes(_type_, _value_, _isLittleEndian_).
37500
-
1. Let _execution_ be the [[CandidateExecution]] field of the surrounding agent's Agent Record.
37501
-
1. Let _eventList_ be the [[EventList]] field of the element in _execution_.[[EventsRecords]] whose [[AgentSignifier]] is AgentSignifier().
37502
-
1. Let _rawBytesRead_ be a List of length _elementSize_ of nondeterministically chosen byte values.
37503
-
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.
1. Append Chosen Value Record { [[Event]]: _rmwEvent_, [[ChosenValue]]: _rawBytesRead_ } to _execution_.[[ChosenValues]].
37500
+
1. If IsSharedArrayBuffer(_arrayBuffer_) is *true*, then
37501
+
1. Let _execution_ be the [[CandidateExecution]] field of the surrounding agent's Agent Record.
37502
+
1. Let _eventList_ be the [[EventList]] field of the element in _execution_.[[EventsRecords]] whose [[AgentSignifier]] is AgentSignifier().
37503
+
1. Let _rawBytesRead_ be a List of length _elementSize_ of nondeterministically chosen byte values.
37504
+
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.
<p>The abstract operation ValidateSharedIntegerTypedArray takes argument _typedArray_ and optional argument _waitable_ (a Boolean). It performs the following steps when called:</p>
<p>The abstract operation ValidateIntegerTypedArray takes argument _typedArray_ and optional argument _waitable_ (a Boolean). It performs the following steps when called:</p>
38182
38187
<emu-alg>
38183
38188
1. If _waitable_ is not present, set _waitable_ to *false*.
<p>The abstract operation AtomicReadModifyWrite takes arguments _typedArray_, _index_, _value_, and _op_ (a read-modify-write modification function). _op_ takes two List of byte values arguments and returns a List of byte values. This operation atomically loads a value, combines it with another value, and stores the result of the combination. It returns the loaded value. It performs the following steps when called:</p>
38326
38328
<emu-alg>
38327
-
1. Let _buffer_ be ? ValidateSharedIntegerTypedArray(_typedArray_).
38329
+
1. Let _buffer_ be ? ValidateIntegerTypedArray(_typedArray_).
38328
38330
1. Let _i_ be ? ValidateAtomicAccess(_typedArray_, _index_).
38329
38331
1. Let _arrayTypeName_ be _typedArray_.[[TypedArrayName]].
38330
38332
1. If _typedArray_.[[ContentType]] is ~BigInt~, let _v_ be ? ToBigInt(_value_).
38331
38333
1. Otherwise, let _v_ be ? ToInteger(_value_).
38334
+
1. If IsDetachedBuffer(_buffer_) is *true*, throw a *TypeError* exception.
38335
+
1. NOTE: The above check is not redundant with the check in ValidateIntegerTypedArray because the call to ToBigInt or ToInteger on the preceding lines can have arbitrary side effects, which could cause the buffer to become detached.
38332
38336
1. Let _elementSize_ be the Element Size value specified in <emu-xref href="#table-the-typedarray-constructors"></emu-xref> for _arrayTypeName_.
38333
38337
1. Let _elementType_ be the Element Type value in <emu-xref href="#table-the-typedarray-constructors"></emu-xref> for _arrayTypeName_.
<p>The abstract operation AtomicLoad takes arguments _typedArray_ and _index_. It atomically loads a value and returns the loaded value. It performs the following steps when called:</p>
38343
38347
<emu-alg>
38344
-
1. Let _buffer_ be ? ValidateSharedIntegerTypedArray(_typedArray_).
38348
+
1. Let _buffer_ be ? ValidateIntegerTypedArray(_typedArray_).
38345
38349
1. Let _i_ be ? ValidateAtomicAccess(_typedArray_, _index_).
38350
+
1. If IsDetachedBuffer(_buffer_) is *true*, throw a *TypeError* exception.
38351
+
1. NOTE: The above check is not redundant with the check in ValidateIntegerTypedArray because the call to ValidateAtomicAccess on the preceding line can have arbitrary side effects, which could cause the buffer to become detached.
38346
38352
1. Let _arrayTypeName_ be _typedArray_.[[TypedArrayName]].
38347
38353
1. Let _elementSize_ be the Element Size value specified in <emu-xref href="#table-the-typedarray-constructors"></emu-xref> for _arrayTypeName_.
38348
38354
1. Let _elementType_ be the Element Type value in <emu-xref href="#table-the-typedarray-constructors"></emu-xref> for _arrayTypeName_.
1. Let _expected_ be ? ToInteger(_expectedValue_).
38429
38435
1. Let _replacement_ be ? ToInteger(_replacementValue_).
38436
+
1. If IsDetachedBuffer(_buffer_) is *true*, throw a *TypeError* exception.
38437
+
1. NOTE: The above check is not redundant with the check in ValidateIntegerTypedArray because the call to ToBigInt or ToInteger on the preceding lines can have arbitrary side effects, which could cause the buffer to become detached.
38430
38438
1. Let _elementType_ be the Element Type value in <emu-xref href="#table-the-typedarray-constructors"></emu-xref> for _arrayTypeName_.
38431
38439
1. Let _isLittleEndian_ be the value of the [[LittleEndian]] field of the surrounding agent's Agent Record.
38432
38440
1. Let _expectedBytes_ be NumericToRawBytes(_elementType_, _expected_, _isLittleEndian_).
1. Let _buffer_ be ? ValidateSharedIntegerTypedArray(_typedArray_).
38501
+
1. Let _buffer_ be ? ValidateIntegerTypedArray(_typedArray_).
38494
38502
1. Let _i_ be ? ValidateAtomicAccess(_typedArray_, _index_).
38495
38503
1. Let _arrayTypeName_ be _typedArray_.[[TypedArrayName]].
38496
38504
1. If _arrayTypeName_ is *"BigUint64Array"* or *"BigInt64Array"*, let _v_ be ? ToBigInt(_value_).
38497
38505
1. Otherwise, let _v_ be ? ToInteger(_value_).
38506
+
1. If IsDetachedBuffer(_buffer_) is *true*, throw a *TypeError* exception.
38507
+
1. NOTE: The above check is not redundant with the check in ValidateIntegerTypedArray because the call to ToBigInt or ToInteger on the preceding lines can have arbitrary side effects, which could cause the buffer to become detached.
38498
38508
1. Let _elementSize_ be the Element Size value specified in <emu-xref href="#table-the-typedarray-constructors"></emu-xref> for _arrayTypeName_.
38499
38509
1. Let _elementType_ be the Element Type value in <emu-xref href="#table-the-typedarray-constructors"></emu-xref> for _arrayTypeName_.
<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>
38528
38538
<emu-alg>
38529
-
1. Let _buffer_ be ? ValidateSharedIntegerTypedArray(_typedArray_, *true*).
38539
+
1. Let _buffer_ be ? ValidateIntegerTypedArray(_typedArray_, *true*).
38540
+
1. If IsSharedArrayBuffer(_buffer_) is *false*, throw a *TypeError* exception.
38530
38541
1. Let _i_ be ? ValidateAtomicAccess(_typedArray_, _index_).
38531
38542
1. Let _arrayTypeName_ be _typedArray_.[[TypedArrayName]].
38532
38543
1. If _arrayTypeName_ is *"BigInt64Array"*, let _v_ be ? ToBigInt64(_value_).
0 commit comments