25 구조화된 데이터

25.1 ArrayBuffer 객체

25.1.1 표기법

이 section, 25.4, 및 29 안의 아래 descriptions는 read-modify-write modification function internal data structure를 사용합니다.

read-modify-write modification function은 two Lists of byte values를 arguments로 받아 List of byte values를 반환하는 Abstract Closure로 represented되는 mathematical function입니다. 이러한 Abstract Closures는 다음 properties를 모두 satisfy합니다:

  • 그들의 모든 algorithm steps를 atomically 수행합니다.
  • 그들의 individual algorithm steps는 observable하지 않습니다.
Note

read-modify-write modification function의 algorithm steps가 pure, mathematical function을 constitute하는지 verifying하는 데 도움을 주기 위해, 다음 editorial conventions가 recommended됩니다:

25.1.2 Fixed-length 및 Resizable ArrayBuffer 객체

fixed-length ArrayBuffer는 creation 후 byte length가 change될 수 없는 ArrayBuffer입니다.

resizable ArrayBufferArrayBuffer.prototype.resize ( newLength )에 대한 calls를 통해 creation 후 byte length가 change될 수 있는 ArrayBuffer입니다.

created되는 ArrayBuffer object의 kind는 ArrayBuffer ( length [ , options ] )에 passed된 arguments에 따라 달라집니다.

25.1.3 ArrayBuffer 객체를 위한 추상 연산

25.1.3.1 AllocateArrayBuffer ( ctor, byteLength [ , maxByteLength ] )

The abstract operation AllocateArrayBuffer takes arguments ctor (생성자) and byteLength (음이 아닌 정수) and optional argument maxByteLength (음이 아닌 정수 또는 empty) and returns ArrayBuffer를 포함하는 정상 완료 또는 throw 완료. ArrayBuffer를 만드는 데 사용된다. It performs the following steps when called:

  1. Let slots be « [[ArrayBufferData]], [[ArrayBufferByteLength]], [[ArrayBufferDetachKey]] ».
  2. If maxByteLength is present and maxByteLength is not empty, let allocatingResizableBuffer be true; else let allocatingResizableBuffer be false.
  3. If allocatingResizableBuffer is true, then
    1. If byteLength > maxByteLength, throw a RangeError exception.
    2. Append [[ArrayBufferMaxByteLength]] to slots.
  4. Let obj be ? OrdinaryCreateFromConstructor(ctor, "%ArrayBuffer.prototype%", slots).
  5. Let block be ? CreateByteDataBlock(byteLength).
  6. Set obj.[[ArrayBufferData]] to block.
  7. Set obj.[[ArrayBufferByteLength]] to byteLength.
  8. If allocatingResizableBuffer is true, then
    1. If it is not possible to create a Data Block block consisting of maxByteLength bytes, throw a RangeError exception.
    2. NOTE: Resizable ArrayBuffers are designed to be implementable with in-place growth. Implementations may throw if, for example, virtual memory cannot be reserved up front.
    3. Set obj.[[ArrayBufferMaxByteLength]] to maxByteLength.
  9. Return obj.

25.1.3.2 ArrayBufferByteLength ( arrayBuffer, order )

The abstract operation ArrayBufferByteLength takes arguments arrayBuffer (ArrayBuffer 또는 SharedArrayBuffer) and order (seq-cst 또는 unordered) and returns 음이 아닌 정수. It performs the following steps when called:

  1. IsGrowableSharedArrayBuffer(arrayBuffer)가 true이면,
    1. bufferByteLengthBlockarrayBuffer.[[ArrayBufferByteLengthData]]로 하라.
    2. rawLengthGetRawBytesFromSharedBlock(bufferByteLengthBlock, 0, biguint64, true, order)로 하라.
    3. agentRecordsurrounding agentAgent Record로 하라.
    4. isLittleEndianagentRecord.[[LittleEndian]]으로 하라.
    5. (RawBytesToNumeric(biguint64, rawLength, isLittleEndian))를 반환하라.
  2. Assert: IsDetachedBuffer(arrayBuffer)는 false이다.
  3. arrayBuffer.[[ArrayBufferByteLength]]를 반환하라.

25.1.3.3 ArrayBufferCopyAndDetach ( arrayBuffer, newLength, preserveResizability )

The abstract operation ArrayBufferCopyAndDetach takes arguments arrayBuffer (ECMAScript 언어 값), newLength (ECMAScript 언어 값), and preserveResizability (preserve-resizability 또는 fixed-length) and returns ArrayBuffer를 포함하는 정상 완료 또는 throw 완료. It performs the following steps when called:

  1. RequireInternalSlot(arrayBuffer, [[ArrayBufferData]])를 수행하라.
  2. IsSharedArrayBuffer(arrayBuffer)가 true이면, TypeError 예외를 던진다.
  3. newLengthundefined이면,
    1. newByteLengtharrayBuffer.[[ArrayBufferByteLength]]로 하라.
  4. 그렇지 않으면,
    1. newByteLength를 ? ToIndex(newLength)로 하라.
  5. IsDetachedBuffer(arrayBuffer)가 true이면, TypeError 예외를 던진다.
  6. preserveResizabilitypreserve-resizability이고 IsFixedLengthArrayBuffer(arrayBuffer)가 false이면,
    1. newMaxByteLengtharrayBuffer.[[ArrayBufferMaxByteLength]]로 하라.
  7. 그렇지 않으면,
    1. newMaxByteLengthempty로 하라.
  8. arrayBuffer.[[ArrayBufferDetachKey]]undefined가 아니면, TypeError 예외를 던진다.
  9. newBuffer를 ? AllocateArrayBuffer(%ArrayBuffer%, newByteLength, newMaxByteLength)로 하라.
  10. copyLengthmin(newByteLength, arrayBuffer.[[ArrayBufferByteLength]])로 하라.
  11. fromBlockarrayBuffer.[[ArrayBufferData]]로 하라.
  12. toBlocknewBuffer.[[ArrayBufferData]]로 하라.
  13. CopyDataBlockBytes(toBlock, 0, fromBlock, 0, copyLength)를 수행하라.
  14. NOTE: 새 Data Block의 생성도, 이전 Data Block에서의 복사도 관찰 가능하지 않다. 구현체는 이 메서드를 무복사 이동 또는 realloc으로 구현할 수 있다.
  15. DetachArrayBuffer(arrayBuffer)를 수행하라.
  16. newBuffer를 반환하라.

25.1.3.4 IsDetachedBuffer ( arrayBuffer )

The abstract operation IsDetachedBuffer takes argument arrayBuffer (ArrayBuffer 또는 SharedArrayBuffer) and returns Boolean. It performs the following steps when called:

  1. arrayBuffer.[[ArrayBufferData]]null이면, true를 반환하라.
  2. false를 반환하라.

25.1.3.5 DetachArrayBuffer ( arrayBuffer [ , key ] )

The abstract operation DetachArrayBuffer takes argument arrayBuffer (ArrayBuffer) and optional argument key (아무것) and returns unused를 포함하는 정상 완료 또는 throw 완료. It performs the following steps when called:

  1. Assert: IsSharedArrayBuffer(arrayBuffer)는 false이다.
  2. key가 존재하지 않으면, keyundefined로 설정하라.
  3. arrayBuffer.[[ArrayBufferDetachKey]]key가 아니면, TypeError 예외를 던진다.
  4. arrayBuffer.[[ArrayBufferData]]null로 설정하라.
  5. arrayBuffer.[[ArrayBufferByteLength]]를 0으로 설정하라.
  6. unused를 반환하라.
Note

ArrayBuffer 인스턴스를 detach하면 backing store로 사용되는 Data Block을 해당 인스턴스에서 분리하고 버퍼의 바이트 길이를 0으로 설정한다.

25.1.3.6 CloneArrayBuffer ( sourceBuffer, sourceByteOffset, sourceLength )

The abstract operation CloneArrayBuffer takes arguments sourceBuffer (ArrayBuffer 또는 SharedArrayBuffer), sourceByteOffset (음이 아닌 정수), and sourceLength (음이 아닌 정수) and returns ArrayBuffer를 포함하는 정상 완료 또는 throw 완료. sourceByteOffset에서 시작하여 sourceLength 바이트 동안 이어지는 범위에 걸친 sourceBuffer의 데이터 복사본을 데이터로 가지는 새 ArrayBuffer를 만든다. It performs the following steps when called:

  1. Assert: IsDetachedBuffer(sourceBuffer)는 false이다.
  2. targetBuffer를 ? AllocateArrayBuffer(%ArrayBuffer%, sourceLength)로 하라.
  3. sourceBlocksourceBuffer.[[ArrayBufferData]]로 하라.
  4. targetBlocktargetBuffer.[[ArrayBufferData]]로 하라.
  5. CopyDataBlockBytes(targetBlock, 0, sourceBlock, sourceByteOffset, sourceLength)를 수행하라.
  6. targetBuffer를 반환하라.

25.1.3.7 GetArrayBufferMaxByteLengthOption ( options )

The abstract operation GetArrayBufferMaxByteLengthOption takes argument options (an ECMAScript language value) and returns either a normal completion containing either a non-negative integer or empty, or a throw completion. It performs the following steps when called:

  1. options가 Object가 아니면, empty를 반환하라.
  2. maxByteLength를 ? Get(options, "maxByteLength")로 하라.
  3. maxByteLengthundefined이면, empty를 반환하라.
  4. ToIndex(maxByteLength)를 반환하라.

25.1.3.8 HostResizeArrayBuffer ( buffer, newByteLength )

The host-defined abstract operation HostResizeArrayBuffer takes arguments buffer (an ArrayBuffer) and newByteLength (a non-negative integer) and returns either a normal completion containing either handled or unhandled, or a throw completion. 호스트가 buffer의 구현 정의 크기 조정을 수행할 기회를 제공한다. 호스트가 buffer의 크기 조정을 처리하지 않기로 선택하면, 기본 동작을 위해 unhandled를 반환할 수 있다.

HostResizeArrayBuffer의 구현은 다음 요구사항을 준수해야 한다:

  • 이 추상 연산은 buffer를 detach하지 않는다.
  • 이 추상 연산이 handled로 정상 완료되면, buffer.[[ArrayBufferByteLength]]newByteLength이다.

HostResizeArrayBuffer의 기본 구현은 NormalCompletion(unhandled)를 반환하는 것이다.

25.1.3.9 IsFixedLengthArrayBuffer ( arrayBuffer )

The abstract operation IsFixedLengthArrayBuffer takes argument arrayBuffer (ArrayBuffer 또는 SharedArrayBuffer) and returns Boolean. It performs the following steps when called:

  1. arrayBuffer[[ArrayBufferMaxByteLength]] 내부 슬롯을 가지면, false를 반환하라.
  2. true를 반환하라.

25.1.3.10 IsUnsignedElementType ( type )

The abstract operation IsUnsignedElementType takes argument type (TypedArray 요소 타입) and returns Boolean. 인수 type이 부호 없는 TypedArray 요소 타입인지 검증한다. It performs the following steps when called:

  1. typeuint8, uint8clamped, uint16, uint32, 또는 biguint64 중 하나이면, true를 반환하라.
  2. false를 반환하라.

25.1.3.11 IsUnclampedIntegerElementType ( type )

The abstract operation IsUnclampedIntegerElementType takes argument type (TypedArray 요소 타입) and returns Boolean. 인수 typeuint8clamped를 포함하지 않는 Integer TypedArray 요소 타입인지 검증한다. It performs the following steps when called:

  1. typeint8, uint8, int16, uint16, int32, 또는 uint32 중 하나이면, true를 반환하라.
  2. false를 반환하라.

25.1.3.12 IsBigIntElementType ( type )

The abstract operation IsBigIntElementType takes argument type (TypedArray 요소 타입) and returns Boolean. 인수 type이 BigInt TypedArray 요소 타입인지 검증한다. It performs the following steps when called:

  1. typebiguint64 또는 bigint64이면, true를 반환하라.
  2. false를 반환하라.

25.1.3.13 IsNoTearConfiguration ( type, order )

The abstract operation IsNoTearConfiguration takes arguments type (a TypedArray element type) and order (seq-cst, unordered, or init) and returns a Boolean. It performs the following steps when called:

  1. IsUnclampedIntegerElementType(type)가 true이면, true를 반환하라.
  2. IsBigIntElementType(type)가 true이고 orderinitunordered도 아니면, true를 반환하라.
  3. false를 반환하라.

25.1.3.14 RawBytesToNumeric ( type, rawBytes, isLittleEndian )

The abstract operation RawBytesToNumeric takes arguments type (TypedArray 요소 타입), rawBytes (바이트 값의 List), and isLittleEndian (Boolean) and returns Number 또는 BigInt. It performs the following steps when called:

  1. elementSize를 Element Type type에 대해 Table 71에 명시된 Element Size 값으로 하라.
  2. isLittleEndianfalse이면, rawBytes의 요소 순서를 뒤집어라.
  3. typefloat16이면,
    1. valuerawBytes의 바이트 요소들을 연결하고 IEEE 754-2019 binary16 값의 리틀 엔디언 비트 문자열 인코딩으로 해석한 것으로 하라.
    2. value가 NaN이면, NaN을 반환하라.
    3. value에 해당하는 Number 값을 반환하라.
  4. typefloat32이면,
    1. valuerawBytes의 바이트 요소들을 연결하고 IEEE 754-2019 binary32 값의 리틀 엔디언 비트 문자열 인코딩으로 해석한 것으로 하라.
    2. value가 NaN이면, NaN을 반환하라.
    3. value에 해당하는 Number 값을 반환하라.
  5. typefloat64이면,
    1. valuerawBytes의 바이트 요소들을 연결하고 IEEE 754-2019 binary64 값의 리틀 엔디언 비트 문자열 인코딩으로 해석한 것으로 하라.
    2. value가 NaN이면, NaN을 반환하라.
    3. value에 해당하는 Number 값을 반환하라.
  6. IsUnsignedElementType(type)가 true이면,
    1. intValuerawBytes의 바이트 요소들을 연결하고 부호 없는 리틀 엔디언 이진수의 비트 문자열 인코딩으로 해석한 것으로 하라.
  7. 그렇지 않으면,
    1. intValuerawBytes의 바이트 요소들을 연결하고 비트 길이가 elementSize × 8인 이진 리틀 엔디언 2의 보수 수의 비트 문자열 인코딩으로 해석한 것으로 하라.
  8. IsBigIntElementType(type)가 true이면, intValue에 해당하는 BigInt 값을 반환하라.
  9. intValue에 해당하는 Number 값을 반환하라.

25.1.3.15 GetRawBytesFromSharedBlock ( block, byteIndex, type, isTypedArray, order )

The abstract operation GetRawBytesFromSharedBlock takes arguments block (Shared Data Block), byteIndex (음이 아닌 정수), type (TypedArray 요소 타입), isTypedArray (Boolean), and order (seq-cst 또는 unordered) and returns 바이트 값의 List. It performs the following steps when called:

  1. elementSize를 Element Type type에 대해 Table 71에 명시된 Element Size 값으로 하라.
  2. agentRecordsurrounding agentAgent Record로 하라.
  3. executionagentRecord.[[CandidateExecution]]으로 하라.
  4. eventsRecord[[AgentSignifier]]AgentSignifier()인 execution.[[EventsRecords]]Agent Events Record로 하라.
  5. isTypedArraytrue이고 IsNoTearConfiguration(type, order)가 true이면, noTeartrue로 하라; 그렇지 않으면 noTearfalse로 하라.
  6. rawValue를 요소가 비결정적으로 선택된 바이트 값인 길이 elementSizeList로 하라.
  7. NOTE: 구현에서 rawValue는 기반 하드웨어의 비원자적 또는 원자적 읽기 명령의 결과이다. 비결정성은 약한 일관성을 가진 하드웨어의 관찰 가능한 동작을 설명하기 위한 메모리 모델의 의미론적 규정이다.
  8. readEventReadSharedMemory { [[Order]]: order, [[NoTear]]: noTear, [[Block]]: block, [[ByteIndex]]: byteIndex, [[ElementSize]]: elementSize }로 하라.
  9. readEventeventsRecord.[[EventList]]에 추가하라.
  10. Chosen Value Record { [[Event]]: readEvent, [[ChosenValue]]: rawValue }를 execution.[[ChosenValues]]에 추가하라.
  11. rawValue를 반환하라.

25.1.3.16 GetValueFromBuffer ( arrayBuffer, byteIndex, type, isTypedArray, order [ , isLittleEndian ] )

The abstract operation GetValueFromBuffer takes arguments arrayBuffer (ArrayBuffer 또는 SharedArrayBuffer), byteIndex (음이 아닌 정수), type (TypedArray 요소 타입), isTypedArray (Boolean), and order (seq-cst 또는 unordered) and optional argument isLittleEndian (Boolean) and returns Number 또는 BigInt. It performs the following steps when called:

  1. Assert: IsDetachedBuffer(arrayBuffer)는 false이다.
  2. Assert: byteIndex에서 시작하여 type의 값을 나타내기에 충분한 바이트가 arrayBuffer에 있다.
  3. blockarrayBuffer.[[ArrayBufferData]]로 하라.
  4. elementSize를 Element Type type에 대해 Table 71에 명시된 Element Size 값으로 하라.
  5. IsSharedArrayBuffer(arrayBuffer)가 true이면,
    1. Assert: blockShared Data Block이다.
    2. rawValueGetRawBytesFromSharedBlock(block, byteIndex, type, isTypedArray, order)로 하라.
  6. 그렇지 않으면,
    1. rawValuebyteIndex 이상 byteIndex + elementSize 미만의 구간에 있는 block의 인덱스들에서 온 바이트를 요소로 하는 List로 하라.
  7. Assert: rawValue의 요소 수는 elementSize이다.
  8. isLittleEndian이 존재하지 않으면,
    1. agentRecordsurrounding agentAgent Record로 하라.
    2. isLittleEndianagentRecord.[[LittleEndian]]으로 설정하라.
  9. RawBytesToNumeric(type, rawValue, isLittleEndian)를 반환하라.

25.1.3.17 NumericToRawBytes ( type, value, isLittleEndian )

The abstract operation NumericToRawBytes takes arguments type (TypedArray 요소 타입), value (Number 또는 BigInt), and isLittleEndian (Boolean) and returns 바이트 값의 List. It performs the following steps when called:

  1. typefloat16이면,
    1. rawBytes를 roundTiesToEven 모드를 사용하여 valueIEEE 754-2019 binary16 형식으로 변환한 결과인 2개의 바이트를 요소로 하는 List로 하라. 바이트는 리틀 엔디언 순서로 배열된다. valueNaN이면, rawBytes는 구현체가 선택한 IEEE 754-2019 binary16 형식 NaN 인코딩 중 하나로 설정될 수 있다. 구현체는 구현체가 구별할 수 있는 각 NaN 값에 대해 항상 동일한 인코딩을 선택해야 한다.
  2. 그렇지 않고 typefloat32이면,
    1. rawBytes를 roundTiesToEven 모드를 사용하여 valueIEEE 754-2019 binary32 형식으로 변환한 결과인 4개의 바이트를 요소로 하는 List로 하라. 바이트는 리틀 엔디언 순서로 배열된다. valueNaN이면, rawBytes는 구현체가 선택한 IEEE 754-2019 binary32 형식 NaN 인코딩 중 하나로 설정될 수 있다. 구현체는 구현체가 구별할 수 있는 각 NaN 값에 대해 항상 동일한 인코딩을 선택해야 한다.
  3. 그렇지 않고 typefloat64이면,
    1. rawBytesvalueIEEE 754-2019 binary64 형식 인코딩인 8개의 바이트를 요소로 하는 List로 하라. 바이트는 리틀 엔디언 순서로 배열된다. valueNaN이면, rawBytes는 구현체가 선택한 IEEE 754-2019 binary64 형식 NaN 인코딩 중 하나로 설정될 수 있다. 구현체는 구현체가 구별할 수 있는 각 NaN 값에 대해 항상 동일한 인코딩을 선택해야 한다.
  4. 그렇지 않으면,
    1. n을 Element Type type에 대해 Table 71에 명시된 Element Size 값으로 하라.
    2. conversionOperation을 Element Type type에 대해 Table 71의 “Conversion Operation” 열에 이름이 지정된 추상 연산으로 하라.
    3. intValue(! conversionOperation(value))로 하라.
    4. intValue ≥ 0이면,
      1. rawBytesintValuen-바이트 이진 인코딩을 요소로 하는 List로 하라. 바이트는 리틀 엔디언 순서로 정렬된다.
    5. 그렇지 않으면,
      1. rawBytesintValuen-바이트 이진 2의 보수 인코딩을 요소로 하는 List로 하라. 바이트는 리틀 엔디언 순서로 정렬된다.
  5. isLittleEndianfalse이면, rawBytes의 요소 순서를 뒤집어라.
  6. rawBytes를 반환하라.

