Skip to content

Add test case where IteratorBindingInitialization throws when evaluating initializer#4926

Open
G-Lee1031 wants to merge 1 commit intotc39:mainfrom
G-Lee1031:initializer-evaluation-throws
Open

Add test case where IteratorBindingInitialization throws when evaluating initializer#4926
G-Lee1031 wants to merge 1 commit intotc39:mainfrom
G-Lee1031:initializer-evaluation-throws

Conversation

@G-Lee1031
Copy link
Contributor

Hello.
This PR adds a test case where IteratorBindingInitialization of BindingElement : BindingPattern Initializer? throws in step 3.a and step 3.b.

Step 3.a initializer-evaluation-throws-unaryexpression

  • First
    In IteratorBindingInitialization of BindingElement : BindingPattern Initializer? step 3.a evaluation of Initializer is performed.
  • Second
    In this particular test file, Evaluation of UnaryExpression : '+' UnaryExpression is performed.
  • Third
    In Evaluation of UnaryExpression : '+' UnaryExpression step 1, Evaluation of IdentifierReference : Identifier is performed. And as a result, ResolveBinding is called.
  • Fourth
    ResolveBinding calls GetIdentifierReference. Since the identifier x is not declared in the current environment record, GetIdentifierReference traverses the environment chain until it reaches the global environment (where env is null). It returns a Reference Record where the [[Base]] property is set to unresolvable (as per GetIdentifierReference step 1.a).
  • Fifth
    Back in Evaluation of UnaryExpression : + UnaryExpression step 2, GetValue(expr) is called.
  • Sixth
    In GetValue step 2, IsUnresolvableReference(V) returns true because V.[[Base]] is unresolvable. Consequently, GetValue throws a ReferenceError.

Step 3.b initializer-evaluation-throws-identifier

  • First
    In IteratorBindingInitialization of BindingElement : BindingPattern Initializer? step 3.a, evaluation of Initializer is performed.
  • Second
    In this particular test file, Evaluation of IdentifierReference : Identifier is performed.
  • Third
    In Evaluation of IdentifierReference : Identifier step 1, ResolveBinding is called.
  • Fourth
    ResolveBinding calls GetIdentifierReference. Since the identifier x is not declared in the current environment record, GetIdentifierReference traverses the environment chain until it reaches the global environment (where env is null). It returns a Reference Record where the [[Base]] property is set to unresolvable (as per GetIdentifierReference step 1.a).
  • Fifth
    Back in IteratorBindingInitialization of BindingElement : BindingPattern Initializer? step 3.b, GetValue(expr) is called with the unresolvable Reference Record obtained from the previous step.
  • Sixth
    In GetValue step 2, IsUnresolvableReference(V) returns true because V.[[Base]] is unresolvable. Consequently, GetValue throws a ReferenceError.

@G-Lee1031 G-Lee1031 requested a review from a team as a code owner February 17, 2026 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants