Commit 3454a45f authored by wingo@igalia.com's avatar wingo@igalia.com

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
parent a05abda4
......@@ -1543,7 +1543,7 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::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<Traits>::ExpressionT ParserBase<Traits>::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);
......
......@@ -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 }
};
......
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