25.1.3.18 SetValueInBuffer ( arrayBuffer, byteIndex, type, value, isTypedArray, order [ , isLittleEndian ] )

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 (seq-cst, unordered, or init) and optional argument isLittleEndian (a Boolean) and returns unused. It performs the following steps when called:

  1. Assert: IsDetachedBuffer(arrayBuffer)는 false이다.
  2. Assert: byteIndex에서 시작하여 type의 값을 나타내기에 충분한 바이트가 arrayBuffer에 있다.
  3. Assert: IsBigIntElementType(type)가 true이면 value는 BigInt이고, 그렇지 않으면 value는 Number이다.
  4. blockarrayBuffer.[[ArrayBufferData]]로 하라.
  5. elementSize를 Element Type type에 대해 Table 71에 명시된 Element Size 값으로 하라.
  6. agentRecordsurrounding agentAgent Record로 하라.
  7. isLittleEndian이 존재하지 않으면,
    1. isLittleEndianagentRecord.[[LittleEndian]]으로 설정하라.
  8. rawBytesNumericToRawBytes(type, value, isLittleEndian)로 하라.
  9. IsSharedArrayBuffer(arrayBuffer)가 true이면,
    1. executionagentRecord.[[CandidateExecution]]으로 하라.
    2. eventsRecord[[AgentSignifier]]AgentSignifier()인 execution.[[EventsRecords]]Agent Events Record로 하라.
    3. isTypedArraytrue이고 IsNoTearConfiguration(type, order)가 true이면, noTeartrue로 하라; 그렇지 않으면 noTearfalse로 하라.
    4. WriteSharedMemory { [[Order]]: order, [[NoTear]]: noTear, [[Block]]: block, [[ByteIndex]]: byteIndex, [[ElementSize]]: elementSize, [[Payload]]: rawBytes }를 eventsRecord.[[EventList]]에 추가하라.
  10. 그렇지 않으면,
    1. rawBytes의 개별 바이트를 block[byteIndex]에서 시작하여 block에 저장하라.
  11. unused를 반환하라.

25.1.3.19 GetModifySetValueInBuffer ( arrayBuffer, byteIndex, type, value, op )

The abstract operation GetModifySetValueInBuffer takes arguments arrayBuffer (ArrayBuffer 또는 SharedArrayBuffer), byteIndex (음이 아닌 정수), type (TypedArray 요소 타입), value (Number 또는 BigInt), and op (읽기-수정-쓰기 수정 함수) and returns Number 또는 BigInt. It performs the following steps when called:

  1. Assert: IsDetachedBuffer(arrayBuffer)는 false이다.
  2. Assert: byteIndex에서 시작하여 type의 값을 나타내기에 충분한 바이트가 arrayBuffer에 있다.
  3. Assert: IsBigIntElementType(type)가 true이면 value는 BigInt이고, 그렇지 않으면 value는 Number이다.
  4. blockarrayBuffer.[[ArrayBufferData]]로 하라.
  5. elementSize를 Element Type type에 대해 Table 71에 명시된 Element Size 값으로 하라.
  6. agentRecordsurrounding agentAgent Record로 하라.
  7. isLittleEndianagentRecord.[[LittleEndian]]으로 하라.
  8. rawBytesNumericToRawBytes(type, value, isLittleEndian)로 하라.
  9. IsSharedArrayBuffer(arrayBuffer)가 true이면,
    1. executionagentRecord.[[CandidateExecution]]으로 하라.
    2. eventsRecord[[AgentSignifier]]AgentSignifier()인 execution.[[EventsRecords]]Agent Events Record로 하라.
    3. rawBytesRead를 요소가 비결정적으로 선택된 바이트 값인 길이 elementSizeList로 하라.
    4. NOTE: 구현에서 rawBytesRead는 기반 하드웨어의 load-link, load-exclusive, 또는 읽기-수정-쓰기 명령의 피연산자 결과이다. 비결정성은 약한 일관성을 가진 하드웨어의 관찰 가능한 동작을 설명하기 위한 메모리 모델의 의미론적 규정이다.
    5. rmwEventReadModifyWriteSharedMemory { [[Order]]: seq-cst, [[NoTear]]: true, [[Block]]: block, [[ByteIndex]]: byteIndex, [[ElementSize]]: elementSize, [[Payload]]: rawBytes, [[ModifyOp]]: op }로 하라.
    6. rmwEventeventsRecord.[[EventList]]에 추가하라.
    7. Chosen Value Record { [[Event]]: rmwEvent, [[ChosenValue]]: rawBytesRead }를 execution.[[ChosenValues]]에 추가하라.
  10. 그렇지 않으면,
    1. rawBytesReadblock[byteIndex]로 시작하는 elementSize 바이트의 시퀀스를 요소로 하는 길이 elementSizeList로 하라.
    2. rawBytesModifiedop(rawBytesRead, rawBytes)로 하라.
    3. rawBytesModified의 개별 바이트를 block[byteIndex]에서 시작하여 block에 저장하라.
  11. RawBytesToNumeric(type, rawBytesRead, isLittleEndian)를 반환하라.

25.1.4 ArrayBuffer Constructor

ArrayBuffer constructor는:

  • %ArrayBuffer%입니다.
  • global object"ArrayBuffer" property의 initial value입니다.
  • constructor로 called될 때 new ArrayBuffer를 create하고 initialize합니다.
  • function으로 called되도록 intended되지 않으며, such manner로 called될 때 exception을 throw합니다.
  • 클래스 정의의 extends 절의 값으로 사용될 수 있다. 지정된 ArrayBuffer 동작을 상속하려는 서브클래스 생성자는 ArrayBuffer.prototype의 내장 메서드를 지원하는 데 필요한 내부 상태로 서브클래스 인스턴스를 생성하고 초기화하기 위해 ArrayBuffer 생성자에 대한 super 호출을 포함해야 한다.

25.1.4.1 ArrayBuffer ( length [ , options ] )

이 function은 called될 때 다음 steps를 수행합니다:

  1. NewTarget이 undefined이면, TypeError exception을 throw한다.
  2. byteLength를 ? ToIndex(length)로 둔다.
  3. requestedMaxByteLength를 ? GetArrayBufferMaxByteLengthOption(options)로 둔다.
  4. AllocateArrayBuffer(NewTarget, byteLength, requestedMaxByteLength)를 반환한다.

25.1.5 ArrayBuffer Constructor의 Properties

ArrayBuffer constructor는:

  • value가 %Function.prototype%[[Prototype]] internal slot을 가집니다.
  • 다음 properties를 가집니다:

25.1.5.1 ArrayBuffer.isView ( arg )

이 function은 called될 때 다음 steps를 수행합니다:

  1. arg가 Object가 아니면, false를 반환한다.
  2. arg[[ViewedArrayBuffer]] internal slot을 가지면, true를 반환한다.
  3. false를 반환한다.

25.1.5.2 ArrayBuffer.prototype

ArrayBuffer.prototype의 initial value는 ArrayBuffer prototype object입니다.

이 property는 attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }를 가집니다.

25.1.5.3 get ArrayBuffer [ %Symbol.species% ]

ArrayBuffer[%Symbol.species%]는 set accessor function이 undefinedaccessor property입니다. Its get accessor function은 called될 때 다음 steps를 수행합니다:

  1. this value를 반환한다.

이 function의 "name" property의 value는 "get [Symbol.species]"입니다.

Note

ArrayBuffer.prototype.slice ( start, end )는 normally its this value의 constructor를 사용하여 derived object를 create합니다. However, subclass constructor는 its %Symbol.species% property를 redefining하여 ArrayBuffer.prototype.slice ( start, end ) method에 대한 that default behaviour를 over-ride할 수 있습니다.

25.1.6 ArrayBuffer Prototype Object의 Properties

ArrayBuffer prototype object는:

  • %ArrayBuffer.prototype%입니다.
  • value가 %Object.prototype%[[Prototype]] internal slot을 가집니다.
  • ordinary object입니다.
  • [[ArrayBufferData]] 또는 [[ArrayBufferByteLength]] internal slot을 가지지 않습니다.

25.1.6.1 get ArrayBuffer.prototype.byteLength

ArrayBuffer.prototype.byteLength는 set accessor function이 undefinedaccessor property입니다. Its get accessor function은 called될 때 다음 steps를 수행합니다:

  1. objthis value로 둔다.
  2. RequireInternalSlot(obj, [[ArrayBufferData]])를 수행한다.
  3. IsSharedArrayBuffer(obj)가 true이면, TypeError exception을 throw한다.
  4. IsDetachedBuffer(obj)가 true이면, +0𝔽를 반환한다.
  5. lengthobj.[[ArrayBufferByteLength]]로 둔다.
  6. 𝔽(length)를 반환한다.

25.1.6.2 ArrayBuffer.prototype.constructor

ArrayBuffer.prototype.constructor의 initial value는 %ArrayBuffer%입니다.

25.1.6.3 get ArrayBuffer.prototype.detached

ArrayBuffer.prototype.detached는 set accessor function이 undefinedaccessor property입니다. Its get accessor function은 called될 때 다음 steps를 수행합니다:

  1. objthis value로 둔다.
  2. RequireInternalSlot(obj, [[ArrayBufferData]])를 수행한다.
  3. IsSharedArrayBuffer(obj)가 true이면, TypeError exception을 throw한다.
  4. IsDetachedBuffer(obj)를 반환한다.

25.1.6.4 get ArrayBuffer.prototype.maxByteLength

ArrayBuffer.prototype.maxByteLength는 set accessor function이 undefinedaccessor property입니다. Its get accessor function은 called될 때 다음 steps를 수행합니다:

  1. objthis value로 둔다.
  2. RequireInternalSlot(obj, [[ArrayBufferData]])를 수행한다.
  3. IsSharedArrayBuffer(obj)가 true이면, TypeError exception을 throw한다.
  4. IsDetachedBuffer(obj)가 true이면, +0𝔽를 반환한다.
  5. IsFixedLengthArrayBuffer(obj)가 true이면, 다음을 수행한다.
    1. lengthobj.[[ArrayBufferByteLength]]로 둔다.
  6. 그렇지 않으면,
    1. lengthobj.[[ArrayBufferMaxByteLength]]로 둔다.
  7. 𝔽(length)를 반환한다.

25.1.6.5 get ArrayBuffer.prototype.resizable

ArrayBuffer.prototype.resizable는 set accessor function이 undefinedaccessor property입니다. Its get accessor function은 called될 때 다음 steps를 수행합니다:

  1. objthis value로 둔다.
  2. RequireInternalSlot(obj, [[ArrayBufferData]])를 수행한다.
  3. IsSharedArrayBuffer(obj)가 true이면, TypeError exception을 throw한다.
  4. IsFixedLengthArrayBuffer(obj)가 false이면, true를 반환한다.
  5. false를 반환한다.

25.1.6.6 ArrayBuffer.prototype.resize ( newLength )

이 method는 called될 때 다음 steps를 수행합니다:

  1. objthis value로 둔다.
  2. RequireInternalSlot(obj, [[ArrayBufferMaxByteLength]])를 수행한다.
  3. IsSharedArrayBuffer(obj)가 true이면, TypeError exception을 throw한다.
  4. newByteLength를 ? ToIndex(newLength)로 둔다.
  5. IsDetachedBuffer(obj)가 true이면, TypeError exception을 throw한다.
  6. newByteLength > obj.[[ArrayBufferMaxByteLength]]이면, RangeError exception을 throw한다.
  7. hostHandled를 ? HostResizeArrayBuffer(obj, newByteLength)로 둔다.
  8. hostHandledhandled이면, undefined를 반환한다.
  9. oldBlockobj.[[ArrayBufferData]]로 둔다.
  10. newBlock을 ? CreateByteDataBlock(newByteLength)로 둔다.
  11. copyLengthmin(newByteLength, obj.[[ArrayBufferByteLength]])로 둔다.
  12. CopyDataBlockBytes(newBlock, 0, oldBlock, 0, copyLength)를 수행한다.
  13. NOTE: new Data Block의 creation도 old Data Block으로부터의 copying도 observable하지 않습니다. Implementations는 이 method를 in-place growth 또는 shrinkage로 implement할 수 있습니다.
  14. obj.[[ArrayBufferData]]newBlock으로 설정한다.
  15. obj.[[ArrayBufferByteLength]]newByteLength로 설정한다.
  16. undefined를 반환한다.

25.1.6.7 ArrayBuffer.prototype.slice ( start, end )

이 method는 called될 때 다음 steps를 수행합니다:

  1. objthis value로 둔다.
  2. RequireInternalSlot(obj, [[ArrayBufferData]])를 수행한다.
  3. IsSharedArrayBuffer(obj)가 true이면, TypeError exception을 throw한다.
  4. IsDetachedBuffer(obj)가 true이면, TypeError exception을 throw한다.
  5. lengthobj.[[ArrayBufferByteLength]]로 둔다.
  6. relativeStart를 ? ToIntegerOrInfinity(start)로 둔다.
  7. relativeStart = -∞이면, first를 0으로 둔다.
  8. 그렇지 않고 relativeStart < 0이면, firstmax(length + relativeStart, 0)으로 둔다.
  9. 그렇지 않으면, firstmin(relativeStart, length)로 둔다.
  10. endundefined이면 relativeEndlength로 둔다; 그렇지 않으면 relativeEnd를 ? ToIntegerOrInfinity(end)로 둔다.
  11. relativeEnd = -∞이면, final을 0으로 둔다.
  12. 그렇지 않고 relativeEnd < 0이면, finalmax(length + relativeEnd, 0)으로 둔다.
  13. 그렇지 않으면, finalmin(relativeEnd, length)로 둔다.
  14. newLengthmax(final - first, 0)으로 둔다.
  15. ctor를 ? SpeciesConstructor(obj, %ArrayBuffer%)로 둔다.
  16. new를 ? Construct(ctor, « 𝔽(newLength) »)로 둔다.
  17. RequireInternalSlot(new, [[ArrayBufferData]])를 수행한다.
  18. IsSharedArrayBuffer(new)가 true이면, TypeError exception을 throw한다.
  19. IsDetachedBuffer(new)가 true이면, TypeError exception을 throw한다.
  20. SameValue(new, obj)가 true이면, TypeError exception을 throw한다.
  21. new.[[ArrayBufferByteLength]] < newLength이면, TypeError exception을 throw한다.
  22. NOTE: above steps의 side-effects가 obj를 detached 또는 resized했을 수 있다.
  23. IsDetachedBuffer(obj)가 true이면, TypeError exception을 throw한다.
  24. fromBufobj.[[ArrayBufferData]]로 둔다.
  25. toBufnew.[[ArrayBufferData]]로 둔다.
  26. currentLengthobj.[[ArrayBufferByteLength]]로 둔다.
  27. first < currentLength이면, 다음을 수행한다.
    1. countmin(newLength, currentLength - first)로 둔다.
    2. CopyDataBlockBytes(toBuf, 0, fromBuf, first, count)를 수행한다.
  28. new를 반환한다.

25.1.6.8 ArrayBuffer.prototype.transfer ( [ newLength ] )

이 method는 called될 때 다음 steps를 수행합니다:

  1. objthis value로 둔다.
  2. ArrayBufferCopyAndDetach(obj, newLength, preserve-resizability)를 반환한다.

25.1.6.9 ArrayBuffer.prototype.transferToFixedLength ( [ newLength ] )

이 method는 called될 때 다음 steps를 수행합니다:

  1. objthis value로 둔다.
  2. ArrayBufferCopyAndDetach(obj, newLength, fixed-length)를 반환한다.

25.1.6.10 ArrayBuffer.prototype [ %Symbol.toStringTag% ]

%Symbol.toStringTag% property의 initial value는 String value "ArrayBuffer"입니다.

이 property는 attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }를 가집니다.

25.1.7 ArrayBuffer Instances의 Properties

ArrayBuffer instances는 ArrayBuffer prototype object로부터 properties를 inherit합니다. ArrayBuffer instances는 각각 [[ArrayBufferData]] internal slot, [[ArrayBufferByteLength]] internal slot, 및 [[ArrayBufferDetachKey]] internal slot을 가집니다. resizable인 ArrayBuffer instances는 각각 [[ArrayBufferMaxByteLength]] internal slot을 가집니다.

[[ArrayBufferData]]null인 ArrayBuffer instances는 detached된 것으로 considered되며, ArrayBuffer instance 안에 contained된 data에 access하거나 modify하는 모든 operators는 fail합니다.

[[ArrayBufferDetachKey]]undefined가 아닌 value로 set된 ArrayBuffer instances는 all DetachArrayBuffer calls가 same “detach key”를 argument로 passing해야 하며, 그렇지 않으면 TypeError가 result됩니다. 이 internal slot은 only certain embedding environments에 의해 set되며, 이 specification의 algorithms에 의해 set되지 않습니다.

25.1.8 Resizable ArrayBuffer Guidelines

Note 1

다음은 resizable ArrayBuffer로 작업하는 ECMAScript programmers를 위한 guidelines입니다.

가능한 경우 programs를 그 deployment environments에서 test할 것을 recommend합니다. available physical memory의 amount는 hardware devices 사이에서 크게 differs합니다. Similarly, virtual memory subsystems 또한 hardware devices 및 operating systems 사이에서 크게 differs합니다. 64-bit desktop web browser에서 out-of-memory errors 없이 runs하는 application이 32-bit mobile web browser에서는 memory가 부족해질 수 있습니다.

resizable ArrayBuffer에 대한 "maxByteLength" option의 value를 choosing할 때, application에 대해 가능한 smallest size를 choose할 것을 recommend합니다. "maxByteLength"가 1,073,741,824 (230 bytes 또는 1GiB)를 exceed하지 않을 것을 recommend합니다.

particular maximum size에 대해 resizable ArrayBuffer를 successfully constructing하는 것이 future resizes가 succeed할 것을 guarantee하지 않는다는 점에 note하십시오.

Note 2

다음은 resizable ArrayBuffer를 implementing하는 ECMAScript implementers를 위한 guidelines입니다.

Resizable ArrayBuffer는 resize 시 copying, virtual memory를 up front로 reserving하는 in-place growth, 또는 constructor"maxByteLength" option의 different values에 대해 both의 combination으로 implemented될 수 있습니다.

host가 web browser처럼 multi-tenanted(즉, many ECMAScript applications를 simultaneously runs)이고, its implementations가 virtual memory를 reserving하여 in-place growth를 implement하기로 choose하는 경우, 32-bit와 64-bit implementations 모두 "maxByteLength" ≥ 1GiB to 1.5GiB인 values에 대해 throw할 것을 recommend합니다. 이는 single application이 virtual memory address space를 exhaust할 likelihood를 reduce하고 interoperability risk를 reduce하기 위한 것입니다.

