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 TEST(CrossScriptReferences) { |
738 HandleScope scope; | 738 HandleScope scope; |
739 | 739 |
740 { SimpleContext context; | 740 { SimpleContext context; |
741 context.Check("var x = 1; x", | 741 context.Check("var x = 1; x", |
742 EXPECT_RESULT, Number::New(1)); | 742 EXPECT_RESULT, Number::New(1)); |
743 context.Check("var x = 2; x", | 743 context.Check("var x = 2; x", |
744 EXPECT_RESULT, Number::New(2)); | 744 EXPECT_RESULT, Number::New(2)); |
745 context.Check("const x = 3; x", | 745 context.Check("const x = 3; x", |
746 EXPECT_RESULT, Number::New(3)); | 746 EXPECT_RESULT, Number::New(3)); |
747 context.Check("const x = 4; x", | 747 context.Check("const x = 4; x", |
(...skipping 17 matching lines...) Expand all Loading... |
765 EXPECT_RESULT, Number::New(1)); | 765 EXPECT_RESULT, Number::New(1)); |
766 context.Check("x = 4; x", // assignment ignored | 766 context.Check("x = 4; x", // assignment ignored |
767 EXPECT_RESULT, Number::New(1)); | 767 EXPECT_RESULT, Number::New(1)); |
768 context.Check("var x = 5; x", // assignment ignored | 768 context.Check("var x = 5; x", // assignment ignored |
769 EXPECT_RESULT, Number::New(1)); | 769 EXPECT_RESULT, Number::New(1)); |
770 context.Check("this.x", | 770 context.Check("this.x", |
771 EXPECT_RESULT, Number::New(1)); | 771 EXPECT_RESULT, Number::New(1)); |
772 context.Check("function x() { return 7 }; x", | 772 context.Check("function x() { return 7 }; x", |
773 EXPECT_EXCEPTION); | 773 EXPECT_EXCEPTION); |
774 } | 774 } |
| 775 } |
775 | 776 |
| 777 |
| 778 TEST(CrossScriptReferencesHarmony) { |
776 i::FLAG_use_strict = true; | 779 i::FLAG_use_strict = true; |
777 i::FLAG_harmony_scoping = true; | 780 i::FLAG_harmony_scoping = true; |
| 781 i::FLAG_harmony_modules = true; |
778 | 782 |
779 { SimpleContext context; | 783 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 | 784 |
788 { SimpleContext context; | 785 const char* decs[] = { |
789 context.Check("function x() { return 4 }; x()", | 786 "var x = 1; x", "x", "this.x", |
790 EXPECT_RESULT, Number::New(4)); | 787 "function x() { return 1 }; x()", "x()", "this.x()", |
791 context.Check("x()", | 788 "let x = 1; x", "x", "this.x", |
792 EXPECT_RESULT, Number::New(4)); | 789 "const x = 1; x", "x", "this.x", |
793 context.Check("this.x()", | 790 "module x { export let a = 1 }; x.a", "x.a", "this.x.a", |
794 EXPECT_RESULT, Number::New(4)); | 791 NULL |
795 } | 792 }; |
796 | 793 |
797 { SimpleContext context; | 794 for (int i = 0; decs[i] != NULL; i += 3) { |
798 context.Check("let x = 2; x", | 795 SimpleContext context; |
799 EXPECT_RESULT, Number::New(2)); | 796 context.Check(decs[i], EXPECT_RESULT, Number::New(1)); |
800 context.Check("x", | 797 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 | 798 // TODO(rossberg): The current ES6 draft spec does not reflect lexical |
803 // bindings on the global object. However, this will probably change, in | 799 // bindings on the global object. However, this will probably change, in |
804 // which case we reactivate the following test. | 800 // which case we reactivate the following test. |
805 // context.Check("this.x", | 801 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 } | 802 } |
906 } | 803 } |
| 804 |
| 805 |
| 806 TEST(CrossScriptConflicts) { |
| 807 i::FLAG_use_strict = true; |
| 808 i::FLAG_harmony_scoping = true; |
| 809 i::FLAG_harmony_modules = true; |
| 810 |
| 811 HandleScope scope; |
| 812 |
| 813 const char* firsts[] = { |
| 814 "var x = 1; x", |
| 815 "function x() { return 1 }; x()", |
| 816 "let x = 1; x", |
| 817 "const x = 1; x", |
| 818 "module x { export let a = 1 }; x.a", |
| 819 NULL |
| 820 }; |
| 821 const char* seconds[] = { |
| 822 "var x = 2; x", |
| 823 "function x() { return 2 }; x()", |
| 824 "let x = 2; x", |
| 825 "const x = 2; x", |
| 826 "module x { export let a = 2 }; x.a", |
| 827 NULL |
| 828 }; |
| 829 |
| 830 for (int i = 0; firsts[i] != NULL; ++i) { |
| 831 for (int j = 0; seconds[j] != NULL; ++j) { |
| 832 SimpleContext context; |
| 833 context.Check(firsts[i], EXPECT_RESULT, Number::New(1)); |
| 834 // TODO(rossberg): All tests should actually be errors in Harmony, |
| 835 // but we currently do not detect the cases where the first declaration |
| 836 // is not lexical. |
| 837 context.Check(seconds[j], |
| 838 i < 2 ? EXPECT_RESULT : EXPECT_ERROR, Number::New(2)); |
| 839 } |
| 840 } |
| 841 } |
OLD | NEW |