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 6528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6539 "[yield]", | 6539 "[yield]", |
6540 "{ x : yield }", | 6540 "{ x : yield }", |
6541 NULL}; | 6541 NULL}; |
6542 // clang-format on | 6542 // clang-format on |
6543 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, | 6543 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, |
6544 arraysize(always_flags)); | 6544 arraysize(always_flags)); |
6545 } | 6545 } |
6546 } | 6546 } |
6547 | 6547 |
6548 | 6548 |
| 6549 TEST(DestructuringAssignmentPositiveTests) { |
| 6550 i::FLAG_harmony_destructuring = true; |
| 6551 i::FLAG_harmony_computed_property_names = true; |
| 6552 |
| 6553 const char* context_data[][2] = { |
| 6554 {"'use strict'; let x, y, z; (", " = {});"}, |
| 6555 {"var x, y, z; (", " = {});"}, |
| 6556 {"'use strict'; let x, y, z; for (x in ", " = {});"}, |
| 6557 {"'use strict'; let x, y, z; for (x of ", " = {});"}, |
| 6558 {"var x, y, z; for (x in ", " = {});"}, |
| 6559 {"var x, y, z; for (x of ", " = {});"}, |
| 6560 {NULL, NULL}}; |
| 6561 |
| 6562 // clang-format off |
| 6563 const char* data[] = { |
| 6564 "x", |
| 6565 "{ x : y }", |
| 6566 "{ x : y = 1 }", |
| 6567 "{ x }", |
| 6568 "{ x, y, z }", |
| 6569 "{ x = 1, y: z, z: y }", |
| 6570 "{x = 42, y = 15}", |
| 6571 "[x]", |
| 6572 "[x = 1]", |
| 6573 "[x,y,z]", |
| 6574 "[x, y = 42, z]", |
| 6575 "{ x : x, y : y }", |
| 6576 "{ x : x = 1, y : y }", |
| 6577 "{ x : x, y : y = 42 }", |
| 6578 "[]", |
| 6579 "{}", |
| 6580 "[{x:x, y:y}, [,x,z,]]", |
| 6581 "[{x:x = 1, y:y = 2}, [z = 3, z = 4, z = 5]]", |
| 6582 "[x,,y]", |
| 6583 "[(x),,(y)]", |
| 6584 "[(x)]", |
| 6585 "{42 : x}", |
| 6586 "{42 : x = 42}", |
| 6587 "{42e-2 : x}", |
| 6588 "{42e-2 : x = 42}", |
| 6589 "{'hi' : x}", |
| 6590 "{'hi' : x = 42}", |
| 6591 "{var: x}", |
| 6592 "{var: x = 42}", |
| 6593 "{var: (x) = 42}", |
| 6594 "{[x] : z}", |
| 6595 "{[1+1] : z}", |
| 6596 "{[1+1] : (z)}", |
| 6597 "{[foo()] : z}", |
| 6598 "{[foo()] : (z)}", |
| 6599 "{[foo()] : foo().bar}", |
| 6600 "{[foo()] : foo()['bar']}", |
| 6601 "{[foo()] : this.bar}", |
| 6602 "{[foo()] : this['bar']}", |
| 6603 "{[foo()] : 'foo'.bar}", |
| 6604 "{[foo()] : 'foo'['bar']}", |
| 6605 "[...x]", |
| 6606 "[x,y,...z]", |
| 6607 "[x,,...z]", |
| 6608 "{ x: y } = z", |
| 6609 "[x, y] = z", |
| 6610 "{ x: y } = { z }", |
| 6611 "[x, y] = { z }", |
| 6612 "{ x: y } = [ z ]", |
| 6613 "[x, y] = [ z ]", |
| 6614 "[((x, y) => z).x]", |
| 6615 "{x: ((y, z) => z).x}", |
| 6616 "[((x, y) => z)['x']]", |
| 6617 "{x: ((y, z) => z)['x']}", |
| 6618 NULL}; |
| 6619 // clang-format on |
| 6620 static const ParserFlag always_flags[] = { |
| 6621 kAllowHarmonyObjectLiterals, kAllowHarmonyComputedPropertyNames, |
| 6622 kAllowHarmonyDestructuring, kAllowHarmonyArrowFunctions}; |
| 6623 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, |
| 6624 arraysize(always_flags)); |
| 6625 } |
| 6626 |
| 6627 |
| 6628 TEST(DestructuringAssignmentNegativeTests) { |
| 6629 i::FLAG_harmony_destructuring = true; |
| 6630 i::FLAG_harmony_computed_property_names = true; |
| 6631 |
| 6632 const char* context_data[][2] = { |
| 6633 {"'use strict'; let x, y, z; (", " = {});"}, |
| 6634 {"var x, y, z; (", " = {});"}, |
| 6635 {"'use strict'; let x, y, z; for (x in ", " = {});"}, |
| 6636 {"'use strict'; let x, y, z; for (x of ", " = {});"}, |
| 6637 {"var x, y, z; for (x in ", " = {});"}, |
| 6638 {"var x, y, z; for (x of ", " = {});"}, |
| 6639 {NULL, NULL}}; |
| 6640 |
| 6641 // clang-format off |
| 6642 const char* data[] = { |
| 6643 "{ x : ++y }", |
| 6644 "{ x : y * 2 }", |
| 6645 "{ ...x }", |
| 6646 "{ get x() {} }", |
| 6647 "{ set x() {} }", |
| 6648 "{ x: y() }", |
| 6649 "{ this }", |
| 6650 "{ x: this }", |
| 6651 "{ x: this = 1 }", |
| 6652 "{ super }", |
| 6653 "{ x: super }", |
| 6654 "{ x: super = 1 }", |
| 6655 "{ new.target }", |
| 6656 "{ x: new.target }", |
| 6657 "{ x: new.target = 1 }", |
| 6658 "[x--]", |
| 6659 "[--x = 1]", |
| 6660 "[x()]", |
| 6661 "[this]", |
| 6662 "[this = 1]", |
| 6663 "[new.target]", |
| 6664 "[new.target = 1]", |
| 6665 "[super]", |
| 6666 "[super = 1]", |
| 6667 "[function f() {}]", |
| 6668 "[50]", |
| 6669 "[(50)]", |
| 6670 "[(function() {})]", |
| 6671 "[(foo())]", |
| 6672 "{ x: 50 }", |
| 6673 "{ x: (50) }", |
| 6674 "['str']", |
| 6675 "{ x: 'str' }", |
| 6676 "{ x: ('str') }", |
| 6677 "{ x: (foo()) }", |
| 6678 "{ x: (function() {}) }", |
| 6679 "{ x: y } = 'str'", |
| 6680 "[x, y] = 'str'", |
| 6681 "[(x,y) => z]", |
| 6682 "{x: (y) => z}", |
| 6683 "[x, ...y, z]", |
| 6684 "[...x,]", |
| 6685 "[x, y, ...z = 1]", |
| 6686 "[...z = 1]", |
| 6687 NULL}; |
| 6688 // clang-format on |
| 6689 static const ParserFlag always_flags[] = { |
| 6690 kAllowHarmonyObjectLiterals, kAllowHarmonyComputedPropertyNames, |
| 6691 kAllowHarmonyDestructuring, kAllowHarmonyArrowFunctions}; |
| 6692 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, |
| 6693 arraysize(always_flags)); |
| 6694 } |
| 6695 |
| 6696 |
6549 TEST(DestructuringDisallowPatternsInForVarIn) { | 6697 TEST(DestructuringDisallowPatternsInForVarIn) { |
6550 i::FLAG_harmony_destructuring = true; | 6698 i::FLAG_harmony_destructuring = true; |
6551 static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring}; | 6699 static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring}; |
6552 const char* context_data[][2] = { | 6700 const char* context_data[][2] = { |
6553 {"", ""}, {"function f() {", "}"}, {NULL, NULL}}; | 6701 {"", ""}, {"function f() {", "}"}, {NULL, NULL}}; |
6554 // clang-format off | 6702 // clang-format off |
6555 const char* error_data[] = { | 6703 const char* error_data[] = { |
6556 "for (var {x} = {} in null);", | 6704 "for (var {x} = {} in null);", |
6557 "for (var {x} = {} of null);", | 6705 "for (var {x} = {} of null);", |
6558 "for (let x = {} in null);", | 6706 "for (let x = {} in null);", |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6665 kAllowHarmonyObjectLiterals, | 6813 kAllowHarmonyObjectLiterals, |
6666 kAllowHarmonySloppy, | 6814 kAllowHarmonySloppy, |
6667 }; | 6815 }; |
6668 // clang-format on | 6816 // clang-format on |
6669 | 6817 |
6670 RunParserSyncTest(good_context_data, data, kSuccess, NULL, 0, always_flags, | 6818 RunParserSyncTest(good_context_data, data, kSuccess, NULL, 0, always_flags, |
6671 arraysize(always_flags)); | 6819 arraysize(always_flags)); |
6672 RunParserSyncTest(bad_context_data, data, kError, NULL, 0, always_flags, | 6820 RunParserSyncTest(bad_context_data, data, kError, NULL, 0, always_flags, |
6673 arraysize(always_flags)); | 6821 arraysize(always_flags)); |
6674 } | 6822 } |
OLD | NEW |