Commit 5058f685 authored by caitpotter88's avatar caitpotter88 Committed by Commit bot

[parser] treat MethodDefinitions in ObjectPatterns as SyntaxErrors

BUG=v8:4585
LOG=N
R=adamk@chromium.org, rossberg@chromium.org

Review URL: https://codereview.chromium.org/1488043002

Cr-Commit-Position: refs/heads/master@{#32477}
parent d2f78c6b
...@@ -2737,6 +2737,8 @@ ParserBase<Traits>::ParsePropertyDefinition( ...@@ -2737,6 +2737,8 @@ ParserBase<Traits>::ParsePropertyDefinition(
return this->EmptyObjectLiteralProperty(); return this->EmptyObjectLiteralProperty();
} }
BindingPatternUnexpectedToken(classifier);
if (is_generator || peek() == Token::LPAREN) { if (is_generator || peek() == Token::LPAREN) {
// MethodDefinition // MethodDefinition
// PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}' // PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}'
......
...@@ -6715,6 +6715,10 @@ TEST(DestructuringNegativeTests) { ...@@ -6715,6 +6715,10 @@ TEST(DestructuringNegativeTests) {
"{ x : 'foo' }", "{ x : 'foo' }",
"{ x : /foo/ }", "{ x : /foo/ }",
"{ x : `foo` }", "{ x : `foo` }",
"{ get a() {} }",
"{ set a() {} }",
"{ method() {} }",
"{ *method() {} }",
NULL}; NULL};
// clang-format on // clang-format on
RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
......
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-destructuring-bind
assertThrows(`for(const { method() {} } = this) {}`, SyntaxError);
assertThrows(`var { method() {} } = this;`, SyntaxError);
assertThrows(`for(const { *method() {} } = this) {}`, SyntaxError);
assertThrows(`var { *method() {} } = this;`, SyntaxError);
assertThrows(`for(var { get foo() {} } = this) {}`, SyntaxError);
assertThrows(`for(var { set foo() {} } = this) {}`, SyntaxError);
// Still OK in other objects
for (var { name = "" + { toString() { return "test" } } } in { a: 1}) break;
assertEquals(name, "test");
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