20 기본 객체

20.1 Object 객체들

20.1.1 Object 생성자

Object 생성자:

  • %Object%이다.
  • 전역 객체"Object" 속성의 초기 값이다.
  • 생성자로 호출될 때 새로운 일반 객체를 생성한다.
  • 생성자가 아닌 함수로 호출될 때 형 변환을 수행한다.
  • 클래스 정의의 extends 절의 값으로 사용될 수 있다.

20.1.1.1 Object ( value )

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

  1. 만약 NewTarget가 undefined도 아니고 활성 함수 객체도 아니라면,
    1. OrdinaryCreateFromConstructor(NewTarget, "%Object.prototype%")를 반환한다.
  2. 만약 valueundefined 또는 null이면 OrdinaryObjectCreate(%Object.prototype%)를 반환한다.
  3. ToObject(value)를 반환한다.

20.1.2 Object 생성자의 속성들

Object 생성자:

  • 값이 %Function.prototype%[[Prototype]] 내부 슬롯을 가진다.
  • 다음의 추가적인 속성들을 가진다:

20.1.2.1 Object.assign ( target, ...sources )

이 함수는 하나 이상의 소스 객체로부터 열거 가능한 모든 자체 속성의 값을 target 객체로 복사한다.

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

  1. to를 ? ToObject(target)로 하자.
  2. 인수가 하나만 전달된다면 to를 반환한다.
  3. sources의 각 요소 nextSource에 대해
    1. 만약 nextSourceundefined도 아니고 null도 아니면,
      1. from을 ! ToObject(nextSource)로 하자.
      2. keys를 ? from.[[OwnPropertyKeys]]()로 하자.
      3. keys의 각 요소 nextKey에 대해
        1. desc를 ? from.[[GetOwnProperty]](nextKey)로 하자.
        2. 만약 descundefined가 아니고 desc.[[Enumerable]]true이면,
          1. propValue를 ? Get(from, nextKey)로 하자.
          2. Perform ? Set(to, nextKey, propValue, true).
  4. to를 반환한다.

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

20.1.2.2 Object.create ( proto, properties )

이 함수는 지정된 프로토타입을 가진 새로운 객체를 만든다.

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

  1. 만약 proto가 객체가 아니고 protonull도 아니면, TypeError 예외를 던진다.
  2. objOrdinaryObjectCreate(proto)로 하자.
  3. 만약 propertiesundefined가 아니면,
    1. ObjectDefineProperties(obj, properties)를 반환한다.
  4. obj를 반환한다.

20.1.2.3 Object.defineProperties ( obj, properties )

이 함수는 객체의 자체 속성을 추가하고/또는 기존 자체 속성의 속성들을 갱신한다.

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

  1. 만약 obj가 객체가 아니면, TypeError 예외를 던진다.
  2. ObjectDefineProperties(obj, properties)를 반환한다.

20.1.2.3.1 ObjectDefineProperties ( obj, properties )

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

  1. props를 ? ToObject(properties)로 하자.
  2. keys를 ? props.[[OwnPropertyKeys]]()로 하자.
  3. descriptors를 새로운 빈 목록으로 하자.
  4. keys의 각 요소 nextKey에 대해
    1. propDesc를 ? props.[[GetOwnProperty]](nextKey)로 하자.
    2. 만약 propDescundefined가 아니고 propDesc.[[Enumerable]]true이면,
      1. descObj를 ? Get(props, nextKey)로 하자.
      2. desc를 ? ToPropertyDescriptor(descObj)로 하자.
      3. 레코드 { [[Key]]: nextKey, [[Descriptor]]: desc }를 descriptors에 추가하라.
  5. descriptors의 각 요소 property에 대해
    1. Perform ? DefinePropertyOrThrow(obj, property.[[Key]], property.[[Descriptor]]).
  6. obj를 반환하라.

20.1.2.4 Object.defineProperty ( obj, propertyKey, attributes )

이 함수는 객체의 자체 속성을 추가하고/또는 기존 자체 속성의 속성을 갱신한다.

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

  1. 만약 obj가 객체가 아니면, TypeError 예외를 던진다.
  2. key를 ? ToPropertyKey(propertyKey)로 하자.
  3. desc를 ? ToPropertyDescriptor(attributes)로 하자.
  4. Perform ? DefinePropertyOrThrow(obj, key, desc).
  5. obj를 반환하라.

20.1.2.5 Object.entries ( obj )

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

  1. coerced를 ? ToObject(obj)로 하자.
  2. entryList를 ? EnumerableOwnProperties(coerced, key+value)로 하자.
  3. CreateArrayFromList(entryList)를 반환하라.

20.1.2.6 Object.freeze ( obj )

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

  1. 만약 obj가 객체가 아니면 obj를 반환한다.
  2. status를 ? SetIntegrityLevel(obj, frozen)로 하자.
  3. 만약 statusfalse이면 TypeError 예외를 던진다.
  4. obj를 반환한다.

20.1.2.7 Object.fromEntries ( iterable )

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

  1. Perform ? RequireObjectCoercible(iterable).
  2. objOrdinaryObjectCreate(%Object.prototype%)로 하자.
  3. 단언: obj는 자체 속성이 없는 확장 가능한 일반 객체이다.
  4. closureobj를 캡처하고 호출될 때 다음 단계를 수행하는 매개변수 (key, value)를 가진 새로운 추상 클로저로 하자:
    1. propertyKey를 ? ToPropertyKey(key)로 하자.
    2. Perform ! CreateDataPropertyOrThrow(obj, propertyKey, value).
    3. NormalCompletion(undefined)를 반환하라.
  5. adderCreateBuiltinFunction(closure, 2, "", « »)로 하자.
  6. Return ? AddEntriesFromIterable(obj, iterable, adder).
Note
adder를 위해 생성된 함수는 ECMAScript 코드에서 직접 접근할 수 없다.

20.1.2.8 Object.getOwnPropertyDescriptor ( obj, propertyKey )

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

  1. coerced를 ? ToObject(obj)로 하자.
  2. key를 ? ToPropertyKey(propertyKey)로 하자.
  3. desc를 ? coerced.[[GetOwnProperty]](key)로 하자.
  4. FromPropertyDescriptor(desc)를 반환하라.

20.1.2.9 Object.getOwnPropertyDescriptors ( obj )

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

  1. coerced를 ? ToObject(obj)로 하자.
  2. ownKeys를 ? coerced.[[OwnPropertyKeys]]()로 하자.
  3. descriptorsOrdinaryObjectCreate(%Object.prototype%)로 하자.
  4. ownKeys의 각 요소 key에 대해
    1. desc를 ? coerced.[[GetOwnProperty]](key)로 하자.
    2. descriptorFromPropertyDescriptor(desc)로 하자.
    3. 만약 descriptorundefined가 아니면, Perform ! CreateDataPropertyOrThrow(descriptors, key, descriptor).
  5. descriptors를 반환하라.

20.1.2.10 Object.getOwnPropertyNames ( obj )

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

  1. CreateArrayFromList(? GetOwnPropertyKeys(obj, string))를 반환한다.

20.1.2.11 Object.getOwnPropertySymbols ( obj )

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

  1. CreateArrayFromList(? GetOwnPropertyKeys(obj, symbol))를 반환한다.

20.1.2.11.1 GetOwnPropertyKeys ( value, type )

The abstract operation GetOwnPropertyKeys takes arguments value (an ECMAScript language value) and type (string or symbol) and returns either a normal completion containing a List of property keys or a throw completion. It performs the following steps when called:

  1. obj를 ? ToObject(value)로 하자.
  2. keys를 ? obj.[[OwnPropertyKeys]]()로 하자.
  3. nameList를 새로운 빈 목록으로 하자.
  4. keys의 각 요소 nextKey에 대해
    1. 만약 nextKey가 Symbol이고 typesymbol이거나, 또는 nextKey가 String이고 typestring이면,
      1. nextKeynameList에 추가하라.
  5. nameList를 반환하라.

20.1.2.12 Object.getPrototypeOf ( obj )

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

  1. coerced를 ? ToObject(obj)로 하자.
  2. Return ? coerced.[[GetPrototypeOf]]().

20.1.2.13 Object.groupBy ( items, callback )

Note

callback은 두 개의 인수를 받는 함수여야 한다. groupByitems의 각 요소에 대해 오름차순으로 callback을 한 번 호출하여 새로운 객체를 구성한다. callback이 반환하는 각 값은 속성 키로 강제 변환된다. 그러한 속성 키들 각각에 대해 결과 객체는 해당 속성 키를 키로 하고 callback의 반환 값이 해당 키로 강제 변환되는 모든 요소를 포함하는 배열을 값으로 하는 속성을 가진다.

callback은 요소의 값과 요소의 인덱스라는 두 개의 인수로 호출된다.

groupBy의 반환값은 %Object.prototype%로부터 상속되지 않는 객체이다.

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

  1. groups를 ? GroupBy(items, callback, property)로 하자.
  2. objOrdinaryObjectCreate(null)로 하자.
  3. groups의 각 레코드 { [[Key]], [[Elements]] } g에 대해
    1. elementsCreateArrayFromList(g.[[Elements]])로 하자.
    2. Perform ! CreateDataPropertyOrThrow(obj, g.[[Key]], elements).
  4. obj를 반환하라.

20.1.2.14 Object.hasOwn ( obj, propertyKey )

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

  1. coerced를 ? ToObject(obj)로 하자.
  2. key를 ? ToPropertyKey(propertyKey)로 하자.
  3. HasOwnProperty(coerced, key)를 반환하라.

20.1.2.15 Object.is ( value1, value2 )

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

  1. SameValue(value1, value2)를 반환한다.

20.1.2.16 Object.isExtensible ( obj )

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

  1. 만약 obj가 객체가 아니면 false를 반환한다.
  2. Return ? IsExtensible(obj).

20.1.2.17 Object.isFrozen ( obj )

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

  1. 만약 obj가 객체가 아니면 true를 반환한다.
  2. Return ? TestIntegrityLevel(obj, frozen).

20.1.2.18 Object.isSealed ( obj )

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

  1. 만약 obj가 객체가 아니면 true를 반환한다.
  2. Return ? TestIntegrityLevel(obj, sealed).

20.1.2.19 Object.keys ( obj )

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

  1. coerced를 ? ToObject(obj)로 하자.
  2. keyList를 ? EnumerableOwnProperties(coerced, key)로 하자.
  3. CreateArrayFromList(keyList)를 반환하라.

20.1.2.20 Object.preventExtensions ( obj )

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

  1. 만약 obj가 객체가 아니면 obj를 반환한다.
  2. status를 ? obj.[[PreventExtensions]]()로 하자.
  3. 만약 statusfalse이면 TypeError 예외를 던진다.
  4. obj를 반환하라.

20.1.2.21 Object.prototype

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

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

20.1.2.22 Object.seal ( obj )

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

  1. 만약 obj가 객체가 아니면 obj를 반환한다.
  2. status를 ? SetIntegrityLevel(obj, sealed)로 하자.
  3. 만약 statusfalse이면 TypeError 예외를 던진다.
  4. obj를 반환하라.

20.1.2.23 Object.setPrototypeOf ( obj, proto )

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

  1. Perform ? RequireObjectCoercible(obj).
  2. 만약 proto가 객체가 아니고 protonull도 아니면, TypeError 예외를 던진다.
  3. 만약 obj가 객체가 아니면 obj를 반환한다.
  4. status를 ? obj.[[SetPrototypeOf]](proto)로 하자.
  5. 만약 statusfalse이면 TypeError 예외를 던진다.
  6. obj를 반환하라.

20.1.2.24 Object.values ( obj )

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

  1. coerced를 ? ToObject(obj)로 하자.
  2. valueList를 ? EnumerableOwnProperties(coerced, value)로 하자.
  3. CreateArrayFromList(valueList)를 반환하라.

20.1.3 Object 프로토타입 객체의 속성들

Object 프로토타입 객체는:

  • %Object.prototype%이다.
  • 값이 true[[Extensible]] 내부 슬롯을 가진다.
  • 일반 객체용으로 정의된 내부 메서드들을 가지며, [[SetPrototypeOf]] 메서드는 10.4.7.1에 정의된 바와 같다. (따라서, 불변 프로토타입 이국적 객체이다.)
  • 값이 null[[Prototype]] 내부 슬롯을 가진다.

20.1.3.1 Object.prototype.constructor

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

20.1.3.2 Object.prototype.hasOwnProperty ( value )

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

  1. propertyKey를 ? ToPropertyKey(value)로 하자.
  2. obj를 ? ToObject(this value)로 하자.
  3. HasOwnProperty(obj, propertyKey)를 반환하라.
Note

단계 12의 순서는 이전 판본의 이 명세에서 단계 1에 의해 던져졌을 예외가 this 값이 undefined 또는 null인 경우에도 계속 던져지도록 보장하기 위해 선택되었다.

20.1.3.3 Object.prototype.isPrototypeOf ( value )

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

  1. 만약 value가 객체가 아니면 false를 반환한다.
  2. obj를 ? ToObject(this value)로 하자.
  3. 반복,
    1. value를 ? value.[[GetPrototypeOf]]()로 설정하라.
    2. 만약 valuenull이면 false를 반환하라.
    3. 만약 SameValue(obj, value)가 true이면 true를 반환하라.
Note

단계 12의 순서는 이전 판본의 이 명세에서 value가 객체가 아니고 this 값이 undefined 또는 null인 경우에 지정된 동작을 보존한다.

20.1.3.4 Object.prototype.propertyIsEnumerable ( value )

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

  1. propertyKey를 ? ToPropertyKey(value)로 하자.
  2. obj를 ? ToObject(this value)로 하자.
  3. desc를 ? obj.[[GetOwnProperty]](propertyKey)로 하자.
  4. 만약 descundefined이면 false를 반환하라.
  5. desc.[[Enumerable]]를 반환하라.
Note 1

이 메서드는 프로토타입 체인의 객체들은 고려하지 않는다.

Note 2

단계 12의 순서는 이전 판본의 이 명세에서 단계 1에 의해 던져졌을 예외가 this 값이 undefined 또는 null인 경우에도 계속 던져지도록 보장하기 위해 선택되었다.

20.1.3.5 Object.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] )

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

  1. thisValuethis 값으로 하자.
  2. Invoke(thisValue, "toString")를 반환하라.

이 메서드의 선택적 매개변수들은 사용되지 않지만 ECMA-402의 toLocaleString 메서드에서 사용되는 매개변수 패턴에 대응하도록 의도되었다. ECMA-402 지원을 포함하지 않는 구현체는 그 매개변수 위치들을 다른 목적으로 사용해서는 안 된다.

Note 1

이 메서드는 로케일에 민감한 toString 동작이 없는 객체들을 위한 일반적인 toLocaleString 구현을 제공한다. Array, Number, Date, 및 %TypedArray%는 자체적인 로케일 민감 toLocaleString 메서드를 제공한다.

Note 2

ECMA-402는 의도적으로 이 기본 구현에 대한 대안을 제공하지 않는다.

