ECMA-262 (12th Edition) ECMAScript 2021 Language Specification - page 54

 

  Главная      Manuals     ECMA-262 (12th Edition) ECMAScript 2021 Language Specification

 

Search            copyright infringement  

 

 

 

 

 

 

 

 

 

 

 

Content      ..     52      53      54      55     ..

 

 

 

ECMA-262 (12th Edition) ECMAScript 2021 Language Specification - page 54

 

 

The following steps are taken:

1.  Let 

M

 be the 

this

 value.

2.  Perform ? 

RequireInternalSlot

(

M

, [[WeakMapData]]).

3.  Let 

entries

 be the 

List

 that is 

M

.[[WeakMapData]].

4.  If 

Type

(

key

) is not Object, return 

false

.

5.  For each 

Record

 { [[Key]], [[Value]] } 

p

 of 

entries

, do

a.  If 

p

.[[Key]] is not 

empty

 and 

SameValue

(

p

.[[Key]], 

key

) is 

true

, then

i.  Set 

p

.[[Key]] to 

empty

.

ii.  Set 

p

.[[Value]] to 

empty

.

iii.  Return 

true

.

6.  Return 

false

.

NOTE

The following steps are taken:

1.  Let 

M

 be the 

this

 value.

2.  Perform ? 

RequireInternalSlot

(

M

, [[WeakMapData]]).

3.  Let 

entries

 be the 

List

 that is 

M

.[[WeakMapData]].

4.  If 

Type

(

key

) is not Object, return 

undefined

.

5.  For each 

Record

 { [[Key]], [[Value]] } 

p

 of 

entries

, do

a.  If 

p

.[[Key]] is not 

empty

 and 

SameValue

(

p

.[[Key]], 

key

) is 

true

, return 

p

.[[Value]].

6.  Return 

undefined

.

The following steps are taken:

1.  Let 

M

 be the 

this

 value.

2.  Perform ? 

RequireInternalSlot

(

M

, [[WeakMapData]]).

3.  Let 

entries

 be the 

List

 that is 

M

.[[WeakMapData]].

4.  If 

Type

(

key

) is not Object, return 

false

.

5.  For each 

Record

 { [[Key]], [[Value]] } 

p

 of 

entries

, do

a.  If 

p

.[[Key]] is not 

empty

 and 

SameValue

(

p

.[[Key]], 

key

) is 

true

, return 

true

.

6.  Return 

false

.

The following steps are taken:

1.  Let 

M

 be the 

this

 value.

2.  Perform ? 

RequireInternalSlot

(

M

, [[WeakMapData]]).

3.  Let 

entries

 be the 

List

 that is 

M

.[[WeakMapData]].

The value 

empty

 is used as a specification device to indicate that an entry has been deleted.

Actual implementations may take other actions such as physically removing the entry from
internal data structures.

24.3.3.3  WeakMap.prototype.get ( 

key

 )

24.3.3.4  WeakMap.prototype.has ( 

key

 )

24.3.3.5  WeakMap.prototype.set ( 

key

value

 )

704

4.  If 

Type

(

key

) is not Object, throw a 

TypeError

 exception.

5.  For each 

Record

 { [[Key]], [[Value]] } 

p

 of 

entries

, do

a.  If 

p

.[[Key]] is not 

empty

 and 

SameValue

(

p

.[[Key]], 

key

) is 

true

, then

i.  Set 

p

.[[Value]] to 

value

.

ii.  Return 

M

.

6.  Let 

p

 be the 

Record

 { [[Key]]: 

key

, [[Value]]: 

value

 }.

7.  Append 

p

 as the last element of 

entries

.

8.  Return 

M

.

The initial value of the 

@@toStringTag

 property is the String value 

"WeakMap"

.

This property has the attributes { [[Writable]]: 

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

true

 }.

WeakMap instances are ordinary objects that inherit properties from the WeakMap prototype. WeakMap instances
also have a [[WeakMapData]] internal slot.

WeakSet objects are collections of objects. A distinct object may only occur once as an element of a WeakSet's
collection. A WeakSet may be queried to see if it contains a specific object, but no mechanism is provided for
enumerating the objects it holds. In certain conditions, objects which are not 

live

 are removed as WeakSet elements, as

described in 

9.9.3

.

An implementation may impose an arbitrarily determined latency between the time an object contained in a WeakSet
becomes inaccessible and the time when the object is removed from the WeakSet. If this latency was observable to
ECMAScript program, it would be a source of indeterminacy that could impact program execution. For that reason,
an ECMAScript implementation must not provide any means to determine if a WeakSet contains a particular object
that does not require the observer to present the observed object.

WeakSet objects must be implemented using either hash tables or other mechanisms that, on average, provide access
times that are sublinear on the number of elements in the collection. The data structure used in this WeakSet objects
specification is only intended to describe the required observable semantics of WeakSet objects. It is not intended to be
a viable implementation model.

NOTE

The WeakSet 

constructor

:

is 

%WeakSet%

.

is the initial value of the 

"WeakSet"

 property of the 

global object

.

creates and initializes a new WeakSet object when called as a 

constructor

.

See the NOTE in 

24.3

.

24.3.3.6  WeakMap.prototype [ @@toStringTag ]

24.3.4  Properties of WeakMap Instances

24.4  WeakSet Objects

24.4.1  The WeakSet Constructor

705

is not intended to be called as a function and will throw an exception when called in that manner.
is designed to be subclassable. It may be used as the value in an 

extends

extends

 clause of a class definition. Subclass

constructors that intend to inherit the specified WeakSet behaviour must include a 

super

super

 call to the WeakSet

constructor

 to create and initialize the subclass instance with the internal state necessary to support the

WeakSet.prototype

WeakSet.prototype

 built-in methods.

When the 

WeakSet

WeakSet

 function is called with optional argument 

iterable

, the following steps are taken:

1.  If NewTarget is 

undefined

, throw a 

TypeError

 exception.

2.  Let 

set

 be ? 

