Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix in operator inside for statement destructuring
https://bugs.webkit.org/show_bug.cgi?id=247436
rdar://102065296

Reviewed by Alexey Shvayka.

Destructing statement should allow `in` operator even in `for...in/of`.

* JSTests/stress/destructing-in.js: Added.
(shouldBe):
* Source/JavaScriptCore/parser/Parser.cpp:
(JSC::Parser<LexerType>::parseVariableDeclarationList):

Canonical link: https://commits.webkit.org/256497@main
  • Loading branch information
Yijia Huang committed Nov 9, 2022
1 parent 6a2efe7 commit 598cda6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
20 changes: 20 additions & 0 deletions JSTests/stress/destructing-in.js
@@ -0,0 +1,20 @@
function shouldBe(actual, expected) {
if (actual !== expected)
throw new Error('bad value: ' + actual);
}

for (var { x = 0 in [0] } of [0]) {
shouldBe(x, true);
}

for (var { x = (0 in [0]) } of [0]) {
shouldBe(x, true);
}

for (var { x = 0 in [0] } in [0]) {
shouldBe(x, true);
}

for (var { x = (0 in [0]) } in [0]) {
shouldBe(x, true);
}
7 changes: 6 additions & 1 deletion Source/JavaScriptCore/parser/Parser.cpp
Expand Up @@ -952,7 +952,12 @@ template <class TreeBuilder> TreeExpression Parser<LexerType>::parseVariableDecl
}
} else {
lastIdent = nullptr;
auto pattern = parseDestructuringPattern(context, destructuringKindFromDeclarationType(declarationType), exportType, nullptr, nullptr, assignmentContext);
TreeDestructuringPattern pattern;
{
bool allowsInOperator = true;
SetForScope allowsInScope(m_allowsIn, allowsInOperator);
pattern = parseDestructuringPattern(context, destructuringKindFromDeclarationType(declarationType), exportType, nullptr, nullptr, assignmentContext);
}
failIfFalse(pattern, "Cannot parse this destructuring pattern");
hasInitializer = match(EQUAL);
failIfTrue(declarationListContext == VarDeclarationContext && !hasInitializer, "Expected an initializer in destructuring variable declaration");
Expand Down

0 comments on commit 598cda6

Please sign in to comment.