20 Fundamental Objects

20.1 Object Objects

20.1.1 The Object Constructor

Object constructorは:

  • %Object%です。
  • global object"Object" propertyのinitial valueです。
  • constructorとして呼び出されたとき、新しいordinary objectを作成します。
  • constructorとしてではなくfunctionとして呼び出されたとき、type conversionを実行します。
  • class definitionのextends clauseのvalueとして使用できます。

20.1.1.1 Object ( value )

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. NewTargetがundefinedでもactive function objectでもないなら、
    1. OrdinaryCreateFromConstructor(NewTarget, "%Object.prototype%")を返す。
  2. valueundefinedまたはnullのいずれかなら、OrdinaryObjectCreate(%Object.prototype%)を返す。
  3. ToObject(value)を返す。

20.1.2 Properties of the Object Constructor

Object constructorは:

  • valueが%Function.prototype%である[[Prototype]] internal slotを持ちます。
  • 次の追加propertiesを持ちます:

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

このfunctionは、1つ以上のsource objectsからすべてのenumerable own propertiesのvaluesをtarget objectへcopyします。

これは呼び出されたとき、次のstepsを実行します:

  1. ToObject(target)をtargetObjとする。
  2. 引数が1個だけ渡された場合、targetObjを返す。
  3. sourcesの各要素nextSourceについて、次を行う。
    1. nextSourceundefinedでもnullでもない場合、
      1. ToObject(nextSource)をfromとする。
      2. from.[[OwnPropertyKeys]]()keysとする。
      3. keysの各要素nextKeyについて、次を行う。
        1. from.[[GetOwnProperty]](nextKey)propertyDescとする。
        2. propertyDescundefinedでなく、かつpropertyDesc.[[Enumerable]]trueである場合、
          1. Get(from, nextKey)をpropertyValueとする。
          2. Set(targetObj, nextKey, propertyValue, true)を実行する。
  4. targetObjを返す。

このfunctionの"length" propertyは2𝔽です。

20.1.2.2 Object.create ( proto, properties )

このfunctionは、指定されたprototypeを持つ新しいobjectを作成します。

これは呼び出されたとき、次のstepsを実行します:

  1. protoがObjectでなく、かつprotonullでないなら、TypeError例外をthrowする。
  2. objOrdinaryObjectCreate(proto)とする。
  3. propertiesundefinedでないなら、
    1. ObjectDefineProperties(obj, properties)を返す。
  4. objを返す。

20.1.2.3 Object.defineProperties ( obj, properties )

このfunctionは、objectのown propertiesを追加し、かつ/または既存のown propertiesのattributesをupdateします。

これは呼び出されたとき、次のstepsを実行します:

  1. objがObjectでないなら、TypeError例外をthrowする。
  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. propertiesを ? ToObject(properties) に設定する。
  2. keysを ? properties.[[OwnPropertyKeys]]() とする。
  3. propertyDescsを新しい空のListとする。
  4. keysの各要素nextKeyについて、以下を行う
    1. currentPropertyDescを ? properties.[[GetOwnProperty]](nextKey) とする。
    2. currentPropertyDescundefinedでなく、currentPropertyDesc.[[Enumerable]]trueなら、
      1. propertyDescObjを ? Get(properties, nextKey) とする。
      2. propertyDescを ? ToPropertyDescriptor(propertyDescObj) とする。
      3. Record { [[Key]]: nextKey, [[Descriptor]]: propertyDesc }をpropertyDescsへappendする。
  5. propertyDescsの各要素propertyについて、以下を行う
    1. DefinePropertyOrThrow(obj, property.[[Key]], property.[[Descriptor]])を実行する。
  6. objを返す。

20.1.2.4 Object.defineProperty ( obj, key, attrs )

このfunctionは、objectのown propertyを追加し、かつ/または既存のown propertyのattributesをupdateします。

これは呼び出されたとき、次のstepsを実行します:

  1. objがObjectでないなら、TypeError例外をthrowする。
  2. propertyKeyを ? ToPropertyKey(key) とする。
  3. propertyDescを ? ToPropertyDescriptor(attrs) とする。
  4. DefinePropertyOrThrow(obj, propertyKey, propertyDesc)を実行する。
  5. objを返す。

20.1.2.5 Object.entries ( obj )

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. coercedを ? ToObject(obj) とする。
  2. entryListを ? EnumerableOwnProperties(coerced, key+value) とする。
  3. CreateArrayFromList(entryList)を返す。

20.1.2.6 Object.freeze ( obj )

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. objがObjectでないなら、objを返す。
  2. statusを ? SetIntegrityLevel(obj, frozen) とする。
  3. statusfalseなら、TypeError例外をthrowする。
  4. objを返す。

20.1.2.7 Object.fromEntries ( iterable )

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. RequireObjectCoercible(iterable)を実行する。
  2. objOrdinaryObjectCreate(%Object.prototype%)とする。
  3. Assert: objはown propertiesを持たないextensible ordinary objectである。
  4. objをcaptureし、呼び出されたとき次のstepsを実行する、parameters (key, value)を持つ新しいAbstract Closure closureとする:
    1. propertyKeyを ? ToPropertyKey(key) とする。
    2. CreateDataPropertyOrThrow(obj, propertyKey, value)を実行する。
    3. NormalCompletion(undefined)を返す。
  5. adderCreateBuiltinFunction(closure, 2, "", « »)とする。
  6. AddEntriesFromIterable(obj, iterable, adder)を返す。
Note
adderのために作成されたfunctionは、ECMAScript codeから直接accessできることはありません。

20.1.2.8 Object.getOwnPropertyDescriptor ( obj, key )

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. coercedを ? ToObject(obj) とする。
  2. propertyKeyを ? ToPropertyKey(key) とする。
  3. propertyDescを ? coerced.[[GetOwnProperty]](propertyKey) とする。
  4. FromPropertyDescriptor(propertyDesc)を返す。

20.1.2.9 Object.getOwnPropertyDescriptors ( obj )

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. coercedを ? ToObject(obj) とする。
  2. ownKeysを ? coerced.[[OwnPropertyKeys]]() とする。
  3. descsOrdinaryObjectCreate(%Object.prototype%)とする。
  4. ownKeysの各要素keyについて、以下を行う
    1. propertyDescを ? coerced.[[GetOwnProperty]](key) とする。
    2. propertyDescObjFromPropertyDescriptor(propertyDesc)とする。
    3. propertyDescObjundefinedでないなら、! CreateDataPropertyOrThrow(descs, key, propertyDescObj)を実行する。
  5. descsを返す。

20.1.2.10 Object.getOwnPropertyNames ( obj )

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. CreateArrayFromList(? GetOwnPropertyKeys(obj, string))を返す。

20.1.2.11 Object.getOwnPropertySymbols ( obj )

このfunctionは呼び出されたとき、次のstepsを実行します:

  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を新しい空のListとする。
  4. keysの各要素nextKeyについて、以下を行う
    1. nextKeyがSymbolでありtypesymbolである、またはnextKeyがStringでありtypestringであるなら、
      1. nextKeynameListへappendする。
  5. nameListを返す。

20.1.2.12 Object.getPrototypeOf ( obj )

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. coercedを ? ToObject(obj) とする。
  2. coerced.[[GetPrototypeOf]]()を返す。

20.1.2.13 Object.groupBy ( items, callback )

Note

callbackは2つのargumentsをacceptするfunctionであるべきです。groupByitems内の各elementについてascending orderでcallbackを1回呼び出し、新しいobjectをconstructします。callbackによって返される各valueはproperty keyへcoercedされます。そのような各property keyについて、result objectは、そのkeyがそのproperty keyであり、そのvalueがcallbackのreturn valueがそのkeyへcoercedされたすべてのelementsを含むarrayであるpropertyを持ちます。

callbackは2つのarguments、すなわちelementのvalueとelementのindexを伴って呼び出されます。

