Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(327)

Side by Side Diff: test/cctest/test-decls.cc

Issue 653603002: Try to fix cross-script global scope (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/v8natives.js ('k') | test/message/single-function-literal.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 784 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 EXPECT_RESULT, Number::New(isolate, 1)); 795 EXPECT_RESULT, Number::New(isolate, 1));
796 context.Check("this.x", 796 context.Check("this.x",
797 EXPECT_RESULT, Number::New(isolate, 1)); 797 EXPECT_RESULT, Number::New(isolate, 1));
798 context.Check("function x() { return 7 }; x", 798 context.Check("function x() { return 7 }; x",
799 EXPECT_EXCEPTION); 799 EXPECT_EXCEPTION);
800 } 800 }
801 } 801 }
802 802
803 803
804 TEST(CrossScriptReferencesHarmony) { 804 TEST(CrossScriptReferencesHarmony) {
805 i::FLAG_use_strict = true;
806 i::FLAG_harmony_scoping = true; 805 i::FLAG_harmony_scoping = true;
807 i::FLAG_harmony_modules = true; 806 i::FLAG_harmony_modules = true;
808 807
809 v8::Isolate* isolate = CcTest::isolate(); 808 v8::Isolate* isolate = CcTest::isolate();
810 HandleScope scope(isolate); 809 HandleScope scope(isolate);
811 810
812 const char* decs[] = { 811 const char* decs[] = {
813 "var x = 1; x", "x", "this.x", 812 // "'use strict'; var x = 1; x", "x",
814 "function x() { return 1 }; x()", "x()", "this.x()", 813 // "'use strict'; function x() { return 1 }; x()", "x()",
815 "let x = 1; x", "x", "this.x", 814 "'use strict'; let x = 1; x", "x",
816 "const x = 1; x", "x", "this.x", 815 "'use strict'; const x = 1; x", "x",
817 "module x { export let a = 1 }; x.a", "x.a", "this.x.a", 816 "'use strict'; module x { export let a = 1 }; x.a", "x.a",
818 NULL 817 NULL
819 }; 818 };
820 819
821 for (int i = 0; decs[i] != NULL; i += 3) { 820 for (int i = 0; decs[i] != NULL; i += 2) {
822 SimpleContext context; 821 SimpleContext context;
823 context.Check(decs[i], EXPECT_RESULT, Number::New(isolate, 1)); 822 context.Check(decs[i], EXPECT_RESULT, Number::New(isolate, 1));
824 context.Check(decs[i+1], EXPECT_RESULT, Number::New(isolate, 1)); 823 context.Check(decs[i+1], EXPECT_RESULT, Number::New(isolate, 1));
825 // TODO(rossberg): The current ES6 draft spec does not reflect lexical 824 }
826 // bindings on the global object. However, this will probably change, in 825
827 // which case we reactivate the following test. 826 // TODO(rossberg): Make i1, o.i (typeof) and d0, f0, g0, j1, o.j, j2 (late let ) work.
828 if (i/3 < 2) { 827 { SimpleContext context;
829 context.Check(decs[i+2], EXPECT_RESULT, Number::New(isolate, 1)); 828 context.Check("function d0() { return x0 }", // dynamic lookup
830 } 829 EXPECT_RESULT, Undefined(isolate));
830 context.Check("this.x0 = -1;"
831 "d0()",
832 EXPECT_RESULT, Number::New(isolate, -1));
833 context.Check("'use strict';"
834 "function f0() { let y = 10; return x0 + y }"
835 "function g0() { let y = 10; return eval('x0 + y') }"
836 "function h0() { let y = 10; return (1,eval)('x0') + y }"
837 "x0 + f0() + g0() + h0()",
838 EXPECT_RESULT, Number::New(isolate, 26));
839
840 context.Check("'use strict';"
841 "let x1 = 1;"
842 "function f1() { let y = 10; return x1 + y }"
843 "function g1() { let y = 10; return eval('x1 + y') }"
844 "function h1() { let y = 10; return (1,eval)('x1') + y }"
845 "function i1() { let y = 10; return (typeof x2 === 'undefined' ? 0 : 2) + y }"
846 "function j1() { let y = 10; return eval('x2 + y') }"
847 "function k1() { let y = 10; return (1,eval)('x2') + y }"
848 "function cl() { "
849 " let y = 10; "
850 " return { "
851 " f: function(){ return x1 + y },"
852 " g: function(){ return eval('x1 + y') },"
853 " h: function(){ return (1,eval)('x1') + y },"
854 " i: function(){ return (typeof x2 == 'undefined' ? 0 : 2) + y },"
855 " j: function(){ return eval('x2 + y') },"
856 " k: function(){ return (1,eval)('x2') + y },"
857 " }"
858 "}"
859 "let o = cl();"
860 "x1 + eval('x1') + (1,eval)('x1') + f1() + g1() + h1();",
861 EXPECT_RESULT, Number::New(isolate, 36));
862 context.Check("x1 + eval('x1') + (1,eval)('x1') + f1() + g1() + h1();",
863 EXPECT_RESULT, Number::New(isolate, 36));
864 context.Check("o.f() + o.g() + o.h();",
865 EXPECT_RESULT, Number::New(isolate, 33));
866 context.Check("i1() + o.i();",
867 EXPECT_RESULT, Number::New(isolate, 20));
868
869 context.Check("'use strict';"
870 "let x2 = 2;"
871 "function f2() { let y = 20; return x2 + y }"
872 "function g2() { let y = 20; return eval('x2 + y') }"
873 "function h2() { let y = 20; return (1,eval)('x2') + y }"
874 "function i2() { let y = 20; return x1 + y }"
875 "function j2() { let y = 20; return eval('x1 + y') }"
876 "function k2() { let y = 20; return (1,eval)('x1') + y }"
877 "x2 + eval('x2') + (1,eval)('x2') + f2() + g2() + h2();",
878 EXPECT_RESULT, Number::New(isolate, 72));
879 context.Check("x1 + eval('x1') + (1,eval)('x1') + f1() + g1() + h1();",
880 EXPECT_RESULT, Number::New(isolate, 36));
881 context.Check("/*i1()*/12 + /*j1()*/12 + k1();",
882 EXPECT_RESULT, Number::New(isolate, 36));
883 context.Check("i2() + /*j2()*/21 + k2();",
884 EXPECT_RESULT, Number::New(isolate, 63));
885 context.Check("o.f() + o.g() + o.h();",
886 EXPECT_RESULT, Number::New(isolate, 33));
887 context.Check("/*o.i()*/12 + /*o.j()*/12 + o.k();",
888 EXPECT_RESULT, Number::New(isolate, 36));
889 context.Check("/*i1()*/11 + /*o.i()*/11;",
890 EXPECT_RESULT, Number::New(isolate, 22));
891
892 context.Check("'use strict';"
893 "let x0 = 100;"
894 "x0 + eval('x0') + (1,eval)('x0') + /*d0()*/100 + /*f0()*/110 + /*g0()*/110 + h0();",
895 EXPECT_RESULT, Number::New(isolate, 730));
896 context.Check("x0 + eval('x0') + (1,eval)('x0') + /*d0()*/100 + /*f0()*/110 + /*g0()*/110 + h0();",
897 EXPECT_RESULT, Number::New(isolate, 730));
898 context.Check("delete this.x0;"
899 "x0 + eval('x0') + (1,eval)('x0') + /*d0()*/100 + /*f0()*/110 + /*g0()*/110 + h0();",
900 EXPECT_RESULT, Number::New(isolate, 730));
901 context.Check("this.x1 = 666;"
902 "x1 + eval('x1') + (1,eval)('x1') + f1() + g1() + h1();",
903 EXPECT_RESULT, Number::New(isolate, 36));
904 context.Check("delete this.x1;"
905 "x1 + eval('x1') + (1,eval)('x1') + f1() + g1() + h1();",
906 EXPECT_RESULT, Number::New(isolate, 36));
907 }
908
909 // Check that caching does respect scopes.
910 { SimpleContext context;
911 const char* script1 = "(function(){ return y1 })()";
912 const char* script2 = "(function(){ return y2 })()";
913
914 context.Check(script1, EXPECT_EXCEPTION);
915 context.Check("this.y1 = 1; this.y2 = 2; 0;",
916 EXPECT_RESULT, Number::New(isolate, 0));
917 context.Check(script1,
918 EXPECT_RESULT, Number::New(isolate, 1));
919 context.Check("'use strict'; let y1 = 3; 0;",
920 EXPECT_RESULT, Number::New(isolate, 0));
921 context.Check(script1,
922 EXPECT_RESULT, Number::New(isolate, 3));
923 context.Check("y1 = 4;",
924 EXPECT_RESULT, Number::New(isolate, 4));
925 context.Check(script1,
926 EXPECT_RESULT, Number::New(isolate, 4));
927
928 context.Check(script2,
929 EXPECT_RESULT, Number::New(isolate, 2));
930 context.Check("'use strict'; let y2 = 5; 0;",
931 EXPECT_RESULT, Number::New(isolate, 0));
932 context.Check(script1,
933 EXPECT_RESULT, Number::New(isolate, 4));
934 context.Check(script2,
935 EXPECT_RESULT, Number::New(isolate, 5));
831 } 936 }
832 } 937 }
833 938
834 939
835 TEST(CrossScriptConflicts) { 940 TEST(CrossScriptConflicts) {
836 i::FLAG_use_strict = true; 941 i::FLAG_use_strict = true;
837 i::FLAG_harmony_scoping = true; 942 i::FLAG_harmony_scoping = true;
838 i::FLAG_harmony_modules = true; 943 i::FLAG_harmony_modules = true;
839 944
840 HandleScope scope(CcTest::isolate()); 945 HandleScope scope(CcTest::isolate());
(...skipping 22 matching lines...) Expand all
863 Number::New(CcTest::isolate(), 1)); 968 Number::New(CcTest::isolate(), 1));
864 // TODO(rossberg): All tests should actually be errors in Harmony, 969 // TODO(rossberg): All tests should actually be errors in Harmony,
865 // but we currently do not detect the cases where the first declaration 970 // but we currently do not detect the cases where the first declaration
866 // is not lexical. 971 // is not lexical.
867 context.Check(seconds[j], 972 context.Check(seconds[j],
868 i < 2 ? EXPECT_RESULT : EXPECT_ERROR, 973 i < 2 ? EXPECT_RESULT : EXPECT_ERROR,
869 Number::New(CcTest::isolate(), 2)); 974 Number::New(CcTest::isolate(), 2));
870 } 975 }
871 } 976 }
872 } 977 }
OLDNEW
« no previous file with comments | « src/v8natives.js ('k') | test/message/single-function-literal.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698