Commit 56e07b4a authored by Caitlin Potter's avatar Caitlin Potter Committed by Commit Bot

[parser] don't treat SuperCall as a valid DestructuringAssignmentTarget

BUG=v8:6291, v8:811
R=marja@chromium.org, vogelheim@chromium.org

Change-Id: I978ea446d7b42092592b0a3ae3c99626e36d40fd
Reviewed-on: https://chromium-review.googlesource.com/485099
Commit-Queue: Caitlin Potter <caitp@igalia.com>
Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Reviewed-by: 's avatarDaniel Vogelheim <vogelheim@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44819}
parent 68235eb9
......@@ -3302,6 +3302,9 @@ ParserBase<Impl>::ParseLeftHandSideExpression(bool* ok) {
// Explicit calls to the super constructor using super() perform an
// implicit binding assignment to the 'this' variable.
if (is_super_call) {
classifier()->RecordAssignmentPatternError(
Scanner::Location(pos, scanner()->location().end_pos),
MessageTemplate::kInvalidDestructuringTarget);
ExpressionT this_expr = impl()->ThisExpression(pos);
result =
factory()->NewAssignment(Token::INIT, this_expr, result, pos);
......
......@@ -533,3 +533,38 @@ assertEquals(oz, [1, 2, 3, 4, 5]);
assertEquals(FakeNewTarget,
Reflect.construct(ReturnNewTarget4, [], FakeNewTarget));
})();
(function testSuperCall() {
function ctor(body) {
return () => eval("(class extends Object { \n" +
" constructor() {\n" +
body +
"\n }\n" +
"})");
}
assertThrows(ctor("({ new: super() } = {})"), SyntaxError);
assertThrows(ctor("({ new: x } = { new: super() } = {})"), SyntaxError);
assertThrows(ctor("[super()] = []"), SyntaxError);
assertThrows(ctor("[x] = [super()] = []"), SyntaxError);
assertThrows(ctor("[...super()] = []"), SyntaxError);
assertThrows(ctor("[x] = [...super()] = []"), SyntaxError);
class Base { get foo() { return 1; } }
function ext(body) {
return eval("new (class extends Base {\n" +
" constructor() {\n" +
body + ";\n" +
" return { x: super.foo }" +
"\n }\n" +
"})");
}
assertEquals(1, ext("let x; [x = super()] = []").x);
assertEquals(1, ext("let x, y; [y] = [x = super()] = []").x);
assertEquals(1, ext("let x; [x] = [super()]").x);
assertEquals(1, ext("let x, y; [y] = [x] = [super()]").x);
assertEquals(1, ext("let x; ({x = super()} = {})").x);
assertEquals(1, ext("let x, y; ({ x: y } = { x = super() } = {})").x);
assertEquals(1, ext("let x; ({x} = { x: super() })").x);
assertEquals(1, ext("let x, y; ({ x: y } = { x } = { x: super() })").x);
})();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment