23 인덱스 컬렉션

23.1 Array 객체

Array는 특정 종류의 속성 이름에 특별한 처리를 부여하는 특수 객체이다. 이 특별한 처리의 정의는 10.4.2를 보라.

23.1.1 Array 생성자

Array 생성자는:

  • %Array%이다.
  • 전역 객체"Array" 속성의 초기값이다.
  • 생성자로 호출될 때 새로운 Array를 생성하고 초기화한다.
  • 생성자가 아니라 함수로 호출될 때도 새로운 Array를 생성하고 초기화한다. 따라서 함수 호출 Array(…)는 같은 인자를 가진 객체 생성 표현식 new Array(…)와 동등하다.
  • 인자의 개수와 타입에 따라 동작이 달라지는 함수이다.
  • 클래스 정의의 extends 절의 값으로 사용될 수 있다. 특수 Array 동작을 상속하려는 서브클래스 생성자는 Array 특수 객체인 서브클래스 인스턴스를 초기화하기 위해 Array 생성자에 대한 super 호출을 포함해야 한다. 그러나 대부분의 Array.prototype 메서드는 자신의 this 값이 Array 특수 객체인지에 의존하지 않는 제네릭 메서드이다.

23.1.1.1 Array ( ...values )

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

  1. NewTarget이 undefined이면, newTarget을 활성 함수 객체라고 하자; 그렇지 않으면 newTarget을 NewTarget이라고 하자.
  2. proto를 ? GetPrototypeFromConstructor(newTarget, "%Array.prototype%")라고 하자.
  3. numberOfArgsvalues의 요소 개수라고 하자.
  4. numberOfArgs = 0이면, ! ArrayCreate(0, proto)를 반환한다.
  5. numberOfArgs = 1이면,
    1. lenvalues[0]이라고 하자.
    2. array를 ! ArrayCreate(0, proto)라고 하자.
    3. len이 Number가 아니면,
      1. CreateDataPropertyOrThrow(array, "0", len)을 수행한다.
      2. intLen1𝔽이라고 하자.
    4. 그렇지 않으면,
      1. intLen을 ! ToUint32(len)이라고 하자.
      2. SameValueZero(intLen, len)가 false이면, RangeError 예외를 던진다.
    5. Set(array, "length", intLen, true)를 수행한다.
    6. array를 반환한다.
  6. Assert: numberOfArgs ≥ 2.
  7. array를 ? ArrayCreate(numberOfArgs, proto)라고 하자.
  8. k를 0이라고 하자.
  9. k < numberOfArgs인 동안 반복한다,
    1. propertyKey를 ! ToString(𝔽(k))라고 하자.
    2. itemKvalues[k]라고 하자.
    3. CreateDataPropertyOrThrow(array, propertyKey, itemK)를 수행한다.
    4. kk + 1로 설정한다.
  10. Assert: array"length" 속성의 수학적 값numberOfArgs이다.
  11. array를 반환한다.

23.1.2 Array 생성자의 속성

Array 생성자는:

  • 값이 %Function.prototype%[[Prototype]] 내부 슬롯을 가진다.
  • 값이 1𝔽"length" 속성을 가진다.
  • 다음 속성들을 가진다:

23.1.2.1 Array.from ( items [ , mapper [ , thisArg ] ] )

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

  1. constructorthis 값이라고 하자.
  2. mapperundefined이면,
    1. mappingfalse라고 하자.
  3. 그렇지 않으면,
    1. IsCallable(mapper)가 false이면, TypeError 예외를 던진다.
    2. mappingtrue라고 하자.
  4. usingIterator를 ? GetMethod(items, %Symbol.iterator%)라고 하자.
  5. usingIteratorundefined가 아니면,
    1. IsConstructor(constructor)가 true이면,
      1. array를 ? Construct(constructor)라고 하자.
    2. 그렇지 않으면,
      1. array를 ! ArrayCreate(0)이라고 하자.
    3. iteratorRecord를 ? GetIteratorFromMethod(items, usingIterator)라고 하자.
    4. k를 0이라고 하자.
    5. 반복한다,
      1. k ≥ 253 - 1이면,
        1. errorThrowCompletion(새로 생성된 TypeError 객체)라고 하자.
        2. IteratorClose(iteratorRecord, error)를 반환한다.
      2. propertyKey를 ! ToString(𝔽(k))라고 하자.
      3. next를 ? IteratorStepValue(iteratorRecord)라고 하자.
      4. nextdone이면,
        1. Set(array, "length", 𝔽(k), true)를 수행한다.
        2. array를 반환한다.
      5. mappingtrue이면,
        1. mappedValueCompletion(Call(mapper, thisArg, « next, 𝔽(k) »))라고 하자.
        2. IfAbruptCloseIterator(mappedValue, iteratorRecord).
      6. 그렇지 않으면,
        1. mappedValuenext라고 하자.
      7. defineStatusCompletion(CreateDataPropertyOrThrow(array, propertyKey, mappedValue))라고 하자.
      8. IfAbruptCloseIterator(defineStatus, iteratorRecord).
      9. kk + 1로 설정한다.
  6. NOTE: items는 반복 가능하지 않으므로 배열 유사 객체라고 가정한다.
  7. arrayLike를 ! ToObject(items)라고 하자.
  8. len을 ? LengthOfArrayLike(arrayLike)라고 하자.
  9. IsConstructor(constructor)가 true이면,
    1. array를 ? Construct(constructor, « 𝔽(len) »)라고 하자.
  10. 그렇지 않으면,
    1. array를 ? ArrayCreate(len)라고 하자.
  11. k를 0이라고 하자.
  12. k < len인 동안 반복한다,
    1. propertyKey를 ! ToString(𝔽(k))라고 하자.
    2. kValue를 ? Get(arrayLike, propertyKey)라고 하자.
    3. mappingtrue이면,
      1. mappedValue를 ? Call(mapper, thisArg, « kValue, 𝔽(k) »)라고 하자.
    4. 그렇지 않으면,
      1. mappedValuekValue라고 하자.
    5. CreateDataPropertyOrThrow(array, propertyKey, mappedValue)를 수행한다.
    6. kk + 1로 설정한다.
  13. Set(array, "length", 𝔽(len), true)를 수행한다.
  14. array를 반환한다.
Note

이 메서드는 의도적으로 제네릭인 팩터리 메서드이다; 이 메서드는 자신의 this 값이 Array 생성자일 것을 요구하지 않는다. 따라서 단일 수치 인자와 함께 호출될 수 있는 다른 생성자로 이전되거나 상속될 수 있다.

23.1.2.2 Array.fromAsync ( items [ , mapper [ , thisArg ] ] )

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

  1. constructorthis 값이라고 하자.
  2. mappingfalse라고 하자.
  3. mapperundefined가 아니면,
    1. IsCallable(mapper)가 false이면, TypeError 예외를 던진다.
    2. mappingtrue로 설정한다.
  4. iteratorRecordundefined라고 하자.
  5. usingAsyncIterator를 ? GetMethod(items, %Symbol.asyncIterator%)라고 하자.
  6. usingAsyncIteratorundefined이면,
    1. usingSyncIterator를 ? GetMethod(items, %Symbol.iterator%)라고 하자.
    2. usingSyncIteratorundefined가 아니면,
      1. iteratorRecordCreateAsyncFromSyncIterator(? GetIteratorFromMethod(items, usingSyncIterator))로 설정한다.
  7. 그렇지 않으면,
    1. iteratorRecord를 ? GetIteratorFromMethod(items, usingAsyncIterator)로 설정한다.
  8. iteratorRecordundefined가 아니면,
    1. IsConstructor(constructor)가 true이면,
      1. array를 ? Construct(constructor)라고 하자.
    2. 그렇지 않으면,
      1. array를 ! ArrayCreate(0)이라고 하자.
    3. k를 0이라고 하자.
    4. 반복한다,
      1. k ≥ 253 - 1이면,
        1. errorThrowCompletion(새로 생성된 TypeError 객체)라고 하자.
        2. AsyncIteratorClose(iteratorRecord, error)를 반환한다.
      2. propertyKey를 ! ToString(𝔽(k))라고 하자.
      3. nextResult를 ? Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]])라고 하자.
      4. nextResult를 ? Await(nextResult)로 설정한다.
      5. nextResult가 Object가 아니면, TypeError 예외를 던진다.
      6. done을 ? IteratorComplete(nextResult)라고 하자.
      7. donetrue이면,
        1. Set(array, "length", 𝔽(k), true)를 수행한다.
        2. array를 반환한다.
      8. nextValue를 ? IteratorValue(nextResult)라고 하자.
      9. mappingtrue이면,
        1. mappedValueCompletion(Call(mapper, thisArg, « nextValue, 𝔽(k) »))라고 하자.
        2. IfAbruptCloseAsyncIterator(mappedValue, iteratorRecord).
        3. mappedValueCompletion(Await(mappedValue))로 설정한다.
        4. IfAbruptCloseAsyncIterator(mappedValue, iteratorRecord).
      10. 그렇지 않으면,
        1. mappedValuenextValue라고 하자.
      11. defineStatusCompletion(CreateDataPropertyOrThrow(array, propertyKey, mappedValue))라고 하자.
      12. IfAbruptCloseAsyncIterator(defineStatus, iteratorRecord).
      13. kk + 1로 설정한다.
  9. 그렇지 않으면,
    1. NOTE: items는 비동기 반복 가능하지도 반복 가능하지도 않으므로 배열 유사 객체라고 가정한다.
    2. arrayLike를 ! ToObject(items)라고 하자.
    3. len을 ? LengthOfArrayLike(arrayLike)라고 하자.
    4. IsConstructor(constructor)가 true이면,
      1. array를 ? Construct(constructor, « 𝔽(len) »)라고 하자.
    5. 그렇지 않으면,
      1. array를 ? ArrayCreate(len)라고 하자.
    6. k를 0이라고 하자.
    7. k < len인 동안 반복한다,
      1. propertyKey를 ! ToString(𝔽(k))라고 하자.
      2. kValue를 ? Get(arrayLike, propertyKey)라고 하자.
      3. kValue를 ? Await(kValue)로 설정한다.
      4. mappingtrue이면,
        1. mappedValue를 ? Call(mapper, thisArg, « kValue, 𝔽(k) »)라고 하자.
        2. mappedValue를 ? Await(mappedValue)로 설정한다.
      5. 그렇지 않으면,
        1. mappedValuekValue라고 하자.
      6. CreateDataPropertyOrThrow(array, propertyKey, mappedValue)를 수행한다.
      7. kk + 1로 설정한다.
    8. Set(array, "length", 𝔽(len), true)를 수행한다.
    9. array를 반환한다.
Note

이 메서드는 의도적으로 제네릭인 팩터리 메서드이다; 이 메서드는 자신의 this 값이 Array 생성자일 것을 요구하지 않는다. 따라서 단일 수치 인자와 함께 호출될 수 있는 다른 생성자로 이전되거나 상속될 수 있다.

23.1.2.3 Array.isArray ( arg )

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

  1. IsArray(arg)를 반환한다.

23.1.2.4 Array.of ( ...items )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. lenitems의 요소 개수라고 하자.
  2. lenNumber𝔽(len)이라고 하자.
  3. constructorthis 값이라고 하자.
  4. IsConstructor(constructor)가 true이면,
    1. array를 ? Construct(constructor, « lenNumber »)라고 하자.
  5. 그렇지 않으면,
    1. array를 ? ArrayCreate(len)라고 하자.
  6. k를 0이라고 하자.
  7. k < len인 동안 반복한다,
    1. kValueitems[k]라고 하자.
    2. propertyKey를 ! ToString(𝔽(k))라고 하자.
    3. CreateDataPropertyOrThrow(array, propertyKey, kValue)를 수행한다.
    4. kk + 1로 설정한다.
  8. Set(array, "length", lenNumber, true)를 수행한다.
  9. array를 반환한다.
Note

이 메서드는 의도적으로 제네릭인 팩터리 메서드이다; 이 메서드는 자신의 this 값이 Array 생성자일 것을 요구하지 않는다. 따라서 단일 수치 인자와 함께 호출될 수 있는 다른 생성자로 이전되거나 상속될 수 있다.

23.1.2.5 Array.prototype

Array.prototype의 값은 Array 프로토타입 객체이다.

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

23.1.2.6 get Array [ %Symbol.species% ]

Array[%Symbol.species%]는 set 접근자 함수가 undefined인 접근자 속성이다. 그 get 접근자 함수는 호출될 때 다음 단계를 수행한다:

  1. this 값을 반환한다.

이 함수의 "name" 속성의 값은 "get [Symbol.species]"이다.

Note

Array 프로토타입 메서드는 보통 자신의 this 값의 생성자를 사용해 파생 객체를 생성한다. 그러나 서브클래스 생성자는 자신의 %Symbol.species% 속성을 재정의하여 그 기본 동작을 재정의할 수 있다.

23.1.3 Array 프로토타입 객체의 속성

Array 프로토타입 객체는:

  • %Array.prototype%이다.
  • Array 특수 객체이며 그러한 객체에 대해 지정된 내부 메서드를 가진다.
  • 초기값이 +0𝔽이고 속성 특성이 { [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }인 "length" 속성을 가진다.
  • 값이 %Object.prototype%[[Prototype]] 내부 슬롯을 가진다.
Note

Array 프로토타입 객체는 ECMAScript 2015 명세 이전에 만들어진 ECMAScript 코드와의 호환성을 보장하기 위해 Array 특수 객체로 지정된다.

23.1.3.1 Array.prototype.at ( index )

  1. obj를 ? ToObject(this value)라고 하자.
  2. len을 ? LengthOfArrayLike(obj)라고 하자.
  3. relativeIndex를 ? ToIntegerOrInfinity(index)라고 하자.
  4. relativeIndex ≥ 0이면,
    1. krelativeIndex라고 하자.
  5. 그렇지 않으면,
    1. klen + relativeIndex라고 하자.
  6. k < 0이거나 klen이면, undefined를 반환한다.
  7. Get(obj, ! ToString(𝔽(k)))를 반환한다.

23.1.3.2 Array.prototype.concat ( ...items )

이 메서드는 객체의 배열 요소 뒤에 각 인자의 배열 요소가 이어진 배열을 반환한다.

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

  1. obj를 ? ToObject(this value)라고 하자.
  2. array를 ? ArraySpeciesCreate(obj, 0)이라고 하자.
  3. nextIndex를 0이라고 하자.
  4. objitems 앞에 추가한다.
  5. items의 각 요소 item에 대해, 다음을 수행한다.
    1. spreadable을 ? IsConcatSpreadable(item)이라고 하자.
    2. spreadabletrue이면,
      1. len을 ? LengthOfArrayLike(item)이라고 하자.
      2. nextIndex + len > 253 - 1이면, TypeError 예외를 던진다.
      3. sourceIndex를 0이라고 하자.
      4. sourceIndex < len인 동안 반복한다,
        1. propertyKey를 ! ToString(𝔽(sourceIndex))라고 하자.
        2. exists를 ? HasProperty(item, propertyKey)라고 하자.
        3. existstrue이면,
          1. subElement를 ? Get(item, propertyKey)라고 하자.
          2. CreateDataPropertyOrThrow(array, ! ToString(𝔽(nextIndex)), subElement)를 수행한다.
        4. nextIndexnextIndex + 1로 설정한다.
        5. sourceIndexsourceIndex + 1로 설정한다.
    3. 그렇지 않으면,
      1. NOTE: item은 펼쳐지지 않고 단일 항목으로 추가된다.
      2. nextIndex ≥ 253 - 1이면, TypeError 예외를 던진다.
      3. CreateDataPropertyOrThrow(array, ! ToString(𝔽(nextIndex)), item)를 수행한다.
      4. nextIndexnextIndex + 1로 설정한다.
  6. Set(array, "length", 𝔽(nextIndex), true)를 수행한다.
  7. array를 반환한다.

이 메서드의 "length" 속성은 1𝔽이다.

Note 1

단계 6에서 "length" 속성을 명시적으로 설정하는 것은, items의 마지막 비어 있지 않은 요소에 뒤따르는 빈 슬롯이 있거나 array가 내장 Array가 아닐 때 길이가 올바르도록 보장하기 위한 것이다.

Note 2

이 메서드는 의도적으로 제네릭이다; 이 메서드는 자신의 this 값이 Array일 것을 요구하지 않는다. 따라서 메서드로 사용하기 위해 다른 종류의 객체로 이전될 수 있다.

23.1.3.2.1 IsConcatSpreadable ( obj )

The abstract operation IsConcatSpreadable takes argument obj (an ECMAScript language value) and returns either a normal completion containing a Boolean or a throw completion. It performs the following steps when called:

  1. obj가 Object가 아니면, false를 반환한다.
  2. spreadable을 ? Get(obj, %Symbol.isConcatSpreadable%)라고 하자.
  3. spreadableundefined가 아니면, ToBoolean(spreadable)를 반환한다.
  4. IsArray(obj)를 반환한다.

23.1.3.3 Array.prototype.constructor

Array.prototype.constructor의 초기값은 %Array%이다.

23.1.3.4 Array.prototype.copyWithin ( target, start [ , end ] )

Note 1

end 인자는 선택적이다. 제공되지 않으면, this 값의 길이가 사용된다.

Note 2

target이 음수이면, 배열의 길이인 length에 대해 length + target으로 취급된다. start가 음수이면, length + start로 취급된다. end가 음수이면, length + end로 취급된다.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. obj를 ? ToObject(this value)라고 하자.
  2. len을 ? LengthOfArrayLike(obj)라고 하자.
  3. relativeTarget을 ? ToIntegerOrInfinity(target)이라고 하자.
  4. relativeTarget = -∞이면, to를 0이라고 하자.
  5. 그렇지 않고 relativeTarget < 0이면, tomax(len + relativeTarget, 0)이라고 하자.
  6. 그렇지 않으면, tomin(relativeTarget, len)이라고 하자.
  7. relativeStart를 ? ToIntegerOrInfinity(start)라고 하자.
  8. relativeStart = -∞이면, from을 0이라고 하자.
  9. 그렇지 않고 relativeStart < 0이면, frommax(len + relativeStart, 0)이라고 하자.
  10. 그렇지 않으면, frommin(relativeStart, len)이라고 하자.
  11. endundefined이면 relativeEndlen이라고 하자; 그렇지 않으면 relativeEnd를 ? ToIntegerOrInfinity(end)라고 하자.
  12. relativeEnd = -∞이면, final을 0이라고 하자.
  13. 그렇지 않고 relativeEnd < 0이면, finalmax(len + relativeEnd, 0)이라고 하자.
  14. 그렇지 않으면, finalmin(relativeEnd, len)이라고 하자.
  15. countmin(final - from, len - to)라고 하자.
  16. from < to이고 to < from + count이면,
    1. direction을 -1이라고 하자.
    2. fromfrom + count - 1로 설정한다.
    3. toto + count - 1로 설정한다.
  17. 그렇지 않으면,
    1. direction을 1이라고 하자.
  18. count > 0인 동안 반복한다,
    1. fromKey를 ! ToString(𝔽(from))라고 하자.
    2. toKey를 ! ToString(𝔽(to))라고 하자.
    3. fromPresent를 ? HasProperty(obj, fromKey)라고 하자.
    4. fromPresenttrue이면,
      1. fromValue를 ? Get(obj, fromKey)라고 하자.
      2. Set(obj, toKey, fromValue, true)를 수행한다.
    5. 그렇지 않으면,
      1. Assert: fromPresentfalse이다.
      2. DeletePropertyOrThrow(obj, toKey)를 수행한다.
    6. fromfrom + direction으로 설정한다.
    7. toto + direction으로 설정한다.
    8. countcount - 1로 설정한다.
  19. obj를 반환한다.
Note 3

이 메서드는 의도적으로 제네릭이다; 이 메서드는 자신의 this 값이 Array일 것을 요구하지 않는다. 따라서 메서드로 사용하기 위해 다른 종류의 객체로 이전될 수 있다.

23.1.3.5 Array.prototype.entries ( )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. obj를 ? ToObject(this value)라고 하자.
  2. CreateArrayIterator(obj, key+value)를 반환한다.

23.1.3.6 Array.prototype.every ( callback [ , thisArg ] )

Note 1

callback은 세 개의 인자를 받아 Boolean 값으로 강제 변환될 수 있는 값을 반환하는 함수여야 한다. everycallbackfalse를 반환하는 요소를 찾을 때까지 배열에 존재하는 각 요소에 대해 오름차순으로 한 번씩 callback을 호출한다. 그러한 요소를 찾으면, every는 즉시 false를 반환한다. 그렇지 않으면, everytrue를 반환한다. callback은 실제로 존재하는 배열 요소에 대해서만 호출되며, 배열의 누락된 요소에 대해서는 호출되지 않는다.

thisArg 매개변수가 제공되면, callback의 각 호출에서 this 값으로 사용된다. 제공되지 않으면, 대신 undefined가 사용된다.

callback은 세 개의 인자, 즉 요소의 값, 요소의 인덱스, 그리고 순회 중인 객체와 함께 호출된다.

every는 호출 대상 객체를 직접 변경하지 않지만, callback 호출에 의해 객체가 변경될 수 있다.

every가 처리하는 요소의 범위는 callback의 첫 호출 전에 설정된다. every 호출이 시작된 뒤 배열에 추가되는 요소는 callback이 방문하지 않는다. 배열의 기존 요소가 변경되면, callback에 전달되는 값은 every가 해당 요소를 방문하는 시점의 값이 된다; every 호출이 시작된 뒤 방문되기 전에 삭제되는 요소는 방문되지 않는다. every는 수학의 "for all" 한정자처럼 동작한다. 특히 빈 배열에 대해서는 true를 반환한다.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. obj를 ? ToObject(this value)라고 하자.
  2. len을 ? LengthOfArrayLike(obj)라고 하자.
  3. IsCallable(callback)가 false이면, TypeError 예외를 던진다.
  4. k를 0이라고 하자.
  5. k < len인 동안 반복한다,
    1. propertyKey를 ! ToString(𝔽(k))라고 하자.
    2. kPresent를 ? HasProperty(obj, propertyKey)라고 하자.
    3. kPresenttrue이면,
      1. kValue를 ? Get(obj, propertyKey)라고 하자.
      2. testResultToBoolean(? Call(callback, thisArg, « kValue, 𝔽(k), obj »))라고 하자.
      3. testResultfalse이면, false를 반환한다.
    4. kk + 1로 설정한다.
  6. true를 반환한다.
Note 2

이 메서드는 의도적으로 제네릭이다; 이 메서드는 자신의 this 값이 Array일 것을 요구하지 않는다. 따라서 메서드로 사용하기 위해 다른 종류의 객체로 이전될 수 있다.

23.1.3.7 Array.prototype.fill ( value [ , start [ , end ] ] )

Note 1

start 인자는 선택적이다. 제공되지 않으면, +0𝔽이 사용된다.

end 인자는 선택적이다. 제공되지 않으면, this 값의 길이가 사용된다.

Note 2

start가 음수이면, 배열의 길이인 length에 대해 length + start로 취급된다. end가 음수이면, length + end로 취급된다.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. obj를 ? ToObject(this value)라고 하자.
  2. len을 ? LengthOfArrayLike(obj)라고 하자.
  3. relativeStart를 ? ToIntegerOrInfinity(start)라고 하자.
  4. relativeStart = -∞이면, k를 0이라고 하자.
  5. 그렇지 않고 relativeStart < 0이면, kmax(len + relativeStart, 0)이라고 하자.
  6. 그렇지 않으면, kmin(relativeStart, len)이라고 하자.
  7. endundefined이면 relativeEndlen이라고 하자; 그렇지 않으면 relativeEnd를 ? ToIntegerOrInfinity(end)라고 하자.
  8. relativeEnd = -∞이면, final을 0이라고 하자.
  9. 그렇지 않고 relativeEnd < 0이면, finalmax(len + relativeEnd, 0)이라고 하자.
  10. 그렇지 않으면, finalmin(relativeEnd, len)이라고 하자.
  11. k < final인 동안 반복한다,
    1. propertyKey를 ! ToString(𝔽(k))라고 하자.
    2. Set(obj, propertyKey, value, true)를 수행한다.
    3. kk + 1로 설정한다.
  12. obj를 반환한다.
Note 3

이 메서드는 의도적으로 제네릭이다; 이 메서드는 자신의 this 값이 Array일 것을 요구하지 않는다. 따라서 메서드로 사용하기 위해 다른 종류의 객체로 이전될 수 있다.

23.1.3.8 Array.prototype.filter ( callback [ , thisArg ] )

Note 1

callback은 세 개의 인자를 받아 Boolean 값으로 강제 변환될 수 있는 값을 반환하는 함수여야 한다. filter는 배열의 각 요소에 대해 오름차순으로 한 번씩 callback을 호출하고, callbacktrue를 반환하는 모든 값으로 새 배열을 구성한다. callback은 실제로 존재하는 배열 요소에 대해서만 호출되며, 배열의 누락된 요소에 대해서는 호출되지 않는다.

thisArg 매개변수가 제공되면, callback의 각 호출에서 this 값으로 사용된다. 제공되지 않으면, 대신 undefined가 사용된다.

callback은 세 개의 인자, 즉 요소의 값, 요소의 인덱스, 그리고 순회 중인 객체와 함께 호출된다.

filter는 호출 대상 객체를 직접 변경하지 않지만, callback 호출에 의해 객체가 변경될 수 있다.

filter가 처리하는 요소의 범위는 callback의 첫 호출 전에 설정된다. filter 호출이 시작된 뒤 배열에 추가되는 요소는 callback이 방문하지 않는다. 배열의 기존 요소가 변경되면 callback에 전달되는 값은 filter가 해당 요소를 방문하는 시점의 값이 된다; filter 호출이 시작된 뒤 방문되기 전에 삭제되는 요소는 방문되지 않는다.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. obj를 ? ToObject(this value)라고 하자.
  2. len을 ? LengthOfArrayLike(obj)라고 하자.
  3. IsCallable(callback)가 false이면, TypeError 예외를 던진다.
  4. array를 ? ArraySpeciesCreate(obj, 0)이라고 하자.
  5. k를 0이라고 하자.
  6. to를 0이라고 하자.
  7. k < len인 동안 반복한다,
    1. propertyKey를 ! ToString(𝔽(k))라고 하자.
    2. kPresent를 ? HasProperty(obj, propertyKey)라고 하자.
    3. kPresenttrue이면,
      1. kValue를 ? Get(obj, propertyKey)라고 하자.
      2. selectedToBoolean(? Call(callback, thisArg, « kValue, 𝔽(k), obj »))라고 하자.
      3. selectedtrue이면,
        1. CreateDataPropertyOrThrow(array, ! ToString(𝔽(to)), kValue)를 수행한다.
        2. toto + 1로 설정한다.
    4. kk + 1로 설정한다.
  8. array를 반환한다.
Note 2

이 메서드는 의도적으로 제네릭이다; 이 메서드는 자신의 this 값이 Array일 것을 요구하지 않는다. 따라서 메서드로 사용하기 위해 다른 종류의 객체로 이전될 수 있다.

23.1.3.9 Array.prototype.find ( predicate [ , thisArg ] )

Note 1

이 메서드는 predicatetrue로 강제 변환되는 값을 반환하는 요소를 찾을 때까지 배열의 각 요소에 대해 오름차순 인덱스 순서로 한 번씩 predicate를 호출한다. 그러한 요소를 찾으면, find는 즉시 그 요소 값을 반환한다. 그렇지 않으면, findundefined를 반환한다.

추가 정보는 FindViaPredicate를 보라.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. obj를 ? ToObject(this value)라고 하자.
  2. len을 ? LengthOfArrayLike(obj)라고 하자.
  3. findRec를 ? FindViaPredicate(obj, len, ascending, predicate, thisArg)라고 하자.
  4. findRec.[[Value]]를 반환한다.
Note 2

이 메서드는 의도적으로 제네릭이다; 이 메서드는 자신의 this 값이 Array일 것을 요구하지 않는다. 따라서 메서드로 사용하기 위해 다른 종류의 객체로 이전될 수 있다.

23.1.3.10 Array.prototype.findIndex ( predicate [ , thisArg ] )

Note 1

이 메서드는 predicatetrue로 강제 변환되는 값을 반환하는 요소를 찾을 때까지 배열의 각 요소에 대해 오름차순 인덱스 순서로 한 번씩 predicate를 호출한다. 그러한 요소를 찾으면, findIndex는 즉시 그 요소 값의 인덱스를 반환한다. 그렇지 않으면, findIndex는 -1을 반환한다.

추가 정보는 FindViaPredicate를 보라.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. obj를 ? ToObject(this value)라고 하자.
  2. len을 ? LengthOfArrayLike(obj)라고 하자.
  3. findRec를 ? FindViaPredicate(obj, len, ascending, predicate, thisArg)라고 하자.
  4. findRec.[[Index]]를 반환한다.
Note 2

이 메서드는 의도적으로 제네릭이다; 이 메서드는 자신의 this 값이 Array일 것을 요구하지 않는다. 따라서 메서드로 사용하기 위해 다른 종류의 객체로 이전될 수 있다.

23.1.3.11 Array.prototype.findLast ( predicate [ , thisArg ] )

Note 1

이 메서드는 predicatetrue로 강제 변환되는 값을 반환하는 요소를 찾을 때까지 배열의 각 요소에 대해 내림차순 인덱스 순서로 한 번씩 predicate를 호출한다. 그러한 요소를 찾으면, findLast는 즉시 그 요소 값을 반환한다. 그렇지 않으면, findLastundefined를 반환한다.

추가 정보는 FindViaPredicate를 보라.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. obj를 ? ToObject(this value)라고 하자.
  2. len을 ? LengthOfArrayLike(obj)라고 하자.
  3. findRec를 ? FindViaPredicate(obj, len, descending, predicate, thisArg)라고 하자.
  4. findRec.[[Value]]를 반환한다.
Note 2

이 메서드는 의도적으로 제네릭이다; 이 메서드는 자신의 this 값이 Array 객체일 것을 요구하지 않는다. 따라서 메서드로 사용하기 위해 다른 종류의 객체로 이전될 수 있다.

23.1.3.12 Array.prototype.findLastIndex ( predicate [ , thisArg ] )

Note 1

이 메서드는 predicatetrue로 강제 변환되는 값을 반환하는 요소를 찾을 때까지 배열의 각 요소에 대해 내림차순 인덱스 순서로 한 번씩 predicate를 호출한다. 그러한 요소를 찾으면, findLastIndex는 즉시 그 요소 값의 인덱스를 반환한다. 그렇지 않으면, findLastIndex는 -1을 반환한다.

추가 정보는 FindViaPredicate를 보라.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. obj를 ? ToObject(this value)라고 하자.
  2. len을 ? LengthOfArrayLike(obj)라고 하자.
  3. findRec를 ? FindViaPredicate(obj, len, descending, predicate, thisArg)라고 하자.
  4. findRec.[[Index]]를 반환한다.
Note 2

이 메서드는 의도적으로 제네릭이다; 이 메서드는 자신의 this 값이 Array 객체일 것을 요구하지 않는다. 따라서 메서드로 사용하기 위해 다른 종류의 객체로 이전될 수 있다.

23.1.3.12.1 FindViaPredicate ( obj, len, direction, predicate, thisArg )

The abstract operation FindViaPredicate takes arguments obj (an Object), len (a non-negative integer), direction (ascending or descending), predicate (an ECMAScript language value), and thisArg (an ECMAScript language value) and returns either a normal completion containing a Record with fields [[Index]] (an integral Number) and [[Value]] (an ECMAScript language value) or a throw completion.

obj는 배열 유사 객체 또는 TypedArray여야 한다. 이 연산은 direction이 나타내는 대로 오름차순 인덱스 순서 또는 내림차순 인덱스 순서로 obj의 각 요소에 대해 한 번씩 predicate를 호출하며, predicatetrue로 강제 변환되는 값을 반환하는 요소를 찾을 때까지 계속한다. 그 시점에서 이 연산은 찾은 요소의 인덱스와 값을 제공하는 Record를 반환한다. 그러한 요소를 찾지 못하면, 이 연산은 인덱스로 -1𝔽, 값으로 undefined를 지정하는 Record를 반환한다.

predicate는 함수여야 한다. 배열의 요소에 대해 호출될 때, 요소의 값, 요소의 인덱스, 그리고 순회 중인 객체라는 세 인자가 전달된다. 그 반환값은 Boolean 값으로 강제 변환된다.

thisArgpredicate의 각 호출에서 this 값으로 사용된다.

이 연산은 호출 대상 객체를 직접 변경하지 않지만, predicate 호출에 의해 객체가 변경될 수 있다.

처리되는 요소의 범위는 predicate의 첫 호출 전, 순회가 시작되기 직전에 설정된다. 이후 배열에 추가되는 요소는 predicate가 방문하지 않는다. 배열의 기존 요소가 변경되면, predicate에 전달되는 값은 이 연산이 해당 요소를 방문하는 시점의 값이 된다. 순회가 시작된 뒤 방문되기 전에 삭제되는 요소는 여전히 방문되며, 프로토타입에서 조회되거나 undefined가 된다.

It performs the following steps when called:

  1. IsCallable(predicate)가 false이면, TypeError 예외를 던진다.
  2. directionascending이면,
    1. indices를 0(포함)부터 len(제외)까지의 구간에 있는 정수들의 List로, 오름차순으로 하자.
  3. 그렇지 않으면,
    1. indices를 0(포함)부터 len(제외)까지의 구간에 있는 정수들의 List로, 내림차순으로 하자.
  4. indices의 각 정수 k에 대해, 다음을 수행한다.
    1. propertyKey를 ! ToString(𝔽(k))라고 하자.
    2. NOTE: objTypedArray이면, 다음 Get 호출은 정상 완료를 반환한다.
    3. kValue를 ? Get(obj, propertyKey)라고 하자.
    4. testResult를 ? Call(predicate, thisArg, « kValue, 𝔽(k), obj »)라고 하자.
    5. ToBoolean(testResult)가 true이면, Record { [[Index]]: 𝔽(k), [[Value]]: kValue }를 반환한다.
  5. Record { [[Index]]: -1𝔽, [[Value]]: undefined }를 반환한다.

23.1.3.13 Array.prototype.flat ( [ depth ] )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. obj를 ? ToObject(this value)라고 하자.
  2. sourceLen을 ? LengthOfArrayLike(obj)라고 하자.
  3. depthNum을 1이라고 하자.
  4. depthundefined가 아니면,
    1. depthNum을 ? ToIntegerOrInfinity(depth)로 설정한다.
    2. depthNum < 0이면, depthNum을 0으로 설정한다.
  5. array를 ? ArraySpeciesCreate(obj, 0)이라고 하자.
  6. FlattenIntoArray(array, obj, sourceLen, 0, depthNum)를 수행한다.
  7. array를 반환한다.

23.1.3.13.1 FlattenIntoArray ( target, source, sourceLen, start, depth [ , mapperFunction [ , thisArg ] ] )

The abstract operation FlattenIntoArray takes arguments target (an Object), source (an Object), sourceLen (a non-negative integer), start (a non-negative integer), and depth (a non-negative integer or +∞) and optional arguments mapperFunction (a function object) and thisArg (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. Assert: mapperFunction이 존재하면, IsCallable(mapperFunction)는 true이고, thisArg가 존재하며, depth는 1이다.
  2. targetIndexstart라고 하자.
  3. sourceIndex+0𝔽이라고 하자.
  4. (sourceIndex) < sourceLen인 동안 반복한다,
    1. propertyKey를 ! ToString(sourceIndex)라고 하자.
    2. exists를 ? HasProperty(source, propertyKey)라고 하자.
    3. existstrue이면,
      1. element를 ? Get(source, propertyKey)라고 하자.
      2. mapperFunction이 존재하면,
        1. element를 ? Call(mapperFunction, thisArg, « element, sourceIndex, source »)로 설정한다.
      3. shouldFlattenfalse라고 하자.
      4. depth > 0이면,
        1. shouldFlatten을 ? IsArray(element)로 설정한다.
      5. shouldFlattentrue이면,
        1. depth = +∞이면 newDepth를 +∞라고 하자.
        2. 그렇지 않으면, newDepthdepth - 1이라고 하자.
        3. elementLen을 ? LengthOfArrayLike(element)라고 하자.
        4. targetIndex를 ? FlattenIntoArray(target, element, elementLen, targetIndex, newDepth)로 설정한다.
      6. 그렇지 않으면,
        1. targetIndex ≥ 253 - 1이면, TypeError 예외를 던진다.
        2. CreateDataPropertyOrThrow(target, ! ToString(𝔽(targetIndex)), element)를 수행한다.
        3. targetIndextargetIndex + 1로 설정한다.
    4. sourceIndexsourceIndex + 1𝔽로 설정한다.
  5. targetIndex를 반환한다.

23.1.3.14 Array.prototype.flatMap ( mapperFunction [ , thisArg ] )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. obj를 ? ToObject(this value)라고 하자.
  2. sourceLen을 ? LengthOfArrayLike(obj)라고 하자.
  3. IsCallable(mapperFunction)가 false이면, TypeError 예외를 던진다.
  4. array를 ? ArraySpeciesCreate(obj, 0)이라고 하자.
  5. FlattenIntoArray(array, obj, sourceLen, 0, 1, mapperFunction, thisArg)를 수행한다.
  6. array를 반환한다.

23.1.3.15 Array.prototype.forEach ( callback [ , thisArg ] )

Note 1

callback은 세 개의 인자를 받는 함수여야 한다. forEach는 배열에 존재하는 각 요소에 대해 오름차순으로 한 번씩 callback을 호출한다. callback은 실제로 존재하는 배열 요소에 대해서만 호출되며, 배열의 누락된 요소에 대해서는 호출되지 않는다.

thisArg 매개변수가 제공되면, callback의 각 호출에서 this 값으로 사용된다. 제공되지 않으면, 대신 undefined가 사용된다.

callback은 세 개의 인자, 즉 요소의 값, 요소의 인덱스, 그리고 순회 중인 객체와 함께 호출된다.

forEach는 호출 대상 객체를 직접 변경하지 않지만, callback 호출에 의해 객체가 변경될 수 있다.

forEach가 처리하는 요소의 범위는 callback의 첫 호출 전에 설정된다. forEach 호출이 시작된 뒤 배열에 추가되는 요소는 callback이 방문하지 않는다. 배열의 기존 요소가 변경되면, callback에 전달되는 값은 forEach가 해당 요소를 방문하는 시점의 값이 된다; forEach 호출이 시작된 뒤 방문되기 전에 삭제되는 요소는 방문되지 않는다.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. obj를 ? ToObject(this value)라고 하자.
  2. len을 ? LengthOfArrayLike(obj)라고 하자.
  3. IsCallable(callback)가 false이면, TypeError 예외를 던진다.
  4. k를 0이라고 하자.
  5. k < len인 동안 반복한다,
    1. propertyKey를 ! ToString(𝔽(k))라고 하자.
    2. kPresent를 ? HasProperty(obj, propertyKey)라고 하자.
    3. kPresenttrue이면,
      1. kValue를 ? Get(obj, propertyKey)라고 하자.
      2. Call(callback, thisArg, « kValue, 𝔽(k), obj »)를 수행한다.
    4. kk + 1로 설정한다.
  6. undefined를 반환한다.
Note 2

이 메서드는 의도적으로 제네릭이다; 이 메서드는 자신의 this 값이 Array일 것을 요구하지 않는다. 따라서 메서드로 사용하기 위해 다른 종류의 객체로 이전될 수 있다.

23.1.3.16 Array.prototype.includes ( searchElement [ , fromIndex ] )

Note 1

이 메서드는 SameValueZero 알고리즘을 사용해 searchElement를 배열의 요소들과 오름차순으로 비교하고, 어느 위치에서든 발견되면 true를 반환한다; 그렇지 않으면 false를 반환한다.

선택적 두 번째 인자 fromIndex의 기본값은 +0𝔽이다(즉, 전체 배열을 검색한다). 이 값이 배열의 길이보다 크거나 같으면, false가 반환된다. 즉 배열을 검색하지 않는다. -0𝔽보다 작으면, fromIndex를 계산하기 위해 배열 끝으로부터의 오프셋으로 사용된다. 계산된 인덱스가 +0𝔽 이하이면, 전체 배열을 검색한다.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. obj를 ? ToObject(this value)라고 하자.
  2. len을 ? LengthOfArrayLike(obj)라고 하자.
  3. len = 0이면, false를 반환한다.
  4. startIndex를 ? ToIntegerOrInfinity(fromIndex)라고 하자.
  5. Assert: fromIndexundefined이면, startIndex는 0이다.
  6. startIndex = +∞이면, false를 반환한다.
  7. startIndex = -∞이면, startIndex를 0으로 설정한다.
  8. startIndex ≥ 0이면,
    1. kstartIndex라고 하자.
  9. 그렇지 않으면,
    1. klen + startIndex라고 하자.
    2. k < 0이면, k를 0으로 설정한다.
  10. k < len인 동안 반복한다,
    1. elementK를 ? Get(obj, ! ToString(𝔽(k)))라고 하자.
    2. SameValueZero(searchElement, elementK)가 true이면, true를 반환한다.
    3. kk + 1로 설정한다.
  11. false를 반환한다.
Note 2

이 메서드는 의도적으로 제네릭이다; 이 메서드는 자신의 this 값이 Array일 것을 요구하지 않는다. 따라서 메서드로 사용하기 위해 다른 종류의 객체로 이전될 수 있다.

Note 3

이 메서드는 유사한 indexOf 메서드와 의도적으로 두 가지 점에서 다르다. 첫째, IsStrictlyEqual 대신 SameValueZero 알고리즘을 사용하므로 NaN 배열 요소를 감지할 수 있다. 둘째, 누락된 배열 요소를 건너뛰지 않고 undefined로 취급한다.

23.1.3.17 Array.prototype.indexOf ( searchElement [ , fromIndex ] )

이 메서드는 IsStrictlyEqual 알고리즘을 사용해 searchElement를 배열의 요소들과 오름차순으로 비교하고, 하나 이상의 인덱스에서 발견되면 그러한 가장 작은 인덱스를 반환한다; 그렇지 않으면 -1𝔽을 반환한다.

Note 1

선택적 두 번째 인자 fromIndex의 기본값은 +0𝔽이다(즉, 전체 배열을 검색한다). 이 값이 배열의 길이보다 크거나 같으면, -1𝔽이 반환된다. 즉 배열을 검색하지 않는다. -0𝔽보다 작으면, 배열 끝으로부터의 오프셋을 계산하는 데 사용된다. 계산된 인덱스가 +0𝔽 이하이면, 전체 배열을 검색한다.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. obj를 ? ToObject(this value)라고 하자.
  2. len을 ? LengthOfArrayLike(obj)라고 하자.
  3. len = 0이면, -1𝔽을 반환한다.
  4. startIndex를 ? ToIntegerOrInfinity(fromIndex)라고 하자.
  5. Assert: fromIndexundefined이면, startIndex는 0이다.
  6. startIndex = +∞이면, -1𝔽을 반환한다.
  7. startIndex = -∞이면, startIndex를 0으로 설정한다.
  8. startIndex ≥ 0이면,
    1. kstartIndex라고 하자.
  9. 그렇지 않으면,
    1. klen + startIndex라고 하자.
    2. k < 0이면, k를 0으로 설정한다.
  10. k < len인 동안 반복한다,
    1. propertyKey를 ! ToString(𝔽(k))라고 하자.
    2. kPresent를 ? HasProperty(obj, propertyKey)라고 하자.
    3. kPresenttrue이면,
      1. elementK를 ? Get(obj, propertyKey)라고 하자.
      2. IsStrictlyEqual(searchElement, elementK)가 true이면, 𝔽(k)를 반환한다.
    4. kk + 1로 설정한다.
  11. -1𝔽을 반환한다.
Note 2

이 메서드는 의도적으로 제네릭이다; 이 메서드는 자신의 this 값이 Array일 것을 요구하지 않는다. 따라서 메서드로 사용하기 위해 다른 종류의 객체로 이전될 수 있다.

23.1.3.18 Array.prototype.join ( separator )

이 메서드는 배열의 요소들을 String으로 변환한 뒤, separator의 출현으로 구분하여 이 String들을 연결한다. 구분자가 제공되지 않으면, 단일 쉼표가 구분자로 사용된다.

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

  1. obj를 ? ToObject(this value)라고 하자.
  2. len을 ? LengthOfArrayLike(obj)라고 하자.
  3. separatorundefined이면, sep","라고 하자.
  4. 그렇지 않으면, sep를 ? ToString(separator)라고 하자.
  5. result를 빈 String이라고 하자.
  6. k를 0이라고 하자.
  7. k < len인 동안 반복한다,
    1. k > 0이면, resultresultsep의 문자열 연결로 설정한다.
    2. element를 ? Get(obj, ! ToString(𝔽(k)))라고 하자.
    3. elementundefined도 아니고 null도 아니면,
      1. elementStr을 ? ToString(element)라고 하자.
      2. resultresultelementStr의 문자열 연결로 설정한다.
    4. kk + 1로 설정한다.
  8. result를 반환한다.
Note

이 메서드는 의도적으로 제네릭이다; 이 메서드는 자신의 this 값이 Array일 것을 요구하지 않는다. 따라서 메서드로 사용하기 위해 다른 종류의 객체로 이전될 수 있다.

23.1.3.19 Array.prototype.keys ( )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. obj를 ? ToObject(this value)라고 하자.
  2. CreateArrayIterator(obj, key)를 반환한다.

23.1.3.20 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] )

Note 1

이 메서드는 IsStrictlyEqual 알고리즘을 사용해 searchElement를 배열의 요소들과 내림차순으로 비교하고, 하나 이상의 인덱스에서 발견되면 그러한 가장 큰 인덱스를 반환한다; 그렇지 않으면 -1𝔽을 반환한다.

선택적 두 번째 인자 fromIndex의 기본값은 배열의 길이에서 1을 뺀 값이다(즉, 전체 배열을 검색한다). 이 값이 배열의 길이보다 크거나 같으면, 전체 배열을 검색한다. -0𝔽보다 작으면, 배열 끝으로부터의 오프셋을 계산하는 데 사용된다. 계산된 인덱스가 -0𝔽보다 작으면, -1𝔽이 반환된다.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. obj를 ? ToObject(this value)라고 하자.
  2. len을 ? LengthOfArrayLike(obj)라고 하자.
  3. len = 0이면, -1𝔽을 반환한다.
  4. fromIndex가 존재하면 startIndex를 ? ToIntegerOrInfinity(fromIndex)라고 하자; 그렇지 않으면 startIndexlen - 1이라고 하자.
  5. startIndex = -∞이면, -1𝔽을 반환한다.
  6. startIndex ≥ 0이면,
    1. kmin(startIndex, len - 1)이라고 하자.
  7. 그렇지 않으면,
    1. klen + startIndex라고 하자.
  8. k ≥ 0인 동안 반복한다,
    1. propertyKey를 ! ToString(𝔽(k))라고 하자.
    2. kPresent를 ? HasProperty(obj, propertyKey)라고 하자.
    3. kPresenttrue이면,
      1. elementK를 ? Get(obj, propertyKey)라고 하자.
      2. IsStrictlyEqual(searchElement, elementK)가 true이면, 𝔽(k)를 반환한다.
    4. kk - 1로 설정한다.
  9. -1𝔽을 반환한다.
Note 2

이 메서드는 의도적으로 제네릭이다; 이 메서드는 자신의 this 값이 Array일 것을 요구하지 않는다. 따라서 메서드로 사용하기 위해 다른 종류의 객체로 이전될 수 있다.

23.1.3.21 Array.prototype.map ( callback [ , thisArg ] )

Note 1

callback은 세 개의 인자를 받는 함수여야 한다. map은 배열의 각 요소에 대해 오름차순으로 한 번씩 callback을 호출하고, 그 결과로 새 Array를 구성한다. callback은 실제로 존재하는 배열 요소에 대해서만 호출되며, 배열의 누락된 요소에 대해서는 호출되지 않는다.

thisArg 매개변수가 제공되면, callback의 각 호출에서 this 값으로 사용된다. 제공되지 않으면, 대신 undefined가 사용된다.

callback은 세 개의 인자, 즉 요소의 값, 요소의 인덱스, 그리고 순회 중인 객체와 함께 호출된다.

map은 호출 대상 객체를 직접 변경하지 않지만, callback 호출에 의해 객체가 변경될 수 있다.