groupByのreturn valueは%Object.prototype%からinheritしないobjectです。

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. GroupBy(items, callback, property)をgroupsとする。
  2. OrdinaryObjectCreate(null)をobjとする。
  3. groupsの各Record { [[Key]], [[Elements]] } groupについて、次を行う。
    1. CreateArrayFromList(group.[[Elements]])をelementsとする。
    2. CreateDataPropertyOrThrow(obj, group.[[Key]], elements)を実行する。
  4. objを返す。

20.1.2.14 Object.hasOwn ( obj, key )

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. coercedを ? ToObject(obj) とする。
  2. propertyKeyを ? ToPropertyKey(key) とする。
  3. HasOwnProperty(coerced, propertyKey)を返す。

20.1.2.15 Object.is ( value1, value2 )

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. SameValue(value1, value2)を返す。

20.1.2.16 Object.isExtensible ( obj )

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. objがObjectでないなら、falseを返す。
  2. IsExtensible(obj)を返す。

20.1.2.17 Object.isFrozen ( obj )

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. objがObjectでないなら、trueを返す。
  2. TestIntegrityLevel(obj, frozen)を返す。

20.1.2.18 Object.isSealed ( obj )

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. objがObjectでないなら、trueを返す。
  2. TestIntegrityLevel(obj, sealed)を返す。

20.1.2.19 Object.keys ( obj )

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. coercedを ? ToObject(obj) とする。
  2. keyListを ? EnumerableOwnProperties(coerced, key) とする。
  3. CreateArrayFromList(keyList)を返す。

20.1.2.20 Object.preventExtensions ( obj )

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. objがObjectでないなら、objを返す。
  2. statusを ? obj.[[PreventExtensions]]() とする。
  3. statusfalseなら、TypeError例外をthrowする。
  4. objを返す。

20.1.2.21 Object.prototype

Object.prototypeのinitial valueはObject prototype objectです。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

20.1.2.22 Object.seal ( obj )

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. objがObjectでないなら、objを返す。
  2. statusを ? SetIntegrityLevel(obj, sealed) とする。
  3. statusfalseなら、TypeError例外をthrowする。
  4. objを返す。

20.1.2.23 Object.setPrototypeOf ( obj, proto )

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. RequireObjectCoercible(obj)を実行する。
  2. protoがObjectでなく、かつprotonullでないなら、TypeError例外をthrowする。
  3. objがObjectでないなら、objを返す。
  4. statusを ? obj.[[SetPrototypeOf]](proto) とする。
  5. statusfalseなら、TypeError例外をthrowする。
  6. objを返す。

20.1.2.24 Object.values ( obj )

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. coercedを ? ToObject(obj) とする。
  2. valueListを ? EnumerableOwnProperties(coerced, value) とする。
  3. CreateArrayFromList(valueList)を返す。

20.1.3 Properties of the Object Prototype Object

Object prototype objectは:

  • %Object.prototype%です。
  • valueがtrueである[[Extensible]] internal slotを持ちます。
  • ordinary objectsのために定義されるinternal methodsを持ちます。ただし[[SetPrototypeOf]] methodは例外で、10.4.7.1で定義される通りです。(したがって、これはimmutable prototype exotic objectです。)
  • valueがnullである[[Prototype]] internal slotを持ちます。

20.1.3.1 Object.prototype.constructor

Object.prototype.constructorのinitial valueは%Object%です。

20.1.3.2 Object.prototype.hasOwnProperty ( value )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. propertyKeyを ? ToPropertyKey(value) とする。
  2. objを ? ToObject(this value) とする。
  3. HasOwnProperty(obj, propertyKey)を返す。
Note

steps 1および2のorderingは、this valueがundefinedまたはnullであっても、この仕様のprevious editionsにおいてstep 1によってthrowされていたであろう任意のexceptionが引き続きthrowされることを保証するために選ばれています。

20.1.3.3 Object.prototype.isPrototypeOf ( value )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. valueがObjectでないなら、falseを返す。
  2. objを ? ToObject(this value) とする。
  3. 繰り返す
    1. valueを ? value.[[GetPrototypeOf]]() に設定する。
    2. valuenullなら、falseを返す。
    3. SameValue(obj, value)がtrueなら、trueを返す。
Note

steps 1および2のorderingは、valueがobjectでなく、this valueがundefinedまたはnullであるcaseについて、この仕様のprevious editionsで指定されたbehaviourをpreserveします。

20.1.3.4 Object.prototype.propertyIsEnumerable ( value )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. propertyKeyを ? ToPropertyKey(value) とする。
  2. objを ? ToObject(this value) とする。
  3. propertyDescを ? obj.[[GetOwnProperty]](propertyKey) とする。
  4. propertyDescundefinedなら、falseを返す。
  5. propertyDesc.[[Enumerable]]を返す。
Note 1

このmethodはprototype chain内のobjectsを考慮しません。

Note 2

steps 1および2のorderingは、this valueがundefinedまたはnullであっても、この仕様のprevious editionsにおいてstep 1によってthrowされていたであろう任意のexceptionが引き続きthrowされることを保証するために選ばれています。

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

このmethodは呼び出されたとき、次のstepsを実行します:

  1. thisValuethis valueとする。
  2. Invoke(thisValue, "toString")を返す。

このmethodのoptional parametersは使用されませんが、ECMA-402 toLocaleString methodsによって使用されるparameter patternに対応することを意図しています。ECMA-402 supportを含まないimplementationsは、これらのparameter positionsを他のpurposesのために使用してはなりません。

Note 1

このmethodは、locale-sensitiveなtoString behaviourを持たないobjectsに対してgenericなtoLocaleString implementationを提供します。ArrayNumberDate、および%TypedArray%は、それぞれ独自のlocale-sensitiveなtoLocaleString methodsを提供します。

Note 2

ECMA-402は意図的に、このdefault implementationのalternativeを提供していません。

20.1.3.6 Object.prototype.toString ( )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. this valueがundefinedなら、"[object Undefined]"を返す。
  2. this valueがnullなら、"[object Null]"を返す。
  3. objを ! ToObject(this value) とする。
  4. isArrayを ? IsArray(obj) とする。
  5. isArraytrueなら、builtinTag"Array"とする。
  6. そうでなく、obj[[ParameterMap]] internal slotを持つなら、builtinTag"Arguments"とする。
  7. そうでなく、obj[[Call]] internal methodを持つなら、builtinTag"Function"とする。
  8. そうでなく、obj[[ErrorData]] internal slotを持つなら、builtinTag"Error"とする。
  9. そうでなく、obj[[BooleanData]] internal slotを持つなら、builtinTag"Boolean"とする。
  10. そうでなく、obj[[NumberData]] internal slotを持つなら、builtinTag"Number"とする。
  11. そうでなく、obj[[StringData]] internal slotを持つなら、builtinTag"String"とする。
  12. そうでなく、obj[[DateValue]] internal slotを持つなら、builtinTag"Date"とする。
  13. そうでなく、obj[[RegExpMatcher]] internal slotを持つなら、builtinTag"RegExp"とする。
  14. そうでなければ、builtinTag"Object"とする。
  15. tagを ? Get(obj, %Symbol.toStringTag%) とする。
  16. tagがStringでないなら、tagbuiltinTagに設定する。
  17. "[object "tag、および"]"string-concatenationを返す。
Note

Historically、このmethodは、この仕様のprevious editionsでさまざまなbuilt-in objectsのnominal type tagとして使用されていた[[Class]] internal slotのString valueにaccessするために時々使用されていました。上記のtoStringのdefinitionは、toStringをそれら特定の種類のbuilt-in objectsに対するtestとして使用するlegacy codeとのcompatibilityをpreserveします。これは他の種類のbuilt-inまたはprogram defined objectsに対するreliable type testing mechanismを提供しません。加えて、programsは、そのようなlegacy type testsのreliabilityを無効にする方法で%Symbol.toStringTag%を使用できます。