20.1.3.6 Object.prototype.toString ( )

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

  1. 만약 this 값이 undefined이면 "[object Undefined]"를 반환한다.
  2. 만약 this 값이 null이면 "[object Null]"를 반환한다.
  3. obj를 ! ToObject(this value)로 하자.
  4. isArray를 ? IsArray(obj)로 하자.
  5. 만약 isArraytrue이면 builtinTag"Array"로 하자.
  6. 그렇지 않고 obj[[ParameterMap]] 내부 슬롯을 가지고 있으면 builtinTag"Arguments"로 하자.
  7. 그렇지 않고 obj[[Call]] 내부 메서드를 가지고 있으면 builtinTag"Function"로 하자.
  8. 그렇지 않고 obj[[ErrorData]] 내부 슬롯을 가지고 있으면 builtinTag"Error"로 하자.
  9. 그렇지 않고 obj[[BooleanData]] 내부 슬롯을 가지고 있으면 builtinTag"Boolean"로 하자.
  10. 그렇지 않고 obj[[NumberData]] 내부 슬롯을 가지고 있으면 builtinTag"Number"로 하자.
  11. 그렇지 않고 obj[[StringData]] 내부 슬롯을 가지고 있으면 builtinTag"String"로 하자.
  12. 그렇지 않고 obj[[DateValue]] 내부 슬롯을 가지고 있으면 builtinTag"Date"로 하자.
  13. 그렇지 않고 obj[[RegExpMatcher]] 내부 슬롯을 가지고 있으면 builtinTag"RegExp"로 하자.
  14. 그렇지 않으면 builtinTag"Object"로 하자.
  15. tag를 ? Get(obj, %Symbol.toStringTag%)로 하자.
  16. 만약 tag가 문자열이 아니면 tagbuiltinTag로 설정하라.
  17. "[object ", tag, 및 "]"의 문자열 이어붙이기를 반환하라.
Note

역사적으로 이 메서드는 이전 판본의 이 명세에서 다양한 내장 객체들에 대한 명목형 타입 태그로 사용되었던 [[Class]] 내부 슬롯의 문자열 값을 접근하기 위해 가끔 사용되었다. 위의 toString 정의는 이러한 특정 종류의 내장 객체들에 대해 toString을 타입 검사로 사용하는 레거시 코드와의 호환성을 보존한다. 다른 종류의 내장 또는 프로그램 정의 객체들에 대해 신뢰할 수 있는 타입 검사 메커니즘을 제공하지 않는다. 또한 프로그램은 %Symbol.toStringTag%를 사용하여 그러한 레거시 타입 검사들의 신뢰성을 무효화하는 방식으로 사용할 수 있다.

20.1.3.7 Object.prototype.valueOf ( )

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

  1. ToObject(this value)를 반환한다.
Normative Optional, Legacy

20.1.3.8 Object.prototype.__proto__

Object.prototype.__proto__는 속성들 { [[Enumerable]]: false, [[Configurable]]: true }를 가진 접근자 속성이다. [[Get]][[Set]] 접근자는 다음과 같이 정의된다:

20.1.3.8.1 get Object.prototype.__proto__

[[Get]] 속성의 값은 인수를 필요로 하지 않는 내장 함수이다. 이 함수는 호출될 때 다음 단계를 수행한다:

  1. obj를 ? ToObject(this value)로 하자.
  2. Return ? obj.[[GetPrototypeOf]]().

20.1.3.8.2 set Object.prototype.__proto__

[[Set]] 속성의 값은 매개변수 proto를 받는 내장 함수이다. 이 함수는 호출될 때 다음 단계를 수행한다:

  1. thisValuethis 값으로 하자.
  2. Perform ? RequireObjectCoercible(thisValue).
  3. 만약 proto가 객체가 아니고 protonull도 아니면 undefined를 반환하라.
  4. 만약 thisValue가 객체가 아니면 undefined를 반환하라.
  5. status를 ? thisValue.[[SetPrototypeOf]](proto)로 하자.
  6. 만약 statusfalse이면 TypeError 예외를 던진다.
  7. undefined를 반환하라.
Normative Optional, Legacy

20.1.3.9 레거시 Object.prototype 접근자 메서드들

20.1.3.9.1 Object.prototype.__defineGetter__ ( propertyKey, getter )

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

  1. obj를 ? ToObject(this value)로 하자.
  2. 만약 IsCallable(getter)가 false이면 TypeError 예외를 던진다.
  3. desc를 PropertyDescriptor { [[Get]]: getter, [[Enumerable]]: true, [[Configurable]]: true }로 하자.
  4. key를 ? ToPropertyKey(propertyKey)로 하자.
  5. Perform ? DefinePropertyOrThrow(obj, key, desc).
  6. undefined를 반환하라.

20.1.3.9.2 Object.prototype.__defineSetter__ ( propertyKey, setter )

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

  1. obj를 ? ToObject(this value)로 하자.
  2. 만약 IsCallable(setter)가 false이면 TypeError 예외를 던진다.
  3. desc를 PropertyDescriptor { [[Set]]: setter, [[Enumerable]]: true, [[Configurable]]: true }로 하자.
  4. key를 ? ToPropertyKey(propertyKey)로 하자.
  5. Perform ? DefinePropertyOrThrow(obj, key, desc).
  6. undefined를 반환하라.

20.1.3.9.3 Object.prototype.__lookupGetter__ ( propertyKey )

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

  1. obj를 ? ToObject(this value)로 하자.
  2. key를 ? ToPropertyKey(propertyKey)로 하자.
  3. 반복,
    1. desc를 ? obj.[[GetOwnProperty]](key)로 하자.
    2. 만약 descundefined가 아니면,
      1. 만약 IsAccessorDescriptor(desc)가 true이면 desc.[[Get]]를 반환하라.
      2. undefined를 반환하라.
    3. obj를 ? obj.[[GetPrototypeOf]]()로 설정하라.
    4. 만약 objnull이면 undefined를 반환하라.

20.1.3.9.4 Object.prototype.__lookupSetter__ ( propertyKey )

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

  1. obj를 ? ToObject(this value)로 하자.
  2. key를 ? ToPropertyKey(propertyKey)로 하자.
  3. 반복,
    1. desc를 ? obj.[[GetOwnProperty]](key)로 하자.
    2. 만약 descundefined가 아니면,
      1. 만약 IsAccessorDescriptor(desc)가 true이면 desc.[[Set]]를 반환하라.
      2. undefined를 반환하라.
    3. obj를 ? obj.[[GetPrototypeOf]]()로 설정하라.
    4. 만약 objnull이면 undefined를 반환하라.

20.1.4 객체 인스턴스의 속성들

객체 인스턴스는 Object 프로토타입 객체로부터 상속되는 것 이외에 특별한 속성을 가지지 않는다.

20.2 함수 객체들

20.2.1 Function 생성자

Function 생성자:

  • %Function%이다.
  • 전역 객체"Function" 속성의 초기 값이다.
  • 생성자가 아닌 함수로 호출될 때 새로운 함수 객체를 생성하고 초기화한다. 따라서 함수 호출 Function(…)은 동일한 인수로 new Function(…) 객체 생성 표현식과 동등하다.
  • 클래스 정의의 extends 절의 값으로 사용될 수 있다. 지정된 Function 동작을 상속하려는 서브클래스 생성자는 내장 함수 동작에 필요한 내부 슬롯들로 서브클래스 인스턴스를 생성하고 초기화하기 위해 Function 생성자에 대한 super 호출을 포함해야 한다. 함수 객체를 정의하는 모든 ECMAScript 문법 형태는 Function의 인스턴스를 생성한다. 내장된 GeneratorFunction, AsyncFunction, AsyncGeneratorFunction 서브클래스를 제외하고는 Function 서브클래스의 인스턴스를 생성하는 문법적 수단은 없다.

20.2.1.1 Function ( ...parameterArgs, bodyArg )

마지막 인수(있다면)는 함수의 본문(실행 가능한 코드)을 지정한다; 앞의 인수들은 형식 매개변수를 지정한다.

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

  1. constructor를 활성 함수 객체로 하자.
  2. 만약 bodyArg가 존재하지 않으면 bodyArg를 빈 문자열로 설정하라.
  3. Return ? CreateDynamicFunction(constructor, NewTarget, normal, parameterArgs, bodyArg).
Note

각 형식 매개변수마다 하나의 인수를 가지는 것이 허용되지만 필수는 아니다. 예를 들어 다음 세 표현식은 동일한 결과를 생성한다:

new Function("a", "b", "c", "return a+b+c")
new Function("a, b, c", "return a+b+c")
new Function("a,b", "c", "return a+b+c")

20.2.1.1.1 CreateDynamicFunction ( constructor, newTarget, kind, parameterArgs, bodyArg )

