Revision: 22005
Author:   [email protected]
Date:     Wed Jun 25 10:13:10 2014 UTC
Log:      Test that trailing commas in object literals are allowed

ES6 will allow trailing commas in object literals.  It turns out that V8
already allowed it, too, as does JSC and SpiderMonkey.

[email protected]
BUG=

Review URL: https://codereview.chromium.org/350353002
http://code.google.com/p/v8/source/detail?r=22005

Modified:
 /branches/bleeding_edge/src/preparser.h
 /branches/bleeding_edge/test/cctest/test-parsing.cc

=======================================
--- /branches/bleeding_edge/src/preparser.h     Tue Jun 24 14:03:24 2014 UTC
+++ /branches/bleeding_edge/src/preparser.h     Wed Jun 25 10:13:10 2014 UTC
@@ -1543,7 +1543,7 @@
   //       ((IdentifierName | String | Number) ':' AssignmentExpression) |
// (('get' | 'set') (IdentifierName | String | Number) FunctionLiteral)
   //      ) ',')* '}'
-  // (Except that trailing comma is not required and not allowed.)
+  // (Except that the trailing comma is not required.)

   int pos = peek_position();
   typename Traits::Type::PropertyList properties =
@@ -1674,7 +1674,6 @@
     }
     properties->Add(property, zone());

-    // TODO(1240767): Consider allowing trailing comma.
     if (peek() != Token::RBRACE) {
       // Need {} because of the CHECK_OK macro.
       Expect(Token::COMMA, CHECK_OK);
=======================================
--- /branches/bleeding_edge/test/cctest/test-parsing.cc Tue Jun 24 14:03:24 2014 UTC +++ /branches/bleeding_edge/test/cctest/test-parsing.cc Wed Jun 25 10:13:10 2014 UTC
@@ -2240,10 +2240,12 @@
 TEST(StrictObjectLiteralChecking) {
   const char* strict_context_data[][2] = {
     {"\"use strict\"; var myobject = {", "};"},
+    {"\"use strict\"; var myobject = {", ",};"},
     { NULL, NULL }
   };
   const char* non_strict_context_data[][2] = {
     {"var myobject = {", "};"},
+    {"var myobject = {", ",};"},
     { NULL, NULL }
   };

@@ -2272,6 +2274,7 @@
   };

   const char* statement_data[] = {
+    ",",
     "foo: 1, get foo() {}",
     "foo: 1, set foo(v) {}",
     "\"foo\": 1, get \"foo\"() {}",
@@ -2307,7 +2310,9 @@
 TEST(NoErrorsObjectLiteralChecking) {
   const char* context_data[][2] = {
     {"var myobject = {", "};"},
+    {"var myobject = {", ",};"},
     {"\"use strict\"; var myobject = {", "};"},
+    {"\"use strict\"; var myobject = {", ",};"},
     { NULL, NULL }
   };

--
--
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