Skip to content

Commit

Permalink
Cherry-pick d102e7a. rdar://problem/101940195
Browse files Browse the repository at this point in the history
    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

Canonical link: https://commits.webkit.org/256138.58@safari-7615.1.12-branch
  • Loading branch information
Yijia Huang authored and alancoon committed Nov 14, 2022
1 parent 2751352 commit 5737ac0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions JSTests/stress/class-static-block.js
Expand Up @@ -647,3 +647,11 @@ shouldThrow(() => {
}
}
}

{
class x {
static {
var x;
}
}
}
3 changes: 2 additions & 1 deletion Source/JavaScriptCore/parser/Parser.cpp
Expand Up @@ -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();
Expand Down

0 comments on commit 5737ac0

Please sign in to comment.