host가 MMU 없이 embedded devices에서 running하는 것처럼 virtual memory를 가지지 않거나, host가 resizing을 copying으로만 implements하는 경우, "maxByteLength" option에 대한 any Number value for을 accept할 수 있습니다. However, requested size의 memory block이 never allocated될 수 없는 경우 RangeError가 thrown될 것을 recommend합니다. 예를 들어, requested size가 device에서 usable한 maximum memory amount보다 greater한 경우입니다.

25.2 SharedArrayBuffer 객체

25.2.1 Fixed-length 및 Growable SharedArrayBuffer 객체

fixed-length SharedArrayBuffer는 creation 후 byte length가 change될 수 없는 SharedArrayBuffer입니다.

growable SharedArrayBufferSharedArrayBuffer.prototype.grow ( newLength )에 대한 calls를 통해 creation 후 byte length가 increase될 수 있는 SharedArrayBuffer입니다.

created되는 SharedArrayBuffer object의 kind는 SharedArrayBuffer ( length [ , options ] )에 passed된 arguments에 따라 달라집니다.

25.2.2 SharedArrayBuffer 객체를 위한 Abstract Operations

25.2.2.1 AllocateSharedArrayBuffer ( ctor, byteLength [ , maxByteLength ] )

The abstract operation AllocateSharedArrayBuffer takes arguments ctor (a constructor) and byteLength (a non-negative integer) and optional argument maxByteLength (a non-negative integer or empty) and returns either a normal completion containing a SharedArrayBuffer or a throw completion. SharedArrayBuffer를 create하는 데 사용됩니다. It performs the following steps when called:

  1. Let slots be « [[ArrayBufferData]] ».
  2. If maxByteLength is present and maxByteLength is not empty, let allocatingGrowableBuffer be true; else let allocatingGrowableBuffer be false.
  3. If allocatingGrowableBuffer is true, then
    1. If byteLength > maxByteLength, throw a RangeError exception.
    2. Append [[ArrayBufferByteLengthData]] and [[ArrayBufferMaxByteLength]] to slots.
  4. Else,
    1. Append [[ArrayBufferByteLength]] to slots.
  5. Let obj be ? OrdinaryCreateFromConstructor(ctor, "%SharedArrayBuffer.prototype%", slots).
  6. If allocatingGrowableBuffer is true, let allocLength be maxByteLength; else let allocLength be byteLength.
  7. Let block be ? CreateSharedByteDataBlock(allocLength).
  8. Set obj.[[ArrayBufferData]] to block.
  9. If allocatingGrowableBuffer is true, then
    1. Assert: byteLengthmaxByteLength.
    2. Let byteLengthBlock be ? CreateSharedByteDataBlock(8).
    3. Perform SetValueInBuffer(byteLengthBlock, 0, biguint64, (byteLength), true, seq-cst).
    4. Set obj.[[ArrayBufferByteLengthData]] to byteLengthBlock.
    5. Set obj.[[ArrayBufferMaxByteLength]] to maxByteLength.
  10. Else,
    1. Set obj.[[ArrayBufferByteLength]] to byteLength.
  11. Return obj.

25.2.2.2 IsSharedArrayBuffer ( obj )

The abstract operation IsSharedArrayBuffer takes argument obj (an ArrayBuffer or a SharedArrayBuffer) and returns a Boolean. object가 SharedArrayBuffer인지 tests합니다. It performs the following steps when called:

  1. obj.[[ArrayBufferData]]Shared Data Block이면, true를 반환한다.
  2. false를 반환한다.

25.2.2.3 IsGrowableSharedArrayBuffer ( obj )

The abstract operation IsGrowableSharedArrayBuffer takes argument obj (an ArrayBuffer or a SharedArrayBuffer) and returns a Boolean. object가 growable SharedArrayBuffer인지 tests합니다. It performs the following steps when called:

  1. IsSharedArrayBuffer(obj)가 true이고 obj[[ArrayBufferByteLengthData]] internal slot을 가지면, true를 반환한다.
  2. false를 반환한다.

25.2.2.4 HostGrowSharedArrayBuffer ( buffer, newByteLength )

The host-defined abstract operation HostGrowSharedArrayBuffer takes arguments buffer (a SharedArrayBuffer) and newByteLength (a non-negative integer) and returns either a normal completion containing either handled or unhandled, or a throw completion. host에게 bufferimplementation-defined growing을 수행할 opportunity를 제공합니다. hostbuffer의 growing을 handle하지 않기로 choose하면, default behaviour를 위해 unhandled를 반환할 수 있습니다.

HostGrowSharedArrayBuffer의 implementation은 다음 requirements를 conform해야 합니다:

  • abstract operation이 unhandled로 normally complete하지 않고, newByteLength < buffer의 current byte length이거나 newByteLength > buffer.[[ArrayBufferMaxByteLength]]이면, RangeError exception을 throw합니다.
  • agentRecordsurrounding agentAgent Record로 둡니다. isLittleEndianagentRecord.[[LittleEndian]]으로 둡니다. abstract operation이 handled로 normally completes하면, [[Order]]seq-cst, [[Payload]]NumericToRawBytes(biguint64, newByteLength, isLittleEndian), [[Block]]buffer.[[ArrayBufferByteLengthData]], [[ByteIndex]]가 0, [[ElementSize]]가 8인 WriteSharedMemory 또는 ReadModifyWriteSharedMemory event가 surrounding agentcandidate execution에 added되어 SharedArrayBuffer.prototype.grow ( newLength )에 대한 racing calls가 “lost”되지 않도록, 즉 silently do nothing하지 않도록 합니다.
Note

위의 second requirement는 buffer의 current byte length가 how 또는 when read되는지에 대해 intentionally vague합니다. byte length는 underlying hardware에서 atomic read-modify-write operation을 통해 updated되어야 하므로, load-link/store-conditional 또는 load-exclusive/store-exclusive instruction pairs를 사용하는 architectures는 paired instructions를 instruction stream 안에서 close하게 유지하기를 원할 수 있습니다. 따라서 SharedArrayBuffer.prototype.grow ( newLength ) 자체는 HostGrowSharedArrayBuffer를 calling하기 전에 newByteLength에 대한 bounds checking을 수행하지 않으며, current byte length가 언제 read되는지에 대한 requirement도 없습니다.

이는 0 ≤ newByteLengthbuffer.[[ArrayBufferMaxByteLength]]가 guaranteed되는 HostResizeArrayBuffer와 대비됩니다.

HostGrowSharedArrayBuffer의 default implementation은 NormalCompletion(unhandled)를 반환하는 것입니다.

25.2.3 SharedArrayBuffer Constructor

SharedArrayBuffer constructor는:

  • %SharedArrayBuffer%입니다.
  • 그 property가 present한 경우, global object"SharedArrayBuffer" property의 initial value입니다(아래 참조).
  • constructor로 called될 때 new SharedArrayBuffer를 create하고 initialize합니다.
  • function으로 called되도록 intended되지 않으며, such manner로 called될 때 exception을 throw합니다.
  • 클래스 정의의 extends 절의 값으로 사용될 수 있다. 지정된 SharedArrayBuffer 동작을 상속하려는 서브클래스 생성자는 SharedArrayBuffer.prototype의 내장 메서드를 지원하는 데 필요한 내부 상태로 서브클래스 인스턴스를 생성하고 초기화하기 위해 SharedArrayBuffer 생성자에 대한 super 호출을 포함해야 한다.

host가 SharedArrayBuffers에 대한 concurrent access를 provide하지 않을 때마다, global object"SharedArrayBuffer" property를 omit할 수 있습니다.

Note

ArrayBuffer와 달리, SharedArrayBuffer는 detached될 수 없고, its internal [[ArrayBufferData]] slot은 never null입니다.

25.2.3.1 SharedArrayBuffer ( length [ , options ] )

이 function은 called될 때 다음 steps를 수행합니다:

  1. NewTarget이 undefined이면, TypeError exception을 throw한다.
  2. byteLength를 ? ToIndex(length)로 둔다.
  3. requestedMaxByteLength를 ? GetArrayBufferMaxByteLengthOption(options)로 둔다.
  4. AllocateSharedArrayBuffer(NewTarget, byteLength, requestedMaxByteLength)를 반환한다.

25.2.4 SharedArrayBuffer Constructor의 Properties

SharedArrayBuffer constructor는:

  • value가 %Function.prototype%[[Prototype]] internal slot을 가집니다.
  • 다음 properties를 가집니다:

25.2.4.1 SharedArrayBuffer.prototype

SharedArrayBuffer.prototype의 initial value는 SharedArrayBuffer prototype object입니다.

이 property는 attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }를 가집니다.

25.2.4.2 get SharedArrayBuffer [ %Symbol.species% ]

SharedArrayBuffer[%Symbol.species%]는 set accessor function이 undefinedaccessor property입니다. Its get accessor function은 called될 때 다음 steps를 수행합니다:

  1. this value를 반환한다.

이 function의 "name" property의 value는 "get [Symbol.species]"입니다.

25.2.5 SharedArrayBuffer Prototype Object의 Properties

SharedArrayBuffer prototype object는:

  • %SharedArrayBuffer.prototype%입니다.
  • value가 %Object.prototype%[[Prototype]] internal slot을 가집니다.
  • ordinary object입니다.
  • [[ArrayBufferData]] 또는 [[ArrayBufferByteLength]] internal slot을 가지지 않습니다.

25.2.5.1 get SharedArrayBuffer.prototype.byteLength

SharedArrayBuffer.prototype.byteLength는 set accessor function이 undefinedaccessor property입니다. Its get accessor function은 called될 때 다음 steps를 수행합니다:

  1. objthis value로 둔다.
  2. RequireInternalSlot(obj, [[ArrayBufferData]])를 수행한다.
  3. IsSharedArrayBuffer(obj)가 false이면, TypeError exception을 throw한다.
  4. lengthArrayBufferByteLength(obj, seq-cst)로 둔다.
  5. 𝔽(length)를 반환한다.

25.2.5.2 SharedArrayBuffer.prototype.constructor

SharedArrayBuffer.prototype.constructor의 initial value는 %SharedArrayBuffer%입니다.

25.2.5.3 SharedArrayBuffer.prototype.grow ( newLength )

이 method는 called될 때 다음 steps를 수행합니다:

  1. objthis value로 둔다.
  2. RequireInternalSlot(obj, [[ArrayBufferMaxByteLength]])를 수행한다.
  3. IsSharedArrayBuffer(obj)가 false이면, TypeError exception을 throw한다.
  4. newByteLength를 ? ToIndex(newLength)로 둔다.
  5. hostHandled를 ? HostGrowSharedArrayBuffer(obj, newByteLength)로 둔다.
  6. hostHandledhandled이면, undefined를 반환한다.
  7. agentRecordsurrounding agentAgent Record로 둔다.
  8. isLittleEndianagentRecord.[[LittleEndian]]으로 둔다.
  9. byteLengthBlockobj.[[ArrayBufferByteLengthData]]로 둔다.
  10. currentByteLengthRawBytesGetRawBytesFromSharedBlock(byteLengthBlock, 0, biguint64, true, seq-cst)로 둔다.
  11. newByteLengthRawBytesNumericToRawBytes(biguint64, (newByteLength), isLittleEndian)로 둔다.
  12. 반복한다.
    1. NOTE: 이것은 same buffer의 parallel, racing grows가 totally ordered되고, lost되지 않으며, silently do nothing하지 않도록 보장하기 위한 compare-and-exchange loop입니다. loop는 uncontended로 grow를 attempt할 수 있었을 때 exits합니다.
    2. currentByteLength(RawBytesToNumeric(biguint64, currentByteLengthRawBytes, isLittleEndian))로 둔다.
    3. newByteLength = currentByteLength이면, undefined를 반환한다.
    4. newByteLength < currentByteLength이거나 newByteLength > obj.[[ArrayBufferMaxByteLength]]이면, RangeError exception을 throw한다.
    5. byteLengthDeltanewByteLength - currentByteLength로 둔다.
    6. byteLengthDelta bytes로 구성된 new Shared Data Block value를 create하는 것이 impossible하면, RangeError exception을 throw한다.
    7. NOTE: 여기서는 new Shared Data Block이 constructed되고 used되지 않습니다. growable SharedArrayBuffers의 observable behaviour는 construction time에 max-sized Shared Data Block을 allocating하는 것으로 specified되며, 이 step은 memory가 부족해진 implementations가 RangeError를 throw해야 한다는 requirement를 captures합니다.
    8. readByteLengthRawBytesAtomicCompareExchangeInSharedBlock(byteLengthBlock, 0, 8, currentByteLengthRawBytes, newByteLengthRawBytes)로 둔다.
    9. ByteListEqual(readByteLengthRawBytes, currentByteLengthRawBytes)가 true이면, undefined를 반환한다.
    10. currentByteLengthRawBytesreadByteLengthRawBytes로 설정한다.
Note

length를 update하는 compare-exchange의 spurious failures는 prohibited됩니다. new length에 대한 bounds checking이 passes하고 implementation이 out of memory가 아니면, ReadModifyWriteSharedMemory event(즉 successful compare-exchange)는 always candidate execution 안에 added됩니다.

SharedArrayBuffer.prototype.grow에 대한 parallel calls는 totally ordered됩니다. 예를 들어, 두 racing calls sab.grow(10)sab.grow(20)을 consider하십시오. 두 calls 중 하나는 race에서 win하는 것이 guaranteed됩니다. sab.grow(20)이 먼저 happened하더라도 sab.grow(10)에 대한 call은 never sab를 shrink하지 않습니다; 그 경우 대신 RangeError를 throw합니다.

25.2.5.4 get SharedArrayBuffer.prototype.growable

SharedArrayBuffer.prototype.growable은 set accessor function이 undefinedaccessor property입니다. Its get accessor function은 called될 때 다음 steps를 수행합니다:

  1. objthis value로 둔다.
  2. RequireInternalSlot(obj, [[ArrayBufferData]])를 수행한다.
  3. IsSharedArrayBuffer(obj)가 false이면, TypeError exception을 throw한다.
  4. IsFixedLengthArrayBuffer(obj)가 false이면, true를 반환한다.
  5. false를 반환한다.

25.2.5.5 get SharedArrayBuffer.prototype.maxByteLength

SharedArrayBuffer.prototype.maxByteLength는 set accessor function이 undefinedaccessor property입니다. Its get accessor function은 called될 때 다음 steps를 수행합니다:

  1. objthis value로 둔다.
  2. RequireInternalSlot(obj, [[ArrayBufferData]])를 수행한다.
  3. IsSharedArrayBuffer(obj)가 false이면, TypeError exception을 throw한다.
  4. IsFixedLengthArrayBuffer(obj)가 true이면, 다음을 수행한다.
    1. lengthobj.[[ArrayBufferByteLength]]로 둔다.
  5. 그렇지 않으면,
    1. lengthobj.[[ArrayBufferMaxByteLength]]로 둔다.
  6. 𝔽(length)를 반환한다.

25.2.5.6 SharedArrayBuffer.prototype.slice ( start, end )

이 method는 called될 때 다음 steps를 수행합니다:

  1. objthis value로 둔다.
  2. RequireInternalSlot(obj, [[ArrayBufferData]])를 수행한다.
  3. IsSharedArrayBuffer(obj)가 false이면, TypeError exception을 throw한다.
  4. lengthArrayBufferByteLength(obj, seq-cst)로 둔다.
  5. relativeStart를 ? ToIntegerOrInfinity(start)로 둔다.
  6. relativeStart = -∞이면, first를 0으로 둔다.
  7. 그렇지 않고 relativeStart < 0이면, firstmax(length + relativeStart, 0)으로 둔다.
  8. 그렇지 않으면, firstmin(relativeStart, length)로 둔다.
  9. endundefined이면 relativeEndlength로 둔다; 그렇지 않으면 relativeEnd를 ? ToIntegerOrInfinity(end)로 둔다.
  10. relativeEnd = -∞이면, final을 0으로 둔다.
  11. 그렇지 않고 relativeEnd < 0이면, finalmax(length + relativeEnd, 0)으로 둔다.
  12. 그렇지 않으면, finalmin(relativeEnd, length)로 둔다.
  13. newLengthmax(final - first, 0)으로 둔다.
  14. ctor를 ? SpeciesConstructor(obj, %SharedArrayBuffer%)로 둔다.
  15. new를 ? Construct(ctor, « 𝔽(newLength) »)로 둔다.
  16. RequireInternalSlot(new, [[ArrayBufferData]])를 수행한다.
  17. IsSharedArrayBuffer(new)가 false이면, TypeError exception을 throw한다.
  18. new.[[ArrayBufferData]]obj.[[ArrayBufferData]]이면, TypeError exception을 throw한다.
  19. ArrayBufferByteLength(new, seq-cst) < newLength이면, TypeError exception을 throw한다.
  20. fromBufobj.[[ArrayBufferData]]로 둔다.
  21. toBufnew.[[ArrayBufferData]]로 둔다.
  22. CopyDataBlockBytes(toBuf, 0, fromBuf, first, newLength)를 수행한다.
  23. new를 반환한다.

25.2.5.7 SharedArrayBuffer.prototype [ %Symbol.toStringTag% ]

%Symbol.toStringTag% property의 initial value는 String value "SharedArrayBuffer"입니다.

이 property는 attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }를 가집니다.

25.2.6 SharedArrayBuffer Instances의 Properties

SharedArrayBuffer instances는 SharedArrayBuffer prototype object로부터 properties를 inherit합니다. SharedArrayBuffer instances는 각각 [[ArrayBufferData]] internal slot을 가집니다. growable이 아닌 SharedArrayBuffer instances는 각각 [[ArrayBufferByteLength]] internal slot을 가집니다. growable인 SharedArrayBuffer instances는 각각 [[ArrayBufferByteLengthData]] internal slot과 [[ArrayBufferMaxByteLength]] internal slot을 가집니다.

Note

SharedArrayBuffer instances는 ArrayBuffer instances와 달리 never detached됩니다.

25.2.7 Growable SharedArrayBuffer Guidelines

Note 1

다음은 growable SharedArrayBuffer로 작업하는 ECMAScript programmers를 위한 guidelines입니다.

가능한 경우 programs를 그 deployment environments에서 test할 것을 recommend합니다. available physical memory의 amount는 hardware devices 사이에서 greatly differ합니다. Similarly, virtual memory subsystems 또한 hardware devices 및 operating systems 사이에서 greatly differ합니다. 64-bit desktop web browser에서 out-of-memory errors 없이 runs하는 application이 32-bit mobile web browser에서는 memory가 부족해질 수 있습니다.

growable SharedArrayBuffer에 대한 "maxByteLength" option의 value를 choosing할 때, application에 대해 가능한 smallest size를 choose할 것을 recommend합니다. "maxByteLength"가 1073741824, 또는 1GiB를 exceed하지 않을 것을 recommend합니다.

particular maximum size에 대해 growable SharedArrayBuffer를 successfully constructing하는 것이 future grows가 succeed할 것을 guarantee하지 않는다는 점에 note하십시오.

growable SharedArrayBuffer's length의 모든 loads가 synchronizing seq-cst loads인 것은 아닙니다. integer-indexed property access의 bounds-checking을 위한 length의 loads, 예를 들어 u8[idx],는 synchronizing하지 않습니다. 일반적으로 explicit synchronization이 없을 때, one property access가 in-bound라는 것이 same agent 안의 subsequent property access도 in-bound라는 것을 imply하지 않습니다. 이와 contrast하여, SharedArrayBuffer, %TypedArray%.prototype, 및 DataView.prototype의 lengthbyteLength getters를 통한 length의 explicit loads는 synchronizing합니다. TypedArray가 entirely out-of-bounds인지 check하기 위해 built-in methods에 의해 performed되는 length의 loads도 synchronizing합니다.

Note 2

다음은 growable SharedArrayBuffer를 implementing하는 ECMAScript implementers를 위한 guidelines입니다.

growable SharedArrayBuffer는 virtual memory를 up front로 reserving하는 in-place growth로 implemented될 것을 recommend합니다.