The abstract operation CreateDynamicFunction takes arguments constructor (a constructor), newTarget (a constructor or undefined), kind (normal, generator, async, or async-generator), parameterArgs (a List of ECMAScript language values), and bodyArg (an ECMAScript language value) and returns either a normal completion containing an ECMAScript function object or a throw completion. constructor는 이 동작을 수행하는 생성자 함수이다. newTargetnew가 처음 적용된 생성자이다. parameterArgsbodyArgconstructor에 전달된 인수 값을 반영한다. It performs the following steps when called:

  1. 만약 newTargetundefined이면 newTargetconstructor로 설정하라.
  2. 만약 kindnormal이면,
    1. prefix"function"으로 하자.
    2. exprSym를 문법 기호 FunctionExpression으로 하자.
    3. bodySym를 문법 기호 FunctionBody[~Yield, ~Await]으로 하자.
    4. parameterSym를 문법 기호 FormalParameters[~Yield, ~Await]으로 하자.
    5. fallbackProto"%Function.prototype%"로 하자.
  3. 그렇지 않고 kindgenerator이면,
    1. prefix"function*"으로 하자.
    2. exprSym를 문법 기호 GeneratorExpression으로 하자.
    3. bodySym를 문법 기호 GeneratorBody으로 하자.
    4. parameterSym를 문법 기호 FormalParameters[+Yield, ~Await]으로 하자.
    5. fallbackProto"%GeneratorFunction.prototype%"로 하자.
  4. 그렇지 않고 kindasync이면,
    1. prefix"async function"으로 하자.
    2. exprSym를 문법 기호 AsyncFunctionExpression으로 하자.
    3. bodySym를 문법 기호 AsyncFunctionBody으로 하자.
    4. parameterSym를 문법 기호 FormalParameters[~Yield, +Await]으로 하자.
    5. fallbackProto"%AsyncFunction.prototype%"으로 하자.
  5. 그렇지 않으면,
    1. 단언: kindasync-generator이다.
    2. prefix"async function*"으로 하자.
    3. exprSym를 문법 기호 AsyncGeneratorExpression으로 하자.
    4. bodySym를 문법 기호 AsyncGeneratorBody으로 하자.
    5. parameterSym를 문법 기호 FormalParameters[+Yield, +Await]으로 하자.
    6. fallbackProto"%AsyncGeneratorFunction.prototype%"로 하자.
  6. argCountparameterArgs의 요소 수로 하자.
  7. parameterStrings를 새로운 빈 목록으로 하자.
  8. parameterArgs의 각 요소 arg에 대해
    1. ToString(arg)를 parameterStrings에 추가하라.
  9. bodyString를 ? ToString(bodyArg)로 하자.
  10. currentRealm을 현재 Realm 기록으로 하자.
  11. Perform ? HostEnsureCanCompileStrings(currentRealm, parameterStrings, bodyString, false).
  12. parameterString를 빈 문자열로 하자.
  13. 만약 argCount > 0이면,
    1. parameterStringparameterStrings[0]로 설정하라.
    2. k를 1로 하자.
    3. 반복, k < argCount인 동안,
      1. nextArgStringparameterStrings[k]로 하자.
      2. parameterStringparameterString, ","(쉼표), 및 nextArgString의 문자열 이어붙이기로 설정하라.
      3. kk + 1로 설정하라.
  14. bodyParseString를 0x000A (LINE FEED), bodyString, 및 0x000A (LINE FEED)의 문자열 이어붙이기로 하자.
  15. sourceStringprefix, " anonymous(", parameterString, 0x000A (LINE FEED), ") {", bodyParseString, 및 "}"의 문자열 이어붙이기로 하자.
  16. sourceTextStringToCodePoints(sourceString)로 하자.
  17. parametersParseText(parameterString, parameterSym)로 하자.
  18. 만약 parameters가 오류 목록이면 SyntaxError 예외를 던진다.
  19. bodyParseText(bodyParseString, bodySym)로 하자.
  20. 만약 body가 오류 목록이면 SyntaxError 예외를 던진다.
  21. 참고: 매개변수와 본문은 각각 단독으로 유효한지 확인하기 위해 별도로 파싱된다. 예를 들어 new Function("/*", "*/ ) {")는 함수로 평가되지 않는다.
  22. 참고: 이 단계에 도달하면 sourceTextexprSym의 문법을 가져야 한다(역은 성립하지 않을 수 있다). 다음 두 단계의 목적은 exprSym에 직접 적용되는 조기 오류 규칙을 강제하기 위함이다.
  23. exprParseText(sourceText, exprSym)로 하자.
  24. 만약 expr가 오류 목록이면 SyntaxError 예외를 던진다.
  25. proto를 ? GetPrototypeFromConstructor(newTarget, fallbackProto)로 하자.
  26. envcurrentRealm.[[GlobalEnv]]로 하자.
  27. privateEnvnull로 하자.
  28. funcOrdinaryFunctionCreate(proto, sourceText, parameters, body, non-lexical-this, env, privateEnv)로 하자.
  29. Perform SetFunctionName(func, "anonymous").
  30. 만약 kindgenerator이면,
    1. prototypeOrdinaryObjectCreate(%GeneratorPrototype%)로 하자.
    2. Perform ! DefinePropertyOrThrow(func, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }).
  31. 그렇지 않고 kindasync-generator이면,
    1. prototypeOrdinaryObjectCreate(%AsyncGeneratorPrototype%)로 하자.
    2. Perform ! DefinePropertyOrThrow(func, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }).
  32. 그렇지 않고 kindnormal이면,
    1. Perform MakeConstructor(func).
  33. 참고: kindasync인 함수는 생성 가능하지 않으며 [[Construct]] 내부 메서드나 "prototype" 속성을 가지지 않는다.
  34. func를 반환하라.
Note

CreateDynamicFunction은 생성하는 함수 중 kindasync가 아닌 함수에 대해 "prototype" 속성을 정의하여 그 함수가 생성자로 사용될 가능성에 대비한다.

20.2.2 Function 생성자의 속성들

Function 생성자:

  • 자체가 내장 함수 객체이다.
  • 값이 %Function.prototype%[[Prototype]] 내부 슬롯을 가진다.
  • "length" 속성의 값은 1𝔽이다.
  • 다음의 속성들을 가진다:

20.2.2.1 Function.prototype

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

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

20.2.3 Function 프로토타입 객체의 속성들

Function 프로토타입 객체는:

  • %Function.prototype%이다.
  • 자체가 내장 함수 객체이다.
  • 호출될 때 어떤 인수도 받아들이며 undefined를 반환한다.
  • [[Construct]] 내부 메서드를 가지지 않는다; new 연산자로 생성자로 사용할 수 없다.
  • 값이 %Object.prototype%[[Prototype]] 내부 슬롯을 가진다.
  • "prototype" 속성을 가지지 않는다.
  • "length" 속성의 값은 +0𝔽이다.
  • "name" 속성의 값은 빈 문자열이다.
Note

Function 프로토타입 객체는 ECMAScript 2015 이전에 생성된 ECMAScript 코드와의 호환성을 보장하기 위해 함수 객체로 지정되어 있다.

20.2.3.1 Function.prototype.apply ( thisArg, argArray )

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

  1. functhis 값으로 하자.
  2. 만약 IsCallable(func)가 false이면 TypeError 예외를 던진다.
  3. 만약 argArrayundefined 또는 null이면,
    1. Perform PrepareForTailCall().
    2. Return ? Call(func, thisArg).
  4. argList를 ? CreateListFromArrayLike(argArray)로 하자.
  5. Perform PrepareForTailCall().
  6. Return ? Call(func, thisArg, argList).
Note 1

thisArg 값은 변경 없이 this 값으로 전달된다. 이는 Edition 3에서 undefined 또는 nullthisArg전역 객체로 대체되고 다른 모든 값에 ToObject가 적용되어 그 결과가 this 값으로 전달되던 동작에서의 변경이다. thisArg가 변경 없이 전달되더라도, 비엄격 함수들은 함수 진입 시에 여전히 이러한 변환을 수행한다.

Note 2

