Commit b444da41 authored by caitpotter88's avatar caitpotter88 Committed by Commit bot

[es6] support `get` and `set` in shorthand properties

Add support for `get` and `set` as shorthand properties. Also
supports them for CoverInitializedName in BindingPatterns and (once implemented)
AssignmentPatterns.

BUG=v8:4412, v8:3584
LOG=N
R=adamk, aperez, wingo, rossberg

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

Cr-Commit-Position: refs/heads/master@{#30769}
parent afba4792
...@@ -2655,7 +2655,9 @@ ParserBase<Traits>::ParsePropertyDefinition( ...@@ -2655,7 +2655,9 @@ ParserBase<Traits>::ParsePropertyDefinition(
// static MethodDefinition // static MethodDefinition
return ParsePropertyDefinition(checker, true, has_extends, true, return ParsePropertyDefinition(checker, true, has_extends, true,
is_computed_name, nullptr, classifier, ok); is_computed_name, nullptr, classifier, ok);
} else if (is_get || is_set) { } else if ((is_get || is_set) &&
(in_class || (peek() != Token::RBRACE && peek() != Token::COMMA &&
peek() != Token::ASSIGN))) {
// Accessor // Accessor
name = this->EmptyIdentifier(); name = this->EmptyIdentifier();
bool dont_care = false; bool dont_care = false;
......
...@@ -6541,6 +6541,8 @@ TEST(DestructuringPositiveTests) { ...@@ -6541,6 +6541,8 @@ TEST(DestructuringPositiveTests) {
"a", "a",
"{ x : y }", "{ x : y }",
"{ x : y = 1 }", "{ x : y = 1 }",
"{ get, set }",
"{ get = 1, set = 2 }",
"[a]", "[a]",
"[a = 1]", "[a = 1]",
"[a,b,c]", "[a,b,c]",
......
...@@ -10,6 +10,14 @@ ...@@ -10,6 +10,14 @@
})(); })();
(function TestBasicsGetSet() {
var get = 1, set = 2;
var object = {get, set};
assertEquals(1, object.get);
assertEquals(2, object.set);
})();
(function TestDescriptor() { (function TestDescriptor() {
var x = 1; var x = 1;
var object = {x}; var object = {x};
......
...@@ -6,9 +6,11 @@ ...@@ -6,9 +6,11 @@
// Flags: --harmony-default-parameters --harmony-rest-parameters // Flags: --harmony-default-parameters --harmony-rest-parameters
(function TestObjectLiteralPattern() { (function TestObjectLiteralPattern() {
var { x : x, y : y } = { x : 1, y : 2 }; var { x : x, y : y, get, set } = { x : 1, y : 2, get: 3, set: 4 };
assertEquals(1, x); assertEquals(1, x);
assertEquals(2, y); assertEquals(2, y);
assertEquals(3, get);
assertEquals(4, set);
var {z} = { z : 3 }; var {z} = { z : 3 };
assertEquals(3, z); assertEquals(3, z);
......
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