map이 처리하는 요소의 범위는 callback의 첫 호출 전에 설정된다. map 호출이 시작된 뒤 배열에 추가되는 요소는 callback이 방문하지 않는다. 배열의 기존 요소가 변경되면, callback에 전달되는 값은 map이 해당 요소를 방문하는 시점의 값이 된다; map 호출이 시작된 뒤 방문되기 전에 삭제되는 요소는 방문되지 않는다.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. obj를 ? ToObject(this value)라고 하자.
  2. len을 ? LengthOfArrayLike(obj)라고 하자.
  3. IsCallable(callback)가 false이면, TypeError 예외를 던진다.
  4. array를 ? ArraySpeciesCreate(obj, len)라고 하자.
  5. k를 0이라고 하자.
  6. k < len인 동안 반복한다,
    1. propertyKey를 ! ToString(𝔽(k))라고 하자.
    2. kPresent를 ? HasProperty(obj, propertyKey)라고 하자.
    3. kPresenttrue이면,
      1. kValue를 ? Get(obj, propertyKey)라고 하자.
      2. mappedValue를 ? Call(callback, thisArg, « kValue, 𝔽(k), obj »)라고 하자.
      3. CreateDataPropertyOrThrow(array, propertyKey, mappedValue)를 수행한다.
    4. kk + 1로 설정한다.
  7. array를 반환한다.
Note 2

이 메서드는 의도적으로 제네릭이다; 이 메서드는 자신의 this 값이 Array일 것을 요구하지 않는다. 따라서 메서드로 사용하기 위해 다른 종류의 객체로 이전될 수 있다.

23.1.3.22 Array.prototype.pop ( )

Note 1

이 메서드는 배열의 마지막 요소를 제거하고 그것을 반환한다.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. obj를 ? ToObject(this value)라고 하자.
  2. len을 ? LengthOfArrayLike(obj)라고 하자.
  3. len = 0이면,
    1. Set(obj, "length", +0𝔽, true)를 수행한다.
    2. undefined를 반환한다.
  4. Assert: len > 0.
  5. newLen𝔽(len - 1)이라고 하자.
  6. index를 ! ToString(newLen)이라고 하자.
  7. element를 ? Get(obj, index)라고 하자.
  8. DeletePropertyOrThrow(obj, index)를 수행한다.
  9. Set(obj, "length", newLen, true)를 수행한다.
  10. element를 반환한다.
Note 2

이 메서드는 의도적으로 제네릭이다; 이 메서드는 자신의 this 값이 Array일 것을 요구하지 않는다. 따라서 메서드로 사용하기 위해 다른 종류의 객체로 이전될 수 있다.

23.1.3.23 Array.prototype.push ( ...items )

Note 1

이 메서드는 인자들을 나타나는 순서대로 배열의 끝에 추가한다. 이 메서드는 배열의 새 길이를 반환한다.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. obj를 ? ToObject(this value)라고 하자.
  2. len을 ? LengthOfArrayLike(obj)라고 하자.
  3. argCountitems의 요소 개수라고 하자.
  4. len + argCount > 253 - 1이면, TypeError 예외를 던진다.
  5. items의 각 요소 item에 대해, 다음을 수행한다.
    1. Set(obj, ! ToString(𝔽(len)), item, true)를 수행한다.
    2. lenlen + 1로 설정한다.
  6. Set(obj, "length", 𝔽(len), true)를 수행한다.
  7. 𝔽(len)를 반환한다.

이 메서드의 "length" 속성은 1𝔽이다.

Note 2

이 메서드는 의도적으로 제네릭이다; 이 메서드는 자신의 this 값이 Array일 것을 요구하지 않는다. 따라서 메서드로 사용하기 위해 다른 종류의 객체로 이전될 수 있다.

23.1.3.24 Array.prototype.reduce ( callback [ , initialValue ] )

Note 1

callback은 네 개의 인수를 받는 함수여야 한다. reduceinitialValue가 제공되지 않는 한 첫 번째 요소를 건너뛰고, 배열에 존재하는 각 요소에 대해 오름차순으로 callback을 한 번씩 호출한다.

callback은 네 개의 인자, 즉 previousValue(callback의 이전 호출에서 온 값), currentValue(현재 요소의 값), currentIndex, 그리고 순회 중인 객체와 함께 호출된다. callback이 처음 호출될 때, previousValuecurrentValue는 두 값 중 하나일 수 있다. reduce 호출에서 initialValue가 제공되었다면, previousValueinitialValue가 되고 currentValue는 배열의 첫 번째 값이 된다. initialValue가 제공되지 않았다면, previousValue는 배열의 첫 번째 값이 되고 currentValue는 두 번째 값이 된다. 배열이 요소를 포함하지 않고 initialValue가 제공되지 않으면 TypeError이다.

reduce는 호출 대상 객체를 직접 변경하지 않지만, callback 호출에 의해 객체가 변경될 수 있다.

reduce가 처리하는 요소의 범위는 callback의 첫 호출 전에 설정된다. reduce 호출이 시작된 뒤 배열에 추가되는 요소는 callback이 방문하지 않는다. 배열의 기존 요소가 변경되면, callback에 전달되는 값은 reduce가 해당 요소를 방문하는 시점의 값이 된다; reduce 호출이 시작된 뒤 방문되기 전에 삭제되는 요소는 방문되지 않는다.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. obj를 ? ToObject(this value)라고 하자.
  2. len을 ? LengthOfArrayLike(obj)라고 하자.
  3. IsCallable(callback)가 false이면, TypeError 예외를 던진다.
  4. len = 0이고 initialValue가 존재하지 않으면, TypeError 예외를 던진다.
  5. k를 0이라고 하자.
  6. accumulatorundefined라고 하자.
  7. initialValue가 존재하면,
    1. accumulatorinitialValue로 설정한다.
  8. 그렇지 않으면,
    1. kPresentfalse라고 하자.
    2. kPresentfalse이고 k < len인 동안 반복한다,
      1. propertyKey를 ! ToString(𝔽(k))라고 하자.
      2. kPresent를 ? HasProperty(obj, propertyKey)로 설정한다.
      3. kPresenttrue이면,
        1. accumulator를 ? Get(obj, propertyKey)로 설정한다.
      4. kk + 1로 설정한다.
    3. kPresentfalse이면, TypeError 예외를 던진다.
  9. k < len인 동안 반복한다,
    1. propertyKey를 ! ToString(𝔽(k))라고 하자.
    2. kPresent를 ? HasProperty(obj, propertyKey)라고 하자.
    3. kPresenttrue이면,
      1. kValue를 ? Get(obj, propertyKey)라고 하자.
      2. accumulator를 ? Call(callback, undefined, « accumulator, kValue, 𝔽(k), obj »)로 설정한다.
    4. kk + 1로 설정한다.
  10. accumulator를 반환한다.
Note 2

이 메서드는 의도적으로 제네릭이다; 이 메서드는 자신의 this 값이 Array일 것을 요구하지 않는다. 따라서 메서드로 사용하기 위해 다른 종류의 객체로 이전될 수 있다.

23.1.3.25 Array.prototype.reduceRight ( callback [ , initialValue ] )

Note 1

callback은 네 개의 인수를 받는 함수여야 한다. reduceRightinitialValue가 제공되지 않는 한 첫 번째 호출을 건너뛰고, 배열에 존재하는 각 요소에 대해 내림차순으로 callback을 한 번씩 호출한다.

callback은 네 개의 인자, 즉 previousValue(callback의 이전 호출에서 온 값), currentValue(현재 요소의 값), currentIndex, 그리고 순회 중인 객체와 함께 호출된다. 함수가 처음 호출될 때, previousValuecurrentValue는 두 값 중 하나일 수 있다. reduceRight 호출에서 initialValue가 제공되었다면, previousValueinitialValue가 되고 currentValue는 배열의 마지막 값이 된다. initialValue가 제공되지 않았다면, previousValue는 배열의 마지막 값이 되고 currentValue는 끝에서 두 번째 값이 된다. 배열이 요소를 포함하지 않고 initialValue가 제공되지 않으면 TypeError이다.

reduceRight는 호출 대상 객체를 직접 변경하지 않지만, callback 호출에 의해 객체가 변경될 수 있다.

reduceRight가 처리하는 요소의 범위는 callback의 첫 호출 전에 설정된다. reduceRight 호출이 시작된 뒤 배열에 추가되는 요소는 callback이 방문하지 않는다. 배열의 기존 요소가 callback에 의해 변경되면, callback에 전달되는 값은 reduceRight가 해당 요소를 방문하는 시점의 값이 된다; reduceRight 호출이 시작된 뒤 방문되기 전에 삭제되는 요소는 방문되지 않는다.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. obj를 ? ToObject(this value)라고 하자.
  2. len을 ? LengthOfArrayLike(obj)라고 하자.
  3. IsCallable(callback)가 false이면, TypeError 예외를 던진다.
  4. len = 0이고 initialValue가 존재하지 않으면, TypeError 예외를 던진다.
  5. klen - 1이라고 하자.
  6. accumulatorundefined라고 하자.
  7. initialValue가 존재하면,
    1. accumulatorinitialValue로 설정한다.
  8. 그렇지 않으면,
    1. kPresentfalse라고 하자.
    2. kPresentfalse이고 k ≥ 0인 동안 반복한다,
      1. propertyKey를 ! ToString(𝔽(k))라고 하자.
      2. kPresent를 ? HasProperty(obj, propertyKey)로 설정한다.
      3. kPresenttrue이면,
        1. accumulator를 ? Get(obj, propertyKey)로 설정한다.
      4. kk - 1로 설정한다.
    3. kPresentfalse이면, TypeError 예외를 던진다.
  9. k ≥ 0인 동안 반복한다,
    1. propertyKey를 ! ToString(𝔽(k))라고 하자.
    2. kPresent를 ? HasProperty(obj, propertyKey)라고 하자.
    3. kPresenttrue이면,
      1. kValue를 ? Get(obj, propertyKey)라고 하자.
      2. accumulator를 ? Call(callback, undefined, « accumulator, kValue, 𝔽(k), obj »)로 설정한다.
    4. kk - 1로 설정한다.
  10. accumulator를 반환한다.
Note 2

이 메서드는 의도적으로 제네릭이다; 이 메서드는 자신의 this 값이 Array일 것을 요구하지 않는다. 따라서 메서드로 사용하기 위해 다른 종류의 객체로 이전될 수 있다.

23.1.3.26 Array.prototype.reverse ( )

Note 1

이 메서드는 배열의 요소들을 재배열하여 그 순서를 뒤집는다. 뒤집힌 배열을 반환한다.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. obj를 ? ToObject(this value)라고 하자.
  2. len을 ? LengthOfArrayLike(obj)라고 하자.
  3. middlefloor(len / 2)라고 하자.
  4. lower를 0이라고 하자.
  5. lowermiddle인 동안 반복한다,
    1. upperlen - lower - 1이라고 하자.
    2. upperP를 ! ToString(𝔽(upper))라고 하자.
    3. lowerP를 ! ToString(𝔽(lower))라고 하자.
    4. lowerExists를 ? HasProperty(obj, lowerP)라고 하자.
    5. lowerExiststrue이면,
      1. lowerValue를 ? Get(obj, lowerP)라고 하자.
    6. upperExists를 ? HasProperty(obj, upperP)라고 하자.
    7. upperExiststrue이면,
      1. upperValue를 ? Get(obj, upperP)라고 하자.
    8. lowerExiststrue이고 upperExiststrue이면,
      1. Set(obj, lowerP, upperValue, true)를 수행한다.
      2. Set(obj, upperP, lowerValue, true)를 수행한다.
    9. 그렇지 않고 lowerExistsfalse이고 upperExiststrue이면,
      1. Set(obj, lowerP, upperValue, true)를 수행한다.
      2. DeletePropertyOrThrow(obj, upperP)를 수행한다.
    10. 그렇지 않고 lowerExiststrue이고 upperExistsfalse이면,
      1. DeletePropertyOrThrow(obj, lowerP)를 수행한다.
      2. Set(obj, upperP, lowerValue, true)를 수행한다.
    11. 그렇지 않으면,
      1. Assert: lowerExistsupperExists는 모두 false이다.
      2. NOTE: 아무 동작도 필요하지 않다.
    12. lowerlower + 1로 설정한다.
  6. obj를 반환한다.
Note 2

이 메서드는 의도적으로 제네릭이다; 이 메서드는 자신의 this 값이 Array일 것을 요구하지 않는다. 따라서 메서드로 사용하기 위해 다른 종류의 객체로 이전될 수 있다.

23.1.3.27 Array.prototype.shift ( )

이 메서드는 배열의 첫 번째 요소를 제거하고 그것을 반환한다.

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

  1. obj를 ? ToObject(this value)라고 하자.
  2. len을 ? LengthOfArrayLike(obj)라고 하자.
  3. len = 0이면,
    1. Set(obj, "length", +0𝔽, true)를 수행한다.
    2. undefined를 반환한다.
  4. first를 ? Get(obj, "0")라고 하자.
  5. k를 1이라고 하자.
  6. k < len인 동안 반복한다,
    1. from을 ! ToString(𝔽(k))라고 하자.
    2. to를 ! ToString(𝔽(k - 1))라고 하자.
    3. fromPresent를 ? HasProperty(obj, from)라고 하자.
    4. fromPresenttrue이면,
      1. fromValue를 ? Get(obj, from)라고 하자.
      2. Set(obj, to, fromValue, true)를 수행한다.
    5. 그렇지 않으면,
      1. Assert: fromPresentfalse이다.
      2. DeletePropertyOrThrow(obj, to)를 수행한다.
    6. kk + 1로 설정한다.
  7. DeletePropertyOrThrow(obj, ! ToString(𝔽(len - 1)))를 수행한다.
  8. Set(obj, "length", 𝔽(len - 1), true)를 수행한다.
  9. first를 반환한다.
Note

이 메서드는 의도적으로 제네릭이다; 이 메서드는 자신의 this 값이 Array일 것을 요구하지 않는다. 따라서 메서드로 사용하기 위해 다른 종류의 객체로 이전될 수 있다.

23.1.3.28 Array.prototype.slice ( start, end )

이 메서드는 배열의 요소 start부터 요소 end 전까지(endundefined이면 배열의 끝까지)의 요소들을 포함하는 배열을 반환한다. start가 음수이면, 배열의 길이인 length에 대해 length + start로 취급된다. end가 음수이면, 배열의 길이인 length에 대해 length + end로 취급된다.

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

  1. obj를 ? ToObject(this value)라고 하자.
  2. len을 ? LengthOfArrayLike(obj)라고 하자.
  3. relativeStart를 ? ToIntegerOrInfinity(start)라고 하자.
  4. relativeStart = -∞이면, k를 0이라고 하자.
  5. 그렇지 않고 relativeStart < 0이면, kmax(len + relativeStart, 0)이라고 하자.
  6. 그렇지 않으면, kmin(relativeStart, len)이라고 하자.
  7. endundefined이면 relativeEndlen이라고 하자; 그렇지 않으면 relativeEnd를 ? ToIntegerOrInfinity(end)라고 하자.
  8. relativeEnd = -∞이면, final을 0이라고 하자.
  9. 그렇지 않고 relativeEnd < 0이면, finalmax(len + relativeEnd, 0)이라고 하자.
  10. 그렇지 않으면, finalmin(relativeEnd, len)이라고 하자.
  11. countmax(final - k, 0)이라고 하자.
  12. array를 ? ArraySpeciesCreate(obj, count)라고 하자.
  13. resultIndex를 0이라고 하자.
  14. k < final인 동안 반복한다,
    1. propertyKey를 ! ToString(𝔽(k))라고 하자.
    2. kPresent를 ? HasProperty(obj, propertyKey)라고 하자.
    3. kPresenttrue이면,
      1. kValue를 ? Get(obj, propertyKey)라고 하자.
      2. CreateDataPropertyOrThrow(array, ! ToString(𝔽(resultIndex)), kValue)를 수행한다.
    4. kk + 1로 설정한다.
    5. resultIndexresultIndex + 1로 설정한다.
  15. Set(array, "length", 𝔽(resultIndex), true)를 수행한다.
  16. array를 반환한다.
Note 1

단계 15에서 "length" 속성을 명시적으로 설정하는 것은 array가 내장 Array가 아닐 때도 길이가 올바르도록 보장하기 위한 것이다.

Note 2

이 메서드는 의도적으로 제네릭이다; 이 메서드는 자신의 this 값이 Array일 것을 요구하지 않는다. 따라서 메서드로 사용하기 위해 다른 종류의 객체로 이전될 수 있다.

23.1.3.29 Array.prototype.some ( callback [ , thisArg ] )

Note 1

callback은 세 개의 인자를 받아 Boolean 값으로 강제 변환될 수 있는 값을 반환하는 함수여야 한다. somecallbacktrue를 반환하는 요소를 찾을 때까지 배열에 존재하는 각 요소에 대해 오름차순으로 한 번씩 callback을 호출한다. 그러한 요소를 찾으면, some은 즉시 true를 반환한다. 그렇지 않으면, somefalse를 반환한다. callback은 실제로 존재하는 배열 요소에 대해서만 호출되며, 배열의 누락된 요소에 대해서는 호출되지 않는다.

thisArg 매개변수가 제공되면, callback의 각 호출에서 this 값으로 사용된다. 제공되지 않으면, 대신 undefined가 사용된다.

callback은 세 개의 인자, 즉 요소의 값, 요소의 인덱스, 그리고 순회 중인 객체와 함께 호출된다.

some은 호출 대상 객체를 직접 변경하지 않지만, callback 호출에 의해 객체가 변경될 수 있다.

some이 처리하는 요소의 범위는 callback의 첫 호출 전에 설정된다. some 호출이 시작된 뒤 배열에 추가되는 요소는 callback이 방문하지 않는다. 배열의 기존 요소가 변경되면, callback에 전달되는 값은 some이 해당 요소를 방문하는 시점의 값이 된다; some 호출이 시작된 뒤 방문되기 전에 삭제되는 요소는 방문되지 않는다. some은 수학의 "exists" 한정자처럼 동작한다. 특히 빈 배열에 대해서는 false를 반환한다.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. obj를 ? ToObject(this value)라고 하자.
  2. len을 ? LengthOfArrayLike(obj)라고 하자.
  3. IsCallable(callback)가 false이면, TypeError 예외를 던진다.
  4. k를 0이라고 하자.
  5. k < len인 동안 반복한다,
    1. propertyKey를 ! ToString(𝔽(k))라고 하자.
    2. kPresent를 ? HasProperty(obj, propertyKey)라고 하자.
    3. kPresenttrue이면,
      1. kValue를 ? Get(obj, propertyKey)라고 하자.
      2. testResultToBoolean(? Call(callback, thisArg, « kValue, 𝔽(k), obj »))라고 하자.
      3. testResulttrue이면, true를 반환한다.
    4. kk + 1로 설정한다.
  6. false를 반환한다.
Note 2

이 메서드는 의도적으로 제네릭이다; 이 메서드는 자신의 this 값이 Array일 것을 요구하지 않는다. 따라서 메서드로 사용하기 위해 다른 종류의 객체로 이전될 수 있다.

23.1.3.30 Array.prototype.sort ( comparator )

이 메서드는 이 배열의 요소들을 정렬한다. comparatorundefined가 아니면, 두 인자 xy를 받아 x < y이면 음수 Number, x > y이면 양수 Number, 그 밖의 경우에는 0을 반환하는 함수여야 한다.

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

  1. comparatorundefined가 아니고 IsCallable(comparator)가 false이면, TypeError 예외를 던진다.
  2. obj를 ? ToObject(this value)라고 하자.
  3. len을 ? LengthOfArrayLike(obj)라고 하자.
  4. sortComparecomparator를 캡처하고 호출될 때 다음 단계를 수행하는, 매개변수 (x, y)를 가진 새로운 Abstract Closure라고 하자:
    1. CompareArrayElements(x, y, comparator)를 반환한다.
  5. sortedList를 ? SortIndexedProperties(obj, len, sortCompare, skip-holes)라고 하자.
  6. itemCountsortedList의 요소 개수라고 하자.
  7. j를 0이라고 하자.
  8. j < itemCount인 동안 반복한다,
    1. Set(obj, ! ToString(𝔽(j)), sortedList[j], true)를 수행한다.
    2. jj + 1로 설정한다.
  9. NOTE: 단계 5에서 SortIndexedProperties 호출은 skip-holes를 사용한다. 나머지 인덱스는 감지되어 정렬에서 제외된 빈 슬롯의 수를 보존하기 위해 삭제된다.
  10. j < len인 동안 반복한다,
    1. DeletePropertyOrThrow(obj, ! ToString(𝔽(j)))를 수행한다.
    2. jj + 1로 설정한다.
  11. obj를 반환한다.
Note 1

존재하지 않는 속성 값은 항상 undefined 속성 값보다 크게 비교되고, undefined는 항상 다른 어떤 값보다도 크게 비교되므로(CompareArrayElements를 보라), undefined 속성 값은 항상 결과의 끝으로 정렬되고, 그 뒤에 존재하지 않는 속성 값이 온다.

Note 2

단계 56ToString 추상 연산에 의해 수행되는 메서드 호출은 sortCompare일관된 비교자로 동작하지 않게 만들 가능성이 있다.

Note 3

이 메서드는 의도적으로 제네릭이다; 이 메서드는 자신의 this 값이 Array일 것을 요구하지 않는다. 따라서 메서드로 사용하기 위해 다른 종류의 객체로 이전될 수 있다.

23.1.3.30.1 SortIndexedProperties ( obj, len, sortCompare, holes )

The abstract operation SortIndexedProperties takes arguments obj (an Object), len (a non-negative integer), sortCompare (an Abstract Closure with two parameters), and holes (skip-holes or read-through-holes) and returns either a normal completion containing a List of ECMAScript language values or a throw completion. It performs the following steps when called:

  1. items를 새로운 빈 List라고 하자.
  2. k를 0이라고 하자.
  3. k < len인 동안 반복한다,
    1. propertyKey를 ! ToString(𝔽(k))라고 하자.
    2. holesskip-holes이면,
      1. kRead를 ? HasProperty(obj, propertyKey)라고 하자.
    3. 그렇지 않으면,
      1. Assert: holesread-through-holes이다.
      2. kReadtrue라고 하자.
    4. kReadtrue이면,
      1. kValue를 ? Get(obj, propertyKey)라고 하자.
      2. kValueitems에 추가한다.
    5. kk + 1로 설정한다.
  4. 구현 정의 순서의 sortCompare 호출을 사용하여 items를 정렬한다. 그러한 호출 중 하나라도 abrupt completion을 반환하면, sortCompare에 대한 추가 호출을 수행하기 전에 중단하고 그 Completion Record를 반환한다.
  5. items를 반환한다.

정렬 순서는 위 알고리즘의 단계 4가 완료된 후 items의 순서이다. sortCompareitems의 요소들에 대해 일관된 비교자가 아니면 정렬 순서구현 정의이다. SortIndexedProperties가 Array.prototype.sort 또는 Array.prototype.toSorted에 의해 호출될 때, comparatorundefined이고 sortCompare의 인자로 전달된 특정 값에 대한 모든 ToString 적용이 같은 결과를 생성하지 않는 경우에도 정렬 순서구현 정의이다.

정렬 순서구현 정의로 지정되지 않는 한, 다음 조건을 모두 만족해야 한다:

  • itemCount보다 작은 음이 아닌 정수들의 어떤 수학적 순열 π가 존재하여, itemCount보다 작은 모든 음이 아닌 정수 j에 대해 요소 old[j]new[π(j)]와 정확히 같아야 한다.
  • 그러면 itemCount보다 각각 작은 모든 음이 아닌 정수 jk에 대해, (sortCompare(old[j], old[k])) < 0이면 π(j) < π(k)이다.
  • 그리고 j < k < itemCount인 모든 음이 아닌 정수 jk에 대해, (sortCompare(old[j], old[k])) = 0이면 π(j) < π(k)이다; 즉 정렬은 안정적이다.

여기서 표기 old[j]는 단계 4가 실행되기 전의 items[j]를 가리키기 위해 사용되고, 표기 new[j]는 단계 4가 실행된 후의 items[j]를 가리키기 위해 사용된다.

Abstract Closure 또는 함수 comparator는 값들의 집합 values에 대해 다음 요구사항이 그 집합 values 안의 모든 값 a, b, 및 c(같은 값일 수도 있음)에 대해 충족되면 일관된 비교자이다: 표기 a <C b(comparator(a, b)) < 0을 의미하고; a =C b(comparator(a, b)) = 0을 의미하며; a >C b(comparator(a, b)) > 0을 의미한다.

  • comparator(a, b)를 호출하면 특정 값 쌍 ab를 두 인자로 받았을 때 항상 같은 값 v를 반환한다. 또한 v는 Number이고, vNaN이 아니다. 이는 주어진 ab 쌍에 대해 a <C b, a =C b, a >C b 중 정확히 하나가 참임을 함의한다.
  • comparator(a, b)를 호출해도 objobj의 프로토타입 체인상의 어떤 객체도 변경하지 않는다.
  • a =C a (반사성)
  • a =C b이면, b =C a (대칭성)
  • a =C b이고 b =C c이면, a =C c (=C의 추이성)
  • a <C b이고 b <C c이면, a <C c (<C의 추이성)
  • a >C b이고 b >C c이면, a >C c (>C의 추이성)
Note

위 조건들은 comparator가 집합 values를 동치류로 나누고 그 동치류들이 전순서화됨을 보장하기 위한 필요충분조건이다.

23.1.3.30.2 CompareArrayElements ( x, y, comparator )

The abstract operation CompareArrayElements takes arguments x (an ECMAScript language value), y (an ECMAScript language value), and comparator (a function object or undefined) and returns either a normal completion containing a Number or an abrupt completion. It performs the following steps when called:

  1. xundefined이고 yundefined이면, +0𝔽을 반환한다.
  2. xundefined이면, 1𝔽을 반환한다.
  3. yundefined이면, -1𝔽을 반환한다.
  4. comparatorundefined가 아니면,
    1. result를 ? ToNumber(? Call(comparator, undefined, « x, y »))라고 하자.
    2. resultNaN이면, +0𝔽을 반환한다.
    3. result를 반환한다.
  5. xString을 ? ToString(x)라고 하자.
  6. yString을 ? ToString(y)라고 하자.
  7. xSmaller를 ! IsLessThan(xString, yString, true)라고 하자.
  8. xSmallertrue이면, -1𝔽을 반환한다.
  9. ySmaller를 ! IsLessThan(yString, xString, true)라고 하자.
  10. ySmallertrue이면, 1𝔽을 반환한다.
  11. +0𝔽을 반환한다.

23.1.3.31 Array.prototype.splice ( start, deleteCount, ...items )

Note 1

이 메서드는 정수 인덱스 start에서 시작하는 배열의 deleteCount개 요소를 삭제하고, 이를 items의 요소들로 대체한다. 삭제된 요소들을 포함하는 Array를 반환한다(있는 경우).

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. obj를 ? ToObject(this value)라고 하자.
  2. len을 ? LengthOfArrayLike(obj)라고 하자.
  3. relativeStart를 ? ToIntegerOrInfinity(start)라고 하자.
  4. relativeStart = -∞이면, actualStart를 0이라고 하자.
  5. 그렇지 않고 relativeStart < 0이면, actualStartmax(len + relativeStart, 0)이라고 하자.
  6. 그렇지 않으면, actualStartmin(relativeStart, len)이라고 하자.
  7. itemCountitems의 요소 개수라고 하자.
  8. start가 존재하지 않으면,
    1. actualDeleteCount를 0이라고 하자.
  9. 그렇지 않고 deleteCount가 존재하지 않으면,
    1. actualDeleteCountlen - actualStart라고 하자.
  10. 그렇지 않으면,
    1. dc를 ? ToIntegerOrInfinity(deleteCount)라고 하자.
    2. actualDeleteCountdc를 0과 len - actualStart 사이로 클램프한 결과라고 하자.
  11. len + itemCount - actualDeleteCount > 253 - 1이면, TypeError 예외를 던진다.
  12. deletedArray를 ? ArraySpeciesCreate(obj, actualDeleteCount)라고 하자.
  13. k를 0이라고 하자.
  14. k < actualDeleteCount인 동안 반복한다,
    1. from을 ! ToString(𝔽(actualStart + k))라고 하자.
    2. HasProperty(obj, from)가 true이면,
      1. fromValue를 ? Get(obj, from)라고 하자.
      2. CreateDataPropertyOrThrow(deletedArray, ! ToString(𝔽(k)), fromValue)를 수행한다.
    3. kk + 1로 설정한다.
  15. Set(deletedArray, "length", 𝔽(actualDeleteCount), true)를 수행한다.
  16. itemCount < actualDeleteCount이면,
    1. kactualStart로 설정한다.
    2. k < (len - actualDeleteCount)인 동안 반복한다,
      1. from을 ! ToString(𝔽(k + actualDeleteCount))라고 하자.
      2. to를 ! ToString(𝔽(k + itemCount))라고 하자.
      3. HasProperty(obj, from)가 true이면,
        1. fromValue를 ? Get(obj, from)라고 하자.
        2. Set(obj, to, fromValue, true)를 수행한다.
      4. 그렇지 않으면,
        1. DeletePropertyOrThrow(obj, to)를 수행한다.
      5. kk + 1로 설정한다.
    3. klen으로 설정한다.
    4. k > (len - actualDeleteCount + itemCount)인 동안 반복한다,
      1. DeletePropertyOrThrow(obj, ! ToString(𝔽(k - 1)))를 수행한다.
      2. kk - 1로 설정한다.
  17. 그렇지 않고 itemCount > actualDeleteCount이면,
    1. k를 (len - actualDeleteCount)로 설정한다.
    2. k > actualStart인 동안 반복한다,
      1. from을 ! ToString(𝔽(k + actualDeleteCount - 1))라고 하자.
      2. to를 ! ToString(𝔽(k + itemCount - 1))라고 하자.
      3. HasProperty(obj, from)가 true이면,
        1. fromValue를 ? Get(obj, from)라고 하자.
        2. Set(obj, to, fromValue, true)를 수행한다.
      4. 그렇지 않으면,
        1. DeletePropertyOrThrow(obj, to)를 수행한다.
      5. kk - 1로 설정한다.
  18. kactualStart로 설정한다.
  19. items의 각 요소 item에 대해, 다음을 수행한다.
    1. Set(obj, ! ToString(𝔽(k)), item, true)를 수행한다.
    2. kk + 1로 설정한다.
  20. Set(obj, "length", 𝔽(len - actualDeleteCount + itemCount), true)를 수행한다.
  21. deletedArray를 반환한다.
Note 2

단계 1520에서 "length" 속성을 명시적으로 설정하는 것은 객체들이 내장 Array가 아닐 때도 길이가 올바르도록 보장하기 위한 것이다.

Note 3

이 메서드는 의도적으로 제네릭이다; 이 메서드는 자신의 this 값이 Array일 것을 요구하지 않는다. 따라서 메서드로 사용하기 위해 다른 종류의 객체로 이전될 수 있다.

23.1.3.32 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] )

ECMA-402 국제화 API를 포함하는 ECMAScript 구현은 ECMA-402 명세에 지정된 대로 이 메서드를 구현해야 한다. ECMAScript 구현이 ECMA-402 API를 포함하지 않는 경우 이 메서드에 대한 다음 명세가 사용된다.

Note 1

ECMA-402의 초판은 이 메서드에 대한 대체 명세를 포함하지 않았다.

이 메서드의 선택적 매개변수의 의미는 ECMA-402 명세에 정의되어 있다; ECMA-402 지원을 포함하지 않는 구현은 그 매개변수 위치를 다른 어떤 용도로도 사용해서는 안 된다.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. array를 ? ToObject(this value)라고 하자.
  2. len을 ? LengthOfArrayLike(array)라고 하자.
  3. separator호스트 환경의 현재 로캘에 적절한 구현 정의 list-separator String 값(예: ", ")이라고 하자.
  4. result를 빈 String이라고 하자.
  5. k를 0이라고 하자.
  6. k < len인 동안 반복한다,
    1. k > 0이면, resultresultseparator의 문자열 연결로 설정한다.
    2. element를 ? Get(array, ! ToString(𝔽(k)))라고 하자.
    3. elementundefined도 아니고 null도 아니면,
      1. elementStr을 ? ToString(? Invoke(element, "toLocaleString"))라고 하자.
      2. resultresultelementStr의 문자열 연결로 설정한다.
    4. kk + 1로 설정한다.
  7. result를 반환한다.
Note 2

이 메서드는 배열의 요소들을 그들의 toLocaleString 메서드를 사용해 String으로 변환한 뒤, 구현 정의 로캘 민감 구분자 String의 출현으로 구분하여 이 String들을 연결한다. 이 메서드는 toString과 유사하지만, 호스트 환경의 현재 로캘 관례에 대응하는 로캘 민감 결과를 산출하도록 의도되어 있다는 점이 다르다.

Note 3

이 메서드는 의도적으로 제네릭이다; 이 메서드는 자신의 this 값이 Array일 것을 요구하지 않는다. 따라서 메서드로 사용하기 위해 다른 종류의 객체로 이전될 수 있다.

23.1.3.33 Array.prototype.toReversed ( )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. obj를 ? ToObject(this value)라고 하자.
  2. len을 ? LengthOfArrayLike(obj)라고 하자.
  3. array를 ? ArrayCreate(len)라고 하자.
  4. k를 0이라고 하자.
  5. k < len인 동안 반복한다,
    1. from을 ! ToString(𝔽(len - k - 1))라고 하자.
    2. propertyKey를 ! ToString(𝔽(k))라고 하자.
    3. fromValue를 ? Get(obj, from)라고 하자.
    4. CreateDataPropertyOrThrow(array, propertyKey, fromValue)를 수행한다.
    5. kk + 1로 설정한다.
  6. array를 반환한다.

23.1.3.34 Array.prototype.toSorted ( comparator )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. comparatorundefined가 아니고 IsCallable(comparator)가 false이면, TypeError 예외를 던진다.
  2. obj를 ? ToObject(this value)라고 하자.
  3. len을 ? LengthOfArrayLike(obj)라고 하자.
  4. array를 ? ArrayCreate(len)라고 하자.
  5. sortComparecomparator를 캡처하고 호출될 때 다음 단계를 수행하는, 매개변수 (x, y)를 가진 새로운 Abstract Closure라고 하자:
    1. CompareArrayElements(x, y, comparator)를 반환한다.
  6. sortedList를 ? SortIndexedProperties(obj, len, sortCompare, read-through-holes)라고 하자.
  7. j를 0이라고 하자.
  8. j < len인 동안 반복한다,
    1. CreateDataPropertyOrThrow(array, ! ToString(𝔽(j)), sortedList[j])를 수행한다.
    2. jj + 1로 설정한다.
  9. array를 반환한다.

23.1.3.35 Array.prototype.toSpliced ( start, skipCount, ...items )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. obj를 ? ToObject(this value)라고 하자.
  2. len을 ? LengthOfArrayLike(obj)라고 하자.
  3. relativeStart를 ? ToIntegerOrInfinity(start)라고 하자.
  4. relativeStart = -∞이면, actualStart를 0이라고 하자.
  5. 그렇지 않고 relativeStart < 0이면, actualStartmax(len + relativeStart, 0)이라고 하자.
  6. 그렇지 않으면, actualStartmin(relativeStart, len)이라고 하자.
  7. insertCountitems의 요소 개수라고 하자.
  8. start가 존재하지 않으면,
    1. actualSkipCount를 0이라고 하자.
  9. 그렇지 않고 skipCount가 존재하지 않으면,
    1. actualSkipCountlen - actualStart라고 하자.
  10. 그렇지 않으면,
    1. sc를 ? ToIntegerOrInfinity(skipCount)라고 하자.
    2. actualSkipCountsc를 0과 len - actualStart 사이로 클램프한 결과라고 하자.
  11. newLenlen + insertCount - actualSkipCount라고 하자.
  12. newLen > 253 - 1이면, TypeError 예외를 던진다.
  13. newArray를 ? ArrayCreate(newLen)라고 하자.
  14. writeIndex를 0이라고 하자.
  15. readIndexactualStart + actualSkipCount라고 하자.
  16. writeIndex < actualStart인 동안 반복한다,
    1. propertyKey를 ! ToString(𝔽(writeIndex))라고 하자.
    2. iValue를 ? Get(obj, propertyKey)라고 하자.
    3. CreateDataPropertyOrThrow(newArray, propertyKey, iValue)를 수행한다.
    4. writeIndexwriteIndex + 1로 설정한다.
  17. items의 각 요소 item에 대해, 다음을 수행한다.
    1. propertyKey를 ! ToString(𝔽(writeIndex))라고 하자.
    2. CreateDataPropertyOrThrow(newArray, propertyKey, item)를 수행한다.
    3. writeIndexwriteIndex + 1로 설정한다.
  18. writeIndex < newLen인 동안 반복한다,
    1. propertyKey를 ! ToString(𝔽(writeIndex))라고 하자.
    2. from을 ! ToString(𝔽(readIndex))라고 하자.
    3. fromValue를 ? Get(obj, from)라고 하자.
    4. CreateDataPropertyOrThrow(newArray, propertyKey, fromValue)를 수행한다.
    5. writeIndexwriteIndex + 1로 설정한다.
    6. readIndexreadIndex + 1로 설정한다.
  19. newArray를 반환한다.

23.1.3.36 Array.prototype.toString ( )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. array를 ? ToObject(this value)라고 하자.
  2. func를 ? Get(array, "join")라고 하자.
  3. IsCallable(func)가 false이면, func를 내재 함수 %Object.prototype.toString%으로 설정한다.
  4. Call(func, array)를 반환한다.
Note

이 메서드는 의도적으로 제네릭이다; 이 메서드는 자신의 this 값이 Array일 것을 요구하지 않는다. 따라서 메서드로 사용하기 위해 다른 종류의 객체로 이전될 수 있다.

23.1.3.37 Array.prototype.unshift ( ...items )

이 메서드는 인자들을 배열의 시작 부분에 앞에 붙이며, 배열 안에서 그 순서는 인자 목록에 나타난 순서와 같다.

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

  1. obj를 ? ToObject(this value)라고 하자.
  2. len을 ? LengthOfArrayLike(obj)라고 하자.
  3. argCountitems의 요소 개수라고 하자.
  4. argCount > 0이면,
    1. len + argCount > 253 - 1이면, TypeError 예외를 던진다.
    2. klen이라고 하자.
    3. k > 0인 동안 반복한다,
      1. from을 ! ToString(𝔽(k - 1))라고 하자.
      2. to를 ! ToString(𝔽(k + argCount - 1))라고 하자.
      3. fromPresent를 ? HasProperty(obj, from)라고 하자.
      4. fromPresenttrue이면,
        1. fromValue를 ? Get(obj, from)라고 하자.
        2. Set(obj, to, fromValue, true)를 수행한다.
      5. 그렇지 않으면,
        1. Assert: fromPresentfalse이다.
        2. DeletePropertyOrThrow(obj, to)를 수행한다.
      6. kk - 1로 설정한다.
    4. j+0𝔽이라고 하자.
    5. items의 각 요소 item에 대해, 다음을 수행한다.
      1. Set(obj, ! ToString(j), item, true)를 수행한다.
      2. jj + 1𝔽로 설정한다.
  5. Set(obj, "length", 𝔽(len + argCount), true)를 수행한다.
  6. 𝔽(len + argCount)를 반환한다.

이 메서드의 "length" 속성은 1𝔽이다.

Note

이 메서드는 의도적으로 제네릭이다; 이 메서드는 자신의 this 값이 Array일 것을 요구하지 않는다. 따라서 메서드로 사용하기 위해 다른 종류의 객체로 이전될 수 있다.

23.1.3.38 Array.prototype.values ( )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. obj를 ? ToObject(this value)라고 하자.
  2. CreateArrayIterator(obj, value)를 반환한다.

23.1.3.39 Array.prototype.with ( index, value )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. obj를 ? ToObject(this value)라고 하자.
  2. len을 ? LengthOfArrayLike(obj)라고 하자.
  3. relativeIndex를 ? ToIntegerOrInfinity(index)라고 하자.
  4. relativeIndex ≥ 0이면, actualIndexrelativeIndex라고 하자.
  5. 그렇지 않으면, actualIndexlen + relativeIndex라고 하자.
  6. actualIndexlen이거나 actualIndex < 0이면, RangeError 예외를 던진다.
  7. array를 ? ArrayCreate(len)라고 하자.
  8. k를 0이라고 하자.
  9. k < len인 동안 반복한다,
    1. propertyKey를 ! ToString(𝔽(k))라고 하자.
    2. k = actualIndex이면 fromValuevalue라고 하자.
    3. 그렇지 않으면, fromValue를 ? Get(obj, propertyKey)라고 하자.
    4. CreateDataPropertyOrThrow(array, propertyKey, fromValue)를 수행한다.
    5. kk + 1로 설정한다.
  10. array를 반환한다.

23.1.3.40 Array.prototype [ %Symbol.iterator% ] ( )

%Symbol.iterator% 속성의 초기값은 23.1.3.38에 정의된 %Array.prototype.values%이다.

23.1.3.41 Array.prototype [ %Symbol.unscopables% ]

%Symbol.unscopables% 데이터 속성의 초기값은 다음 단계들로 생성된 객체이다:

  1. unscopableListOrdinaryObjectCreate(null)라고 하자.
  2. CreateDataPropertyOrThrow(unscopableList, "at", true)를 수행한다.
  3. CreateDataPropertyOrThrow(unscopableList, "copyWithin", true)를 수행한다.
  4. CreateDataPropertyOrThrow(unscopableList, "entries", true)를 수행한다.
  5. CreateDataPropertyOrThrow(unscopableList, "fill", true)를 수행한다.
  6. CreateDataPropertyOrThrow(unscopableList, "find", true)를 수행한다.
  7. CreateDataPropertyOrThrow(unscopableList, "findIndex", true)를 수행한다.
  8. CreateDataPropertyOrThrow(unscopableList, "findLast", true)를 수행한다.
  9. CreateDataPropertyOrThrow(unscopableList, "findLastIndex", true)를 수행한다.
  10. CreateDataPropertyOrThrow(unscopableList, "flat", true)를 수행한다.
  11. CreateDataPropertyOrThrow(unscopableList, "flatMap", true)를 수행한다.
  12. CreateDataPropertyOrThrow(unscopableList, "includes", true)를 수행한다.
  13. CreateDataPropertyOrThrow(unscopableList, "keys", true)를 수행한다.
  14. CreateDataPropertyOrThrow(unscopableList, "toReversed", true)를 수행한다.
  15. CreateDataPropertyOrThrow(unscopableList, "toSorted", true)를 수행한다.
  16. CreateDataPropertyOrThrow(unscopableList, "toSpliced", true)를 수행한다.
  17. CreateDataPropertyOrThrow(unscopableList, "values", true)를 수행한다.
  18. unscopableList를 반환한다.

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

Note

이 객체의 자기 자신의 속성 이름들은 ECMAScript 2015 명세 이전에는 Array.prototype의 표준 속성으로 포함되지 않았던 속성 이름들이다. 이러한 이름들은, 이 이름들 중 하나를 외부 스코프의 바인딩으로 사용하고 그 바인딩이 바인딩 객체가 Array인 with 문에 의해 가려질 수 있는 기존 코드의 동작을 보존하기 위해, with 문 바인딩 목적상 무시된다.

"with"unscopableList에 포함되지 않는 이유는 이미 reserved word이기 때문이다.

23.1.4 Array 인스턴스의 속성

Array 인스턴스는 Array 특수 객체이며 그러한 객체에 대해 지정된 내부 메서드를 가진다. Array 인스턴스는 Array 프로토타입 객체로부터 속성을 상속한다.

Array 인스턴스는 "length" 속성과, 배열 인덱스 이름을 가진 열거 가능한 속성들의 집합을 가진다.

23.1.4.1 length

Array 인스턴스의 "length" 속성은 그 값이 배열 인덱스인 이름을 가진 모든 configurable 자기 자신의 속성 이름보다 항상 수치적으로 큰 데이터 속성이다.

"length" 속성은 처음에 { [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false } 속성 특성을 가진다.

Note

"length" 속성의 값을 줄이면, 배열 인덱스가 이전 길이 값과 새 길이 값 사이에 있는 자기 자신의 배열 요소가 삭제되는 부수 효과가 있다. 그러나 non-configurable 속성은 삭제될 수 없다. Array의 "length" 속성을 배열의 기존 non-configurable array-indexed 속성 중 가장 큰 수치 자기 자신의 속성 이름보다 작거나 같은 수치 값으로 설정하려고 하면, 길이는 그 non-configurable 수치 자기 자신의 속성 이름보다 1 큰 수치 값으로 설정된다. 10.4.2.1를 보라.

23.1.5 Array Iterator 객체

Array Iterator는 어떤 특정 Array 인스턴스 객체에 대한 특정 반복을 나타내는 객체이다. Array Iterator 객체에는 이름 있는 생성자가 없다. 대신, Array Iterator 객체는 Array 인스턴스 객체의 특정 메서드를 호출하여 생성된다.

23.1.5.1 CreateArrayIterator ( array, kind )

The abstract operation CreateArrayIterator takes arguments array (an Object) and kind (key+value, key, or value) and returns an Object. 이 연산은 그러한 반복자를 반환하는 Array 메서드를 위한 반복자 객체를 생성하는 데 사용된다. It performs the following steps when called:

  1. iteratorOrdinaryObjectCreate(%ArrayIteratorPrototype%, « [[IteratedArrayLike]], [[ArrayLikeNextIndex]], [[ArrayLikeIterationKind]] »)라고 하자.
  2. iterator.[[IteratedArrayLike]]array로 설정한다.
  3. iterator.[[ArrayLikeNextIndex]]를 0으로 설정한다.
  4. iterator.[[ArrayLikeIterationKind]]kind로 설정한다.
  5. iterator를 반환한다.

23.1.5.2 %ArrayIteratorPrototype% 객체

%ArrayIteratorPrototype% 객체는:

  • 모든 Array Iterator 객체가 상속하는 속성들을 가진다.
  • 보통 객체이다.
  • 값이 %Iterator.prototype%[[Prototype]] 내부 슬롯을 가진다.
  • 다음 속성들을 가진다:

23.1.5.2.1 %ArrayIteratorPrototype%.next ( )

  1. iteratorObjthis 값이라고 하자.
  2. iteratorObj가 Object가 아니면, TypeError 예외를 던진다.
  3. iteratorObjArray Iterator Instance의 모든 내부 슬롯(23.1.5.3)을 가지지 않으면, TypeError 예외를 던진다.
  4. arrayiteratorObj.[[IteratedArrayLike]]라고 하자.
  5. arrayundefined이면, CreateIteratorResultObject(undefined, true)를 반환한다.
  6. indexiteratorObj.[[ArrayLikeNextIndex]]라고 하자.
  7. kinditeratorObj.[[ArrayLikeIterationKind]]라고 하자.
  8. array[[TypedArrayName]] 내부 슬롯을 가지면,
    1. taRecordMakeTypedArrayWithBufferWitnessRecord(array, seq-cst)라고 하자.
    2. IsTypedArrayOutOfBounds(taRecord)가 true이면, TypeError 예외를 던진다.
    3. lenTypedArrayLength(taRecord)라고 하자.
  9. 그렇지 않으면,
    1. len을 ? LengthOfArrayLike(array)라고 하자.
  10. indexlen이면,
    1. iteratorObj.[[IteratedArrayLike]]undefined로 설정한다.
    2. CreateIteratorResultObject(undefined, true)를 반환한다.
  11. iteratorObj.[[ArrayLikeNextIndex]]index + 1로 설정한다.
  12. indexNumber𝔽(index)라고 하자.
  13. kindkey이면,
    1. resultindexNumber라고 하자.
  14. 그렇지 않으면,
    1. elementKey를 ! ToString(indexNumber)라고 하자.
    2. elementValue를 ? Get(array, elementKey)라고 하자.
    3. kindvalue이면,
      1. resultelementValue라고 하자.
    4. 그렇지 않으면,
      1. Assert: kindkey+value이다.
      2. resultCreateArrayFromListindexNumber, elementValue »)라고 하자.
  15. CreateIteratorResultObject(result, false)를 반환한다.

23.1.5.2.2 %ArrayIteratorPrototype% [ %Symbol.toStringTag% ]

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

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

23.1.5.3 Array Iterator 인스턴스의 속성

Array Iterator 인스턴스는 %ArrayIteratorPrototype% 내재 객체로부터 속성을 상속하는 보통 객체이다. Array Iterator 인스턴스는 처음에 Table 69에 나열된 내부 슬롯을 가지고 생성된다.

Table 69: Array Iterator 인스턴스의 내부 슬롯
내부 슬롯 타입 설명
[[IteratedArrayLike]] Object 또는 undefined 반복되고 있는 배열 유사 객체.
[[ArrayLikeNextIndex]] 음이 아닌 정수 이 반복자가 다음에 검사할 요소의 정수 인덱스.
[[ArrayLikeIterationKind]] key+value, key, 또는 value 반복의 각 요소에 대해 무엇이 반환되는지 식별하는 값.

