574
Reference number ECMA-123:2009 © Ecma International 2009 Ecma/TC39/2015/30 ECMA-262 6 th Edition / April 2015 Final draft ECMAScript 2015 Language Specification Report Errors and Issues at: https://bugs.ecmascript.org Product: Draft for 6th Edition Component: choose an appropriate one Version: Rev 38, April 14, 2015 Final Draft Draft

ECMAScript 2015 Language Specification - Ecma International€¦ · 14/04/2015  · Reference number ECMA-123:2009 Ecma International 2009 Ecma/TC39/2015/30 ECMA-262 6th Edition

  • Upload
    others

  • View
    20

  • Download
    0

Embed Size (px)

Citation preview

  • Reference number ECMA-123:2009

    © Ecma International 2009

    Ecma/TC39/2015/30

    ECMA-262 6th Edition / April 2015

    Final draft

    ECMAScript 2015

    Language Specification

    Report Errors and Issues at: https://bugs.ecmascript.org

    Product: Draft for 6th Edition Component: choose an appropriate one Version: Rev 38, April 14, 2015 Final Draft

    Draft

    https://bugs.ecmascript.org/

  • COPYRIGHT PROTECTED DOCUMENT

    © Ecma International 2015

  • © Ecma International 2015 i

    COPYRIGHT NOTICE

    © 2015 Ecma International

    This document may be copied, published and distributed to others, and certain derivative works of it may be prepared, copied, published, and distributed, in whole or in part, provided that the above copyright notice and this Copyright License and Disclaimer are included on all such copies and derivative works. The only derivative works that are permissible under this Copyright License and Disclaimer are:

    (i) works which incorporate all or portion of this document for the purpose of providing commentary or explanation (such as an annotated version of the document),

    (ii) works which incorporate all or portion of this document for the purpose of incorporating features that provide accessibility,

    (iii) translations of this document into languages other than English and into different formats and

    (iv) works by making use of this specification in standard conformant products by implementing (e.g. by copy and paste wholly or partly) the functionality therein.

    However, the content of this document itself may not be modified in any way, including by removing the copyright notice or references to Ecma International, except as required to translate it into languages other than English or into a different format.

    The official version of an Ecma International document is the English language version on the Ecma International website. In the event of discrepancies between a translated version and the official version, the official version shall govern.

    The limited permissions granted above are perpetual and will not be revoked by Ecma International or its successors or assigns.

    This document and the information contained herein is provided on an "AS IS" basis and ECMA INTERNATIONAL DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY OWNERSHIP RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE."

    Software License

    All Software contained in this document ("Software)" is protected by copyright and is being made available under the "BSD

    License", included below. This Software may be subject to third party rights (rights from parties other than Ecma

    International), including patent rights, and no licenses under such third party rights are granted under this license even if

    the third party concerned is a member of Ecma International. SEE THE ECMA CODE OF CONDUCT IN PATENT

    MATTERS AVAILABLE AT http://www.ecma-international.org/memento/codeofconduct.htm FOR INFORMATION

    REGARDING THE LICENSING OF PATENT CLAIMS THAT ARE REQUIRED TO IMPLEMENT ECMA INTERNATIONAL

    STANDARDS*.

    Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following

    conditions are met:

    1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

    2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following

    disclaimer in the documentation and/or other materials provided with the distribution.

    3. Neither the name of the authors nor Ecma International may be used to endorse or promote products derived from this

    software without specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY THE ECMA INTERNATIONAL "AS IS" AND ANY EXPRESS OR IMPLIED

    WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND

    FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ECMA INTERNATIONAL BE

    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES

    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,

    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,

    WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN

    ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

    Moved (insertion) [1]

  • ii © Ecma International 2015

  • © Ecma International 2015 iii

    Contents Page

    1 Scope ............................................................................................................................................................. 1

    2 Conformance ................................................................................................................................................ 1

    3 Normative references ................................................................................................................................. 1

    4 Overview ....................................................................................................................................................... 1 4.1 Web Scripting ............................................................................................................................................... 2 4.2 ECMAScript Overview ................................................................................................................................ 2

    Objects .......................................................................................................................................................... 3 4.2.1 The Strict Variant of ECMAScript ............................................................................................................. 4 4.2.2

    4.3 Terms and definitions ................................................................................................................................. 5 4.4 Organization of This Specification ........................................................................................................... 8

    5 Notational Conventions.............................................................................................................................. 8 5.1 Syntactic and Lexical Grammars.............................................................................................................. 8

    Context-Free Grammars ............................................................................................................................. 8 5.1.1 The Lexical and RegExp Grammars......................................................................................................... 9 5.1.2 The Numeric String Grammar ................................................................................................................... 9 5.1.3 The Syntactic Grammar.............................................................................................................................. 9 5.1.4 Grammar Notation ..................................................................................................................................... 10 5.1.5

    5.2 Algorithm Conventions ............................................................................................................................ 14 5.3 Static Semantic Rules............................................................................................................................... 16

    6 ECMAScript Data Types and Values ...................................................................................................... 16 6.1 ECMAScript Language Types ................................................................................................................. 16

    The Undefined Type .................................................................................................................................. 17 6.1.1 The Null Type ............................................................................................................................................. 17 6.1.2 The Boolean Type ..................................................................................................................................... 17 6.1.3 The String Type ......................................................................................................................................... 17 6.1.4 The Symbol Type ....................................................................................................................................... 17 6.1.5 The Number Type ...................................................................................................................................... 19 6.1.6 The Object Type ......................................................................................................................................... 20 6.1.7

    6.2 ECMAScript Specification Types............................................................................................................ 29 The List and Record Specification Type ............................................................................................... 29 6.2.1 The Completion Record Specification Type ......................................................................................... 30 6.2.2 The Reference Specification Type ......................................................................................................... 31 6.2.3 The Property Descriptor Specification Type ........................................................................................ 33 6.2.4 The Lexical Environment and Environment Record Specification Types....................................... 35 6.2.5 Data Blocks ................................................................................................................................................ 35 6.2.6

    7 Abstract Operations .................................................................................................................................. 36 7.1 Type Conversion ....................................................................................................................................... 36

    ToPrimitive ( input [, PreferredType] ) ................................................................................................... 36 7.1.1 ToBoolean ( argument )............................................................................................................................ 37 7.1.2 ToNumber ( argument ) ............................................................................................................................ 38 7.1.3 ToInteger ( argument ) .............................................................................................................................. 40 7.1.4 ToInt32 ( argument ) .................................................................................................................................. 40 7.1.5 ToUint32 ( argument ) ............................................................................................................................... 41 7.1.6 ToInt16 ( argument ) .................................................................................................................................. 41 7.1.7 ToUint16 ( argument ) ............................................................................................................................... 41 7.1.8 ToInt8 ( argument ) .................................................................................................................................... 41 7.1.9

    ToUint8 ( argument ) ................................................................................................................................. 42 7.1.10 ToUint8Clamp ( argument ) ..................................................................................................................... 42 7.1.11 ToString ( argument )................................................................................................................................ 42 7.1.12

  • iv © Ecma International 2015

    ToObject ( argument )............................................................................................................................... 44 7.1.13 ToPropertyKey ( argument ) .................................................................................................................... 44 7.1.14 ToLength ( argument ) .............................................................................................................................. 44 7.1.15 CanonicalNumericIndexString ( argument ) ......................................................................................... 45 7.1.16

    7.2 Testing and Comparison Operations .................................................................................................... 45 RequireObjectCoercible ( argument ) .................................................................................................... 45 7.2.1 IsArray ( argument ) .................................................................................................................................. 45 7.2.2 IsCallable ( argument ) ............................................................................................................................. 45 7.2.3 IsConstructor ( argument ) ...................................................................................................................... 46 7.2.4 IsExtensible (O) ......................................................................................................................................... 46 7.2.5 IsInteger ( argument ) ............................................................................................................................... 46 7.2.6 IsPropertyKey ( argument ) ..................................................................................................................... 46 7.2.7 IsRegExp ( argument ) .............................................................................................................................. 46 7.2.8 SameValue(x, y) ......................................................................................................................................... 46 7.2.9

    SameValueZero(x, y) ................................................................................................................................. 47 7.2.10 Abstract Relational Comparison ............................................................................................................ 47 7.2.11 Abstract Equality Comparison ................................................................................................................ 48 7.2.12 Strict Equality Comparison .................................................................................................................. 49 7.2.13

    7.3 Operations on Objects ............................................................................................................................. 49 Get (O, P) .................................................................................................................................................... 49 7.3.1 GetV (V, P) .................................................................................................................................................. 49 7.3.2 Set (O, P, V, Throw) ................................................................................................................................... 49 7.3.3 CreateDataProperty (O, P, V)................................................................................................................... 50 7.3.4 CreateMethodProperty (O, P, V) ............................................................................................................. 50 7.3.5 CreateDataPropertyOrThrow (O, P, V) ................................................................................................... 50 7.3.6 DefinePropertyOrThrow (O, P, desc) ..................................................................................................... 51 7.3.7 DeletePropertyOrThrow (O, P) ................................................................................................................ 51 7.3.8 GetMethod (O, P) ....................................................................................................................................... 51 7.3.9

    HasProperty (O, P) .................................................................................................................................... 51 7.3.10 HasOwnProperty (O, P) ............................................................................................................................ 51 7.3.11 Call(F, V, [argumentsList]) ....................................................................................................................... 52 7.3.12 Construct (F, [argumentsList], [newTarget]) ........................................................................................ 52 7.3.13 SetIntegrityLevel (O, level) ...................................................................................................................... 52 7.3.14 TestIntegrityLevel (O, level) .................................................................................................................... 53 7.3.15 CreateArrayFromList (elements) ............................................................................................................ 53 7.3.16 CreateListFromArrayLike (obj [, elementTypes] ) ............................................................................... 53 7.3.17 Invoke(O,P, [argumentsList]) .................................................................................................................. 54 7.3.18 OrdinaryHasInstance (C, O) .................................................................................................................... 54 7.3.19 SpeciesConstructor ( O, defaultConstructor ) ..................................................................................... 54 7.3.20 EnumerableOwnNames (O) ..................................................................................................................... 54 7.3.21 GetFunctionRealm ( obj ) ......................................................................................................................... 55 7.3.22

    7.4 Operations on Iterator Objects ............................................................................................................... 55 GetIterator ( obj, method ) ....................................................................................................................... 55 7.4.1 IteratorNext ( iterator, value ) .................................................................................................................. 55 7.4.2 IteratorComplete ( iterResult ) ................................................................................................................ 56 7.4.3 IteratorValue ( iterResult ) ........................................................................................................................ 56 7.4.4 IteratorStep ( iterator ) .............................................................................................................................. 56 7.4.5 IteratorClose( iterator, completion )....................................................................................................... 56 7.4.6 CreateIterResultObject ( value, done ) .................................................................................................. 56 7.4.7 CreateListIterator ( list ) ........................................................................................................................... 56 7.4.8

    8 Executable Code and Execution Contexts ........................................................................................... 57 8.1 Lexical Environments ............................................................................................................................... 57

    Environment Records............................................................................................................................... 58 8.1.1 Lexical Environment Operations ............................................................................................................ 72 8.1.2

    8.2 Code Realms .............................................................................................................................................. 74 CreateRealm ( ) .......................................................................................................................................... 74 8.2.1 CreateIntrinsics ( realmRec )................................................................................................................... 74 8.2.2 SetRealmGlobalObject ( realmRec, globalObj ) ................................................................................... 75 8.2.3 SetDefaultGlobalBindings ( realmRec ) ................................................................................................ 75 8.2.4

  • © Ecma International 2015 v

    8.3 Execution Contexts ................................................................................................................................... 75 ResolveBinding ( name, [env] ) ............................................................................................................... 77 8.3.1 GetThisEnvironment ( ) ............................................................................................................................ 77 8.3.2 ResolveThisBinding ( ) ............................................................................................................................. 77 8.3.3 GetNewTarget ( ) ........................................................................................................................................ 77 8.3.4 GetGlobalObject ( ).................................................................................................................................... 77 8.3.5

    8.4 Jobs and Job Queues ............................................................................................................................... 78 EnqueueJob (queueName, job, arguments) ......................................................................................... 79 8.4.1 NextJob result ............................................................................................................................................ 79 8.4.2

    8.5 ECMAScript Initialization() ....................................................................................................................... 79 InitializeHostDefinedRealm ( realm ) ...................................................................................................... 80 8.5.1

    9 Ordinary and Exotic Objects Behaviours ............................................................................................. 80 9.1 Ordinary Object Internal Methods and Internal Slots ......................................................................... 80

    [[GetPrototypeOf]] ( ) ................................................................................................................................ 80 9.1.1 [[SetPrototypeOf]] (V) ............................................................................................................................... 80 9.1.2 [[IsExtensible]] ( ) ...................................................................................................................................... 81 9.1.3 [[PreventExtensions]] ( ) .......................................................................................................................... 81 9.1.4 [[GetOwnProperty]] (P) ............................................................................................................................. 81 9.1.5 [[DefineOwnProperty]] (P, Desc) ............................................................................................................ 81 9.1.6 [[HasProperty]](P) ..................................................................................................................................... 83 9.1.7 [[Get]] (P, Receiver) ................................................................................................................................... 83 9.1.8 [[Set]] ( P, V, Receiver) ............................................................................................................................. 83 9.1.9

    [[Delete]] (P)................................................................................................................................................ 84 9.1.10 [[Enumerate]] () .......................................................................................................................................... 84 9.1.11 [[OwnPropertyKeys]] ( )............................................................................................................................ 85 9.1.12 ObjectCreate(proto, internalSlotsList) .............................................................................................. 85 9.1.13 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto, internalSlotsList ) ........ 85 9.1.14 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) ............................................. 86 9.1.15

    9.2 ECMAScript Function Objects ................................................................................................................ 86 [[Call]] ( thisArgument, argumentsList) ................................................................................................. 87 9.2.1 [[Construct]] ( argumentsList, newTarget) ........................................................................................... 88 9.2.2 FunctionAllocate (functionPrototype, strict [,functionKind] ) ........................................................... 89 9.2.3 FunctionInitialize (F, kind, ParameterList, Body, Scope) ................................................................... 89 9.2.4 FunctionCreate (kind, ParameterList, Body, Scope, Strict, prototype) ........................................... 90 9.2.5 GeneratorFunctionCreate (kind, ParameterList, Body, Scope, Strict) ............................................. 90 9.2.6 AddRestrictedFunctionProperties ( F, realm ) ..................................................................................... 90 9.2.7 MakeConstructor (F, writablePrototype, prototype) ........................................................................... 90 9.2.8 MakeClassConstructor ( F) ...................................................................................................................... 91 9.2.9

    MakeMethod ( F, homeObject) ................................................................................................................ 91 9.2.10 SetFunctionName (F, name, prefix) ........................................................................................................ 91 9.2.11 FunctionDeclarationInstantiation(func, argumentsList) .................................................................... 91 9.2.12

    9.3 Built-in Function Objects ......................................................................................................................... 94 [[Call]] ( thisArgument, argumentsList) ................................................................................................. 95 9.3.1 [[Construct]] (argumentsList, newTarget) ............................................................................................ 95 9.3.2 CreateBuiltinFunction(realm, steps, prototype, internalSlotsList)................................................... 95 9.3.3

    9.4 Built-in Exotic Object Internal Methods and Slots .............................................................................. 95 Bound Function Exotic Objects .............................................................................................................. 96 9.4.1 Array Exotic Objects ................................................................................................................................. 97 9.4.2 String Exotic Objects ................................................................................................................................ 99 9.4.3 Arguments Exotic Objects ..................................................................................................................... 101 9.4.4 Integer Indexed Exotic Objects ............................................................................................................. 105 9.4.5 Module Namespace Exotic Objects ..................................................................................................... 108 9.4.6

    9.5 Proxy Object Internal Methods and Internal Slots............................................................................. 110 [[GetPrototypeOf]] ( ) .............................................................................................................................. 111 9.5.1 [[SetPrototypeOf]] (V) ............................................................................................................................. 112 9.5.2 [[IsExtensible]] ( ) .................................................................................................................................... 112 9.5.3 [[PreventExtensions]] ( ) ........................................................................................................................ 113 9.5.4 [[GetOwnProperty]] (P) ........................................................................................................................... 113 9.5.5 [[DefineOwnProperty]] (P, Desc) .......................................................................................................... 114 9.5.6

  • vi © Ecma International 2015

    [[HasProperty]] (P) .................................................................................................................................. 114 9.5.7 [[Get]] (P, Receiver)................................................................................................................................. 115 9.5.8 [[Set]] ( P, V, Receiver) ........................................................................................................................... 116 9.5.9

    [[Delete]] (P) ............................................................................................................................................. 116 9.5.10 [[Enumerate]] () ........................................................................................................................................ 117 9.5.11 [[OwnPropertyKeys]] ( ) ......................................................................................................................... 117 9.5.12 [[Call]] (thisArgument, argumentsList)................................................................................................ 118 9.5.13 [[Construct]] ( argumentsList, newTarget) ......................................................................................... 118 9.5.14 ProxyCreate(target, handler) ................................................................................................................. 118 9.5.15

    10 ECMAScript Language: Source Code ................................................................................................. 119 10.1 Source Text .............................................................................................................................................. 119

    Static Semantics: UTF16Encoding ( cp ) ........................................................................................... 119 10.1.1 Static Semantics: UTF16Decode( lead, trail ) ..................................................................................... 120 10.1.2

    10.2 Types of Source Code ............................................................................................................................ 120 Strict Mode Code ..................................................................................................................................... 120 10.2.1 Non-ECMAScript Functions .................................................................................................................. 121 10.2.2

    11 ECMAScript Language: Lexical Grammar .......................................................................................... 121 11.1 Unicode Format-Control Characters.................................................................................................... 122 11.2 White Space ............................................................................................................................................. 122 11.3 Line Terminators ..................................................................................................................................... 123 11.4 Comments ................................................................................................................................................ 124 11.5 Tokens ....................................................................................................................................................... 125 11.6 Names and Keywords............................................................................................................................. 125

    Identifier Names ...................................................................................................................................... 126 11.6.1 Reserved Words ...................................................................................................................................... 126 11.6.2

    11.7 Punctuators .............................................................................................................................................. 127 11.8 Literals ...................................................................................................................................................... 128

    Null Literals .............................................................................................................................................. 128 11.8.1 Boolean Literals ...................................................................................................................................... 128 11.8.2 Numeric Literals ...................................................................................................................................... 128 11.8.3 String Literals .......................................................................................................................................... 131 11.8.4 Regular Expression Literals .................................................................................................................. 133 11.8.5 Template Literal Lexical Components ................................................................................................. 135 11.8.6

    11.9 Automatic Semicolon Insertion ............................................................................................................ 137 Rules of Automatic Semicolon Insertion ............................................................................................ 137 11.9.1 Examples of Automatic Semicolon Insertion ..................................................................................... 138 11.9.2

    12 ECMAScript Language: Expressions .................................................................................................. 140 12.1 Identifiers .................................................................................................................................................. 140

    Static Semantics: Early Errors............................................................................................................. 140 12.1.1 Static Semantics: BoundNames ........................................................................................................... 140 12.1.2 Static Semantics: IsValidSimpleAssignmentTarget ........................................................................ 141 12.1.3 Static Semantics: StringValue ............................................................................................................... 141 12.1.4 Runtime Semantics: BindingInitialization .......................................................................................... 141 12.1.5 Runtime Semantics: Evaluation .......................................................................................................... 142 12.1.6

    12.2 Primary Expression ................................................................................................................................ 142 Semantics ................................................................................................................................................. 142 12.2.1 The this Keyword .................................................................................................................................. 144 12.2.2 Identifier Reference................................................................................................................................. 144 12.2.3 Literals ...................................................................................................................................................... 144 12.2.4 Array Initializer......................................................................................................................................... 145 12.2.5 Object Initializer ....................................................................................................................................... 147 12.2.6 Function Defining Expressions ............................................................................................................ 151 12.2.7 Regular Expression Literals .................................................................................................................. 151 12.2.8 Template Literals ..................................................................................................................................... 151 12.2.9

    The Grouping Operator .......................................................................................................................... 155 12.2.1012.3 Left-Hand-Side Expressions ................................................................................................................. 156

    Static Semantics ...................................................................................................................................... 157 12.3.1 Property Accessors ................................................................................................................................ 159 12.3.2

  • © Ecma International 2015 vii

    The new Operator .................................................................................................................................... 160 12.3.3 Function Calls .......................................................................................................................................... 160 12.3.4 The super Keyword ................................................................................................................................ 162 12.3.5 Argument Lists ........................................................................................................................................ 163 12.3.6 Tagged Templates ................................................................................................................................... 164 12.3.7 Meta Properties ........................................................................................................................................ 164 12.3.8

    12.4 Postfix Expressions ................................................................................................................................ 164 Static Semantics: Early Errors ............................................................................................................. 164 12.4.1 Static Semantics: IsFunctionDefinition .............................................................................................. 164 12.4.2 Static Semantics: IsValidSimpleAssignmentTarget......................................................................... 164 12.4.3 Postfix Increment Operator ................................................................................................................... 165 12.4.4 Postfix Decrement Operator .................................................................................................................. 165 12.4.5

    12.5 Unary Operators ...................................................................................................................................... 165 Static Semantics: Early Errors ............................................................................................................. 165 12.5.1 Static Semantics: IsFunctionDefinition .............................................................................................. 166 12.5.2 Static Semantics: IsValidSimpleAssignmentTarget......................................................................... 166 12.5.3 The delete Operator .............................................................................................................................. 166 12.5.4 The void Operator .................................................................................................................................. 167 12.5.5 The typeof Operator .............................................................................................................................. 167 12.5.6 Prefix Increment Operator ..................................................................................................................... 168 12.5.7 Prefix Decrement Operator .................................................................................................................... 168 12.5.8 Unary + Operator ..................................................................................................................................... 168 12.5.9

    Unary - Operator ..................................................................................................................................... 169 12.5.10 Bitwise NOT Operator ( ~ ) ..................................................................................................................... 169 12.5.11 Logical NOT Operator ( ! ) ..................................................................................................................... 169 12.5.12

    12.6 Multiplicative Operators ......................................................................................................................... 169 Static Semantics: IsFunctionDefinition .............................................................................................. 169 12.6.1 Static Semantics: IsValidSimpleAssignmentTarget......................................................................... 170 12.6.2 Runtime Semantics: Evaluation .......................................................................................................... 170 12.6.3

    12.7 Additive Operators .................................................................................................................................. 172 Static Semantics: IsFunctionDefinition .............................................................................................. 172 12.7.1 Static Semantics: IsValidSimpleAssignmentTarget......................................................................... 172 12.7.2 The Addition operator ( + )..................................................................................................................... 172 12.7.3 The Subtraction Operator ( - ) .............................................................................................................. 173 12.7.4 Applying the Additive Operators to Numbers .................................................................................... 173 12.7.5

    12.8 Bitwise Shift Operators .......................................................................................................................... 174 Static Semantics: IsFunctionDefinition .............................................................................................. 174 12.8.1 Static Semantics: IsValidSimpleAssignmentTarget......................................................................... 174 12.8.2 The Left Shift Operator ( > ) ................................................................................................ 174 12.8.4 The Unsigned Right Shift Operator ( >>> ) ......................................................................................... 175 12.8.5

    12.9 Relational Operators ............................................................................................................................... 175 Static Semantics: IsFunctionDefinition .............................................................................................. 176 12.9.1 Static Semantics: IsValidSimpleAssignmentTarget......................................................................... 176 12.9.2 Runtime Semantics: Evaluation .......................................................................................................... 176 12.9.3 Runtime Semantics: InstanceofOperator(O, C) ................................................................................. 177 12.9.4

    12.10 Equality Operators .................................................................................................................................. 177 Static Semantics: IsFunctionDefinition .............................................................................................. 178 12.10.1 Static Semantics: IsValidSimpleAssignmentTarget......................................................................... 178 12.10.2 Runtime Semantics: Evaluation .......................................................................................................... 178 12.10.3

    12.11 Binary Bitwise Operators ....................................................................................................................... 179 Static Semantics: IsFunctionDefinition .............................................................................................. 179 12.11.1 Static Semantics: IsValidSimpleAssignmentTarget......................................................................... 180 12.11.2 Runtime Semantics: Evaluation .......................................................................................................... 180 12.11.3

    12.12 Binary Logical Operators ....................................................................................................................... 180 Static Semantics: IsFunctionDefinition .............................................................................................. 180 12.12.1 Static Semantics: IsValidSimpleAssignmentTarget......................................................................... 181 12.12.2 Runtime Semantics: Evaluation .......................................................................................................... 181 12.12.3

  • viii © Ecma International 2015

    12.13 Conditional Operator ( ? : ) .............................................................................................................. 181 Static Semantics: IsFunctionDefinition .............................................................................................. 181 12.13.1 Static Semantics: IsValidSimpleAssignmentTarget ........................................................................ 181 12.13.2 Runtime Semantics: Evaluation .......................................................................................................... 182 12.13.3

    12.14 Assignment Operators ........................................................................................................................... 182 Static Semantics: Early Errors............................................................................................................. 182 12.14.1 Static Semantics: IsFunctionDefinition .............................................................................................. 182 12.14.2 Static Semantics: IsValidSimpleAssignmentTarget ........................................................................ 182 12.14.3 Runtime Semantics: Evaluation .......................................................................................................... 183 12.14.4 Destructuring Assignment .................................................................................................................... 183 12.14.5

    12.15 Comma Operator ( , ) .......................................................................................................................... 189 Static Semantics: IsFunctionDefinition .............................................................................................. 189 12.15.1 Static Semantics: IsValidSimpleAssignmentTarget ........................................................................ 189 12.15.2 Runtime Semantics: Evaluation .......................................................................................................... 189 12.15.3

    13 ECMAScript Language: Statements and Declarations ..................................................................... 189 13.1 Statement Semantics .............................................................................................................................. 190

    Static Semantics: ContainsDuplicateLabels ...................................................................................... 190 13.1.1 Static Semantics: ContainsUndefinedBreakTarget .......................................................................... 190 13.1.2 Static Semantics: ContainsUndefinedContinueTarget..................................................................... 190 13.1.3 Static Semantics: DeclarationPart ...................................................................................................... 191 13.1.4 Static Semantics: VarDeclaredNames ................................................................................................ 191 13.1.5 Static Semantics: VarScopedDeclarations ........................................................................................ 191 13.1.6 Runtime Semantics: LabelledEvaluation .......................................................................................... 192 13.1.7 Runtime Semantics: Evaluation .......................................................................................................... 192 13.1.8

    13.2 Block .......................................................................................................................................................... 192 Static Semantics: Early Errors............................................................................................................. 193 13.2.1 Static Semantics: ContainsDuplicateLabels ...................................................................................... 193 13.2.2 Static Semantics: ContainsUndefinedBreakTarget .......................................................................... 193 13.2.3 Static Semantics: ContainsUndefinedContinueTarget..................................................................... 193 13.2.4 Static Semantics: LexicallyDeclaredNames ...................................................................................... 194 13.2.5 Static Semantics: LexicallyScopedDeclarations .............................................................................. 194 13.2.6 Static Semantics: TopLevelLexicallyDeclaredNames ..................................................................... 194 13.2.7 Static Semantics: TopLevelLexicallyScopedDeclarations ............................................................. 195 13.2.8 Static Semantics: TopLevelVarDeclaredNames ............................................................................... 195 13.2.9

    Static Semantics: TopLevelVarScopedDeclarations ....................................................................... 196 13.2.10 Static Semantics: VarDeclaredNames ................................................................................................ 196 13.2.11 Static Semantics: VarScopedDeclarations ........................................................................................ 196 13.2.12 Runtime Semantics: Evaluation .......................................................................................................... 197 13.2.13 Runtime Semantics: BlockDeclarationInstantiation( code, env ) ................................................... 197 13.2.14

    13.3 Declarations and the Variable Statement............................................................................................ 198 Let and Const Declarations ................................................................................................................... 198 13.3.1 Variable Statement .................................................................................................................................. 200 13.3.2 Destructuring Binding Patterns ............................................................................................................ 201 13.3.3

    13.4 Empty Statement ..................................................................................................................................... 208 Runtime Semantics: Evaluation .......................................................................................................... 208 13.4.1

    13.5 Expression Statement ............................................................................................................................ 209 Runtime Semantics: Evaluation .......................................................................................................... 209 13.5.1

    13.6 The if Statement .................................................................................................................................... 209 Static Semantics: Early Errors............................................................................................................. 209 13.6.1 Static Semantics: ContainsDuplicateLabels ...................................................................................... 209 13.6.2 Static Semantics: ContainsUndefinedBreakTarget .......................................................................... 209 13.6.3 Static Semantics: ContainsUndefinedContinueTarget..................................................................... 210 13.6.4 Static Semantics: VarDeclaredNames ................................................................................................ 210 13.6.5 Static Semantics: VarScopedDeclarations ........................................................................................ 210 13.6.6 Runtime Semantics: Evaluation ......................................................................................................... 211 13.6.7

    13.7 Iteration Statements................................................................................................................................ 211 Semantics ................................................................................................................................................. 211 13.7.1 The do-while Statement ........................................................................................................................ 212 13.7.2

  • © Ecma International 2015 ix

    The while Statement.............................................................................................................................. 213 13.7.3 The for Statement .................................................................................................................................. 214 13.7.4 The for-in and for-of Statements ..................................................................................................... 217 13.7.5

    13.8 The continue Statement ....................................................................................................................... 223 Static Semantics: Early Errors ............................................................................................................. 223 13.8.1 Static Semantics: ContainsUndefinedContinueTarget ..................................................................... 223 13.8.2 Runtime Semantics: Evaluation .......................................................................................................... 223 13.8.3

    13.9 The break Statement.............................................................................................................................. 224 Static Semantics: Early Errors ............................................................................................................. 224 13.9.1 Static Semantics: ContainsUndefinedBreakTarget ........................................................................... 224 13.9.2 Runtime Semantics: Evaluation .......................................................................................................... 224 13.9.3

    13.10 The return Statement ........................................................................................................................... 224 Runtime Semantics: Evaluation .......................................................................................................... 224 13.10.1

    13.11 The with Statement ................................................................................................................................ 225 Static Semantics: Early Errors ............................................................................................................. 225 13.11.1 Static Semantics: ContainsDuplicateLabels ...................................................................................... 225 13.11.2 Static Semantics: ContainsUndefinedBreakTarget ........................................................................... 225 13.11.3 Static Semantics: ContainsUndefinedContinueTarget ..................................................................... 225 13.11.4 Static Semantics: VarDeclaredNames ................................................................................................ 225 13.11.5 Static Semantics: VarScopedDeclarations ........................................................................................ 226 13.11.6 Runtime Semantics: Evaluation .......................................................................................................... 226 13.11.7

    13.12 The switch Statement ........................................................................................................................... 226 Static Semantics: Early Errors ............................................................................................................. 226 13.12.1 Static Semantics: ContainsDuplicateLabels ...................................................................................... 227 13.12.2 Static Semantics: ContainsUndefinedBreakTarget ........................................................................... 227 13.12.3 Static Semantics: ContainsUndefinedContinueTarget ..................................................................... 228 13.12.4 Static Semantics: LexicallyDeclaredNames ...................................................................................... 229 13.12.5 Static Semantics: LexicallyScopedDeclarations .............................................................................. 229 13.12.6 Static Semantics: VarDeclaredNames ................................................................................................ 230 13.12.7 Static Semantics: VarScopedDeclarations ........................................................................................ 230 13.12.8 Runtime Semantics: CaseBlockEvaluation ....................................................................................... 231 13.12.9

    Runtime Semantics: CaseSelectorEvaluation .......................................................................... 232 13.12.10 Runtime Semantics: Evaluation .................................................................................................. 232 13.12.11

    13.13 Labelled Statements ............................................................................................................................... 233 Static Semantics: Early Errors ............................................................................................................. 233 13.13.1 Static Semantics: ContainsDuplicateLabels ...................................................................................... 233 13.13.2 Static Semantics: ContainsUndefinedBreakTarget ........................................................................... 233 13.13.3 Static Semantics: ContainsUndefinedContinueTarget ..................................................................... 234 13.13.4 Static Semantics: IsLabelledFunction ( stmt ) .................................................................................. 234 13.13.5 Static Semantics: LexicallyDeclaredNames ...................................................................................... 234 13.13.6 Static Semantics: LexicallyScopedDeclarations .............................................................................. 234 13.13.7 Static Semantics: TopLevelLexicallyDeclaredNames ..................................................................... 235 13.13.8 Static Semantics: TopLevelLexicallyScopedDeclarations ............................................................. 235 13.13.9

    Static Semantics: TopLevelVarDeclaredNames ....................................................................... 235 13.13.10 Static Semantics: TopLevelVarScopedDeclarations ............................................................... 235 13.13.11 Static Semantics: VarDeclaredNames ........................................................................................ 236 13.13.12 Static Semantics: VarScopedDeclarations ................................................................................ 236 13.13.13 Runtime Semantics: LabelledEvaluation .................................................................................. 236 13.13.14 Runtime Semantics: Evaluation ................................................................................................... 236 13.13.15

    13.14 The throw Statement.............................................................................................................................. 237 Runtime Semantics: Evaluation .......................................................................................................... 237 13.14.1

    13.15 The try Statement .................................................................................................................................. 237 Static Semantics: Early Errors ............................................................................................................. 237 13.15.1 Static Semantics: ContainsDuplicateLabels ...................................................................................... 237 13.15.2 Static Semantics: ContainsUndefinedBreakTarget ........................................................................... 238 13.15.3 Static Semantics: ContainsUndefinedContinueTarget ..................................................................... 238 13.15.4 Static Semantics: VarDeclaredNames ................................................................................................ 239 13.15.5 Static Semantics: VarScopedDeclarations ........................................................................................ 239 13.15.6 Runtime Semantics: CatchClauseEvaluation..................................................................................... 240 13.15.7

  • x © Ecma International 2015

    Runtime Semantics: Evaluation .......................................................................................................... 240 13.15.813.16 The debugger statement ....................................................................................................................... 241

    Runtime Semantics: Evaluation .......................................................................................................... 241 13.16.1

    14 ECMAScript Language: Functions and Classes................................................................................ 241 14.1 Function Definitions ............................................................................................................................... 241

    Directive Prologues and the Use Strict Directive .............................................................................. 242 14.1.1 Static Semantics: Early Errors............................................................................................................. 242 14.1.2 Static Semantics: BoundNames .......................................................................................................... 243 14.1.3 Static Semantics: Contains .................................................................................................................. 243 14.1.4 Static Semantics: ContainsExpression .............................................................................................. 244 14.1.5 Static Semantics: ExpectedArgumentCount..................................................................................... 244 14.1.6 Static Semantics: HasInitializer ........................................................................................................... 244 14.1.7 Static Semantics: HasName ................................................................................................................. 245 14.1.8 Static Semantics: IsAnonymousFunctionDefinition ( production ) .............................................. 245 14.1.9

    Static Semantics: IsConstantDeclaration .......................................................................................... 245 14.1.10 Static Semantics: IsFunctionDefinition .............................................................................................. 245 14.1.11 Static Semantics: IsSimpleParameterList ......................................................................................... 245 14.1.12 Static Semantics: LexicallyDeclaredNames ...................................................................................... 246 14.1.13 Static Semantics: LexicallyScopedDeclarations .............................................................................. 246 14.1.14 Static Semantics: VarDeclaredNames ................................................................................................ 246 14.1.15 Static Semantics: VarScopedDeclarations ........................................................................................ 246 14.1.16 Runtime Semantics: EvaluateBody ..................................................................................................... 247 14.1.17 Runtime Semantics: IteratorBindingInitialization ........................................................................... 247 14.1.18 Runtime Semantics: InstantiateFunctionObject ................................................................................ 248 14.1.19 Runtime Semantics: Evaluation .......................................................................................................... 248 14.1.20

    14.2 Arrow Function Definitions ................................................................................................................... 249 Static Semantics: Early Errors............................................................................................................. 249 14.2.1 Static Semantics: BoundNames .......................................................................................................... 250 14.2.2 Static Semantics: Contains .................................................................................................................. 250 14.2.3 Static Semantics: ContainsExpression .............................................................................................. 250 14.2.4 Static Semantics: ExpectedArgumentCount..................................................................................... 250 14.2.5 Static Semantics: HasInitializer ........................................................................................................... 250 14.2.6 Static Semantics: HasName ................................................................................................................. 251 14.2.7 Static Semantics: IsSimpleParameterList ......................................................................................... 251 14.2.8 Static Semantics: CoveredFormalsList .............................................................................................. 251 14.2.9

    Static Semantics: LexicallyDeclaredNames ...................................................................................... 251 14.2.10 Static Semantics: LexicallyScopedDeclarations .............................................................................. 251 14.2.11 Static Semantics: VarDeclaredNames ................................................................................................ 252 14.2.12 Static Semantics: VarScopedDeclarations ........................................................................................ 252 14.2.13 Runtime Semantics: IteratorBindingInitialization ........................................................................... 252 14.2.14 Runtime Semantics: EvaluateBody ..................................................................................................... 252 14.2.15 Runtime Semantics: Evaluation .......................................................................................................... 253 14.2.16

    14.3 Method Definitions .................................................................................................................................. 253 Static Semantics: Early Errors............................................................................................................. 253 14.3.1 Static Semantics: ComputedPropertyContains ................................................................................ 253 14.3.2 Static Semantics: ExpectedArgumentCount..................................................................................... 253 14.3.3 Static Semantics: HasComputedPropertyKey .................................................................................. 254 14.3.4 Static Semantics: HasDirectSuper ...................................................................................................... 254 14.3.5 Static Semantics: PropName ............................................................................................................... 254 14.3.6 Static Semantics: SpecialMethod........................................................................................................ 254 14.3.7 Runtime Semantics: DefineMethod ..................................................................................................... 254 14.3.8 Runtime Semantics: PropertyDefinitionEvaluation ......................................................................... 255 14.3.9

    14.4 Generator Function Definitions ............................................................................................................ 256 Static Semantics: Early Errors............................................................................................................. 256 14.4.1 Static Semantics: BoundNames .......................................................................................................... 256 14.4.2 Static Semantics: ComputedPropertyContains ................................................................................ 257 14.4.3 Static Semantics: Contains .................................................................................................................. 257 14.4.4 Static Semantics: HasComputedPropertyKey .................................................................................. 257 14.4.5 Static Semantics: HasDirectSuper ...................................................................................................... 257 14.4.6

  • © Ecma International 2015 xi

    Static Semantics: HasName ................................................................................................................. 258 14.4.7 Static Semantics: IsConstantDeclaration .......................................................................................... 258 14.4.8 Static Semantics: IsFunctionDefinition .............................................................................................. 258 14.4.9

    Static Semantics: PropName ............................................................................................................... 258 14.4.10 Runtime Semantics: EvaluateBody ..................................................................................................... 258 14.4.11 Runtime Semantics: InstantiateFunctionObject ................................................................................ 259 14.4.12 Runtime Semantics: PropertyDefinitionEvaluation ......................................................................... 259 14.4.13 Runtime Semantics: Evaluation .......................................................................................................... 259 14.4.14

    14.5 Class Definitions ..................................................................................................................................... 261 Static Semantics: Early Errors ............................................................................................................. 262 14.5.1 Static Semantics: BoundNames .......................................................................................................... 262 14.5.2 Static Semantics: ConstructorMethod ............................................................................................... 262 14.5.3 Static Semantics: Contains .................................................................................................................. 263 14.5.4 Static Semantics: ComputedPropertyContains ................................................................................ 263 14.5.5 Static Semantics: HasName ................................................................................................................. 263 14.5.6 Static Semantics: IsConstantDeclaration .......................................................................................... 263 14.5.7 Static Semantics: IsFunctionDefinition .............................................................................................. 264 14.5.8 Static Semantics: IsStatic ..................................................................................................................... 264 14.5.9

    Static Semantics: NonConstructorMethodDefinitions .................................................................... 264 14.5.10 Static Semantics: PrototypePropertyNameList ................................................................................ 264 14.5.11 Static Semantics: PropName ............................................................................................................... 264 14.5.12 Static Semantics: StaticPropertyNameList ....................................................................................... 265 14.5.13 Runtime Semantics: ClassDefinitionEvaluation ................................................................................ 265 14.5.14 Runtime Semantics: BindingClassDeclarationEvaluation ............................................................... 266 14.5.15 Runtime Semantics: Evaluation .......................................................................................................... 266 14.5.16

    14.6 Tail Position Calls ................................................................................................................................... 267 Static Semantics: IsInTailPosition(nonterminal) ............................................................................... 267 14.6.1 Static Semantics: HasProductionInTailPosition ................................................................................ 267 14.6.2 Runtime Semantics: PrepareForTailCall ( ) ...................................................................................... 271 14.6.3

    15 ECMAScript Language: Scripts and Modules .................................................................................... 271 15.1 Scripts ....................................................................................................................................................... 271

    Static Semantics: Early Errors ............................................................................................................. 271 15.1.1 Static Semantics: IsStrict...................................................................................................................... 272 15.1.2 Static Semantics: LexicallyDeclaredNames ...................................................................................... 272 15.1.3 Static Semantics: LexicallyScopedDeclarations .............................................................................. 272 15.1.4 Static Semantics: VarDeclaredNames ................................................................................................ 272 15.1.5 Static Semantics: VarScopedDeclarations ........................................................................................ 272 15.1.6 Runtime Semantics: ScriptEvaluation ............................................................................................... 272 15.1.7 Runtime Semantics: GlobalDeclarationInstantiation (script, env) ................................................. 273 15.1.8 Runtime Semantics: ScriptEvaluationJob ( sourceText ) ................................................................ 274 15.1.9

    15.2 Modules ..................................................................................................................................................... 275 Module Semantics ................................................................................................................................... 275 15.2.1 Imports ...................................................................................................................................................... 287 15.2.2 Exports ...................................................................................................................................................... 290 15.2.3

    16 Error Handling and Language Extensions .......................................................................................... 296 16.1 Forbidden Extensions ............................................................................................................................ 297

    17 ECMAScript Standard Built-in Objects ................................................................................................ 298

    18 The Global Object .................................................................................................................................... 299 18.1 Value Properties of the Global Object ................................................................................................. 299

    Infinity ........................................................................................................................................................ 299 18.1.1 NaN............................................................................................................................................................. 299 18.1.2 undefined .................................................................................................................................................. 299 18.1.3

    18.2 Function Properties of the Global Object ........................................................................................... 300 eval (x) ....................................................................................................................................................... 300 18.2.1 isFinite (number) ..................................................................................................................................... 302 18.2.2 isNaN (number) ........................................................................................................................................ 302 18.2.3 parseFloat (string) ................................................................................................................................... 302 18.2.4

  • xii © Ecma International 2015

    parseInt (string , radix) ........................................................................................................................... 303 18.2.5 URI Handling Functions ......................................................................................................................... 304 18.2.6

    18.3 Constructor Properties of the Global Object ..................................................................................... 308 Array ( . . . ) ............................................................................................................................................... 308 18.3.1 ArrayBuffer ( . . . ) .................................................................................................................................... 308 18.3.2 Boolean ( . . . ) .......................................................................................................................................... 308 18.3.3 DataView ( . . . ) ........................................................................................................................................ 308 18.3.4 Date ( . . . ) ................................................................................................................................................. 308 18.3.5 Error ( . . . ) ................................................................................................................................................ 309 18.3.6 EvalError ( . . . ) ........................................................................................................................................ 309 18.3.7 Float32Array ( . . . ) .................................................................................................................................. 309 18.3.8 Float64Array ( . . . ) .................................................................................................................................. 309 18.3.9

    Function ( . . . ) ......................................................................................................................................... 309 18.3.10 Int8Array ( . . . ) ........................................................................................................................................ 309 18.3.11 Int16Array ( . . . ) ...................................................................................................................................... 309 18.3.12 Int32Array ( . . . ) ...................................................................................................................................... 309 18.3.13 Map ( . . . ) ................................................................................................................................................. 309 18.3.14 Number ( . . . ) ........................................................................................................................................... 309 18.3.15 Object ( . . . ) ............................................................................................................................................. 309 18.3.16 Proxy ( . . . ) .............................................................................................................................................. 309 18.3.17 Promise ( . . . ) .......................................................................................................................................... 309 18.3.18 RangeError ( . . . ) .................................................................................................................................... 309 18.3.19 ReferenceError ( . . . ) ............................................................................................................................. 309 18.3.20 RegExp ( . . . ) ........................................................................................................................................... 310 18.3.21 Set ( . . . ) ................................................................................................................................................... 310 18.3.22 String ( . . . ) .............................................................................................................................................. 310 18.3.23 Symbol ( . . . ) ........................................................................................................................................... 310 18.3.24 SyntaxError ( . . . ) ................................................................................................................................... 310 18.3.25 TypeError ( . . . ) ....................................................................................................................................... 310 18.3.26 Uint8Array ( . . . ) ...................................................................................................................................... 310 18.3.27 Uint8ClampedArray ( . . . ) ...................................................................................................................... 310 18.3.28 Uint16Array ( . . . ) ................................................................................................................................... 310 18.3.29 Uint32Array ( . . . ) ................................................................................................................................... 310 18.3.30 URIError ( . . . ) ......................................................................................................................................... 310 18.3.31 WeakMap ( . . . )........................................................................................................................................ 310 18.3.32 WeakSet ( . . . ) ......................................................................................................................................... 310 18.3.33

    18.4 Other Properties of the Global Object ................................................................................................. 310 JSON .......................................................................................................................................................... 310 18.4.1 Math ........................................................................................................................................................... 311 18.4.2 Reflect ....................................................................................................................................................... 311 18.4.3

    19 Fundamental Objects ..............