From 3454a45f5dcb6b803e5ef6ac338aa48b35b739d2 Mon Sep 17 00:00:00 2001 From: "wingo@igalia.com" Date: Wed, 25 Jun 2014 10:13:10 +0000 Subject: [PATCH] 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. R=marja@chromium.org BUG= Review URL: https://codereview.chromium.org/350353002 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22005 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/preparser.h | 3 +-- test/cctest/test-parsing.cc | 5 +++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/preparser.h b/src/preparser.h index 753ff1b..499240e 100644 --- a/src/preparser.h +++ b/src/preparser.h @@ -1543,7 +1543,7 @@ typename ParserBase::ExpressionT ParserBase::ParseObjectLiteral( // ((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 @@ typename ParserBase::ExpressionT ParserBase::ParseObjectLiteral( } 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); diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc index 858354d..857089e 100644 --- a/test/cctest/test-parsing.cc +++ b/test/cctest/test-parsing.cc @@ -2240,10 +2240,12 @@ TEST(ErrorsNewExpression) { 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 @@ TEST(ErrorsObjectLiteralChecking) { }; const char* statement_data[] = { + ",", "foo: 1, get foo() {}", "foo: 1, set foo(v) {}", "\"foo\": 1, get \"foo\"() {}", @@ -2307,7 +2310,9 @@ TEST(ErrorsObjectLiteralChecking) { TEST(NoErrorsObjectLiteralChecking) { const char* context_data[][2] = { {"var myobject = {", "};"}, + {"var myobject = {", ",};"}, {"\"use strict\"; var myobject = {", "};"}, + {"\"use strict\"; var myobject = {", ",};"}, { NULL, NULL } }; -- 2.7.4