€¦ · © ecma international 2015 i contents page introduction

613
Reference number ECMA-123:2009 © Ecma International 2009 ECMA-262 6 th Edition / Draft April 3, 2015 ECMAScript 2015 Language Specification Draft Ecma/TC39/2015/0XX Report Errors and Issues at: https://bugs.ecmascript.org Product: Draft for 6th Edition Component: choose an appropriate one Version: Rev 37, April 3, 2015 Draft Draft Release Candidate #4

Upload: others

Post on 25-Jun-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

  • Reference number ECMA-123:2009

    © Ecma International 2009

    ECMA-262 6th Edition / Draft April 3, 2015

    ECMAScript 2015

    Language Specification

    Draft

    Ecma/TC39/2015/0XX

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

    Product: Draft for 6th Edition Component: choose an appropriate one Version: Rev 37, April 3, 2015 Draft

    Draft Release Candidate #4

    https://bugs.ecmascript.org/

  • COPYRIGHT PROTECTED DOCUMENT

    © Ecma International 2015

  • © Ecma International 2015 i

    Contents Page

    Introduction .............................................................................................................................................................. vii

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

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

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

    4 Overview ....................................................................................................................................................... 2 4.1 Web Scripting ............................................................................................................................................... 3 4.2 ECMAScript Overview ................................................................................................................................ 3 4.2.1 Objects .......................................................................................................................................................... 4 4.2.2 The Strict Variant of ECMAScript ............................................................................................................. 5 4.3 Terms and definitions ................................................................................................................................. 5 4.4 Organization of This Specification ........................................................................................................... 9

    5 Notational Conventions .............................................................................................................................. 9 5.1 Syntactic and Lexical Grammars .............................................................................................................. 9 5.1.1 Context-Free Grammars ............................................................................................................................. 9 5.1.2 The Lexical and RegExp Grammars ....................................................................................................... 10 5.1.3 The Numeric String Grammar ................................................................................................................. 10 5.1.4 The Syntactic Grammar ............................................................................................................................ 10 5.1.5 Grammar Notation ..................................................................................................................................... 11 5.2 Algorithm Conventions ............................................................................................................................ 16 5.3 Static Semantic Rules ............................................................................................................................... 17

    6 ECMAScript Data Types and Values ...................................................................................................... 18 6.1 ECMAScript Language Types ................................................................................................................. 18 6.1.1 The Undefined Type .................................................................................................................................. 18 6.1.2 The Null Type ............................................................................................................................................. 18 6.1.3 The Boolean Type...................................................................................................................................... 18 6.1.4 The String Type.......................................................................................................................................... 19 6.1.5 The Symbol Type ....................................................................................................................................... 19 6.1.6 The Number Type ...................................................................................................................................... 20 6.1.7 The Object Type ......................................................................................................................................... 22 6.2 ECMAScript Specification Types ............................................................................................................ 32 6.2.1 The List and Record Specification Type ............................................................................................... 32 6.2.2 The Completion Record Specification Type ......................................................................................... 33 6.2.3 The Reference Specification Type.......................................................................................................... 34 6.2.4 The Property Descriptor Specification Type ........................................................................................ 36 6.2.5 The Lexical Environment and Environment Record Specification Types ....................................... 38 6.2.6 Data Blocks................................................................................................................................................. 38

    7 Abstract Operations .................................................................................................................................. 39 7.1 Type Conversion ....................................................................................................................................... 39 7.1.1 ToPrimitive ( input [, PreferredType] ) ................................................................................................... 39 7.1.2 ToBoolean ( argument ) ............................................................................................................................ 40 7.1.3 ToNumber ( argument ) ............................................................................................................................ 41 7.1.4 ToInteger ( argument ) .............................................................................................................................. 44 7.1.5 ToInt32 ( argument ) .................................................................................................................................. 44 7.1.6 ToUint32 ( argument ) ............................................................................................................................... 44 7.1.7 ToInt16 ( argument ) .................................................................................................................................. 44 7.1.8 ToUint16 ( argument ) ............................................................................................................................... 45

  • ii © Ecma International 2015

    7.1.9 ToInt8 ( argument ).................................................................................................................................... 45 7.1.10 ToUint8 ( argument ) ................................................................................................................................. 45 7.1.11 ToUint8Clamp ( argument ) ..................................................................................................................... 45 7.1.12 ToString ( argument ) ............................................................................................................................... 46 7.1.13 ToObject ( argument ) .............................................................................................................................. 47 7.1.14 ToPropertyKey ( argument ) .................................................................................................................... 48 7.1.15 ToLength ( argument ) .............................................................................................................................. 48 7.1.16 CanonicalNumericIndexString ( argument ) ......................................................................................... 48 7.2 Testing and Comparison Operations .................................................................................................... 49 7.2.1 RequireObjectCoercible ( argument ) .................................................................................................... 49 7.2.2 IsArray ( argument ) .................................................................................................................................. 49 7.2.3 IsCallable ( argument ) ............................................................................................................................. 49 7.2.4 IsConstructor ( argument ) ...................................................................................................................... 49 7.2.5 IsExtensible (O) ......................................................................................................................................... 50 7.2.6 IsInteger ( argument ) ............................................................................................................................... 50 7.2.7 IsPropertyKey ( argument ) ..................................................................................................................... 50 7.2.8 IsRegExp ( argument ) .............................................................................................................................. 50 7.2.9 SameValue(x, y) ......................................................................................................................................... 50 7.2.10 SameValueZero(x, y)................................................................................................................................. 51 7.2.11 Abstract Relational Comparison ............................................................................................................ 51 7.2.12 Abstract Equality Comparison................................................................................................................ 52 7.2.13 Strict Equality Comparison .................................................................................................................. 53 7.3 Operations on Objects ............................................................................................................................. 53 7.3.1 Get (O, P) .................................................................................................................................................... 53 7.3.2 GetV (V, P) .................................................................................................................................................. 53 7.3.3 Set (O, P, V, Throw) ................................................................................................................................... 54 7.3.4 CreateDataProperty (O, P, V) .................................................................................................................. 54 7.3.5 CreateMethodProperty (O, P, V) ............................................................................................................. 54 7.3.6 CreateDataPropertyOrThrow (O, P, V) ................................................................................................... 54 7.3.7 DefinePropertyOrThrow (O, P, desc) ..................................................................................................... 55 7.3.8 DeletePropertyOrThrow (O, P) ................................................................................................................ 55 7.3.9 GetMethod (O, P) ....................................................................................................................................... 55 7.3.10 HasProperty (O, P) .................................................................................................................................... 55 7.3.11 HasOwnProperty (O, P) ............................................................................................................................ 56 7.3.12 Call(F, V, [argumentsList]) ....................................................................................................................... 56 7.3.13 Construct (F, [argumentsList], [newTarget]) ........................................................................................ 56 7.3.14 SetIntegrityLevel (O, level) ...................................................................................................................... 56 7.3.15 TestIntegrityLevel (O, level) .................................................................................................................... 57 7.3.16 CreateArrayFromList (elements) ............................................................................................................ 57 7.3.17 CreateListFromArrayLike (obj [, elementTypes] ) ............................................................................... 57 7.3.18 Invoke(O,P, [argumentsList]) .................................................................................................................. 58 7.3.19 OrdinaryHasInstance (C, O) .................................................................................................................... 58 7.3.20 SpeciesConstructor ( O, defaultConstructor ) ..................................................................................... 58 7.3.21 EnumerableOwnNames (O) ..................................................................................................................... 59 7.3.22 GetFunctionRealm ( obj ) ......................................................................................................................... 59 7.4 Operations on Iterator Objects ............................................................................................................... 60 7.4.1 GetIterator ( obj, method ) ....................................................................................................................... 60 7.4.2 IteratorNext ( iterator, value ) .................................................................................................................. 60 7.4.3 IteratorComplete ( iterResult ) ................................................................................................................ 60 7.4.4 IteratorValue ( iterResult )........................................................................................................................ 60 7.4.5 IteratorStep ( iterator ) .............................................................................................................................. 60 7.4.6 IteratorClose( iterator, completion ) ...................................................................................................... 61 7.4.7 CreateIterResultObject ( value, done ) .................................................................................................. 61 7.4.8 CreateListIterator ( list ) ........................................................................................................................... 61

    8 Executable Code and Execution Contexts ........................................................................................... 62

  • © Ecma International 2015 iii

    8.1 Lexical Environments ............................................................................................................................... 62 8.1.1 Environment Records ............................................................................................................................... 62 8.1.2 Lexical Environment Operations ............................................................................................................ 77 8.2 Code Realms .............................................................................................................................................. 79 8.2.1 CreateRealm ( ) .......................................................................................................................................... 79 8.2.2 CreateIntrinsics ( realmRec ) ................................................................................................................... 80 8.2.3 SetRealmGlobalObject ( realmRec, globalObj ) ................................................................................... 80 8.2.4 SetDefaultGlobalBindings ( realmRec ) ................................................................................................. 80 8.3 Execution Contexts ................................................................................................................................... 81 8.3.1 ResolveBinding ( name, [env] ) ............................................................................................................... 82 8.3.2 GetThisEnvironment ( ) ............................................................................................................................ 82 8.3.3 ResolveThisBinding ( ) ............................................................................................................................. 82 8.3.4 GetNewTarget ( ) ........................................................................................................................................ 83 8.3.5 GetGlobalObject ( ) .................................................................................................................................... 83 8.4 Jobs and Job Queues ............................................................................................................................... 83 8.4.1 EnqueueJob ( queueName, job, arguments) ........................................................................................ 84 8.4.2 NextJob result ........................................................................................................................................... 84 8.5 ECMAScript Initialization() ....................................................................................................................... 85 8.5.1 InitializeHostDefinedRealm ( realm ) ...................................................................................................... 85

    9 Ordinary and Exotic Objects Behaviours.............................................................................................. 86 9.1 Ordinary Object Internal Methods and Internal Slots ......................................................................... 86 9.1.1 [[GetPrototypeOf]] ( ) ................................................................................................................................ 86 9.1.2 [[SetPrototypeOf]] (V) ............................................................................................................................... 86 9.1.3 [[IsExtensible]] ( ) ...................................................................................................................................... 86 9.1.4 [[PreventExtensions]] ( ) .......................................................................................................................... 87 9.1.5 [[GetOwnProperty]] (P) ............................................................................................................................. 87 9.1.6 [[DefineOwnProperty]] (P, Desc)............................................................................................................. 87 9.1.7 [[HasProperty]](P)...................................................................................................................................... 89 9.1.8 [[Get]] (P, Receiver) ................................................................................................................................... 89 9.1.9 [[Set]] ( P, V, Receiver).............................................................................................................................. 90 9.1.10 [[Delete]] (P) ................................................................................................................................................ 90 9.1.11 [[Enumerate]] () .......................................................................................................................................... 90 9.1.12 [[OwnPropertyKeys]] ( ) ............................................................................................................................ 91 9.1.13 ObjectCreate(proto, internalSlotsList) .............................................................................................. 91 9.1.14 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto, internalSlotsList ) ........ 92 9.1.15 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) ............................................. 92 9.2 ECMAScript Function Objects ................................................................................................................ 92 9.2.1 [[Call]] ( thisArgument, argumentsList) ................................................................................................. 93 9.2.2 [[Construct]] ( argumentsList, newTarget) ........................................................................................... 94 9.2.3 FunctionAllocate (functionPrototype, strict [,functionKind] ) ........................................................... 95 9.2.4 FunctionInitialize (F, kind, ParameterList, Body, Scope) ................................................................... 96 9.2.5 FunctionCreate (kind, ParameterList, Body, Scope, Strict, prototype) ........................................... 96 9.2.6 GeneratorFunctionCreate (kind, ParameterList, Body, Scope, Strict) ............................................. 96 9.2.7 AddRestrictedFunctionProperties ( F, realm ) ..................................................................................... 96 9.2.8 MakeConstructor (F, writablePrototype, prototype) ........................................................................... 97 9.2.9 MakeClassConstructor ( F) ...................................................................................................................... 97 9.2.10 MakeMethod ( F, homeObject) ................................................................................................................ 97 9.2.11 SetFunctionName (F, name, prefix) ........................................................................................................ 98 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) .................................................................... 98 9.3 Built-in Function Objects ....................................................................................................................... 100 9.3.1 [[Call]] ( thisArgument, argumentsList) ............................................................................................... 101 9.3.2 [[Construct]] (argumentsList, newTarget)........................................................................................... 102 9.3.3 CreateBuiltinFunction(realm, steps, prototype, internalSlotsList) ................................................. 102 9.4 Built-in Exotic Object Internal Methods and Slots ............................................................................ 102 9.4.1 Bound Function Exotic Objects ............................................................................................................ 102

  • iv © Ecma International 2015

    9.4.2 Array Exotic Objects............................................................................................................................... 104 9.4.3 String Exotic Objects.............................................................................................................................. 106 9.4.4 Arguments Exotic Objects .................................................................................................................... 108 9.4.5 Integer Indexed Exotic Objects ............................................................................................................ 112 9.4.6 Module Namespace Exotic Objects ..................................................................................................... 115 9.5 Proxy Object Internal Methods and Internal Slots ............................................................................ 118 9.5.1 [[GetPrototypeOf]] ( ) .............................................................................................................................. 119 9.5.2 [[SetPrototypeOf]] (V) ............................................................................................................................. 120 9.5.3 [[IsExtensible]] ( ) .................................................................................................................................... 120 9.5.4 [[PreventExtensions]] ( ) ........................................................................................................................ 121 9.5.5 [[GetOwnProperty]] (P)........................................................................................................................... 121 9.5.6 [[DefineOwnProperty]] (P, Desc) .......................................................................................................... 122 9.5.7 [[HasProperty]] (P) .................................................................................................................................. 123 9.5.8 [[Get]] (P, Receiver) ................................................................................................................................ 123 9.5.9 [[Set]] ( P, V, Receiver) ........................................................................................................................... 124 9.5.10 [[Delete]] (P) ............................................................................................................................................. 125 9.5.11 [[Enumerate]] () ........................................................................................................................................ 125 9.5.12 [[OwnPropertyKeys]] ( ) ......................................................................................................................... 125 9.5.13 [[Call]] (thisArgument, argumentsList) ............................................................................................... 126 9.5.14 [[Construct]] ( argumentsList, newTarget) ......................................................................................... 127 9.5.15 ProxyCreate(target, handler) ................................................................................................................. 127

    10 ECMAScript Language: Source Code ................................................................................................. 128 10.1 Source Text .............................................................................................................................................. 128 10.1.1 Static Semantics: UTF16Encoding ( cp ) ........................................................................................... 128 10.1.2 Static Semantics: UTF16Decode( lead, trail ) ..................................................................................... 128 10.2 Types of Source Code ............................................................................................................................ 129 10.2.1 Strict Mode Code ..................................................................................................................................... 129 10.2.2 Non-ECMAScript Functions .................................................................................................................. 130

    11 ECMAScript Language: Lexical Grammar .......................................................................................... 130 11.1 Unicode Format-Control Characters ................................................................................................... 131 11.2 White Space ............................................................................................................................................. 131 11.3 Line Terminators ..................................................................................................................................... 132 11.4 Comments ................................................................................................................................................ 133 11.5 Tokens....................................................................................................................................................... 134 11.6 Names and Keywords ............................................................................................................................ 134 11.6.1 Identifier Names ...................................................................................................................................... 135 11.6.2 Reserved Words ...................................................................................................................................... 136 11.7 Punctuators .............................................................................................................................................. 137 11.8 Literals ...................................................................................................................................................... 137 11.8.1 Null Literals .............................................................................................................................................. 137 11.8.2 Boolean Literals ...................................................................................................................................... 137 11.8.3 Numeric Literals ...................................................................................................................................... 137 11.8.4 String Literals .......................................................................................................................................... 140 11.8.5 Regular Expression Literals .................................................................................................................. 143 11.8.6 Template Literal Lexical Components ................................................................................................. 145 11.9 Automatic Semicolon Insertion ............................................................................................................ 147 11.9.1 Rules of Automatic Semicolon Insertion ............................................................................................ 147 11.9.2 Examples of Automatic Semicolon Insertion ..................................................................................... 149

    12 ECMAScript Language: Expressions .................................................................................................. 150 12.1 Identifiers .................................................................................................................................................. 150 12.1.1 Static Semantics: Early Errors ............................................................................................................ 150 12.1.2 Static Semantics: BoundNames ........................................................................................................... 151 12.1.3 Static Semantics: IsValidSimpleAssignmentTarget ........................................................................ 151 12.1.4 Static Semantics: StringValue ............................................................................................................. 151

  • © Ecma International 2015 v

    12.1.5 Runtime Semantics: BindingInitialization ........................................................................................... 151 12.1.6 Runtime Semantics: Evaluation .......................................................................................................... 152 12.2 Primary Expression ................................................................................................................................. 152 12.2.0 Semantics ................................................................................................................................................. 153 12.2.1 The this Keyword .................................................................................................................................. 154 12.2.2 Identifier Reference ................................................................................................................................. 155 12.2.3 Literals ....................................................................................................................................................... 155 12.2.4 Array Initializer ......................................................................................................................................... 155 12.2.5 Object Initializer ....................................................................................................................................... 157 12.2.6 Function Defining Expressions ............................................................................................................ 162 12.2.7 Regular Expression Literals .................................................................................................................. 162 12.2.8 Template Literals ..................................................................................................................................... 162 12.2.9 The Grouping Operator .......................................................................................................................... 166 12.3 Left-Hand-Side Expressions .................................................................................................................. 167 12.3.1 Static Semantics ...................................................................................................................................... 168 12.3.2 Property Accessors ................................................................................................................................ 170 12.3.3 The new Operator..................................................................................................................................... 171 12.3.4 Function Calls .......................................................................................................................................... 172 12.3.5 The super Keyword ................................................................................................................................ 173 12.3.6 Argument Lists ........................................................................................................................................ 174 12.3.7 Tagged Templates ................................................................................................................................... 175 12.3.8 Meta Properties ........................................................................................................................................ 176 12.4 Postfix Expressions ................................................................................................................................ 176 12.4.1 Static Semantics: Early Errors ............................................................................................................. 176 12.4.2 Static Semantics: IsFunctionDefinition .............................................................................................. 176 12.4.3 Static Semantics: IsValidSimpleAssignmentTarget ......................................................................... 176 12.4.4 Postfix Increment Operator ................................................................................................................... 176 12.4.5 Postfix Decrement Operator .................................................................................................................. 177 12.5 Unary Operators ...................................................................................................................................... 177 12.5.1 Static Semantics: Early Errors ............................................................................................................. 177 12.5.2 Static Semantics: IsFunctionDefinition .............................................................................................. 177 12.5.3 Static Semantics: IsValidSimpleAssignmentTarget ......................................................................... 178 12.5.4 The delete Operator .............................................................................................................................. 178 12.5.5 The void Operator .................................................................................................................................. 179 12.5.6 The typeof Operator .............................................................................................................................. 179 12.5.7 Prefix Increment Operator ..................................................................................................................... 180 12.5.8 Prefix Decrement Operator .................................................................................................................... 180 12.5.9 Unary + Operator ..................................................................................................................................... 181 12.5.10 Unary - Operator ..................................................................................................................................... 181 12.5.11 Bitwise NOT Operator ( ~ ) ..................................................................................................................... 181 12.5.12 Logical NOT Operator ( ! ) ..................................................................................................................... 181 12.6 Multiplicative Operators ......................................................................................................................... 181 12.6.1 Static Semantics: IsFunctionDefinition .............................................................................................. 182 12.6.2 Static Semantics: IsValidSimpleAssignmentTarget ......................................................................... 182 12.6.3 Runtime Semantics: Evaluation .......................................................................................................... 182 12.7 Additive Operators .................................................................................................................................. 184 12.7.1 Static Semantics: IsFunctionDefinition .............................................................................................. 184 12.7.2 Static Semantics: IsValidSimpleAssignmentTarget ......................................................................... 184 12.7.3 The Addition operator ( + ) ..................................................................................................................... 184 12.7.4 The Subtraction Operator ( - ) .............................................................................................................. 185 12.7.5 Applying the Additive Operators to Numbers .................................................................................... 185 12.8 Bitwise Shift Operators .......................................................................................................................... 186 12.8.1 Static Semantics: IsFunctionDefinition .............................................................................................. 186 12.8.2 Static Semantics: IsValidSimpleAssignmentTarget ......................................................................... 186

  • vi © Ecma International 2015

    12.8.3 The Left Shift Operator ( > ) ................................................................................................ 187 12.8.5 The Unsigned Right Shift Operator ( >>> ) ......................................................................................... 187 12.9 Relational Operators............................................................................................................................... 188 12.9.1 Static Semantics: IsFunctionDefinition.............................................................................................. 188 12.9.2 Static Semantics: IsValidSimpleAssignmentTarget ........................................................................ 188 12.9.3 Runtime Semantics: Evaluation .......................................................................................................... 189 12.9.4 Runtime Semantics: InstanceofOperator(O, C) ................................................................................. 190 12.10 Equality Operators .................................................................................................................................. 190 12.10.1 Static Semantics: IsFunctionDefinition.............................................................................................. 190 12.10.2 Static Semantics: IsValidSimpleAssignmentTarget ........................................................................ 191 12.10.3 Runtime Semantics: Evaluation .......................................................................................................... 191 12.11 Binary Bitwise Operators....................................................................................................................... 192 12.11.1 Static Semantics: IsFunctionDefinition.............................................................................................. 192 12.11.2 Static Semantics: IsValidSimpleAssignmentTarget ........................................................................ 192 12.11.3 Runtime Semantics: Evaluation .......................................................................................................... 193 12.12 Binary Logical Operators....................................................................................................................... 193 12.12.1 Static Semantics: IsFunctionDefinition.............................................................................................. 193 12.12.2 Static Semantics: IsValidSimpleAssignmentTarget ........................................................................ 193 12.12.3 Runtime Semantics: Evaluation .......................................................................................................... 193 12.13 Conditional Operator ( ? : ) .............................................................................................................. 194 12.13.1 Static Semantics: IsFunctionDefinition.............................................................................................. 194 12.13.2 Static Semantics: IsValidSimpleAssignmentTarget ........................................................................ 194 12.13.3 Runtime Semantics: Evaluation .......................................................................................................... 194 12.14 Assignment Operators ........................................................................................................................... 195 12.14.1 Static Semantics: Early Errors ............................................................................................................ 195 12.14.2 Static Semantics: IsFunctionDefinition.............................................................................................. 195 12.14.3 Static Semantics: IsValidSimpleAssignmentTarget ........................................................................ 195 12.14.4 Runtime Semantics: Evaluation .......................................................................................................... 196 12.14.5 Destructuring Assignment .................................................................................................................... 196 12.15 Comma Operator ( , ) .......................................................................................................................... 202 12.15.1 Static Semantics: IsFunctionDefinition.............................................................................................. 202 12.15.2 Static Semantics: IsValidSimpleAssignmentTarget ........................................................................ 202 12.15.3 Runtime Semantics: Evaluation .......................................................................................................... 202

    13 ECMAScript Language: Statements and Declarations ..................................................................... 203 13.0 Statement Semantics.............................................................................................................................. 203 13.0.1 Static Semantics: ContainsDuplicateLabels ...................................................................................... 203 13.0.2 Static Semantics: ContainsUndefinedBreakTarget .......................................................................... 203 13.0.3 Static Semantics: ContainsUndefinedContinueTarget .................................................................... 204 13.0.4 Static Semantics: DeclarationPart ...................................................................................................... 204 13.0.5 Static Semantics: VarDeclaredNames ................................................................................................ 204 13.0.6 Static Semantics: VarScopedDeclarations ........................................................................................ 205 13.0.7 Runtime Semantics: LabelledEvaluation .......................................................................................... 205 13.0.8 Runtime Semantics: Evaluation .......................................................................................................... 205 13.1 Block.......................................................................................................................................................... 206 13.1.1 Static Semantics: Early Errors ............................................................................................................ 206 13.1.2 Static Semantics: ContainsDuplicateLabels ...................................................................................... 206 13.1.3 Static Semantics: ContainsUndefinedBreakTarget .......................................................................... 207 13.1.4 Static Semantics: ContainsUndefinedContinueTarget .................................................................... 207 13.1.5 Static Semantics: LexicallyDeclaredNames ...................................................................................... 207 13.1.6 Static Semantics: LexicallyScopedDeclarations .............................................................................. 208 13.1.7 Static Semantics: TopLevelLexicallyDeclaredNames ..................................................................... 208 13.1.8 Static Semantics: TopLevelLexicallyScopedDeclarations ............................................................. 208 13.1.9 Static Semantics: TopLevelVarDeclaredNames ............................................................................... 209

  • © Ecma International 2015 vii

    13.1.10 Static Semantics: TopLevelVarScopedDeclarations ....................................................................... 209 13.1.11 Static Semantics: VarDeclaredNames ................................................................................................ 210 13.1.12 Static Semantics: VarScopedDeclarations ........................................................................................ 210 13.1.13 Runtime Semantics: Evaluation .......................................................................................................... 210 13.1.14 Runtime Semantics: BlockDeclarationInstantiation( code, env ) ................................................... 211 13.2 Declarations and the Variable Statement ............................................................................................ 211 13.2.1 Let and Const Declarations ................................................................................................................... 211 13.2.2 Variable Statement .................................................................................................................................. 213 13.2.3 Destructuring Binding Patterns ............................................................................................................ 215 13.3 Empty Statement ..................................................................................................................................... 223 13.3.1 Runtime Semantics: Evaluation .......................................................................................................... 223 13.4 Expression Statement ............................................................................................................................ 223 13.4.1 Runtime Semantics: Evaluation .......................................................................................................... 223 13.5 The if Statement .................................................................................................................................... 223 13.5.1 Static Semantics: Early Errors ............................................................................................................. 224 13.5.2 Static Semantics: ContainsDuplicateLabels ...................................................................................... 224 13.5.3 Static Semantics: ContainsUndefinedBreakTarget ........................................................................... 224 13.5.4 Static Semantics: ContainsUndefinedContinueTarget ..................................................................... 224 13.5.5 Static Semantics: VarDeclaredNames ................................................................................................ 225 13.5.6 Static Semantics: VarScopedDeclarations ........................................................................................ 225 13.5.7 Runtime Semantics: Evaluation ......................................................................................................... 225 13.6 Iteration Statements ................................................................................................................................ 226 13.6.0 Semantics ................................................................................................................................................. 226 13.6.1 The do-while Statement ........................................................................................................................ 227 13.6.2 The while Statement .............................................................................................................................. 228 13.6.3 The for Statement .................................................................................................................................. 229 13.6.4 The for-in and for-of Statements ..................................................................................................... 232 13.7 The continue Statement ....................................................................................................................... 239 13.7.1 Static Semantics: Early Errors ............................................................................................................. 239 13.7.2 Static Semantics: ContainsUndefinedContinueTarget ..................................................................... 239 13.7.3 Runtime Semantics: Evaluation .......................................................................................................... 239 13.8 The break Statement .............................................................................................................................. 239 13.8.1 Static Semantics: Early Errors ............................................................................................................. 239 13.8.2 Static Semantics: ContainsUndefinedBreakTarget ........................................................................... 240 13.8.3 Runtime Semantics: Evaluation .......................................................................................................... 240 13.9 The return Statement ........................................................................................................................... 240 13.9.1 Runtime Semantics: Evaluation .......................................................................................................... 240 13.10 The with Statement ................................................................................................................................ 240 13.10.1 Static Semantics: Early Errors ............................................................................................................. 241 13.10.2 Static Semantics: ContainsDuplicateLabels ...................................................................................... 241 13.10.3 Static Semantics: ContainsUndefinedBreakTarget ........................................................................... 241 13.10.4 Static Semantics: ContainsUndefinedContinueTarget ..................................................................... 241 13.10.5 Static Semantics: VarDeclaredNames ................................................................................................ 241 13.10.6 Static Semantics: VarScopedDeclarations ........................................................................................ 242 13.10.7 Runtime Semantics: Evaluation .......................................................................................................... 242 13.11 The switch Statement ........................................................................................................................... 242 13.11.1 Static Semantics: Early Errors ............................................................................................................. 242 13.11.2 Static Semantics: ContainsDuplicateLabels ...................................................................................... 243 13.11.3 Static Semantics: ContainsUndefinedBreakTarget ........................................................................... 243 13.11.4 Static Semantics: ContainsUndefinedContinueTarget ..................................................................... 244 13.11.5 Static Semantics: LexicallyDeclaredNames ...................................................................................... 245 13.11.6 Static Semantics: LexicallyScopedDeclarations .............................................................................. 245 13.11.7 Static Semantics: VarDeclaredNames ................................................................................................ 246 13.11.8 Static Semantics: VarScopedDeclarations ........................................................................................ 247

  • viii © Ecma International 2015

    13.11.9 Runtime Semantics: CaseBlockEvaluation ....................................................................................... 247 13.11.10 Runtime Semantics: CaseSelectorEvaluation .......................................................................... 249 13.11.11 Runtime Semantics: Evaluation .................................................................................................. 249 13.12 Labelled Statements ............................................................................................................................... 249 13.12.1 Static Semantics: Early Errors ............................................................................................................ 250 13.12.2 Static Semantics: ContainsDuplicateLabels ...................................................................................... 250 13.12.3 Static Semantics: ContainsUndefinedBreakTarget .......................................................................... 250 13.12.4 Static Semantics: ContainsUndefinedContinueTarget .................................................................... 250 13.12.5 Static Semantics: IsLabelledFunction ( stmt ) .................................................................................. 251 13.12.6 Static Semantics: LexicallyDeclaredNames ...................................................................................... 251 13.12.7 Static Semantics: LexicallyScopedDeclarations .............................................................................. 251 13.12.8 Static Semantics: TopLevelLexicallyDeclaredNames ..................................................................... 251 13.12.9 Static Semantics: TopLevelLexicallyScopedDeclarations ............................................................. 252 13.12.10 Static Semantics: TopLevelVarDeclaredNames ....................................................................... 252 13.12.11 Static Semantics: TopLevelVarScopedDeclarations ............................................................... 252 13.12.12 Static Semantics: VarDeclaredNames ........................................................................................ 252 13.12.13 Static Semantics: VarScopedDeclarations ................................................................................ 252 13.12.14 Runtime Semantics: LabelledEvaluation .................................................................................. 253 13.12.15 Runtime Semantics: Evaluation ................................................................................................... 253 13.13 The throw Statement ............................................................................................................................. 253 13.13.1 Runtime Semantics: Evaluation .......................................................................................................... 253 13.14 The try Statement .................................................................................................................................. 254 13.14.1 Static Semantics: Early Errors ............................................................................................................ 254 13.14.2 Static Semantics: ContainsDuplicateLabels ...................................................................................... 254 13.14.3 Static Semantics: ContainsUndefinedBreakTarget .......................................................................... 255 13.14.4 Static Semantics: ContainsUndefinedContinueTarget .................................................................... 255 13.14.5 Static Semantics: VarDeclaredNames ................................................................................................ 256 13.14.6 Static Semantics: VarScopedDeclarations ........................................................................................ 256 13.14.7 Runtime Semantics: CatchClauseEvaluation .................................................................................... 257 13.14.8 Runtime Semantics: Evaluation .......................................................................................................... 257 13.15 The debugger statement ....................................................................................................................... 258 13.15.1 Runtime Semantics: Evaluation .......................................................................................................... 258

    14 ECMAScript Language: Functions and Classes ............................................................................... 258 14.1 Function Definitions ............................................................................................................................... 258 14.1.1 Directive Prologues and the Use Strict Directive .............................................................................. 259 14.1.2 Static Semantics: Early Errors ............................................................................................................ 259 14.1.3 Static Semantics: BoundNames .......................................................................................................... 260 14.1.4 Static Semantics: Contains .................................................................................................................. 260 14.1.5 Static Semantics: ContainsExpression.............................................................................................. 261 14.1.6 Static Semantics: ExpectedArgumentCount .................................................................................... 261 14.1.7 Static Semantics: HasInitializer ........................................................................................................... 262 14.1.8 Static Semantics: HasName ................................................................................................................. 262 14.1.9 Static Semantics: IsAnonymousFunctionDefinition ( production ) .............................................. 262 14.1.10 Static Semantics: IsConstantDeclaration .......................................................................................... 262 14.1.11 Static Semantics: IsFunctionDefinition.............................................................................................. 262 14.1.12 Static Semantics: IsSimpleParameterList ......................................................................................... 263 14.1.13 Static Semantics: LexicallyDeclaredNames ...................................................................................... 263 14.1.14 Static Semantics: LexicallyScopedDeclarations .............................................................................. 263 14.1.15 Static Semantics: VarDeclaredNames ................................................................................................ 263 14.1.16 Static Semantics: VarScopedDeclarations ........................................................................................ 264 14.1.17 Runtime Semantics: EvaluateBody ..................................................................................................... 264 14.1.18 Runtime Semantics: IteratorBindingInitialization ........................................................................... 264 14.1.19 Runtime Semantics: InstantiateFunctionObject ................................................................................ 265 14.1.20 Runtime Semantics: Evaluation .......................................................................................................... 265

  • © Ecma International 2015 ix

    14.2 Arrow Function Definitions.................................................................................................................... 266 14.2.1 Static Semantics: Early Errors ............................................................................................................. 267 14.2.2 Static Semantics: BoundNames .......................................................................................................... 267 14.2.3 Static Semantics: Contains .................................................................................................................. 267 14.2.4 Static Semantics: ContainsExpression .............................................................................................. 267 14.2.5 Static Semantics: ExpectedArgumentCount ..................................................................................... 268 14.2.6 Static Semantics: HasInitializer ........................................................................................................... 268 14.2.7 Static Semantics: HasName ................................................................................................................. 268 14.2.8 Static Semantics: IsSimpleParameterList .......................................................................................... 268 14.2.9 Static Semantics: CoveredFormalsList .............................................................................................. 268 14.2.10 Static Semantics: LexicallyDeclaredNames ...................................................................................... 269 14.2.11 Static Semantics: LexicallyScopedDeclarations .............................................................................. 269 14.2.12 Static Semantics: VarDeclaredNames ................................................................................................ 269 14.2.13 Static Semantics: VarScopedDeclarations ........................................................................................ 269 14.2.14 Runtime Semantics: IteratorBindingInitialization ........................................................................... 269 14.2.15 Runtime Semantics: EvaluateBody ..................................................................................................... 270 14.2.16 Runtime Semantics: Evaluation .......................................................................................................... 270 14.3 Method Definitions .................................................................................................................................. 271 14.3.1 Static Semantics: Early Errors ............................................................................................................. 271 14.3.2 Static Semantics: ComputedPropertyContains ................................................................................ 271 14.3.3 Static Semantics: ExpectedArgumentCount ..................................................................................... 271 14.3.4 Static Semantics: HasComputedPropertyKey .................................................................................. 271 14.3.5 Static Semantics: HasDirectSuper ...................................................................................................... 272 14.3.6 Static Semantics: PropName................................................................................................................ 272 14.3.7 Static Semantics: SpecialMethod ........................................................................................................ 272 14.3.8 Runtime Semantics: DefineMethod ...................................................................................................... 272 14.3.9 Runtime Semantics: PropertyDefinitionEvaluation ......................................................................... 273 14.4 Generator Function Definitions ............................................................................................................ 273 14.4.1 Static Semantics: Early Errors ............................................................................................................. 274 14.4.2 Static Semantics: BoundNames .......................................................................................................... 274 14.4.3 Static Semantics: ComputedPropertyContains ................................................................................ 275 14.4.4 Static Semantics: Contains .................................................................................................................. 275 14.4.5 Static Semantics: HasComputedPropertyKey .................................................................................. 275 14.4.6 Static Semantics: HasDirectSuper ...................................................................................................... 275 14.4.7 Static Semantics: HasName ................................................................................................................. 276 14.4.8 Static Semantics: IsConstantDeclaration .......................................................................................... 276 14.4.9 Static Semantics: IsFunctionDefinition .............................................................................................. 276 14.4.10 Static Semantics: PropName................................................................................................................ 276 14.4.11 Runtime Semantics: EvaluateBody ..................................................................................................... 276 14.4.12 Runtime Semantics: InstantiateFunctionObject ................................................................................ 277 14.4.13 Runtime Semantics: PropertyDefinitionEvaluation ......................................................................... 277 14.4.14 Runtime Semantics: Evaluation .......................................................................................................... 278 14.5 Class Definitions ..................................................................................................................................... 279 14.5.1 Static Semantics: Early Errors ............................................................................................................. 280 14.5.2 Static Semantics: BoundNames .......................................................................................................... 280 14.5.3 Static Semantics: ConstructorMethod ............................................................................................... 281 14.5.4 Static Semantics: Contains .................................................................................................................. 281 14.5.5 Static Semantics: ComputedPropertyContains ................................................................................ 281 14.5.6 Static Semantics: HasName ................................................................................................................. 282 14.5.7 Static Semantics: IsConstantDeclaration .......................................................................................... 282 14.5.8 Static Semantics: IsFunctionDefinition .............................................................................................. 282 14.5.9 Static Semantics: IsStatic ..................................................................................................................... 282 14.5.10 Static Semantics: NonConstructorMethodDefinitions .................................................................... 282 14.5.11 Static Semantics: PrototypePropertyNameList ................................................................................ 283 14.5.12 Static Semantics: PropName................................................................................................................ 283

  • x © Ecma International 2015

    14.5.13 Static Semantics: StaticPropertyNameList ....................................................................................... 283 14.5.14 Runtime Semantics: ClassDefinitionEvaluation ................................................................................ 283 14.5.15 Runtime Semantics: BindingClassDeclarationEvaluation .............................................................. 285 14.5.16 Runtime Semantics: Evaluation .......................................................................................................... 285 14.6 Tail Position Calls ................................................................................................................................... 285 14.6.1 Static Semantics: IsInTailPosition(nonterminal) ............................................................................... 285 14.6.2 Static Semantics: HasProductionInTailPosition ............................................................................... 286 14.6.3 Runtime Semantics: PrepareForTailCall ( )...................................................................................... 290

    15 ECMAScript Language: Scripts and Modules .................................................................................... 290 15.1 Scripts ....................................................................................................................................................... 290 15.1.1 Static Semantics: Early Errors ............................................................................................................ 290 15.1.2 Static Semantics: IsStrict ..................................................................................................................... 291 15.1.3 Static Semantics: LexicallyDeclaredNames ...................................................................................... 291 15.1.4 Static Semantics: LexicallyScopedDeclarations .............................................................................. 291 15.1.5 Static Semantics: VarDeclaredNames ................................................................................................ 291 15.1.6 Static Semantics: VarScopedDeclarations ........................................................................................ 291 15.1.7 Runtime Semantics: ScriptEvaluation ............................................................................................... 291 15.1.8 Runtime Semantics: GlobalDeclarationInstantiation (script, env) ................................................. 292 15.1.9 Runtime Semantics: ScriptEvaluationJob ( sourceText ) ................................................................ 293 15.2 Modules .................................................................................................................................................... 294 15.2.1 Module Semantics................................................................................................................................... 294 15.2.2 Imports ...................................................................................................................................................... 308 15.2.3 Exports ...................................................................................................................................................... 311

    16 Error Handling and Language Extensions ......................................................................................... 317 16.1 Forbidden Extensions ............................................................................................................................ 318

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

    18 The Global Object ................................................................................................................................... 320 18.1 Value Properties of the Global Object ................................................................................................. 321 18.1.1 Infinity ....................................................................................................................................................... 321 18.1.2 NaN ............................................................................................................................................................ 321 18.1.3 undefined .................................................................................................................................................. 321 18.2 Function Properties of the Global Object ........................................................................................... 321 18.2.1 eval (x) ....................................................................................................................................................... 321 18.2.2 isFinite (number) ..................................................................................................................................... 324 18.2.3 isNaN (number) ........................................................................................................................................ 324 18.2.4 parseFloat (string)................................................................................................................................... 324 18.2.5 parseInt (string , radix) ........................................................................................................................... 324 18.2.6 URI Handling Functions ......................................................................................................................... 325 18.3 Constructor Properties of the Global Object ..................................................................................... 330 18.3.1 Array ( . . . ) ............................................................................................................................................... 330 18.3.2 ArrayBuffer ( . . . ) .................................................................................................................................... 330 18.3.3 Boolean ( . . . ) .......................................................................................................................................... 330 18.3.4 DataView ( . . . ) ........................................................................................................................................ 330 18.3.5 Date ( . . . ) ................................................................................................................................................. 331 18.3.6 Error ( . . . ) ................................................................................................................................................ 331 18.3.7 EvalError ( . . . ) ........................................................................................................................................ 331 18.3.8 Float32Array ( . . . ) .................................................................................................................................. 331 18.3.9 Float64Array ( . . . ) .................................................................................................................................. 331 18.3.10 Function ( . . . ) ......................................................................................................................................... 331 18.3.11 Int8Array ( . . . ) ........................................................................................................................................ 331 18.3.12 Int16Array ( . . . ) ...................................................................................................................................... 331 18.3.13 Int32Array ( . . . ) ...................................................................................................................................... 331 18.3.14 Map ( . . . ) ................................................................................................................................................. 331

  • © Ecma International 2015 xi

    18.3.15 Number ( . . . ) ........................................................................................................................................... 331 18.3.16 Object ( . . . ) ............................................................................................................................................. 331 18.3.17 Proxy ( . . . ) ............................................................................................................................................... 331 18.3.18 Promise ( . . . ) .......................................................................................................................................... 331 18.3.19 RangeError ( . . . ) .................................................................................................................................... 332 18.3.20 ReferenceError ( . . . ) .............................................................................................................................. 332 18.3.21 RegExp ( . . . ) ........................................................................................................................................... 332 18.3.22 Set ( . . . ) ................................................................................................................................................... 332 18.3.23 String ( . . . ) .............................................................................................................................................. 332 18.3.24 Symbol ( . . . )............................................................................................................................................ 332 18.3.25 SyntaxError ( . . . ).................................................................................................................................... 332 18.3.26 TypeError ( . . . ) ....................................................................................................................................... 332 18.3.27 Uint8Array ( . . . ) ...................................................................................................................................... 332 18.3.28 Uint8ClampedArray ( . . . ) ...................................................................................................................... 332 18.3.29 Uint16Array ( . . . ) .................................................................................................................................... 332 18.3.30 Uint32Array ( . . . ) .................................................................................................................................... 332 18.3.31 URIError ( . . . ) ......................................................................................................................................... 332 18.3.32 WeakMap ( . . . ) ........................................................................................................................................ 332 18.3.33 WeakSet ( . . . ) ......................................................................................................................................... 333 18.4 Other Properties of the Global Object ................................................................................................. 333 18.4.1 JSON .......................................................................................................................................................... 333 18.4.2 Math ........................................................................................................................................................... 333 18.4.3 Reflect........................................................................................................................................................ 333

    19 Fundamental Objects .............................................................................................................................. 333 19.1 Object Objects ......................................................................................................................................... 333 19.1.1 The Object Constructor .......................................................................................................................... 333 19.1.2 Properties of the Object Constructor................................................................................................... 333 19.1.3 Properties of the Object Prototype Object .......................................................................................... 337 19.1.4 Properties of Object Instances ............................................................................................................. 339 19.2 Function Objects ..................................................................................................................................... 339 19.2.1 The Function Constructor ...................................................................................................................... 339 19.2.2 Properties of the Function Constructor .............................................................................................. 341 19.2.3 Properties of the Function Prototype Object ..................................................................................... 342 19.2.4 Function Instances .................................................................................................................................. 344 19.3 Boolean Objects ...................................................................................................................................... 345 19.3.1 The Boolean Constructor ....................................................................................................................... 345 19.3.2 Properties of the Boolean Constructor ............................................................................................... 346 19.3.3 Properties of the Boolean Prototype Object....................................................................................... 346 19.3.4 Properties of Boolean Instances .......................................................................................................... 347 19.4 Symbol Objects........................................................................................................................................ 347 19.4.1 The Symbol Constructor ........................................................................................................................ 347 19.4.2 Properties of the Symbol Constructor ................................................................................................. 347 19.4.3 Properties of the Symbol Prototype Object ........................................................................................ 349 19.4.4 Properties of Symbol Instances............................................................................................................ 350 19.5 Error Objects ............................................................................................................................................ 351 19.5.1 The Error Constructor ............................................................................................................................ 351 19.5.2 Properties of the Error Constructor ..................................................................................................... 351 19.5.3 Properties of the Error Prototype Object ............................................................................................ 351 19.5.4 Properties of Error Instances ................................................................................................................ 352 19.5.5 Native Error Types Used in This Standard ......................................................................................... 352 19.5.6 NativeError Object Structure ................................................................................................................. 353

    20 Numbers and Dates ................................................................................................................................. 354 20.1 Number Objects ....................................................................................................................................... 354 20.1.1 The Number Constructor ....................................................................................................................... 354

  • xii © Ecma International 2015