grow operations는 growable SharedArrayBuffer에 대한 memory accesses와 parallel하게 happen할 수 있으므로, memory model의 constraints는 unordered accesses조차도 “tear”하지 않을 것(그 values의 bits가 mixed되지 않을 것)을 require합니다. In practice, 이는 growable SharedArrayBuffer의 underlying data block이 stopping the world 없이 copied되어 grown될 수 없음을 의미합니다. 우리는 stopping the world를 implementation strategy로 recommend하지 않습니다. 이는 serialization point를 introduce하고 느리기 때문입니다.

Grown memory는 creation 순간부터 zeroed된 것으로 appear해야 하며, parallel한 any racy accesses에도 포함됩니다. 이는 zero-filled-on-demand virtual memory pages를 통해 또는 manually zeroing memory하는 경우 careful synchronization을 통해 accomplished될 수 있습니다.

growable SharedArrayBuffers의 TypedArray views에 대한 Integer-indexed property access는 non-growable SharedArrayBuffers의 TypedArray views에 대한 access와 similarly optimizable되도록 intended됩니다. 이는 integer-indexed property loads가 underlying buffer's length에 대해 synchronizing하지 않기 때문입니다(위 programmer guidelines 참조). 예를 들어, property accesses를 위한 bounds checks는 still loops 밖으로 hoisted될 수 있습니다.

In practice, virtual memory가 없는 hosts, 예를 들어 MMU 없이 embedded devices에서 running하는 hosts에서 growable SharedArrayBuffer를 copying으로 implement하는 것은 어렵습니다. 이러한 hosts에서 growable SharedArrayBuffers의 memory usage behaviour는 virtual memory가 있는 hosts와 significantly differ할 수 있습니다. Such hosts는 memory usage expectations를 users에게 clearly communicate해야 합니다.

25.3 DataView 객체

25.3.1 DataView 객체를 위한 Abstract Operations

25.3.1.1 DataView With Buffer Witness Records

DataView With Buffer Witness Record는 viewed buffer의 cached byte length와 함께 DataView를 encapsulate하는 데 사용되는 Record value입니다. viewed buffer가 growable SharedArrayBuffer일 때 byte length data block의 single ReadSharedMemory event가 있음을 ensure하는 데 도움을 주기 위해 사용됩니다.

DataView With Buffer Witness Records는 Table 73에 listed된 fields를 가집니다.

Table 73: DataView With Buffer Witness Record Fields
Field Name Value Meaning
[[Object]] a DataView buffer's byte length가 loaded되는 DataView object입니다.
[[CachedBufferByteLength]] a non-negative integer or detached Record가 created되었을 때 object's [[ViewedArrayBuffer]]의 byte length입니다.

25.3.1.2 MakeDataViewWithBufferWitnessRecord ( obj, order )

The abstract operation MakeDataViewWithBufferWitnessRecord takes arguments obj (a DataView) and order (seq-cst or unordered) and returns a DataView With Buffer Witness Record. It performs the following steps when called:

  1. bufferobj.[[ViewedArrayBuffer]]로 둔다.
  2. IsDetachedBuffer(buffer)가 true이면, 다음을 수행한다.
    1. byteLengthdetached로 둔다.
  3. 그렇지 않으면,
    1. byteLengthArrayBufferByteLength(buffer, order)로 둔다.
  4. DataView With Buffer Witness Record { [[Object]]: obj, [[CachedBufferByteLength]]: byteLength }를 반환한다.

25.3.1.3 GetViewByteLength ( viewRecord )

The abstract operation GetViewByteLength takes argument viewRecord (a DataView With Buffer Witness Record) and returns a non-negative integer. It performs the following steps when called:

  1. Assert: IsViewOutOfBounds(viewRecord)는 false이다.
  2. viewviewRecord.[[Object]]로 둔다.
  3. view.[[ByteLength]]auto가 아니면, view.[[ByteLength]]를 반환한다.
  4. Assert: IsFixedLengthArrayBuffer(view.[[ViewedArrayBuffer]])는 false이다.
  5. byteOffsetview.[[ByteOffset]]으로 둔다.
  6. byteLengthviewRecord.[[CachedBufferByteLength]]로 둔다.
  7. Assert: byteLengthdetached가 아니다.
  8. byteLength - byteOffset을 반환한다.

25.3.1.4 IsViewOutOfBounds ( viewRecord )

The abstract operation IsViewOutOfBounds takes argument viewRecord (a DataView With Buffer Witness Record) and returns a Boolean. It performs the following steps when called:

  1. viewviewRecord.[[Object]]로 둔다.
  2. bufferByteLengthviewRecord.[[CachedBufferByteLength]]로 둔다.
  3. IsDetachedBuffer(view.[[ViewedArrayBuffer]])가 true이면, 다음을 수행한다.
    1. Assert: bufferByteLengthdetached이다.
    2. true를 반환한다.
  4. Assert: bufferByteLength는 non-negative integer이다.
  5. byteOffsetStartview.[[ByteOffset]]으로 둔다.
  6. view.[[ByteLength]]auto이면, 다음을 수행한다.
    1. byteOffsetEndbufferByteLength로 둔다.
  7. 그렇지 않으면,
    1. byteOffsetEndbyteOffsetStart + view.[[ByteLength]]로 둔다.
  8. NOTE: [[ByteOffset]]bufferByteLength인 0-length DataView는 out-of-bounds로 considered되지 않습니다.
  9. byteOffsetStart > bufferByteLength이거나 byteOffsetEnd > bufferByteLength이면, true를 반환한다.
  10. false를 반환한다.

25.3.1.5 GetViewValue ( view, requestIndex, isLittleEndian, type )

The abstract operation GetViewValue takes arguments view (an ECMAScript language value), requestIndex (an ECMAScript language value), isLittleEndian (an ECMAScript language value), and type (a TypedArray element type) and returns either a normal completion containing either a Number or a BigInt, or a throw completion. DataView instances의 functions에 의해 view's buffer로부터 values를 retrieve하는 데 사용됩니다. It performs the following steps when called:

  1. RequireInternalSlot(view, [[DataView]])를 수행한다.
  2. Assert: view[[ViewedArrayBuffer]] internal slot을 가진다.
  3. getIndex를 ? ToIndex(requestIndex)로 둔다.
  4. isLittleEndianToBoolean(isLittleEndian)으로 설정한다.
  5. viewOffsetview.[[ByteOffset]]으로 둔다.
  6. viewRecordMakeDataViewWithBufferWitnessRecord(view, unordered)로 둔다.
  7. NOTE: view's backing buffer가 growable SharedArrayBuffer일 때 bounds checking은 synchronizing operation이 아닙니다.
  8. IsViewOutOfBounds(viewRecord)가 true이면, TypeError exception을 throw한다.
  9. viewSizeGetViewByteLength(viewRecord)로 둔다.
  10. elementSize를 Element Type type에 대해 Table 71에 specified된 Element Size value로 둔다.
  11. getIndex + elementSize > viewSize이면, RangeError exception을 throw한다.
  12. bufferIndexgetIndex + viewOffset으로 둔다.
  13. GetValueFromBuffer(view.[[ViewedArrayBuffer]], bufferIndex, type, false, unordered, isLittleEndian)을 반환한다.

25.3.1.6 SetViewValue ( view, requestIndex, isLittleEndian, type, value )

The abstract operation SetViewValue takes arguments view (an ECMAScript language value), requestIndex (an ECMAScript language value), isLittleEndian (an ECMAScript language value), type (a TypedArray element type), and value (an ECMAScript language value) and returns either a normal completion containing undefined or a throw completion. DataView instances의 functions에 의해 values를 view's buffer 안으로 store하는 데 사용됩니다. It performs the following steps when called:

  1. RequireInternalSlot(view, [[DataView]])를 수행한다.
  2. Assert: view[[ViewedArrayBuffer]] internal slot을 가진다.
  3. getIndex를 ? ToIndex(requestIndex)로 둔다.
  4. IsBigIntElementType(type)이 true이면, number를 ? ToBigInt(value)로 둔다.
  5. 그렇지 않으면, number를 ? ToNumber(value)로 둔다.
  6. isLittleEndianToBoolean(isLittleEndian)으로 설정한다.
  7. viewOffsetview.[[ByteOffset]]으로 둔다.
  8. viewRecordMakeDataViewWithBufferWitnessRecord(view, unordered)로 둔다.
  9. NOTE: view's backing buffer가 growable SharedArrayBuffer일 때 bounds checking은 synchronizing operation이 아닙니다.
  10. IsViewOutOfBounds(viewRecord)가 true이면, TypeError exception을 throw한다.
  11. viewSizeGetViewByteLength(viewRecord)로 둔다.
  12. elementSize를 Element Type type에 대해 Table 71에 specified된 Element Size value로 둔다.
  13. getIndex + elementSize > viewSize이면, RangeError exception을 throw한다.
  14. bufferIndexgetIndex + viewOffset으로 둔다.
  15. SetValueInBuffer(view.[[ViewedArrayBuffer]], bufferIndex, type, number, false, unordered, isLittleEndian)를 수행한다.
  16. undefined를 반환한다.

25.3.2 DataView Constructor

DataView constructor는:

  • %DataView%입니다.
  • global object"DataView" property의 initial value입니다.
  • constructor로 called될 때 new DataView를 create하고 initialize합니다.
  • function으로 called되도록 intended되지 않으며, such manner로 called될 때 exception을 throw합니다.
  • 클래스 정의의 extends 절의 값으로 사용될 수 있다. 지정된 DataView 동작을 상속하려는 서브클래스 생성자는 DataView.prototype의 내장 메서드를 지원하는 데 필요한 내부 상태로 서브클래스 인스턴스를 생성하고 초기화하기 위해 DataView 생성자에 대한 super 호출을 포함해야 한다.

25.3.2.1 DataView ( buffer [ , byteOffset [ , byteLength ] ] )

이 function은 called될 때 다음 steps를 수행합니다:

  1. NewTarget이 undefined이면, TypeError exception을 throw한다.
  2. RequireInternalSlot(buffer, [[ArrayBufferData]])를 수행한다.
  3. offset을 ? ToIndex(byteOffset)로 둔다.
  4. IsDetachedBuffer(buffer)가 true이면, TypeError exception을 throw한다.
  5. bufferByteLengthArrayBufferByteLength(buffer, seq-cst)로 둔다.
  6. offset > bufferByteLength이면, RangeError exception을 throw한다.
  7. bufferIsFixedLengthIsFixedLengthArrayBuffer(buffer)로 둔다.
  8. byteLengthundefined이면, 다음을 수행한다.
    1. bufferIsFixedLengthtrue이면, 다음을 수행한다.
      1. viewByteLengthbufferByteLength - offset으로 둔다.
    2. 그렇지 않으면,
      1. viewByteLengthauto로 둔다.
  9. 그렇지 않으면,
    1. viewByteLength를 ? ToIndex(byteLength)로 둔다.
    2. offset + viewByteLength > bufferByteLength이면, RangeError exception을 throw한다.
  10. obj를 ? OrdinaryCreateFromConstructor(NewTarget, "%DataView.prototype%", « [[DataView]], [[ViewedArrayBuffer]], [[ByteLength]], [[ByteOffset]] »)로 둔다.
  11. IsDetachedBuffer(buffer)가 true이면, TypeError exception을 throw한다.
  12. bufferByteLengthArrayBufferByteLength(buffer, seq-cst)로 설정한다.
  13. offset > bufferByteLength이면, RangeError exception을 throw한다.
  14. byteLengthundefined가 아니면, 다음을 수행한다.
    1. offset + viewByteLength > bufferByteLength이면, RangeError exception을 throw한다.
  15. obj.[[ViewedArrayBuffer]]buffer로 설정한다.
  16. obj.[[ByteLength]]viewByteLength로 설정한다.
  17. obj.[[ByteOffset]]offset으로 설정한다.
  18. obj를 반환한다.

25.3.3 DataView Constructor의 Properties

DataView constructor는:

  • value가 %Function.prototype%[[Prototype]] internal slot을 가집니다.
  • 다음 properties를 가집니다:

25.3.3.1 DataView.prototype

DataView.prototype의 initial value는 DataView prototype object입니다.

이 property는 attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }를 가집니다.

25.3.4 DataView Prototype Object의 Properties

DataView prototype object는:

  • %DataView.prototype%입니다.
  • value가 %Object.prototype%[[Prototype]] internal slot을 가집니다.
  • ordinary object입니다.
  • [[DataView]], [[ViewedArrayBuffer]], [[ByteLength]], 또는 [[ByteOffset]] internal slot을 가지지 않습니다.

25.3.4.1 get DataView.prototype.buffer

DataView.prototype.buffer는 set accessor function이 undefinedaccessor property입니다. Its get accessor function은 called될 때 다음 steps를 수행합니다:

  1. objthis value로 둔다.
  2. RequireInternalSlot(obj, [[DataView]])를 수행한다.
  3. Assert: obj[[ViewedArrayBuffer]] internal slot을 가진다.
  4. bufferobj.[[ViewedArrayBuffer]]로 둔다.
  5. buffer를 반환한다.

25.3.4.2 get DataView.prototype.byteLength

DataView.prototype.byteLength는 set accessor function이 undefinedaccessor property입니다. Its get accessor function은 called될 때 다음 steps를 수행합니다:

  1. objthis value로 둔다.
  2. RequireInternalSlot(obj, [[DataView]])를 수행한다.
  3. Assert: obj[[ViewedArrayBuffer]] internal slot을 가진다.
  4. viewRecordMakeDataViewWithBufferWitnessRecord(obj, seq-cst)로 둔다.
  5. IsViewOutOfBounds(viewRecord)가 true이면, TypeError exception을 throw한다.
  6. sizeGetViewByteLength(viewRecord)로 둔다.
  7. 𝔽(size)를 반환한다.

25.3.4.3 get DataView.prototype.byteOffset

DataView.prototype.byteOffset는 set accessor function이 undefinedaccessor property입니다. Its get accessor function은 called될 때 다음 steps를 수행합니다:

  1. objthis value로 둔다.
  2. RequireInternalSlot(obj, [[DataView]])를 수행한다.
  3. Assert: obj[[ViewedArrayBuffer]] internal slot을 가진다.
  4. viewRecordMakeDataViewWithBufferWitnessRecord(obj, seq-cst)로 둔다.
  5. IsViewOutOfBounds(viewRecord)가 true이면, TypeError exception을 throw한다.
  6. offsetobj.[[ByteOffset]]으로 둔다.
  7. 𝔽(offset)를 반환한다.

25.3.4.4 DataView.prototype.constructor

DataView.prototype.constructor의 initial value는 %DataView%입니다.

25.3.4.5 DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] )

이 method는 called될 때 다음 steps를 수행합니다:

  1. viewthis value로 둔다.
  2. GetViewValue(view, byteOffset, littleEndian, bigint64)를 반환한다.

25.3.4.6 DataView.prototype.getBigUint64 ( byteOffset [ , littleEndian ] )

이 method는 called될 때 다음 steps를 수행합니다:

  1. viewthis value로 둔다.
  2. GetViewValue(view, byteOffset, littleEndian, biguint64)를 반환한다.

25.3.4.7 DataView.prototype.getFloat16 ( byteOffset [ , littleEndian ] )

이 method는 called될 때 다음 steps를 수행합니다:

  1. viewthis value로 둔다.
  2. littleEndian이 present하지 않으면, littleEndianfalse로 설정한다.
  3. GetViewValue(view, byteOffset, littleEndian, float16)를 반환한다.

25.3.4.8 DataView.prototype.getFloat32 ( byteOffset [ , littleEndian ] )

이 method는 called될 때 다음 steps를 수행합니다:

  1. viewthis value로 둔다.
  2. littleEndian이 present하지 않으면, littleEndianfalse로 설정한다.
  3. GetViewValue(view, byteOffset, littleEndian, float32)를 반환한다.

25.3.4.9 DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] )

이 method는 called될 때 다음 steps를 수행합니다:

  1. viewthis value로 둔다.
  2. littleEndian이 present하지 않으면, littleEndianfalse로 설정한다.
  3. GetViewValue(view, byteOffset, littleEndian, float64)를 반환한다.

25.3.4.10 DataView.prototype.getInt8 ( byteOffset )

이 method는 called될 때 다음 steps를 수행합니다:

  1. viewthis value로 둔다.
  2. GetViewValue(view, byteOffset, true, int8)를 반환한다.

25.3.4.11 DataView.prototype.getInt16 ( byteOffset [ , littleEndian ] )

이 method는 called될 때 다음 steps를 수행합니다:

  1. viewthis value로 둔다.
  2. littleEndian이 present하지 않으면, littleEndianfalse로 설정한다.
  3. GetViewValue(view, byteOffset, littleEndian, int16)를 반환한다.

25.3.4.12 DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] )

이 method는 called될 때 다음 steps를 수행합니다:

  1. viewthis value로 둔다.
  2. littleEndian이 present하지 않으면, littleEndianfalse로 설정한다.
  3. GetViewValue(view, byteOffset, littleEndian, int32)를 반환한다.

25.3.4.13 DataView.prototype.getUint8 ( byteOffset )

이 method는 called될 때 다음 steps를 수행합니다:

  1. viewthis value로 둔다.
  2. GetViewValue(view, byteOffset, true, uint8)를 반환한다.

25.3.4.14 DataView.prototype.getUint16 ( byteOffset [ , littleEndian ] )

이 method는 called될 때 다음 steps를 수행합니다:

  1. viewthis value로 둔다.
  2. littleEndian이 present하지 않으면, littleEndianfalse로 설정한다.
  3. GetViewValue(view, byteOffset, littleEndian, uint16)를 반환한다.

25.3.4.15 DataView.prototype.getUint32 ( byteOffset [ , littleEndian ] )

이 method는 called될 때 다음 steps를 수행합니다:

  1. viewthis value로 둔다.
  2. littleEndian이 present하지 않으면, littleEndianfalse로 설정한다.
  3. GetViewValue(view, byteOffset, littleEndian, uint32)를 반환한다.

25.3.4.16 DataView.prototype.setBigInt64 ( byteOffset, value [ , littleEndian ] )

이 method는 called될 때 다음 steps를 수행합니다:

  1. viewthis value로 둔다.
  2. SetViewValue(view, byteOffset, littleEndian, bigint64, value)를 반환한다.

25.3.4.17 DataView.prototype.setBigUint64 ( byteOffset, value [ , littleEndian ] )

이 method는 called될 때 다음 steps를 수행합니다:

  1. viewthis value로 둔다.
  2. SetViewValue(view, byteOffset, littleEndian, biguint64, value)를 반환한다.

25.3.4.18 DataView.prototype.setFloat16 ( byteOffset, value [ , littleEndian ] )

이 method는 called될 때 다음 steps를 수행합니다:

  1. viewthis value로 둔다.
  2. littleEndian이 present하지 않으면, littleEndianfalse로 설정한다.
  3. SetViewValue(view, byteOffset, littleEndian, float16, value)를 반환한다.

25.3.4.19 DataView.prototype.setFloat32 ( byteOffset, value [ , littleEndian ] )

이 method는 called될 때 다음 steps를 수행합니다:

  1. viewthis value로 둔다.
  2. littleEndian이 present하지 않으면, littleEndianfalse로 설정한다.
  3. SetViewValue(view, byteOffset, littleEndian, float32, value)를 반환한다.

25.3.4.20 DataView.prototype.setFloat64 ( byteOffset, value [ , littleEndian ] )

이 method는 called될 때 다음 steps를 수행합니다:

  1. viewthis value로 둔다.
  2. littleEndian이 present하지 않으면, littleEndianfalse로 설정한다.
  3. SetViewValue(view, byteOffset, littleEndian, float64, value)를 반환한다.

25.3.4.21 DataView.prototype.setInt8 ( byteOffset, value )

이 method는 called될 때 다음 steps를 수행합니다:

  1. viewthis value로 둔다.
  2. SetViewValue(view, byteOffset, true, int8, value)를 반환한다.

25.3.4.22 DataView.prototype.setInt16 ( byteOffset, value [ , littleEndian ] )

이 method는 called될 때 다음 steps를 수행합니다:

  1. viewthis value로 둔다.
  2. littleEndian이 present하지 않으면, littleEndianfalse로 설정한다.
  3. SetViewValue(view, byteOffset, littleEndian, int16, value)를 반환한다.

25.3.4.23 DataView.prototype.setInt32 ( byteOffset, value [ , littleEndian ] )

이 method는 called될 때 다음 steps를 수행합니다:

  1. viewthis value로 둔다.
  2. littleEndian이 present하지 않으면, littleEndianfalse로 설정한다.
  3. SetViewValue(view, byteOffset, littleEndian, int32, value)를 반환한다.

25.3.4.24 DataView.prototype.setUint8 ( byteOffset, value )

이 method는 called될 때 다음 steps를 수행합니다:

  1. viewthis value로 둔다.
  2. SetViewValue(view, byteOffset, true, uint8, value)를 반환한다.

25.3.4.25 DataView.prototype.setUint16 ( byteOffset, value [ , littleEndian ] )

이 method는 called될 때 다음 steps를 수행합니다:

  1. viewthis value로 둔다.
  2. littleEndian이 present하지 않으면, littleEndianfalse로 설정한다.
  3. SetViewValue(view, byteOffset, littleEndian, uint16, value)를 반환한다.

25.3.4.26 DataView.prototype.setUint32 ( byteOffset, value [ , littleEndian ] )

이 method는 called될 때 다음 steps를 수행합니다:

  1. viewthis value로 둔다.
  2. littleEndian이 present하지 않으면, littleEndianfalse로 설정한다.
  3. SetViewValue(view, byteOffset, littleEndian, uint32, value)를 반환한다.

25.3.4.27 DataView.prototype [ %Symbol.toStringTag% ]

%Symbol.toStringTag% property의 initial value는 String value "DataView"입니다.

이 property는 attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }를 가집니다.

25.3.5 DataView Instances의 Properties

DataView instances는 DataView prototype object로부터 properties를 inherit하는 ordinary objects입니다. DataView instances는 각각 [[DataView]], [[ViewedArrayBuffer]], [[ByteLength]], 및 [[ByteOffset]] internal slots를 가집니다.

Note

[[DataView]] internal slot의 value는 이 specification 안에서 사용되지 않습니다. 그 internal slot의 simple presence는 DataView constructor를 사용하여 created된 objects를 identify하기 위해 specification 안에서 사용됩니다.

25.4 Atomics 객체

Atomics object는:

  • %Atomics%입니다.
  • global object"Atomics" property의 initial value입니다.
  • ordinary object입니다.
  • value가 %Object.prototype%[[Prototype]] internal slot을 가집니다.
  • [[Construct]] internal method를 가지지 않습니다; new operator와 함께 constructor로 사용될 수 없습니다.
  • [[Call]] internal method를 가지지 않습니다; function으로 invoked될 수 없습니다.

Atomics object는 shared memory array cells에 대해 indivisibly(atomically) operate하는 functions뿐 아니라 agents가 primitive events를 wait하고 dispatch할 수 있게 하는 functions를 제공합니다. disciplined하게 사용될 때, Atomics functions는 shared memory를 통해 communicate하는 multi-agent programs가 parallel CPUs에서도 well-understood order로 execute되도록 합니다. shared-memory communication을 govern하는 rules는 아래에 defined된 memory model에 의해 제공됩니다.

Note

ECMAScript에서 shared memory를 programming하고 implementing하기 위한 informative guidelines는 memory model section의 끝에 있는 notes를 참조하십시오.

25.4.1 Waiter Record

Waiter RecordAtomics.wait 또는 Atomics.waitAsync에 대한 particular call을 denote하는 데 사용되는 Record value입니다.

Waiter Record는 Table 74에 listed된 fields를 가집니다.

Table 74: Waiter Record Fields
Field Name Value Meaning
[[AgentSignifier]] an agent signifier Atomics.wait 또는 Atomics.waitAsync를 called한 agent입니다.
[[PromiseCapability]] a PromiseCapability Record or blocking Atomics.waitAsync에 대한 call을 denoting하는 경우 resulting promise이고, 그렇지 않으면 blocking입니다.
[[TimeoutTime]] a non-negative extended mathematical value timeout이 trigger될 수 있는 earliest time입니다; time values를 사용하여 computed됩니다.
[[Result]] "ok" or "timed-out" call의 return value입니다.

25.4.2 WaiterList Records

WaiterList RecordAtomics.wait, Atomics.waitAsync, 및 Atomics.notify를 통한 agents의 waiting과 notification을 explain하는 데 사용됩니다.

WaiterList Record는 Table 75에 listed된 fields를 가집니다.

Table 75: WaiterList Record Fields
Field Name Value Meaning
[[Waiters]] a List of Waiter Records 이 WaiterList가 associated된 location에서 waiting하고 있는 Atomics.wait 또는 Atomics.waitAsync에 대한 calls입니다.
[[MostRecentLeaveEvent]] a Synchronize event or empty its critical section의 most recent leaving event이거나, its critical section이 never entered된 경우 empty입니다.

same agent signifier를 가진 multiple Waiter Records가 WaiterList 안에 있을 수 있습니다.

agent cluster는 WaiterList Records의 store를 가집니다; store는 (block, i)로 indexed되며, 여기서 blockShared Data Block이고 iblock의 memory 안으로의 byte offset입니다. WaiterList Records는 agent-independent입니다: any agent in the agent cluster에서 (block, i)로 WaiterList Records의 store를 lookup하면 same WaiterList Record가 result됩니다.

Each WaiterList Record는 evaluation 동안 that WaiterList Record에 대한 exclusive access를 control하는 critical section을 가집니다. 한 번에 단일 agent만 WaiterList Record's critical section에 enter할 수 있습니다. WaiterList Record's critical section에 entering하고 leaving하는 것은 EnterCriticalSectionLeaveCriticalSection abstract operations에 의해 controlled됩니다. WaiterList Record에 대한 operations—waiting agents를 adding 및 removing하기, agents의 list를 traversing하기, list의 agents를 suspending 및 notifying하기, Synchronize event를 setting 및 retrieving하기—는 WaiterList Record's critical section에 entered한 agents에 의해서만 performed될 수 있습니다.

25.4.3 Atomics를 위한 Abstract Operations

25.4.3.1 ValidateIntegerTypedArray ( ta, waitable )

The abstract operation ValidateIntegerTypedArray takes arguments ta (an ECMAScript language value) and waitable (a Boolean) and returns either a normal completion containing a TypedArray With Buffer Witness Record, or a throw completion. It performs the following steps when called:

  1. taRecord를 ? ValidateTypedArray(ta, unordered)로 둔다.
  2. NOTE: ta's backing buffer가 growable SharedArrayBuffer일 때 bounds checking은 synchronizing operation이 아닙니다.
  3. waitabletrue이면, 다음을 수행한다.
    1. ta.[[TypedArrayName]]"Int32Array""BigInt64Array"도 아니면, TypeError exception을 throw한다.
  4. 그렇지 않으면,
    1. typeTypedArrayElementType(ta)로 둔다.
    2. IsUnclampedIntegerElementType(type)이 false이고 IsBigIntElementType(type)이 false이면, TypeError exception을 throw한다.
  5. taRecord를 반환한다.

25.4.3.2 ValidateAtomicAccess ( taRecord, requestIndex )

The abstract operation ValidateAtomicAccess takes arguments taRecord (a TypedArray With Buffer Witness Record) and requestIndex (an ECMAScript language value) and returns either a normal completion containing a non-negative integer or a throw completion. It performs the following steps when called:

  1. lengthTypedArrayLength(taRecord)로 둔다.
  2. accessIndex를 ? ToIndex(requestIndex)로 둔다.
  3. Assert: accessIndex ≥ 0.
  4. accessIndexlength이면, RangeError exception을 throw한다.
  5. tataRecord.[[Object]]로 둔다.
  6. elementSizeTypedArrayElementSize(ta)로 둔다.
  7. offsetta.[[ByteOffset]]으로 둔다.
  8. (accessIndex × elementSize) + offset을 반환한다.

25.4.3.3 ValidateAtomicAccessOnIntegerTypedArray ( ta, requestIndex )

The abstract operation ValidateAtomicAccessOnIntegerTypedArray takes arguments ta (an ECMAScript language value) and requestIndex (an ECMAScript language value) and returns either a normal completion containing a non-negative integer or a throw completion. It performs the following steps when called:

  1. taRecord를 ? ValidateIntegerTypedArray(ta, false)로 둔다.
  2. ValidateAtomicAccess(taRecord, requestIndex)를 반환한다.

25.4.3.4 RevalidateAtomicAccess ( ta, byteIndexInBuffer )

The abstract operation RevalidateAtomicAccess takes arguments ta (a TypedArray) and byteIndexInBuffer (a non-negative integer) and returns either a normal completion containing unused or a throw completion. 이 operation은 Atomics methods에서 모든 argument coercions가 performed된 후 atomic operations를 위한 backing buffer 안의 index를 revalidates합니다. argument coercions는 arbitrary side effects를 가질 수 있고, 이는 buffer가 out of bounds가 되도록 cause할 수 있기 때문입니다. 이 operation은 ta's backing buffer가 SharedArrayBuffer일 때 throw하지 않습니다. It performs the following steps when called:

  1. taRecordMakeTypedArrayWithBufferWitnessRecord(ta, unordered)로 둔다.
  2. NOTE: ta's backing buffer가 growable SharedArrayBuffer일 때 bounds checking은 synchronizing operation이 아닙니다.
  3. IsTypedArrayOutOfBounds(taRecord)가 true이면, TypeError exception을 throw한다.
  4. Assert: byteIndexInBufferta.[[ByteOffset]].
  5. byteIndexInBuffertaRecord.[[CachedBufferByteLength]]이면, RangeError exception을 throw한다.
  6. unused를 반환한다.

25.4.3.5 GetWaiterList ( block, i )

The abstract operation GetWaiterList takes arguments block (a Shared Data Block) and i (a non-negative integer that is evenly divisible by 4) and returns a WaiterList Record. It performs the following steps when called:

  1. Assert: ii + 3은 block의 memory 안에서 valid byte offsets이다.
  2. pair (block, i)에 의해 referenced되는 WaiterList Record를 반환한다.

25.4.3.6 EnterCriticalSection ( waiterList )

The abstract operation EnterCriticalSection takes argument waiterList (a WaiterList Record) and returns unused. It performs the following steps when called:

  1. Assert: surrounding agent는 any WaiterList Record에 대한 critical section 안에 있지 않다.
  2. no agentwaiterList에 대한 critical section 안에 있을 때까지 wait한 다음, waiterList에 대한 critical section에 enter한다(any other agent가 enter하는 것을 allow하지 않고).
  3. waiterList.[[MostRecentLeaveEvent]]empty가 아니면, 다음을 수행한다.
    1. NOTE: critical section이 at least once entered된 waiterListLeaveCriticalSection에 의해 set된 Synchronize event를 가집니다.
    2. agentRecordsurrounding agentAgent Record로 둔다.
    3. executionagentRecord.[[CandidateExecution]]으로 둔다.
    4. eventsRecordAgentSignifier()인 [[AgentSignifier]]를 가진 execution.[[EventsRecords]]Agent Events Record로 둔다.
    5. enterEvent를 new Synchronize event로 둔다.
    6. enterEventeventsRecord.[[EventList]]에 append한다.
    7. (waiterList.[[MostRecentLeaveEvent]], enterEvent)를 eventsRecord.[[AgentSynchronizesWith]]에 append한다.
  4. unused를 반환한다.

EnterCriticalSection은 critical section에 enter하려는 agent가 another agent가 leave할 때까지 wait해야 할 때 contention을 가집니다. contention이 없을 때, EnterCriticalSection calls의 FIFO order는 observable입니다. contention이 있을 때, implementation은 arbitrary order를 choose할 수 있지만 agent가 indefinitely wait하도록 cause해서는 안 됩니다.

25.4.3.7 LeaveCriticalSection ( waiterList )

The abstract operation LeaveCriticalSection takes argument waiterList (a WaiterList Record) and returns unused. It performs the following steps when called:

  1. Assert: surrounding agentwaiterList에 대한 critical section 안에 있다.
  2. agentRecordsurrounding agentAgent Record로 둔다.
  3. executionagentRecord.[[CandidateExecution]]으로 둔다.
  4. eventsRecordAgentSignifier()인 [[AgentSignifier]]를 가진 execution.[[EventsRecords]]Agent Events Record로 둔다.
  5. leaveEvent를 new Synchronize event로 둔다.
  6. leaveEventeventsRecord.[[EventList]]에 append한다.
  7. waiterList.[[MostRecentLeaveEvent]]leaveEvent로 설정한다.
  8. waiterList에 대한 critical section을 leave한다.
  9. unused를 반환한다.

25.4.3.8 AddWaiter ( waiterList, waiterRecord )

The abstract operation AddWaiter takes arguments waiterList (a WaiterList Record) and waiterRecord (a Waiter Record) and returns unused. It performs the following steps when called:

  1. Assert: surrounding agentwaiterList에 대한 critical section 안에 있다.
  2. Assert: waiterList.[[Waiters]] 안에는 [[PromiseCapability]] field가 waiterRecord.[[PromiseCapability]]이고 [[AgentSignifier]] field가 waiterRecord.[[AgentSignifier]]Waiter Record가 없다.
  3. waiterRecordwaiterList.[[Waiters]]에 append한다.
  4. unused를 반환한다.

25.4.3.9 RemoveWaiter ( waiterList, waiterRecord )

The abstract operation RemoveWaiter takes arguments waiterList (a WaiterList Record) and waiterRecord (a Waiter Record) and returns unused. It performs the following steps when called:

  1. Assert: surrounding agentwaiterList에 대한 critical section 안에 있다.
  2. Assert: waiterList.[[Waiters]]waiterRecord를 contain한다.
  3. waiterRecordwaiterList.[[Waiters]]에서 remove한다.
  4. unused를 반환한다.

25.4.3.10 RemoveWaiters ( waiterList, count )

The abstract operation RemoveWaiters takes arguments waiterList (a WaiterList Record) and count (a non-negative integer or +∞) and returns a List of Waiter Records. It performs the following steps when called:

  1. Assert: surrounding agentwaiterList에 대한 critical section 안에 있다.
  2. lengthwaiterList.[[Waiters]] 안의 elements 수로 둔다.
  3. countmin(count, length)로 설정한다.
  4. waiters를 elements가 waiterList.[[Waiters]]의 first count elements인 List로 둔다.
  5. waiterList.[[Waiters]]의 first count elements를 remove한다.
  6. waiters를 반환한다.

25.4.3.11 SuspendThisAgent ( waiterList, waiterRecord )

The abstract operation SuspendThisAgent takes arguments waiterList (a WaiterList Record) and waiterRecord (a Waiter Record) and returns unused. It performs the following steps when called:

  1. Assert: surrounding agentwaiterList에 대한 critical section 안에 있다.
  2. Assert: waiterList.[[Waiters]]waiterRecord를 contain한다.
  3. thisAgentAgentSignifier()로 둔다.
  4. Assert: waiterRecord.[[AgentSignifier]]thisAgent이다.
  5. Assert: waiterRecord.[[PromiseCapability]]blocking이다.
  6. Assert: AgentCanSuspend()는 true이다.
  7. LeaveCriticalSection(waiterList)를 수행하고 time이 waiterRecord.[[TimeoutTime]]이 될 때까지 surrounding agent를 suspend하되, critical section이 exited된 후 suspension이 effect를 가지기 전에 arriving하는 notification이 lost되지 않는 방식으로 combined operation을 수행한다. surrounding agent는 timeout 때문이거나 another agent가 arguments waiterListthisAgentNotifyWaiter를 calling하는 것(즉 Atomics.notify에 대한 call을 통해) 때문에만 suspension에서 wake할 수 있다.
  8. EnterCriticalSection(waiterList)를 수행한다.
  9. unused를 반환한다.

25.4.3.12 NotifyWaiter ( waiterList, waiterRecord )

The abstract operation NotifyWaiter takes arguments waiterList (a WaiterList Record) and waiterRecord (a Waiter Record) and returns unused. It performs the following steps when called:

  1. Assert: surrounding agentwaiterList에 대한 critical section 안에 있다.
  2. waiterRecord.[[PromiseCapability]]blocking이면, 다음을 수행한다.
    1. signifier가 waiterRecord.[[AgentSignifier]]agent를 suspension에서 wake한다.
    2. NOTE: 이는 agentSuspendThisAgent 안에서 execution을 resume하도록 causes합니다.
  3. 그렇지 않고 AgentSignifier()가 waiterRecord.[[AgentSignifier]]이면, 다음을 수행한다.
    1. promiseCapabilitywaiterRecord.[[PromiseCapability]]로 둔다.
    2. Call(promiseCapability.[[Resolve]], undefined, « waiterRecord.[[Result]] »)를 수행한다.
  4. 그렇지 않으면,
    1. EnqueueResolveInAgentJob(waiterRecord.[[AgentSignifier]], waiterRecord.[[PromiseCapability]], waiterRecord.[[Result]])를 수행한다.
  5. unused를 반환한다.
Note

agent는 another agent's promise capability를 host에 passing하는 것 beyond any capacity로 access해서는 안 됩니다.

25.4.3.13 EnqueueResolveInAgentJob ( agentSignifier, promiseCapability, resolution )

The abstract operation EnqueueResolveInAgentJob takes arguments agentSignifier (an agent signifier), promiseCapability (a PromiseCapability Record), and resolution ("ok" or "timed-out") and returns unused. It performs the following steps when called:

  1. resolveJob을 parameters가 없고 agentSignifier, promiseCapability, 및 resolution을 captures하며 called될 때 다음 steps를 수행하는 new Job Abstract Closure로 둔다:
    1. Assert: AgentSignifier()는 agentSignifier이다.
    2. Call(promiseCapability.[[Resolve]], undefined, « resolution »)를 수행한다.
    3. unused를 반환한다.
  2. realmInTargetAgent를 ! GetFunctionRealm(promiseCapability.[[Resolve]])로 둔다.
  3. Assert: agentSignifierrealmInTargetAgent.[[AgentSignifier]]이다.
  4. HostEnqueueGenericJob(resolveJob, realmInTargetAgent)를 수행한다.
  5. unused를 반환한다.

25.4.3.14 DoWait ( mode, ta, index, value, timeout )

