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

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

Issue 1189743003: [destructuring] Implement parameter pattern matching. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix magic number issue 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
« no previous file with comments | « src/snapshot/serialize.cc ('k') | test/mjsunit/harmony/destructuring.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 6371 matching lines...) Expand 10 before | Expand all | Expand 10 after
6382 i::FLAG_harmony_destructuring = true; 6382 i::FLAG_harmony_destructuring = true;
6383 i::FLAG_harmony_arrow_functions = true; 6383 i::FLAG_harmony_arrow_functions = true;
6384 i::FLAG_harmony_computed_property_names = true; 6384 i::FLAG_harmony_computed_property_names = true;
6385 6385
6386 const char* context_data[][2] = {{"'use strict'; let ", " = {};"}, 6386 const char* context_data[][2] = {{"'use strict'; let ", " = {};"},
6387 {"var ", " = {};"}, 6387 {"var ", " = {};"},
6388 {"'use strict'; const ", " = {};"}, 6388 {"'use strict'; const ", " = {};"},
6389 {"function f(", ") {}"}, 6389 {"function f(", ") {}"},
6390 {"function f(argument1, ", ") {}"}, 6390 {"function f(argument1, ", ") {}"},
6391 {"var f = (", ") => {};"}, 6391 {"var f = (", ") => {};"},
6392 {"var f = ", " => {};"},
6393 {"var f = (argument1,", ") => {};"}, 6392 {"var f = (argument1,", ") => {};"},
6394 {NULL, NULL}}; 6393 {NULL, NULL}};
6395 6394
6396 // clang-format off 6395 // clang-format off
6397 const char* data[] = { 6396 const char* data[] = {
6398 "a", 6397 "a",
6399 "{ x : y }", 6398 "{ x : y }",
6400 "{ x : y = 1 }", 6399 "{ x : y = 1 }",
6401 "[a]", 6400 "[a]",
6402 "[a = 1]", 6401 "[a = 1]",
6403 "[a,b,c]", 6402 "[a,b,c]",
6404 "[a, b = 42, c]", 6403 "[a, b = 42, c]",
6405 "{ x : x, y : y }", 6404 "{ x : x, y : y }",
6406 "{ x : x = 1, y : y }", 6405 "{ x : x = 1, y : y }",
6407 "{ x : x, y : y = 42 }", 6406 "{ x : x, y : y = 42 }",
6408 "[]", 6407 "[]",
6409 "{}", 6408 "{}",
6410 "[{x:x, y:y}, [a,b,c]]", 6409 "[{x:x, y:y}, [a,b,c]]",
6411 "[{x:x = 1, y:y = 2}, [a = 3, b = 4, c = 5]]", 6410 "[{x:x = 1, y:y = 2}, [a = 3, b = 4, c = 5]]",
6412 "{x}", 6411 "{x}",
6413 "{x, y}", 6412 "{x, y}",
6414 "{x = 42, y = 15}", 6413 "{x = 42, y = 15}",
6415 "[a,,b]", 6414 "[a,,b]",
6416 "{42 : x}", 6415 "{42 : x}",
6417 "{42 : x = 42}", 6416 "{42 : x = 42}",
6418 "{42e-2 : x}", 6417 "{42e-2 : x}",
6419 "{42e-2 : x = 42}", 6418 "{42e-2 : x = 42}",
6419 "{x : y, x : z}",
6420 "{'hi' : x}", 6420 "{'hi' : x}",
6421 "{'hi' : x = 42}", 6421 "{'hi' : x = 42}",
6422 "{var: x}", 6422 "{var: x}",
6423 "{var: x = 42}", 6423 "{var: x = 42}",
6424 "{[x] : z}", 6424 "{[x] : z}",
6425 "{[1+1] : z}", 6425 "{[1+1] : z}",
6426 "{[foo()] : z}", 6426 "{[foo()] : z}",
6427 "{}", 6427 "{}",
6428 "[...rest]", 6428 "[...rest]",
6429 "[a,b,...rest]", 6429 "[a,b,...rest]",
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
6598 // clang-format off 6598 // clang-format off
6599 const char* success_data[] = { 6599 const char* success_data[] = {
6600 "for (var x = {} in null);", 6600 "for (var x = {} in null);",
6601 NULL}; 6601 NULL};
6602 // clang-format on 6602 // clang-format on
6603 RunParserSyncTest(context_data, success_data, kSuccess, NULL, 0, always_flags, 6603 RunParserSyncTest(context_data, success_data, kSuccess, NULL, 0, always_flags,
6604 arraysize(always_flags)); 6604 arraysize(always_flags));
6605 } 6605 }
6606 6606
6607 6607
6608 TEST(DestructuringDuplicateParams) {
6609 i::FLAG_harmony_destructuring = true;
6610 i::FLAG_harmony_arrow_functions = true;
6611 i::FLAG_harmony_computed_property_names = true;
6612 static const ParserFlag always_flags[] = {
6613 kAllowHarmonyObjectLiterals, kAllowHarmonyComputedPropertyNames,
6614 kAllowHarmonyArrowFunctions, kAllowHarmonyDestructuring};
6615 const char* context_data[][2] = {{"'use strict';", ""},
6616 {"function outer() { 'use strict';", "}"},
6617 {nullptr, nullptr}};
6618
6619
6620 // clang-format off
6621 const char* error_data[] = {
6622 "function f(x,x){}",
6623 "function f(x, {x : x}){}",
6624 "function f(x, {x}){}",
6625 "function f({x,x}) {}",
6626 "function f([x,x]) {}",
6627 "function f(x, [y,{z:x}]) {}",
6628 "function f([x,{y:x}]) {}",
6629 // non-simple parameter list causes duplicates to be errors in sloppy mode.
6630 "function f(x, x, {a}) {}",
6631 nullptr};
6632 // clang-format on
6633 RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags,
6634 arraysize(always_flags));
6635 }
6636
6637
6638 TEST(DestructuringDuplicateParamsSloppy) {
6639 i::FLAG_harmony_destructuring = true;
6640 i::FLAG_harmony_arrow_functions = true;
6641 i::FLAG_harmony_computed_property_names = true;
6642 static const ParserFlag always_flags[] = {
6643 kAllowHarmonyObjectLiterals, kAllowHarmonyComputedPropertyNames,
6644 kAllowHarmonyArrowFunctions, kAllowHarmonyDestructuring};
6645 const char* context_data[][2] = {
6646 {"", ""}, {"function outer() {", "}"}, {nullptr, nullptr}};
6647
6648
6649 // clang-format off
6650 const char* error_data[] = {
6651 // non-simple parameter list causes duplicates to be errors in sloppy mode.
6652 "function f(x, {x : x}){}",
6653 "function f(x, {x}){}",
6654 "function f({x,x}) {}",
6655 "function f(x, x, {a}) {}",
6656 nullptr};
6657 // clang-format on
6658 RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags,
6659 arraysize(always_flags));
6660 }
6661
6662
6663 TEST(DestructuringDisallowPatternsInSingleParamArrows) {
6664 i::FLAG_harmony_destructuring = true;
6665 i::FLAG_harmony_arrow_functions = true;
6666 i::FLAG_harmony_computed_property_names = true;
6667 static const ParserFlag always_flags[] = {
6668 kAllowHarmonyObjectLiterals, kAllowHarmonyComputedPropertyNames,
6669 kAllowHarmonyArrowFunctions, kAllowHarmonyDestructuring};
6670 const char* context_data[][2] = {{"'use strict';", ""},
6671 {"function outer() { 'use strict';", "}"},
6672 {"", ""},
6673 {"function outer() { ", "}"},
6674 {nullptr, nullptr}};
6675
6676 // clang-format off
6677 const char* error_data[] = {
6678 "var f = {x} => {};",
6679 "var f = {x,y} => {};",
6680 nullptr};
6681 // clang-format on
6682 RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags,
6683 arraysize(always_flags));
6684 }
6685
6686
6687 TEST(DestructuringDisallowPatternsInRestParams) {
6688 i::FLAG_harmony_destructuring = true;
6689 i::FLAG_harmony_arrow_functions = true;
6690 i::FLAG_harmony_rest_parameters = true;
6691 i::FLAG_harmony_computed_property_names = true;
6692 static const ParserFlag always_flags[] = {
6693 kAllowHarmonyObjectLiterals, kAllowHarmonyComputedPropertyNames,
6694 kAllowHarmonyArrowFunctions, kAllowHarmonyRestParameters,
6695 kAllowHarmonyDestructuring};
6696 const char* context_data[][2] = {{"'use strict';", ""},
6697 {"function outer() { 'use strict';", "}"},
6698 {"", ""},
6699 {"function outer() { ", "}"},
6700 {nullptr, nullptr}};
6701
6702 // clang-format off
6703 const char* error_data[] = {
6704 "function(...{}) {}",
6705 "function(...{x}) {}",
6706 "function(...[x]) {}",
6707 "(...{}) => {}",
6708 "(...{x}) => {}",
6709 "(...[x]) => {}",
6710 nullptr};
6711 // clang-format on
6712 RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags,
6713 arraysize(always_flags));
6714 }
6715
6716
6608 TEST(SpreadArray) { 6717 TEST(SpreadArray) {
6609 i::FLAG_harmony_spread_arrays = true; 6718 i::FLAG_harmony_spread_arrays = true;
6610 6719
6611 const char* context_data[][2] = { 6720 const char* context_data[][2] = {
6612 {"'use strict';", ""}, {"", ""}, {NULL, NULL}}; 6721 {"'use strict';", ""}, {"", ""}, {NULL, NULL}};
6613 6722
6614 // clang-format off 6723 // clang-format off
6615 const char* data[] = { 6724 const char* data[] = {
6616 "[...a]", 6725 "[...a]",
6617 "[a, ...b]", 6726 "[a, ...b]",
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
6698 kAllowHarmonyObjectLiterals, 6807 kAllowHarmonyObjectLiterals,
6699 kAllowHarmonySloppy, 6808 kAllowHarmonySloppy,
6700 }; 6809 };
6701 // clang-format on 6810 // clang-format on
6702 6811
6703 RunParserSyncTest(good_context_data, data, kSuccess, NULL, 0, always_flags, 6812 RunParserSyncTest(good_context_data, data, kSuccess, NULL, 0, always_flags,
6704 arraysize(always_flags)); 6813 arraysize(always_flags));
6705 RunParserSyncTest(bad_context_data, data, kError, NULL, 0, always_flags, 6814 RunParserSyncTest(bad_context_data, data, kError, NULL, 0, always_flags,
6706 arraysize(always_flags)); 6815 arraysize(always_flags));
6707 } 6816 }
OLDNEW
« no previous file with comments | « src/snapshot/serialize.cc ('k') | test/mjsunit/harmony/destructuring.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698