15.2 Function Definitions
Syntax
15.2.1 Static Semantics: Early Errors
-
If the
source text matched by FormalParameters isstrict mode code , the Early Error rules for are applied.UniqueFormalParameters : FormalParameters -
If
BindingIdentifier is present and thesource text matched by BindingIdentifier isstrict mode code , it is a Syntax Error if theStringValue ofBindingIdentifier is either"eval" or"arguments" . -
It is a Syntax Error if
FunctionBodyContainsUseStrict ofFunctionBody istrue andIsSimpleParameterList ofFormalParameters isfalse . -
It is a Syntax Error if any element of the
BoundNames ofFormalParameters also occurs in theLexicallyDeclaredNames ofFunctionBody . -
It is a Syntax Error if
FormalParameters Contains SuperProperty istrue . -
It is a Syntax Error if
FunctionBody Contains SuperProperty istrue . -
It is a Syntax Error if
FormalParameters Contains SuperCall istrue . -
It is a Syntax Error if
FunctionBody Contains SuperCall istrue .
The
-
It is a Syntax Error if the
LexicallyDeclaredNames ofFunctionStatementList contains any duplicate entries. -
It is a Syntax Error if any element of the
LexicallyDeclaredNames ofFunctionStatementList also occurs in theVarDeclaredNames ofFunctionStatementList . -
It is a Syntax Error if
ContainsDuplicateLabels ofFunctionStatementList with argument « » istrue . -
It is a Syntax Error if
ContainsUndefinedBreakTarget ofFunctionStatementList with argument « » istrue . -
It is a Syntax Error if
ContainsUndefinedContinueTarget ofFunctionStatementList with arguments « » and « » istrue .
15.2.2 Static Semantics: FunctionBodyContainsUseStrict
The
- If the
Directive Prologue ofFunctionBody contains aUse Strict Directive , returntrue ; otherwise, returnfalse .
15.2.3 Runtime Semantics: EvaluateFunctionBody
The
- Perform ?
FunctionDeclarationInstantiation (functionObject, argumentsList). - Return ?
Evaluation ofFunctionStatementList .
15.2.4 Runtime Semantics: InstantiateOrdinaryFunctionObject
The
- Let name be
StringValue ofBindingIdentifier . - Let sourceText be the
source text matched by FunctionDeclaration . - Let F be
OrdinaryFunctionCreate (%Function.prototype% , sourceText,FormalParameters ,FunctionBody ,non-lexical-this , env, privateEnv). - Perform
SetFunctionName (F, name). - Perform
MakeConstructor (F). - Return F.
- Let sourceText be the
source text matched by FunctionDeclaration . - Let F be
OrdinaryFunctionCreate (%Function.prototype% , sourceText,FormalParameters ,FunctionBody ,non-lexical-this , env, privateEnv). - Perform
SetFunctionName (F,"default" ). - Perform
MakeConstructor (F). - Return F.
An anonymous export default
declaration, and its function code is therefore always
15.2.5 Runtime Semantics: InstantiateOrdinaryFunctionExpression
The
- If name is not present, set name to
"" . - Let env be the LexicalEnvironment of the
running execution context . - Let privateEnv be the
running execution context 's PrivateEnvironment. - Let sourceText be the
source text matched by FunctionExpression . - Let closure be
OrdinaryFunctionCreate (%Function.prototype% , sourceText,FormalParameters ,FunctionBody ,non-lexical-this , env, privateEnv). - Perform
SetFunctionName (closure, name). - Perform
MakeConstructor (closure). - Return closure.
Assert : name is not present.- Set name to
StringValue ofBindingIdentifier . - Let outerEnv be the
running execution context 's LexicalEnvironment. - Let funcEnv be
NewDeclarativeEnvironment (outerEnv). - Perform ! funcEnv.CreateImmutableBinding(name,
false ). - Let privateEnv be the
running execution context 's PrivateEnvironment. - Let sourceText be the
source text matched by FunctionExpression . - Let closure be
OrdinaryFunctionCreate (%Function.prototype% , sourceText,FormalParameters ,FunctionBody ,non-lexical-this , funcEnv, privateEnv). - Perform
SetFunctionName (closure, name). - Perform
MakeConstructor (closure). - Perform ! funcEnv.InitializeBinding(name, closure).
- Return closure.
The
15.2.6 Runtime Semantics: Evaluation
- Return
empty .
An alternative semantics is provided in
- Return
empty .
A
- Return
undefined .