ecma-262

566
Reference number ECMA-123:2009 © Ecma International 2009 ECMA-262 6 th Edition / June 2015 ECMAScript ® 2015 Language Specification

Upload: ben-warzeski

Post on 19-Feb-2016

2 views

Category:

Documents


0 download

DESCRIPTION

Ecma Specs

TRANSCRIPT

  • Reference number ECMA-123:2009

    Ecma International 2009

    ECMA-262 6th Edition / June 2015

    ECMAScript 2015 Language Specification

  • COPYRIGHT PROTECTED DOCUMENT

    Ecma International 2015

    Ecma International Rue du Rhone 114 CH-1204 Geneva Tel: +41 22 849 6000 Fax: +41 22 849 6001 Web: http://www.ecma-international.org

  • 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 al l 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 differ ent 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 Internat ional 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.

  • 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 .................................................................................................................... 16 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 ........................................................................................................................ 18 6.1.6 The Object Type .......................................................................................................................... 19 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 ) ................................................................................................................. 43 7.1.13 ToPropertyKey ( argument ) ....................................................................................................... 44 7.1.14 ToLength ( argument ) ................................................................................................................ 44 7.1.15 CanonicalNumericIndexString ( argument ) .............................................................................. 44 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 ) ......................................................................................................... 45 7.2.4 IsExtensible (O) ........................................................................................................................... 45 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) ................................................................................................................... 46 7.2.10 Abstract Relational Comparison ................................................................................................ 47 7.2.11 Abstract Equality Comparison ................................................................................................... 48 7.2.12 Strict Equality Comparison ........................................................................................................ 48 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) ...................................................................................................... 49 7.3.4 CreateMethodProperty (O, P, V) ................................................................................................. 50 7.3.5 CreateDataPropertyOrThrow (O, P, V)........................................................................................ 50 7.3.6 DefinePropertyOrThrow (O, P, desc) .......................................................................................... 50 7.3.7 DeletePropertyOrThrow (O, P) .................................................................................................... 50 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]) .......................................................................................................... 51 7.3.12 Construct (F, [argumentsList], [newTarget]) ............................................................................. 51 7.3.13 SetIntegrityLevel (O, level) ......................................................................................................... 52 7.3.14 TestIntegrityLevel (O, level) ........................................................................................................ 52 7.3.15 CreateArrayFromList (elements) ................................................................................................ 52 7.3.16 CreateListFromArrayLike (obj [, elementTypes] )...................................................................... 53 7.3.17 Invoke(O,P, [argumentsList]) ...................................................................................................... 53 7.3.18 OrdinaryHasInstance (C, O) ........................................................................................................ 53 7.3.19 SpeciesConstructor ( O, defaultConstructor ) ........................................................................... 54 7.3.20 EnumerableOwnNames (O) ........................................................................................................ 54 7.3.21 GetFunctionRealm ( obj ) ............................................................................................................ 54 7.3.22

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

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

    Environment Records ................................................................................................................. 57 8.1.1 Lexical Environment Operations ................................................................................................ 71 8.1.2

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

  • Ecma International 2015 v

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

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

    8.5 ECMAScript Initialization() .......................................................................................................... 77 InitializeHostDefinedRealm ( realm ) .......................................................................................... 78 8.5.1

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

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

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

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

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

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

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

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

  • vi Ecma International 2015

    [[HasProperty]] (P) .................................................................................................................... 112 9.5.7 [[Get]] (P, Receiver) ................................................................................................................... 113 9.5.8 [[Set]] ( P, V, Receiver) .............................................................................................................. 113 9.5.9

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

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

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

    10.2 Types of Source Code .............................................................................................................. 117 Strict Mode Code ...................................................................................................................... 118 10.2.1 Non-ECMAScript Functions...................................................................................................... 118 10.2.2

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

    Identifier Names ........................................................................................................................ 123 11.6.1 Reserved Words ........................................................................................................................ 124 11.6.2

    11.7 Punctuators ............................................................................................................................... 125 11.8 Literals ....................................................................................................................................... 125

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

    11.9 Automatic Semicolon Insertion ................................................................................................ 134 Rules of Automatic Semicolon Insertion ................................................................................. 135 11.9.1 Examples of Automatic Semicolon Insertion........................................................................... 136 11.9.2

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

    Static Semantics: Early Errors ................................................................................................ 137 12.1.1 Static Semantics: BoundNames ............................................................................................... 138 12.1.2 Static Semantics: IsValidSimpleAssignmentTarget ............................................................... 138 12.1.3 Static Semantics: StringValue .................................................................................................. 138 12.1.4 Runtime Semantics: BindingInitialization ................................................................................ 138 12.1.5 Runtime Semantics: Evaluation .............................................................................................. 139 12.1.6

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

    The Grouping Operator ............................................................................................................. 152 12.2.1012.3 Left-Hand-Side Expressions ..................................................................................................... 153

    Static Semantics ....................................................................................................................... 153 12.3.1 Property Accessors .................................................................................................................. 156 12.3.2

  • Ecma International 2015 vii

    The new Operator ...................................................................................................................... 157 12.3.3 Function Calls ........................................................................................................................... 157 12.3.4 The super Keyword .................................................................................................................. 159 12.3.5 Argument Lists .......................................................................................................................... 160 12.3.6 Tagged Templates ..................................................................................................................... 160 12.3.7 Meta Properties ......................................................................................................................... 161 12.3.8

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

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

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

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

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

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

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

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

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

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

  • viii Ecma International 2015

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

    12.14 Assignment Operators .............................................................................................................. 178 Static Semantics: Early Errors ................................................................................................ 179 12.14.1 Static Semantics: IsFunctionDefinition ................................................................................... 179 12.14.2 Static Semantics: IsValidSimpleAssignmentTarget ............................................................... 179 12.14.3 Runtime Semantics: Evaluation .............................................................................................. 179 12.14.4 Destructuring Assignment ....................................................................................................... 180 12.14.5

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

    13 ECMAScript Language: Statements and Declarations ............................................................ 186 13.1 Statement Semantics ................................................................................................................ 186

    Static Semantics: ContainsDuplicateLabels ............................................................................ 186 13.1.1 Static Semantics: ContainsUndefinedBreakTarget ................................................................. 187 13.1.2 Static Semantics: ContainsUndefinedContinueTarget ............................................................ 187 13.1.3 Static Semantics: DeclarationPart........................................................................................... 187 13.1.4 Static Semantics: VarDeclaredNames..................................................................................... 188 13.1.5 Static Semantics: VarScopedDeclarations ............................................................................. 188 13.1.6 Runtime Semantics: LabelledEvaluation ............................................................................... 188 13.1.7 Runtime Semantics: Evaluation .............................................................................................. 188 13.1.8

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

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

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

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

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

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

    13.7 Iteration Statements .................................................................................................................. 207 Semantics .................................................................................................................................. 208 13.7.1 The do-while Statement .......................................................................................................... 208 13.7.2

  • Ecma International 2015 ix

    The while Statement ................................................................................................................ 209 13.7.3 The for Statement .................................................................................................................... 210 13.7.4 The for-in and for-of Statements ......................................................................................... 213 13.7.5

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

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

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

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

    13.12 The switch Statement .............................................................................................................. 222 Static Semantics: Early Errors................................................................................................. 222 13.12.1 Static Semantics: ContainsDuplicateLabels ............................................................................ 222 13.12.2 Static Semantics: ContainsUndefinedBreakTarget ................................................................. 223 13.12.3 Static Semantics: ContainsUndefinedContinueTarget ............................................................ 223 13.12.4 Static Semantics: LexicallyDeclaredNames ............................................................................ 224 13.12.5 Static Semantics: LexicallyScopedDeclarations .................................................................... 225 13.12.6 Static Semantics: VarDeclaredNames ..................................................................................... 225 13.12.7 Static Semantics: VarScopedDeclarations ............................................................................. 226 13.12.8 Runtime Semantics: CaseBlockEvaluation ............................................................................. 226 13.12.9

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

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

    Static Semantics: TopLevelVarDeclaredNames...................................................................... 230 13.13.10 Static Semantics: TopLevelVarScopedDeclarations .............................................................. 231 13.13.11 Static Semantics: VarDeclaredNames ..................................................................................... 231 13.13.12 Static Semantics: VarScopedDeclarations ............................................................................. 231 13.13.13 Runtime Semantics: LabelledEvaluation ............................................................................... 231 13.13.14 Runtime Semantics: Evaluation ............................................................................................... 232 13.13.15

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

    13.15 The try Statement .................................................................................................................... 232 Static Semantics: Early Errors................................................................................................. 232 13.15.1 Static Semantics: ContainsDuplicateLabels ............................................................................ 233 13.15.2 Static Semantics: ContainsUndefinedBreakTarget ................................................................. 233 13.15.3 Static Semantics: ContainsUndefinedContinueTarget ............................................................ 234 13.15.4 Static Semantics: VarDeclaredNames ..................................................................................... 234 13.15.5 Static Semantics: VarScopedDeclarations ............................................................................. 235 13.15.6 Runtime Semantics: CatchClauseEvaluation .......................................................................... 235 13.15.7

  • x Ecma International 2015

    Runtime Semantics: Evaluation .............................................................................................. 235 13.15.813.16 The debugger statement .......................................................................................................... 236

    Runtime Semantics: Evaluation .............................................................................................. 236 13.16.1

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

    Directive Prologues and the Use Strict Directive .................................................................... 237 14.1.1 Static Semantics: Early Errors ................................................................................................ 237 14.1.2 Static Semantics: BoundNames .............................................................................................. 238 14.1.3 Static Semantics: Contains ..................................................................................................... 238 14.1.4 Static Semantics: ContainsExpression ................................................................................... 239 14.1.5 Static Semantics: ExpectedArgumentCount .......................................................................... 239 14.1.6 Static Semantics: HasInitializer ............................................................................................... 240 14.1.7 Static Semantics: HasName .................................................................................................... 240 14.1.8 Static Semantics: IsAnonymousFunctionDefinition ( production ) ....................................... 240 14.1.9

    Static Semantics: IsConstantDeclaration ............................................................................... 240 14.1.10 Static Semantics: IsFunctionDefinition ................................................................................... 240 14.1.11 Static Semantics: IsSimpleParameterList ............................................................................... 241 14.1.12 Static Semantics: LexicallyDeclaredNames ........................................................................... 241 14.1.13 Static Semantics: LexicallyScopedDeclarations .................................................................... 241 14.1.14 Static Semantics: VarDeclaredNames..................................................................................... 241 14.1.15 Static Semantics: VarScopedDeclarations ............................................................................. 242 14.1.16 Runtime Semantics: EvaluateBody ......................................................................................... 242 14.1.17 Runtime Semantics: IteratorBindingInitialization.................................................................. 242 14.1.18 Runtime Semantics: InstantiateFunctionObject ...................................................................... 243 14.1.19 Runtime Semantics: Evaluation .............................................................................................. 243 14.1.20

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

    Static Semantics: LexicallyDeclaredNames ........................................................................... 246 14.2.10 Static Semantics: LexicallyScopedDeclarations .................................................................... 246 14.2.11 Static Semantics: VarDeclaredNames..................................................................................... 247 14.2.12 Static Semantics: VarScopedDeclarations ............................................................................. 247 14.2.13 Runtime Semantics: IteratorBindingInitialization.................................................................. 247 14.2.14 Runtime Semantics: EvaluateBody ......................................................................................... 247 14.2.15 Runtime Semantics: Evaluation .............................................................................................. 248 14.2.16

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

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

  • Ecma International 2015 xi

    Static Semantics: HasName ..................................................................................................... 252 14.4.7 Static Semantics: IsConstantDeclaration................................................................................ 253 14.4.8 Static Semantics: IsFunctionDefinition ................................................................................... 253 14.4.9

    Static Semantics: PropName ................................................................................................... 253 14.4.10 Runtime Semantics: EvaluateBody.......................................................................................... 253 14.4.11 Runtime Semantics: InstantiateFunctionObject ...................................................................... 253 14.4.12 Runtime Semantics: PropertyDefinitionEvaluation ................................................................ 254 14.4.13 Runtime Semantics: Evaluation .............................................................................................. 254 14.4.14

    14.5 Class Definitions ....................................................................................................................... 256 Static Semantics: Early Errors................................................................................................. 256 14.5.1 Static Semantics: BoundNames .............................................................................................. 257 14.5.2 Static Semantics: ConstructorMethod .................................................................................... 257 14.5.3 Static Semantics: Contains...................................................................................................... 257 14.5.4 Static Semantics: ComputedPropertyContains ...................................................................... 258 14.5.5 Static Semantics: HasName ..................................................................................................... 258 14.5.6 Static Semantics: IsConstantDeclaration................................................................................ 258 14.5.7 Static Semantics: IsFunctionDefinition ................................................................................... 258 14.5.8 Static Semantics: IsStatic ........................................................................................................ 259 14.5.9

    Static Semantics: NonConstructorMethodDefinitions ........................................................... 259 14.5.10 Static Semantics: PrototypePropertyNameList ...................................................................... 259 14.5.11 Static Semantics: PropName ................................................................................................... 259 14.5.12 Static Semantics: StaticPropertyNameList ............................................................................. 259 14.5.13 Runtime Semantics: ClassDefinitionEvaluation ...................................................................... 260 14.5.14 Runtime Semantics: BindingClassDeclarationEvaluation ...................................................... 261 14.5.15 Runtime Semantics: Evaluation .............................................................................................. 261 14.5.16

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

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

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

    15.2 Modules ..................................................................................................................................... 269 Module Semantics ..................................................................................................................... 269 15.2.1 Imports....................................................................................................................................... 282 15.2.2 Exports ...................................................................................................................................... 284 15.2.3

    16 Error Handling and Language Extensions ............................................................................... 291 16.1 Forbidden Extensions ............................................................................................................... 291

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

    18 The Global Object ...................................................................................................................... 293 18.1 Value Properties of the Global Object ...................................................................................... 294

    Infinity ........................................................................................................................................ 294 18.1.1 NaN ............................................................................................................................................ 294 18.1.2 undefined ................................................................................................................................... 294 18.1.3

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

  • xii Ecma International 2015

    parseInt (string , radix) ............................................................................................................. 297 18.2.5 URI Handling Functions ............................................................................................................ 298 18.2.6

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

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

    18.4 Other Properties of the Global Object ...................................................................................... 304 JSON .......................................................................................................................................... 304 18.4.1 Math ........................................................................................................................................... 304 18.4.2 Reflect ....................................................................................................................................... 305 18.4.3

    19 Fundamental Objects ................................................................................................................ 305 19.1 Object Objects........................................................................................................................... 305

    The Object Constructor ............................................................................................................ 305 19.1.1 Properties of the Object Constructor ....................................................................................... 305 19.1.2 Properties of the Object Prototype Object ............................................................................... 309 19.1.3 Properties of Object Instances ................................................................................................. 310 19.1.4

    19.2 Function Objects ....................................................................................................................... 311 The Function Constructor ........................................................................................................ 311 19.2.1 Properties of the Function Constructor ................................................................................... 312 19.2.2 Properties of the Function Prototype Object ........................................................................... 313 19.2.3 Function Instances ................................................................................................................... 315 19.2.4

    19.3 Boolean Objects ........................................................................................................................ 316 The Boolean Constructor ......................................................................................................... 316 19.3.1 Properties of the Boolean Constructor .................................................................................... 316 19.3.2 Properties of the Boolean Prototype Object ............................................................................ 316 19.3.3 Properties of Boolean Instances .............................................................................................. 317 19.3.4

    19.4 Symbol Objects ......................................................................................................................... 317 The Symbol Constructor........................................................................................................... 317 19.4.1 Properties of the Symbol Constructor ..................................................................................... 317 19.4.2

  • Ecma International 2015 xiii

    Properties of the Symbol Prototype Object ............................................................................. 319 19.4.3 Properties of Symbol Instances ............................................................................................... 320 19.4.4

    19.5 Error Objects ............................................................................................................................. 320 The Error Constructor ............................................................................................................... 321 19.5.1 Properties of the Error Constructor ......................................................................................... 321 19.5.2 Properties of the Error Prototype Object ................................................................................. 321 19.5.3 Properties of Error Instances ................................................................................................... 322 19.5.4 Native Error Types Used in This Standard ............................................................................... 322 19.5.5 NativeError Object Structure .................................................................................................... 322 19.5.6

    20 Numbers and Dates ................................................................................................................... 324 20.1 Number Objects ........................................................................................................................ 324

    The Number Constructor .......................................................................................................... 324 20.1.1 Properties of the Number Constructor ..................................................................................... 324 20.1.2 Properties of the Number Prototype Object ............................................................................. 326 20.1.3 Properties of Number Instances ............................................................................................... 330 20.1.4

    20.2 The Math Object ........................................................................................................................ 330 Value Properties of the Math Object ......................................................................................... 331 20.2.1 Function Properties of the Math Object ................................................................................... 332 20.2.2

    20.3 Date Objects .............................................................................................................................. 339 Overview of Date Objects and Definitions of Abstract Operations ......................................... 339 20.3.1 The Date Constructor ................................................................................................................ 344 20.3.2 Properties of the Date Constructor .......................................................................................... 346 20.3.3 Properties of the Date Prototype Object .................................................................................. 347 20.3.4 Properties of Date Instances .................................................................................................... 357 20.3.5

    21 Text Processing ........................................................................................................................ 357 21.1 String Objects............................................................................................................................ 357

    The String Constructor ............................................................................................................. 357 21.1.1 Properties of the String Constructor ........................................................................................ 357 21.1.2 Properties of the String Prototype Object ................................................................................ 359 21.1.3 Properties of String Instances .................................................................................................. 372 21.1.4 String Iterator Objects ............................................................