The abstract operation DoWait takes arguments mode (sync or async), ta (an ECMAScript language value), index (an ECMAScript language value), value (an ECMAScript language value), and timeout (an ECMAScript language value) and returns either a normal completion containing either an Object, "not-equal", "timed-out", or "ok", or a throw completion. It performs the following steps when called:

  1. taRecord를 ? ValidateIntegerTypedArray(ta, true)로 둔다.
  2. buffertaRecord.[[Object]].[[ViewedArrayBuffer]]로 둔다.
  3. IsSharedArrayBuffer(buffer)가 false이면, TypeError exception을 throw한다.
  4. byteIndexInBuffer를 ? ValidateAtomicAccess(taRecord, index)로 둔다.
  5. arrayTypeNameta.[[TypedArrayName]]으로 둔다.
  6. arrayTypeName"BigInt64Array"이면, expected를 ? ToBigInt64(value)로 둔다.
  7. 그렇지 않으면, expected를 ? ToInt32(value)로 둔다.
  8. timeoutNumber를 ? ToNumber(timeout)로 둔다.
  9. timeoutNumberNaN 또는 +∞𝔽 중 하나이면, realTimeout을 +∞로 둔다.
  10. 그렇지 않고 timeoutNumber-∞𝔽이면, realTimeout을 0으로 둔다.
  11. 그렇지 않으면, realTimeoutmax((timeoutNumber), 0)으로 둔다.
  12. modesync이고 AgentCanSuspend()가 false이면, TypeError exception을 throw한다.
  13. blockbuffer.[[ArrayBufferData]]로 둔다.
  14. waiterListGetWaiterList(block, byteIndexInBuffer)로 둔다.
  15. modesync이면, 다음을 수행한다.
    1. promiseCapabilityblocking으로 둔다.
    2. resultObjundefined로 둔다.
  16. 그렇지 않으면,
    1. promiseCapability를 ! NewPromiseCapability(%Promise%)로 둔다.
    2. resultObjOrdinaryObjectCreate(%Object.prototype%)로 둔다.
  17. EnterCriticalSection(waiterList)를 수행한다.
  18. elementTypeTypedArrayElementType(ta)로 둔다.
  19. witnessGetValueFromBuffer(buffer, byteIndexInBuffer, elementType, true, seq-cst)로 둔다.
  20. expectedwitness이면, 다음을 수행한다.
    1. LeaveCriticalSection(waiterList)를 수행한다.
    2. modesync이면, "not-equal"을 반환한다.
    3. CreateDataPropertyOrThrow(resultObj, "async", false)를 수행한다.
    4. CreateDataPropertyOrThrow(resultObj, "value", "not-equal")를 수행한다.
    5. resultObj를 반환한다.
  21. realTimeout = 0이고 modeasync이면, 다음을 수행한다.
    1. NOTE: synchronous immediate timeouts에 대한 special handling은 없습니다. Asynchronous immediate timeouts는 fail fast하고 unnecessary Promise jobs를 avoid하기 위해 special handling을 가집니다.
    2. LeaveCriticalSection(waiterList)를 수행한다.
    3. CreateDataPropertyOrThrow(resultObj, "async", false)를 수행한다.
    4. CreateDataPropertyOrThrow(resultObj, "value", "timed-out")를 수행한다.
    5. resultObj를 반환한다.
  22. thisAgentAgentSignifier()로 둔다.
  23. now를 current time을 identifying하는 time value (UTC)로 둔다.
  24. additionalTimeoutimplementation-defined non-negative mathematical value로 둔다.
  25. timeoutTime(now) + realTimeout + additionalTimeout으로 둔다.
  26. NOTE: realTimeout이 +∞일 때, timeoutTime도 +∞입니다.
  27. waiterRecord를 new Waiter Record { [[AgentSignifier]]: thisAgent, [[PromiseCapability]]: promiseCapability, [[TimeoutTime]]: timeoutTime, [[Result]]: "ok" }로 둔다.
  28. AddWaiter(waiterList, waiterRecord)를 수행한다.
  29. modesync이면, 다음을 수행한다.
    1. SuspendThisAgent(waiterList, waiterRecord)를 수행한다.
  30. 그렇지 않고 timeoutTimefinite이면, 다음을 수행한다.
    1. EnqueueAtomicsWaitAsyncTimeoutJob(waiterList, waiterRecord)를 수행한다.
  31. LeaveCriticalSection(waiterList)를 수행한다.
  32. modesync이면, waiterRecord.[[Result]]를 반환한다.
  33. CreateDataPropertyOrThrow(resultObj, "async", true)를 수행한다.
  34. CreateDataPropertyOrThrow(resultObj, "value", promiseCapability.[[Promise]])를 수행한다.
  35. resultObj를 반환한다.
Note

additionalTimeout은 power consumption을 reducing하거나 timing attacks를 mitigate하기 위해 timer resolution을 coarsening하는 것처럼, implementations가 necessary하게 timeouts를 pad할 수 있게 합니다. 이 value는 DoWait의 call마다 differ할 수 있습니다.

25.4.3.15 EnqueueAtomicsWaitAsyncTimeoutJob ( waiterList, waiterRecord )

The abstract operation EnqueueAtomicsWaitAsyncTimeoutJob takes arguments waiterList (a WaiterList Record) and waiterRecord (a Waiter Record) and returns unused. It performs the following steps when called:

  1. timeoutJob을 parameters가 없고 waiterListwaiterRecord를 captures하며 called될 때 다음 steps를 수행하는 new Job Abstract Closure로 둔다:
    1. EnterCriticalSection(waiterList)를 수행한다.
    2. waiterList.[[Waiters]]waiterRecord를 contain하면, 다음을 수행한다.
      1. timeOfJobExecution을 current time을 identifying하는 time value (UTC)로 둔다.
      2. Assert: (timeOfJobExecution) ≥ waiterRecord.[[TimeoutTime]] (time values의 potential non-monotonicity를 ignoring함).
      3. waiterRecord.[[Result]]"timed-out"으로 설정한다.
      4. RemoveWaiter(waiterList, waiterRecord)를 수행한다.
      5. NotifyWaiter(waiterList, waiterRecord)를 수행한다.
    3. LeaveCriticalSection(waiterList)를 수행한다.
    4. unused를 반환한다.
  2. now를 current time을 identifying하는 time value (UTC)로 둔다.
  3. currentRealm을 current Realm Record로 둔다.
  4. HostEnqueueTimeoutJob(timeoutJob, currentRealm, 𝔽(waiterRecord.[[TimeoutTime]]) - now)를 수행한다.
  5. unused를 반환한다.

25.4.3.16 AtomicCompareExchangeInSharedBlock ( block, byteIndexInBuffer, elementSize, expectedBytes, replacementBytes )

The abstract operation AtomicCompareExchangeInSharedBlock takes arguments block (a Shared Data Block), byteIndexInBuffer (an integer), elementSize (a non-negative integer), expectedBytes (a List of byte values), and replacementBytes (a List of byte values) and returns a List of byte values. It performs the following steps when called:

  1. agentRecordsurrounding agentAgent Record로 둔다.
  2. executionagentRecord.[[CandidateExecution]]으로 둔다.
  3. eventsRecordAgentSignifier()인 [[AgentSignifier]]를 가진 execution.[[EventsRecords]]Agent Events Record로 둔다.
  4. rawBytesRead를 elements가 nondeterministically chosen byte values인 length elementSizeList로 둔다.
  5. NOTE: implementations에서 rawBytesRead는 underlying hardware의 load-link, load-exclusive, 또는 read-modify-write instruction의 operand의 result입니다. nondeterminism은 weak consistency를 가진 hardware의 observable behaviour를 describe하기 위한 memory model의 semantic prescription입니다.
  6. NOTE: expected value와 read value의 comparison은 expected value가 read value와 equal하지 않을 때 needlessly strong synchronization을 avoid하기 위해 read-modify-write modification function 밖에서 performed됩니다.
  7. ByteListEqual(rawBytesRead, expectedBytes)가 true이면, 다음을 수행한다.
    1. second를 parameters (oldBytes, newBytes)를 가지고 nothing을 captures하며 called될 때 atomically 다음 steps를 수행하는 new read-modify-write modification function으로 둔다:
      1. newBytes를 반환한다.
    2. eventReadModifyWriteSharedMemory { [[Order]]: seq-cst, [[NoTear]]: true, [[Block]]: block, [[ByteIndex]]: byteIndexInBuffer, [[ElementSize]]: elementSize, [[Payload]]: replacementBytes, [[ModifyOp]]: second }로 둔다.
  8. 그렇지 않으면,
    1. eventReadSharedMemory { [[Order]]: seq-cst, [[NoTear]]: true, [[Block]]: block, [[ByteIndex]]: byteIndexInBuffer, [[ElementSize]]: elementSize }로 둔다.
  9. eventeventsRecord.[[EventList]]에 append한다.
  10. Chosen Value Record { [[Event]]: event, [[ChosenValue]]: rawBytesRead }를 execution.[[ChosenValues]]에 append한다.
  11. rawBytesRead를 반환한다.

25.4.3.17 AtomicReadModifyWrite ( ta, index, value, op )

The abstract operation AtomicReadModifyWrite takes arguments ta (an ECMAScript language value), index (an ECMAScript language value), value (an ECMAScript language value), and op (a read-modify-write modification function) and returns either a normal completion containing either a Number or a BigInt, or a throw completion. opbyte values의 두 List arguments를 takes하고 byte valuesList를 returns합니다. 이 operation은 atomically value를 loads하고, 이를 another value와 combines하며, combination을 stores합니다. It returns the loaded value. It performs the following steps when called:

  1. byteIndexInBuffer를 ? ValidateAtomicAccessOnIntegerTypedArray(ta, index)로 둔다.
  2. ta.[[ContentType]]bigint이면, coerced를 ? ToBigInt(value)로 둔다.
  3. 그렇지 않으면, coerced𝔽(? ToIntegerOrInfinity(value))로 둔다.
  4. RevalidateAtomicAccess(ta, byteIndexInBuffer)를 수행한다.
  5. bufferta.[[ViewedArrayBuffer]]로 둔다.
  6. elementTypeTypedArrayElementType(ta)로 둔다.
  7. GetModifySetValueInBuffer(buffer, byteIndexInBuffer, elementType, coerced, op)를 반환한다.

25.4.3.18 ByteListBitwiseOp ( op, xBytes, yBytes )

The abstract operation ByteListBitwiseOp takes arguments op (&, ^, or |), xBytes (a List of byte values), and yBytes (a List of byte values) and returns a List of byte values. 이 operation은 arguments의 모든 byte values에 대해 bitwise operation을 atomically performs하고 byte valuesList를 returns합니다. It performs the following steps when called:

  1. Assert: xBytesyBytes는 same number of elements를 가진다.
  2. result를 new empty List로 둔다.
  3. i를 0으로 둔다.
  4. xBytes의 each element xByte에 대해, 다음을 수행한다.
    1. yByteyBytes[i]로 둔다.
    2. op&이면, 다음을 수행한다.
      1. resultBytexByteyByte에 bitwise AND operation을 applying한 result로 둔다.
    3. 그렇지 않고 op^이면, 다음을 수행한다.
      1. resultBytexByteyByte에 bitwise exclusive OR (XOR) operation을 applying한 result로 둔다.
    4. 그렇지 않으면,
      1. Assert: op|이다.
      2. resultBytexByteyByte에 bitwise inclusive OR operation을 applying한 result로 둔다.
    5. ii + 1로 설정한다.
    6. resultByteresult에 append한다.
  5. result를 반환한다.

25.4.3.19 ByteListEqual ( xBytes, yBytes )

The abstract operation ByteListEqual takes arguments xBytes (a List of byte values) and yBytes (a List of byte values) and returns a Boolean. It performs the following steps when called:

  1. xBytesyBytes가 same number of elements를 가지지 않으면, false를 반환한다.
  2. i를 0으로 둔다.
  3. xBytes의 each element xByte에 대해, 다음을 수행한다.
    1. yByteyBytes[i]로 둔다.
    2. xByteyByte이면, false를 반환한다.
    3. ii + 1로 설정한다.
  4. true를 반환한다.

25.4.4 Atomics.add ( ta, index, value )

이 function은 called될 때 다음 steps를 수행합니다:

  1. add를 parameters (xBytes, yBytes)를 가지고 ta를 captures하며 called될 때 atomically 다음 steps를 수행하는 new read-modify-write modification function으로 둔다:
    1. typeTypedArrayElementType(ta)로 둔다.
    2. agentRecordsurrounding agentAgent Record로 둔다.
    3. isLittleEndianagentRecord.[[LittleEndian]]으로 둔다.
    4. xRawBytesToNumeric(type, xBytes, isLittleEndian)으로 둔다.
    5. yRawBytesToNumeric(type, yBytes, isLittleEndian)으로 둔다.
    6. x가 Number이면, 다음을 수행한다.
      1. sumNumber::add(x, y)로 둔다.
    7. 그렇지 않으면,
      1. Assert: x는 BigInt이다.
      2. sumBigInt::add(x, y)로 둔다.
    8. sumBytesNumericToRawBytes(type, sum, isLittleEndian)로 둔다.
    9. Assert: sumBytes, xBytes, 및 yBytes는 same number of elements를 가진다.
    10. sumBytes를 반환한다.
  2. AtomicReadModifyWrite(ta, index, value, add)를 반환한다.

25.4.5 Atomics.and ( ta, index, value )

이 function은 called될 때 다음 steps를 수행합니다:

  1. and를 parameters (xBytes, yBytes)를 가지고 nothing을 captures하며 called될 때 atomically 다음 steps를 수행하는 new read-modify-write modification function으로 둔다:
    1. ByteListBitwiseOp(&, xBytes, yBytes)를 반환한다.
  2. AtomicReadModifyWrite(ta, index, value, and)를 반환한다.

25.4.6 Atomics.compareExchange ( ta, index, expectedValue, replacementValue )

이 function은 called될 때 다음 steps를 수행합니다:

  1. byteIndexInBuffer를 ? ValidateAtomicAccessOnIntegerTypedArray(ta, index)로 둔다.
  2. bufferta.[[ViewedArrayBuffer]]로 둔다.
  3. blockbuffer.[[ArrayBufferData]]로 둔다.
  4. ta.[[ContentType]]bigint이면, 다음을 수행한다.
    1. expected를 ? ToBigInt(expectedValue)로 둔다.
    2. replacement를 ? ToBigInt(replacementValue)로 둔다.
  5. 그렇지 않으면,
    1. expected𝔽(? ToIntegerOrInfinity(expectedValue))로 둔다.
    2. replacement𝔽(? ToIntegerOrInfinity(replacementValue))로 둔다.
  6. RevalidateAtomicAccess(ta, byteIndexInBuffer)를 수행한다.
  7. elementTypeTypedArrayElementType(ta)로 둔다.
  8. elementSizeTypedArrayElementSize(ta)로 둔다.
  9. agentRecordsurrounding agentAgent Record로 둔다.
  10. isLittleEndianagentRecord.[[LittleEndian]]으로 둔다.
  11. expectedBytesNumericToRawBytes(elementType, expected, isLittleEndian)로 둔다.
  12. replacementBytesNumericToRawBytes(elementType, replacement, isLittleEndian)로 둔다.
  13. IsSharedArrayBuffer(buffer)가 true이면, 다음을 수행한다.
    1. rawBytesReadAtomicCompareExchangeInSharedBlock(block, byteIndexInBuffer, elementSize, expectedBytes, replacementBytes)로 둔다.
  14. 그렇지 않으면,
    1. rawBytesRead를 elements가 block[byteIndexInBuffer]로 starting하는 elementSize bytes의 sequence인 length elementSizeList로 둔다.
    2. ByteListEqual(rawBytesRead, expectedBytes)가 true이면, 다음을 수행한다.
      1. replacementBytes의 individual bytes를 block 안에, block[byteIndexInBuffer]에서 starting하여 store한다.
  15. RawBytesToNumeric(elementType, rawBytesRead, isLittleEndian)을 반환한다.

25.4.7 Atomics.exchange ( ta, index, value )

이 function은 called될 때 다음 steps를 수행합니다:

  1. second를 parameters (oldBytes, newBytes)를 가지고 nothing을 captures하며 called될 때 atomically 다음 steps를 수행하는 new read-modify-write modification function으로 둔다:
    1. newBytes를 반환한다.
  2. AtomicReadModifyWrite(ta, index, value, second)를 반환한다.

25.4.8 Atomics.isLockFree ( size )

이 function은 called될 때 다음 steps를 수행합니다:

  1. n을 ? ToIntegerOrInfinity(size)로 둔다.
  2. agentRecordsurrounding agentAgent Record로 둔다.
  3. n = 1이면, agentRecord.[[IsLockFree1]]을 반환한다.
  4. n = 2이면, agentRecord.[[IsLockFree2]]를 반환한다.
  5. n = 4이면, true를 반환한다.
  6. n = 8이면, agentRecord.[[IsLockFree8]]을 반환한다.
  7. false를 반환한다.
Note

이 function은 optimization primitive입니다. intuition은 size n bytes인 datum에 대한 atomic primitive(compareExchange, load, store, add, sub, and, or, xor, 또는 exchange)의 atomic step이 datum을 comprising하는 n bytes outside의 lock을 surrounding agent가 acquiring하지 않고 performed될 것이라면, Atomics.isLockFree(n)가 true를 반환한다는 것입니다. High-performance algorithms는 critical sections에서 locks를 사용할지 atomic operations를 사용할지 determine하기 위해 이 function을 사용할 것입니다. atomic primitive가 lock-free가 아니면 algorithm이 its own locking을 provide하는 것이 often more efficient합니다.

Atomics.isLockFree(4)는 all known relevant hardware에서 supported될 수 있으므로 always true를 반환합니다. 이를 assume할 수 있음은 generally programs를 simplify할 것입니다.

이 function이 반환하는 value와 관계없이, all atomic operations는 atomic하다고 guaranteed됩니다. 예를 들어, operation 중간에 visible operation이 take place하는 일은 never 없습니다(예: “tearing”).

25.4.9 Atomics.load ( ta, index )

이 function은 called될 때 다음 steps를 수행합니다:

  1. byteIndexInBuffer를 ? ValidateAtomicAccessOnIntegerTypedArray(ta, index)로 둔다.
  2. RevalidateAtomicAccess(ta, byteIndexInBuffer)를 수행한다.
  3. bufferta.[[ViewedArrayBuffer]]로 둔다.
  4. elementTypeTypedArrayElementType(ta)로 둔다.
  5. GetValueFromBuffer(buffer, byteIndexInBuffer, elementType, true, seq-cst)를 반환한다.

25.4.10 Atomics.notify ( ta, index, count )

이 함수는 대기 큐에서 잠자고 있는 일부 에이전트에게 알린다.

호출될 때 다음 단계를 수행한다:

  1. taRecord를 ? ValidateIntegerTypedArray(ta, true)라고 하자.
  2. byteIndexInBuffer를 ? ValidateAtomicAccess(taRecord, index)라고 하자.
  3. countundefined이면,
    1. count를 +∞로 설정한다.
  4. 그렇지 않으면,
    1. intCount를 ? ToIntegerOrInfinity(count)라고 하자.
    2. countmax(intCount, 0)으로 설정한다.
  5. bufferta.[[ViewedArrayBuffer]]라고 하자.
  6. blockbuffer.[[ArrayBufferData]]라고 하자.
  7. IsSharedArrayBuffer(buffer)가 false이면, +0𝔽를 반환한다.
  8. waiterListGetWaiterList(block, byteIndexInBuffer)라고 하자.
  9. EnterCriticalSection(waiterList)를 수행한다.
  10. waitersRemoveWaiters(waiterList, count)라고 하자.
  11. waiters의 각 요소 waiterRecord에 대해, 다음을 수행한다.
    1. NotifyWaiter(waiterList, waiterRecord)를 수행한다.
  12. LeaveCriticalSection(waiterList)를 수행한다.
  13. waitersCountwaiters 안의 요소 수라고 하자.
  14. 𝔽(waitersCount)를 반환한다.

25.4.11 Atomics.or ( ta, index, value )

이 함수는 호출될 때 다음 단계를 수행한다:

  1. or를 매개변수 (xBytes, yBytes)를 가지고 아무것도 캡처하지 않으며 호출될 때 다음 단계를 원자적으로 수행하는 새 read-modify-write 수정 함수라고 하자:
    1. ByteListBitwiseOp(|, xBytes, yBytes)를 반환한다.
  2. AtomicReadModifyWrite(ta, index, value, or)를 반환한다.

25.4.12 Atomics.pause ( )

이 함수는 프로그램이 어떤 값을 기다리면서 스핀 루프 중이라는 힌트를 CPU에 제공한다.

호출될 때 다음 단계를 수행한다:

  1. ECMAScript 구현의 실행 환경이 현재 실행 중인 코드가 spin-wait 루프 안에 있음을 운영체제나 CPU에 신호로 알리는 것을 지원하면, 그 신호를 보낸다.
  2. undefined를 반환한다.
Note 1

이 메서드는 뮤텍스 내부의 spinlock fast path와 같이 spin-wait 루프를 구현하는 프로그램이, 어떤 값을 기다리는 동안 스핀 중이라는 힌트를 CPU에 제공하도록 설계되었다. 이 메서드는 타이밍 외에는 관찰 가능한 동작이 없다.

기반 아키텍처의 모범 사례가 스핀 루프에서 그러한 명령어를 권장하는 경우, 구현은 pause 또는 yield 명령어를 구현할 것으로 기대된다. 예를 들어, Intel 최적화 매뉴얼pause 명령어를 권장한다.

구현은 일시 정지되는 최대 시간에 대해 수십에서 수백 나노초 정도의 내부 상한을 두는 것이 권장된다.

Note 2

함수 호출의 오버헤드 때문에, 최적화 컴파일러에서 이 메서드에 대한 인라인 호출이 인라인되지 않은 호출과 다른 시간 동안 기다리는 것은 합리적이다.

25.4.13 Atomics.store ( ta, index, value )

이 함수는 호출될 때 다음 단계를 수행한다:

  1. byteIndexInBuffer를 ? ValidateAtomicAccessOnIntegerTypedArray(ta, index)라고 하자.
  2. ta.[[ContentType]]bigint이면, coerced를 ? ToBigInt(value)라고 하자.
  3. 그렇지 않으면, coerced𝔽(? ToIntegerOrInfinity(value))라고 하자.
  4. RevalidateAtomicAccess(ta, byteIndexInBuffer)를 수행한다.
  5. bufferta.[[ViewedArrayBuffer]]라고 하자.
  6. elementTypeTypedArrayElementType(ta)이라고 하자.
  7. SetValueInBuffer(buffer, byteIndexInBuffer, elementType, coerced, true, seq-cst)를 수행한다.
  8. coerced를 반환한다.

25.4.14 Atomics.sub ( ta, index, value )

이 함수는 호출될 때 다음 단계를 수행한다:

  1. subtract를 매개변수 (xBytes, yBytes)를 가지고 ta를 캡처하며 호출될 때 다음 단계를 원자적으로 수행하는 새 read-modify-write 수정 함수라고 하자:
    1. typeTypedArrayElementType(ta)이라고 하자.
    2. agentRecord를 둘러싸는 에이전트의 Agent Record라고 하자.
    3. isLittleEndianagentRecord.[[LittleEndian]]이라고 하자.
    4. xRawBytesToNumeric(type, xBytes, isLittleEndian)이라고 하자.
    5. yRawBytesToNumeric(type, yBytes, isLittleEndian)이라고 하자.
    6. x가 Number이면,
      1. differenceNumber::subtract(x, y)라고 하자.
    7. 그렇지 않으면,
      1. 단언: x는 BigInt이다.
      2. differenceBigInt::subtract(x, y)라고 하자.
    8. differenceBytesNumericToRawBytes(type, difference, isLittleEndian)라고 하자.
    9. 단언: differenceBytes, xBytes, yBytes는 같은 수의 요소를 가진다.
    10. differenceBytes를 반환한다.
  2. AtomicReadModifyWrite(ta, index, value, subtract)를 반환한다.

25.4.15 Atomics.wait ( ta, index, value, timeout )

이 함수는 둘러싸는 에이전트를 대기 큐에 넣고 알림을 받거나 대기 시간이 초과될 때까지 이를 일시 중단하며, 이러한 경우를 구분하는 String을 반환한다.

호출될 때 다음 단계를 수행한다:

  1. DoWait(sync, ta, index, value, timeout)를 반환한다.

25.4.16 Atomics.waitAsync ( ta, index, value, timeout )

이 함수는 호출한 에이전트가 알림을 받거나 timeout에 도달했을 때 해결되는 Promise를 반환한다.

호출될 때 다음 단계를 수행한다:

  1. DoWait(async, ta, index, value, timeout)를 반환한다.

25.4.17 Atomics.xor ( ta, index, value )

이 함수는 호출될 때 다음 단계를 수행한다:

  1. xor를 매개변수 (xBytes, yBytes)를 가지고 아무것도 캡처하지 않으며 호출될 때 다음 단계를 원자적으로 수행하는 새 read-modify-write 수정 함수라고 하자:
    1. ByteListBitwiseOp(^, xBytes, yBytes)를 반환한다.
  2. AtomicReadModifyWrite(ta, index, value, xor)를 반환한다.

25.4.18 Atomics [ %Symbol.toStringTag% ]

%Symbol.toStringTag% 속성의 초기값은 String 값 "Atomics"이다.

이 속성은 { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true } 속성을 가진다.

25.5 JSON 객체

JSON object는:

  • %JSON%입니다.
  • global object"JSON" property의 initial value입니다.
  • ordinary object입니다.
  • JSON texts를 parse하고 construct하는 데 사용되는 두 functions, parsestringify를 contains합니다.
  • value가 %Object.prototype%[[Prototype]] internal slot을 가집니다.
  • [[Construct]] internal method를 가지지 않습니다; new operator와 함께 constructor로 사용될 수 없습니다.
  • [[Call]] internal method를 가지지 않습니다; function으로 invoked될 수 없습니다.

JSON Data Interchange Format은 ECMA-404에 defined되어 있습니다. 이 specification에서 사용되는 JSON interchange format은 ECMA-404에 의해 described된 것과 exactly 같습니다. JSON.parseJSON.stringify의 conforming implementations는 ECMA-404 specification에 described된 exact interchange format을, format에 대한 deletions나 extensions 없이 support해야 합니다.

25.5.1 JSON.isRawJSON ( obj )

이 function은 called될 때 다음 steps를 수행합니다:

  1. obj가 Object이고 obj[[IsRawJSON]] internal slot을 가지면, true를 반환한다.
  2. false를 반환한다.

25.5.2 JSON.parse ( text [ , reviver ] )

이 function은 JSON text(JSON-formatted String)를 parses하고 ECMAScript language value를 produces합니다. JSON format은 literals, arrays, 및 objects를 ECMAScript literals, Array Initializers, 및 Object Initializers에 대한 syntax와 similar한 syntax로 represents합니다. parsing 후, JSON objects는 ECMAScript objects로 realized됩니다. JSON arrays는 ECMAScript Array instances로 realized됩니다. JSON strings, numbers, booleans, 및 null은 ECMAScript Strings, Numbers, Booleans, 및 null로 realized됩니다.

optional reviver parameter는 results를 filter하고 transform할 수 있는 function입니다. parse에 의해 produced된 each value에 대해, reviver는 three arguments(associated property key, value, 및 context object)와 함께 called됩니다. property가 unmodified이고 그 value가 primitive이면, provided context object는 corresponding Parse Node의 source text를 containing하는 "source" property를 가집니다. call이 undefined를 반환하면 property는 deleted됩니다. 그렇지 않으면 property는 return value를 사용하도록 redefined됩니다.

  1. jsonString을 ? ToString(text)로 둔다.
  2. parseResult를 ? ParseJSON(jsonString)으로 둔다.
  3. unfilteredparseResult.[[Value]]로 둔다.
  4. IsCallable(reviver)가 false이면, unfiltered를 반환한다.
  5. rootOrdinaryObjectCreate(%Object.prototype%)로 둔다.
  6. rootName을 empty String으로 둔다.
  7. CreateDataPropertyOrThrow(root, rootName, unfiltered)를 수행한다.
  8. snapshotCreateJSONParseRecord(parseResult.[[ParseNode]], rootName, unfiltered)로 둔다.
  9. InternalizeJSONProperty(root, rootName, reviver, snapshot)를 반환한다.

이 function의 "length" property는 2𝔽입니다.

25.5.2.1 ParseJSON ( text )

The abstract operation ParseJSON takes argument text (a String) and returns either a normal completion containing a Record with fields [[ParseNode]] (a Parse Node) and [[Value]] (an ECMAScript language value), or a throw completion. It performs the following steps when called:

  1. StringToCodePoints(text)가 ECMA-404에 specified된 valid JSON text가 아니면, SyntaxError exception을 throw한다.
  2. scriptString"(", text, 및 ");"string-concatenation으로 둔다.
  3. scriptParseText(scriptString, Script)로 둔다.
  4. NOTE: 13.2.5.1에 defined된 early error rules는 위 ParseText invocation에 대해 special handling을 가집니다.
  5. Assert: scriptParse Node이다.
  6. result를 ! Evaluation of script로 둔다.
  7. NOTE: 13.2.5.6에 defined된 PropertyDefinitionEvaluation semantics는 위 evaluation에 대해 special handling을 가집니다.
  8. Assert: result는 String, Number, Boolean, ArrayLiteral 또는 ObjectLiteral 중 하나에 의해 defined된 Object, 또는 null 중 하나이다.
  9. Record { [[ParseNode]]: script, [[Value]]: result }를 반환한다.

JSON.parse의 conforming implementation이 JSON grammars를 extend하는 것은 permitted되지 않습니다. implementation이 modified 또는 extended JSON interchange format을 support하려면, different parse function을 defining하여 그렇게 해야 합니다.

Note 1

Valid JSON text는 ECMAScript PrimaryExpression syntax의 subset입니다. Step 1jsonString이 that subset에 conforms함을 verifies하고, step 8는 evaluation이 appropriate type의 value를 returns함을 asserts합니다.

그러나 13.2.5.6가 ParseJSON 동안 differently behaves하기 때문에, same source text는 JSON이 아니라 PrimaryExpression으로 evaluated될 때 different results를 produce할 수 있습니다. Furthermore, object literals 안의 duplicate "__proto__" properties에 대한 Early Error도 likewise ParseJSON 동안 apply되지 않으므로, grammar와 matching함에도 불구하고 ParseJSON이 accepted하는 모든 texts가 PrimaryExpression으로 valid인 것은 아닙니다.

Note 2

object 안에 duplicate name Strings가 있는 경우, same key에 대해 lexically preceding values는 overwritten되어야 합니다.

25.5.2.2 JSON Parse Record

JSON Parse Record는 JSON text에서 parsed된 value의 initial state를 describe하는 데 사용되는 Record value입니다.

JSON Parse Records는 Table 76에 listed된 fields를 가집니다.

Table 76: JSON Parse Record Fields
Field Name Value Meaning
[[ParseNode]] a Parse Node context Parse Node입니다.
[[Key]] a property name [[Value]]가 associated된 property name입니다.
[[Value]] an ECMAScript language value [[ParseNode]]의 evaluation에 의해 produced된 value입니다.
[[Elements]] a List of JSON Parse Records [[Value]]가 Array이면, 이는 [[Value]]의 elements에 corresponding하는 JSON Parse Records를 contains합니다. 그렇지 않으면, 이는 empty List입니다.
[[Entries]] a List of JSON Parse Records [[Value]]가 non-Array Object이면, 이는 [[Value]]의 entries에 corresponding하는 JSON Parse Records를 contains합니다. 그렇지 않으면, 이는 empty List입니다.

25.5.2.3 CreateJSONParseRecord ( parseNode, key, value )

The abstract operation CreateJSONParseRecord takes arguments parseNode (a Parse Node), key (a property name), and value (an ECMAScript language value) and returns a JSON Parse Record. JSON text에서 parsed된 parseNode와 그 evaluation에 의해 produced된 value를 recursively combines합니다. It performs the following steps when called:

  1. typedValueNodeShallowestContainedJSONValue(parseNode)로 둔다.
  2. Assert: typedValueNodeempty가 아니다.
  3. elements를 new empty List로 둔다.
  4. entries를 new empty List로 둔다.
  5. value가 Object이면, 다음을 수행한다.
    1. isArray를 ! IsArray(value)로 둔다.
    2. isArraytrue이면, 다음을 수행한다.
      1. Assert: typedValueNodeArrayLiteral Parse Node이다.
      2. contentNodestypedValueNodeJSONArrayLiteralContentNodes로 둔다.
      3. lengthcontentNodes 안의 elements 수로 둔다.
      4. valueLength를 ! LengthOfArrayLike(value)로 둔다.
      5. Assert: valueLengthlength이다.
      6. index를 0으로 둔다.
      7. Repeat, while index < length,
        1. propertyName을 ! ToString(𝔽(index))로 둔다.
        2. elementParseRecordCreateJSONParseRecord(contentNodes[index], propertyName, ! Get(value, propertyName))로 둔다.
        3. elementParseRecordelements에 append한다.
        4. indexindex + 1로 설정한다.
    3. 그렇지 않으면,
      1. Assert: typedValueNodeObjectLiteral Parse Node이다.
      2. propertyNodestypedValueNodePropertyDefinitionNodes로 둔다.
      3. NOTE: value가 JSON text에서 produced되었고 modified되지 않았기 때문에, its property keys는 모두 Strings이고 exhaustively enumerated될 것입니다.
      4. keys를 ! EnumerableOwnProperties(value, key)로 둔다.
      5. keys의 each String propertyKey에 대해, 다음을 수행한다.
        1. NOTE: single object에 대해 same name을 가진 multiple name/value pairs를 specifying하는 JSON text의 경우(예: {"a":"lost","a":"kept"}), resulting ECMAScript object의 corresponding property에 대한 value는 that name을 가진 last pair로 specified됩니다.
        2. propertyDefinitionempty로 둔다.
        3. propertyNodes의 each Parse Node propertyNode에 대해, 다음을 수행한다.
          1. propertyNamepropertyNodePropName으로 둔다.
          2. propertyNamepropertyKey이면, propertyDefinitionpropertyNode로 설정한다.
        4. Assert: propertyDefinition PropertyDefinition : PropertyName : AssignmentExpression 이다.
        5. propertyValueNodepropertyDefinitionAssignmentExpression으로 둔다.
        6. entryParseRecordCreateJSONParseRecord(propertyValueNode, propertyKey, ! Get(value, propertyKey))로 둔다.
        7. entryParseRecordentries에 append한다.
  6. 그렇지 않으면,
    1. Assert: typedValueNodeArrayLiteral Parse NodeObjectLiteral Parse Node도 아니다.
  7. JSON Parse Record { [[ParseNode]]: typedValueNode, [[Key]]: key, [[Value]]: value, [[Elements]]: elements, [[Entries]]: entries }를 반환한다.

25.5.2.4 InternalizeJSONProperty ( holder, name, reviver, parseRecord )

The abstract operation InternalizeJSONProperty takes arguments holder (an Object), name (a String), reviver (a function object), and parseRecord (a JSON Parse Record or empty) and returns either a normal completion containing an ECMAScript language value or a throw completion.

Note

이 algorithm은 [[Delete]] 또는 CreateDataProperty 중 하나가 false를 반환해도 intentionally exception을 throw하지 않습니다.

called될 때 다음 steps를 수행합니다:

  1. value를 ? Get(holder, name)로 둔다.
  2. contextOrdinaryObjectCreate(%Object.prototype%)로 둔다.
  3. parseRecordJSON Parse Record이고 SameValue(parseRecord.[[Value]], value)가 true이면, 다음을 수행한다.
    1. value가 Object가 아니면, 다음을 수행한다.
      1. parseNodeparseRecord.[[ParseNode]]로 둔다.
      2. Assert: parseNodeArrayLiteral Parse NodeObjectLiteral Parse Node도 아니다.
      3. sourceTextparseNode에 의해 matched된 source text로 둔다.
      4. CreateDataPropertyOrThrow(context, "source", CodePointsToString(sourceText))를 수행한다.
    2. elementRecordsparseRecord.[[Elements]]로 둔다.
    3. entryRecordsparseRecord.[[Entries]]로 둔다.
  4. 그렇지 않으면,
    1. elementRecords를 new empty List로 둔다.
    2. entryRecords를 new empty List로 둔다.
  5. value가 Object이면, 다음을 수행한다.
    1. isArray를 ? IsArray(value)로 둔다.
    2. isArraytrue이면, 다음을 수행한다.
      1. elementRecordsLengthelementRecords 안의 elements 수로 둔다.
      2. length를 ? LengthOfArrayLike(value)로 둔다.
      3. index를 0으로 둔다.
      4. Repeat, while index < length,
        1. propertyKey를 ! ToString(𝔽(index))로 둔다.
        2. index < elementRecordsLength이면, elementRecordelementRecords[index]로 둔다; 그렇지 않으면 elementRecordempty로 둔다.
        3. newElement를 ? InternalizeJSONProperty(value, propertyKey, reviver, elementRecord)로 둔다.
        4. newElementundefined이면, 다음을 수행한다.
          1. value.[[Delete]](propertyKey)를 수행한다.
        5. 그렇지 않으면,
          1. CreateDataProperty(value, propertyKey, newElement)를 수행한다.
        6. indexindex + 1로 설정한다.
    3. 그렇지 않으면,
      1. keys를 ? EnumerableOwnProperties(value, key)로 둔다.
      2. keys의 each String propertyKey에 대해, 다음을 수행한다.
        1. entryRecords의 element entryentry.[[Key]]propertyKey인 것이 존재하면, entryRecordentry로 둔다; 그렇지 않으면 entryRecordempty로 둔다.
        2. newElement를 ? InternalizeJSONProperty(value, propertyKey, reviver, entryRecord)로 둔다.
        3. newElementundefined이면, 다음을 수행한다.
          1. value.[[Delete]](propertyKey)를 수행한다.
        4. 그렇지 않으면,
          1. CreateDataProperty(value, propertyKey, newElement)를 수행한다.
  6. Call(reviver, holder, « name, value, context »)를 반환한다.

25.5.2.5 Static Semantics: ShallowestContainedJSONValue ( root )

The abstract operation ShallowestContainedJSONValue takes argument root (a Parse Node) and returns a Parse Node or empty. root에 rooted된 parse tree의 breadth-first search를 performs하고, JSON value에 corresponding하는 nonterminal의 instance인 first node를 returns하거나, such node가 없으면 empty를 returns합니다. It performs the following steps when called:

  1. activeFunc를 active function object로 둔다.
  2. Assert: activeFuncJSON.parse built-in function object이다(JSON.parse 참조).
  3. types를 « NullLiteral, BooleanLiteral, NumericLiteral, StringLiteral, ArrayLiteral, ObjectLiteral, UnaryExpression »로 둔다.
  4. unaryExprempty로 둔다.
  5. queue를 « root »로 둔다.
  6. Repeat, while queue is not empty,
    1. candidatequeue의 first element로 둔다.
    2. queue에서 first element를 remove한다.
    3. queuedChildrenfalse로 둔다.
    4. types의 each nonterminal type에 대해, 다음을 수행한다.
      1. candidatetype의 instance이면, 다음을 수행한다.
        1. NOTE: JSON grammar에서 number token은 negative value를 represent할 수 있습니다. ECMAScript에서 negation은 UnaryExpression- 뒤에 derived UnaryExpression이 오는 것으로 parses되는 unary operation으로 represented됩니다.
        2. typeUnaryExpression이면, 다음을 수행한다.
          1. candidate의 parent가 UnaryExpression Parse Node가 아니면, unaryExprcandidate로 설정한다.
        3. 그렇지 않고 typeNumericLiteral이면, 다음을 수행한다.
          1. Assert: candidateunaryExpr 안에 contained된다.
          2. unaryExpr를 반환한다.
        4. 그렇지 않으면,
          1. candidate를 반환한다.
      2. queuedChildrenfalse이고, candidate가 nonterminal의 instance이며, candidate Contains typetrue이면, 다음을 수행한다.
        1. childrencandidate의 each child node를 in order로 containing하는 List로 둔다.
        2. queuequeuechildrenlist-concatenation으로 설정한다.
        3. queuedChildrentrue로 설정한다.
  7. empty를 반환한다.

25.5.2.6 Static Semantics: JSONArrayLiteralContentNodes

The syntax-directed operation JSONArrayLiteralContentNodes takes no arguments and returns a List of Parse Nodes. It is defined piecewise over the following productions:

ArrayLiteral : [ Elisionopt ] [ ElementList ] [ ElementList , Elisionopt ]
  1. Assert: Elision은 present하지 않는다.
  2. ElementList가 present하지 않으면, new empty List를 반환한다.
  3. ElementListJSONArrayLiteralContentNodes를 반환한다.