23.2 TypedArray 객체

TypedArray는 기반 바이너리 데이터 버퍼(25.1)의 배열 유사 뷰를 제공한다. TypedArray 요소 타입TypedArray 인스턴스의 모든 요소가 가지는 기반 바이너리 스칼라 데이터 타입이다. 지원되는 각 요소 타입마다 Table 70에 나열된 서로 다른 TypedArray 생성자가 있다. Table 70의 각 생성자는 대응하는 서로 다른 프로토타입 객체를 가진다.

Table 70: TypedArray 생성자
생성자 이름 및 내재 객체 요소 타입 요소 크기 변환 연산 설명
Int8Array
%Int8Array%
int8 1 ToInt8 8비트 2의 보수 부호 있는 정수
Uint8Array
%Uint8Array%
uint8 1 ToUint8 8비트 부호 없는 정수
Uint8ClampedArray
%Uint8ClampedArray%
uint8clamped 1 ToUint8Clamp 8비트 부호 없는 정수(클램프 변환)
Int16Array
%Int16Array%
int16 2 ToInt16 16비트 2의 보수 부호 있는 정수
Uint16Array
%Uint16Array%
uint16 2 ToUint16 16비트 부호 없는 정수
Int32Array
%Int32Array%
int32 4 ToInt32 32비트 2의 보수 부호 있는 정수
Uint32Array
%Uint32Array%
uint32 4 ToUint32 32비트 부호 없는 정수
BigInt64Array
%BigInt64Array%
bigint64 8 ToBigInt64 64비트 2의 보수 부호 있는 정수
BigUint64Array
%BigUint64Array%
biguint64 8 ToBigUint64 64비트 부호 없는 정수
Float16Array
%Float16Array%
float16 2 16비트 IEEE 부동 소수점
Float32Array
%Float32Array%
float32 4 32비트 IEEE 부동 소수점
Float64Array
%Float64Array%
float64 8 64비트 IEEE 부동 소수점

아래 정의들에서 TypedArray에 대한 참조는 위 표의 적절한 생성자 이름으로 대체되어야 한다.

23.2.1 %TypedArray% 내재 객체

%TypedArray% 내재 객체는:

  • 모든 TypedArray 생성자 객체가 상속하는 생성자 함수 객체이다.
  • 대응하는 프로토타입 객체와 함께, 모든 TypedArray 생성자와 그 인스턴스가 상속하는 공통 속성을 제공한다.
  • 전역 이름을 가지지 않으며 전역 객체의 속성으로 나타나지 않는다.
  • 여러 TypedArray 생성자의 추상 슈퍼클래스처럼 동작한다.
  • 추상 클래스 생성자이므로 호출되면 오류를 던진다. TypedArray 생성자들은 이에 대해 super 호출을 수행하지 않는다.

23.2.1.1 %TypedArray% ( )

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

  1. TypeError 예외를 던진다.

이 함수의 "length" 속성은 +0𝔽이다.

23.2.2 %TypedArray% 내재 객체의 속성

%TypedArray% 내재 객체는:

  • 값이 %Function.prototype%[[Prototype]] 내부 슬롯을 가진다.
  • 값이 "TypedArray""name" 속성을 가진다.
  • 다음 속성들을 가진다:

23.2.2.1 %TypedArray%.from ( source [ , mapper [ , thisArg ] ] )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. constructorthis 값이라고 하자.
  2. IsConstructor(constructor)가 false이면, TypeError 예외를 던진다.
  3. mapperundefined이면,
    1. mappingfalse라고 하자.
  4. 그렇지 않으면,
    1. IsCallable(mapper)가 false이면, TypeError 예외를 던진다.
    2. mappingtrue라고 하자.
  5. usingIterator를 ? GetMethod(source, %Symbol.iterator%)라고 하자.
  6. usingIteratorundefined가 아니면,
    1. values를 ? IteratorToList(? GetIteratorFromMethod(source, usingIterator))라고 하자.
    2. lenvalues의 요소 개수라고 하자.
    3. targetObj를 ? TypedArrayCreateFromConstructor(constructor, « 𝔽(len) »)라고 하자.
    4. k를 0이라고 하자.
    5. k < len인 동안 반복한다,
      1. propertyKey를 ! ToString(𝔽(k))라고 하자.
      2. kValuevalues의 첫 번째 요소라고 하자.
      3. values에서 첫 번째 요소를 제거한다.
      4. mappingtrue이면,
        1. mappedValue를 ? Call(mapper, thisArg, « kValue, 𝔽(k) »)라고 하자.
      5. 그렇지 않으면,
        1. mappedValuekValue라고 하자.
      6. Set(targetObj, propertyKey, mappedValue, true)를 수행한다.
      7. kk + 1로 설정한다.
    6. Assert: values는 이제 빈 List이다.
    7. targetObj를 반환한다.
  7. NOTE: source는 반복 가능 객체가 아니므로, 이미 배열 유사 객체라고 가정한다.
  8. arrayLike를 ! ToObject(source)라고 하자.
  9. len을 ? LengthOfArrayLike(arrayLike)라고 하자.
  10. targetObj를 ? TypedArrayCreateFromConstructor(constructor, « 𝔽(len) »)라고 하자.
  11. k를 0이라고 하자.
  12. k < len인 동안 반복한다,
    1. propertyKey를 ! ToString(𝔽(k))라고 하자.
    2. kValue를 ? Get(arrayLike, propertyKey)라고 하자.
    3. mappingtrue이면,
      1. mappedValue를 ? Call(mapper, thisArg, « kValue, 𝔽(k) »)라고 하자.
    4. 그렇지 않으면,
      1. mappedValuekValue라고 하자.
    5. Set(targetObj, propertyKey, mappedValue, true)를 수행한다.
    6. kk + 1로 설정한다.
  13. targetObj를 반환한다.

23.2.2.2 %TypedArray%.of ( ...items )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. lenitems의 요소 개수라고 하자.
  2. constructorthis 값이라고 하자.
  3. IsConstructor(constructor)가 false이면, TypeError 예외를 던진다.
  4. newObj를 ? TypedArrayCreateFromConstructor(constructor, « 𝔽(len) »)라고 하자.
  5. k를 0이라고 하자.
  6. k < len인 동안 반복한다,
    1. kValueitems[k]라고 하자.
    2. propertyKey를 ! ToString(𝔽(k))라고 하자.
    3. Set(newObj, propertyKey, kValue, true)를 수행한다.
    4. kk + 1로 설정한다.
  7. newObj를 반환한다.

23.2.2.3 %TypedArray%.prototype

%TypedArray%.prototype의 초기값은 %TypedArray% 프로토타입 객체이다.

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

23.2.2.4 get %TypedArray% [ %Symbol.species% ]

%TypedArray%[%Symbol.species%]는 set 접근자 함수가 undefined인 접근자 속성이다. 그 get 접근자 함수는 호출될 때 다음 단계를 수행한다:

  1. this 값을 반환한다.

이 함수의 "name" 속성의 값은 "get [Symbol.species]"이다.

Note

%TypedArray.prototype% 메서드는 보통 자신의 this 값의 생성자를 사용해 파생 객체를 생성한다. 그러나 서브클래스 생성자는 자신의 %Symbol.species% 속성을 재정의하여 그 기본 동작을 재정의할 수 있다.

23.2.3 %TypedArray% 프로토타입 객체의 속성

%TypedArray% 프로토타입 객체는:

  • 값이 %Object.prototype%[[Prototype]] 내부 슬롯을 가진다.
  • %TypedArray.prototype%이다.
  • 보통 객체이다.
  • [[ViewedArrayBuffer]]TypedArray 인스턴스 객체에 특유한 다른 어떤 내부 슬롯도 가지지 않는다.

23.2.3.1 %TypedArray%.prototype.at ( index )

  1. objthis 값이라고 하자.
  2. taRecord를 ? ValidateTypedArray(obj, seq-cst)라고 하자.
  3. lenTypedArrayLength(taRecord)라고 하자.
  4. relativeIndex를 ? ToIntegerOrInfinity(index)라고 하자.
  5. relativeIndex ≥ 0이면,
    1. krelativeIndex라고 하자.
  6. 그렇지 않으면,
    1. klen + relativeIndex라고 하자.
  7. k < 0이거나 klen이면, undefined를 반환한다.
  8. Get(obj, ! ToString(𝔽(k)))를 반환한다.

23.2.3.2 get %TypedArray%.prototype.buffer

%TypedArray%.prototype.buffer는 set 접근자 함수가 undefined인 접근자 속성이다. 그 get 접근자 함수는 호출될 때 다음 단계를 수행한다:

  1. objthis 값이라고 하자.
  2. RequireInternalSlot(obj, [[TypedArrayName]])를 수행한다.
  3. Assert: obj[[ViewedArrayBuffer]] 내부 슬롯을 가진다.
  4. bufferobj.[[ViewedArrayBuffer]]라고 하자.
  5. buffer를 반환한다.

23.2.3.3 get %TypedArray%.prototype.byteLength

%TypedArray%.prototype.byteLength는 set 접근자 함수가 undefined인 접근자 속성이다. 그 get 접근자 함수는 호출될 때 다음 단계를 수행한다:

  1. objthis 값이라고 하자.
  2. RequireInternalSlot(obj, [[TypedArrayName]])를 수행한다.
  3. Assert: obj[[ViewedArrayBuffer]] 내부 슬롯을 가진다.
  4. taRecordMakeTypedArrayWithBufferWitnessRecord(obj, seq-cst)라고 하자.
  5. IsTypedArrayOutOfBounds(taRecord)가 true이면, +0𝔽을 반환한다.
  6. sizeTypedArrayByteLength(taRecord)라고 하자.
  7. 𝔽(size)를 반환한다.

23.2.3.4 get %TypedArray%.prototype.byteOffset

%TypedArray%.prototype.byteOffset는 set 접근자 함수가 undefined인 접근자 속성이다. 그 get 접근자 함수는 호출될 때 다음 단계를 수행한다:

  1. objthis 값이라고 하자.
  2. RequireInternalSlot(obj, [[TypedArrayName]])를 수행한다.
  3. Assert: obj[[ViewedArrayBuffer]] 내부 슬롯을 가진다.
  4. taRecordMakeTypedArrayWithBufferWitnessRecord(obj, seq-cst)라고 하자.
  5. IsTypedArrayOutOfBounds(taRecord)가 true이면, +0𝔽을 반환한다.
  6. offsetobj.[[ByteOffset]]이라고 하자.
  7. 𝔽(offset)을 반환한다.

23.2.3.5 %TypedArray%.prototype.constructor

%TypedArray%.prototype.constructor의 초기값은 %TypedArray%이다.

23.2.3.6 %TypedArray%.prototype.copyWithin ( target, start [ , end ] )

이 메서드의 인자 해석과 사용은 23.1.3.4에 정의된 Array.prototype.copyWithin의 경우와 같다.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. objthis 값이라고 하자.
  2. taRecord를 ? ValidateTypedArray(obj, seq-cst)라고 하자.
  3. lenTypedArrayLength(taRecord)라고 하자.
  4. relativeTarget을 ? ToIntegerOrInfinity(target)이라고 하자.
  5. relativeTarget = -∞이면, targetIndex를 0이라고 하자.
  6. 그렇지 않고 relativeTarget < 0이면, targetIndexmax(len + relativeTarget, 0)이라고 하자.
  7. 그렇지 않으면, targetIndexmin(relativeTarget, len)이라고 하자.
  8. relativeStart를 ? ToIntegerOrInfinity(start)라고 하자.
  9. relativeStart = -∞이면, startIndex를 0이라고 하자.
  10. 그렇지 않고 relativeStart < 0이면, startIndexmax(len + relativeStart, 0)이라고 하자.
  11. 그렇지 않으면, startIndexmin(relativeStart, len)이라고 하자.
  12. endundefined이면 relativeEndlen이라고 하자; 그렇지 않으면 relativeEnd를 ? ToIntegerOrInfinity(end)라고 하자.
  13. relativeEnd = -∞이면, endIndex를 0이라고 하자.
  14. 그렇지 않고 relativeEnd < 0이면, endIndexmax(len + relativeEnd, 0)이라고 하자.
  15. 그렇지 않으면, endIndexmin(relativeEnd, len)이라고 하자.
  16. countmin(endIndex - startIndex, len - targetIndex)라고 하자.
  17. count > 0이면,
    1. NOTE: 복사는 소스 데이터의 비트 수준 인코딩을 보존하는 방식으로 수행되어야 한다.
    2. bufferobj.[[ViewedArrayBuffer]]라고 하자.
    3. taRecordMakeTypedArrayWithBufferWitnessRecord(obj, seq-cst)로 설정한다.
    4. IsTypedArrayOutOfBounds(taRecord)가 true이면, TypeError 예외를 던진다.
    5. lenTypedArrayLength(taRecord)로 설정한다.
    6. NOTE: 위 단계들의 부수 효과로 obj의 크기가 줄어들었을 수 있으며, 이 경우 복사는 여전히 적용 가능한 가장 긴 접두부로 진행되어야 한다.
    7. countmin(count, len - startIndex, len - targetIndex)로 설정한다.
    8. elementSizeTypedArrayElementSize(obj)라고 하자.
    9. byteOffsetobj.[[ByteOffset]]이라고 하자.
    10. toByteIndex를 (targetIndex × elementSize) + byteOffset이라고 하자.
    11. fromByteIndex를 (startIndex × elementSize) + byteOffset이라고 하자.
    12. countBytescount × elementSize라고 하자.
    13. fromByteIndex < toByteIndex이고 toByteIndex < fromByteIndex + countBytes이면,
      1. direction을 -1이라고 하자.
      2. fromByteIndexfromByteIndex + countBytes - 1로 설정한다.
      3. toByteIndextoByteIndex + countBytes - 1로 설정한다.
    14. 그렇지 않으면,
      1. direction을 1이라고 하자.
    15. countBytes > 0인 동안 반복한다,
      1. valueGetValueFromBuffer(buffer, fromByteIndex, uint8, true, unordered)라고 하자.
      2. SetValueInBuffer(buffer, toByteIndex, uint8, value, true, unordered)를 수행한다.
      3. fromByteIndexfromByteIndex + direction으로 설정한다.
      4. toByteIndextoByteIndex + direction으로 설정한다.
      5. countBytescountBytes - 1로 설정한다.
  18. obj를 반환한다.

23.2.3.7 %TypedArray%.prototype.entries ( )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. objthis 값이라고 하자.
  2. ValidateTypedArray(obj, seq-cst)를 수행한다.
  3. CreateArrayIterator(obj, key+value)를 반환한다.

23.2.3.8 %TypedArray%.prototype.every ( callback [ , thisArg ] )

이 메서드의 인자 해석과 사용은 23.1.3.6에 정의된 Array.prototype.every의 경우와 같다.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. objthis 값이라고 하자.
  2. taRecord를 ? ValidateTypedArray(obj, seq-cst)라고 하자.
  3. lenTypedArrayLength(taRecord)라고 하자.
  4. IsCallable(callback)가 false이면, TypeError 예외를 던진다.
  5. k를 0이라고 하자.
  6. k < len인 동안 반복한다,
    1. propertyKey를 ! ToString(𝔽(k))라고 하자.
    2. kValue를 ! Get(obj, propertyKey)라고 하자.
    3. testResultToBoolean(? Call(callback, thisArg, « kValue, 𝔽(k), obj »))라고 하자.
    4. testResultfalse이면, false를 반환한다.
    5. kk + 1로 설정한다.
  7. true를 반환한다.

이 메서드는 제네릭이 아니다. this 값은 [[TypedArrayName]] 내부 슬롯을 가진 객체여야 한다.

23.2.3.9 %TypedArray%.prototype.fill ( value [ , start [ , end ] ] )

이 메서드의 인자 해석과 사용은 23.1.3.7에 정의된 Array.prototype.fill의 경우와 같다.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. objthis 값이라고 하자.
  2. taRecord를 ? ValidateTypedArray(obj, seq-cst)라고 하자.
  3. lenTypedArrayLength(taRecord)라고 하자.
  4. obj.[[ContentType]]bigint이면, value를 ? ToBigInt(value)로 설정한다.
  5. 그렇지 않으면, value를 ? ToNumber(value)로 설정한다.
  6. relativeStart를 ? ToIntegerOrInfinity(start)라고 하자.
  7. relativeStart = -∞이면, startIndex를 0이라고 하자.
  8. 그렇지 않고 relativeStart < 0이면, startIndexmax(len + relativeStart, 0)이라고 하자.
  9. 그렇지 않으면, startIndexmin(relativeStart, len)이라고 하자.
  10. endundefined이면 relativeEndlen이라고 하자; 그렇지 않으면 relativeEnd를 ? ToIntegerOrInfinity(end)라고 하자.
  11. relativeEnd = -∞이면, endIndex를 0이라고 하자.
  12. 그렇지 않고 relativeEnd < 0이면, endIndexmax(len + relativeEnd, 0)이라고 하자.
  13. 그렇지 않으면, endIndexmin(relativeEnd, len)이라고 하자.
  14. taRecordMakeTypedArrayWithBufferWitnessRecord(obj, seq-cst)로 설정한다.
  15. IsTypedArrayOutOfBounds(taRecord)가 true이면, TypeError 예외를 던진다.
  16. lenTypedArrayLength(taRecord)로 설정한다.
  17. endIndexmin(endIndex, len)로 설정한다.
  18. kstartIndex라고 하자.
  19. k < endIndex인 동안 반복한다,
    1. propertyKey를 ! ToString(𝔽(k))라고 하자.
    2. Set(obj, propertyKey, value, true)를 수행한다.
    3. kk + 1로 설정한다.
  20. obj를 반환한다.

23.2.3.10 %TypedArray%.prototype.filter ( callback [ , thisArg ] )

이 메서드의 인자 해석과 사용은 23.1.3.8에 정의된 Array.prototype.filter의 경우와 같다.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. objthis 값이라고 하자.
  2. taRecord를 ? ValidateTypedArray(obj, seq-cst)라고 하자.
  3. lenTypedArrayLength(taRecord)라고 하자.
  4. IsCallable(callback)가 false이면, TypeError 예외를 던진다.
  5. kept를 새로운 빈 List라고 하자.
  6. captured를 0이라고 하자.
  7. k를 0이라고 하자.
  8. k < len인 동안 반복한다,
    1. propertyKey를 ! ToString(𝔽(k))라고 하자.
    2. kValue를 ! Get(obj, propertyKey)라고 하자.
    3. selectedToBoolean(? Call(callback, thisArg, « kValue, 𝔽(k), obj »))라고 하자.
    4. selectedtrue이면,
      1. kValuekept에 추가한다.
      2. capturedcaptured + 1로 설정한다.
    5. kk + 1로 설정한다.
  9. resultTypedArray를 ? TypedArraySpeciesCreate(obj, « 𝔽(captured) »)라고 하자.
  10. n을 0이라고 하자.
  11. kept의 각 요소 e에 대해, 다음을 수행한다.
    1. Set(resultTypedArray, ! ToString(𝔽(n)), e, true)를 수행한다.
    2. nn + 1로 설정한다.
  12. resultTypedArray를 반환한다.

이 메서드는 제네릭이 아니다. this 값은 [[TypedArrayName]] 내부 슬롯을 가진 객체여야 한다.

23.2.3.11 %TypedArray%.prototype.find ( predicate [ , thisArg ] )

이 메서드의 인자 해석과 사용은 23.1.3.9에 정의된 Array.prototype.find의 경우와 같다.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. objthis 값이라고 하자.
  2. taRecord를 ? ValidateTypedArray(obj, seq-cst)라고 하자.
  3. lenTypedArrayLength(taRecord)라고 하자.
  4. findRec를 ? FindViaPredicate(obj, len, ascending, predicate, thisArg)라고 하자.
  5. findRec.[[Value]]를 반환한다.

이 메서드는 제네릭이 아니다. this 값은 [[TypedArrayName]] 내부 슬롯을 가진 객체여야 한다.

23.2.3.12 %TypedArray%.prototype.findIndex ( predicate [ , thisArg ] )

이 메서드의 인자 해석과 사용은 23.1.3.10에 정의된 Array.prototype.findIndex의 경우와 같다.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. objthis 값이라고 하자.
  2. taRecord를 ? ValidateTypedArray(obj, seq-cst)라고 하자.
  3. lenTypedArrayLength(taRecord)라고 하자.
  4. findRec를 ? FindViaPredicate(obj, len, ascending, predicate, thisArg)라고 하자.
  5. findRec.[[Index]]를 반환한다.

이 메서드는 제네릭이 아니다. this 값은 [[TypedArrayName]] 내부 슬롯을 가진 객체여야 한다.

23.2.3.13 %TypedArray%.prototype.findLast ( predicate [ , thisArg ] )

이 메서드의 인자 해석과 사용은 23.1.3.11에 정의된 Array.prototype.findLast의 경우와 같다.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. objthis 값이라고 하자.
  2. taRecord를 ? ValidateTypedArray(obj, seq-cst)라고 하자.
  3. lenTypedArrayLength(taRecord)라고 하자.
  4. findRec를 ? FindViaPredicate(obj, len, descending, predicate, thisArg)라고 하자.
  5. findRec.[[Value]]를 반환한다.

이 메서드는 제네릭이 아니다. this 값은 [[TypedArrayName]] 내부 슬롯을 가진 객체여야 한다.

23.2.3.14 %TypedArray%.prototype.findLastIndex ( predicate [ , thisArg ] )

이 메서드의 인자 해석과 사용은 23.1.3.12에 정의된 Array.prototype.findLastIndex의 경우와 같다.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. objthis 값이라고 하자.
  2. taRecord를 ? ValidateTypedArray(obj, seq-cst)라고 하자.
  3. lenTypedArrayLength(taRecord)라고 하자.
  4. findRec를 ? FindViaPredicate(obj, len, descending, predicate, thisArg)라고 하자.
  5. findRec.[[Index]]를 반환한다.

이 메서드는 제네릭이 아니다. this 값은 [[TypedArrayName]] 내부 슬롯을 가진 객체여야 한다.

23.2.3.15 %TypedArray%.prototype.forEach ( callback [ , thisArg ] )

이 메서드의 인자 해석과 사용은 23.1.3.15에 정의된 Array.prototype.forEach의 경우와 같다.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. objthis 값이라고 하자.
  2. taRecord를 ? ValidateTypedArray(obj, seq-cst)라고 하자.
  3. lenTypedArrayLength(taRecord)라고 하자.
  4. IsCallable(callback)가 false이면, TypeError 예외를 던진다.
  5. k를 0이라고 하자.
  6. k < len인 동안 반복한다,
    1. propertyKey를 ! ToString(𝔽(k))라고 하자.
    2. kValue를 ! Get(obj, propertyKey)라고 하자.
    3. Call(callback, thisArg, « kValue, 𝔽(k), obj »)를 수행한다.
    4. kk + 1로 설정한다.
  7. undefined를 반환한다.

이 메서드는 제네릭이 아니다. this 값은 [[TypedArrayName]] 내부 슬롯을 가진 객체여야 한다.

23.2.3.16 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] )

이 메서드의 인자 해석과 사용은 23.1.3.16에 정의된 Array.prototype.includes의 경우와 같다.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. objthis 값이라고 하자.
  2. taRecord를 ? ValidateTypedArray(obj, seq-cst)라고 하자.
  3. lenTypedArrayLength(taRecord)라고 하자.
  4. len = 0이면, false를 반환한다.
  5. n을 ? ToIntegerOrInfinity(fromIndex)라고 하자.
  6. Assert: fromIndexundefined이면, n은 0이다.
  7. n = +∞이면, false를 반환한다.
  8. n = -∞이면, n을 0으로 설정한다.
  9. n ≥ 0이면,
    1. kn이라고 하자.
  10. 그렇지 않으면,
    1. klen + n이라고 하자.
    2. k < 0이면, k를 0으로 설정한다.
  11. k < len인 동안 반복한다,
    1. elementK를 ! Get(obj, ! ToString(𝔽(k)))라고 하자.
    2. SameValueZero(searchElement, elementK)가 true이면, true를 반환한다.
    3. kk + 1로 설정한다.
  12. false를 반환한다.

이 메서드는 제네릭이 아니다. this 값은 [[TypedArrayName]] 내부 슬롯을 가진 객체여야 한다.

23.2.3.17 %TypedArray%.prototype.indexOf ( searchElement [ , fromIndex ] )