20.1.3.7 Object.prototype.valueOf ( )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. ToObject(this value)を返す。

20.1.3.8 Object.prototype.__proto__

Object.prototype.__proto__はattributes { [[Enumerable]]: false, [[Configurable]]: true }を持つaccessor propertyです。[[Get]]および[[Set]] attributesは次のように定義されます:

20.1.3.8.1 get Object.prototype.__proto__

[[Get]] attributeのvalueは、argumentsを要求しないbuilt-in functionです。これは呼び出されたとき、次のstepsを実行します:

  1. objを ? ToObject(this value) とする。
  2. obj.[[GetPrototypeOf]]()を返す。

20.1.3.8.2 set Object.prototype.__proto__

[[Set]] attributeのvalueは、argument protoを取るbuilt-in functionです。これは呼び出されたとき、次のstepsを実行します:

  1. thisValuethis valueとする。
  2. RequireObjectCoercible(thisValue)を実行する。
  3. protoがObjectでなく、かつprotonullでないなら、undefinedを返す。
  4. thisValueがObjectでないなら、undefinedを返す。
  5. statusを ? thisValue.[[SetPrototypeOf]](proto) とする。
  6. statusfalseなら、TypeError例外をthrowする。
  7. undefinedを返す。

20.1.3.9 Legacy Object.prototype Accessor Methods

20.1.3.9.1 Object.prototype.__defineGetter__ ( key, getter )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. objを ? ToObject(this value) とする。
  2. IsCallable(getter)がfalseなら、TypeError例外をthrowする。
  3. propertyDescをPropertyDescriptor { [[Get]]: getter, [[Enumerable]]: true, [[Configurable]]: true }とする。
  4. propertyKeyを ? ToPropertyKey(key) とする。
  5. DefinePropertyOrThrow(obj, propertyKey, propertyDesc)を実行する。
  6. undefinedを返す。

20.1.3.9.2 Object.prototype.__defineSetter__ ( key, setter )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. objを ? ToObject(this value) とする。
  2. IsCallable(setter)がfalseなら、TypeError例外をthrowする。
  3. propertyDescをPropertyDescriptor { [[Set]]: setter, [[Enumerable]]: true, [[Configurable]]: true }とする。
  4. propertyKeyを ? ToPropertyKey(key) とする。
  5. DefinePropertyOrThrow(obj, propertyKey, propertyDesc)を実行する。
  6. undefinedを返す。

20.1.3.9.3 Object.prototype.__lookupGetter__ ( key )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. objを ? ToObject(this value) とする。
  2. propertyKeyを ? ToPropertyKey(key) とする。
  3. 繰り返す
    1. propertyDescを ? obj.[[GetOwnProperty]](propertyKey) とする。
    2. propertyDescundefinedでないなら、
      1. IsAccessorDescriptor(propertyDesc)がtrueなら、propertyDesc.[[Get]]を返す。
      2. undefinedを返す。
    3. objを ? obj.[[GetPrototypeOf]]() に設定する。
    4. objnullなら、undefinedを返す。

20.1.3.9.4 Object.prototype.__lookupSetter__ ( key )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. objを ? ToObject(this value) とする。
  2. propertyKeyを ? ToPropertyKey(key) とする。
  3. 繰り返す
    1. propertyDescを ? obj.[[GetOwnProperty]](propertyKey) とする。
    2. propertyDescundefinedでないなら、
      1. IsAccessorDescriptor(propertyDesc)がtrueなら、propertyDesc.[[Set]]を返す。
      2. undefinedを返す。
    3. objを ? obj.[[GetPrototypeOf]]() に設定する。
    4. objnullなら、undefinedを返す。

20.1.4 Properties of Object Instances

Object instancesは、Object prototype objectからinheritedされるもの以外にspecial propertiesを持ちません。

20.2 Function Objects

20.2.1 The Function Constructor

Function constructorは:

  • %Function%です。
  • global object"Function" propertyのinitial valueです。
  • constructorとしてではなくfunctionとして呼び出されたとき、新しいfunction objectを作成およびinitializeします。したがってfunction call Function(…)は、同じargumentsを伴うobject creation expression new Function(…)と同等です。
  • class definitionのextends clauseのvalueとして使用できます。指定されたFunction behaviourをinheritしようとするsubclass constructorsは、built-in function behaviourに必要なinternal slotsを持つsubclass instanceを作成およびinitializeするために、Function constructorへのsuper callを含まなければなりません。function objectsを定義するすべてのECMAScript syntactic formsはFunctionのinstancesを作成します。built-in GeneratorFunction、AsyncFunction、およびAsyncGeneratorFunction subclassesを除き、Function subclassesのinstancesを作成するsyntactic meansはありません。

20.2.1.1 Function ( ...paramArgs, bodyArg )

最後のargument(ある場合)はfunctionのbody(executable code)を指定します;それより前のargumentsはformal parametersを指定します。

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. ctoractive function objectとする。
  2. bodyArgが存在しないなら、bodyArgをempty Stringに設定する。
  3. CreateDynamicFunction(ctor, NewTarget, normal, paramArgs, bodyArg)を返す。
Note

指定される各formal parameterごとに1つのargumentを持つことは許されますが、必要ではありません。例えば、次の3つのexpressionsはすべて同じresultをproduceします:

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 ( ctor, newTarget, kind, paramArgs, bodyArg )

The abstract operation CreateDynamicFunction takes arguments ctor (a constructor), newTarget (a constructor or undefined), kind (normal, generator, async, or async-generator), paramArgs (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. ctorはこのactionを実行しているconstructor functionです。newTargetnewがinitiallyに適用されたconstructorです。paramArgsおよびbodyArgctorへ渡されたargument valuesをreflectします。 It performs the following steps when called:

  1. newTargetundefinedなら、newTargetctorに設定する。
  2. kindnormalなら、
    1. prefix"function"とする。
    2. exprGrammarをgrammar symbol FunctionExpressionとする。
    3. bodyGrammarをgrammar symbol FunctionBody[~Yield, ~Await]とする。
    4. paramGrammarをgrammar symbol FormalParameters[~Yield, ~Await]とする。
    5. fallbackProto"%Function.prototype%"とする。
  3. そうでなく、kindgeneratorなら、
    1. prefix"function*"とする。
    2. exprGrammarをgrammar symbol GeneratorExpressionとする。
    3. bodyGrammarをgrammar symbol GeneratorBodyとする。
    4. paramGrammarをgrammar symbol FormalParameters[+Yield, ~Await]とする。
    5. fallbackProto"%GeneratorFunction.prototype%"とする。
  4. そうでなく、kindasyncなら、
    1. prefix"async function"とする。
    2. exprGrammarをgrammar symbol AsyncFunctionExpressionとする。
    3. bodyGrammarをgrammar symbol AsyncFunctionBodyとする。
    4. paramGrammarをgrammar symbol FormalParameters[~Yield, +Await]とする。
    5. fallbackProto"%AsyncFunction.prototype%"とする。
  5. そうでなければ、
    1. Assert: kindasync-generatorである。
    2. prefix"async function*"とする。
    3. exprGrammarをgrammar symbol AsyncGeneratorExpressionとする。
    4. bodyGrammarをgrammar symbol AsyncGeneratorBodyとする。
    5. paramGrammarをgrammar symbol FormalParameters[+Yield, +Await]とする。
    6. fallbackProto"%AsyncGeneratorFunction.prototype%"とする。
  6. argCountparamArgs内の要素数とする。
  7. paramStringsを新しい空のListとする。
  8. paramArgsの各要素argについて、以下を行う
    1. ToString(arg)をparamStringsへappendする。
  9. bodyStringを ? ToString(bodyArg) とする。
  10. currentRealmcurrent Realm Recordとする。
  11. HostEnsureCanCompileStrings(currentRealm, paramStrings, bodyString, false)を実行する。
  12. paramStringをempty Stringとする。
  13. argCount > 0なら、
    1. paramStringparamStrings[0]に設定する。
    2. kを1とする。
    3. k < argCountの間、繰り返す
      1. nextArgStringparamStrings[k]とする。
      2. paramStringparamString","(comma)、およびnextArgStringstring-concatenationに設定する。
      3. kk + 1に設定する。
  14. bodyParseStringを0x000A (LINE FEED)、bodyString、および0x000A (LINE FEED)のstring-concatenationとする。
  15. sourceStringprefix" anonymous("paramString、0x000A (LINE FEED)、") {"bodyParseString、および"}"string-concatenationとする。
  16. sourceTextStringToCodePoints(sourceString)とする。
  17. paramsParseText(paramString, paramGrammar)とする。
  18. paramsがerrorsのListなら、SyntaxError例外をthrowする。
  19. bodyParseText(bodyParseString, bodyGrammar)とする。
  20. bodyがerrorsのListなら、SyntaxError例外をthrowする。
  21. NOTE: parametersとbodyは、それぞれが単独でvalidであることを保証するためにseparatelyにparsedされる。例えば、new Function("/*", "*/ ) {")はfunctionへevaluateされない。
  22. NOTE: このstepに到達した場合、sourceTextexprGrammarのsyntaxを持っていなければならない(ただしそのreverse implicationは成り立たない)。次の2つのstepsの目的は、exprGrammarにdirectlyにapplyされる任意のEarly Error rulesをenforceすることである。
  23. exprParseText(sourceText, exprGrammar)とする。
  24. exprがerrorsのListなら、SyntaxError例外をthrowする。
  25. funcProtoを ? GetPrototypeFromConstructor(newTarget, fallbackProto) とする。
  26. envRecordcurrentRealm.[[GlobalEnv]]とする。
  27. privateEnvnullとする。
  28. funcOrdinaryFunctionCreate(funcProto, sourceText, params, body, non-lexical-this, envRecord, privateEnv)とする。
  29. SetFunctionName(func, "anonymous")を実行する。
  30. kindgeneratorなら、
    1. protoProtoOrdinaryObjectCreate(%GeneratorPrototype%)とする。
    2. DefinePropertyOrThrow(func, "prototype", PropertyDescriptor { [[Value]]: protoProto, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })を実行する。
  31. そうでなく、kindasync-generatorなら、
    1. protoProtoOrdinaryObjectCreate(%AsyncGeneratorPrototype%)とする。
    2. DefinePropertyOrThrow(func, "prototype", PropertyDescriptor { [[Value]]: protoProto, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })を実行する。
  32. そうでなく、kindnormalなら、
    1. MakeConstructor(func)を実行する。
  33. NOTE: kindasyncであるfunctionsはconstructableではなく、[[Construct]] internal methodまたは"prototype" propertyを持たない。
  34. funcを返す。
Note

CreateDynamicFunctionは、そのkindasyncでない、作成する任意のfunctionに対して"prototype" propertyを定義し、そのfunctionがconstructorとして使用される可能性に備えます。

20.2.2 Properties of the Function Constructor

Function constructorは:

  • それ自体がbuilt-in function objectです。
  • valueが%Function.prototype%である[[Prototype]] internal slotを持ちます。
  • valueが1𝔽である"length" propertyを持ちます。
  • 次のpropertiesを持ちます:

20.2.2.1 Function.prototype

Function.prototypeのvalueはFunction prototype objectです。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

20.2.3 Properties of the Function Prototype Object

Function prototype objectは:

  • %Function.prototype%です。
  • それ自体がbuilt-in function objectです。
  • 任意のargumentsをacceptし、invokedされたときundefinedを返します。
  • [[Construct]] internal methodを持ちません;new operatorを伴うconstructorとして使用できません。
  • valueが%Object.prototype%である[[Prototype]] internal slotを持ちます。
  • "prototype" propertyを持ちません。
  • valueが+0𝔽である"length" propertyを持ちます。
  • valueがempty Stringである"name" propertyを持ちます。
Note

Function prototype objectは、ECMAScript 2015 specificationより前に作成されたECMAScript codeとのcompatibilityを保証するため、function objectであると指定されています。

20.2.3.1 Function.prototype.apply ( thisArg, argArray )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. functhis valueとする。
  2. IsCallable(func)がfalseなら、TypeError例外をthrowする。
  3. argArrayundefinedまたはnullのいずれかなら、
    1. PrepareForTailCall()を実行する。
    2. Call(func, thisArg)を返す。
  4. argListを ? CreateListFromArrayLike(argArray) とする。
  5. PrepareForTailCall()を実行する。
  6. Call(func, thisArg, argList)を返す。
Note 1

thisArg valueは、modificationなしでthis valueとして渡されます。これはEdition 3からのchangeであり、そこではundefinedまたはnullthisArgglobal objectで置き換えられ、他のすべてのvaluesにはToObjectが適用され、そのresultがthis valueとして渡されていました。thisArgはmodificationなしで渡されますが、non-strict functionsはfunctionへのentry時に引き続きこれらのtransformationsを実行します。

Note 2

funcがarrow functionまたはbound function exotic objectのいずれかである場合、step 6のfunction [[Call]]によってthisArgはignoredされます。

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

このmethodは呼び出されたとき、次のstepsを実行します:

  1. targetthis valueとする。
  2. IsCallable(target)がfalseなら、TypeError例外をthrowする。
  3. boundFuncを ? BoundFunctionCreate(target, thisArg, args) とする。
  4. lengthを0とする。
  5. targetHasLengthを ? HasOwnProperty(target, "length") とする。
  6. targetHasLengthtrueなら、
    1. targetLengthを ? Get(target, "length") とする。
    2. targetLengthがNumberなら、
      1. targetLength+∞𝔽なら、
        1. lengthを+∞に設定する。
      2. そうでなく、targetLength-∞𝔽なら、
        1. lengthを0に設定する。
      3. そうでなければ、
        1. targetLengthAsIntを ! ToIntegerOrInfinity(targetLength) とする。
        2. Assert: targetLengthAsIntfiniteである。
        3. argCountargs内の要素数とする。
        4. lengthmax(targetLengthAsInt - argCount, 0)に設定する。
  7. SetFunctionLength(boundFunc, length)を実行する。
  8. targetNameを ? Get(target, "name") とする。
  9. targetNameがStringでないなら、targetNameをempty Stringに設定する。
  10. SetFunctionName(boundFunc, targetName, "bound")を実行する。
  11. boundFuncを返す。
Note 1

Function.prototype.bindを使用して作成されたFunction objectsexotic objectsです。それらはまた"prototype" propertyを持ちません。

Note 2

targetがarrow functionまたはbound function exotic objectのいずれかである場合、このmethodに渡されたthisArgfuncへのsubsequent callsによって使用されません。

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

このmethodは呼び出されたとき、次のstepsを実行します:

  1. functhis valueとする。
  2. IsCallable(func)がfalseなら、TypeError例外をthrowする。
  3. PrepareForTailCall()を実行する。
  4. Call(func, thisArg, args)を返す。
Note 1

thisArg valueは、modificationなしでthis valueとして渡されます。これはEdition 3からのchangeであり、そこではundefinedまたはnullthisArgglobal objectで置き換えられ、他のすべてのvaluesにはToObjectが適用され、そのresultがthis valueとして渡されていました。thisArgはmodificationなしで渡されますが、non-strict functionsはfunctionへのentry時に引き続きこれらのtransformationsを実行します。

Note 2

funcがarrow functionまたはbound function exotic objectのいずれかである場合、step 4のfunction [[Call]]によってthisArgはignoredされます。

20.2.3.4 Function.prototype.constructor

Function.prototype.constructorのinitial valueは%Function%です。

20.2.3.5 Function.prototype.toString ( )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. functhis valueとする。
  2. funcがObjectであり、func[[SourceText]] internal slotを持ち、func.[[SourceText]]がUnicode code pointsのsequenceであり、かつHostHasSourceTextAvailable(func)がtrueなら、
    1. CodePointsToString(func.[[SourceText]])を返す。
  3. funcbuilt-in function objectなら、funcimplementation-defined String source code representationを返す。そのrepresentationはNativeFunctionのsyntaxを持たなければなりません。加えて、func[[InitialName]] internal slotを持ち、func.[[InitialName]]がStringである場合、NativeFunctionAccessoropt PropertyNameにmatchするreturned Stringのportionはfunc.[[InitialName]]でなければなりません。
  4. funcがObjectであり、IsCallable(func)がtrueなら、funcimplementation-defined String source code representationを返す。そのrepresentationはNativeFunctionのsyntaxを持たなければなりません。
  5. TypeError例外をThrowする。
NativeFunction : function NativeFunctionAccessoropt PropertyName[~Yield, ~Await]opt ( FormalParameters[~Yield, ~Await] ) { [ native code ] } NativeFunctionAccessor : get set

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

このmethodは呼び出されたとき、次のstepsを実行します:

  1. thisValuethis valueとする。
  2. OrdinaryHasInstance(thisValue, value)を返す。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

Note

これは、ほとんどのfunctionsがinheritする%Symbol.hasInstance%のdefault implementationです。%Symbol.hasInstance%は、valueがspecific constructorのinstanceであるかどうかをdetermineするためにinstanceof operatorによって呼び出されます。次のようなexpressionは、

v instanceof F

次のようにevaluatesされます

F[%Symbol.hasInstance%](v)

constructor functionは、function上に異なる%Symbol.hasInstance% methodをexposeすることによって、instanceofによってどのobjectsがそのinstancesとしてrecognizedされるかをcontrolできます。

このpropertyは、bound functionのtarget functionをgloballyにexposeするために使用され得るtamperingを防ぐため、non-writableかつnon-configurableです。

このmethodの"name" propertyのvalueは"[Symbol.hasInstance]"です。

20.2.4 Function Instances

すべてのFunction instanceはECMAScript function objectであり、Table 26に列挙されたinternal slotsを持ちます。Function.prototype.bind method(20.2.3.2)を使用して作成されたFunction objectsは、Table 27に列挙されたinternal slotsを持ちます。

Function instancesは次のpropertiesを持ちます:

20.2.4.1 length

"length" propertyのvalueは、functionによってexpectedされるtypical number of argumentsを示すintegral Numberです。ただし、languageはfunctionが他のnumber of argumentsでinvokedされることを許します。"length" propertyによって指定される数以外のnumber of argumentsでinvokedされたときのfunctionのbehaviourは、そのfunctionに依存します。このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }を持ちます。