만약 func가 화살표 함수이거나 바인드된 함수 이국적 객체이면, thisArg는 단계 6의 함수 [[Call]]에 의해 무시될 것이다.

20.2.3.2 Function.prototype.bind ( thisArg, ...args )

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

  1. targetthis 값으로 하자.
  2. 만약 IsCallable(target)가 false이면 TypeError 예외를 던진다.
  3. boundFunc를 ? BoundFunctionCreate(target, thisArg, args)로 하자.
  4. length를 0으로 하자.
  5. targetHasLength를 ? HasOwnProperty(target, "length")로 하자.
  6. 만약 targetHasLengthtrue이면,
    1. targetLen을 ? Get(target, "length")로 하자.
    2. 만약 targetLen이 Number이면,
      1. 만약 targetLen+∞𝔽이면,
        1. length를 +∞로 설정하라.
      2. 그렇지 않고 targetLen-∞𝔽이면,
        1. length를 0으로 설정하라.
      3. 그렇지 않으면,
        1. targetLenAsInt를 ! ToIntegerOrInfinity(targetLen)로 하자.
        2. 단언: targetLenAsInt유한하다.
        3. argCountargs의 요소 수로 하자.
        4. lengthmax(targetLenAsInt - argCount, 0)으로 설정하라.
  7. Perform SetFunctionLength(boundFunc, length).
  8. targetName를 ? Get(target, "name")로 하자.
  9. 만약 targetName이 문자열이 아니면 targetName를 빈 문자열로 설정하라.
  10. Perform SetFunctionName(boundFunc, targetName, "bound").
  11. boundFunc를 반환하라.
Note 1

Function.prototype.bind를 사용하여 생성된 함수 객체는 이국적 객체이다. 또한 이들은 "prototype" 속성을 가지지 않는다.

Note 2

만약 target이 화살표 함수이거나 바인드된 함수 이국적 객체이면, 이 메서드에 전달된 thisArg는 이후의 func 호출에서 사용되지 않을 것이다.

20.2.3.3 Function.prototype.call ( thisArg, ...args )

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

  1. functhis 값으로 하자.
  2. 만약 IsCallable(func)가 false이면 TypeError 예외를 던진다.
  3. Perform PrepareForTailCall().
  4. Return ? Call(func, thisArg, args).
Note 1

thisArg 값은 변경 없이 this 값으로 전달된다. 이는 Edition 3에서의 동작에서의 변경이다. 비엄격 함수들은 여전히 진입 시 변환을 수행한다.

Note 2

만약 func가 화살표 함수이거나 바인드된 함수 이국적 객체이면, thisArg는 단계 4의 함수 [[Call]]에서 무시될 것이다.

20.2.3.4 Function.prototype.constructor

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

20.2.3.5 Function.prototype.toString ( )

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

  1. functhis 값으로 하자.
  2. 만약 func가 객체이고, func[[SourceText]] 내부 슬롯을 가지며, func.[[SourceText]]가 유니코드 코드 포인트의 시퀀스이고 HostHasSourceTextAvailable(func)가 true이면,
    1. CodePointsToString(func.[[SourceText]])를 반환하라.
  3. 만약 func내장 함수 객체이면, 구현 정의의 문자열 소스 코드 표현을 반환하라. 그 표현은 NativeFunction의 문법을 가져야 한다. 추가로, 만약 func[[InitialName]] 내부 슬롯을 가지고 있고 func.[[InitialName]]이 문자열이면, 반환된 문자열에서 NativeFunctionAccessoropt PropertyName에 매칭될 부분은 func.[[InitialName]]이어야 한다.
  4. 만약 func가 객체이고 IsCallable(func)가 true이면, 구현 정의의 문자열 소스 코드 표현을 반환하라. 그 표현은 NativeFunction의 문법을 가져야 한다.
  5. TypeError 예외를 던진다.
NativeFunction : function NativeFunctionAccessoropt PropertyName[~Yield, ~Await]opt ( FormalParameters[~Yield, ~Await] ) { [ native code ] } NativeFunctionAccessor : get set

20.2.3.6 Function.prototype [ %Symbol.hasInstance% ] ( value )

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

  1. thisValuethis 값으로 하자.
  2. Return ? OrdinaryHasInstance(thisValue, value).

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

Note

이것은 대부분의 함수가 상속하는 %Symbol.hasInstance%의 기본 구현이다. %Symbol.hasInstance%instanceof 연산자가 값이 특정 생성자의 인스턴스인지 결정할 때 호출된다. 예를 들어 식

v instanceof F

는 다음과 같이 평가된다

F[%Symbol.hasInstance%](v)

생성자 함수는 함수에 다른 %Symbol.hasInstance% 메서드를 노출함으로써 instanceof가 인식하는 객체들을 제어할 수 있다.

이 속성은 바인드된 함수의 대상 함수를 전역적으로 노출하는 데 사용될 수 있는 변조를 방지하기 위해 쓰기 불가 및 구성 불가로 설정되어 있다.

이 메서드의 "name" 속성의 값은 "[Symbol.hasInstance]"이다.

20.2.4 함수 인스턴스들

모든 Function 인스턴스는 ECMAScript 함수 객체이며 Table 25에 나열된 내부 슬롯들을 가진다. Function.prototype.bind 메서드(20.2.3.2)를 사용하여 생성된 함수 객체는 Table 26에 나열된 내부 슬롯들을 가진다.

함수 인스턴스는 다음 속성들을 가진다:

20.2.4.1 length

"length" 속성의 값은 함수가 기대하는 인수의 전형적인 수를 나타내는 정수 Number이다. 그러나 언어는 함수가 다른 수의 인수로 호출되는 것을 허용한다. "length" 속성에 명시된 수와 다른 수의 인수로 호출될 때 함수의 동작은 함수에 따라 다르다. 이 속성은 속성들 { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }을 가진다.

20.2.4.2 name

"name" 속성의 값은 함수에 대해 설명적인 문자열이다. 이름은 의미론적 중요성은 없지만 일반적으로 ECMAScript 소스 텍스트에서 정의 지점에서 함수를 참조하는 변수나 속성 이름이다. 이 속성은 속성들 { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }을 가진다.

이 명세에 의해 컨텍스트 이름이 연관되지 않은 익명 함수 객체는 "name" 속성의 값으로 빈 문자열을 사용한다.

20.2.4.3 prototype

생성자로 사용될 수 있는 함수 인스턴스는 "prototype" 속성을 가진다. 그러한 Function 인스턴스가 생성될 때마다 또 다른 일반 객체가 생성되며 그 객체는 해당 함수의 "prototype" 속성의 초기 값이다. 달리 명시되지 않는 한, "prototype" 속성의 값은 그 함수가 생성자로 호출될 때 생성되는 객체의 [[Prototype]] 내부 슬롯을 초기화하는 데 사용된다.

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

Note

Function.prototype.bind을 사용하여 생성된 함수 객체나 MethodDefinition (GeneratorMethod 또는 AsyncGeneratorMethod이 아닌) 또는 ArrowFunction을 평가하여 생성된 함수 객체는 "prototype" 속성을 가지지 않는다.

20.2.5 HostHasSourceTextAvailable ( func )

The host-defined abstract operation HostHasSourceTextAvailable takes argument func (a function object) and returns a Boolean. 호스트 환경func에 대한 소스 텍스트 제공을 방지할 수 있게 한다.

HostHasSourceTextAvailable의 구현은 다음 요구사항을 충족해야 한다:

  • 매개변수에 대해 결정론적이어야 한다. 특정 func을 인수로 받아 호출될 때마다 동일한 결과를 반환해야 한다.

HostHasSourceTextAvailable의 기본 구현은 true를 반환하는 것이다.

20.3 Boolean 객체들

20.3.1 Boolean 생성자