이 메서드의 인자 해석과 사용은 23.1.3.17에 정의된 Array.prototype.indexOf의 경우와 같다.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. objthis 값이라고 하자.
  2. taRecord를 ? ValidateTypedArray(obj, seq-cst)라고 하자.
  3. lenTypedArrayLength(taRecord)라고 하자.
  4. len = 0이면, -1𝔽을 반환한다.
  5. n을 ? ToIntegerOrInfinity(fromIndex)라고 하자.
  6. Assert: fromIndexundefined이면, n은 0이다.
  7. n = +∞이면, -1𝔽을 반환한다.
  8. n = -∞이면, n을 0으로 설정한다.
  9. n ≥ 0이면,
    1. kn이라고 하자.
  10. 그렇지 않으면,
    1. klen + n이라고 하자.
    2. k < 0이면, k를 0으로 설정한다.
  11. k < len인 동안 반복한다,
    1. propertyKey를 ! ToString(𝔽(k))라고 하자.
    2. kPresent를 ! HasProperty(obj, propertyKey)라고 하자.
    3. kPresenttrue이면,
      1. elementK를 ! Get(obj, propertyKey)라고 하자.
      2. IsStrictlyEqual(searchElement, elementK)가 true이면, 𝔽(k)를 반환한다.
    4. kk + 1로 설정한다.
  12. -1𝔽을 반환한다.

이 메서드는 제네릭이 아니다. this 값은 [[TypedArrayName]] 내부 슬롯을 가진 객체여야 한다.

23.2.3.18 %TypedArray%.prototype.join ( separator )

이 메서드의 인자 해석과 사용은 23.1.3.18에 정의된 Array.prototype.join의 경우와 같다.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. objthis 값이라고 하자.
  2. taRecord를 ? ValidateTypedArray(obj, seq-cst)라고 하자.
  3. lenTypedArrayLength(taRecord)라고 하자.
  4. separatorundefined이면, sep","라고 하자.
  5. 그렇지 않으면, sep를 ? ToString(separator)라고 하자.
  6. result를 빈 String이라고 하자.
  7. k를 0이라고 하자.
  8. k < len인 동안 반복한다,
    1. k > 0이면, resultresultsep의 문자열 연결로 설정한다.
    2. element를 ! Get(obj, ! ToString(𝔽(k)))라고 하자.
    3. elementundefined가 아니면,
      1. elementStr을 ! ToString(element)라고 하자.
      2. resultresultelementStr의 문자열 연결로 설정한다.
    4. kk + 1로 설정한다.
  9. result를 반환한다.

이 메서드는 제네릭이 아니다. this 값은 [[TypedArrayName]] 내부 슬롯을 가진 객체여야 한다.

23.2.3.19 %TypedArray%.prototype.keys ( )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. objthis 값이라고 하자.
  2. ValidateTypedArray(obj, seq-cst)를 수행한다.
  3. CreateArrayIterator(obj, key)를 반환한다.

23.2.3.20 %TypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] )

이 메서드의 인자 해석과 사용은 23.1.3.20에 정의된 Array.prototype.lastIndexOf의 경우와 같다.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. objthis 값이라고 하자.
  2. taRecord를 ? ValidateTypedArray(obj, seq-cst)라고 하자.
  3. lenTypedArrayLength(taRecord)라고 하자.
  4. len = 0이면, -1𝔽을 반환한다.
  5. fromIndex가 존재하면 n을 ? ToIntegerOrInfinity(fromIndex)라고 하자; 그렇지 않으면 nlen - 1이라고 하자.
  6. n = -∞이면, -1𝔽을 반환한다.
  7. n ≥ 0이면,
    1. kmin(n, len - 1)이라고 하자.
  8. 그렇지 않으면,
    1. klen + n이라고 하자.
  9. k ≥ 0인 동안 반복한다,
    1. propertyKey를 ! ToString(𝔽(k))라고 하자.
    2. kPresent를 ! HasProperty(obj, propertyKey)라고 하자.
    3. kPresenttrue이면,
      1. elementK를 ! Get(obj, propertyKey)라고 하자.
      2. IsStrictlyEqual(searchElement, elementK)가 true이면, 𝔽(k)를 반환한다.
    4. kk - 1로 설정한다.
  10. -1𝔽을 반환한다.

이 메서드는 제네릭이 아니다. this 값은 [[TypedArrayName]] 내부 슬롯을 가진 객체여야 한다.

23.2.3.21 get %TypedArray%.prototype.length

%TypedArray%.prototype.length는 set 접근자 함수가 undefined인 접근자 속성이다. 그 get 접근자 함수는 호출될 때 다음 단계를 수행한다:

  1. objthis 값이라고 하자.
  2. RequireInternalSlot(obj, [[TypedArrayName]])를 수행한다.
  3. Assert: obj[[ViewedArrayBuffer]][[ArrayLength]] 내부 슬롯을 가진다.
  4. taRecordMakeTypedArrayWithBufferWitnessRecord(obj, seq-cst)라고 하자.
  5. IsTypedArrayOutOfBounds(taRecord)가 true이면, +0𝔽을 반환한다.
  6. lengthTypedArrayLength(taRecord)라고 하자.
  7. 𝔽(length)를 반환한다.

이 함수는 제네릭이 아니다. this 값은 [[TypedArrayName]] 내부 슬롯을 가진 객체여야 한다.

23.2.3.22 %TypedArray%.prototype.map ( callback [ , thisArg ] )

이 메서드의 인자 해석과 사용은 23.1.3.21에 정의된 Array.prototype.map의 경우와 같다.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. objthis 값이라고 하자.
  2. taRecord를 ? ValidateTypedArray(obj, seq-cst)라고 하자.
  3. lenTypedArrayLength(taRecord)라고 하자.
  4. IsCallable(callback)가 false이면, TypeError 예외를 던진다.
  5. resultTypedArray를 ? TypedArraySpeciesCreate(obj, « 𝔽(len) »)라고 하자.
  6. k를 0이라고 하자.
  7. k < len인 동안 반복한다,
    1. propertyKey를 ! ToString(𝔽(k))라고 하자.
    2. kValue를 ! Get(obj, propertyKey)라고 하자.
    3. mappedValue를 ? Call(callback, thisArg, « kValue, 𝔽(k), obj »)라고 하자.
    4. Set(resultTypedArray, propertyKey, mappedValue, true)를 수행한다.
    5. kk + 1로 설정한다.
  8. resultTypedArray를 반환한다.

이 메서드는 제네릭이 아니다. this 값은 [[TypedArrayName]] 내부 슬롯을 가진 객체여야 한다.

23.2.3.23 %TypedArray%.prototype.reduce ( callback [ , initialValue ] )

이 메서드의 인자 해석과 사용은 23.1.3.24에 정의된 Array.prototype.reduce의 경우와 같다.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. objthis 값이라고 하자.
  2. taRecord를 ? ValidateTypedArray(obj, seq-cst)라고 하자.
  3. lenTypedArrayLength(taRecord)라고 하자.
  4. IsCallable(callback)가 false이면, TypeError 예외를 던진다.
  5. len = 0이고 initialValue가 존재하지 않으면, TypeError 예외를 던진다.
  6. k를 0이라고 하자.
  7. accumulatorundefined라고 하자.
  8. initialValue가 존재하면,
    1. accumulatorinitialValue로 설정한다.
  9. 그렇지 않으면,
    1. propertyKey를 ! ToString(𝔽(k))라고 하자.
    2. accumulator를 ! Get(obj, propertyKey)로 설정한다.
    3. kk + 1로 설정한다.
  10. k < len인 동안 반복한다,
    1. propertyKey를 ! ToString(𝔽(k))라고 하자.
    2. kValue를 ! Get(obj, propertyKey)라고 하자.
    3. accumulator를 ? Call(callback, undefined, « accumulator, kValue, 𝔽(k), obj »)로 설정한다.
    4. kk + 1로 설정한다.
  11. accumulator를 반환한다.

이 메서드는 제네릭이 아니다. this 값은 [[TypedArrayName]] 내부 슬롯을 가진 객체여야 한다.

23.2.3.24 %TypedArray%.prototype.reduceRight ( callback [ , initialValue ] )

이 메서드의 인자 해석과 사용은 23.1.3.25에 정의된 Array.prototype.reduceRight의 경우와 같다.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. objthis 값이라고 하자.
  2. taRecord를 ? ValidateTypedArray(obj, seq-cst)라고 하자.
  3. lenTypedArrayLength(taRecord)라고 하자.
  4. IsCallable(callback)가 false이면, TypeError 예외를 던진다.
  5. len = 0이고 initialValue가 존재하지 않으면, TypeError 예외를 던진다.
  6. klen - 1이라고 하자.
  7. accumulatorundefined라고 하자.
  8. initialValue가 존재하면,
    1. accumulatorinitialValue로 설정한다.
  9. 그렇지 않으면,
    1. propertyKey를 ! ToString(𝔽(k))라고 하자.
    2. accumulator를 ! Get(obj, propertyKey)로 설정한다.
    3. kk - 1로 설정한다.
  10. k ≥ 0인 동안 반복한다,
    1. propertyKey를 ! ToString(𝔽(k))라고 하자.
    2. kValue를 ! Get(obj, propertyKey)라고 하자.
    3. accumulator를 ? Call(callback, undefined, « accumulator, kValue, 𝔽(k), obj »)로 설정한다.
    4. kk - 1로 설정한다.
  11. accumulator를 반환한다.

이 메서드는 제네릭이 아니다. this 값은 [[TypedArrayName]] 내부 슬롯을 가진 객체여야 한다.

23.2.3.25 %TypedArray%.prototype.reverse ( )

이 메서드의 인자 해석과 사용은 23.1.3.26에 정의된 Array.prototype.reverse의 경우와 같다.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. objthis 값이라고 하자.
  2. taRecord를 ? ValidateTypedArray(obj, seq-cst)라고 하자.
  3. lenTypedArrayLength(taRecord)라고 하자.
  4. middlefloor(len / 2)라고 하자.
  5. lower를 0이라고 하자.
  6. lowermiddle인 동안 반복한다,
    1. upperlen - lower - 1이라고 하자.
    2. upperP를 ! ToString(𝔽(upper))라고 하자.
    3. lowerP를 ! ToString(𝔽(lower))라고 하자.
    4. lowerValue를 ! Get(obj, lowerP)라고 하자.
    5. upperValue를 ! Get(obj, upperP)라고 하자.
    6. Set(obj, lowerP, upperValue, true)를 수행한다.
    7. Set(obj, upperP, lowerValue, true)를 수행한다.
    8. lowerlower + 1로 설정한다.
  7. obj를 반환한다.

이 메서드는 제네릭이 아니다. this 값은 [[TypedArrayName]] 내부 슬롯을 가진 객체여야 한다.

23.2.3.26 %TypedArray%.prototype.set ( source [ , offset ] )

이 메서드는 source에서 값을 읽어 이 TypedArray 안에 여러 값을 설정한다. 세부 사항은 source의 타입에 따라 다르다. 선택적 offset 값은 값이 쓰이는 이 TypedArray 안의 첫 번째 요소 인덱스를 나타낸다. 생략되면 0으로 가정된다.

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

  1. targetthis 값이라고 하자.
  2. RequireInternalSlot(target, [[TypedArrayName]])를 수행한다.
  3. Assert: target[[ViewedArrayBuffer]] 내부 슬롯을 가진다.
  4. targetOffset을 ? ToIntegerOrInfinity(offset)이라고 하자.
  5. targetOffset < 0이면, RangeError 예외를 던진다.
  6. source[[TypedArrayName]] 내부 슬롯을 가진 Object이면,
    1. SetTypedArrayFromTypedArray(target, targetOffset, source)를 수행한다.
  7. 그렇지 않으면,
    1. SetTypedArrayFromArrayLike(target, targetOffset, source)를 수행한다.
  8. undefined를 반환한다.

이 메서드는 제네릭이 아니다. this 값은 [[TypedArrayName]] 내부 슬롯을 가진 객체여야 한다.

23.2.3.26.1 SetTypedArrayFromArrayLike ( target, targetOffset, source )

The abstract operation SetTypedArrayFromArrayLike takes arguments target (a TypedArray), targetOffset (a non-negative integer or +∞), and source (an ECMAScript language value, but not a TypedArray) and returns either a normal completion containing unused or a throw completion. 이 연산은 source에서 값을 읽어 targetOffset 인덱스부터 시작하여 target 안에 여러 값을 설정한다. It performs the following steps when called:

  1. targetRecordMakeTypedArrayWithBufferWitnessRecord(target, seq-cst)라고 하자.
  2. IsTypedArrayOutOfBounds(targetRecord)가 true이면, TypeError 예외를 던진다.
  3. targetLengthTypedArrayLength(targetRecord)라고 하자.
  4. src를 ? ToObject(source)라고 하자.
  5. srcLength를 ? LengthOfArrayLike(src)라고 하자.
  6. targetOffset = +∞이면, RangeError 예외를 던진다.
  7. srcLength + targetOffset > targetLength이면, RangeError 예외를 던진다.
  8. k를 0이라고 하자.
  9. k < srcLength인 동안 반복한다,
    1. propertyKey를 ! ToString(𝔽(k))라고 하자.
    2. value를 ? Get(src, propertyKey)라고 하자.
    3. targetIndex𝔽(targetOffset + k)라고 하자.
    4. TypedArraySetElement(target, targetIndex, value)를 수행한다.
    5. kk + 1로 설정한다.
  10. unused를 반환한다.

23.2.3.26.2 SetTypedArrayFromTypedArray ( target, targetOffset, source )

The abstract operation SetTypedArrayFromTypedArray takes arguments target (a TypedArray), targetOffset (a non-negative integer or +∞), and source (a TypedArray) and returns either a normal completion containing unused or a throw completion. 이 연산은 source에서 값을 읽어 targetOffset 인덱스부터 시작하여 target 안에 여러 값을 설정한다. It performs the following steps when called:

  1. targetBuffertarget.[[ViewedArrayBuffer]]라고 하자.
  2. targetRecordMakeTypedArrayWithBufferWitnessRecord(target, seq-cst)라고 하자.
  3. IsTypedArrayOutOfBounds(targetRecord)가 true이면, TypeError 예외를 던진다.
  4. targetLengthTypedArrayLength(targetRecord)라고 하자.
  5. srcBuffersource.[[ViewedArrayBuffer]]라고 하자.
  6. srcRecordMakeTypedArrayWithBufferWitnessRecord(source, seq-cst)라고 하자.
  7. IsTypedArrayOutOfBounds(srcRecord)가 true이면, TypeError 예외를 던진다.
  8. srcLengthTypedArrayLength(srcRecord)라고 하자.
  9. targetTypeTypedArrayElementType(target)이라고 하자.
  10. targetElementSizeTypedArrayElementSize(target)라고 하자.
  11. targetByteOffsettarget.[[ByteOffset]]이라고 하자.
  12. srcTypeTypedArrayElementType(source)라고 하자.
  13. srcElementSizeTypedArrayElementSize(source)라고 하자.
  14. srcByteOffsetsource.[[ByteOffset]]이라고 하자.
  15. targetOffset = +∞이면, RangeError 예외를 던진다.
  16. srcLength + targetOffset > targetLength이면, RangeError 예외를 던진다.
  17. target.[[ContentType]]source.[[ContentType]]가 아니면, TypeError 예외를 던진다.
  18. IsSharedArrayBuffer(srcBuffer)가 true이고, IsSharedArrayBuffer(targetBuffer)가 true이고, srcBuffer.[[ArrayBufferData]]targetBuffer.[[ArrayBufferData]]이면 sameSharedArrayBuffertrue라고 하자; 그렇지 않으면 sameSharedArrayBufferfalse라고 하자.
  19. SameValue(srcBuffer, targetBuffer)가 true이거나 sameSharedArrayBuffertrue이면,
    1. srcByteLengthTypedArrayByteLength(srcRecord)라고 하자.
    2. srcBuffer를 ? CloneArrayBuffer(srcBuffer, srcByteOffset, srcByteLength)로 설정한다.
    3. srcByteIndex를 0이라고 하자.
  20. 그렇지 않으면,
    1. srcByteIndexsrcByteOffset이라고 하자.
  21. targetByteIndex를 (targetOffset × targetElementSize) + targetByteOffset이라고 하자.
  22. limittargetByteIndex + (targetElementSize × srcLength)라고 하자.
  23. srcTypetargetType이면,
    1. NOTE: 전송은 소스 데이터의 비트 수준 인코딩을 보존하는 방식으로 수행되어야 한다.
    2. targetByteIndex < limit인 동안 반복한다,
      1. valueGetValueFromBuffer(srcBuffer, srcByteIndex, uint8, true, unordered)라고 하자.
      2. SetValueInBuffer(targetBuffer, targetByteIndex, uint8, value, true, unordered)를 수행한다.
      3. srcByteIndexsrcByteIndex + 1로 설정한다.
      4. targetByteIndextargetByteIndex + 1로 설정한다.
  24. 그렇지 않으면,
    1. targetByteIndex < limit인 동안 반복한다,
      1. valueGetValueFromBuffer(srcBuffer, srcByteIndex, srcType, true, unordered)라고 하자.
      2. SetValueInBuffer(targetBuffer, targetByteIndex, targetType, value, true, unordered)를 수행한다.
      3. srcByteIndexsrcByteIndex + srcElementSize로 설정한다.
      4. targetByteIndextargetByteIndex + targetElementSize로 설정한다.
  25. unused를 반환한다.

23.2.3.27 %TypedArray%.prototype.slice ( start, end )

이 메서드의 인자 해석과 사용은 23.1.3.28에 정의된 Array.prototype.slice의 경우와 같다.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. objthis 값이라고 하자.
  2. taRecord를 ? ValidateTypedArray(obj, seq-cst)라고 하자.
  3. srcArrayLengthTypedArrayLength(taRecord)라고 하자.
  4. relativeStart를 ? ToIntegerOrInfinity(start)라고 하자.
  5. relativeStart = -∞이면, startIndex를 0이라고 하자.
  6. 그렇지 않고 relativeStart < 0이면, startIndexmax(srcArrayLength + relativeStart, 0)이라고 하자.
  7. 그렇지 않으면, startIndexmin(relativeStart, srcArrayLength)이라고 하자.
  8. endundefined이면 relativeEndsrcArrayLength라고 하자; 그렇지 않으면 relativeEnd를 ? ToIntegerOrInfinity(end)라고 하자.
  9. relativeEnd = -∞이면, endIndex를 0이라고 하자.
  10. 그렇지 않고 relativeEnd < 0이면, endIndexmax(srcArrayLength + relativeEnd, 0)이라고 하자.
  11. 그렇지 않으면, endIndexmin(relativeEnd, srcArrayLength)이라고 하자.
  12. countBytesmax(endIndex - startIndex, 0)이라고 하자.
  13. resultArray를 ? TypedArraySpeciesCreate(obj, « 𝔽(countBytes) »)라고 하자.
  14. countBytes > 0이면,
    1. taRecordMakeTypedArrayWithBufferWitnessRecord(obj, seq-cst)로 설정한다.
    2. IsTypedArrayOutOfBounds(taRecord)가 true이면, TypeError 예외를 던진다.
    3. endIndexmin(endIndex, TypedArrayLength(taRecord))로 설정한다.
    4. countBytesmax(endIndex - startIndex, 0)으로 설정한다.
    5. srcTypeTypedArrayElementType(obj)이라고 하자.
    6. targetTypeTypedArrayElementType(resultArray)이라고 하자.
    7. srcTypetargetType이면,
      1. NOTE: 전송은 소스 데이터의 비트 수준 인코딩을 보존하는 방식으로 수행되어야 한다.
      2. srcBufferobj.[[ViewedArrayBuffer]]라고 하자.
      3. targetBufferresultArray.[[ViewedArrayBuffer]]라고 하자.
      4. elementSizeTypedArrayElementSize(obj)라고 하자.
      5. srcByteOffsetobj.[[ByteOffset]]이라고 하자.
      6. srcByteIndex를 (startIndex × elementSize) + srcByteOffset이라고 하자.
      7. targetByteIndexresultArray.[[ByteOffset]]이라고 하자.
      8. endByteIndextargetByteIndex + (countBytes × elementSize)라고 하자.
      9. targetByteIndex < endByteIndex인 동안 반복한다,
        1. valueGetValueFromBuffer(srcBuffer, srcByteIndex, uint8, true, unordered)라고 하자.
        2. SetValueInBuffer(targetBuffer, targetByteIndex, uint8, value, true, unordered)를 수행한다.
        3. srcByteIndexsrcByteIndex + 1로 설정한다.
        4. targetByteIndextargetByteIndex + 1로 설정한다.
    8. 그렇지 않으면,
      1. n을 0이라고 하자.
      2. kstartIndex라고 하자.
      3. k < endIndex인 동안 반복한다,
        1. propertyKey를 ! ToString(𝔽(k))라고 하자.
        2. kValue를 ! Get(obj, propertyKey)라고 하자.
        3. Set(resultArray, ! ToString(𝔽(n)), kValue, true)를 수행한다.
        4. kk + 1로 설정한다.
        5. nn + 1로 설정한다.
  15. resultArray를 반환한다.

이 메서드는 제네릭이 아니다. this 값은 [[TypedArrayName]] 내부 슬롯을 가진 객체여야 한다.

23.2.3.28 %TypedArray%.prototype.some ( callback [ , thisArg ] )

이 메서드의 인자 해석과 사용은 23.1.3.29에 정의된 Array.prototype.some의 경우와 같다.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. objthis 값이라고 하자.
  2. taRecord를 ? ValidateTypedArray(obj, seq-cst)라고 하자.
  3. lenTypedArrayLength(taRecord)라고 하자.
  4. IsCallable(callback)가 false이면, TypeError 예외를 던진다.
  5. k를 0이라고 하자.
  6. k < len인 동안 반복한다,
    1. propertyKey를 ! ToString(𝔽(k))라고 하자.
    2. kValue를 ! Get(obj, propertyKey)라고 하자.
    3. testResultToBoolean(? Call(callback, thisArg, « kValue, 𝔽(k), obj »))라고 하자.
    4. testResulttrue이면, true를 반환한다.
    5. kk + 1로 설정한다.
  7. false를 반환한다.

이 메서드는 제네릭이 아니다. this 값은 [[TypedArrayName]] 내부 슬롯을 가진 객체여야 한다.

23.2.3.29 %TypedArray%.prototype.sort ( comparator )

이는 아래에 설명된 점을 제외하고 23.1.3.30에 정의된 Array.prototype.sort의 요구사항과 같은 요구사항을 구현하는 별개의 메서드이다. 이 메서드의 구현은 this 값이 고정 길이를 가지며 정수 인덱스 속성이 희소하지 않은 객체라는 지식을 사용해 최적화될 수 있다.

이 메서드는 제네릭이 아니다. this 값은 [[TypedArrayName]] 내부 슬롯을 가진 객체여야 한다.

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

  1. comparatorundefined가 아니고 IsCallable(comparator)가 false이면, TypeError 예외를 던진다.
  2. objthis 값이라고 하자.
  3. taRecord를 ? ValidateTypedArray(obj, seq-cst)라고 하자.
  4. lenTypedArrayLength(taRecord)라고 하자.
  5. NOTE: 다음 클로저는 23.1.3.30에서 사용되는 문자열 비교가 아니라 수치 비교를 수행한다.
  6. sortComparecomparator를 캡처하고 호출될 때 다음 단계를 수행하는, 매개변수 (x, y)를 가진 새로운 Abstract Closure라고 하자:
    1. CompareTypedArrayElements(x, y, comparator)를 반환한다.
  7. sortedList를 ? SortIndexedProperties(obj, len, sortCompare, read-through-holes)라고 하자.
  8. j를 0이라고 하자.
  9. j < len인 동안 반복한다,
    1. Set(obj, ! ToString(𝔽(j)), sortedList[j], true)를 수행한다.
    2. jj + 1로 설정한다.
  10. obj를 반환한다.
Note

NaN은 항상 다른 어떤 값보다도 크게 비교되므로(CompareTypedArrayElements를 보라), comparator가 제공되지 않으면 NaN 속성 값은 항상 결과의 끝으로 정렬된다.

23.2.3.30 %TypedArray%.prototype.subarray ( start, end )