20.2.4.2 name

"name" propertyのvalueは、functionをdescriptiveするStringです。nameにsemantic significanceはありませんが、通常はECMAScript source text内のdefinition pointでfunctionをreferするために使用されるvariableまたはproperty nameです。このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }を持ちます。

この仕様によってcontextual nameが関連付けられていないAnonymous function objectsは、"name" propertyのvalueとしてempty Stringを使用します。

20.2.4.3 prototype

constructorとして使用できるFunction instancesは"prototype" propertyを持ちます。そのようなFunction instanceが作成されるたびに、別のordinary objectも作成され、functionの"prototype" propertyのinitial valueになります。特に指定されない限り、"prototype" propertyのvalueは、そのfunctionがconstructorとしてinvokedされたときに作成されるobjectの[[Prototype]] internal slotをinitializeするために使用されます。

このpropertyはattributes { [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

Note

Function.prototype.bindを使用して作成されたFunction objects、またはMethodDefinitionGeneratorMethodまたはAsyncGeneratorMethodでないもの)もしくはArrowFunctionをevaluateすることによって作成されたFunction objectsは、"prototype" propertyを持ちません。

20.2.5 HostHasSourceTextAvailable ( func )

The host-defined abstract operation HostHasSourceTextAvailable takes argument func (a function object) and returns a Boolean. host environmentsfuncに対してsource textが提供されることをpreventできるようにします。

HostHasSourceTextAvailableのimplementationは、次のrequirementsにconformしなければなりません:

  • これはそのparametersに関してdeterministicでなければなりません。specific funcをargumentとして呼び出されるたびに、同じresultを返さなければなりません。

HostHasSourceTextAvailableのdefault implementationはtrueを返すことです。

20.3 Boolean Objects

20.3.1 The Boolean Constructor

Boolean constructorは:

  • %Boolean%です。
  • global object"Boolean" propertyのinitial valueです。
  • constructorとして呼び出されたとき、新しいBoolean objectを作成およびinitializeします。
  • constructorとしてではなくfunctionとして呼び出されたとき、type conversionを実行します。
  • class definitionのextends clauseのvalueとして使用できます。指定されたBoolean behaviourをinheritしようとするsubclass constructorsは、[[BooleanData]] internal slotを持つsubclass instanceを作成およびinitializeするために、Boolean constructorへのsuper callを含まなければなりません。

20.3.1.1 Boolean ( value )

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. boolToBoolean(value)とする。
  2. NewTargetがundefinedなら、boolを返す。
  3. objを ? OrdinaryCreateFromConstructor(NewTarget, "%Boolean.prototype%", « [[BooleanData]] ») とする。
  4. obj.[[BooleanData]]boolに設定する。
  5. objを返す。

20.3.2 Properties of the Boolean Constructor

Boolean constructorは:

  • valueが%Function.prototype%である[[Prototype]] internal slotを持ちます。
  • 次のpropertiesを持ちます:

20.3.2.1 Boolean.prototype

Boolean.prototypeのinitial valueはBoolean prototype objectです。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

20.3.3 Properties of the Boolean Prototype Object

Boolean prototype objectは:

  • %Boolean.prototype%です。
  • ordinary objectです。
  • それ自体がBoolean objectです;valueがfalseである[[BooleanData]] internal slotを持ちます。
  • valueが%Object.prototype%である[[Prototype]] internal slotを持ちます。

20.3.3.1 Boolean.prototype.constructor

Boolean.prototype.constructorのinitial valueは%Boolean%です。

20.3.3.2 Boolean.prototype.toString ( )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. boolを ? ThisBooleanValue(this value) とする。
  2. booltrueなら、"true"を返す。
  3. "false"を返す。

20.3.3.3 Boolean.prototype.valueOf ( )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. ThisBooleanValue(this value)を返す。

20.3.3.3.1 ThisBooleanValue ( arg )

The abstract operation ThisBooleanValue takes argument arg (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. argがBooleanなら、argを返す。
  2. argがObjectであり、arg[[BooleanData]] internal slotを持つなら、
    1. boolarg.[[BooleanData]]とする。
    2. Assert: boolはBooleanである。
    3. boolを返す。
  3. TypeError例外をThrowする。

20.3.4 Properties of Boolean Instances

Boolean instancesは、Boolean prototype objectからpropertiesをinheritするordinary objectsです。Boolean instancesは[[BooleanData]] internal slotを持ちます。[[BooleanData]] internal slotは、このBoolean objectによって表されるBoolean valueです。

20.4 Symbol Objects

20.4.1 The Symbol Constructor

Symbol constructorは:

  • %Symbol%です。
  • global object"Symbol" propertyのinitial valueです。
  • functionとして呼び出されたとき、新しいSymbol valueを返します。
  • new operatorとともに使用されることを意図していません。
  • subclassedされることを意図していません。
  • class definitionのextends clauseのvalueとして使用できますが、それへのsuper callはexceptionを引き起こします。

20.4.1.1 Symbol ( [ description ] )

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. NewTargetがundefinedでないなら、TypeError例外をthrowする。
  2. descriptionundefinedなら、descStringundefinedとする。
  3. そうでなければ、descStringを ? ToString(description) とする。
  4. ... [[Description]]descStringである新しいSymbolを返す。

20.4.2 Properties of the Symbol Constructor

Symbol constructorは:

  • valueが%Function.prototype%である[[Prototype]] internal slotを持ちます。
  • 次のpropertiesを持ちます:

20.4.2.1 Symbol.asyncIterator

Symbol.asyncIteratorのinitial valueはwell-known symbol %Symbol.asyncIterator%Table 1)です。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

20.4.2.2 Symbol.for ( key )

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. stringKey を ? ToString(key) とする。
  2. agentRecord を周囲のエージェントの Agent Record とする。
  3. globalSymbolRegistryagentRecord.[[GlobalSymbolRegistry]] とする。
  4. globalSymbolRegistry の各要素 element について、次を行う。
    1. element.[[Key]]stringKey である場合、element.[[Symbol]] を返す。
  5. Assert: globalSymbolRegistry は現在、stringKey に対するエントリーを含んでいない。
  6. newSymbol を、[[Description]]stringKey である新しい Symbol とする。
  7. GlobalSymbolRegistry Record { [[Key]]: stringKey, [[Symbol]]: newSymbol } を globalSymbolRegistry に追加する。
  8. newSymbol を返す。

20.4.2.3 Symbol.hasInstance

Symbol.hasInstanceのinitial valueはwell-known symbol %Symbol.hasInstance%Table 1)です。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

20.4.2.4 Symbol.isConcatSpreadable

Symbol.isConcatSpreadableのinitial valueはwell-known symbol %Symbol.isConcatSpreadable%Table 1)です。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

20.4.2.5 Symbol.iterator

Symbol.iteratorのinitial valueはwell-known symbol %Symbol.iterator%Table 1)です。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

20.4.2.6 Symbol.keyFor ( symbol )

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. symbolがSymbolでないなら、TypeError例外をthrowする。
  2. KeyForSymbol(symbol)を返す。

20.4.2.7 Symbol.match

Symbol.matchのinitial valueはwell-known symbol %Symbol.match%Table 1)です。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

20.4.2.8 Symbol.matchAll

Symbol.matchAllのinitial valueはwell-known symbol %Symbol.matchAll%Table 1)です。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

20.4.2.9 Symbol.prototype

Symbol.prototypeのinitial valueはSymbol prototype objectです。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

20.4.2.10 Symbol.replace

Symbol.replaceのinitial valueはwell-known symbol %Symbol.replace%Table 1)です。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

20.4.2.11 Symbol.search

Symbol.searchのinitial valueはwell-known symbol %Symbol.search%Table 1)です。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

20.4.2.12 Symbol.species

Symbol.speciesのinitial valueはwell-known symbol %Symbol.species%Table 1)です。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

20.4.2.13 Symbol.split

Symbol.splitのinitial valueはwell-known symbol %Symbol.split%Table 1)です。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

20.4.2.14 Symbol.toPrimitive

Symbol.toPrimitiveのinitial valueはwell-known symbol %Symbol.toPrimitive%Table 1)です。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

20.4.2.15 Symbol.toStringTag

Symbol.toStringTagのinitial valueはwell-known symbol %Symbol.toStringTag%Table 1)です。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

20.4.2.16 Symbol.unscopables

Symbol.unscopablesのinitial valueはwell-known symbol %Symbol.unscopables%Table 1)です。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

20.4.3 Properties of the Symbol Prototype Object

Symbol prototype objectは:

  • %Symbol.prototype%です。
  • ordinary objectです。
  • Symbol instanceではなく、[[SymbolData]] internal slotを持ちません。
  • valueが%Object.prototype%である[[Prototype]] internal slotを持ちます。

20.4.3.1 Symbol.prototype.constructor

Symbol.prototype.constructorのinitial valueは%Symbol%です。

20.4.3.2 get Symbol.prototype.description

Symbol.prototype.descriptionは、set accessor functionがundefinedであるaccessor propertyです。そのget accessor functionは呼び出されたとき、次のstepsを実行します:

  1. symbolを ? ThisSymbolValue(this value) とする。
  2. symbol.[[Description]]を返す。

20.4.3.3 Symbol.prototype.toString ( )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. symbolを ? ThisSymbolValue(this value) とする。
  2. SymbolDescriptiveString(symbol)を返す。

20.4.3.3.1 SymbolDescriptiveString ( symbol )

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

  1. symbol.[[Description]]descriptionとする。
  2. descriptionundefinedである場合、descriptionを空のStringに設定する。
  3. Assert: descriptionはStringである。
  4. "Symbol("description、および")"string-concatenationを返す。

20.4.3.4 Symbol.prototype.valueOf ( )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. ThisSymbolValue(this value)を返す。

20.4.3.4.1 ThisSymbolValue ( arg )

The abstract operation ThisSymbolValue takes argument arg (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. argがSymbolなら、argを返す。
  2. argがObjectであり、arg[[SymbolData]] internal slotを持つなら、
    1. symbolarg.[[SymbolData]]とする。
    2. Assert: symbolはSymbolである。
    3. symbolを返す。
  3. TypeError例外をThrowする。

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

このmethodは、Symbol objectをprimitive valueへconvertするためにECMAScript language operatorsによって呼び出されます。

これは呼び出されたとき、次のstepsを実行します:

  1. ThisSymbolValue(this value)を返す。
Note

argumentはignoredされます。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }を持ちます。

このmethodの"name" propertyのvalueは"[Symbol.toPrimitive]"です。

20.4.3.6 Symbol.prototype [ %Symbol.toStringTag% ]

%Symbol.toStringTag% propertyのinitial valueはString value "Symbol"です。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }を持ちます。

20.4.4 Properties of Symbol Instances

Symbol instancesは、Symbol prototype objectからpropertiesをinheritするordinary objectsです。Symbol instancesは[[SymbolData]] internal slotを持ちます。[[SymbolData]] internal slotは、このSymbol objectによって表されるSymbol valueです。

20.4.5 Abstract Operations for Symbols

20.4.5.1 GlobalSymbolRegistry Records

GlobalSymbolRegistry Record は、Symbol.for を通じて登録された Symbol 値に String キーを関連付けるために使用される Record 値である。

GlobalSymbolRegistry Records は、Table 59 に列挙されたフィールドを持つ。

Table 59: GlobalSymbolRegistry Record のフィールド
フィールド名 用途
[[Key]] String Symbol をグローバルに識別するために使用される文字列キー。
[[Symbol]] Symbol 任意の realm から取得できるシンボル。

20.4.5.2 KeyForSymbol ( symbol )

The abstract operation KeyForSymbol takes argument symbol (a Symbol) and returns a String or undefined. symbol が周囲のエージェントの [[GlobalSymbolRegistry]] List 内にある場合、symbol の登録に使用された String が返される。 It performs the following steps when called:

  1. agentRecord を周囲のエージェントの Agent Record とする。
  2. globalSymbolRegistryagentRecord.[[GlobalSymbolRegistry]] とする。
  3. globalSymbolRegistry の各要素 element について、次を行う。
    1. SameValue(element.[[Symbol]], symbol) が true である場合、element.[[Key]] を返す。
  4. Assert: globalSymbolRegistry は現在、symbol に対するエントリーを含んでいない。
  5. undefined を返す。

20.5 Error Objects

runtime errorsが発生したとき、Error objectsのinstancesはexceptionsとしてthrownされます。Error objectsはuser-defined exception classesのbase objectsとしてもserveする場合があります。

