Skip to content
Permalink
Browse files
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 598cda65c4a2c2af24667bc86fdc1ed5cbafec23
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
@@ -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);
}
@@ -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");

0 comments on commit 598cda6

Please sign in to comment.