OrdinaryCreateFromConstructor

(NewTarget, 

"%WeakSet.prototype%"

, « [[WeakSetData]] »).

3.  Set 

set

.[[WeakSetData]] to a new empty 

List

.

4.  If 

iterable

 is either 

undefined

 or 

null

, return 

set

.

5.  Let 

adder

 be ? 

Get

(

set

"add"

).

6.  If 

IsCallable

(

adder

) is 

false

, throw a 

TypeError

 exception.

7.  Let 

iteratorRecord

 be ? 

GetIterator

(

iterable

).

8.  Repeat,

a.  Let 

next

 be ? 

IteratorStep

(

iteratorRecord

).

b.  If 

next

 is 

false

, return 

set

.

c.  Let 

nextValue

 be ? 

IteratorValue

(

next

).

d.  Let 

status

 be 

Call

(

adder

set

, « 

nextValue

 »).

e.  If 

status

 is an 

abrupt completion

, return ? 

IteratorClose

(

iteratorRecord

status

).

The WeakSet 

constructor

:

has a [[Prototype]] internal slot whose value is 

%Function.prototype%

.

has the following properties:

The initial value of 

WeakSet.prototype

WeakSet.prototype

 is the 

WeakSet prototype object

.

This property has the attributes { [[Writable]]: 

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }.

The 

WeakSet prototype object

:

is 

%WeakSet.prototype%

.

has a [[Prototype]] internal slot whose value is 

%Object.prototype%

.

is an 

ordinary object

.

does not have a [[WeakSetData]] internal slot.

The following steps are taken:

24.4.1.1  WeakSet ( [ 

iterable

 ] )

24.4.2  Properties of the WeakSet Constructor

24.4.2.1  WeakSet.prototype

24.4.3  Properties of the WeakSet Prototype Object

24.4.3.1  WeakSet.prototype.add ( 

value

 )

706

1.  Let 

S

 be the 

this

 value.

2.  Perform ? 

RequireInternalSlot

(

S

, [[WeakSetData]]).

3.  If 

Type

(

value

) is not Object, throw a 

TypeError

 exception.

4.  Let 

entries

 be the 

List

 that is 

S

.[[WeakSetData]].

5.  For each element 

e

 of 

entries

, do

a.  If 

e

 is not 

empty

 and 

SameValue

(

e

value

) is 

true

, then

i.  Return 

S

.

6.  Append 

value

 as the last element of 

entries

.

7.  Return 

S

.

The initial value of 

WeakSet.prototype.constructor

WeakSet.prototype.constructor

 is the 

%WeakSet%

 intrinsic object.

The following steps are taken:

1.  Let 

S

 be the 

this

 value.

2.  Perform ? 

RequireInternalSlot

(

S

, [[WeakSetData]]).

3.  If 

Type

(

value

) is not Object, return 

false

.

4.  Let 

entries

 be the 

List

 that is 

S

.[[WeakSetData]].

5.  For each element 

e

 of 

entries

, do

a.  If 

e

 is not 

empty

 and 

SameValue

(

e

value

) is 

true

, then

i.  Replace the element of 

entries

 whose value is 

e

 with an element whose value is 

empty

.

ii.  Return 

true

.

6.  Return 

false

.

NOTE

The following steps are taken:

1.  Let 

S

 be the 

this

 value.

2.  Perform ? 

RequireInternalSlot

(

S

, [[WeakSetData]]).

3.  Let 

entries

 be the 

List

 that is 

S

.[[WeakSetData]].

4.  If 

Type

(

value

) is not Object, return 

false

.

5.  For each element 

e

 of 

entries

, do

a.  If 

e

 is not 

empty

 and 

SameValue

(

e

value

) is 

true

, return 

true

.

6.  Return 

false

.

The initial value of the 

@@toStringTag

 property is the String value 

"WeakSet"

.

The value 

empty

 is used as a specification device to indicate that an entry has been deleted.

Actual implementations may take other actions such as physically removing the entry from
internal data structures.

24.4.3.2  WeakSet.prototype.constructor

24.4.3.3  WeakSet.prototype.delete ( 

value

 )

24.4.3.4  WeakSet.prototype.has ( 

value

 )

24.4.3.5  WeakSet.prototype [ @@toStringTag ]

707

This property has the attributes { [[Writable]]: 

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

true

 }.

WeakSet instances are ordinary objects that inherit properties from the WeakSet prototype. WeakSet instances also
have a [[WeakSetData]] internal slot.

The descriptions below in this section, 

25.4

, and 

29

 use the read-modify-write modification function internal data

structure.

read-modify-write modification function

 is a mathematical function that is notationally represented as an abstract

closure that takes two Lists of byte values as arguments and returns a 

List

 of byte values. These abstract closures

satisfy all of the following properties:

They perform all their algorithm steps atomically.
Their individual algorithm steps are not observable.

NOTE

The abstract operation AllocateArrayBuffer takes arguments 

constructor

 and 

byteLength

 (a non-negative 

integer

). It is

used to create an ArrayBuffer object. It performs the following steps when called:

1.  Let 

obj

 be ? 

OrdinaryCreateFromConstructor

(

constructor

"%ArrayBuffer.prototype%"

, « [[ArrayBufferData]],

[[ArrayBufferByteLength]], [[ArrayBufferDetachKey]] »).

2.  Let 

block

 be ? 

CreateByteDataBlock

(

byteLength

).

3.  Set 

obj

.[[ArrayBufferData]] to 

block

.

4.  Set 

obj

.[[ArrayBufferByteLength]] to 

byteLength

.

5.  Return 

obj

.

To aid verifying that a read-modify-write modification function's algorithm steps constitute a
pure, mathematical function, the following editorial conventions are recommended:

They do not access, directly or transitively via invoked 

abstract operations

 and abstract

closures, any language or specification values except their parameters and captured
values.
They do not return completion values.

24.4.4  Properties of WeakSet Instances

25  Structured Data

25.1  ArrayBuffer Objects

