ecmascript 2017 language specification · pdf fileecmascript® 2017 language specification...

885
Reference number ECMA-123:2009 © Ecma International 2009 ECMA-262 8 th Edition / June 2017 ECMAScript ® 2017 Language Specification

Upload: vuongque

Post on 01-Feb-2018

226 views

Category:

Documents


0 download

TRANSCRIPT

  • Reference number ECMA-123:2009

    Ecma International 2009

    ECMA-262 8th Edition / June 2017

    ECMAScript 2017 Language Specification

  • COPYRIGHT PROTECTED DOCUMENT

    Ecma International 2017

    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

    http://www.ecma-international.org/

  • Ecma International 2017 i

    COPYRIGHT NOTICE

    2017 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.

    http://www.ecma-international.org/memento/codeofconduct.htm

  • ii Ecma International 2017

  • Introduction1Scope2Conformance3NormativeReferences4Overview4.1WebScripting4.2ECMAScriptOverview4.2.1Objects4.2.2TheStrictVariantofECMAScript

    4.3TermsandDeinitions4.3.1type4.3.2primitivevalue4.3.3object4.3.4constructor4.3.5prototype4.3.6ordinaryobject4.3.7exoticobject4.3.8standardobject4.3.9builtinobject4.3.10undeinedvalue4.3.11Undeinedtype4.3.12nullvalue4.3.13Nulltype4.3.14Booleanvalue4.3.15Booleantype4.3.16Booleanobject4.3.17Stringvalue4.3.18Stringtype4.3.19Stringobject4.3.20Numbervalue4.3.21Numbertype4.3.22Numberobject4.3.23Ininity

    ECMAScript2017LanguageSpeciicationTableofContents

  • 4.3.24NaN4.3.25Symbolvalue4.3.26Symboltype4.3.27Symbolobject4.3.28function4.3.29builtinfunction4.3.30property4.3.31method4.3.32builtinmethod4.3.33attribute4.3.34ownproperty4.3.35inheritedproperty

    4.4OrganizationofThisSpeciication5NotationalConventions5.1SyntacticandLexicalGrammars5.1.1ContextFreeGrammars5.1.2TheLexicalandRegExpGrammars5.1.3TheNumericStringGrammar5.1.4TheSyntacticGrammar5.1.5GrammarNotation

    5.2AlgorithmConventions5.3StaticSemanticRules

    6ECMAScriptDataTypesandValues6.1ECMAScriptLanguageTypes6.1.1TheUndeinedType6.1.2TheNullType6.1.3TheBooleanType6.1.4TheStringType6.1.5TheSymbolType6.1.5.1WellKnownSymbols

    6.1.6TheNumberType6.1.7TheObjectType6.1.7.1PropertyAttributes6.1.7.2ObjectInternalMethodsandInternalSlots6.1.7.3InvariantsoftheEssentialInternalMethods6.1.7.4WellKnownIntrinsicObjects

    6.2ECMAScriptSpeciicationTypes6.2.1TheListandRecordSpeciicationTypes6.2.2TheSetandRelationSpeciicationTypes6.2.3TheCompletionRecordSpeciicationType

  • 6.2.3.1NormalCompletion6.2.3.2ImplicitCompletionValues6.2.3.3ThrowanException6.2.3.4ReturnIfAbrupt6.2.3.5UpdateEmpty(completionRecord,value)

    6.2.4TheReferenceSpeciicationType6.2.4.1GetValue(V)6.2.4.2PutValue(V,W)6.2.4.3GetThisValue(V)6.2.4.4InitializeReferencedBinding(V,W)

    6.2.5ThePropertyDescriptorSpeciicationType6.2.5.1IsAccessorDescriptor(Desc)6.2.5.2IsDataDescriptor(Desc)6.2.5.3IsGenericDescriptor(Desc)6.2.5.4FromPropertyDescriptor(Desc)6.2.5.5ToPropertyDescriptor(Obj)6.2.5.6CompletePropertyDescriptor(Desc)

    6.2.6TheLexicalEnvironmentandEnvironmentRecordSpeciicationTypes6.2.7DataBlocks6.2.7.1CreateByteDataBlock(size)6.2.7.2CreateSharedByteDataBlock(size)6.2.7.3CopyDataBlockBytes(toBlock,toIndex,fromBlock,fromIndex,count)

    7AbstractOperations7.1TypeConversion7.1.1ToPrimitive(input[,PreferredType])7.1.1.1OrdinaryToPrimitive(O,hint)

    7.1.2ToBoolean(argument)7.1.3ToNumber(argument)7.1.3.1ToNumberAppliedtotheStringType7.1.3.1.1RS:MV

    7.1.4ToInteger(argument)7.1.5ToInt32(argument)7.1.6ToUint32(argument)7.1.7ToInt16(argument)7.1.8ToUint16(argument)7.1.9ToInt8(argument)7.1.10ToUint8(argument)7.1.11ToUint8Clamp(argument)7.1.12ToString(argument)7.1.12.1ToStringAppliedtotheNumberType

  • 7.1.13ToObject(argument)7.1.14ToPropertyKey(argument)7.1.15ToLength(argument)7.1.16CanonicalNumericIndexString(argument)7.1.17ToIndex(value)

    7.2TestingandComparisonOperations7.2.1RequireObjectCoercible(argument)7.2.2IsArray(argument)7.2.3IsCallable(argument)7.2.4IsConstructor(argument)7.2.5IsExtensible(O)7.2.6IsInteger(argument)7.2.7IsPropertyKey(argument)7.2.8IsRegExp(argument)7.2.9SameValue(x,y)7.2.10SameValueZero(x,y)7.2.11SameValueNonNumber(x,y)7.2.12AbstractRelationalComparison7.2.13AbstractEqualityComparison7.2.14StrictEqualityComparison

    7.3OperationsonObjects7.3.1Get(O,P)7.3.2GetV(V,P)7.3.3Set(O,P,V,Throw)7.3.4CreateDataProperty(O,P,V)7.3.5CreateMethodProperty(O,P,V)7.3.6CreateDataPropertyOrThrow(O,P,V)7.3.7DeinePropertyOrThrow(O,P,desc)7.3.8DeletePropertyOrThrow(O,P)7.3.9GetMethod(V,P)7.3.10HasProperty(O,P)7.3.11HasOwnProperty(O,P)7.3.12Call(F,V[,argumentsList])7.3.13Construct(F[,argumentsList[,newTarget]])7.3.14SetIntegrityLevel(O,level)7.3.15TestIntegrityLevel(O,level)7.3.16CreateArrayFromList(elements)7.3.17CreateListFromArrayLike(obj[,elementTypes])7.3.18Invoke(V,P[,argumentsList])7.3.19OrdinaryHasInstance(C,O)

  • 7.3.20SpeciesConstructor(O,defaultConstructor)7.3.21EnumerableOwnProperties(O,kind)7.3.22GetFunctionRealm(obj)

    7.4OperationsonIteratorObjects7.4.1GetIterator(obj[,method])7.4.2IteratorNext(iterator[,value])7.4.3IteratorComplete(iterResult)7.4.4IteratorValue(iterResult)7.4.5IteratorStep(iterator)7.4.6IteratorClose(iterator,completion)7.4.7CreateIterResultObject(value,done)7.4.8CreateListIterator(list)7.4.8.1ListIteratornext()

    8ExecutableCodeandExecutionContexts8.1LexicalEnvironments8.1.1EnvironmentRecords8.1.1.1DeclarativeEnvironmentRecords8.1.1.1.1HasBinding(N)8.1.1.1.2CreateMutableBinding(N,D)8.1.1.1.3CreateImmutableBinding(N,S)8.1.1.1.4InitializeBinding(N,V)8.1.1.1.5SetMutableBinding(N,V,S)8.1.1.1.6GetBindingValue(N,S)8.1.1.1.7DeleteBinding(N)8.1.1.1.8HasThisBinding()8.1.1.1.9HasSuperBinding()8.1.1.1.10WithBaseObject()

    8.1.1.2ObjectEnvironmentRecords8.1.1.2.1HasBinding(N)8.1.1.2.2CreateMutableBinding(N,D)8.1.1.2.3CreateImmutableBinding(N,S)8.1.1.2.4InitializeBinding(N,V)8.1.1.2.5SetMutableBinding(N,V,S)8.1.1.2.6GetBindingValue(N,S)8.1.1.2.7DeleteBindin