OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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) { | |
wingo
2015/06/22 10:28:33
Need tests that patterns are not allowed in rest p
Dmitry Lomov (no reviews)
2015/06/22 11:11:42
Done (also fixed)
| |
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}) {}", | |
wingo
2015/06/22 10:28:33
Arrow function tests would be nice here:
({x, x
Dmitry Lomov (no reviews)
2015/06/22 11:11:42
For arrow functions duplicate parameter detection
| |
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 | |
6608 TEST(SpreadArray) { | 6687 TEST(SpreadArray) { |
6609 i::FLAG_harmony_spread_arrays = true; | 6688 i::FLAG_harmony_spread_arrays = true; |
6610 | 6689 |
6611 const char* context_data[][2] = { | 6690 const char* context_data[][2] = { |
6612 {"'use strict';", ""}, {"", ""}, {NULL, NULL}}; | 6691 {"'use strict';", ""}, {"", ""}, {NULL, NULL}}; |
6613 | 6692 |
6614 // clang-format off | 6693 // clang-format off |
6615 const char* data[] = { | 6694 const char* data[] = { |
6616 "[...a]", | 6695 "[...a]", |
6617 "[a, ...b]", | 6696 "[a, ...b]", |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6698 kAllowHarmonyObjectLiterals, | 6777 kAllowHarmonyObjectLiterals, |
6699 kAllowHarmonySloppy, | 6778 kAllowHarmonySloppy, |
6700 }; | 6779 }; |
6701 // clang-format on | 6780 // clang-format on |
6702 | 6781 |
6703 RunParserSyncTest(good_context_data, data, kSuccess, NULL, 0, always_flags, | 6782 RunParserSyncTest(good_context_data, data, kSuccess, NULL, 0, always_flags, |
6704 arraysize(always_flags)); | 6783 arraysize(always_flags)); |
6705 RunParserSyncTest(bad_context_data, data, kError, NULL, 0, always_flags, | 6784 RunParserSyncTest(bad_context_data, data, kError, NULL, 0, always_flags, |
6706 arraysize(always_flags)); | 6785 arraysize(always_flags)); |
6707 } | 6786 } |
OLD | NEW |