ECMAScript 実装が実行時エラーを検出した場合、20.5.5 で定義される NativeError オブジェクトのいずれかの新しいインスタンス、または 20.5.7 で定義される AggregateError オブジェクト、もしくは 20.5.8 で定義される SuppressedError オブジェクトの新しいインスタンスを投げる。これらの各オブジェクトは以下に記述される構造を持ち、違いは NativeError の代わりにコンストラクタ名として使用される名前、プロトタイプオブジェクトの "name" プロパティ、プロトタイプオブジェクトの実装定義の "message" プロパティ、および %AggregateError% 固有の "errors" プロパティまたは %SuppressedError% 固有の "error" および "suppressed" プロパティの存在のみである。

20.5.1 The Error Constructor

Error constructorは:

  • %Error%です。
  • global object"Error" propertyのinitial valueです。
  • constructorとしてではなくfunctionとして呼び出されたとき、新しいError objectを作成およびinitializeします。したがってfunction call Error(…)は、同じargumentsを伴うobject creation expression new Error(…)と同等です。
  • class definitionのextends clauseのvalueとして使用できます。指定されたError behaviourをinheritしようとするsubclass constructorsは、[[ErrorData]] internal slotを持つsubclass instancesを作成およびinitializeするために、Error constructorへのsuper callを含まなければなりません。

20.5.1.1 Error ( message [ , options ] )

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. NewTargetがundefinedなら、newTargetactive function objectとする;そうでなければ、newTargetをNewTargetとする。
  2. objを ? OrdinaryCreateFromConstructor(newTarget, "%Error.prototype%", « [[ErrorData]] ») とする。
  3. messageundefinedでないなら、
    1. messageStringを ? ToString(message) とする。
    2. CreateNonEnumerableDataPropertyOrThrow(obj, "message", messageString)を実行する。
  4. InstallErrorCause(obj, options)を実行する。
  5. objを返す。

20.5.2 Properties of the Error Constructor

Error constructorは:

  • valueが%Function.prototype%である[[Prototype]] internal slotを持ちます。
  • 次のpropertiesを持ちます:

20.5.2.1 Error.isError ( arg )

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. argがObjectでないなら、falseを返す。
  2. arg[[ErrorData]] internal slotを持たないなら、falseを返す。
  3. trueを返す。

20.5.2.2 Error.prototype

Error.prototypeのinitial valueはError prototype objectです。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

20.5.3 Properties of the Error Prototype Object

Error prototype objectは:

  • %Error.prototype%です。
  • ordinary objectです。
  • Error instanceではなく、[[ErrorData]] internal slotを持ちません。
  • valueが%Object.prototype%である[[Prototype]] internal slotを持ちます。

20.5.3.1 Error.prototype.constructor

Error.prototype.constructorのinitial valueは%Error%です。

20.5.3.2 Error.prototype.message

Error.prototype.messageのinitial valueはempty Stringです。

20.5.3.3 Error.prototype.name

Error.prototype.nameのinitial valueは"Error"です。

20.5.3.4 Error.prototype.toString ( )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. objthis valueとする。
  2. objがObjectでないなら、TypeError例外をthrowする。
  3. nameを ? Get(obj, "name") とする。
  4. nameundefinedなら、name"Error"に設定する;そうでなければ、nameを ? ToString(name) に設定する。
  5. messageを ? Get(obj, "message") とする。
  6. messageundefinedなら、messageをempty Stringに設定する;そうでなければ、messageを ? ToString(message) に設定する。
  7. nameがempty Stringなら、messageを返す。
  8. messageがempty Stringなら、nameを返す。
  9. name、code unit 0x003A (COLON)、code unit 0x0020 (SPACE)、およびmessagestring-concatenationを返す。

20.5.4 Properties of Error Instances

Error インスタンスは、Error プロトタイプオブジェクトからプロパティを継承し、値が undefined である [[ErrorData]] 内部スロットを持つ通常のオブジェクトである。[[ErrorData]] の唯一の仕様上の用途は、Object.prototype.toString および Error.isError において、Error、AggregateError、SuppressedError、および NativeError インスタンスを Error オブジェクトとして識別することである。

20.5.5 Native Error Types Used in This Standard

実行時エラーが検出された場合、以下の NativeError オブジェクトのいずれか、または AggregateError オブジェクトもしくは SuppressedError オブジェクトの新しいインスタンスが投げられる。すべての NativeError オブジェクトは、20.5.6 に記述される同じ構造を共有する。

20.5.5.1 EvalError

EvalError constructor%EvalError%です。

このexceptionは現在この仕様内では使用されていません。このobjectは、この仕様のprevious editionsとのcompatibilityのために残されています。

20.5.5.2 RangeError

RangeError constructor%RangeError%です。

allowable valuesのsetまたはrange内にないvalueを示します。

20.5.5.3 ReferenceError

ReferenceError constructor%ReferenceError%です。

invalid referenceがdetectedされたことを示します。

20.5.5.4 SyntaxError

SyntaxError constructor%SyntaxError%です。

parsing errorが発生したことを示します。

20.5.5.5 TypeError

TypeError constructor%TypeError%です。

TypeErrorは、他のNativeError objectsのいずれもfailure causeのappropriate indicationでない場合に、unsuccessful operationを示すために使用されます。

20.5.5.6 URIError

URIError constructor%URIError%です。

global URI handling functionsの1つが、そのdefinitionとincompatibleな方法で使用されたことを示します。

20.5.6 NativeError Object Structure

これらの各objectは、constructor nameとして使用されるnameおよびprototype objectの"name" propertyだけが異なり、以下に記述されるstructureを持ちます。

各error objectについて、definition内のNativeErrorへのreferencesは、20.5.5からのappropriate error object nameで置き換えられるべきです。

20.5.6.1 The NativeError Constructors

NativeError constructorは:

  • constructorとしてではなくfunctionとして呼び出されたとき、新しいNativeError objectを作成およびinitializeします。functionとしてのobjectのcallは、同じargumentsでconstructorとして呼び出すことと同等です。したがってfunction call NativeError(…)は、同じargumentsを伴うobject creation expression new NativeError(…)と同等です。
  • class definitionのextends clauseのvalueとして使用できます。指定されたNativeError behaviourをinheritしようとするsubclass constructorsは、[[ErrorData]] internal slotを持つsubclass instancesを作成およびinitializeするために、NativeError constructorへのsuper callを含まなければなりません。

20.5.6.1.1 NativeError ( message [ , options ] )

NativeError functionは呼び出されたとき、次のstepsを実行します:

  1. NewTargetがundefinedなら、newTargetactive function objectとする;そうでなければ、newTargetをNewTargetとする。
  2. objを ? OrdinaryCreateFromConstructor(newTarget, "%NativeError.prototype%", « [[ErrorData]] ») とする。
  3. messageundefinedでないなら、
    1. messageStringを ? ToString(message) とする。
    2. CreateNonEnumerableDataPropertyOrThrow(obj, "message", messageString)を実行する。
  4. InstallErrorCause(obj, options)を実行する。
  5. objを返す。

step 2で渡されるstringのactual valueは、定義されているNativeError constructorに対応して、"%EvalError.prototype%""%RangeError.prototype%""%ReferenceError.prototype%""%SyntaxError.prototype%""%TypeError.prototype%"、または"%URIError.prototype%"のいずれかです。

20.5.6.2 Properties of the NativeError Constructors

NativeError constructorは:

  • valueが%Error%である[[Prototype]] internal slotを持ちます。
  • valueがString value "NativeError"である"name" propertyを持ちます。
  • 次のpropertiesを持ちます:

20.5.6.2.1 NativeError.prototype

NativeError.prototypeのinitial valueはNativeError prototype object(20.5.6.3)です。各NativeError constructorはdistinct prototype objectを持ちます。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

20.5.6.3 Properties of the NativeError Prototype Objects

NativeError prototype objectは:

  • ordinary objectです。
  • Error instanceではなく、[[ErrorData]] internal slotを持ちません。
  • valueが%Error.prototype%である[[Prototype]] internal slotを持ちます。

20.5.6.3.1 NativeError.prototype.constructor

与えられたNativeError constructorに対するprototypeの"constructor" propertyのinitial valueは、そのconstructor自身です。