Boolean 생성자:

  • %Boolean%이다.
  • 전역 객체"Boolean" 속성의 초기 값이다.
  • 생성자로 호출될 때 새로운 Boolean 객체를 생성하고 초기화한다.
  • 생성자가 아닌 함수로 호출될 때 형 변환을 수행한다.
  • 클래스 정의의 extends 절의 값으로 사용될 수 있다. 지정된 Boolean 동작을 상속하려는 서브클래스 생성자는 [[BooleanData]] 내부 슬롯을 가진 서브클래스 인스턴스를 생성하고 초기화하기 위해 Boolean 생성자에 대한 super 호출을 포함해야 한다.

20.3.1.1 Boolean ( value )

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

  1. bToBoolean(value)로 하자.
  2. 만약 NewTarget이 undefined이면 b를 반환하라.
  3. obj를 ? OrdinaryCreateFromConstructor(NewTarget, "%Boolean.prototype%", « [[BooleanData]] »)로 하자.
  4. obj.[[BooleanData]]b로 설정하라.
  5. obj를 반환하라.

20.3.2 Boolean 생성자의 속성들

Boolean 생성자:

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

20.3.2.1 Boolean.prototype

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

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

20.3.3 Boolean 프로토타입 객체의 속성들

Boolean 프로토타입 객체는:

  • %Boolean.prototype%이다.
  • 일반 객체이다.
  • 자체가 Boolean 객체이다; 값이 false[[BooleanData]] 내부 슬롯을 가진다.
  • 값이 %Object.prototype%[[Prototype]] 내부 슬롯을 가진다.

20.3.3.1 Boolean.prototype.constructor

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

20.3.3.2 Boolean.prototype.toString ( )

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

  1. b를 ? ThisBooleanValue(this value)로 하자.
  2. 만약 btrue이면 "true"를 반환한다.
  3. "false"를 반환한다.

20.3.3.3 Boolean.prototype.valueOf ( )

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

  1. ThisBooleanValue(this value)를 반환한다.

20.3.3.3.1 ThisBooleanValue ( value )

The abstract operation ThisBooleanValue takes argument value (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. 만약 value가 Boolean이면 value를 반환한다.
  2. 만약 value가 객체이고 value[[BooleanData]] 내부 슬롯을 가지고 있으면,
    1. bvalue.[[BooleanData]]로 하자.
    2. 단언: b는 Boolean이다.
    3. b를 반환하라.
  3. TypeError 예외를 던진다.

20.3.4 Boolean 인스턴스의 속성들

Boolean 인스턴스는 Boolean 프로토타입 객체로부터 속성을 상속하는 일반 객체이다. Boolean 인스턴스는 [[BooleanData]] 내부 슬롯을 가진다. [[BooleanData]] 내부 슬롯은 이 Boolean 객체가 표현하는 Boolean 값이다.

20.4 Symbol 객체

20.4.1 Symbol 생성자

Symbol 생성자는:

  • %Symbol%이다.
  • 전역 객체"Symbol" 속성의 초기값이다.
  • 함수로 호출될 때 새로운 Symbol 값을 반환한다.
  • new 연산자와 함께 사용되도록 의도된 것이 아니다.
  • 서브클래싱되도록 의도된 것이 아니다.
  • 클래스 정의의 extends 절의 값으로 사용될 수 있지만, 이에 대한 super 호출은 예외를 발생시킨다.

20.4.1.1 Symbol ( [ description ] )

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

  1. If NewTarget is not undefined, throw a TypeError exception.
  2. If description is undefined, let descString be undefined.
  3. Else, let descString be ? ToString(description).
  4. Return a new Symbol whose [[Description]] is descString.

20.4.2 Symbol 생성자의 속성

Symbol 생성자는:

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

20.4.2.1 Symbol.asyncIterator

Symbol.asyncIterator의 초기값은 잘 알려진 Symbol %Symbol.asyncIterator%이다(Table 1).

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

20.4.2.2 Symbol.for ( key )

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

  1. stringKey를 ? ToString(key)으로 둔다.
  2. GlobalSymbolRegistry List의 각 요소 e에 대해, 다음을 수행한다
    1. e.[[Key]]stringKey이면, e.[[Symbol]]을 반환한다.
  3. Assert: GlobalSymbolRegistry List는 현재 stringKey에 대한 항목을 포함하지 않는다.
  4. newSymbol[[Description]]stringKey인 새로운 Symbol로 둔다.
  5. GlobalSymbolRegistry Record { [[Key]]: stringKey, [[Symbol]]: newSymbol }를 GlobalSymbolRegistry List에 추가한다.
  6. newSymbol을 반환한다.

GlobalSymbolRegistry List는 전역적으로 사용 가능한 추가 전용 List이다. 이는 모든 Realm이 공유한다. 어떤 ECMAScript 코드의 평가보다 먼저, 새로운 빈 List로 초기화된다. GlobalSymbolRegistry List의 요소는 Table 58에 정의된 구조를 가진 Record이다.

Table 58: GlobalSymbolRegistry Record 필드
필드 이름 용도
[[Key]] String Symbol을 전역적으로 식별하는 데 사용되는 문자열 키.
[[Symbol]] Symbol 어떤 Realm에서도 가져올 수 있는 Symbol.

20.4.2.3 Symbol.hasInstance

Symbol.hasInstance의 초기값은 잘 알려진 Symbol %Symbol.hasInstance%이다(Table 1).

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

20.4.2.4 Symbol.isConcatSpreadable

Symbol.isConcatSpreadable의 초기값은 잘 알려진 Symbol %Symbol.isConcatSpreadable%이다(Table 1).

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

20.4.2.5 Symbol.iterator

Symbol.iterator의 초기값은 잘 알려진 Symbol %Symbol.iterator%이다(Table 1).

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

20.4.2.6 Symbol.keyFor ( sym )

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

  1. sym이 Symbol이 아니면, TypeError 예외를 던진다.
  2. KeyForSymbol(sym)을 반환한다.

20.4.2.7 Symbol.match

Symbol.match의 초기값은 잘 알려진 Symbol %Symbol.match%이다(Table 1).

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

20.4.2.8 Symbol.matchAll

Symbol.matchAll의 초기값은 잘 알려진 Symbol %Symbol.matchAll%이다(Table 1).

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

20.4.2.9 Symbol.prototype

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

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

20.4.2.10 Symbol.replace

Symbol.replace의 초기값은 잘 알려진 Symbol %Symbol.replace%이다(Table 1).

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

20.4.2.11 Symbol.search

Symbol.search의 초기값은 잘 알려진 Symbol %Symbol.search%이다(Table 1).

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

20.4.2.12 Symbol.species

Symbol.species의 초기값은 잘 알려진 Symbol %Symbol.species%이다(Table 1).

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

20.4.2.13 Symbol.split

Symbol.split의 초기값은 잘 알려진 Symbol %Symbol.split%이다(Table 1).

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

20.4.2.14 Symbol.toPrimitive

Symbol.toPrimitive의 초기값은 잘 알려진 Symbol %Symbol.toPrimitive%이다(Table 1).

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

20.4.2.15 Symbol.toStringTag

Symbol.toStringTag의 초기값은 잘 알려진 Symbol %Symbol.toStringTag%이다(Table 1).

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

20.4.2.16 Symbol.unscopables

Symbol.unscopables의 초기값은 잘 알려진 Symbol %Symbol.unscopables%이다(Table 1).

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

20.4.3 Symbol 프로토타입 객체의 속성

Symbol 프로토타입 객체는:

  • %Symbol.prototype%이다.
  • ordinary object이다.
  • Symbol 인스턴스가 아니며 [[SymbolData]] 내부 슬롯을 가지지 않는다.
  • 그 값이 %Object.prototype%[[Prototype]] 내부 슬롯을 가진다.

20.4.3.1 Symbol.prototype.constructor

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

20.4.3.2 get Symbol.prototype.description

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

  1. sthis 값으로 둔다.
  2. sym을 ? ThisSymbolValue(s)로 둔다.
  3. sym.[[Description]]을 반환한다.

20.4.3.3 Symbol.prototype.toString ( )

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

  1. sym을 ? ThisSymbolValue(this value)로 둔다.
  2. SymbolDescriptiveString(sym)을 반환한다.

20.4.3.3.1 SymbolDescriptiveString ( sym )

The abstract operation SymbolDescriptiveString takes argument sym (a Symbol) and returns a String. It performs the following steps when called:

  1. descsym.[[Description]]으로 둔다.
  2. descundefined이면, desc를 빈 String으로 설정한다.
  3. Assert: desc는 String이다.
  4. "Symbol(", desc, 그리고 ")"의 문자열 연결을 반환한다.

20.4.3.4 Symbol.prototype.valueOf ( )

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

  1. ThisSymbolValue(this value)를 반환한다.

20.4.3.4.1 ThisSymbolValue ( value )

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

  1. value가 Symbol이면, value를 반환한다.
  2. value가 Object이고 value[[SymbolData]] 내부 슬롯을 가지면, 다음을 수행한다
    1. svalue.[[SymbolData]]로 둔다.
    2. Assert: s는 Symbol이다.
    3. s를 반환한다.
  3. TypeError 예외를 던진다.

20.4.3.5 Symbol.prototype [ %Symbol.toPrimitive% ] ( hint )

이 메서드는 ECMAScript 언어 연산자에 의해 Symbol 객체를 원시 값으로 변환하기 위해 호출된다.

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

  1. ThisSymbolValue(this value)를 반환한다.
Note

인수는 무시된다.

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

이 메서드의 "name" 속성 값은 "[Symbol.toPrimitive]"이다.

20.4.3.6 Symbol.prototype [ %Symbol.toStringTag% ]

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

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

20.4.4 Symbol 인스턴스의 속성

Symbol 인스턴스는 Symbol 프로토타입 객체로부터 속성을 상속하는 ordinary object이다. Symbol 인스턴스는 [[SymbolData]] 내부 슬롯을 가진다. [[SymbolData]] 내부 슬롯은 이 Symbol 객체가 나타내는 Symbol 값이다.

20.4.5 Symbol을 위한 추상 연산

20.4.5.1 KeyForSymbol ( sym )

The abstract operation KeyForSymbol takes argument sym (a Symbol) and returns a String or undefined. symGlobalSymbolRegistry List에 있으면, sym을 등록하는 데 사용된 String이 반환된다. It performs the following steps when called:

  1. GlobalSymbolRegistry List의 각 요소 e에 대해, 다음을 수행한다
    1. SameValue(e.[[Symbol]], sym)가 true이면, e.[[Key]]를 반환한다.
  2. Assert: GlobalSymbolRegistry List는 현재 sym에 대한 항목을 포함하지 않는다.
  3. undefined를 반환한다.

20.5 Error 객체들

Error 객체의 인스턴스는 런타임 오류가 발생할 때 예외로 던져진다. Error 객체는 사용자 정의 예외 클래스의 기반 객체로도 사용될 수 있다.

ECMAScript 구현이 런타임 오류를 감지하면, 20.5.5에 정의된 NativeError 객체들 중 하나의 새 인스턴스 또는 20.5.7에 정의된 AggregateError 객체의 새 인스턴스를 던진다.

20.5.1 Error 생성자

Error 생성자:

  • %Error%이다.
  • 전역 객체"Error" 속성의 초기 값이다.
  • 생성자가 아닌 함수로 호출될 때 새로운 Error 객체를 생성하고 초기화한다. 따라서 함수 호출 Error(…)는 동일한 인수로 new Error(…) 객체 생성 표현식과 동등하다.
  • 클래스 정의의 extends 절의 값으로 사용될 수 있다. 지정된 Error 동작을 상속하려는 서브클래스 생성자는 [[ErrorData]] 내부 슬롯을 가진 서브클래스 인스턴스를 생성하고 초기화하기 위해 Error 생성자에 대한 super 호출을 포함해야 한다.

20.5.1.1 Error ( message [ , options ] )

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

  1. 만약 NewTarget이 undefined이면 newTarget을 활성 함수 객체로 하자; 그렇지 않으면 newTarget을 NewTarget으로 하자.
  2. obj를 ? OrdinaryCreateFromConstructor(newTarget, "%Error.prototype%", « [[ErrorData]] »)로 하자.
  3. 만약 messageundefined가 아니면,
    1. msg를 ? ToString(message)로 하자.
    2. Perform CreateNonEnumerableDataPropertyOrThrow(obj, "message", msg).
  4. Perform ? InstallErrorCause(obj, options).
  5. obj를 반환하라.

20.5.2 Error 생성자의 속성들

Error 생성자:

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

20.5.2.1 Error.isError ( arg )

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

  1. 만약 arg가 객체가 아니면 false를 반환한다.
  2. 만약 arg[[ErrorData]] 내부 슬롯을 가지고 있지 않으면 false를 반환한다.
  3. true를 반환한다.

20.5.2.2 Error.prototype

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

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

20.5.3 Error 프로토타입 객체의 속성들

Error 프로토타입 객체:

  • %Error.prototype%이다.
  • 일반 객체이다.
  • Error 인스턴스가 아니며 [[ErrorData]] 내부 슬롯을 가지지 않는다.
  • 값이 %Object.prototype%[[Prototype]] 내부 슬롯을 가진다.

20.5.3.1 Error.prototype.constructor

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

20.5.3.2 Error.prototype.message

Error.prototype.message의 초기 값은 빈 문자열이다.

20.5.3.3 Error.prototype.name

Error.prototype.name의 초기 값은 "Error"이다.

20.5.3.4 Error.prototype.toString ( )

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

  1. objthis 값으로 하자.
  2. 만약 obj가 객체가 아니면 TypeError 예외를 던진다.
  3. name를 ? Get(obj, "name")로 하자.
  4. 만약 nameundefined이면 name"Error"로 설정; 그렇지 않으면 name을 ? ToString(name)로 설정하라.
  5. msg를 ? Get(obj, "message")로 하자.
  6. 만약 msgundefined이면 msg를 빈 문자열로 설정; 그렇지 않으면 msg를 ? ToString(msg)로 설정하라.
  7. 만약 name이 빈 문자열이면 msg를 반환하라.
  8. 만약 msg가 빈 문자열이면 name을 반환하라.
  9. name, 코드 유닛 0x003A (COLON), 코드 유닛 0x0020 (SPACE), 및 msg의 문자열 이어붙이기를 반환하라.

20.5.4 Error 인스턴스의 속성들

Error 인스턴스는 Error 프로토타입 객체로부터 속성을 상속하는 일반 객체이며 값이 undefined[[ErrorData]] 내부 슬롯을 가진다. [[ErrorData]]의 유일한 명시된 용도는 Object.prototype.toStringError.isError에서 Error, AggregateError, 및 NativeError 인스턴스를 Error 객체로 식별하는 것이다.

20.5.5 이 표준에서 사용되는 네이티브 오류 유형들

런타임 오류가 감지되면 아래의 NativeError 객체들 중 하나 또는 AggregateError 객체의 새 인스턴스가 던져진다. 모든 NativeError 객체는 20.5.6에 설명된 동일한 구조를 공유한다.

20.5.5.1 EvalError

EvalError 생성자는 %EvalError%이다.

이 예외는 현재 이 명세 내에서 사용되지 않는다. 이 객체는 이전 판본과의 호환성을 위해 남아 있다.

20.5.5.2 RangeError

RangeError 생성자는 %RangeError%이다.

허용 가능한 값의 집합 또는 범위에 속하지 않는 값을 나타낸다.

20.5.5.3 ReferenceError

ReferenceError 생성자는 %ReferenceError%이다.

잘못된 참조가 감지되었음을 나타낸다.

20.5.5.4 SyntaxError

SyntaxError 생성자는 %SyntaxError%이다.

파싱 오류가 발생했음을 나타낸다.

20.5.5.5 TypeError

TypeError 생성자는 %TypeError%이다.

다른 NativeError 객체들이 실패 원인의 적절한 표시가 아닐 때 실패한 연산을 나타내는 데 사용된다.

20.5.5.6 URIError

URIError 생성자는 %URIError%이다.

전역 URI 처리 함수들 중 하나가 그 정의와 호환되지 않는 방식으로 사용되었음을 나타낸다.

20.5.6 NativeError 객체 구조

각 객체는 아래에 설명된 구조를 가지며, 생성자 이름과 프로토타입 객체의 "name" 속성에 사용되는 이름만 다르다.

각 오류 객체에 대해 정의에서 NativeError에 대한 참조는 20.5.5에서 적절한 오류 객체 이름으로 대체되어야 한다.

20.5.6.1 NativeError 생성자들

NativeError 생성자:

  • 생성자가 아닌 함수로 호출될 때 새로운 NativeError 객체를 생성하고 초기화한다. 함수로 객체를 호출하는 것은 동일한 인수로 생성자로 호출하는 것과 동등하다. 따라서 함수 호출 NativeError(…)는 동일한 인수로 객체 생성 표현식 new NativeError(…)과 동등하다.
  • 클래스 정의의 extends 절의 값으로 사용될 수 있다. 지정된 NativeError 동작을 상속하려는 서브클래스 생성자는 [[ErrorData]] 내부 슬롯을 가진 서브클래스 인스턴스를 생성하고 초기화하기 위해 NativeError 생성자에 대한 super 호출을 포함해야 한다.

20.5.6.1.1 NativeError ( message [ , options ] )

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

  1. 만약 NewTarget이 undefined이면 newTarget을 활성 함수 객체로 하자; 그렇지 않으면 newTarget을 NewTarget으로 하자.
  2. obj를 ? OrdinaryCreateFromConstructor(newTarget, "%NativeError.prototype%", « [[ErrorData]] »)로 하자.
  3. 만약 messageundefined가 아니면,
    1. msg를 ? ToString(message)로 하자.
    2. Perform CreateNonEnumerableDataPropertyOrThrow(obj, "message", msg).
  4. Perform ? InstallErrorCause(obj, options).
  5. obj를 반환하라.

단계 2에서 전달되는 문자열의 실제 값은 정의되는 NativeError 생성자에 해당하여 "%EvalError.prototype%", "%RangeError.prototype%", "%ReferenceError.prototype%", "%SyntaxError.prototype%", "%TypeError.prototype%", 또는 "%URIError.prototype%" 중 하나이다.

20.5.6.2 NativeError 생성자들의 속성들

NativeError 생성자:

  • 값이 %Error%[[Prototype]] 내부 슬롯을 가진다.
  • "name" 속성의 값은 문자열 "NativeError"이다.
  • 다음의 속성들을 가진다:

20.5.6.2.1 NativeError.prototype

NativeError.prototype의 초기 값은 NativeError 프로토타입 객체이다 (20.5.6.3). 각 NativeError 생성자는 구별되는 프로토타입 객체를 가진다.

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

20.5.6.3 NativeError 프로토타입 객체의 속성들

NativeError 프로토타입 객체는:

  • 일반 객체이다.
  • Error 인스턴스가 아니며 [[ErrorData]] 내부 슬롯을 가지지 않는다.
  • 값이 %Error.prototype%[[Prototype]] 내부 슬롯을 가진다.

20.5.6.3.1 NativeError.prototype.constructor

주어진 NativeError 생성자의 프로토타입에 대한 "constructor" 속성의 초기 값은 그 생성자 자체이다.

20.5.6.3.2 NativeError.prototype.message

주어진 NativeError 생성자의 프로토타입에 대한 "message" 속성의 초기 값은 빈 문자열이다.

20.5.6.3.3 NativeError.prototype.name

주어진 NativeError 생성자의 프로토타입에 대한 "name" 속성의 초기 값은 생성자의 이름( NativeError 대신 사용되는 이름)으로 구성된 문자열 값이다.

20.5.6.4 NativeError 인스턴스의 속성들

NativeError 인스턴스는 자신의 NativeError 프로토타입 객체로부터 속성을 상속하는 일반 객체이며 값이 undefined[[ErrorData]] 내부 슬롯을 가진다. [[ErrorData]]의 유일한 명시된 사용은 Object.prototype.toStringError.isError에서 Error, AggregateError, 또는 NativeError 인스턴스를 식별하는 것이다.

20.5.7 AggregateError 객체들

20.5.7.1 AggregateError 생성자

AggregateError 생성자:

  • %AggregateError%이다.
  • 전역 객체"AggregateError" 속성의 초기 값이다.
  • 생성자가 아닌 함수로 호출될 때 새로운 AggregateError 객체를 생성하고 초기화한다. 따라서 함수 호출 AggregateError(…)는 동일한 인수로 new AggregateError(…) 객체 생성 표현식과 동등하다.
  • 클래스 정의의 extends 절의 값으로 사용될 수 있다. 지정된 AggregateError 동작을 상속하려는 서브클래스 생성자는 [[ErrorData]] 내부 슬롯을 가진 서브클래스 인스턴스를 생성하고 초기화하기 위해 AggregateError 생성자에 대한 super 호출을 포함해야 한다.

20.5.7.1.1 AggregateError ( errors, message [ , options ] )

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

  1. 만약 NewTarget이 undefined이면 newTarget을 활성 함수 객체로 하자; 그렇지 않으면 newTarget을 NewTarget으로 하자.
  2. obj를 ? OrdinaryCreateFromConstructor(newTarget, "%AggregateError.prototype%", « [[ErrorData]] »)로 하자.
  3. 만약 messageundefined가 아니면,
    1. msg를 ? ToString(message)로 하자.
    2. Perform CreateNonEnumerableDataPropertyOrThrow(obj, "message", msg).
  4. Perform ? InstallErrorCause(obj, options).
  5. errorsList를 ? IteratorToList(? GetIterator(errors, sync))로 하자.
  6. Perform ! DefinePropertyOrThrow(obj, "errors", PropertyDescriptor { [[Configurable]]: true, [[Enumerable]]: false, [[Writable]]: true, [[Value]]: CreateArrayFromList(errorsList) }).
  7. obj를 반환하라.

20.5.7.2 AggregateError 생성자의 속성들

AggregateError 생성자:

  • 값이 %Error%[[Prototype]] 내부 슬롯을 가진다.
  • 다음의 속성들을 가진다:

20.5.7.2.1 AggregateError.prototype

AggregateError.prototype의 초기 값은 %AggregateError.prototype%이다.

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

20.5.7.3 AggregateError 프로토타입 객체의 속성들

AggregateError 프로토타입 객체는:

  • %AggregateError.prototype%이다.
  • 일반 객체이다.
  • Error 인스턴스나 AggregateError 인스턴스가 아니며 [[ErrorData]] 내부 슬롯을 가지지 않는다.
  • 값이 %Error.prototype%[[Prototype]] 내부 슬롯을 가진다.

20.5.7.3.1 AggregateError.prototype.constructor

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

20.5.7.3.2 AggregateError.prototype.message

AggregateError.prototype.message의 초기 값은 빈 문자열이다.

20.5.7.3.3 AggregateError.prototype.name

AggregateError.prototype.name의 초기 값은 "AggregateError"이다.

20.5.7.4 AggregateError 인스턴스의 속성들

AggregateError 인스턴스는 자신의 AggregateError 프로토타입 객체로부터 속성을 상속하는 일반 객체이며 값이 undefined[[ErrorData]] 내부 슬롯을 가진다. [[ErrorData]]의 유일한 명시된 사용은 Object.prototype.toStringError.isError에서 Error, AggregateError, 또는 NativeError 인스턴스를 식별하는 것이다.

20.5.8 Error 객체들을 위한 추상 연산들

20.5.8.1 InstallErrorCause ( obj, options )

The abstract operation InstallErrorCause takes arguments obj (an Object) and options (an ECMAScript language value) and returns either a normal completion containing unused or a throw completion. 옵션 options"cause" 속성이 존재할 때 obj"cause" 속성을 생성하는 데 사용된다. It performs the following steps when called:

  1. 만약 options가 객체이고 ? HasProperty(options, "cause")가 true이면,
    1. cause를 ? Get(options, "cause")로 하자.
    2. Perform CreateNonEnumerableDataPropertyOrThrow(obj, "cause", cause).
  2. unused를 반환하라.