Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(458)

Side by Side Diff: test/cctest/test-parsing.cc

Issue 477263002: ES6: Add support for method shorthand in object literals (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: merge Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/x87/lithium-codegen-x87.cc ('k') | test/mjsunit/harmony/object-literals-method.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1210 1210
1211 1211
1212 enum ParserFlag { 1212 enum ParserFlag {
1213 kAllowLazy, 1213 kAllowLazy,
1214 kAllowNativesSyntax, 1214 kAllowNativesSyntax,
1215 kAllowHarmonyScoping, 1215 kAllowHarmonyScoping,
1216 kAllowModules, 1216 kAllowModules,
1217 kAllowGenerators, 1217 kAllowGenerators,
1218 kAllowHarmonyNumericLiterals, 1218 kAllowHarmonyNumericLiterals,
1219 kAllowArrowFunctions, 1219 kAllowArrowFunctions,
1220 kAllowClasses 1220 kAllowClasses,
1221 kAllowHarmonyObjectLiterals
1221 }; 1222 };
1222 1223
1223 1224
1224 enum ParserSyncTestResult { 1225 enum ParserSyncTestResult {
1225 kSuccessOrError, 1226 kSuccessOrError,
1226 kSuccess, 1227 kSuccess,
1227 kError 1228 kError
1228 }; 1229 };
1229 1230
1230 template <typename Traits> 1231 template <typename Traits>
1231 void SetParserFlags(i::ParserBase<Traits>* parser, 1232 void SetParserFlags(i::ParserBase<Traits>* parser,
1232 i::EnumSet<ParserFlag> flags) { 1233 i::EnumSet<ParserFlag> flags) {
1233 parser->set_allow_lazy(flags.Contains(kAllowLazy)); 1234 parser->set_allow_lazy(flags.Contains(kAllowLazy));
1234 parser->set_allow_natives_syntax(flags.Contains(kAllowNativesSyntax)); 1235 parser->set_allow_natives_syntax(flags.Contains(kAllowNativesSyntax));
1235 parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping)); 1236 parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping));
1236 parser->set_allow_modules(flags.Contains(kAllowModules)); 1237 parser->set_allow_modules(flags.Contains(kAllowModules));
1237 parser->set_allow_generators(flags.Contains(kAllowGenerators)); 1238 parser->set_allow_generators(flags.Contains(kAllowGenerators));
1238 parser->set_allow_harmony_numeric_literals( 1239 parser->set_allow_harmony_numeric_literals(
1239 flags.Contains(kAllowHarmonyNumericLiterals)); 1240 flags.Contains(kAllowHarmonyNumericLiterals));
1241 parser->set_allow_harmony_object_literals(
1242 flags.Contains(kAllowHarmonyObjectLiterals));
1240 parser->set_allow_arrow_functions(flags.Contains(kAllowArrowFunctions)); 1243 parser->set_allow_arrow_functions(flags.Contains(kAllowArrowFunctions));
1241 parser->set_allow_classes(flags.Contains(kAllowClasses)); 1244 parser->set_allow_classes(flags.Contains(kAllowClasses));
1242 } 1245 }
1243 1246
1244 1247
1245 void TestParserSyncWithFlags(i::Handle<i::String> source, 1248 void TestParserSyncWithFlags(i::Handle<i::String> source,
1246 i::EnumSet<ParserFlag> flags, 1249 i::EnumSet<ParserFlag> flags,
1247 ParserSyncTestResult result) { 1250 ParserSyncTestResult result) {
1248 i::Isolate* isolate = CcTest::i_isolate(); 1251 i::Isolate* isolate = CcTest::i_isolate();
1249 i::Factory* factory = isolate->factory(); 1252 i::Factory* factory = isolate->factory();
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
1439 NULL 1442 NULL
1440 }; 1443 };
1441 1444
1442 v8::HandleScope handles(CcTest::isolate()); 1445 v8::HandleScope handles(CcTest::isolate());
1443 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); 1446 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate());
1444 v8::Context::Scope context_scope(context); 1447 v8::Context::Scope context_scope(context);
1445 1448
1446 CcTest::i_isolate()->stack_guard()->SetStackLimit( 1449 CcTest::i_isolate()->stack_guard()->SetStackLimit(
1447 i::GetCurrentStackPosition() - 128 * 1024); 1450 i::GetCurrentStackPosition() - 128 * 1024);
1448 1451
1449 static const ParserFlag flags1[] = {kAllowLazy, kAllowHarmonyScoping, 1452 static const ParserFlag flags1[] = {
1450 kAllowModules, kAllowGenerators, 1453 kAllowLazy, kAllowHarmonyScoping,
1451 kAllowArrowFunctions}; 1454 kAllowModules, kAllowGenerators,
1455 kAllowArrowFunctions, kAllowHarmonyNumericLiterals,
1456 kAllowHarmonyObjectLiterals};
1452 for (int i = 0; context_data[i][0] != NULL; ++i) { 1457 for (int i = 0; context_data[i][0] != NULL; ++i) {
1453 for (int j = 0; statement_data[j] != NULL; ++j) { 1458 for (int j = 0; statement_data[j] != NULL; ++j) {
1454 for (int k = 0; termination_data[k] != NULL; ++k) { 1459 for (int k = 0; termination_data[k] != NULL; ++k) {
1455 int kPrefixLen = i::StrLength(context_data[i][0]); 1460 int kPrefixLen = i::StrLength(context_data[i][0]);
1456 int kStatementLen = i::StrLength(statement_data[j]); 1461 int kStatementLen = i::StrLength(statement_data[j]);
1457 int kTerminationLen = i::StrLength(termination_data[k]); 1462 int kTerminationLen = i::StrLength(termination_data[k]);
1458 int kSuffixLen = i::StrLength(context_data[i][1]); 1463 int kSuffixLen = i::StrLength(context_data[i][1]);
1459 int kProgramSize = kPrefixLen + kStatementLen + kTerminationLen 1464 int kProgramSize = kPrefixLen + kStatementLen + kTerminationLen
1460 + kSuffixLen + i::StrLength("label: for (;;) { }"); 1465 + kSuffixLen + i::StrLength("label: for (;;) { }");
1461 1466
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1516 const ParserFlag* always_true_flags = NULL, 1521 const ParserFlag* always_true_flags = NULL,
1517 int always_true_flags_len = 0) { 1522 int always_true_flags_len = 0) {
1518 v8::HandleScope handles(CcTest::isolate()); 1523 v8::HandleScope handles(CcTest::isolate());
1519 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); 1524 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate());
1520 v8::Context::Scope context_scope(context); 1525 v8::Context::Scope context_scope(context);
1521 1526
1522 CcTest::i_isolate()->stack_guard()->SetStackLimit( 1527 CcTest::i_isolate()->stack_guard()->SetStackLimit(
1523 i::GetCurrentStackPosition() - 128 * 1024); 1528 i::GetCurrentStackPosition() - 128 * 1024);
1524 1529
1525 static const ParserFlag default_flags[] = { 1530 static const ParserFlag default_flags[] = {
1526 kAllowLazy, kAllowHarmonyScoping, kAllowModules, 1531 kAllowArrowFunctions, kAllowClasses,
1527 kAllowGenerators, kAllowNativesSyntax, kAllowArrowFunctions, 1532 kAllowGenerators, kAllowHarmonyNumericLiterals,
1528 kAllowClasses}; 1533 kAllowHarmonyObjectLiterals, kAllowHarmonyScoping,
1534 kAllowLazy, kAllowModules,
1535 kAllowNativesSyntax,
1536 };
1529 ParserFlag* generated_flags = NULL; 1537 ParserFlag* generated_flags = NULL;
1530 if (flags == NULL) { 1538 if (flags == NULL) {
1531 flags = default_flags; 1539 flags = default_flags;
1532 flags_len = arraysize(default_flags); 1540 flags_len = arraysize(default_flags);
1533 if (always_true_flags != NULL) { 1541 if (always_true_flags != NULL) {
1534 // Remove always_true_flags from default_flags. 1542 // Remove always_true_flags from default_flags.
1535 CHECK(always_true_flags_len < flags_len); 1543 CHECK(always_true_flags_len < flags_len);
1536 generated_flags = new ParserFlag[flags_len - always_true_flags_len]; 1544 generated_flags = new ParserFlag[flags_len - always_true_flags_len];
1537 int flag_index = 0; 1545 int flag_index = 0;
1538 for (int i = 0; i < flags_len; ++i) { 1546 for (int i = 0; i < flags_len; ++i) {
(...skipping 974 matching lines...) Expand 10 before | Expand all | Expand 10 after
2513 2521
2514 2522
2515 TEST(ErrorsObjectLiteralChecking) { 2523 TEST(ErrorsObjectLiteralChecking) {
2516 const char* context_data[][2] = { 2524 const char* context_data[][2] = {
2517 {"\"use strict\"; var myobject = {", "};"}, 2525 {"\"use strict\"; var myobject = {", "};"},
2518 {"var myobject = {", "};"}, 2526 {"var myobject = {", "};"},
2519 { NULL, NULL } 2527 { NULL, NULL }
2520 }; 2528 };
2521 2529
2522 const char* statement_data[] = { 2530 const char* statement_data[] = {
2523 ",", "foo: 1, get foo() {}", "foo: 1, set foo(v) {}", 2531 ",",
2524 "\"foo\": 1, get \"foo\"() {}", "\"foo\": 1, set \"foo\"(v) {}", 2532 "foo: 1, get foo() {}",
2525 "1: 1, get 1() {}", "1: 1, set 1() {}", 2533 "foo: 1, set foo(v) {}",
2534 "\"foo\": 1, get \"foo\"() {}",
2535 "\"foo\": 1, set \"foo\"(v) {}",
2536 "1: 1, get 1() {}",
2537 "1: 1, set 1() {}",
2538 "get foo() {}, get foo() {}",
2539 "set foo(_) {}, set foo(_) {}",
2526 // It's counter-intuitive, but these collide too (even in classic 2540 // It's counter-intuitive, but these collide too (even in classic
2527 // mode). Note that we can have "foo" and foo as properties in classic 2541 // mode). Note that we can have "foo" and foo as properties in classic
2528 // mode, 2542 // mode,
2529 // but we cannot have "foo" and get foo, or foo and get "foo". 2543 // but we cannot have "foo" and get foo, or foo and get "foo".
2530 "foo: 1, get \"foo\"() {}", "foo: 1, set \"foo\"(v) {}", 2544 "foo: 1, get \"foo\"() {}",
2531 "\"foo\": 1, get foo() {}", "\"foo\": 1, set foo(v) {}", 2545 "foo: 1, set \"foo\"(v) {}",
2532 "1: 1, get \"1\"() {}", "1: 1, set \"1\"() {}", 2546 "\"foo\": 1, get foo() {}",
2547 "\"foo\": 1, set foo(v) {}",
2548 "1: 1, get \"1\"() {}",
2549 "1: 1, set \"1\"() {}",
2533 "\"1\": 1, get 1() {}" 2550 "\"1\": 1, get 1() {}"
2534 "\"1\": 1, set 1(v) {}" 2551 "\"1\": 1, set 1(v) {}"
2535 // Wrong number of parameters 2552 // Wrong number of parameters
2536 "get bar(x) {}", 2553 "get bar(x) {}",
2537 "get bar(x, y) {}", "set bar() {}", "set bar(x, y) {}", 2554 "get bar(x, y) {}",
2555 "set bar() {}",
2556 "set bar(x, y) {}",
2538 // Parsing FunctionLiteral for getter or setter fails 2557 // Parsing FunctionLiteral for getter or setter fails
2539 "get foo( +", "get foo() \"error\"", NULL}; 2558 "get foo( +",
2559 "get foo() \"error\"",
2560 NULL};
2540 2561
2541 RunParserSyncTest(context_data, statement_data, kError); 2562 RunParserSyncTest(context_data, statement_data, kError);
2542 } 2563 }
2543 2564
2544 2565
2545 TEST(NoErrorsObjectLiteralChecking) { 2566 TEST(NoErrorsObjectLiteralChecking) {
2546 const char* context_data[][2] = { 2567 const char* context_data[][2] = {
2547 {"var myobject = {", "};"}, 2568 {"var myobject = {", "};"},
2548 {"var myobject = {", ",};"}, 2569 {"var myobject = {", ",};"},
2549 {"\"use strict\"; var myobject = {", "};"}, 2570 {"\"use strict\"; var myobject = {", "};"},
(...skipping 16 matching lines...) Expand all
2566 "set foo(v) {}", 2587 "set foo(v) {}",
2567 "set \"foo\"(v) {}", 2588 "set \"foo\"(v) {}",
2568 "set 1(v) {}", 2589 "set 1(v) {}",
2569 // Non-colliding getters and setters -> no errors 2590 // Non-colliding getters and setters -> no errors
2570 "foo: 1, get bar() {}", 2591 "foo: 1, get bar() {}",
2571 "foo: 1, set bar(v) {}", 2592 "foo: 1, set bar(v) {}",
2572 "\"foo\": 1, get \"bar\"() {}", 2593 "\"foo\": 1, get \"bar\"() {}",
2573 "\"foo\": 1, set \"bar\"(v) {}", 2594 "\"foo\": 1, set \"bar\"(v) {}",
2574 "1: 1, get 2() {}", 2595 "1: 1, get 2() {}",
2575 "1: 1, set 2(v) {}", 2596 "1: 1, set 2(v) {}",
2597 "get: 1, get foo() {}",
2598 "set: 1, set foo(_) {}",
2576 // Keywords, future reserved and strict future reserved are also allowed as 2599 // Keywords, future reserved and strict future reserved are also allowed as
2577 // property names. 2600 // property names.
2578 "if: 4", 2601 "if: 4",
2579 "interface: 5", 2602 "interface: 5",
2580 "super: 6", 2603 "super: 6",
2581 "eval: 7", 2604 "eval: 7",
2582 "arguments: 8", 2605 "arguments: 8",
2583 NULL 2606 NULL
2584 }; 2607 };
2585 2608
(...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after
3385 const char* statement_data[] = { 3408 const char* statement_data[] = {
3386 "super = x", 3409 "super = x",
3387 "y = super", 3410 "y = super",
3388 "f(super)", 3411 "f(super)",
3389 NULL}; 3412 NULL};
3390 3413
3391 static const ParserFlag always_flags[] = {kAllowClasses}; 3414 static const ParserFlag always_flags[] = {kAllowClasses};
3392 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, 3415 RunParserSyncTest(context_data, statement_data, kError, NULL, 0,
3393 always_flags, arraysize(always_flags)); 3416 always_flags, arraysize(always_flags));
3394 } 3417 }
3418
3419
3420 TEST(NoErrorsMethodDefinition) {
3421 const char* context_data[][2] = {{"({", "});"},
3422 {"'use strict'; ({", "});"},
3423 {NULL, NULL}};
3424
3425 const char* object_literal_body_data[] = {
3426 "m() {}",
3427 "m(x) { return x; }",
3428 "m(x, y) {}, n() {}",
3429 "set(x, y) {}",
3430 "get(x, y) {}",
3431 NULL
3432 };
3433
3434 static const ParserFlag always_flags[] = {kAllowHarmonyObjectLiterals};
3435 RunParserSyncTest(context_data, object_literal_body_data, kSuccess, NULL, 0,
3436 always_flags, arraysize(always_flags));
3437 }
3438
3439
3440 TEST(MethodDefinitionNames) {
3441 const char* context_data[][2] = {{"({", "(x, y) {}});"},
3442 {"'use strict'; ({", "(x, y) {}});"},
3443 {NULL, NULL}};
3444
3445 const char* name_data[] = {
3446 "m",
3447 "'m'",
3448 "\"m\"",
3449 "\"m n\"",
3450 "true",
3451 "false",
3452 "null",
3453 "0",
3454 "1.2",
3455 "1e1",
3456 "1E1",
3457 "1e+1",
3458 "1e-1",
3459
3460 // Keywords
3461 "async",
3462 "await",
3463 "break",
3464 "case",
3465 "catch",
3466 "class",
3467 "const",
3468 "continue",
3469 "debugger",
3470 "default",
3471 "delete",
3472 "do",
3473 "else",
3474 "enum",
3475 "export",
3476 "extends",
3477 "finally",
3478 "for",
3479 "function",
3480 "if",
3481 "implements",
3482 "import",
3483 "in",
3484 "instanceof",
3485 "interface",
3486 "let",
3487 "new",
3488 "package",
3489 "private",
3490 "protected",
3491 "public",
3492 "return",
3493 "static",
3494 "super",
3495 "switch",
3496 "this",
3497 "throw",
3498 "try",
3499 "typeof",
3500 "var",
3501 "void",
3502 "while",
3503 "with",
3504 "yield",
3505 NULL
3506 };
3507
3508 static const ParserFlag always_flags[] = {kAllowHarmonyObjectLiterals};
3509 RunParserSyncTest(context_data, name_data, kSuccess, NULL, 0,
3510 always_flags, arraysize(always_flags));
3511 }
3512
3513
3514 TEST(MethodDefinitionStrictFormalParamereters) {
3515 const char* context_data[][2] = {{"({method(", "){}});"},
3516 {"'use strict'; ({method(", "){}});"},
3517 {NULL, NULL}};
3518
3519 const char* params_data[] = {
3520 "x, x",
3521 "x, y, x",
3522 "eval",
3523 "arguments",
3524 "var",
3525 "const",
3526 NULL
3527 };
3528
3529 static const ParserFlag always_flags[] = {kAllowHarmonyObjectLiterals};
3530 RunParserSyncTest(context_data, params_data, kError, NULL, 0,
3531 always_flags, arraysize(always_flags));
3532 }
3533
3534
3535 TEST(MethodDefinitionDuplicateProperty) {
3536 // Duplicate properties are allowed in ES6 but we haven't removed that check
3537 // yet.
3538 const char* context_data[][2] = {{"'use strict'; ({", "});"},
3539 {NULL, NULL}};
3540
3541 const char* params_data[] = {
3542 "x: 1, x() {}",
3543 "x() {}, x: 1",
3544 "x() {}, get x() {}",
3545 "x() {}, set x(_) {}",
3546 "x() {}, x() {}",
3547 "x() {}, y() {}, x() {}",
3548 "x() {}, \"x\"() {}",
3549 "x() {}, 'x'() {}",
3550 "0() {}, '0'() {}",
3551 "1.0() {}, 1: 1",
3552 NULL
3553 };
3554
3555 static const ParserFlag always_flags[] = {kAllowHarmonyObjectLiterals};
3556 RunParserSyncTest(context_data, params_data, kError, NULL, 0,
3557 always_flags, arraysize(always_flags));
3558 }
OLDNEW
« no previous file with comments | « src/x87/lithium-codegen-x87.cc ('k') | test/mjsunit/harmony/object-literals-method.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698