25.2 SharedArrayBuffer Objects
25.2.1 Abstract Operations for SharedArrayBuffer Objects
25.2.1.1 AllocateSharedArrayBuffer ( constructor, byteLength )
The abstract operation AllocateSharedArrayBuffer takes arguments constructor (a
- Let obj be ?
OrdinaryCreateFromConstructor (constructor,"%SharedArrayBuffer.prototype%" , « [[ArrayBufferData]], [[ArrayBufferByteLength]] »). - Let block be ?
CreateSharedByteDataBlock (byteLength). - Set obj.[[ArrayBufferData]] to block.
- Set obj.[[ArrayBufferByteLength]] to byteLength.
- Return obj.
25.2.1.2 IsSharedArrayBuffer ( obj )
The abstract operation IsSharedArrayBuffer takes argument obj (an ArrayBuffer or a SharedArrayBuffer) and returns a Boolean. It tests whether an object is an ArrayBuffer, a SharedArrayBuffer, or a subtype of either. It performs the following steps when called:
- Let bufferData be obj.[[ArrayBufferData]].
- If bufferData is
null , returnfalse . - If bufferData is a
Data Block , returnfalse . Assert : bufferData is aShared Data Block .- Return
true .
25.2.2 The SharedArrayBuffer Constructor
The SharedArrayBuffer
- is %SharedArrayBuffer%.
- is the initial value of the
"SharedArrayBuffer" property of theglobal object , if that property is present (see below). - creates and initializes a new SharedArrayBuffer when called as a
constructor . - is not intended to be called as a function and will throw an exception when called in that manner.
- may be used as the value of an
extends
clause of a class definition. Subclassconstructors that intend to inherit the specified SharedArrayBuffer behaviour must include asuper
call to the SharedArrayBufferconstructor to create and initialize subclass instances with the internal state necessary to support theSharedArrayBuffer.prototype
built-in methods.
Whenever a
Unlike an ArrayBuffer
, a SharedArrayBuffer
cannot become detached, and its internal [[ArrayBufferData]] slot is never
25.2.2.1 SharedArrayBuffer ( length )
This function performs the following steps when called:
- If NewTarget is
undefined , throw aTypeError exception. - Let byteLength be ?
ToIndex (length). - Return ?
AllocateSharedArrayBuffer (NewTarget, byteLength).
25.2.3 Properties of the SharedArrayBuffer Constructor
The SharedArrayBuffer
- has a [[Prototype]] internal slot whose value is
%Function.prototype% . - has the following properties:
25.2.3.1 SharedArrayBuffer.prototype
The initial value of SharedArrayBuffer.prototype
is the
This property has the attributes { [[Writable]]:
25.2.3.2 get SharedArrayBuffer [ @@species ]
SharedArrayBuffer[@@species]
is an
- Return the
this value.
The value of the
25.2.4 Properties of the SharedArrayBuffer Prototype Object
The SharedArrayBuffer prototype object:
- is %SharedArrayBuffer.prototype%.
- has a [[Prototype]] internal slot whose value is
%Object.prototype% . - is an
ordinary object . - does not have an [[ArrayBufferData]] or [[ArrayBufferByteLength]] internal slot.
25.2.4.1 get SharedArrayBuffer.prototype.byteLength
SharedArrayBuffer.prototype.byteLength
is an
- Let O be the
this value. - Perform ?
RequireInternalSlot (O, [[ArrayBufferData]]). - If
IsSharedArrayBuffer (O) isfalse , throw aTypeError exception. - Let length be O.[[ArrayBufferByteLength]].
- Return
𝔽 (length).
25.2.4.2 SharedArrayBuffer.prototype.constructor
The initial value of SharedArrayBuffer.prototype.constructor
is
25.2.4.3 SharedArrayBuffer.prototype.slice ( start, end )
This method performs the following steps when called:
- Let O be the
this value. - Perform ?
RequireInternalSlot (O, [[ArrayBufferData]]). - If
IsSharedArrayBuffer (O) isfalse , throw aTypeError exception. - Let len be O.[[ArrayBufferByteLength]].
- Let relativeStart be ?
ToIntegerOrInfinity (start). - If relativeStart = -∞, let first be 0.
- Else if relativeStart < 0, let first be
max (len + relativeStart, 0). - Else, let first be
min (relativeStart, len). - If end is
undefined , let relativeEnd be len; else let relativeEnd be ?ToIntegerOrInfinity (end). - If relativeEnd = -∞, let final be 0.
- Else if relativeEnd < 0, let final be
max (len + relativeEnd, 0). - Else, let final be
min (relativeEnd, len). - Let newLen be
max (final - first, 0). - Let ctor be ?
SpeciesConstructor (O,%SharedArrayBuffer% ). - Let new be ?
Construct (ctor, «𝔽 (newLen) »). - Perform ?
RequireInternalSlot (new, [[ArrayBufferData]]). - If
IsSharedArrayBuffer (new) isfalse , throw aTypeError exception. - If new.[[ArrayBufferData]] is O.[[ArrayBufferData]], throw a
TypeError exception. - If new.[[ArrayBufferByteLength]] < newLen, throw a
TypeError exception. - Let fromBuf be O.[[ArrayBufferData]].
- Let toBuf be new.[[ArrayBufferData]].
- Perform
CopyDataBlockBytes (toBuf, 0, fromBuf, first, newLen). - Return new.
25.2.4.4 SharedArrayBuffer.prototype [ @@toStringTag ]
The initial value of the
This property has the attributes { [[Writable]]:
25.2.5 Properties of SharedArrayBuffer Instances
SharedArrayBuffer instances inherit properties from the
SharedArrayBuffer instances, unlike ArrayBuffer instances, are never detached.