forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 49
JSModuleRecord::evaluate: resume suspended TLA body when a cycle sibling throws #281
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
Open
robobun
wants to merge
1
commit into
main
Choose a base branch
from
robobun/tla-cycle-sibling-throw-resume
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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
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.
🟡 nit: The new function-scope
statelocal (line 118) is shadowed by the pre-existing if-initJSValue state = ...on line 130. Both reads are correct — line 130 intentionally re-reads afterexecuteModuleProgrammay mutate the field — but renaming this one to something likeinitialState(or scoping it in its own if-init) would make it clearer that it's the pre-execution snapshot.Extended reasoning...
What
The PR introduces
JSValue state = internalField(Field::State).get();at function scope on line 118 ofJSModuleRecord::evaluate. A few lines below, the pre-existing code on line 130 has:if (JSValue state = internalField(Field::State).get(); !state.isNumber() || ...)which declares a second
statein the C++17 if-init scope, shadowing the outer one added by this PR.Why it's only a nit
Both reads are semantically correct and intentionally distinct:
executeModuleProgramruns, to decide whether theevaluationError()early-return applies (only when the body is still inState::Init).executeModuleProgramreturns, because the interpreter mutatesField::Stateduring execution (e.g. toExecutingon completion, or a suspend index onawait). Reusing the outerstatehere would be wrong — it holds a stale pre-execution value — so the re-read is required regardless of naming.There is no build impact: JavaScriptCore does not compile with
-Wshadow(that flag only appears underSource/ThirdPartyfor gtest/opus/abseil/libwebrtc, andOptionsIOS.cmakeexplicitly passes-Wno-shadow). So this cannot cause a warning or failure on any supported configuration.Step-by-step
evaluate()is entered; line 118 binds outerstateto, say,jsNumber(0)(Init) or a suspend index.state— correct.executeModuleProgramruns and writes a new value intointernalField(Field::State).statebound to the fresh field value and uses it in the condition. The outerstateis shadowed but never referenced again, so behavior is unchanged.Addressing the refutation
One verifier argued this shouldn't be reported at all because scoped if-init reuse is idiomatic in this file (e.g.
execute()uses the same pattern) and JSC doesn't build with-Wshadow. That's fair — this is purely a readability suggestion, not a defect, and it should not block the PR. It's flagged only because the two reads are deliberately different snapshots of the same field within ~12 lines, and a distinct name makes that intent self-documenting.Suggested fix
Rename the new variable to
initialState(or move it into its own if-init so both declarations are equally scoped):Entirely optional.