20.5.6.3.2 NativeError.prototype.message

与えられたNativeError constructorに対するprototypeの"message" propertyのinitial valueはempty Stringです。

20.5.6.3.3 NativeError.prototype.name

与えられたNativeError constructorに対するprototypeの"name" propertyのinitial valueは、constructorのname(NativeErrorの代わりに使用されるname)から構成されるString valueです。

20.5.6.4 Properties of NativeError Instances

NativeError インスタンスは、自身の NativeError プロトタイプオブジェクトからプロパティを継承し、値が undefined である [[ErrorData]] 内部スロットを持つ通常のオブジェクトである。[[ErrorData]] の唯一の仕様上の用途は、Object.prototype.toString20.1.3.6)および Error.isError20.5.2.1)によって、Error、AggregateError、SuppressedError、または NativeError インスタンスを識別することである。

20.5.7 AggregateError Objects

20.5.7.1 The AggregateError Constructor

AggregateError constructorは:

  • %AggregateError%です。
  • global object"AggregateError" propertyのinitial valueです。
  • constructorとしてではなくfunctionとして呼び出されたとき、新しいAggregateError objectを作成およびinitializeします。したがってfunction call AggregateError(…)は、同じargumentsを伴うobject creation expression new AggregateError(…)と同等です。
  • class definitionのextends clauseのvalueとして使用できます。指定されたAggregateError behaviourをinheritしようとするsubclass constructorsは、[[ErrorData]] internal slotを持つsubclass instancesを作成およびinitializeするために、AggregateError constructorへのsuper callを含まなければなりません。

20.5.7.1.1 AggregateError ( errors, message [ , options ] )

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. NewTargetがundefinedなら、newTargetactive function objectとする;そうでなければ、newTargetをNewTargetとする。
  2. objを ? OrdinaryCreateFromConstructor(newTarget, "%AggregateError.prototype%", « [[ErrorData]] ») とする。
  3. messageundefinedでないなら、
    1. messageStringを ? ToString(message) とする。
    2. CreateNonEnumerableDataPropertyOrThrow(obj, "message", messageString)を実行する。
  4. InstallErrorCause(obj, options)を実行する。
  5. errorsListを ? IteratorToList(? GetIterator(errors, sync)) とする。
  6. DefinePropertyOrThrow(obj, "errors", PropertyDescriptor { [[Configurable]]: true, [[Enumerable]]: false, [[Writable]]: true, [[Value]]: CreateArrayFromList(errorsList) })を実行する。
  7. objを返す。

20.5.7.2 Properties of the AggregateError Constructor

AggregateError constructorは:

  • valueが%Error%である[[Prototype]] internal slotを持ちます。
  • 次のpropertiesを持ちます:

20.5.7.2.1 AggregateError.prototype

AggregateError.prototypeのinitial valueは%AggregateError.prototype%です。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

20.5.7.3 Properties of the AggregateError Prototype Object

AggregateError prototype objectは:

  • %AggregateError.prototype%です。
  • ordinary objectです。
  • Error instanceでもAggregateError instanceでもなく、[[ErrorData]] internal slotを持ちません。
  • valueが%Error.prototype%である[[Prototype]] internal slotを持ちます。

20.5.7.3.1 AggregateError.prototype.constructor

AggregateError.prototype.constructorのinitial valueは%AggregateError%です。

20.5.7.3.2 AggregateError.prototype.message

AggregateError.prototype.messageのinitial valueはempty Stringです。

20.5.7.3.3 AggregateError.prototype.name

AggregateError.prototype.nameのinitial valueは"AggregateError"です。

20.5.7.4 AggregateError インスタンスのプロパティ

AggregateError インスタンスは、自身の AggregateError プロトタイプオブジェクトからプロパティを継承し、値が undefined である [[ErrorData]] 内部スロットを持つ通常のオブジェクトである。[[ErrorData]] の唯一の仕様上の用途は、Object.prototype.toString20.1.3.6)および Error.isError20.5.2.1)によって、Error、AggregateError、SuppressedError、または NativeError インスタンスを識別することである。

20.5.8 SuppressedError オブジェクト

20.5.8.1 SuppressedError コンストラクタ

SuppressedError コンストラクタは次のとおりである:

  • %SuppressedError% である。
  • グローバルオブジェクトの "SuppressedError" プロパティの初期値である。
  • コンストラクタとしてではなく関数として呼び出された場合、新しい SuppressedError オブジェクトを作成して初期化する。したがって、関数呼び出し SuppressedError(…) は、同じ引数を持つオブジェクト作成式 new SuppressedError(…) と等価である。
  • クラス定義の extends 節の値として使用できる。指定された SuppressedError の振る舞いを継承しようとするサブクラスコンストラクタは、[[ErrorData]] 内部スロットを持つサブクラスインスタンスを作成して初期化するために、SuppressedError コンストラクタへの super 呼び出しを含めなければならない。

20.5.8.1.1 SuppressedError ( error, suppressed, message )

この関数は、呼び出されたときに次のステップを実行する:

  1. NewTarget が undefined である場合、newTarget をアクティブな関数オブジェクトとする。そうでなければ、newTarget を NewTarget とする。
  2. obj を ? OrdinaryCreateFromConstructor(newTarget, "%SuppressedError.prototype%", « [[ErrorData]] ») とする。
  3. messageundefined でない場合、then
    1. messageString を ? ToString(message) とする。
    2. CreateNonEnumerableDataPropertyOrThrow(obj, "message", messageString) を実行する。
  4. CreateNonEnumerableDataPropertyOrThrow(obj, "error", error) を実行する。
  5. CreateNonEnumerableDataPropertyOrThrow(obj, "suppressed", suppressed) を実行する。
  6. obj を返す。

20.5.8.2 SuppressedError コンストラクタのプロパティ

SuppressedError コンストラクタは次のとおりである:

  • 値が %Error% である [[Prototype]] 内部スロットを持つ。
  • 次のプロパティを持つ:

20.5.8.2.1 SuppressedError.prototype

SuppressedError.prototype の初期値は SuppressedError プロトタイプオブジェクトである。

このプロパティは属性 { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false } を持つ。

20.5.8.3 SuppressedError プロトタイプオブジェクトのプロパティ

SuppressedError プロトタイプオブジェクトは次のとおりである:

  • %SuppressedError.prototype% である。
  • 通常のオブジェクトである。
  • Error インスタンスでも SuppressedError インスタンスでもなく、[[ErrorData]] 内部スロットを持たない。
  • 値が %Error.prototype% である [[Prototype]] 内部スロットを持つ。

20.5.8.3.1 SuppressedError.prototype.constructor

SuppressedError.prototype.constructor の初期値は %SuppressedError% である。

20.5.8.3.2 SuppressedError.prototype.message

SuppressedError.prototype.message の初期値は空の String である。

20.5.8.3.3 SuppressedError.prototype.name

SuppressedError.prototype.name の初期値は "SuppressedError" である。

20.5.8.4 SuppressedError インスタンスのプロパティ

SuppressedError インスタンスは、自身の SuppressedError プロトタイプオブジェクトからプロパティを継承し、値が undefined である [[ErrorData]] 内部スロットを持つ通常のオブジェクトである。[[ErrorData]] の唯一の仕様上の用途は、Object.prototype.toString および Error.isError において、Error、AggregateError、SuppressedError、および NativeError インスタンスを Error オブジェクトとして識別することである。

20.5.9 Abstract Operations for Error Objects

20.5.9.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" propertyが存在する場合に、obj上に"cause" propertyを作成するために使用されます。 It performs the following steps when called:

  1. optionsがObjectであり、? HasProperty(options, "cause")がtrueなら、
    1. causeを ? Get(options, "cause") とする。
    2. CreateNonEnumerableDataPropertyOrThrow(obj, "cause", cause)を実行する。
  2. unusedを返す。