이 메서드는 요소 타입이 이 TypedArray의 요소 타입이고 ArrayBuffer가 이 TypedArray의 ArrayBuffer이며, start(포함)부터 end(제외)까지의 구간에 있는 요소들을 참조하는 새로운 TypedArray를 반환한다. start 또는 end 중 하나가 음수이면, 처음부터가 아니라 배열의 끝으로부터의 인덱스를 가리킨다.

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

  1. objthis 값이라고 하자.
  2. RequireInternalSlot(obj, [[TypedArrayName]])를 수행한다.
  3. Assert: obj[[ViewedArrayBuffer]] 내부 슬롯을 가진다.
  4. bufferobj.[[ViewedArrayBuffer]]라고 하자.
  5. srcRecordMakeTypedArrayWithBufferWitnessRecord(obj, seq-cst)라고 하자.
  6. IsTypedArrayOutOfBounds(srcRecord)가 true이면,
    1. srcLength를 0이라고 하자.
  7. 그렇지 않으면,
    1. srcLengthTypedArrayLength(srcRecord)라고 하자.
  8. relativeStart를 ? ToIntegerOrInfinity(start)라고 하자.
  9. relativeStart = -∞이면, startIndex를 0이라고 하자.
  10. 그렇지 않고 relativeStart < 0이면, startIndexmax(srcLength + relativeStart, 0)이라고 하자.
  11. 그렇지 않으면, startIndexmin(relativeStart, srcLength)이라고 하자.
  12. elementSizeTypedArrayElementSize(obj)라고 하자.
  13. srcByteOffsetobj.[[ByteOffset]]이라고 하자.
  14. beginByteOffsetsrcByteOffset + (startIndex × elementSize)라고 하자.
  15. obj.[[ArrayLength]]auto이고 endundefined이면,
    1. argumentsList를 « buffer, 𝔽(beginByteOffset) »라고 하자.
  16. 그렇지 않으면,
    1. endundefined이면 relativeEndsrcLength라고 하자; 그렇지 않으면 relativeEnd를 ? ToIntegerOrInfinity(end)라고 하자.
    2. relativeEnd = -∞이면, endIndex를 0이라고 하자.
    3. 그렇지 않고 relativeEnd < 0이면, endIndexmax(srcLength + relativeEnd, 0)이라고 하자.
    4. 그렇지 않으면, endIndexmin(relativeEnd, srcLength)이라고 하자.
    5. newLengthmax(endIndex - startIndex, 0)이라고 하자.
    6. argumentsList를 « buffer, 𝔽(beginByteOffset), 𝔽(newLength) »라고 하자.
  17. TypedArraySpeciesCreate(obj, argumentsList)를 반환한다.

이 메서드는 제네릭이 아니다. this 값은 [[TypedArrayName]] 내부 슬롯을 가진 객체여야 한다.

23.2.3.31 %TypedArray%.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] )

이는 23.1.3.32에 정의된 Array.prototype.toLocaleString과 같은 알고리즘을 구현하는 별개의 메서드이지만, "length"[[Get]]을 수행하는 대신 TypedArrayLength가 호출된다는 점이 다르다. 이 알고리즘의 구현은 기반 버퍼가 크기 조절 가능하지 않을 때 this 값이 고정 길이를 가지며 정수 인덱스 속성이 희소하지 않다는 지식을 사용해 최적화될 수 있다. 그러나 그러한 최적화는 알고리즘의 지정된 동작에 관찰 가능한 변경을 도입해서는 안 된다.

이 메서드는 제네릭이 아니다. 알고리즘을 평가하기 전에 ValidateTypedArraythis 값과 seq-cst를 인자로 하여 호출된다. 그 결과가 abrupt completion이면 알고리즘을 평가하는 대신 그 예외가 던져진다.

Note

ECMAScript 구현이 ECMA-402 국제화 API를 포함하는 경우, 이 메서드는 ECMA-402 명세에 있는 Array.prototype.toLocaleString 알고리즘에 기반한다.

23.2.3.32 %TypedArray%.prototype.toReversed ( )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. objthis 값이라고 하자.
  2. taRecord를 ? ValidateTypedArray(obj, seq-cst)라고 하자.
  3. lenTypedArrayLength(taRecord)라고 하자.
  4. resultArray를 ? TypedArrayCreateSameType(obj, len)라고 하자.
  5. k를 0이라고 하자.
  6. k < len인 동안 반복한다,
    1. from을 ! ToString(𝔽(len - k - 1))라고 하자.
    2. propertyKey를 ! ToString(𝔽(k))라고 하자.
    3. fromValue를 ! Get(obj, from)라고 하자.
    4. Set(resultArray, propertyKey, fromValue, true)를 수행한다.
    5. kk + 1로 설정한다.
  7. resultArray를 반환한다.

23.2.3.33 %TypedArray%.prototype.toSorted ( comparator )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. comparatorundefined가 아니고 IsCallable(comparator)가 false이면, TypeError 예외를 던진다.
  2. objthis 값이라고 하자.
  3. taRecord를 ? ValidateTypedArray(obj, seq-cst)라고 하자.
  4. lenTypedArrayLength(taRecord)라고 하자.
  5. resultArray를 ? TypedArrayCreateSameType(obj, len)라고 하자.
  6. NOTE: 다음 클로저는 23.1.3.34에서 사용되는 문자열 비교가 아니라 수치 비교를 수행한다.
  7. sortComparecomparator를 캡처하고 호출될 때 다음 단계를 수행하는, 매개변수 (x, y)를 가진 새로운 Abstract Closure라고 하자:
    1. CompareTypedArrayElements(x, y, comparator)를 반환한다.
  8. sortedList를 ? SortIndexedProperties(obj, len, sortCompare, read-through-holes)라고 하자.
  9. j를 0이라고 하자.
  10. j < len인 동안 반복한다,
    1. Set(resultArray, ! ToString(𝔽(j)), sortedList[j], true)를 수행한다.
    2. jj + 1로 설정한다.
  11. resultArray를 반환한다.

23.2.3.34 %TypedArray%.prototype.toString ( )

"toString" 속성의 초기값은 23.1.3.36에 정의된 %Array.prototype.toString%이다.

23.2.3.35 %TypedArray%.prototype.values ( )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. objthis 값이라고 하자.
  2. ValidateTypedArray(obj, seq-cst)를 수행한다.
  3. CreateArrayIterator(obj, value)를 반환한다.

23.2.3.36 %TypedArray%.prototype.with ( index, value )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. objthis 값이라고 하자.
  2. taRecord를 ? ValidateTypedArray(obj, seq-cst)라고 하자.
  3. lenTypedArrayLength(taRecord)라고 하자.
  4. relativeIndex를 ? ToIntegerOrInfinity(index)라고 하자.
  5. relativeIndex ≥ 0이면, actualIndexrelativeIndex라고 하자.
  6. 그렇지 않으면, actualIndexlen + relativeIndex라고 하자.
  7. obj.[[ContentType]]bigint이면, numericValue를 ? ToBigInt(value)라고 하자.
  8. 그렇지 않으면, numericValue를 ? ToNumber(value)라고 하자.
  9. IsValidIntegerIndex(obj, 𝔽(actualIndex))가 false이면, RangeError 예외를 던진다.
  10. resultArray를 ? TypedArrayCreateSameType(obj, len)라고 하자.
  11. k를 0이라고 하자.
  12. k < len인 동안 반복한다,
    1. propertyKey를 ! ToString(𝔽(k))라고 하자.
    2. k = actualIndex이면, fromValuenumericValue라고 하자.
    3. 그렇지 않으면, fromValue를 ! Get(obj, propertyKey)라고 하자.
    4. Set(resultArray, propertyKey, fromValue, true)를 수행한다.
    5. kk + 1로 설정한다.
  13. resultArray를 반환한다.

23.2.3.37 %TypedArray%.prototype [ %Symbol.iterator% ] ( )

%Symbol.iterator% 속성의 초기값은 23.2.3.35에 정의된 %TypedArray.prototype.values%이다.

23.2.3.38 get %TypedArray%.prototype [ %Symbol.toStringTag% ]

%TypedArray%.prototype[%Symbol.toStringTag%]는 set 접근자 함수가 undefined인 접근자 속성이다. 그 get 접근자 함수는 호출될 때 다음 단계를 수행한다:

  1. objthis 값이라고 하자.
  2. obj가 Object가 아니면, undefined를 반환한다.
  3. obj[[TypedArrayName]] 내부 슬롯을 가지지 않으면, undefined를 반환한다.
  4. nameobj.[[TypedArrayName]]이라고 하자.
  5. Assert: name은 String이다.
  6. name을 반환한다.

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

이 함수의 "name" 속성의 초기값은 "get [Symbol.toStringTag]"이다.

23.2.4 TypedArray 객체를 위한 추상 연산

23.2.4.1 TypedArrayCreateFromConstructor ( constructor, argumentList )

The abstract operation TypedArrayCreateFromConstructor takes arguments constructor (a constructor) and argumentList (a List of ECMAScript language values) and returns either a normal completion containing a TypedArray or a throw completion. 생성자 함수를 사용한 새 TypedArray의 생성을 지정하는 데 사용된다. It performs the following steps when called:

  1. newTypedArray를 ? Construct(constructor, argumentList)라고 하자.
  2. taRecord를 ? ValidateTypedArray(newTypedArray, seq-cst)라고 하자.
  3. Assert: newTypedArrayTypedArray 인스턴스의 속성에 언급된 모든 내부 슬롯을 가진다.
  4. argumentList의 요소 개수가 1이고 argumentList[0]이 Number이면,
    1. IsTypedArrayOutOfBounds(taRecord)가 true이면, TypeError 예외를 던진다.
    2. lengthTypedArrayLength(taRecord)라고 하자.
    3. length < (argumentList[0])이면, TypeError 예외를 던진다.
  5. newTypedArray를 반환한다.

23.2.4.2 TypedArrayCreateSameType ( exemplar, length )

The abstract operation TypedArrayCreateSameType takes arguments exemplar (a TypedArray) and length (a non-negative integer) and returns either a normal completion containing a TypedArray or a throw completion. exemplar에서 파생된 생성자 함수를 사용한 새 TypedArray의 생성을 지정하는 데 사용된다. %Symbol.species%를 사용하여 사용자 정의 TypedArray 서브클래스를 생성할 수 있는 TypedArraySpeciesCreate와 달리, 이 연산은 항상 내장 TypedArray 생성자 중 하나를 사용한다. It performs the following steps when called:

  1. constructorTable 70에서 생성자 이름 exemplar.[[TypedArrayName]]에 연관된 내재 객체라고 하자.
  2. result를 ? TypedArrayCreateFromConstructor(constructor, « 𝔽(length) »)라고 하자.
  3. Assert: result[[TypedArrayName]][[ContentType]] 내부 슬롯을 가진다.
  4. Assert: result.[[ContentType]]exemplar.[[ContentType]]이다.
  5. result를 반환한다.

23.2.4.3 TypedArraySpeciesCreate ( exemplar, argumentList )

The abstract operation TypedArraySpeciesCreate takes arguments exemplar (a TypedArray) and argumentList (a List of ECMAScript language values) and returns either a normal completion containing a TypedArray or a throw completion. exemplar에서 파생된 생성자 함수를 사용한 새 TypedArray의 생성을 지정하는 데 사용된다. %Symbol.species%를 사용하여 Array가 아닌 객체를 생성할 수 있는 ArraySpeciesCreate와 달리, 이 연산은 생성자 함수가 실제 TypedArray를 생성하도록 강제한다. It performs the following steps when called:

  1. defaultConstructorTable 70에서 생성자 이름 exemplar.[[TypedArrayName]]에 연관된 내재 객체라고 하자.
  2. constructor를 ? SpeciesConstructor(exemplar, defaultConstructor)라고 하자.
  3. result를 ? TypedArrayCreateFromConstructor(constructor, argumentList)라고 하자.
  4. result.[[ContentType]]exemplar.[[ContentType]]가 아니면, TypeError 예외를 던진다.
  5. result를 반환한다.

23.2.4.4 ValidateTypedArray ( obj, order )

The abstract operation ValidateTypedArray takes arguments obj (an ECMAScript language value) and order (seq-cst or unordered) 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. RequireInternalSlot(obj, [[TypedArrayName]])를 수행한다.
  2. Assert: obj[[ViewedArrayBuffer]] 내부 슬롯을 가진다.
  3. taRecordMakeTypedArrayWithBufferWitnessRecord(obj, order)라고 하자.
  4. IsTypedArrayOutOfBounds(taRecord)가 true이면, TypeError 예외를 던진다.
  5. taRecord를 반환한다.

23.2.4.5 TypedArrayElementSize ( obj )

The abstract operation TypedArrayElementSize takes argument obj (a TypedArray) and returns a non-negative integer. It performs the following steps when called:

  1. obj.[[TypedArrayName]]에 대해 Table 70에 지정된 Element Size 값을 반환한다.

23.2.4.6 TypedArrayElementType ( obj )

The abstract operation TypedArrayElementType takes argument obj (a TypedArray) and returns a TypedArray element type. It performs the following steps when called:

  1. obj.[[TypedArrayName]]에 대해 Table 70에 지정된 Element Type 값을 반환한다.

23.2.4.7 CompareTypedArrayElements ( x, y, comparator )

The abstract operation CompareTypedArrayElements takes arguments x (a Number or a BigInt), y (a Number or a BigInt), and comparator (a function object or undefined) and returns either a normal completion containing a Number or an abrupt completion. It performs the following steps when called:

  1. Assert: x는 Number이고 y는 Number이거나, x는 BigInt이고 y는 BigInt이다.
  2. comparatorundefined가 아니면,
    1. result를 ? ToNumber(? Call(comparator, undefined, « x, y »))라고 하자.
    2. resultNaN이면, +0𝔽을 반환한다.
    3. result를 반환한다.
  3. xNaN이고 yNaN이면, +0𝔽을 반환한다.
  4. xNaN이면, 1𝔽을 반환한다.
  5. yNaN이면, -1𝔽을 반환한다.
  6. x < y이면, -1𝔽을 반환한다.
  7. x > y이면, 1𝔽을 반환한다.
  8. x-0𝔽이고 y+0𝔽이면, -1𝔽을 반환한다.
  9. x+0𝔽이고 y-0𝔽이면, 1𝔽을 반환한다.
  10. +0𝔽을 반환한다.
Note
이는 23.1.3.30.2에서 사용되는 문자열 비교가 아니라 수치 비교를 수행한다.

23.2.5 TypedArray 생성자

TypedArray 생성자는:

  • 달리 명시된 경우를 제외하고, Table 70에서 TypedArray 대신 생성자 이름으로 사용되는 이름만 다를 뿐 아래에 설명된 구조를 가지는 내재 객체이다.
  • 인자의 개수와 타입에 따라 동작이 달라지는 함수이다. TypedArray 호출의 실제 동작은 전달된 인자의 개수와 종류에 의존한다.
  • 함수로 호출되도록 의도되지 않았으며, 그런 방식으로 호출되면 예외를 던진다.
  • 클래스 정의의 extends 절의 값으로 사용될 수 있다. 지정된 TypedArray 동작을 상속하려는 서브클래스 생성자는 %TypedArray%.prototype 내장 메서드를 지원하는 데 필요한 내부 상태로 서브클래스 인스턴스를 생성하고 초기화하기 위해 TypedArray 생성자에 대한 super 호출을 포함해야 한다.

23.2.5.1 TypedArray ( ...args )

TypedArray 생성자는 호출될 때 다음 단계를 수행한다:

  1. NewTarget이 undefined이면, TypeError 예외를 던진다.
  2. constructorName을 이 TypedArray 생성자에 대해 Table 70에 지정된 Constructor Name 값의 String 값이라고 하자.
  3. proto"%TypedArray.prototype%"라고 하자.
  4. numberOfArgsargs의 요소 개수라고 하자.
  5. numberOfArgs = 0이면, ? AllocateTypedArray(constructorName, NewTarget, proto, 0)를 반환한다.
  6. firstArgumentargs[0]이라고 하자.
  7. firstArgument가 Object이면,
    1. obj를 ? AllocateTypedArray(constructorName, NewTarget, proto)라고 하자.
    2. firstArgument[[TypedArrayName]] 내부 슬롯을 가지면,
      1. InitializeTypedArrayFromTypedArray(obj, firstArgument)를 수행한다.
    3. 그렇지 않고 firstArgument[[ArrayBufferData]] 내부 슬롯을 가지면,
      1. numberOfArgs > 1이면 byteOffsetargs[1]이라고 하자; 그렇지 않으면 byteOffsetundefined라고 하자.
      2. numberOfArgs > 2이면 lengthargs[2]라고 하자; 그렇지 않으면 lengthundefined라고 하자.
      3. InitializeTypedArrayFromArrayBuffer(obj, firstArgument, byteOffset, length)를 수행한다.
    4. 그렇지 않으면,
      1. Assert: firstArgument는 Object이고 firstArgument[[TypedArrayName]] 또는 [[ArrayBufferData]] 내부 슬롯 중 어느 것도 가지지 않는다.
      2. usingIterator를 ? GetMethod(firstArgument, %Symbol.iterator%)라고 하자.
      3. usingIteratorundefined가 아니면,
        1. values를 ? IteratorToList(? GetIteratorFromMethod(firstArgument, usingIterator))라고 하자.
        2. InitializeTypedArrayFromList(obj, values)를 수행한다.
      4. 그렇지 않으면,
        1. NOTE: firstArgument는 반복 가능 객체가 아니므로, 이미 배열 유사 객체라고 가정한다.
        2. InitializeTypedArrayFromArrayLike(obj, firstArgument)를 수행한다.
    5. obj를 반환한다.
  8. Assert: firstArgument는 Object가 아니다.
  9. elementLength를 ? ToIndex(firstArgument)라고 하자.
  10. AllocateTypedArray(constructorName, NewTarget, proto, elementLength)를 반환한다.

23.2.5.1.1 AllocateTypedArray ( constructorName, newTarget, defaultProto [ , length ] )

The abstract operation AllocateTypedArray takes arguments constructorName (a String which is the name of a TypedArray constructor in Table 70), newTarget (a constructor), and defaultProto (a String) and optional argument length (a non-negative integer) and returns either a normal completion containing a TypedArray or a throw completion. TypedArray 생성자의 인스턴스를 검증하고 생성하는 데 사용된다. length 인자가 전달되면, 그 길이의 ArrayBuffer도 할당되어 새 TypedArray 인스턴스와 연결된다. AllocateTypedArray는 TypedArray가 사용하는 공통 의미론을 제공한다. It performs the following steps when called:

  1. proto를 ? GetPrototypeFromConstructor(newTarget, defaultProto)라고 하자.
  2. objTypedArrayCreate(proto)라고 하자.
  3. Assert: obj.[[ViewedArrayBuffer]]undefined이다.
  4. obj.[[TypedArrayName]]constructorName으로 설정한다.
  5. constructorName"BigInt64Array" 또는 "BigUint64Array"이면, obj.[[ContentType]]bigint로 설정한다.
  6. 그렇지 않으면, obj.[[ContentType]]number로 설정한다.
  7. length가 존재하지 않으면,
    1. obj.[[ByteLength]]를 0으로 설정한다.
    2. obj.[[ByteOffset]]을 0으로 설정한다.
    3. obj.[[ArrayLength]]를 0으로 설정한다.
  8. 그렇지 않으면,
    1. AllocateTypedArrayBuffer(obj, length)를 수행한다.
  9. obj를 반환한다.

23.2.5.1.2 InitializeTypedArrayFromTypedArray ( obj, srcArray )

The abstract operation InitializeTypedArrayFromTypedArray takes arguments obj (a TypedArray) and srcArray (a TypedArray) and returns either a normal completion containing unused or a throw completion. It performs the following steps when called:

  1. srcDatasrcArray.[[ViewedArrayBuffer]]라고 하자.
  2. elementTypeTypedArrayElementType(obj)이라고 하자.
  3. elementSizeTypedArrayElementSize(obj)라고 하자.
  4. srcTypeTypedArrayElementType(srcArray)라고 하자.
  5. srcElementSizeTypedArrayElementSize(srcArray)라고 하자.
  6. srcByteOffsetsrcArray.[[ByteOffset]]이라고 하자.
  7. srcRecordMakeTypedArrayWithBufferWitnessRecord(srcArray, seq-cst)라고 하자.
  8. IsTypedArrayOutOfBounds(srcRecord)가 true이면, TypeError 예외를 던진다.
  9. elementLengthTypedArrayLength(srcRecord)라고 하자.
  10. byteLengthelementSize × elementLength라고 하자.
  11. elementTypesrcType이면,
    1. data를 ? CloneArrayBuffer(srcData, srcByteOffset, byteLength)라고 하자.
  12. 그렇지 않으면,
    1. data를 ? AllocateArrayBuffer(%ArrayBuffer%, byteLength)라고 하자.
    2. srcArray.[[ContentType]]obj.[[ContentType]]가 아니면, TypeError 예외를 던진다.
    3. srcByteIndexsrcByteOffset이라고 하자.
    4. targetByteIndex를 0이라고 하자.
    5. countelementLength라고 하자.
    6. count > 0인 동안 반복한다,
      1. valueGetValueFromBuffer(srcData, srcByteIndex, srcType, true, unordered)라고 하자.
      2. SetValueInBuffer(data, targetByteIndex, elementType, value, true, unordered)를 수행한다.
      3. srcByteIndexsrcByteIndex + srcElementSize로 설정한다.
      4. targetByteIndextargetByteIndex + elementSize로 설정한다.
      5. countcount - 1로 설정한다.
  13. obj.[[ViewedArrayBuffer]]data로 설정한다.
  14. obj.[[ByteLength]]byteLength로 설정한다.
  15. obj.[[ByteOffset]]을 0으로 설정한다.
  16. obj.[[ArrayLength]]elementLength로 설정한다.
  17. unused를 반환한다.

23.2.5.1.3 InitializeTypedArrayFromArrayBuffer ( obj, buffer, byteOffset, length )

The abstract operation InitializeTypedArrayFromArrayBuffer takes arguments obj (a TypedArray), buffer (an ArrayBuffer or a SharedArrayBuffer), byteOffset (an ECMAScript language value), and length (an ECMAScript language value) and returns either a normal completion containing unused or a throw completion. It performs the following steps when called:

  1. elementSizeTypedArrayElementSize(obj)라고 하자.
  2. offset을 ? ToIndex(byteOffset)이라고 하자.
  3. offset modulo elementSize ≠ 0이면, RangeError 예외를 던진다.
  4. bufferIsFixedLengthIsFixedLengthArrayBuffer(buffer)라고 하자.
  5. lengthundefined가 아니면,
    1. newLength를 ? ToIndex(length)라고 하자.
  6. IsDetachedBuffer(buffer)가 true이면, TypeError 예외를 던진다.
  7. bufferByteLengthArrayBufferByteLength(buffer, seq-cst)라고 하자.
  8. lengthundefined이고 bufferIsFixedLengthfalse이면,
    1. offset > bufferByteLength이면, RangeError 예외를 던진다.
    2. obj.[[ByteLength]]auto로 설정한다.
    3. obj.[[ArrayLength]]auto로 설정한다.
  9. 그렇지 않으면,
    1. lengthundefined이면,
      1. bufferByteLength modulo elementSize ≠ 0이면, RangeError 예외를 던진다.
      2. newByteLengthbufferByteLength - offset이라고 하자.
      3. newByteLength < 0이면, RangeError 예외를 던진다.
    2. 그렇지 않으면,
      1. newByteLengthnewLength × elementSize라고 하자.
      2. offset + newByteLength > bufferByteLength이면, RangeError 예외를 던진다.
    3. obj.[[ByteLength]]newByteLength로 설정한다.
    4. obj.[[ArrayLength]]newByteLength / elementSize로 설정한다.
  10. obj.[[ViewedArrayBuffer]]buffer로 설정한다.
  11. obj.[[ByteOffset]]offset으로 설정한다.
  12. unused를 반환한다.

23.2.5.1.4 InitializeTypedArrayFromList ( obj, values )

The abstract operation InitializeTypedArrayFromList takes arguments obj (a TypedArray) and values (a List of ECMAScript language values) and returns either a normal completion containing unused or a throw completion. It performs the following steps when called:

  1. lenvalues의 요소 개수라고 하자.
  2. AllocateTypedArrayBuffer(obj, len)를 수행한다.
  3. k를 0이라고 하자.
  4. k < len인 동안 반복한다,
    1. propertyKey를 ! ToString(𝔽(k))라고 하자.
    2. kValuevalues의 첫 번째 요소라고 하자.
    3. values에서 첫 번째 요소를 제거한다.
    4. Set(obj, propertyKey, kValue, true)를 수행한다.
    5. kk + 1로 설정한다.
  5. Assert: values는 이제 빈 List이다.
  6. unused를 반환한다.

23.2.5.1.5 InitializeTypedArrayFromArrayLike ( obj, arrayLike )

