mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:17:35 +00:00
LibJS: Disallow member expression in binding pattern as parameters
This commit is contained in:
parent
51e23cd043
commit
156dfe3d62
2 changed files with 17 additions and 1 deletions
|
@ -2383,7 +2383,7 @@ Vector<FunctionNode::Parameter> Parser::parse_formal_parameters(int& function_le
|
||||||
Vector<FunctionNode::Parameter> parameters;
|
Vector<FunctionNode::Parameter> parameters;
|
||||||
|
|
||||||
auto consume_identifier_or_binding_pattern = [&]() -> Variant<FlyString, NonnullRefPtr<BindingPattern>> {
|
auto consume_identifier_or_binding_pattern = [&]() -> Variant<FlyString, NonnullRefPtr<BindingPattern>> {
|
||||||
if (auto pattern = parse_binding_pattern(AllowDuplicates::No, AllowMemberExpressions::Yes))
|
if (auto pattern = parse_binding_pattern(AllowDuplicates::No, AllowMemberExpressions::No))
|
||||||
return pattern.release_nonnull();
|
return pattern.release_nonnull();
|
||||||
|
|
||||||
auto token = consume_identifier();
|
auto token = consume_identifier();
|
||||||
|
@ -2635,6 +2635,8 @@ RefPtr<BindingPattern> Parser::parse_binding_pattern(Parser::AllowDuplicates all
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
consume();
|
consume();
|
||||||
|
} else if (is_object && !match(TokenType::CurlyClose)) {
|
||||||
|
consume(TokenType::Comma);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,20 @@ describe("parsing", () => {
|
||||||
expect(`const [ a, [ ...{length} ] ] = [];`).toEval();
|
expect(`const [ a, [ ...{length} ] ] = [];`).toEval();
|
||||||
expect(`let [ a, [ ...{length} ] ] = [];`).toEval();
|
expect(`let [ a, [ ...{length} ] ] = [];`).toEval();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("function parameters cannot use member expresssions", () => {
|
||||||
|
expect("function f([a.b]) {}").not.toEval();
|
||||||
|
expect("function f([b[0]]) {}").not.toEval();
|
||||||
|
|
||||||
|
expect("function f({c:a.b}) {}").not.toEval();
|
||||||
|
expect("function f({a:b[0]}) {}").not.toEval();
|
||||||
|
|
||||||
|
expect("([a.b]) => 1").not.toEval();
|
||||||
|
expect("([b[0]]) => 2").not.toEval();
|
||||||
|
|
||||||
|
expect("({c:a.b}) => 3").not.toEval();
|
||||||
|
expect("({a:b[0]}) => 4").not.toEval();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("evaluating", () => {
|
describe("evaluating", () => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue