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

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

Issue 1167393005: [destructuring] Parse binding patterns in formal parameters. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase + tests Created 5 years, 6 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
« src/parser.cc ('K') | « src/preparser.cc ('k') | no next file » | 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 6362 matching lines...) Expand 10 before | Expand all | Expand 10 after
6373 strcmp( 6373 strcmp(
6374 "ReferenceError: In strong mode, using an undeclared global " 6374 "ReferenceError: In strong mode, using an undeclared global "
6375 "variable 'not_there3' is not allowed", 6375 "variable 'not_there3' is not allowed",
6376 *exception)); 6376 *exception));
6377 } 6377 }
6378 } 6378 }
6379 6379
6380 6380
6381 TEST(DestructuringPositiveTests) { 6381 TEST(DestructuringPositiveTests) {
6382 i::FLAG_harmony_destructuring = true; 6382 i::FLAG_harmony_destructuring = true;
6383 i::FLAG_harmony_arrow_functions = true;
6383 i::FLAG_harmony_computed_property_names = true; 6384 i::FLAG_harmony_computed_property_names = true;
6384 6385
6385 const char* context_data[][2] = {{"'use strict'; let ", " = {};"}, 6386 const char* context_data[][2] = {{"'use strict'; let ", " = {};"},
6386 {"var ", " = {};"}, 6387 {"var ", " = {};"},
6387 {"'use strict'; const ", " = {};"}, 6388 {"'use strict'; const ", " = {};"},
6389 {"function f(", ") {}"},
6390 {"function f(argument1, ", ") {}"},
6391 {"var f = (", ") => {};"},
6392 {"var f = ", " => {};"},
6393 {"var f = (argument1,", ") => {};"},
6388 {NULL, NULL}}; 6394 {NULL, NULL}};
6389 6395
6390 // clang-format off 6396 // clang-format off
6391 const char* data[] = { 6397 const char* data[] = {
6392 "a", 6398 "a",
6393 "{ x : y }", 6399 "{ x : y }",
6394 "{ x : y = 1 }", 6400 "{ x : y = 1 }",
6395 "[a]", 6401 "[a]",
6396 "[a = 1]", 6402 "[a = 1]",
6397 "[a,b,c]", 6403 "[a,b,c]",
(...skipping 19 matching lines...) Expand all
6417 "{var: x = 42}", 6423 "{var: x = 42}",
6418 "{[x] : z}", 6424 "{[x] : z}",
6419 "{[1+1] : z}", 6425 "{[1+1] : z}",
6420 "{[foo()] : z}", 6426 "{[foo()] : z}",
6421 "{}", 6427 "{}",
6422 "[...rest]", 6428 "[...rest]",
6423 "[a,b,...rest]", 6429 "[a,b,...rest]",
6424 "[a,,...rest]", 6430 "[a,,...rest]",
6425 NULL}; 6431 NULL};
6426 // clang-format on 6432 // clang-format on
6427 static const ParserFlag always_flags[] = {kAllowHarmonyObjectLiterals, 6433 static const ParserFlag always_flags[] = {
6428 kAllowHarmonyComputedPropertyNames, 6434 kAllowHarmonyObjectLiterals, kAllowHarmonyComputedPropertyNames,
6429 kAllowHarmonyDestructuring}; 6435 kAllowHarmonyArrowFunctions, kAllowHarmonyDestructuring};
6430 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, 6436 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags,
6431 arraysize(always_flags)); 6437 arraysize(always_flags));
6432 } 6438 }
6433 6439
6434 6440
6435 TEST(DestructuringNegativeTests) { 6441 TEST(DestructuringNegativeTests) {
6436 i::FLAG_harmony_destructuring = true; 6442 i::FLAG_harmony_destructuring = true;
6443 i::FLAG_harmony_arrow_functions = true;
6437 i::FLAG_harmony_computed_property_names = true; 6444 i::FLAG_harmony_computed_property_names = true;
6438 static const ParserFlag always_flags[] = {kAllowHarmonyObjectLiterals, 6445 static const ParserFlag always_flags[] = {
6439 kAllowHarmonyComputedPropertyNames, 6446 kAllowHarmonyObjectLiterals, kAllowHarmonyComputedPropertyNames,
6440 kAllowHarmonyDestructuring}; 6447 kAllowHarmonyArrowFunctions, kAllowHarmonyDestructuring};
6441 6448
6442 { // All modes. 6449 { // All modes.
6443 const char* context_data[][2] = {{"'use strict'; let ", " = {};"}, 6450 const char* context_data[][2] = {{"'use strict'; let ", " = {};"},
6444 {"var ", " = {};"}, 6451 {"var ", " = {};"},
6445 {"'use strict'; const ", " = {};"}, 6452 {"'use strict'; const ", " = {};"},
6453 {"function f(", ") {}"},
6454 {"function f(argument1, ", ") {}"},
6455 {"var f = (", ") => {};"},
6456 {"var f = ", " => {};"},
6457 {"var f = (argument1,", ") => {};"},
6446 {NULL, NULL}}; 6458 {NULL, NULL}};
6447 6459
6448 // clang-format off 6460 // clang-format off
6449 const char* data[] = { 6461 const char* data[] = {
6450 "a++", 6462 "a++",
6451 "++a", 6463 "++a",
6452 "delete a", 6464 "delete a",
6453 "void a", 6465 "void a",
6454 "typeof a", 6466 "typeof a",
6455 "--a", 6467 "--a",
(...skipping 12 matching lines...) Expand all
6468 "a * a", 6480 "a * a",
6469 "a / a", 6481 "a / a",
6470 "a == a", 6482 "a == a",
6471 "a != a", 6483 "a != a",
6472 "a > a", 6484 "a > a",
6473 "a < a", 6485 "a < a",
6474 "a <<< a", 6486 "a <<< a",
6475 "a >>> a", 6487 "a >>> a",
6476 "function a() {}", 6488 "function a() {}",
6477 "a`bcd`", 6489 "a`bcd`",
6478 "x => x",
6479 "this", 6490 "this",
6480 "null", 6491 "null",
6481 "true", 6492 "true",
6482 "false", 6493 "false",
6483 "1", 6494 "1",
6484 "'abc'", 6495 "'abc'",
6485 "class {}", 6496 "class {}",
6486 "() => x",
6487 "{+2 : x}", 6497 "{+2 : x}",
6488 "{-2 : x}", 6498 "{-2 : x}",
6489 "var", 6499 "var",
6490 "[var]", 6500 "[var]",
6491 "{x : {y : var}}", 6501 "{x : {y : var}}",
6492 "{x : x = a+}", 6502 "{x : x = a+}",
6493 "{x : x = (a+)}", 6503 "{x : x = (a+)}",
6494 "{x : x += a}", 6504 "{x : x += a}",
6495 "{m() {} = 0}", 6505 "{m() {} = 0}",
6496 "{[1+1]}", 6506 "{[1+1]}",
6497 "[...rest, x]", 6507 "[...rest, x]",
6498 "[a,b,...rest, x]", 6508 "[a,b,...rest, x]",
6499 "[a,,...rest, x]", 6509 "[a,,...rest, x]",
6500 "[...rest,]", 6510 "[...rest,]",
6501 "[a,b,...rest,]", 6511 "[a,b,...rest,]",
6502 "[a,,...rest,]", 6512 "[a,,...rest,]",
6503 "[...rest,...rest1]", 6513 "[...rest,...rest1]",
6504 "[a,b,...rest,...rest1]", 6514 "[a,b,...rest,...rest1]",
6505 "[a,,..rest,...rest1]", 6515 "[a,,..rest,...rest1]",
6506 NULL}; 6516 NULL};
6507 // clang-format on 6517 // clang-format on
6508 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, 6518 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
6509 arraysize(always_flags)); 6519 arraysize(always_flags));
6510 } 6520 }
6511 6521
6522 { // All modes.
6523 const char* context_data[][2] = {{"'use strict'; let ", " = {};"},
6524 {"var ", " = {};"},
6525 {"'use strict'; const ", " = {};"},
6526 {"function f(", ") {}"},
6527 {"function f(argument1, ", ") {}"},
6528 {"var f = (", ") => {};"},
6529 {"var f = (argument1,", ") => {};"},
6530 {NULL, NULL}};
6531
6532 // clang-format off
6533 const char* data[] = {
6534 "x => x",
6535 "() => x",
6536 NULL};
6537 // clang-format on
6538 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
6539 arraysize(always_flags));
6540 }
6541
6512 { // Strict mode. 6542 { // Strict mode.
6513 const char* context_data[][2] = {{"'use strict'; let ", " = {};"}, 6543 const char* context_data[][2] = {
6514 {"'use strict'; const ", " = {};"}, 6544 {"'use strict'; let ", " = {};"},
6515 {NULL, NULL}}; 6545 {"'use strict'; const ", " = {};"},
6546 {"'use strict'; function f(", ") {}"},
6547 {"'use strict'; function f(argument1, ", ") {}"},
6548 {NULL, NULL}};
6516 6549
6517 // clang-format off 6550 // clang-format off
6518 const char* data[] = { 6551 const char* data[] = {
6519 "[eval]", 6552 "[eval]",
6520 "{ a : arguments }", 6553 "{ a : arguments }",
6521 "[public]", 6554 "[public]",
6522 "{ x : private }", 6555 "{ x : private }",
6523 NULL}; 6556 NULL};
6524 // clang-format on 6557 // clang-format on
6525 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, 6558 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
6565 // clang-format off 6598 // clang-format off
6566 const char* success_data[] = { 6599 const char* success_data[] = {
6567 "for (var x = {} in null);", 6600 "for (var x = {} in null);",
6568 NULL}; 6601 NULL};
6569 // clang-format on 6602 // clang-format on
6570 RunParserSyncTest(context_data, success_data, kSuccess, NULL, 0, always_flags, 6603 RunParserSyncTest(context_data, success_data, kSuccess, NULL, 0, always_flags,
6571 arraysize(always_flags)); 6604 arraysize(always_flags));
6572 } 6605 }
6573 6606
6574 6607
6608 TEST(DestructuringParameterPatternsPositive) {
6609 i::FLAG_harmony_destructuring = true;
6610 static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring};
6611
6612 const char* context_data[][2] = {
6613 {"function f(", "){}"}, {"function f(x, ", "){}"}, {NULL, NULL}};
6614
6615 // clang-format off
6616 const char* success_data[] = {
6617 "{a : a}",
arv (Not doing code reviews) 2015/06/15 15:21:59 Isn't this case already covered on line 6405?
Dmitry Lomov (no reviews) 2015/06/15 16:12:51 Removed.
6618 NULL};
6619 // clang-format on
6620 RunParserSyncTest(context_data, success_data, kSuccess, NULL, 0, always_flags,
6621 arraysize(always_flags));
6622 }
6623
6624
6575 TEST(SpreadArray) { 6625 TEST(SpreadArray) {
6576 i::FLAG_harmony_spread_arrays = true; 6626 i::FLAG_harmony_spread_arrays = true;
6577 6627
6578 const char* context_data[][2] = { 6628 const char* context_data[][2] = {
6579 {"'use strict';", ""}, {"", ""}, {NULL, NULL}}; 6629 {"'use strict';", ""}, {"", ""}, {NULL, NULL}};
6580 6630
6581 // clang-format off 6631 // clang-format off
6582 const char* data[] = { 6632 const char* data[] = {
6583 "[...a]", 6633 "[...a]",
6584 "[a, ...b]", 6634 "[a, ...b]",
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
6665 kAllowHarmonyObjectLiterals, 6715 kAllowHarmonyObjectLiterals,
6666 kAllowHarmonySloppy, 6716 kAllowHarmonySloppy,
6667 }; 6717 };
6668 // clang-format on 6718 // clang-format on
6669 6719
6670 RunParserSyncTest(good_context_data, data, kSuccess, NULL, 0, always_flags, 6720 RunParserSyncTest(good_context_data, data, kSuccess, NULL, 0, always_flags,
6671 arraysize(always_flags)); 6721 arraysize(always_flags));
6672 RunParserSyncTest(bad_context_data, data, kError, NULL, 0, always_flags, 6722 RunParserSyncTest(bad_context_data, data, kError, NULL, 0, always_flags,
6673 arraysize(always_flags)); 6723 arraysize(always_flags));
6674 } 6724 }
OLDNEW
« src/parser.cc ('K') | « src/preparser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698