25.1.1  Notation

25.1.2  Abstract Operations For ArrayBuffer Objects

25.1.2.1  AllocateArrayBuffer ( 

constructor

byteLength

 )

708

The abstract operation IsDetachedBuffer takes argument 

arrayBuffer

. It performs the following steps when called:

1. 

Assert

Type

(

arrayBuffer

) is Object and it has an [[ArrayBufferData]] internal slot.

2.  If 

arrayBuffer

.[[ArrayBufferData]] is 

null

, return 

true

.

3.  Return 

false

.

The abstract operation DetachArrayBuffer takes argument 

arrayBuffer

 and optional argument 

key

. It performs the

following steps when called:

1. 

Assert

Type

(

arrayBuffer

) is Object and it has [[ArrayBufferData]], [[ArrayBufferByteLength]], and

[[ArrayBufferDetachKey]] internal slots.

2. 

Assert

IsSharedArrayBuffer

(

arrayBuffer

) is 

false

.

3.  If 

key

 is not present, set 

key

 to 

undefined

.

4.  If 

SameValue

(

arrayBuffer

.[[ArrayBufferDetachKey]], 

key

) is 

false

, throw a 

TypeError

 exception.

5.  Set 

arrayBuffer

.[[ArrayBufferData]] to 

null

.

6.  Set 

arrayBuffer

.[[ArrayBufferByteLength]] to 0.

7.  Return 

NormalCompletion

(

null

).

NOTE

The abstract operation CloneArrayBuffer takes arguments 

srcBuffer

 (an ArrayBuffer object), 

srcByteOffset

 (a non-

negative 

integer

), 

srcLength

 (a non-negative 

integer

), and 

cloneConstructor

 (a 

constructor

). It creates a new ArrayBuffer

whose data is a copy of 

srcBuffer

's data over the range starting at 

srcByteOffset

 and continuing for 

srcLength

 bytes. It

performs the following steps when called:

1. 

Assert

Type

(

srcBuffer

) is Object and it has an [[ArrayBufferData]] internal slot.

2. 

Assert

IsConstructor

(

cloneConstructor

) is 

true

.

3.  Let 

targetBuffer

 be ? 

AllocateArrayBuffer

(

cloneConstructor

srcLength

).

4.  If 

IsDetachedBuffer

(

srcBuffer

) is 

true

, throw a 

TypeError

 exception.

5.  Let 

srcBlock

 be 

srcBuffer

.[[ArrayBufferData]].

6.  Let 

targetBlock

 be 

targetBuffer

.[[ArrayBufferData]].

7.  Perform 

CopyDataBlockBytes

(

targetBlock

, 0, 

srcBlock

srcByteOffset

srcLength

).

8.  Return 

targetBuffer

.

The abstract operation IsUnsignedElementType takes argument 

type

. It verifies if the argument 

type

 is an unsigned

TypedArray element type

. It performs the following steps when called:

1.  If 

type

 is 

Uint8

Uint8C

Uint16

Uint32

, or 

BigUint64

, return 

true

.

Detaching an ArrayBuffer instance disassociates the 

Data Block

 used as its backing store from the

instance and sets the byte length of the buffer to 0. No operations defined by this specification
use the DetachArrayBuffer abstract operation. However, an ECMAScript 

host

 or implementation

may define such operations.

25.1.2.2  IsDetachedBuffer ( 

arrayBuffer

 )

25.1.2.3  DetachArrayBuffer ( 

arrayBuffer

 [ , 

key

 ] )

25.1.2.4  CloneArrayBuffer ( 

srcBuffer

srcByteOffset

srcLength

cloneConstructor

 )

25.1.2.5  IsUnsignedElementType ( 

type

 )

709

2.  Return 

false

.

The abstract operation IsUnclampedIntegerElementType takes argument 

type

. It verifies if the argument 

type

 is an

Integer

 

TypedArray element type

 not including 

Uint8C

. It performs the following steps when called:

1.  If 

type

 is 

Int8

Uint8

Int16

Uint16

Int32

, or 

Uint32

, return 

true

.

2.  Return 

false

.

The abstract operation IsBigIntElementType takes argument 

type

. It verifies if the argument 

type

 is a BigInt

TypedArray element type

. It performs the following steps when called:

1.  If 

type

 is 

BigUint64

 or 

BigInt64

, return 

true

.

2.  Return 

false

.

The abstract operation IsNoTearConfiguration takes arguments 

type

 and 

order

. It performs the following steps when

called:

1.  If ! 

IsUnclampedIntegerElementType

(

type

) is 

true

, return 

true

.

2.  If ! 

IsBigIntElementType

(

type

) is 

true

 and 

order

 is not 

Init

 or 

Unordered

, return 

true

.

3.  Return 

false

.

The abstract operation RawBytesToNumeric takes arguments 

type

 (a 

TypedArray element type

), 

rawBytes

 (a 

List

), and

isLittleEndian

 (a Boolean). It performs the following steps when called:

1.  Let 

elementSize

 be the Element Size value specified in 

Table 60

 for Element Type 

type

.

2.  If 

isLittleEndian

 is 

false

, reverse the order of the elements of 

rawBytes

.

3.  If 

type

 is 

Float32

, then

a.  Let 

value

 be the byte elements of 

rawBytes

 concatenated and interpreted as a little-endian bit string

encoding of an 

IEEE 754-2019

 binary32 value.

b.  If 

value

 is an 

IEEE 754-2019

 binary32 NaN value, return the 

NaN

 

Number value

.

c.  Return the 

Number value

 that corresponds to 

value

.

4.  If 

type

 is 

Float64

, then

a.  Let 

value

 be the byte elements of 

rawBytes

 concatenated and interpreted as a little-endian bit string

encoding of an 

IEEE 754-2019

 binary64 value.

b.  If 

value

 is an 

IEEE 754-2019

 binary64 NaN value, return the 

NaN

 

Number value

.

c.  Return the 

Number value

 that corresponds to 

value

.

5.  If ! 

