Skip to content
Permalink
Browse files
Fix duplicated name in class static block
https://bugs.webkit.org/show_bug.cgi?id=247426
rdar://101940195

Reviewed by Mark Lam.

When parsing block statement in static block mode, we should alllow
var declaration in the block scope. This is becuase static block is
evaluated as a function call, where function scope should allow var
declaration. In this case, var variables would be bounded under the
static block scope when checking hoistable declarations in the parsing phase.

* JSTests/stress/class-static-block.js:
(foo.x):
(foo):
* Source/JavaScriptCore/parser/Parser.cpp:
(JSC::Parser<LexerType>::parseBlockStatement):
* Source/JavaScriptCore/parser/Parser.h:
(JSC::Scope::setAllowsVarDeclarations):

Canonical link: https://commits.webkit.org/256311@main
  • Loading branch information
Yijia Huang committed Nov 4, 2022
1 parent 887ce26 commit d102e7a7748f84dee8ac70af3a2147d78ed6598d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
@@ -647,3 +647,11 @@ shouldThrow(() => {
}
}
}

{
class x {
static {
var x;
}
}
}
@@ -1918,15 +1918,16 @@ template <class TreeBuilder> TreeStatement Parser<LexerType>::parseBlockStatemen
if (shouldPushLexicalScope) {
ScopeRef newScope = pushScope();
newScope->setIsLexicalScope();
newScope->preventVarDeclarations();
switch (type) {
case BlockType::CatchBlock:
newScope->setIsCatchBlockScope();
newScope->preventVarDeclarations();
break;
case BlockType::StaticBlock:
newScope->setIsStaticBlock();
break;
case BlockType::Normal:
newScope->preventVarDeclarations();
break;
default:
RELEASE_ASSERT_NOT_REACHED();

0 comments on commit d102e7a

Please sign in to comment.