forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 45
BytecodeGenerator: emit expression info before [Symbol.iterator] get and spread #255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Same problem exists in the sibling
ObjectPatternNode::bindValue(line ~6293):emitRequireObjectCoercibleForDestructuringemitsOpThrowStaticErrorwith no precedingemitExpressionInfo, soconst {a} = nullafter another statement still attributes the TypeError to the previous line. This is pre-existing and outside the stated[Symbol.iterator]/spread scope (object destructuring throws via static error, notget_by_id, so only line/column is wrong — no(evaluating ...)suffix), but since you're fixing the array sibling for the same root cause, the same one-liner —generator.emitExpressionInfo(divot(), divotStart(), divotEnd())beforeemitRequireObjectCoercibleForDestructuring— would close the gap.Extended reasoning...
What
ObjectPatternNode::bindValue(NodesCodegen.cpp:6285) begins with:emitRequireObjectCoercibleForDestructuring(BytecodeGenerator.cpp:5276–5291) emitsOpJnundefinedOrNullfollowed byemitThrowTypeError→emitThrowStaticError→OpThrowStaticError::emit, and none of these callemitExpressionInfo. So thethrow_static_errorop inherits the previous statement's expression range — the exact mechanism this PR fixes forArrayPatternNode::bindValueat line 6102.Why nothing else covers it
Both array and object patterns reach
bindValuethroughDestructuringAssignmentNode::emitBytecode(NodesCodegen.cpp:6079–6083):emitNode(initializer, m_initializer)on aNullNodecallsemitLoadand emits no expression info, thenm_bindings->bindValue()runs with nothing in between. That gap is precisely why the line-6102 fix was needed for arrays; the object path shares it.ObjectPatternNodeis aThrowableExpressionData(Nodes.h:2553) whose divot is set viafinishObjectPattern→setExceptionLocation(ASTBuilder.h:1072, called from Parser.cpp:1451), sodivot()/divotStart()/divotEnd()are valid and the same one-line fix applies.Step-by-step
console.log("here")emits its call; the lastemitExpressionInfopoints at line 1, column 9 (console.log).DeclarationStatement→DestructuringAssignmentNode::emitBytecoderuns.emitNode(initializer, NullNode)→emitLoad(jsNull()). No expression info emitted.m_bindings->bindValue(generator, rhs)→ObjectPatternNode::bindValue.emitRequireObjectCoercibleForDestructuring(rhs, &"a")emitsOpJnundefinedOrNull(not taken — rhs is null) thenOpThrowStaticError.throw_static_errorop's expression range is still line 1, column 9.TypeError: Cannot destructure property 'a' from null or undefined valueattest.js:1:9instead of line 2.Impact
Only line/column is wrong. Unlike the
[Symbol.iterator]get_by_idcase,OpThrowStaticErrorproduces a fixed message with no(evaluating '…')suffix, so the error text itself doesn't quote the wrong source. This is why I'm flagging it as a nit rather than blocking — it's outside the PR's stated[Symbol.iterator]/spread scope and is pre-existing behavior the PR didn't touch.Fix
Directly mirrors what this PR does for
ArrayPatternNode::bindValue.