IsUnsignedElementType

(

type

) is 

true

, then

a.  Let 

intValue

 be the byte elements of 

rawBytes

 concatenated and interpreted as a bit string encoding of an

unsigned little-endian binary number.

6.  Else,

a.  Let 

intValue

 be the byte elements of 

rawBytes

 concatenated and interpreted as a bit string encoding of a

25.1.2.6  IsUnclampedIntegerElementType ( 

type

 )

25.1.2.7  IsBigIntElementType ( 

type

 )

25.1.2.8  IsNoTearConfiguration ( 

type

order

 )

25.1.2.9  RawBytesToNumeric ( 

type

rawBytes

isLittleEndian

 )

710

binary little-endian two's complement number of bit length 

elementSize

 

×

 8.

7.  If ! 

IsBigIntElementType

(

type

) is 

true

, return the BigInt value that corresponds to 

intValue

.

8.  Otherwise, return the 

Number value

 that corresponds to 

intValue

.

The abstract operation GetValueFromBuffer takes arguments 

arrayBuffer

 (an ArrayBuffer or SharedArrayBuffer),

byteIndex

 (a non-negative 

integer

), 

type

 (a 

TypedArray element type

), 

isTypedArray

 (a Boolean), and 

order

 (either

SeqCst

 or 

Unordered

) and optional argument 

isLittleEndian

 (a Boolean). It performs the following steps when called:

1. 

Assert

IsDetachedBuffer

(

arrayBuffer

) is 

false

.

2. 

Assert

: There are sufficient bytes in 

arrayBuffer

 starting at 

byteIndex

 to represent a value of 

type

.

3.  Let 

block

 be 

arrayBuffer

.[[ArrayBufferData]].

4.  Let 

elementSize

 be the Element Size value specified in 

Table 60

 for Element Type 

type

.

5.  If 

IsSharedArrayBuffer

(

arrayBuffer

) is 

true

, then

a.  Let 

execution

 be the [[CandidateExecution]] field of the 

surrounding agent

's 

Agent Record

.

b.  Let 

eventList

 be the [[EventList]] field of the element in 

execution

.[[EventsRecords]] whose

[[AgentSignifier]] is 

AgentSignifier

().

c.  If 

isTypedArray

 is 

true

 and 

IsNoTearConfiguration

(

type

order

) is 

true

, let 

noTear

 be 

true

; otherwise let

noTear

 be 

false

.

d.  Let 

rawValue

 be a 

List

 of length 

elementSize

 whose elements are nondeterministically chosen byte values.

e.  NOTE: In implementations, 

rawValue

 is the result of a non-atomic or atomic read instruction on the

underlying hardware. The nondeterminism is a semantic prescription of the 

memory model

 to describe

observable behaviour of hardware with weak consistency.

f.  Let 

readEvent

 be 

ReadSharedMemory

 { [[Order]]: 

order

, [[NoTear]]: 

noTear

, [[Block]]: 

block

, [[ByteIndex]]:

byteIndex

, [[ElementSize]]: 

elementSize

 }.

g.  Append 

readEvent

 to 

eventList

.

h.  Append 

Chosen Value Record

 { [[Event]]: 

readEvent

, [[ChosenValue]]: 

rawValue

 } to 

execution

.

[[ChosenValues]].

6.  Else, let 

rawValue

 be a 

List

 whose elements are bytes from 

block

 at indices 

byteIndex

 (inclusive) through 

byteIndex

elementSize

 (exclusive).

7. 

Assert

: The number of elements in 

rawValue

 is 

elementSize

.

8.  If 

isLittleEndian

 is not present, set 

isLittleEndian

 to the value of the [[LittleEndian]] field of the 

surrounding

agent

's 

Agent Record

.

9.  Return 

RawBytesToNumeric

(

type

rawValue

isLittleEndian

).

The abstract operation NumericToRawBytes takes arguments 

type

 (a 

TypedArray element type

), 

value

 (a BigInt or a

Number), and 

isLittleEndian

 (a Boolean). It performs the following steps when called:

1.  If 

type

 is 

Float32

, then

a.  Let 

rawBytes

 be a 

List

 whose elements are the 4 bytes that are the result of converting 

value

 to 

IEEE 754-

2019

 binary32 format using roundTiesToEven mode. If 

isLittleEndian

 is 

false

, the bytes are arranged in

big endian order. Otherwise, the bytes are arranged in little endian order. If 

value

 is 

NaN

rawBytes

 may

be set to any implementation chosen 

IEEE 754-2019

 binary32 format Not-a-Number encoding. An

implementation must always choose the same encoding for each implementation distinguishable 

NaN

value.

25.1.2.10  GetValueFromBuffer ( 

arrayBuffer

byteIndex

type

isTypedArray

order

 [ , 

isLittleEndian

 ] )

25.1.2.11  NumericToRawBytes ( 

type

value

isLittleEndian

 )

711

2.  Else if 

type

 is 

Float64

, then

a.  Let 

rawBytes

 be a 

List

 whose elements are the 8 bytes that are the 

IEEE 754-2019

 binary64 format

encoding of 

value

. If 

isLittleEndian

 is 

false

, the bytes are arranged in big endian order. Otherwise, the

bytes are arranged in little endian order. If 

value

 is 

NaN

rawBytes

 may be set to any implementation

chosen 

IEEE 754-2019

 binary64 format Not-a-Number encoding. An implementation must always

choose the same encoding for each implementation distinguishable 

NaN

 value.

3.  Else,

a.  Let 

n

 be the Element Size value specified in 

Table 60

 for Element Type 

type

.

b.  Let 

convOp

 be the abstract operation named in the Conversion Operation column in 

Table 60

 for

Element Type 

type

.

c.  Let 

intValue

convOp

(

value

)).

d.  If 

intValue

 

 0, then

i.  Let 

rawBytes

 be a 

List

 whose elements are the 

n

-byte binary encoding of 

intValue

. If 

isLittleEndian

is 

false

