Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 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 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 727 CHECK_EQ(value, catcher.Exception()); | 727 CHECK_EQ(value, catcher.Exception()); |
| 728 } | 728 } |
| 729 } | 729 } |
| 730 } | 730 } |
| 731 | 731 |
| 732 private: | 732 private: |
| 733 Persistent<Context> context_; | 733 Persistent<Context> context_; |
| 734 }; | 734 }; |
| 735 | 735 |
| 736 | 736 |
| 737 TEST(MultiScriptConflicts) { | 737 |
|
Michael Starzinger
2012/11/20 12:05:05
Drop the third empty newline.
rossberg
2012/11/20 17:23:45
Done.
| |
| 738 TEST(CrossScriptReferences) { | |
| 738 HandleScope scope; | 739 HandleScope scope; |
| 739 | 740 |
| 740 { SimpleContext context; | 741 { SimpleContext context; |
| 741 context.Check("var x = 1; x", | 742 context.Check("var x = 1; x", |
| 742 EXPECT_RESULT, Number::New(1)); | 743 EXPECT_RESULT, Number::New(1)); |
| 743 context.Check("var x = 2; x", | 744 context.Check("var x = 2; x", |
| 744 EXPECT_RESULT, Number::New(2)); | 745 EXPECT_RESULT, Number::New(2)); |
| 745 context.Check("const x = 3; x", | 746 context.Check("const x = 3; x", |
| 746 EXPECT_RESULT, Number::New(3)); | 747 EXPECT_RESULT, Number::New(3)); |
| 747 context.Check("const x = 4; x", | 748 context.Check("const x = 4; x", |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 765 EXPECT_RESULT, Number::New(1)); | 766 EXPECT_RESULT, Number::New(1)); |
| 766 context.Check("x = 4; x", // assignment ignored | 767 context.Check("x = 4; x", // assignment ignored |
| 767 EXPECT_RESULT, Number::New(1)); | 768 EXPECT_RESULT, Number::New(1)); |
| 768 context.Check("var x = 5; x", // assignment ignored | 769 context.Check("var x = 5; x", // assignment ignored |
| 769 EXPECT_RESULT, Number::New(1)); | 770 EXPECT_RESULT, Number::New(1)); |
| 770 context.Check("this.x", | 771 context.Check("this.x", |
| 771 EXPECT_RESULT, Number::New(1)); | 772 EXPECT_RESULT, Number::New(1)); |
| 772 context.Check("function x() { return 7 }; x", | 773 context.Check("function x() { return 7 }; x", |
| 773 EXPECT_EXCEPTION); | 774 EXPECT_EXCEPTION); |
| 774 } | 775 } |
| 776 } | |
| 775 | 777 |
| 778 | |
| 779 | |
|
Michael Starzinger
2012/11/20 12:05:05
Drop the third empty newline.
rossberg
2012/11/20 17:23:45
Done.
| |
| 780 TEST(CrossScriptReferencesHarmony) { | |
| 776 i::FLAG_use_strict = true; | 781 i::FLAG_use_strict = true; |
| 777 i::FLAG_harmony_scoping = true; | 782 i::FLAG_harmony_scoping = true; |
| 783 i::FLAG_harmony_modules = true; | |
| 778 | 784 |
| 779 { SimpleContext context; | 785 HandleScope scope; |
| 780 context.Check("var x = 1; x", | |
| 781 EXPECT_RESULT, Number::New(1)); | |
| 782 context.Check("x", | |
| 783 EXPECT_RESULT, Number::New(1)); | |
| 784 context.Check("this.x", | |
| 785 EXPECT_RESULT, Number::New(1)); | |
| 786 } | |
| 787 | 786 |
| 788 { SimpleContext context; | 787 const char* decs[] = { |
| 789 context.Check("function x() { return 4 }; x()", | 788 "var x = 1; x", "x", "this.x", |
| 790 EXPECT_RESULT, Number::New(4)); | 789 "function x() { return 1 }; x()", "x()", "this.x()", |
| 791 context.Check("x()", | 790 "let x = 1; x", "x", "this.x", |
| 792 EXPECT_RESULT, Number::New(4)); | 791 "const x = 1; x", "x", "this.x", |
| 793 context.Check("this.x()", | 792 "module x { export let a = 1 }; x.a", "x.a", "this.x.a", |
| 794 EXPECT_RESULT, Number::New(4)); | 793 NULL |
| 795 } | 794 }; |
| 796 | 795 |
| 797 { SimpleContext context; | 796 for (int i = 0; decs[i] != NULL; i += 3) { |
| 798 context.Check("let x = 2; x", | 797 SimpleContext context; |
| 799 EXPECT_RESULT, Number::New(2)); | 798 context.Check(decs[i], EXPECT_RESULT, Number::New(1)); |
| 800 context.Check("x", | 799 context.Check(decs[i+1], EXPECT_RESULT, Number::New(1)); |
| 801 EXPECT_RESULT, Number::New(2)); | |
| 802 // TODO(rossberg): The current ES6 draft spec does not reflect lexical | 800 // TODO(rossberg): The current ES6 draft spec does not reflect lexical |
| 803 // bindings on the global object. However, this will probably change, in | 801 // bindings on the global object. However, this will probably change, in |
| 804 // which case we reactivate the following test. | 802 // which case we reactivate the following test. |
| 805 // context.Check("this.x", | 803 if (i/3 < 2) context.Check(decs[i+2], EXPECT_RESULT, Number::New(1)); |
| 806 // EXPECT_RESULT, Number::New(2)); | |
| 807 } | |
| 808 | |
| 809 { SimpleContext context; | |
| 810 context.Check("const x = 3; x", | |
| 811 EXPECT_RESULT, Number::New(3)); | |
| 812 context.Check("x", | |
| 813 EXPECT_RESULT, Number::New(3)); | |
| 814 // TODO(rossberg): The current ES6 draft spec does not reflect lexical | |
| 815 // bindings on the global object. However, this will probably change, in | |
| 816 // which case we reactivate the following test. | |
| 817 // context.Check("this.x", | |
| 818 // EXPECT_RESULT, Number::New(3)); | |
| 819 } | |
| 820 | |
| 821 // TODO(rossberg): All of the below should actually be errors in Harmony. | |
| 822 | |
| 823 { SimpleContext context; | |
| 824 context.Check("var x = 1; x", | |
| 825 EXPECT_RESULT, Number::New(1)); | |
| 826 context.Check("let x = 2; x", | |
| 827 EXPECT_RESULT, Number::New(2)); | |
| 828 } | |
| 829 | |
| 830 { SimpleContext context; | |
| 831 context.Check("var x = 1; x", | |
| 832 EXPECT_RESULT, Number::New(1)); | |
| 833 context.Check("const x = 2; x", | |
| 834 EXPECT_RESULT, Number::New(2)); | |
| 835 } | |
| 836 | |
| 837 { SimpleContext context; | |
| 838 context.Check("function x() { return 1 }; x()", | |
| 839 EXPECT_RESULT, Number::New(1)); | |
| 840 context.Check("let x = 2; x", | |
| 841 EXPECT_RESULT, Number::New(2)); | |
| 842 } | |
| 843 | |
| 844 { SimpleContext context; | |
| 845 context.Check("function x() { return 1 }; x()", | |
| 846 EXPECT_RESULT, Number::New(1)); | |
| 847 context.Check("const x = 2; x", | |
| 848 EXPECT_RESULT, Number::New(2)); | |
| 849 } | |
| 850 | |
| 851 { SimpleContext context; | |
| 852 context.Check("let x = 1; x", | |
| 853 EXPECT_RESULT, Number::New(1)); | |
| 854 context.Check("var x = 2; x", | |
| 855 EXPECT_ERROR); | |
| 856 } | |
| 857 | |
| 858 { SimpleContext context; | |
| 859 context.Check("let x = 1; x", | |
| 860 EXPECT_RESULT, Number::New(1)); | |
| 861 context.Check("let x = 2; x", | |
| 862 EXPECT_ERROR); | |
| 863 } | |
| 864 | |
| 865 { SimpleContext context; | |
| 866 context.Check("let x = 1; x", | |
| 867 EXPECT_RESULT, Number::New(1)); | |
| 868 context.Check("const x = 2; x", | |
| 869 EXPECT_ERROR); | |
| 870 } | |
| 871 | |
| 872 { SimpleContext context; | |
| 873 context.Check("let x = 1; x", | |
| 874 EXPECT_RESULT, Number::New(1)); | |
| 875 context.Check("function x() { return 2 }; x()", | |
| 876 EXPECT_ERROR); | |
| 877 } | |
| 878 | |
| 879 { SimpleContext context; | |
| 880 context.Check("const x = 1; x", | |
| 881 EXPECT_RESULT, Number::New(1)); | |
| 882 context.Check("var x = 2; x", | |
| 883 EXPECT_ERROR); | |
| 884 } | |
| 885 | |
| 886 { SimpleContext context; | |
| 887 context.Check("const x = 1; x", | |
| 888 EXPECT_RESULT, Number::New(1)); | |
| 889 context.Check("let x = 2; x", | |
| 890 EXPECT_ERROR); | |
| 891 } | |
| 892 | |
| 893 { SimpleContext context; | |
| 894 context.Check("const x = 1; x", | |
| 895 EXPECT_RESULT, Number::New(1)); | |
| 896 context.Check("const x = 2; x", | |
| 897 EXPECT_ERROR); | |
| 898 } | |
| 899 | |
| 900 { SimpleContext context; | |
| 901 context.Check("const x = 1; x", | |
| 902 EXPECT_RESULT, Number::New(1)); | |
| 903 context.Check("function x() { return 2 }; x()", | |
| 904 EXPECT_ERROR); | |
| 905 } | 804 } |
| 906 } | 805 } |
| 806 | |
| 807 | |
| 808 | |
|
Michael Starzinger
2012/11/20 12:05:05
Drop the third empty newline.
rossberg
2012/11/20 17:23:45
Done.
| |
| 809 TEST(CrossScriptConflicts) { | |
| 810 i::FLAG_use_strict = true; | |
| 811 i::FLAG_harmony_scoping = true; | |
| 812 i::FLAG_harmony_modules = true; | |
| 813 | |
| 814 HandleScope scope; | |
| 815 | |
| 816 const char* firsts[] = { | |
| 817 "var x = 1; x", | |
| 818 "function x() { return 1 }; x()", | |
| 819 "let x = 1; x", | |
| 820 "const x = 1; x", | |
| 821 "module x { export let a = 1 }; x.a", | |
| 822 NULL | |
| 823 }; | |
| 824 const char* seconds[] = { | |
| 825 "var x = 2; x", | |
| 826 "function x() { return 2 }; x()", | |
| 827 "let x = 2; x", | |
| 828 "const x = 2; x", | |
| 829 "module x { export let a = 2 }; x.a", | |
| 830 NULL | |
| 831 }; | |
| 832 | |
| 833 for (int i = 0; firsts[i] != NULL; ++i) { | |
| 834 for (int j = 0; seconds[j] != NULL; ++j) { | |
| 835 SimpleContext context; | |
| 836 context.Check(firsts[i], EXPECT_RESULT, Number::New(1)); | |
| 837 // TODO(rossberg): All tests should actually be errors in Harmony, | |
| 838 // but we currently do not detect the cases where the first declaration | |
| 839 // is not lexical. | |
| 840 context.Check(seconds[j], | |
| 841 i < 2 ? EXPECT_RESULT : EXPECT_ERROR, Number::New(2)); | |
| 842 } | |
| 843 } | |
| 844 } | |
| OLD | NEW |