The abstract operation InitializeTypedArrayFromArrayLike takes arguments obj (a TypedArray) and arrayLike (an Object, but not a TypedArray or an ArrayBuffer) and returns either a normal completion containing unused or a throw completion. It performs the following steps when called:

  1. len을 ? LengthOfArrayLike(arrayLike)라고 하자.
  2. AllocateTypedArrayBuffer(obj, len)를 수행한다.
  3. k를 0이라고 하자.
  4. k < len인 동안 반복한다,
    1. propertyKey를 ! ToString(𝔽(k))라고 하자.
    2. kValue를 ? Get(arrayLike, propertyKey)라고 하자.
    3. Set(obj, propertyKey, kValue, true)를 수행한다.
    4. kk + 1로 설정한다.
  5. unused를 반환한다.

23.2.5.1.6 AllocateTypedArrayBuffer ( obj, length )

The abstract operation AllocateTypedArrayBuffer takes arguments obj (a TypedArray) and length (a non-negative integer) and returns either a normal completion containing unused or a throw completion. obj에 ArrayBuffer를 할당하고 연결한다. It performs the following steps when called:

  1. Assert: obj.[[ViewedArrayBuffer]]undefined이다.
  2. elementSizeTypedArrayElementSize(obj)라고 하자.
  3. byteLengthelementSize × length라고 하자.
  4. data를 ? AllocateArrayBuffer(%ArrayBuffer%, byteLength)라고 하자.
  5. obj.[[ViewedArrayBuffer]]data로 설정한다.
  6. obj.[[ByteLength]]byteLength로 설정한다.
  7. obj.[[ByteOffset]]을 0으로 설정한다.
  8. obj.[[ArrayLength]]length로 설정한다.
  9. unused를 반환한다.

23.2.6 TypedArray 생성자의 속성

TypedArray 생성자는:

  • 값이 %TypedArray%[[Prototype]] 내부 슬롯을 가진다.
  • 값이 3𝔽"length" 속성을 가진다.
  • 값이 Table 70에서 그 생성자에 대해 지정된 생성자 이름의 String 값인 "name" 속성을 가진다.
  • 다음 속성들을 가진다:

23.2.6.1 TypedArray.BYTES_PER_ELEMENT

TypedArray.BYTES_PER_ELEMENT의 값은 TypedArray에 대해 Table 70에 지정된 Element Size 값이다.

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

23.2.6.2 TypedArray.prototype

TypedArray.prototype의 초기값은 대응하는 TypedArray 프로토타입 내재 객체(23.2.7)이다.

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

23.2.7 TypedArray 프로토타입 객체의 속성

TypedArray 프로토타입 객체는:

  • 값이 %TypedArray.prototype%[[Prototype]] 내부 슬롯을 가진다.
  • 보통 객체이다.
  • [[ViewedArrayBuffer]]TypedArray 인스턴스 객체에 특유한 다른 어떤 내부 슬롯도 가지지 않는다.

23.2.7.1 TypedArray.prototype.BYTES_PER_ELEMENT

TypedArray.prototype.BYTES_PER_ELEMENT의 값은 TypedArray에 대해 Table 70에 지정된 Element Size 값이다.

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

23.2.7.2 TypedArray.prototype.constructor

주어진 TypedArray 생성자의 프로토타입의 "constructor" 속성의 초기값은 생성자 자체이다.

23.2.8 TypedArray 인스턴스의 속성

TypedArray 인스턴스는 TypedArray이다. 각 TypedArray 인스턴스는 대응하는 TypedArray 프로토타입 객체로부터 속성을 상속한다. 각 TypedArray 인스턴스는 다음 내부 슬롯을 가진다: [[ViewedArrayBuffer]], [[TypedArrayName]], [[ContentType]], [[ByteLength]], [[ByteOffset]], 및 [[ArrayLength]].

23.3 Uint8Array 객체

Uint8Array는 위에 설명된 TypedArray의 특정 종류이다. 또한 Uint8Array 생성자(23.3.1)와 Uint8Array 프로토타입 객체(23.3.2)에는 추가 메서드가 있다.

23.3.1 Uint8Array 생성자의 추가 속성

23.3.1.1 Uint8Array.fromBase64 ( string [ , options ] )

  1. string이 String이 아니면, TypeError 예외를 던진다.
  2. opts를 ? GetOptionsObject(options)라고 하자.
  3. alphabet을 ? Get(opts, "alphabet")이라고 하자.
  4. alphabetundefined이면, alphabet"base64"로 설정한다.
  5. alphabet"base64""base64url"도 아니면, TypeError 예외를 던진다.
  6. lastChunkHandling을 ? Get(opts, "lastChunkHandling")이라고 하자.
  7. lastChunkHandlingundefined이면, lastChunkHandling"loose"로 설정한다.
  8. lastChunkHandling"loose", "strict", 또는 "stop-before-partial" 중 하나가 아니면, TypeError 예외를 던진다.
  9. resultFromBase64(string, alphabet, lastChunkHandling)라고 하자.
  10. result.[[Error]]none이 아니면,
    1. result.[[Error]]를 던진다.
  11. resultLengthresult.[[Bytes]]의 요소 개수라고 하자.
  12. ta를 ? AllocateTypedArray("Uint8Array", %Uint8Array%, "%Uint8Array.prototype%", resultLength)라고 하자.
  13. Assert: ta.[[ViewedArrayBuffer]].[[ArrayBufferByteLength]]result.[[Bytes]]의 요소 개수이다.
  14. ta.[[ViewedArrayBuffer]].[[ArrayBufferData]]의 각 인덱스 값을 result.[[Bytes]]의 대응하는 인덱스 값으로 설정한다.
  15. ta를 반환한다.

23.3.1.2 Uint8Array.fromHex ( string )

  1. string이 String이 아니면, TypeError 예외를 던진다.
  2. resultFromHex(string)라고 하자.
  3. result.[[Error]]none이 아니면,
    1. result.[[Error]]를 던진다.
  4. resultLengthresult.[[Bytes]]의 요소 개수라고 하자.
  5. ta를 ? AllocateTypedArray("Uint8Array", %Uint8Array%, "%Uint8Array.prototype%", resultLength)라고 하자.
  6. Assert: ta.[[ViewedArrayBuffer]].[[ArrayBufferByteLength]]result.[[Bytes]]의 요소 개수이다.
  7. ta.[[ViewedArrayBuffer]].[[ArrayBufferData]]의 각 인덱스 값을 result.[[Bytes]]의 대응하는 인덱스 값으로 설정한다.
  8. ta를 반환한다.

23.3.2 Uint8Array 프로토타입 객체의 추가 속성

23.3.2.1 Uint8Array.prototype.setFromBase64 ( string [ , options ] )

  1. intothis 값이라고 하자.
  2. ValidateUint8Array(into)를 수행한다.
  3. string이 String이 아니면, TypeError 예외를 던진다.
  4. opts를 ? GetOptionsObject(options)라고 하자.
  5. alphabet을 ? Get(opts, "alphabet")이라고 하자.
  6. alphabetundefined이면, alphabet"base64"로 설정한다.
  7. alphabet"base64""base64url"도 아니면, TypeError 예외를 던진다.
  8. lastChunkHandling을 ? Get(opts, "lastChunkHandling")이라고 하자.
  9. lastChunkHandlingundefined이면, lastChunkHandling"loose"로 설정한다.
  10. lastChunkHandling"loose", "strict", 또는 "stop-before-partial" 중 하나가 아니면, TypeError 예외를 던진다.
  11. taRecordMakeTypedArrayWithBufferWitnessRecord(into, seq-cst)라고 하자.
  12. IsTypedArrayOutOfBounds(taRecord)가 true이면, TypeError 예외를 던진다.
  13. byteLengthTypedArrayLength(taRecord)라고 하자.
  14. resultFromBase64(string, alphabet, lastChunkHandling, byteLength)라고 하자.
  15. bytesresult.[[Bytes]]라고 하자.
  16. writtenbytes의 요소 개수라고 하자.
  17. NOTE: FromBase64는 어떤 사용자 코드도 호출하지 않으므로, into를 뒷받침하는 ArrayBuffer는 detached되거나 축소될 수 없다.
  18. Assert: writtenbyteLength.
  19. SetUint8ArrayBytes(into, bytes)를 수행한다.
  20. result.[[Error]]none이 아니면,
    1. result.[[Error]]를 던진다.
  21. resultObjectOrdinaryObjectCreate(%Object.prototype%)라고 하자.
  22. CreateDataPropertyOrThrow(resultObject, "read", 𝔽(result.[[Read]]))를 수행한다.
  23. CreateDataPropertyOrThrow(resultObject, "written", 𝔽(written))를 수행한다.
  24. resultObject를 반환한다.

23.3.2.2 Uint8Array.prototype.setFromHex ( string )

  1. intothis 값이라고 하자.
  2. ValidateUint8Array(into)를 수행한다.
  3. string이 String이 아니면, TypeError 예외를 던진다.
  4. taRecordMakeTypedArrayWithBufferWitnessRecord(into, seq-cst)라고 하자.
  5. IsTypedArrayOutOfBounds(taRecord)가 true이면, TypeError 예외를 던진다.
  6. byteLengthTypedArrayLength(taRecord)라고 하자.
  7. resultFromHex(string, byteLength)라고 하자.
  8. bytesresult.[[Bytes]]라고 하자.
  9. writtenbytes의 요소 개수라고 하자.
  10. NOTE: FromHex는 어떤 사용자 코드도 호출하지 않으므로, into를 뒷받침하는 ArrayBuffer는 detached되거나 축소될 수 없다.
  11. Assert: writtenbyteLength.
  12. SetUint8ArrayBytes(into, bytes)를 수행한다.
  13. result.[[Error]]none이 아니면,
    1. result.[[Error]]를 던진다.
  14. resultObjectOrdinaryObjectCreate(%Object.prototype%)라고 하자.
  15. CreateDataPropertyOrThrow(resultObject, "read", 𝔽(result.[[Read]]))를 수행한다.
  16. CreateDataPropertyOrThrow(resultObject, "written", 𝔽(written))를 수행한다.
  17. resultObject를 반환한다.

23.3.2.3 Uint8Array.prototype.toBase64 ( [ options ] )

  1. objthis 값이라고 하자.
  2. ValidateUint8Array(obj)를 수행한다.
  3. opts를 ? GetOptionsObject(options)라고 하자.
  4. alphabet을 ? Get(opts, "alphabet")이라고 하자.
  5. alphabetundefined이면, alphabet"base64"로 설정한다.
  6. alphabet"base64""base64url"도 아니면, TypeError 예외를 던진다.
  7. omitPaddingToBoolean(? Get(opts, "omitPadding"))이라고 하자.
  8. toEncode를 ? GetUint8ArrayBytes(obj)라고 하자.
  9. alphabet"base64"이면,
    1. outAsciiRFC 4648의 4절에 지정된 base64 인코딩에 따라 toEncode를 인코딩한 결과인 코드 포인트들의 시퀀스라고 하자. 패딩은 omitPaddingfalse인 경우에만 포함된다.
  10. 그렇지 않으면,
    1. Assert: alphabet"base64url"이다.
    2. outAsciiRFC 4648의 5절에 지정된 base64url 인코딩에 따라 toEncode를 인코딩한 결과인 코드 포인트들의 시퀀스라고 하자. 패딩은 omitPaddingfalse인 경우에만 포함된다.
  11. CodePointsToString(outAscii)를 반환한다.

23.3.2.4 Uint8Array.prototype.toHex ( )

  1. objthis 값이라고 하자.
  2. ValidateUint8Array(obj)를 수행한다.
  3. toEncode를 ? GetUint8ArrayBytes(obj)라고 하자.
  4. out을 빈 String이라고 하자.
  5. toEncode의 각 바이트 byte에 대해, 다음을 수행한다.
    1. hexNumber::toString(𝔽(byte), 16)이라고 하자.
    2. hexStringPad(hex, 2, "0", start)로 설정한다.
    3. outouthex의 문자열 연결로 설정한다.
  6. out을 반환한다.

23.3.3 Uint8Array 객체를 위한 추상 연산

23.3.3.1 ValidateUint8Array ( ta )

The abstract operation ValidateUint8Array takes argument ta (an ECMAScript language value) and returns either a normal completion containing unused or a throw completion. It performs the following steps when called:

  1. RequireInternalSlot(ta, [[TypedArrayName]])를 수행한다.
  2. ta.[[TypedArrayName]]"Uint8Array"가 아니면, TypeError 예외를 던진다.
  3. unused를 반환한다.

23.3.3.2 GetUint8ArrayBytes ( ta )

The abstract operation GetUint8ArrayBytes takes argument ta (a Uint8Array) and returns either a normal completion containing a List of byte values or a throw completion. It performs the following steps when called:

  1. bufferta.[[ViewedArrayBuffer]]라고 하자.
  2. taRecordMakeTypedArrayWithBufferWitnessRecord(ta, seq-cst)라고 하자.
  3. IsTypedArrayOutOfBounds(taRecord)가 true이면, TypeError 예외를 던진다.
  4. lenTypedArrayLength(taRecord)라고 하자.
  5. byteOffsetta.[[ByteOffset]]이라고 하자.
  6. bytes를 새로운 빈 List라고 하자.
  7. index를 0이라고 하자.
  8. index < len인 동안 반복한다,
    1. byteIndexbyteOffset + index라고 하자.
    2. byte(GetValueFromBuffer(buffer, byteIndex, uint8, true, unordered))라고 하자.
    3. bytebytes에 추가한다.
    4. indexindex + 1로 설정한다.
  9. bytes를 반환한다.

23.3.3.3 SetUint8ArrayBytes ( into, bytes )

The abstract operation SetUint8ArrayBytes takes arguments into (a Uint8Array) and bytes (a List of byte values) and returns unused. It performs the following steps when called:

  1. offsetinto.[[ByteOffset]]이라고 하자.
  2. lenbytes의 요소 개수라고 하자.
  3. index를 0이라고 하자.
  4. index < len인 동안 반복한다,
    1. bytebytes[index]라고 하자.
    2. byteIndexInBufferindex + offset이라고 하자.
    3. SetValueInBuffer(into.[[ViewedArrayBuffer]], byteIndexInBuffer, uint8, 𝔽(byte), true, unordered)를 수행한다.
    4. indexindex + 1로 설정한다.
  5. unused를 반환한다.

23.3.3.4 SkipAsciiWhitespace ( string, index )

The abstract operation SkipAsciiWhitespace takes arguments string (a String) and index (a non-negative integer) and returns a non-negative integer. It performs the following steps when called:

  1. lengthstring의 길이라고 하자.
  2. index < length인 동안 반복한다,
    1. charstring 안의 인덱스 index에 있는 코드 단위라고 하자.
    2. char가 0x0009 (TAB), 0x000A (LF), 0x000C (FF), 0x000D (CR), 또는 0x0020 (SPACE) 중 하나가 아니면,
      1. index를 반환한다.
    3. indexindex + 1로 설정한다.
  3. index를 반환한다.

23.3.3.5 DecodeFinalBase64Chunk ( chunk, throwOnExtraBits )

The abstract operation DecodeFinalBase64Chunk takes arguments chunk (a String of length 2 or 3) and throwOnExtraBits (a Boolean) and returns either a normal completion containing a List of byte values, or a throw completion. It performs the following steps when called:

  1. chunkLengthchunk의 길이라고 하자.
  2. chunkLength = 2이면,
    1. chunkchunk"AA"의 문자열 연결로 설정한다.
  3. 그렇지 않으면,
    1. Assert: chunkLength는 3이다.
    2. chunkchunk"A"의 문자열 연결로 설정한다.
  4. bytesDecodeFullLengthBase64Chunk(chunk)라고 하자.
  5. chunkLength = 2이면,
    1. throwOnExtraBitstrue이고 bytes[1] ≠ 0이면, SyntaxError 예외를 던진다.
    2. « bytes[0] »를 반환한다.
  6. throwOnExtraBitstrue이고 bytes[2] ≠ 0이면, SyntaxError 예외를 던진다.
  7. « bytes[0], bytes[1] »를 반환한다.

23.3.3.6 DecodeFullLengthBase64Chunk ( chunk )

The abstract operation DecodeFullLengthBase64Chunk takes argument chunk (a String of length 4) and returns a List of byte values of length 3.

표준 base64 알파벳"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"이다. 즉 Unicode Basic Latin 블록의 모든 문자와 숫자에 대응하는 코드 단위들과 "+""/"를 요소로 가지는 String이다.

  1. byteSequencechunk를 base64로 디코딩한 결과인 고유한 3바이트 시퀀스라고 하자(즉, RFC 4648의 4절에 지정된 base64 인코딩을 byteSequence에 적용하면 chunk가 생성되는 그러한 시퀀스).
  2. byteSequence의 요소들을 순서대로 요소로 가지는 List를 반환한다.

23.3.3.7 FromBase64 ( string, alphabet, lastChunkHandling [ , maxLength ] )

The abstract operation FromBase64 takes arguments string (a String), alphabet ("base64" or "base64url"), and lastChunkHandling ("loose", "strict", or "stop-before-partial") and optional argument maxLength (a non-negative integer) and returns a Record with fields [[Read]] (an integer), [[Bytes]] (a List of byte values), and [[Error]] (a SyntaxError object or none). It performs the following steps when called:

  1. maxLength가 존재하지 않으면,
    1. maxLength를 253 - 1로 설정한다.
    2. NOTE: 입력이 String이므로, String의 길이는 253 - 1 문자로 제한되고, 출력은 입력이 가진 문자 수보다 많은 바이트를 요구하지 않으므로, 이 한계에는 결코 도달할 수 없다. 그러나 유한 값을 사용하는 것이 편집상 편리하다.
  2. NOTE: 아래 알고리즘에서 검증과 디코딩의 순서는 관찰 가능하지 않다. 구현은 가장 효율적인 어떤 순서로든, 가능하면 검증과 디코딩을 인터리브하여 수행하는 것이 권장된다.
  3. maxLength = 0이면,
    1. Record { [[Read]]: 0, [[Bytes]]: « », [[Error]]: none }를 반환한다.
  4. read를 0이라고 하자.
  5. bytes를 새로운 빈 List라고 하자.
  6. chunk를 빈 String이라고 하자.
  7. chunkLength를 0이라고 하자.
  8. index를 0이라고 하자.
  9. lengthstring의 길이라고 하자.
  10. 반복한다,
    1. indexSkipAsciiWhitespace(string, index)로 설정한다.
    2. index = length이면,
      1. chunkLength > 0이면,
        1. lastChunkHandling"stop-before-partial"이면,
          1. Record { [[Read]]: read, [[Bytes]]: bytes, [[Error]]: none }를 반환한다.
        2. lastChunkHandling"strict"이면,
          1. error를 새로 생성된 SyntaxError 객체라고 하자.
          2. Record { [[Read]]: read, [[Bytes]]: bytes, [[Error]]: error }를 반환한다.
        3. Assert: lastChunkHandling"loose"이다.
        4. chunkLength = 1이면,
          1. error를 새로 생성된 SyntaxError 객체라고 하자.
          2. Record { [[Read]]: read, [[Bytes]]: bytes, [[Error]]: error }를 반환한다.
        5. bytesbytes와 ! DecodeFinalBase64Chunk(chunk, false)의 리스트 연결로 설정한다.
      2. Record { [[Read]]: length, [[Bytes]]: bytes, [[Error]]: none }를 반환한다.
    3. charstringindex부터 index + 1까지의 부분 문자열이라고 하자.
    4. indexindex + 1로 설정한다.
    5. char"="이면,
      1. chunkLength < 2이면,
        1. error를 새로 생성된 SyntaxError 객체라고 하자.
        2. Record { [[Read]]: read, [[Bytes]]: bytes, [[Error]]: error }를 반환한다.
      2. indexSkipAsciiWhitespace(string, index)로 설정한다.
      3. chunkLength = 2이면,
        1. index = length이면,
          1. lastChunkHandling"stop-before-partial"이면,
            1. Record { [[Read]]: read, [[Bytes]]: bytes, [[Error]]: none }를 반환한다.
          2. error를 새로 생성된 SyntaxError 객체라고 하자.
          3. Record { [[Read]]: read, [[Bytes]]: bytes, [[Error]]: error }를 반환한다.
        2. charstringindex부터 index + 1까지의 부분 문자열로 설정한다.
        3. char"="이면,
          1. indexSkipAsciiWhitespace(string, index + 1)로 설정한다.
      4. index < length이면,
        1. error를 새로 생성된 SyntaxError 객체라고 하자.
        2. Record { [[Read]]: read, [[Bytes]]: bytes, [[Error]]: error }를 반환한다.
      5. lastChunkHandling"strict"이면 throwOnExtraBitstrue라고 하자; 그렇지 않으면 throwOnExtraBitsfalse라고 하자.
      6. decodeResultCompletion(DecodeFinalBase64Chunk(chunk, throwOnExtraBits))라고 하자.
      7. decodeResultabrupt completion이면,
        1. errordecodeResult.[[Value]]라고 하자.
        2. Record { [[Read]]: read, [[Bytes]]: bytes, [[Error]]: error }를 반환한다.
      8. bytesbytes와 ! decodeResult의 리스트 연결로 설정한다.
      9. Record { [[Read]]: length, [[Bytes]]: bytes, [[Error]]: none }를 반환한다.
    6. alphabet"base64url"이면,
      1. char"+" 또는 "/"이면,
        1. error를 새로 생성된 SyntaxError 객체라고 하자.
        2. Record { [[Read]]: read, [[Bytes]]: bytes, [[Error]]: error }를 반환한다.
      2. 그렇지 않고 char"-"이면,
        1. char"+"로 설정한다.
      3. 그렇지 않고 char"_"이면,
        1. char"/"로 설정한다.
    7. char의 유일한 코드 단위가 표준 base64 알파벳의 요소가 아니면,
      1. error를 새로 생성된 SyntaxError 객체라고 하자.
      2. Record { [[Read]]: read, [[Bytes]]: bytes, [[Error]]: error }를 반환한다.
    8. remainingmaxLength - bytes의 요소 개수라고 하자.
    9. remaining = 1이고 chunkLength = 2이거나, remaining = 2이고 chunkLength = 3이면,
      1. Record { [[Read]]: read, [[Bytes]]: bytes, [[Error]]: none }를 반환한다.
    10. chunkchunkchar의 문자열 연결로 설정한다.
    11. chunkLengthchunk의 길이로 설정한다.
    12. chunkLength = 4이면,
      1. bytesbytesDecodeFullLengthBase64Chunk(chunk)의 리스트 연결로 설정한다.
      2. chunk를 빈 String으로 설정한다.
      3. chunkLength를 0으로 설정한다.
      4. readindex로 설정한다.
      5. bytes의 요소 개수 = maxLength이면,
        1. Record { [[Read]]: read, [[Bytes]]: bytes, [[Error]]: none }를 반환한다.

23.3.3.8 FromHex ( string [ , maxLength ] )

The abstract operation FromHex takes argument string (a String) and optional argument maxLength (a non-negative integer) and returns a Record with fields [[Read]] (an integer), [[Bytes]] (a List of byte values), and [[Error]] (a SyntaxError object or none). It performs the following steps when called:

  1. maxLength가 존재하지 않으면, maxLength를 253 - 1로 설정한다.
  2. lengthstring의 길이라고 하자.
  3. bytes를 새로운 빈 List라고 하자.
  4. read를 0이라고 하자.
  5. length modulo 2 ≠ 0이면,
    1. error를 새로 생성된 SyntaxError 객체라고 하자.
    2. Record { [[Read]]: read, [[Bytes]]: bytes, [[Error]]: error }를 반환한다.
  6. read < length이고 bytes의 요소 개수 < maxLength인 동안 반복한다,
    1. hexitsstringread부터 read + 2까지의 부분 문자열이라고 하자.
    2. hexits"0123456789abcdefABCDEF" 안에 있지 않은 코드 단위를 포함하면,
      1. error를 새로 생성된 SyntaxError 객체라고 하자.
      2. Record { [[Read]]: read, [[Bytes]]: bytes, [[Error]]: error }를 반환한다.
    3. readread + 2로 설정한다.
    4. byte를 10부터 15까지의 값을 가진 숫자에 대해 문자 A부터 Fa부터 f를 사용하여, base-16 표기법으로 hexits가 나타내는 정수 값이라고 하자.
    5. bytebytes에 추가한다.
  7. Record { [[Read]]: read, [[Bytes]]: bytes, [[Error]]: none }를 반환한다.