, the bytes are ordered in big endian order. Otherwise, the bytes are ordered in little

endian order.

e.  Else,

i.  Let 

rawBytes

 be a 

List

 whose elements are the 

n

-byte binary two's complement encoding of

intValue

. If 

isLittleEndian

 is 

false

, the bytes are ordered in big endian order. Otherwise, the bytes

are ordered in little endian order.

4.  Return 

rawBytes

.

The abstract operation SetValueInBuffer takes arguments 

arrayBuffer

 (an ArrayBuffer or SharedArrayBuffer), 

byteIndex

(a non-negative 

integer

), 

type

 (a 

TypedArray element type

), 

value

 (a Number or a BigInt), 

isTypedArray

 (a Boolean), and

order

 (one of 

SeqCst

Unordered

, or 

Init

) and optional argument 

isLittleEndian

 (a Boolean). It performs the following

steps when called:

1. 

Assert

IsDetachedBuffer

(

arrayBuffer

) is 

false

.

2. 

Assert

: There are sufficient bytes in 

arrayBuffer

 starting at 

byteIndex

 to represent a value of 

type

.

3. 

Assert

Type

(

value

) is BigInt if ! 

IsBigIntElementType

(

type

) is 

true

; otherwise, 

Type

(

value

) is Number.

4.  Let 

block

 be 

arrayBuffer

.[[ArrayBufferData]].

5.  Let 

elementSize

 be the Element Size value specified in 

Table 60

 for Element Type 

type

.

6.  If 

isLittleEndian

 is not present, set 

isLittleEndian

 to the value of the [[LittleEndian]] field of the 

surrounding

agent

's 

Agent Record

.

7.  Let 

rawBytes

 be 

NumericToRawBytes

(

type

value

isLittleEndian

).

8.  If 

IsSharedArrayBuffer

(

arrayBuffer

) is 

true

, then

a.  Let 

execution

 be the [[CandidateExecution]] field of the 

surrounding agent

's 

Agent Record

.

b.  Let 

eventList

 be the [[EventList]] field of the element in 

execution

.[[EventsRecords]] whose

[[AgentSignifier]] is 

AgentSignifier

().

c.  If 

isTypedArray

 is 

true

 and 

IsNoTearConfiguration

(

type

order

) is 

true

, let 

noTear

 be 

true

; otherwise let

noTear

 be 

false

.

d.  Append 

WriteSharedMemory

 { [[Order]]: 

order

, [[NoTear]]: 

noTear

, [[Block]]: 

block

, [[ByteIndex]]:

byteIndex

, [[ElementSize]]: 

elementSize

, [[Payload]]: 

rawBytes

 } to 

eventList

.

9.  Else, store the individual bytes of 

rawBytes

 into 

block

, starting at 

block

[

byteIndex

].

10.  Return 

NormalCompletion

(

undefined

).

25.1.2.12  SetValueInBuffer ( 

arrayBuffer

byteIndex

type

value

isTypedArray

order

 [ , 

isLittleEndian

 ] )

25.1.2.13  GetModifySetValueInBuffer ( 

arrayBuffer

byteIndex

type

value

op

 [ , 

isLittleEndian

 ] )

712

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:

1. 

Assert

IsDetachedBuffer

(

arrayBuffer

) is 

false

.

2. 

Assert

: There are sufficient bytes in 

arrayBuffer

 starting at 

byteIndex

 to represent a value of 

type

.

3. 

Assert

Type

(

value

) is BigInt if ! 

IsBigIntElementType

(

type

) is 

true

; otherwise, 

Type

(

value

) is Number.

4.  Let 

block

 be 

arrayBuffer

.[[ArrayBufferData]].

5.  Let 

elementSize

 be the Element Size value specified in 

Table 60

 for Element Type 

type

.

6.  If 

isLittleEndian

 is not present, set 

isLittleEndian

 to the value of the [[LittleEndian]] field of the 

surrounding

agent

's 

Agent Record

.

7.  Let 

rawBytes

 be 

NumericToRawBytes

(

type

value

isLittleEndian

).

8.  If 

IsSharedArrayBuffer

(

arrayBuffer

) is 

true

, then

a.  Let 

execution

 be the [[CandidateExecution]] field of the 

surrounding agent

's 

Agent Record

.

b.  Let 

eventList

 be the [[EventList]] field of the element in 

execution

.[[EventsRecords]] whose

[[AgentSignifier]] is 

AgentSignifier

().

c.  Let 

rawBytesRead

 be a 

List

 of length 

elementSize

 whose elements are nondeterministically chosen byte

values.

d.  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.

e.  Let 

rmwEvent

 be 

ReadModifyWriteSharedMemory

 { [[Order]]: 

SeqCst

, [[NoTear]]: 

true

, [[Block]]: 

block

,

[[ByteIndex]]: 

byteIndex

, [[ElementSize]]: 

elementSize

, [[Payload]]: 

rawBytes

, [[ModifyOp]]: 

op

 }.

f.  Append 

rmwEvent

 to 

eventList

.

g.  Append 

Chosen Value Record

 { [[Event]]: 

rmwEvent

, [[ChosenValue]]: 

rawBytesRead

 } to 

execution

.

[[ChosenValues]].

9.  Else,

a.  Let 

rawBytesRead

 be a 

List

 of length 

elementSize

 whose elements are the sequence of 

elementSize

 bytes

starting with 

block

[

byteIndex

].

b.  Let 

rawBytesModified

 be 

op

(

rawBytesRead

rawBytes

).

c.  Store the individual bytes of 

rawBytesModified

 into 

block

, starting at 

block

[

byteIndex

].

10.  Return 

RawBytesToNumeric

(

type

rawBytesRead

isLittleEndian

).

The ArrayBuffer 

constructor

:

is 

%ArrayBuffer%

.

is the initial value of the 

"ArrayBuffer"

 property of the 

global object

.

creates and initializes a new ArrayBuffer object when called as a 

constructor

.

