B.3 Other Additional Features
B.3.1 Labelled Function Declarations
Prior to ECMAScript 2015, the specification of
-
It is a Syntax Error if any source text that is
strict mode code is matched by this production.
The
B.3.2 Block-Level Function Declarations Web Legacy Compatibility Semantics
Prior to ECMAScript 2015, the ECMAScript specification did not define the occurrence of a
-
A function is declared and only referenced within a single block.
-
One or more
FunctionDeclaration s whoseBindingIdentifier is the name f occur within the function code of an enclosing function g and that declaration is nested within aBlock . -
No other declaration of f that is not a
var
declaration occurs within the function code of g. -
All occurrences of f as an
IdentifierReference are within theStatementList of theBlock containing the declaration of f.
-
One or more
-
A function is declared and possibly used within a single
Block but also referenced by an inner function definition that is not contained within that sameBlock .-
One or more
FunctionDeclaration s whoseBindingIdentifier is the name f occur within the function code of an enclosing function g and that declaration is nested within aBlock . -
No other declaration of f that is not a
var
declaration occurs within the function code of g. -
There may be occurrences of f as an
IdentifierReference within theStatementList of theBlock containing the declaration of f. -
There is at least one occurrence of f as an
IdentifierReference within another function h that is nested within g and no other declaration of f shadows the references to f from within h. - All invocations of h occur after the declaration of f has been evaluated.
-
One or more
-
A function is declared and possibly used within a single block but also referenced within subsequent blocks.
-
One or more
FunctionDeclaration whoseBindingIdentifier is the name f occur within the function code of an enclosing function g and that declaration is nested within aBlock . -
No other declaration of f that is not a
var
declaration occurs within the function code of g. -
There may be occurrences of f as an
IdentifierReference within theStatementList of theBlock containing the declaration of f. -
There is at least one occurrence of f as an
IdentifierReference within the function code of g that lexically follows theBlock containing the declaration of f.
-
One or more
The first use case is interoperable with the semantics of
ECMAScript 2015 interoperability for the second and third use cases requires the following extensions to the clause
If an ECMAScript implementation has a mechanism for reporting diagnostic warning messages, a warning should be produced when code contains a
B.3.2.1 Changes to FunctionDeclarationInstantiation
During
- If strict is
false , then- For each
FunctionDeclaration f that is directly contained in theStatementList of aBlock ,CaseClause , orDefaultClause , do- Let F be
StringValue of theBindingIdentifier of f. - If replacing the
FunctionDeclaration f with aVariableStatement that has F as aBindingIdentifier would not produce any Early Errors for func and parameterNames does not contain F, then- NOTE: A var binding for F is only instantiated here if it is neither a VarDeclaredName, the name of a formal parameter, or another
FunctionDeclaration . - If instantiatedVarNames does not contain F and F is not
"arguments" , then- Perform ! varEnv.CreateMutableBinding(F,
false ). - Perform ! varEnv.InitializeBinding(F,
undefined ). - Append F to instantiatedVarNames.
- Perform ! varEnv.CreateMutableBinding(F,
- When the
FunctionDeclaration f is evaluated, perform the following steps in place of theFunctionDeclaration Evaluation algorithm provided in15.2.6 :- Let fenv be the
running execution context 's VariableEnvironment. - Let benv be the
running execution context 's LexicalEnvironment. - Let fobj be ! benv.GetBindingValue(F,
false ). - Perform ! fenv.SetMutableBinding(F, fobj,
false ). - Return
unused .
- Let fenv be the
- NOTE: A var binding for F is only instantiated here if it is neither a VarDeclaredName, the name of a formal parameter, or another
- Let F be
- For each
B.3.2.2 Changes to GlobalDeclarationInstantiation
During
- Perform the following steps:
- Let strict be
IsStrict of script. - If strict is
false , then- Let declaredFunctionOrVarNames be the
list-concatenation of declaredFunctionNames and declaredVarNames. - For each
FunctionDeclaration f that is directly contained in theStatementList of aBlock ,CaseClause , orDefaultClause Contained within script, do- Let F be
StringValue of theBindingIdentifier of f. - If replacing the
FunctionDeclaration f with aVariableStatement that has F as aBindingIdentifier would not produce any Early Errors for script, then- If env.HasLexicalDeclaration(F) is
false , then- Let fnDefinable be ? env.CanDeclareGlobalVar(F).
- If fnDefinable is
true , then- NOTE: A var binding for F is only instantiated here if it is neither a VarDeclaredName nor the name of another
FunctionDeclaration . - If declaredFunctionOrVarNames does not contain F, then
- Perform ? env.CreateGlobalVarBinding(F,
false ). - Append F to declaredFunctionOrVarNames.
- Perform ? env.CreateGlobalVarBinding(F,
- When the
FunctionDeclaration f is evaluated, perform the following steps in place of theFunctionDeclaration Evaluation algorithm provided in15.2.6 :- Let genv be the
running execution context 's VariableEnvironment. - Let benv be the
running execution context 's LexicalEnvironment. - Let fobj be ! benv.GetBindingValue(F,
false ). - Perform ? genv.SetMutableBinding(F, fobj,
false ). - Return
unused .
- Let genv be the
- NOTE: A var binding for F is only instantiated here if it is neither a VarDeclaredName nor the name of another
- If env.HasLexicalDeclaration(F) is
- Let F be
- Let declaredFunctionOrVarNames be the
- Let strict be
B.3.2.3 Changes to EvalDeclarationInstantiation
During
- If strict is
false , then- Let declaredFunctionOrVarNames be the
list-concatenation of declaredFunctionNames and declaredVarNames. - For each
FunctionDeclaration f that is directly contained in theStatementList of aBlock ,CaseClause , orDefaultClause Contained within body, do- Let F be
StringValue of theBindingIdentifier of f. - If replacing the
FunctionDeclaration f with aVariableStatement that has F as aBindingIdentifier would not produce any Early Errors for body, then- Let bindingExists be
false . - Let thisEnv be lexEnv.
Assert : The following loop will terminate.- Repeat, while thisEnv is not varEnv,
- If thisEnv
is not an Object Environment Record , then- If ! thisEnv.HasBinding(F) is
true , then- Let bindingExists be
true .
- Let bindingExists be
- If ! thisEnv.HasBinding(F) is
- Set thisEnv to thisEnv.[[OuterEnv]].
- If thisEnv
- If bindingExists is
false and varEnv is aGlobal Environment Record , then- If varEnv.HasLexicalDeclaration(F) is
false , then- Let fnDefinable be ? varEnv.CanDeclareGlobalVar(F).
- Else,
- Let fnDefinable be
false .
- Let fnDefinable be
- If varEnv.HasLexicalDeclaration(F) is
- Else,
- Let fnDefinable be
true .
- Let fnDefinable be
- If bindingExists is
false and fnDefinable istrue , then- If declaredFunctionOrVarNames does not contain F, then
- If varEnv is a
Global Environment Record , then- Perform ? varEnv.CreateGlobalVarBinding(F,
true ).
- Perform ? varEnv.CreateGlobalVarBinding(F,
- Else,
- Let bindingExists be ! varEnv.HasBinding(F).
- If bindingExists is
false , then- Perform ! varEnv.CreateMutableBinding(F,
true ). - Perform ! varEnv.InitializeBinding(F,
undefined ).
- Perform ! varEnv.CreateMutableBinding(F,
- Append F to declaredFunctionOrVarNames.
- If varEnv is a
- When the
FunctionDeclaration f is evaluated, perform the following steps in place of theFunctionDeclaration Evaluation algorithm provided in15.2.6 :- Let genv be the
running execution context 's VariableEnvironment. - Let benv be the
running execution context 's LexicalEnvironment. - Let fobj be ! benv.GetBindingValue(F,
false ). - Perform ? genv.SetMutableBinding(F, fobj,
false ). - Return
unused .
- Let genv be the
- If declaredFunctionOrVarNames does not contain F, then
- Let bindingExists be
- Let F be
- Let declaredFunctionOrVarNames be the
B.3.2.4 Changes to Block Static Semantics: Early Errors
The rules for the following production in
-
It is a Syntax Error if the
LexicallyDeclaredNames ofStatementList contains any duplicate entries, unless thesource text matched by this production is notstrict mode code and the duplicate entries are only bound by FunctionDeclarations. -
It is a Syntax Error if any element of the
LexicallyDeclaredNames ofStatementList also occurs in theVarDeclaredNames ofStatementList .
B.3.2.5 Changes to switch
Statement Static Semantics: Early Errors
The rules for the following production in
-
It is a Syntax Error if the
LexicallyDeclaredNames ofCaseBlock contains any duplicate entries, unless thesource text matched by this production is notstrict mode code and the duplicate entries are only bound by FunctionDeclarations. -
It is a Syntax Error if any element of the
LexicallyDeclaredNames ofCaseBlock also occurs in theVarDeclaredNames ofCaseBlock .
B.3.2.6 Changes to BlockDeclarationInstantiation
During
- If ! env.HasBinding(dn) is
false , then- Perform ! env.CreateMutableBinding(dn,
false ).
- Perform ! env.CreateMutableBinding(dn,
During
- Perform the following steps:
- If the binding for fn in env is an uninitialized binding, then
- Perform ! env.InitializeBinding(fn, fo).
- Else,
Assert : d is aFunctionDeclaration .- Perform ! env.SetMutableBinding(fn, fo,
false ).
- If the binding for fn in env is an uninitialized binding, then
B.3.3 FunctionDeclarations in IfStatement Statement Clauses
The following augments the
This production only applies when parsing
B.3.4 VariableStatements in Catch Blocks
The content of subclause
-
It is a Syntax Error if
BoundNames ofCatchParameter contains any duplicate elements. -
It is a Syntax Error if any element of the
BoundNames ofCatchParameter also occurs in theLexicallyDeclaredNames ofBlock . -
It is a Syntax Error if any element of the
BoundNames ofCatchParameter also occurs in theVarDeclaredNames ofBlock unlessCatchParameter is .CatchParameter : BindingIdentifier
The var
declarations that bind a name that is also bound by the var
declarations will assign to the corresponding catch parameter rather than the var
binding.
This modified behaviour also applies to var
and function
declarations introduced by
Step
- If thisEnv is not the
Environment Record for aCatch clause, throw aSyntaxError exception.
Step
- If thisEnv is not the
Environment Record for aCatch clause, let bindingExists betrue .
B.3.5 Initializers in ForIn Statement Heads
The following augments the
This production only applies when parsing
The
- Return
ContainsDuplicateLabels ofStatement with argument labelSet.
The
- Return
ContainsUndefinedBreakTarget ofStatement with argument labelSet.
The
- Return
ContainsUndefinedContinueTarget ofStatement with arguments iterationSet and « ».
The
- Return
false .
The
- Let names1 be the
BoundNames ofBindingIdentifier . - Let names2 be the
VarDeclaredNames ofStatement . - Return the
list-concatenation of names1 and names2.
The
- Let declarations1 be «
BindingIdentifier ». - Let declarations2 be the
VarScopedDeclarations ofStatement . - Return the
list-concatenation of declarations1 and declarations2.
The
- Let bindingId be
StringValue ofBindingIdentifier . - Let lhs be ?
ResolveBinding (bindingId). - If
IsAnonymousFunctionDefinition (Initializer ) istrue , then- Let value be ?
NamedEvaluation ofInitializer with argument bindingId.
- Let value be ?
- Else,
- Let rhs be ?
Evaluation ofInitializer . - Let value be ?
GetValue (rhs).
- Let rhs be ?
- Perform ?
PutValue (lhs, value). - Let keyResult be ?
ForIn/OfHeadEvaluation (« »,Expression ,enumerate ). - Return ?
ForIn/OfBodyEvaluation (BindingIdentifier ,Statement , keyResult,enumerate ,var-binding , labelSet).
B.3.6 The [[IsHTMLDDA]] Internal Slot
An [[IsHTMLDDA]] internal slot may exist on typeof
operator
Objects with an [[IsHTMLDDA]] internal slot are never created by this specification. However, the document.all
object in web browsers is a document.all
.
B.3.6.1 Changes to ToBoolean
The following step replaces step
- If argument
is an Object and argument has an [[IsHTMLDDA]] internal slot, returnfalse .
B.3.6.2 Changes to IsLooselyEqual
The following steps replace step
- Perform the following steps:
- If x
is an Object , x has an [[IsHTMLDDA]] internal slot, and y is eitherundefined ornull , returntrue . - If x is either
undefined ornull , yis an Object , and y has an [[IsHTMLDDA]] internal slot, returntrue .
- If x
B.3.6.3 Changes to the typeof
Operator
The following step replaces step typeof
- If val has an [[IsHTMLDDA]] internal slot, return
"undefined" .
B.3.7 Non-default behaviour in HostMakeJobCallback
The
B.3.8 Non-default behaviour in HostEnsureCanAddPrivateElement
The