ElementList : Elisionopt AssignmentExpression
  1. Assert: Elision은 present하지 않는다.
  2. « AssignmentExpression »를 반환한다.
ElementList : ElementList , Elisionopt AssignmentExpression
  1. Assert: Elision은 present하지 않는다.
  2. elements를 derived ElementListJSONArrayLiteralContentNodes로 둔다.
  3. elements와 « AssignmentExpression »의 list-concatenation을 반환한다.
ElementList : Elisionopt SpreadElement ElementList , Elisionopt SpreadElement
  1. NOTE: ECMA-404에 specified된 JSON text는 SpreadElement를 include하지 않습니다.
  2. Assert: 이 step은 never reached된다.

25.5.3 JSON.rawJSON ( text )

이 function은 string, number, boolean, 또는 null value의 raw JSON text를 representing하는 object를 반환합니다.

  1. jsonString을 ? ToString(text)로 둔다.
  2. jsonString이 empty String이면, SyntaxError exception을 throw한다.
  3. jsonString의 first code unit이 ASCII lowercase letter code unit(0x0061부터 0x007A까지, inclusive), ASCII digit code unit(0x0030부터 0x0039까지, inclusive), 0x0022 (QUOTATION MARK), 또는 0x002D (HYPHEN-MINUS) 중 어느 것도 아니면, SyntaxError exception을 throw한다.
  4. jsonString의 last code unit이 ASCII lowercase letter code unit(0x0061부터 0x007A까지, inclusive), ASCII digit code unit(0x0030부터 0x0039까지, inclusive), 또는 0x0022 (QUOTATION MARK) 중 어느 것도 아니면, SyntaxError exception을 throw한다.
  5. parseResult를 ? ParseJSON(jsonString)으로 둔다.
  6. Assert: parseResult.[[Value]]는 String, Number, Boolean, 또는 null 중 하나이다.
  7. internalSlotsList를 « [[IsRawJSON]] »로 둔다.
  8. objOrdinaryObjectCreate(null, internalSlotsList)로 둔다.
  9. CreateDataPropertyOrThrow(obj, "rawJSON", jsonString)를 수행한다.
  10. SetIntegrityLevel(obj, frozen)을 수행한다.
  11. obj를 반환한다.

25.5.4 JSON.stringify ( value [ , replacer [ , space ] ] )

이 function은 ECMAScript language value를 representing하는 UTF-16 encoded JSON format의 String 또는 undefined를 반환합니다. 세 parameters를 받을 수 있습니다. value parameter는 ECMAScript language value로, usually object 또는 array이지만 String, Boolean, Number 또는 null일 수도 있습니다. optional replacer parameter는 objects와 arrays가 stringified되는 방식을 alters하는 function이거나, stringified될 object properties를 selecting하기 위한 inclusion list로 acts하는 Strings 및 Numbers의 array입니다. optional space parameter는 result에 human readability를 improve하기 위한 white space가 injected되도록 하는 String 또는 Number입니다.

called될 때 다음 steps를 수행합니다:

  1. stack을 new empty List로 둔다.
  2. indent를 empty String으로 둔다.
  3. propertyListundefined로 둔다.
  4. replacerFuncundefined로 둔다.
  5. replacer가 Object이면, 다음을 수행한다.
    1. IsCallable(replacer)가 true이면, 다음을 수행한다.
      1. replacerFuncreplacer로 설정한다.
    2. 그렇지 않으면,
      1. isArray를 ? IsArray(replacer)로 둔다.
      2. isArraytrue이면, 다음을 수행한다.
        1. propertyList를 new empty List로 설정한다.
        2. length를 ? LengthOfArrayLike(replacer)로 둔다.
        3. k를 0으로 둔다.
        4. Repeat, while k < length,
          1. propertyKey를 ! ToString(𝔽(k))로 둔다.
          2. propertyValue를 ? Get(replacer, propertyKey)로 둔다.
          3. itemundefined로 둔다.
          4. propertyValue가 String이면, 다음을 수행한다.
            1. itempropertyValue로 설정한다.
          5. 그렇지 않고 propertyValue가 Number이면, 다음을 수행한다.
            1. item을 ! ToString(propertyValue)로 설정한다.
          6. 그렇지 않고 propertyValue가 Object이면, 다음을 수행한다.
            1. propertyValue[[StringData]] 또는 [[NumberData]] internal slot을 가지면, item을 ? ToString(propertyValue)로 설정한다.
          7. itemundefined가 아니고 propertyListitem을 contain하지 않으면, 다음을 수행한다.
            1. itempropertyList에 append한다.
          8. kk + 1로 설정한다.
  6. space가 Object이면, 다음을 수행한다.
    1. space[[NumberData]] internal slot을 가지면, 다음을 수행한다.
      1. space를 ? ToNumber(space)로 설정한다.
    2. 그렇지 않고 space[[StringData]] internal slot을 가지면, 다음을 수행한다.
      1. space를 ? ToString(space)로 설정한다.
  7. space가 Number이면, 다음을 수행한다.
    1. spaceMV를 ! ToIntegerOrInfinity(space)로 둔다.
    2. spaceMVmin(10, spaceMV)로 설정한다.
    3. spaceMV < 1이면, gap을 empty String으로 둔다; 그렇지 않으면 gap을 code unit 0x0020 (SPACE)의 spaceMV occurrences를 containing하는 String value로 둔다.
  8. 그렇지 않고 space가 String이면, 다음을 수행한다.
    1. space의 length가 ≤ 10이면, gapspace로 둔다; 그렇지 않으면 gap을 0부터 10까지의 spacesubstring으로 둔다.
  9. 그렇지 않으면,
    1. gap을 empty String으로 둔다.
  10. wrapperOrdinaryObjectCreate(%Object.prototype%)로 둔다.
  11. CreateDataPropertyOrThrow(wrapper, the empty String, value)를 수행한다.
  12. stateJSON Serialization Record { [[ReplacerFunction]]: replacerFunc, [[Stack]]: stack, [[Indent]]: indent, [[Gap]]: gap, [[PropertyList]]: propertyList }로 둔다.
  13. SerializeJSONProperty(state, the empty String, wrapper)를 반환한다.

이 function의 "length" property는 3𝔽입니다.

Note 1

JSON structures는 any depth로 nested될 수 있지만, acyclic이어야 합니다. value가 cyclic structure이거나 cyclic structure를 contains하면, 이 function은 TypeError exception을 throw해야 합니다. 다음은 stringified될 수 없는 value의 예입니다:

a = [];
a[0] = a;
my_text = JSON.stringify(a); // This must throw a TypeError.
Note 2

Symbolic primitive values는 다음과 같이 rendered됩니다:

  • null value는 JSON text에서 String value "null"로 rendered됩니다.
  • undefined value는 rendered되지 않습니다.
  • true value는 JSON text에서 String value "true"로 rendered됩니다.
  • false value는 JSON text에서 String value "false"로 rendered됩니다.
Note 3

String values는 QUOTATION MARK (") code units로 wrapped됩니다. code units "\\ prefixes로 escaped됩니다. Control characters code units는 escape sequences \uHHHH 또는 shorter forms인 \b (BACKSPACE), \f (FORM FEED), \n (LINE FEED), \r (CARRIAGE RETURN), \t (CHARACTER TABULATION)로 replaced됩니다.

Note 4

Finite numbers는 ToString(number)를 calling한 것처럼 stringified됩니다. sign과 관계없이 NaNInfinity는 String value "null"로 represented됩니다.

Note 5

JSON representation을 가지지 않는 values(예: undefined 및 functions)는 String을 produce하지 않습니다. 대신 undefined value를 produce합니다. arrays 안에서 these values는 String value "null"로 represented됩니다. objects 안에서는 unrepresentable value가 property를 stringification에서 excluded되도록 causes합니다.

Note 6

object는 U+007B (LEFT CURLY BRACKET) 뒤에 zero or more properties가 오고, U+002C (COMMA)로 separated되며, U+007D (RIGHT CURLY BRACKET)로 closed되는 것으로 rendered됩니다. property는 property name을 representing하는 quoted String, U+003A (COLON), 그리고 stringified property value입니다. array는 opening U+005B (LEFT SQUARE BRACKET) 뒤에 zero or more values가 오고, U+002C (COMMA)로 separated되며, U+005D (RIGHT SQUARE BRACKET)로 closed되는 것으로 rendered됩니다.

25.5.4.1 JSON Serialization Record

JSON Serialization Record는 JSON format으로의 serialization을 enable하는 데 사용되는 Record value입니다.

JSON Serialization Records는 Table 77에 listed된 fields를 가집니다.

Table 77: JSON Serialization Record Fields
Field Name Value Meaning
[[ReplacerFunction]] a function object or undefined object properties에 대한 replacement values를 supply할 수 있는 function입니다(JSON.stringify의 replacer parameter에서).
[[PropertyList]] either a List of Strings or undefined non-array object를 serializing할 때 include할 properties의 names입니다(JSON.stringify의 replacer parameter에서).
[[Gap]] a String indentation의 unit입니다(JSON.stringify의 space parameter에서).
[[Stack]] a List of Objects serializing되는 과정에 있는 nested objects의 set입니다. cyclic structures를 detect하는 데 사용됩니다.
[[Indent]] a String current indentation입니다.

25.5.4.2 SerializeJSONProperty ( state, key, holder )

The abstract operation SerializeJSONProperty takes arguments state (a JSON Serialization Record), key (a String), and holder (an Object) and returns either a normal completion containing either a String or undefined, or a throw completion. It performs the following steps when called:

  1. value를 ? Get(holder, key)로 둔다.
  2. value가 Object이거나 value가 BigInt이면, 다음을 수행한다.
    1. toJSON을 ? GetV(value, "toJSON")로 둔다.
    2. IsCallable(toJSON)가 true이면, 다음을 수행한다.
      1. value를 ? Call(toJSON, value, « key »)로 설정한다.
  3. state.[[ReplacerFunction]]undefined가 아니면, 다음을 수행한다.
    1. value를 ? Call(state.[[ReplacerFunction]], holder, « key, value »)로 설정한다.
  4. value가 Object이면, 다음을 수행한다.
    1. value[[IsRawJSON]] internal slot을 가지면, 다음을 수행한다.
      1. rawJSON을 ! Get(value, "rawJSON")로 둔다.
      2. Assert: rawJSON은 String이다.
      3. rawJSON을 반환한다.
    2. value[[NumberData]] internal slot을 가지면, 다음을 수행한다.
      1. value를 ? ToNumber(value)로 설정한다.
    3. 그렇지 않고 value[[StringData]] internal slot을 가지면, 다음을 수행한다.
      1. value를 ? ToString(value)로 설정한다.
    4. 그렇지 않고 value[[BooleanData]] internal slot을 가지면, 다음을 수행한다.
      1. valuevalue.[[BooleanData]]로 설정한다.
    5. 그렇지 않고 value[[BigIntData]] internal slot을 가지면, 다음을 수행한다.
      1. valuevalue.[[BigIntData]]로 설정한다.
  5. valuenull이면, "null"을 반환한다.
  6. valuetrue이면, "true"를 반환한다.
  7. valuefalse이면, "false"를 반환한다.
  8. value가 String이면, QuoteJSONString(value)를 반환한다.
  9. value가 Number이면, 다음을 수행한다.
    1. valuefinite이면, ! ToString(value)를 반환한다.
    2. "null"을 반환한다.
  10. value가 BigInt이면, TypeError exception을 throw한다.
  11. value가 Object이고 IsCallable(value)가 false이면, 다음을 수행한다.
    1. isArray를 ? IsArray(value)로 둔다.
    2. isArraytrue이면, 다음을 수행한다.
      1. SerializeJSONArray(state, value)를 반환한다.
    3. SerializeJSONObject(state, value)를 반환한다.
  12. undefined를 반환한다.

25.5.4.3 QuoteJSONString ( value )

The abstract operation QuoteJSONString takes argument value (a String) and returns a String. value를 0x0022 (QUOTATION MARK) code units로 wraps하고, 그 안의 certain other code units를 escapes합니다. 이 operation은 6.1.4에 described된 것처럼 value를 UTF-16 encoded code points의 sequence로 interprets합니다. It performs the following steps when called:

  1. product를 code unit 0x0022 (QUOTATION MARK) solely로 consisting하는 String value로 둔다.
  2. StringToCodePoints(value)의 each code point codePoint에 대해, 다음을 수행한다.
    1. codePointTable 78의 “Code Point” column에 listed되어 있으면, 다음을 수행한다.
      1. productproduct와 corresponding row의 “Escape Sequence” column에 specified된 codePoint에 대한 escape sequence의 string-concatenation으로 설정한다.
    2. 그렇지 않고 codePoint가 0x0020 (SPACE)보다 less than인 numeric value를 가지거나 codePointleading surrogate 또는 trailing surrogate와 same numeric value를 가지면, 다음을 수행한다.
      1. unit을 numeric value가 codePoint의 numeric value인 code unit으로 둔다.
      2. productproductUnicodeEscape(unit)의 string-concatenation으로 설정한다.
    3. 그렇지 않으면,
      1. productproductUTF16EncodeCodePoint(codePoint)의 string-concatenation으로 설정한다.
  3. productproduct와 code unit 0x0022 (QUOTATION MARK)의 string-concatenation으로 설정한다.
  4. product를 반환한다.
Table 78: JSON Single Character Escape Sequences
Code Point Unicode Character Name Escape Sequence
U+0008 BACKSPACE \b
U+0009 CHARACTER TABULATION \t
U+000A LINE FEED (LF) \n
U+000C FORM FEED (FF) \f
U+000D CARRIAGE RETURN (CR) \r
U+0022 QUOTATION MARK \"
U+005C REVERSE SOLIDUS \\

25.5.4.4 UnicodeEscape ( codeUnit )

The abstract operation UnicodeEscape takes argument codeUnit (a code unit) and returns a String. codeUnit을 Unicode escape sequence로 represents합니다. It performs the following steps when called:

  1. ncodeUnit의 numeric value로 둔다.
  2. Assert: n ≤ 0xFFFF.
  3. hex를 lowercase hexadecimal number로 formatted된 n의 String representation으로 둔다.
  4. code unit 0x005C (REVERSE SOLIDUS), "u", 및 StringPad(hex, 4, "0", start)의 string-concatenation을 반환한다.

25.5.4.5 SerializeJSONObject ( state, value )

The abstract operation SerializeJSONObject takes arguments state (a JSON Serialization Record) and value (an Object) and returns either a normal completion containing a String or a throw completion. object를 serializes합니다. It performs the following steps when called:

  1. state.[[Stack]]value를 contain하면, structure가 cyclical이므로 TypeError exception을 throw한다.
  2. valuestate.[[Stack]]에 append한다.
  3. stepBackstate.[[Indent]]로 둔다.
  4. state.[[Indent]]state.[[Indent]]state.[[Gap]]string-concatenation으로 설정한다.
  5. state.[[PropertyList]]undefined가 아니면, 다음을 수행한다.
    1. keysstate.[[PropertyList]]로 둔다.
  6. 그렇지 않으면,
    1. keys를 ? EnumerableOwnProperties(value, key)로 둔다.
  7. partial을 new empty List로 둔다.
  8. keys의 each element propertyKey에 대해, 다음을 수행한다.
    1. stringP를 ? SerializeJSONProperty(state, propertyKey, value)로 둔다.
    2. stringPundefined가 아니면, 다음을 수행한다.
      1. memberQuoteJSONString(propertyKey)로 둔다.
      2. membermember":"string-concatenation으로 설정한다.
      3. state.[[Gap]]이 empty String이 아니면, 다음을 수행한다.
        1. membermember와 code unit 0x0020 (SPACE)의 string-concatenation으로 설정한다.
      4. membermemberstringPstring-concatenation으로 설정한다.
      5. memberpartial에 append한다.
  9. partial이 empty이면, 다음을 수행한다.
    1. final"{}"로 둔다.
  10. 그렇지 않으면,
    1. state.[[Gap]]이 empty String이면, 다음을 수행한다.
      1. propertiespartial의 모든 element Strings를 code unit 0x002C (COMMA)로 separated된 each adjacent pair of Strings와 함께 concatenating하여 formed된 String value로 둔다. comma는 first String before나 last String after에 inserted되지 않는다.
      2. final"{", properties, 및 "}"string-concatenation으로 둔다.
    2. 그렇지 않으면,
      1. separator를 code unit 0x002C (COMMA), code unit 0x000A (LINE FEED), 및 state.[[Indent]]string-concatenation으로 둔다.
      2. propertiespartial의 모든 element Strings를 separator로 separated된 each adjacent pair of Strings와 함께 concatenating하여 formed된 String value로 둔다. separator String은 first String before나 last String after에 inserted되지 않는다.
      3. final"{", code unit 0x000A (LINE FEED), state.[[Indent]], properties, code unit 0x000A (LINE FEED), stepBack, 및 "}"string-concatenation으로 둔다.
  11. state.[[Stack]]의 last element를 remove한다.
  12. state.[[Indent]]stepBack으로 설정한다.
  13. final을 반환한다.

25.5.4.6 SerializeJSONArray ( state, value )

The abstract operation SerializeJSONArray takes arguments state (a JSON Serialization Record) and value (an Object) and returns either a normal completion containing a String or a throw completion. array를 serializes합니다. It performs the following steps when called:

  1. state.[[Stack]]value를 contain하면, structure가 cyclical이므로 TypeError exception을 throw한다.
  2. valuestate.[[Stack]]에 append한다.
  3. stepBackstate.[[Indent]]로 둔다.
  4. state.[[Indent]]state.[[Indent]]state.[[Gap]]string-concatenation으로 설정한다.
  5. partial을 new empty List로 둔다.
  6. length를 ? LengthOfArrayLike(value)로 둔다.
  7. index를 0으로 둔다.
  8. Repeat, while index < length,
    1. stringP를 ? SerializeJSONProperty(state, ! ToString(𝔽(index)), value)로 둔다.
    2. stringPundefined이면, 다음을 수행한다.
      1. "null"partial에 append한다.
    3. 그렇지 않으면,
      1. stringPpartial에 append한다.
    4. indexindex + 1로 설정한다.
  9. partial이 empty이면, 다음을 수행한다.
    1. final"[]"로 둔다.
  10. 그렇지 않으면,
    1. state.[[Gap]]이 empty String이면, 다음을 수행한다.
      1. propertiespartial의 모든 element Strings를 code unit 0x002C (COMMA)로 separated된 each adjacent pair of Strings와 함께 concatenating하여 formed된 String value로 둔다. comma는 first String before나 last String after에 inserted되지 않는다.
      2. final"[", properties, 및 "]"string-concatenation으로 둔다.
    2. 그렇지 않으면,
      1. separator를 code unit 0x002C (COMMA), code unit 0x000A (LINE FEED), 및 state.[[Indent]]string-concatenation으로 둔다.
      2. propertiespartial의 모든 element Strings를 separator로 separated된 each adjacent pair of Strings와 함께 concatenating하여 formed된 String value로 둔다. separator String은 first String before나 last String after에 inserted되지 않는다.
      3. final"[", code unit 0x000A (LINE FEED), state.[[Indent]], properties, code unit 0x000A (LINE FEED), stepBack, 및 "]"string-concatenation으로 둔다.
  11. state.[[Stack]]의 last element를 remove한다.
  12. state.[[Indent]]stepBack으로 설정한다.
  13. final을 반환한다.
Note

arrays의 representation은 +0𝔽 (inclusive)부터 array.length (exclusive)까지의 interval 안의 elements만 includes합니다. keys가 array indices가 아닌 properties는 stringification에서 excluded됩니다. array는 opening LEFT SQUARE BRACKET, COMMA로 separated된 elements, 그리고 closing RIGHT SQUARE BRACKET으로 stringified됩니다.

25.5.5 JSON [ %Symbol.toStringTag% ]

%Symbol.toStringTag% property의 initial value는 String value "JSON"입니다.

이 property는 attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }를 가집니다.