Reviewers: rossberg, wingo, adamk (ooo until sept 8), aperez,

Message:
PTAL, quick bugfix for reported issue with shorthand properties. Super simple
stuff.

Description:
[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

Please review this at https://codereview.chromium.org/1328083002/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+21, -1 lines):
  M src/preparser.h
  M test/cctest/test-parsing.cc
  M test/mjsunit/es6/object-literals-property-shorthand.js
  M test/mjsunit/harmony/destructuring.js


Index: src/preparser.h
diff --git a/src/preparser.h b/src/preparser.h
index 4f710fb65a7301543da44fa206300506d9afd255..5160b311af23d05ebd12f73102fff9e573c2fb8f 100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -2607,6 +2607,14 @@ ParserBase<Traits>::ParsePropertyDefinition(
&name, &is_get, &is_set, &name_is_static, is_computed_name, classifier,
       CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));

+  if (!in_class && (is_get || is_set) &&
+      (peek() == Token::RBRACE || peek() == Token::COMMA ||
+       peek() == Token::ASSIGN)) {
+    // Special-case `get` / `set` as shorthand property names
+    DCHECK(this->IsIdentifier(name));
+    is_get = is_set = false;
+  }
+
   if (fni_ != nullptr && !*is_computed_name) {
     this->PushLiteralName(fni_, name);
   }
Index: test/cctest/test-parsing.cc
diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc
index a05e0e15d6687d26f0e42b6581882db2a1d5a21d..fb7d4d36f46952381744ed8b3068f2685f6558cf 100644
--- a/test/cctest/test-parsing.cc
+++ b/test/cctest/test-parsing.cc
@@ -6479,6 +6479,8 @@ TEST(DestructuringPositiveTests) {
     "a",
     "{ x : y }",
     "{ x : y = 1 }",
+    "{ get, set }",
+    "{ get = 1, set = 2 }",
     "[a]",
     "[a = 1]",
     "[a,b,c]",
Index: test/mjsunit/es6/object-literals-property-shorthand.js
diff --git a/test/mjsunit/es6/object-literals-property-shorthand.js b/test/mjsunit/es6/object-literals-property-shorthand.js index 29ce66d270839e861751b7f0205ef74712bc58f5..f0ddd68d42aad0bc3edaed5177edf98fb519d0e1 100644
--- a/test/mjsunit/es6/object-literals-property-shorthand.js
+++ b/test/mjsunit/es6/object-literals-property-shorthand.js
@@ -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() {
   var x = 1;
   var object = {x};
Index: test/mjsunit/harmony/destructuring.js
diff --git a/test/mjsunit/harmony/destructuring.js b/test/mjsunit/harmony/destructuring.js index 703e521912eb2b6bee292c9271142fa08028c477..f1e2210a2abb2d3b97ca6532d9b28191666ec79c 100644
--- a/test/mjsunit/harmony/destructuring.js
+++ b/test/mjsunit/harmony/destructuring.js
@@ -6,9 +6,11 @@
 // Flags: --harmony-default-parameters --harmony-rest-parameters

 (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(2, y);
+  assertEquals(3, get);
+  assertEquals(4, set);

   var {z} = { z : 3 };
   assertEquals(3, z);


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to