is not intended to be called as a function and will throw an exception when called in that manner.
is designed to be subclassable. It may be used as the value of an 

extends

extends

 clause of a class definition. Subclass

constructors that intend to inherit the specified ArrayBuffer behaviour must include a 

super

super

 call to the

ArrayBuffer 

constructor

 to create and initialize subclass instances with the internal state necessary to support

the 

ArrayBuffer.prototype

ArrayBuffer.prototype

 built-in methods.

25.1.3  The ArrayBuffer Constructor

713

When the 

ArrayBuffer

ArrayBuffer

 function is called with argument 

length

, the following steps are taken:

1.  If NewTarget is 

undefined

, throw a 

TypeError

 exception.

2.  Let 

byteLength

 be ? 

ToIndex

(

length

).

3.  Return ? 

AllocateArrayBuffer

(NewTarget, 

byteLength

).

The ArrayBuffer 

constructor

:

has a [[Prototype]] internal slot whose value is 

%Function.prototype%

.

has the following properties:

The 

isView

isView

 function takes one argument 

arg

, and performs the following steps:

1.  If 

Type

(

arg

) is not Object, return 

false

.

2.  If 

arg

 has a [[ViewedArrayBuffer]] internal slot, return 

true

.

3.  Return 

false

.

The initial value of 

ArrayBuffer.prototype

ArrayBuffer.prototype

 is the 

ArrayBuffer prototype object

.

This property has the attributes { [[Writable]]: 

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }.

ArrayBuffer[@@species]

ArrayBuffer[@@species]

 is an 

accessor property

 whose set accessor function is 

undefined

. Its get accessor

function performs the following steps:

1.  Return the 

this

 value.

The value of the 

"name"

 property of this function is 

"get [Symbol.species]"

.

NOTE

The 

ArrayBuffer prototype object

:

is 

%ArrayBuffer.prototype%

.

has a [[Prototype]] internal slot whose value is 

%Object.prototype%

.

is an 

ordinary object

.

does not have an [[ArrayBufferData]] or [[ArrayBufferByteLength]] internal slot.

ArrayBuffer prototype methods normally use their 

this

 value's 

constructor

 to create a derived

object. However, a subclass 

constructor

 may over-ride that default behaviour by redefining its

@@species

 property.

25.1.3.1  ArrayBuffer ( 

length

 )

25.1.4  Properties of the ArrayBuffer Constructor

25.1.4.1  ArrayBuffer.isView ( 

arg

 )

25.1.4.2  ArrayBuffer.prototype

25.1.4.3  get ArrayBuffer [ @@species ]

25.1.5  Properties of the ArrayBuffer Prototype Object

714

ArrayBuffer.prototype.byteLength

ArrayBuffer.prototype.byteLength

 is an 

accessor property

 whose set accessor function is 

undefined

. Its

get accessor function performs the following steps:

1.  Let 

O

 be the 

this

 value.

2.  Perform ? 

RequireInternalSlot

(

O

, [[ArrayBufferData]]).

3.  If 

IsSharedArrayBuffer

(

O

) is 

true

, throw a 

TypeError

 exception.

4.  If 

IsDetachedBuffer

(

O

) is 

true

, return 

+0

𝔽

.

5.  Let 

length

 be 

O

.[[ArrayBufferByteLength]].

6.  Return 

length

).

The initial value of 

ArrayBuffer.prototype.constructor

ArrayBuffer.prototype.constructor

 is 

%ArrayBuffer%

.

The following steps are taken:

1.  Let 

O

 be the 

this

 value.

2.  Perform ? 

RequireInternalSlot

(

O

, [[ArrayBufferData]]).

3.  If 

IsSharedArrayBuffer

(

O

) is 

true

, throw a 

TypeError

 exception.

4.  If 

IsDetachedBuffer

(

O

) is 

true

, throw a 

TypeError

 exception.

5.  Let 

len

 be 

O

.[[ArrayBufferByteLength]].

6.  Let 

relativeStart

 be ? 

ToIntegerOrInfinity

(

start

).

7.  If 

relativeStart

 is -

, let 

first

 be 0.

8.  Else if 

relativeStart

 < 0, let 

first

 be 

max

(

len

 + 

relativeStart

, 0).

9.  Else, let 

first

 be 

min

(

relativeStart

len

).

10.  If 

end

 is 

undefined

, let 

relativeEnd

 be 

len

; else let 

relativeEnd

 be ? 

ToIntegerOrInfinity

(

end

).

11.  If 

relativeEnd

 is -

, let 

final

 be 0.

12.  Else if 

relativeEnd

 < 0, let 

final

 be 

max

(

len

 + 

relativeEnd

, 0).

13.  Else, let 

final

 be 

min

(

relativeEnd

len

).

14.  Let 

newLen

 be 

max

(

final

 - 

first

, 0).

15.  Let 

ctor

 be ? 

SpeciesConstructor

(

O

%ArrayBuffer%

).

16.  Let 

new

 be ? 

Construct

(

ctor

, « 

(

newLen

) »).

17.  Perform ? 

RequireInternalSlot

(

new

, [[ArrayBufferData]]).

18.  If 

IsSharedArrayBuffer

(

new

) is 

true

, throw a 

TypeError

 exception.

19.  If 

IsDetachedBuffer

(

new

) is 

true

, throw a 

TypeError

 exception.

20.  If 

SameValue

(

new

O

) is 

true

, throw a 

TypeError

 exception.

21.  If 

new

.[[ArrayBufferByteLength]] < 

newLen

, throw a 

TypeError

 exception.

22.  NOTE: Side-effects of the above steps may have detached 

O

.

23.  If 

IsDetachedBuffer

(

O

) is 

true

, throw a 

TypeError

 exception.

24.  Let 

fromBuf

 be 

O

.[[ArrayBufferData]].

25.  Let 

toBuf

 be 

new

.[[ArrayBufferData]].

26.  Perform 

CopyDataBlockBytes

(

toBuf

, 0, 

fromBuf

first

newLen

).

27.  Return 

new

.

25.1.5.1  get ArrayBuffer.prototype.byteLength

25.1.5.2  ArrayBuffer.prototype.constructor

25.1.5.3  ArrayBuffer.prototype.slice ( 

start

end

 )

25.1.5.4  ArrayBuffer.prototype [ @@toStringTag ]

715

The initial value of the 

@@toStringTag

 property is the String value 

"ArrayBuffer"

.

This property has the attributes { [[Writable]]: 

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

true

 }.

ArrayBuffer instances inherit properties from the 

ArrayBuffer prototype object

. ArrayBuffer instances each have an

[[ArrayBufferData]] internal slot, an [[ArrayBufferByteLength]] internal slot, and an [[ArrayBufferDetachKey]]
internal slot.

ArrayBuffer instances whose [[ArrayBufferData]] is 

null

 are considered to be detached and all operators to access or

modify data contained in the ArrayBuffer instance will fail.

ArrayBuffer instances whose [[ArrayBufferDetachKey]] is set to a value other than 

undefined

 need to have all

DetachArrayBuffer

 calls passing that same "detach key" as an argument, otherwise a TypeError will result. This

internal slot is only ever set by certain embedding environments, not by algorithms in this specification.

The abstract operation AllocateSharedArrayBuffer takes arguments 

constructor

 and 

byteLength

 (a non-negative

integer

). It is used to create a SharedArrayBuffer object. It performs the following steps when called:

1.  Let 

obj

 be ? 

OrdinaryCreateFromConstructor

(

constructor

"%SharedArrayBuffer.prototype%"

, «

[[ArrayBufferData]], [[ArrayBufferByteLength]] »).

2.  Let 

block

 be ? 

CreateSharedByteDataBlock

(

byteLength

).

3.  Set 

obj

.[[ArrayBufferData]] to 

block

.

4.  Set 

obj

.[[ArrayBufferByteLength]] to 

byteLength

.

5.  Return 

obj

.

The abstract operation IsSharedArrayBuffer takes argument 

obj

. It tests whether an object is an ArrayBuffer, a

SharedArrayBuffer, or a subtype of either. It performs the following steps when called:

1. 

Assert

Type

(

obj

) is Object and it has an [[ArrayBufferData]] internal slot.

2.  Let 

bufferData

 be 

obj

.[[ArrayBufferData]].

3.  If 

bufferData

 is 

null

, return 

false

.

4.  If 

bufferData

 is a 

Data Block

, return 

false

.

5. 

Assert

bufferData

 is a 

Shared Data Block

.

6.  Return 

true

.

The SharedArrayBuffer 

constructor

:

25.1.6  Properties of ArrayBuffer Instances

25.2  SharedArrayBuffer Objects

25.2.1  Abstract Operations for SharedArrayBuffer Objects

25.2.1.1  AllocateSharedArrayBuffer ( 

constructor

byteLength

 )

25.2.1.2  IsSharedArrayBuffer ( 

obj

 )

25.2.2  The SharedArrayBuffer Constructor

716

is 

%SharedArrayBuffer%

.

is the initial value of the 

"SharedArrayBuffer"

 property of the 

global object

, if that property is present (see

below).
creates and initializes a new SharedArrayBuffer object when called as a 

constructor

.

is not intended to be called as a function and will throw an exception when called in that manner.
is designed to be subclassable. It may be used as the value of an 

extends

extends

 clause of a class definition. Subclass

constructors that intend to inherit the specified SharedArrayBuffer behaviour must include a 

super

super

 call to the

SharedArrayBuffer 

constructor

 to create and initialize subclass instances with the internal state necessary to

support the 

SharedArrayBuffer.prototype

SharedArrayBuffer.prototype

 built-in methods.

Whenever a 

host

 does not provide concurrent access to SharedArrayBuffer objects it may omit the

"SharedArrayBuffer"

 property of the 

global object

.

NOTE

When the 

SharedArrayBuffer

SharedArrayBuffer

 function is called with optional argument 

length

, the following steps are taken:

1.  If NewTarget is 

undefined

, throw a 

TypeError

 exception.

2.  Let 

byteLength

 be ? 

ToIndex

(

length

).

3.  Return ? 

AllocateSharedArrayBuffer

(NewTarget, 

byteLength

).

The SharedArrayBuffer 

constructor

:

has a [[Prototype]] internal slot whose value is 

%Function.prototype%

.

has the following properties:

The initial value of 

SharedArrayBuffer.prototype

SharedArrayBuffer.prototype

 is the 

SharedArrayBuffer prototype object

.

This property has the attributes { [[Writable]]: 

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }.

SharedArrayBuffer[@@species]

SharedArrayBuffer[@@species]

 is an 

accessor property

 whose set accessor function is 

undefined

. Its get

accessor function performs the following steps:

1.  Return the 

this

 value.

The value of the 

"name"

 property of this function is 

"get [Symbol.species]"

.

The 

SharedArrayBuffer prototype object

:

Unlike an 

ArrayBuffer

ArrayBuffer

, a 

SharedArrayBuffer

SharedArrayBuffer

 cannot become detached, and its

internal [[ArrayBufferData]] slot is never 

null

.

25.2.2.1  SharedArrayBuffer ( [ 

length

 ] )

25.2.3  Properties of the SharedArrayBuffer Constructor

25.2.3.1  SharedArrayBuffer.prototype

25.2.3.2  get SharedArrayBuffer [ @@species ]

25.2.4  Properties of the SharedArrayBuffer Prototype Object

717

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.

SharedArrayBuffer.prototype.byteLength

SharedArrayBuffer.prototype.byteLength

 is an 

accessor property

 whose set accessor function is

undefined

. Its get accessor function performs the following steps:

1.  Let 

O

 be the 

this

 value.

2.  Perform ? 

RequireInternalSlot

(

O

, [[ArrayBufferData]]).

3.  If 

IsSharedArrayBuffer

(

O

) is 

false

, throw a 

TypeError

 exception.

4.  Let 

length

 be 

O

.[[ArrayBufferByteLength]].

5.  Return 

length

).

The initial value of 

SharedArrayBuffer.prototype.constructor

SharedArrayBuffer.prototype.constructor

 is 

%SharedArrayBuffer%

.

The following steps are taken:

1.  Let 

O

 be the 

this

 value.

2.  Perform ? 

RequireInternalSlot

(

O

, [[ArrayBufferData]]).

3.  If 

IsSharedArrayBuffer

(

O

) is 

false

, throw a 

TypeError

 exception.

4.  Let 

len

 be 

O

.[[ArrayBufferByteLength]].

5.  Let 

relativeStart

 be ? 

ToIntegerOrInfinity

(

start

).

6.  If 

relativeStart

 is -

, let 

first

 be 0.

7.  Else if 

relativeStart

 < 0, let 

first

 be 

max

(

len

 + 

relativeStart

, 0).

8.  Else, let 

first

 be 

min

(

relativeStart

len

).

9.  If 

end

 is 

undefined

, let 

relativeEnd

 be 

len

; else let 

relativeEnd

 be ? 

ToIntegerOrInfinity

(

end

).

10.  If 

relativeEnd

 is -

, let 

final

 be 0.

11.  Else if 

relativeEnd

 < 0, let 

final

 be 

max

(

len

 + 

relativeEnd

, 0).

12.  Else, let 

final

 be 

min

(

relativeEnd

len

).

13.  Let 

newLen

 be 

max

(

final

 - 

first

, 0).

14.  Let 

ctor

 be ? 

SpeciesConstructor

(

O

%SharedArrayBuffer%

).

15.  Let 

new

 be ? 

Construct

(

ctor

, « 

(

newLen

) »).

16.  Perform ? 

RequireInternalSlot

(

new

, [[ArrayBufferData]]).

17.  If 

IsSharedArrayBuffer

(

new

) is 

false

, throw a 

TypeError

 exception.

18.  If 

new

.[[ArrayBufferData]] and 

O

.[[ArrayBufferData]] are the same 

Shared Data Block

 values, throw a

TypeError

 exception.

19.  If 

new

.[[ArrayBufferByteLength]] < 

newLen

, throw a 

TypeError

 exception.

20.  Let 

fromBuf

 be 

O

.[[ArrayBufferData]].

21.  Let 

toBuf

 be 

new

.[[ArrayBufferData]].

22.  Perform 

CopyDataBlockBytes

(

toBuf

, 0, 

fromBuf

first

newLen

).

23.  Return 

new

.

25.2.4.1  get SharedArrayBuffer.prototype.byteLength

25.2.4.2  SharedArrayBuffer.prototype.constructor

25.2.4.3  SharedArrayBuffer.prototype.slice ( 

start

end

 )

718

The initial value of the 

@@toStringTag

 property is the String value 

"SharedArrayBuffer"

.

This property has the attributes { [[Writable]]: 

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

true

 }.

SharedArrayBuffer instances inherit properties from the 

SharedArrayBuffer prototype object

. SharedArrayBuffer

instances each have an [[ArrayBufferData]] internal slot and an [[ArrayBufferByteLength]] internal slot.

NOTE

The abstract operation GetViewValue takes arguments 

view

requestIndex

isLittleEndian

, and 

type

. It is used by

functions on DataView instances to retrieve values from the view's buffer. It performs the following steps when called:

1.  Perform ? 

RequireInternalSlot

(

view

, [[DataView]]).

2. 

Assert

view

 has a [[ViewedArrayBuffer]] internal slot.

3.  Let 

getIndex

 be ? 

ToIndex

(

requestIndex

).

4.  Set 

isLittleEndian

 to ! 

ToBoolean

(

isLittleEndian

).

5.  Let 

buffer

 be 

view

.[[ViewedArrayBuffer]].

6.  If 

IsDetachedBuffer

(

buffer

) is 

true

, throw a 

TypeError

 exception.

7.  Let 

viewOffset

 be 

view

.[[ByteOffset]].

8.  Let 

viewSize

 be 

view

.[[ByteLength]].

9.  Let 

elementSize

 be the Element Size value specified in 

Table 60

 for Element Type 

type

.

10.  If 

getIndex

 + 

elementSize

 > 

viewSize

, throw a 

RangeError

 exception.

11.  Let 

bufferIndex

 be 

getIndex

 + 

viewOffset

.

12.  Return 

GetValueFromBuffer

(

buffer

bufferIndex

type

false

Unordered

isLittleEndian

).

The abstract operation SetViewValue takes arguments 

view

requestIndex

isLittleEndian

type

, and 

value

. It is used by

functions on DataView instances to store values into the view's buffer. It performs the following steps when called:

1.  Perform ? 

RequireInternalSlot

(

view

, [[DataView]]).

2. 

Assert

view

 has a [[ViewedArrayBuffer]] internal slot.

3.  Let 

getIndex

 be ? 

ToIndex

(

requestIndex

).

4.  If ! 

IsBigIntElementType

(

type

) is 

true

, let 

numberValue

 be ? 

ToBigInt

(

value

).

5.  Otherwise, let 

numberValue

 be ? 

ToNumber

(

value

).

6.  Set 

isLittleEndian

 to ! 

ToBoolean

(

isLittleEndian

).

7.  Let 

buffer

 be 

view

.[[ViewedArrayBuffer]].

SharedArrayBuffer instances, unlike ArrayBuffer instances, are never detached.

25.2.4.4  SharedArrayBuffer.prototype [ @@toStringTag ]

25.2.5  Properties of SharedArrayBuffer Instances

25.3  DataView Objects

25.3.1  Abstract Operations For DataView Objects

25.3.1.1  GetViewValue ( 

view

requestIndex

isLittleEndian

type

 )

25.3.1.2  SetViewValue ( 

view

requestIndex

isLittleEndian

type

value

 )

719

 

 

 

 

 

 

 

Content      ..     52      53      54      55     ..