Repository navigation
[JSC] Import and export declarations should not redeclare a var in module code - #77373
Merged
Conversation
Collaborator
|
EWS run on current version of this PR (hash b2b479c) Details |
robobun
added a commit
to oven-sh/WebKit
that referenced
this pull request
Oct 20, 2026
…dule code The Parser.cpp change is the one of WebKit#77373 (b2b479c, https://bugs.webkit.org/show_bug.cgi?id=327927), unchanged. The test is new. It is a Syntax Error if a LexicallyDeclaredName of a module also occurs in its VarDeclaredNames, but JSC accepted a module when the var came first: var x; import { y as x } from "./m.js"; var x; export let x; var x; export class x { } Builds with assertions then hit ASSERT(symbolTableEntry.isNull()) in BytecodeGenerator::instantiateLexicalVariables. Release builds ran the module with the slot of the var. This module crashed them on a read of the empty value: if (globalThis.c) var p = 2; import * as p from "./m.js"; let t = typeof p; Parser::declareVariable compares a lexical name with the vars only when m_statementDepth is 1, and import and export declarations were parsed at depth 0. They are now parsed at depth 1, the depth of a top-level statement. The four places that set the depth to 1 for an exported function declaration are no longer needed. * JSTests/stress/modules-syntax-error-var-then-import-or-export.js: Added. * Source/JavaScriptCore/parser/Parser.cpp: (JSC::Parser<LexerType>::parseImportDeclaration): (JSC::Parser<LexerType>::parseExportDeclaration): Co-authored-by: Sosuke Suzuki <[email protected]>
Constellation
approved these changes
Oct 20, 2026
…dule code https://bugs.webkit.org/show_bug.cgi?id=327927 Reviewed by Yusuke Suzuki. It is a Syntax Error if a LexicallyDeclaredName of a module also occurs in its VarDeclaredNames [1], but JSC accepted the following when the var came first. var x; import { y as x } from "./m.js"; var x; export let x; var x; export class x { } Debug builds then hit ASSERT(symbolTableEntry.isNull()) in BytecodeGenerator::instantiateLexicalVariables. Parser::declareVariable compares a lexical name with vars only when m_statementDepth is 1, and import and export declarations were parsed at depth 0. This patch parses them at depth 1, the depth of top-level statements, by incrementing it in parseImportDeclaration and parseExportDeclaration as parseStatementListItem does. Setting the depth to 1 only for exported function declarations is no longer needed. [1]: https://tc39.es/ecma262/#sec-module-semantics-static-semantics-early-errors Tests: JSTests/stress/bigint-to-string-divide-and-conquer-large.js JSTests/stress/modules-syntax-error-import-and-export-declarations-after-var.js * JSTests/stress/bigint-to-string-divide-and-conquer-large.js: Added. (shouldBe): * JSTests/stress/modules-syntax-error-import-and-export-declarations-after-var.js: Added. (shouldThrowModuleSyntaxError): (export.x): (export.async x): (export.default.x): (export.default.async x): (const.declaration.of.declarations.const.statement.of.f): (export.default): (export.C): (export.let.y): * JSTests/stress/modules-syntax-error-with-names.js: * Source/JavaScriptCore/parser/Parser.cpp: (JSC::Parser<LexerType>::parseImportDeclaration): (JSC::Parser<LexerType>::parseExportDeclaration): Canonical link: https://commits.webkit.org/324223@main
webkit-commit-queue
force-pushed
the
eng/import-and-export-declarations-should-not-redeclare-a-var-in-module-code
branch
from
October 20, 2026 11:04
b2b479c to
f88678d
Compare
Collaborator
|
Committed 324223@main (f88678d): https://commits.webkit.org/324223@main Reviewed commits have been landed. Closing PR #77373 and removing active labels. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
f88678d
b2b479c