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 6561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6572 "[yield]", | 6572 "[yield]", |
6573 "{ x : yield }", | 6573 "{ x : yield }", |
6574 NULL}; | 6574 NULL}; |
6575 // clang-format on | 6575 // clang-format on |
6576 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, | 6576 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, |
6577 arraysize(always_flags)); | 6577 arraysize(always_flags)); |
6578 } | 6578 } |
6579 } | 6579 } |
6580 | 6580 |
6581 | 6581 |
| 6582 TEST(DestructuringAssignmentPositiveTests) { |
| 6583 i::FLAG_harmony_destructuring = true; |
| 6584 i::FLAG_harmony_computed_property_names = true; |
| 6585 |
| 6586 const char* context_data[][2] = { |
| 6587 {"'use strict'; let x, y, z; (", " = {});"}, |
| 6588 {"var x, y, z; (", " = {});"}, |
| 6589 {"'use strict'; let x, y, z; for (x in ", " = {});"}, |
| 6590 {"'use strict'; let x, y, z; for (x of ", " = {});"}, |
| 6591 {"var x, y, z; for (x in ", " = {});"}, |
| 6592 {"var x, y, z; for (x of ", " = {});"}, |
| 6593 {NULL, NULL}}; |
| 6594 |
| 6595 // clang-format off |
| 6596 const char* data[] = { |
| 6597 "x", |
| 6598 |
| 6599 "{ x : y }", |
| 6600 "{ x : foo().y }", |
| 6601 "{ x : foo()[y] }", |
| 6602 "{ x : y.z }", |
| 6603 "{ x : y[z] }", |
| 6604 "{ x : { y } }", |
| 6605 "{ x : { foo: y } }", |
| 6606 "{ x : { foo: foo().y } }", |
| 6607 "{ x : { foo: foo()[y] } }", |
| 6608 "{ x : { foo: y.z } }", |
| 6609 "{ x : { foo: y[z] } }", |
| 6610 "{ x : [ y ] }", |
| 6611 "{ x : [ foo().y ] }", |
| 6612 "{ x : [ foo()[y] ] }", |
| 6613 "{ x : [ y.z ] }", |
| 6614 "{ x : [ y[z] ] }", |
| 6615 |
| 6616 "{ x : y = 10 }", |
| 6617 "{ x : foo().y = 10 }", |
| 6618 "{ x : foo()[y] = 10 }", |
| 6619 "{ x : y.z = 10 }", |
| 6620 "{ x : y[z] = 10 }", |
| 6621 "{ x : { y = 10 } = {} }", |
| 6622 "{ x : { foo: y = 10 } = {} }", |
| 6623 "{ x : { foo: foo().y = 10 } = {} }", |
| 6624 "{ x : { foo: foo()[y] = 10 } = {} }", |
| 6625 "{ x : { foo: y.z = 10 } = {} }", |
| 6626 "{ x : { foo: y[z] = 10 } = {} }", |
| 6627 "{ x : [ y = 10 ] = {} }", |
| 6628 "{ x : [ foo().y = 10 ] = {} }", |
| 6629 "{ x : [ foo()[y] = 10 ] = {} }", |
| 6630 "{ x : [ y.z = 10 ] = {} }", |
| 6631 "{ x : [ y[z] = 10 ] = {} }", |
| 6632 |
| 6633 "[ x ]", |
| 6634 "[ foo().x ]", |
| 6635 "[ foo()[x] ]", |
| 6636 "[ x.y ]", |
| 6637 "[ x[y] ]", |
| 6638 "[ { x } ]", |
| 6639 "[ { x : y } ]", |
| 6640 "[ { x : foo().y } ]", |
| 6641 "[ { x : foo()[y] } ]", |
| 6642 "[ { x : x.y } ]", |
| 6643 "[ { x : x[y] } ]", |
| 6644 "[ [ x ] ]", |
| 6645 "[ [ foo().x ] ]", |
| 6646 "[ [ foo()[x] ] ]", |
| 6647 "[ [ x.y ] ]", |
| 6648 "[ [ x[y] ] ]", |
| 6649 |
| 6650 "[ x = 10 ]", |
| 6651 "[ foo().x = 10 ]", |
| 6652 "[ foo()[x] = 10 ]", |
| 6653 "[ x.y = 10 ]", |
| 6654 "[ x[y] = 10 ]", |
| 6655 "[ { x = 10 } = {} ]", |
| 6656 "[ { x : y = 10 } = {} ]", |
| 6657 "[ { x : foo().y = 10 } = {} ]", |
| 6658 "[ { x : foo()[y] = 10 } = {} ]", |
| 6659 "[ { x : x.y = 10 } = {} ]", |
| 6660 "[ { x : x[y] = 10 } = {} ]", |
| 6661 "[ [ x = 10 ] = {} ]", |
| 6662 "[ [ foo().x = 10 ] = {} ]", |
| 6663 "[ [ foo()[x] = 10 ] = {} ]", |
| 6664 "[ [ x.y = 10 ] = {} ]", |
| 6665 "[ [ x[y] = 10 ] = {} ]", |
| 6666 |
| 6667 "{ x : y }", |
| 6668 "{ x : y = 1 }", |
| 6669 "{ x }", |
| 6670 "{ x, y, z }", |
| 6671 "{ x = 1, y: z, z: y }", |
| 6672 "{x = 42, y = 15}", |
| 6673 "[x]", |
| 6674 "[x = 1]", |
| 6675 "[x,y,z]", |
| 6676 "[x, y = 42, z]", |
| 6677 "{ x : x, y : y }", |
| 6678 "{ x : x = 1, y : y }", |
| 6679 "{ x : x, y : y = 42 }", |
| 6680 "[]", |
| 6681 "{}", |
| 6682 "[{x:x, y:y}, [,x,z,]]", |
| 6683 "[{x:x = 1, y:y = 2}, [z = 3, z = 4, z = 5]]", |
| 6684 "[x,,y]", |
| 6685 "[(x),,(y)]", |
| 6686 "[(x)]", |
| 6687 "{42 : x}", |
| 6688 "{42 : x = 42}", |
| 6689 "{42e-2 : x}", |
| 6690 "{42e-2 : x = 42}", |
| 6691 "{'hi' : x}", |
| 6692 "{'hi' : x = 42}", |
| 6693 "{var: x}", |
| 6694 "{var: x = 42}", |
| 6695 "{var: (x) = 42}", |
| 6696 "{[x] : z}", |
| 6697 "{[1+1] : z}", |
| 6698 "{[1+1] : (z)}", |
| 6699 "{[foo()] : z}", |
| 6700 "{[foo()] : (z)}", |
| 6701 "{[foo()] : foo().bar}", |
| 6702 "{[foo()] : foo()['bar']}", |
| 6703 "{[foo()] : this.bar}", |
| 6704 "{[foo()] : this['bar']}", |
| 6705 "{[foo()] : 'foo'.bar}", |
| 6706 "{[foo()] : 'foo'['bar']}", |
| 6707 "[...x]", |
| 6708 "[x,y,...z]", |
| 6709 "[x,,...z]", |
| 6710 "{ x: y } = z", |
| 6711 "[x, y] = z", |
| 6712 "{ x: y } = { z }", |
| 6713 "[x, y] = { z }", |
| 6714 "{ x: y } = [ z ]", |
| 6715 "[x, y] = [ z ]", |
| 6716 "[((x, y) => z).x]", |
| 6717 "{x: ((y, z) => z).x}", |
| 6718 "[((x, y) => z)['x']]", |
| 6719 "{x: ((y, z) => z)['x']}", |
| 6720 NULL}; |
| 6721 // clang-format on |
| 6722 static const ParserFlag always_flags[] = { |
| 6723 kAllowHarmonyObjectLiterals, kAllowHarmonyComputedPropertyNames, |
| 6724 kAllowHarmonyDestructuring, kAllowHarmonyArrowFunctions}; |
| 6725 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, |
| 6726 arraysize(always_flags)); |
| 6727 } |
| 6728 |
| 6729 |
| 6730 TEST(DestructuringAssignmentNegativeTests) { |
| 6731 i::FLAG_harmony_destructuring = true; |
| 6732 i::FLAG_harmony_computed_property_names = true; |
| 6733 |
| 6734 const char* context_data[][2] = { |
| 6735 {"'use strict'; let x, y, z; (", " = {});"}, |
| 6736 {"var x, y, z; (", " = {});"}, |
| 6737 {"'use strict'; let x, y, z; for (x in ", " = {});"}, |
| 6738 {"'use strict'; let x, y, z; for (x of ", " = {});"}, |
| 6739 {"var x, y, z; for (x in ", " = {});"}, |
| 6740 {"var x, y, z; for (x of ", " = {});"}, |
| 6741 {NULL, NULL}}; |
| 6742 |
| 6743 // clang-format off |
| 6744 const char* data[] = { |
| 6745 "{ x : ++y }", |
| 6746 "{ x : y * 2 }", |
| 6747 "{ ...x }", |
| 6748 "{ get x() {} }", |
| 6749 "{ set x() {} }", |
| 6750 "{ x: y() }", |
| 6751 "{ this }", |
| 6752 "{ x: this }", |
| 6753 "{ x: this = 1 }", |
| 6754 "{ super }", |
| 6755 "{ x: super }", |
| 6756 "{ x: super = 1 }", |
| 6757 "{ new.target }", |
| 6758 "{ x: new.target }", |
| 6759 "{ x: new.target = 1 }", |
| 6760 "[x--]", |
| 6761 "[--x = 1]", |
| 6762 "[x()]", |
| 6763 "[this]", |
| 6764 "[this = 1]", |
| 6765 "[new.target]", |
| 6766 "[new.target = 1]", |
| 6767 "[super]", |
| 6768 "[super = 1]", |
| 6769 "[function f() {}]", |
| 6770 "[50]", |
| 6771 "[(50)]", |
| 6772 "[(function() {})]", |
| 6773 "[(foo())]", |
| 6774 "{ x: 50 }", |
| 6775 "{ x: (50) }", |
| 6776 "['str']", |
| 6777 "{ x: 'str' }", |
| 6778 "{ x: ('str') }", |
| 6779 "{ x: (foo()) }", |
| 6780 "{ x: (function() {}) }", |
| 6781 "{ x: y } = 'str'", |
| 6782 "[x, y] = 'str'", |
| 6783 "[(x,y) => z]", |
| 6784 "{x: (y) => z}", |
| 6785 "[x, ...y, z]", |
| 6786 "[...x,]", |
| 6787 "[x, y, ...z = 1]", |
| 6788 "[...z = 1]", |
| 6789 NULL}; |
| 6790 // clang-format on |
| 6791 static const ParserFlag always_flags[] = { |
| 6792 kAllowHarmonyObjectLiterals, kAllowHarmonyComputedPropertyNames, |
| 6793 kAllowHarmonyDestructuring, kAllowHarmonyArrowFunctions}; |
| 6794 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, |
| 6795 arraysize(always_flags)); |
| 6796 } |
| 6797 |
| 6798 |
6582 TEST(DestructuringDisallowPatternsInForVarIn) { | 6799 TEST(DestructuringDisallowPatternsInForVarIn) { |
6583 i::FLAG_harmony_destructuring = true; | 6800 i::FLAG_harmony_destructuring = true; |
6584 static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring}; | 6801 static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring}; |
6585 const char* context_data[][2] = { | 6802 const char* context_data[][2] = { |
6586 {"", ""}, {"function f() {", "}"}, {NULL, NULL}}; | 6803 {"", ""}, {"function f() {", "}"}, {NULL, NULL}}; |
6587 // clang-format off | 6804 // clang-format off |
6588 const char* error_data[] = { | 6805 const char* error_data[] = { |
6589 "for (var {x} = {} in null);", | 6806 "for (var {x} = {} in null);", |
6590 "for (var {x} = {} of null);", | 6807 "for (var {x} = {} of null);", |
6591 "for (let x = {} in null);", | 6808 "for (let x = {} in null);", |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6698 kAllowHarmonyObjectLiterals, | 6915 kAllowHarmonyObjectLiterals, |
6699 kAllowHarmonySloppy, | 6916 kAllowHarmonySloppy, |
6700 }; | 6917 }; |
6701 // clang-format on | 6918 // clang-format on |
6702 | 6919 |
6703 RunParserSyncTest(good_context_data, data, kSuccess, NULL, 0, always_flags, | 6920 RunParserSyncTest(good_context_data, data, kSuccess, NULL, 0, always_flags, |
6704 arraysize(always_flags)); | 6921 arraysize(always_flags)); |
6705 RunParserSyncTest(bad_context_data, data, kError, NULL, 0, always_flags, | 6922 RunParserSyncTest(bad_context_data, data, kError, NULL, 0, always_flags, |
6706 arraysize(always_flags)); | 6923 arraysize(always_flags)); |
6707 } | 6924 } |
OLD | NEW |