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

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

Issue 716523002: More tests for toplevel lexical scope (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 1 month 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 | « no previous file | no next file » | 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 665 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 context.Check("let z = 1; z", EXPECT_RESULT, Number::New(isolate, 1)); 676 context.Check("let z = 1; z", EXPECT_RESULT, Number::New(isolate, 1));
677 context.Check("let x = 4; x", EXPECT_RESULT, Number::New(isolate, 4)); 677 context.Check("let x = 4; x", EXPECT_RESULT, Number::New(isolate, 4));
678 } 678 }
679 context.Check("let y = 2; x", EXPECT_RESULT, 679 context.Check("let y = 2; x", EXPECT_RESULT,
680 Number::New(isolate, cond ? 1 : 4)); 680 Number::New(isolate, cond ? 1 : 4));
681 } 681 }
682 } 682 }
683 683
684 684
685 TEST(CrossScriptReferencesHarmony) { 685 TEST(CrossScriptReferencesHarmony) {
686 i::FLAG_harmony_scoping = true;
687 i::FLAG_harmony_modules = true;
688
689 v8::Isolate* isolate = CcTest::isolate();
690 HandleScope scope(isolate);
691
692 // Check that simple cross-script global scope access works.
693 const char* decs[] = {
694 "'use strict'; var x = 1; x", "x",
695 "'use strict'; function x() { return 1 }; x()", "x()",
696 "'use strict'; let x = 1; x", "x",
697 "'use strict'; const x = 1; x", "x",
698 "'use strict'; module x { export let a = 1 }; x.a", "x.a",
699 NULL
700 };
701
702 for (int i = 0; decs[i] != NULL; i += 2) {
703 SimpleContext context;
704 context.Check(decs[i], EXPECT_RESULT, Number::New(isolate, 1));
705 context.Check(decs[i+1], EXPECT_RESULT, Number::New(isolate, 1));
706 }
707
708 // Check that cross-script global scope access works with late declarations.
709 {
710 SimpleContext context;
711 context.Check("function d0() { return x0 }", // dynamic lookup
712 EXPECT_RESULT, Undefined(isolate));
713 context.Check("this.x0 = -1;"
714 "d0()",
715 EXPECT_RESULT, Number::New(isolate, -1));
716 context.Check("'use strict';"
717 "function f0() { let y = 10; return x0 + y }"
718 "function g0() { let y = 10; return eval('x0 + y') }"
719 "function h0() { let y = 10; return (1,eval)('x0') + y }"
720 "x0 + f0() + g0() + h0()",
721 EXPECT_RESULT, Number::New(isolate, 26));
722
723 context.Check("'use strict';"
724 "let x1 = 1;"
725 "function f1() { let y = 10; return x1 + y }"
726 "function g1() { let y = 10; return eval('x1 + y') }"
727 "function h1() { let y = 10; return (1,eval)('x1') + y }"
728 "function i1() { "
729 " let y = 10; return (typeof x2 === 'undefined' ? 0 : 2) + y"
730 "}"
731 "function j1() { let y = 10; return eval('x2 + y') }"
732 "function k1() { let y = 10; return (1,eval)('x2') + y }"
733 "function cl() { "
734 " let y = 10; "
735 " return { "
736 " f: function(){ return x1 + y },"
737 " g: function(){ return eval('x1 + y') },"
738 " h: function(){ return (1,eval)('x1') + y },"
739 " i: function(){"
740 " return (typeof x2 == 'undefined' ? 0 : 2) + y"
741 " },"
742 " j: function(){ return eval('x2 + y') },"
743 " k: function(){ return (1,eval)('x2') + y },"
744 " }"
745 "}"
746 "let o = cl();"
747 "x1 + eval('x1') + (1,eval)('x1') + f1() + g1() + h1();",
748 EXPECT_RESULT, Number::New(isolate, 36));
749 context.Check("x1 + eval('x1') + (1,eval)('x1') + f1() + g1() + h1();",
750 EXPECT_RESULT, Number::New(isolate, 36));
751 context.Check("o.f() + o.g() + o.h();",
752 EXPECT_RESULT, Number::New(isolate, 33));
753 context.Check("i1() + o.i();",
754 EXPECT_RESULT, Number::New(isolate, 20));
755
756 context.Check("'use strict';"
757 "let x2 = 2;"
758 "function f2() { let y = 20; return x2 + y }"
759 "function g2() { let y = 20; return eval('x2 + y') }"
760 "function h2() { let y = 20; return (1,eval)('x2') + y }"
761 "function i2() { let y = 20; return x1 + y }"
762 "function j2() { let y = 20; return eval('x1 + y') }"
763 "function k2() { let y = 20; return (1,eval)('x1') + y }"
764 "x2 + eval('x2') + (1,eval)('x2') + f2() + g2() + h2();",
765 EXPECT_RESULT, Number::New(isolate, 72));
766 context.Check("x1 + eval('x1') + (1,eval)('x1') + f1() + g1() + h1();",
767 EXPECT_RESULT, Number::New(isolate, 36));
768 context.Check("i1() + j1() + k1();",
769 EXPECT_RESULT, Number::New(isolate, 36));
770 context.Check("i2() + j2() + k2();",
771 EXPECT_RESULT, Number::New(isolate, 63));
772 context.Check("o.f() + o.g() + o.h();",
773 EXPECT_RESULT, Number::New(isolate, 33));
774 context.Check("o.i() + o.j() + o.k();",
775 EXPECT_RESULT, Number::New(isolate, 36));
776 context.Check("i1() + o.i();",
777 EXPECT_RESULT, Number::New(isolate, 24));
778
779 context.Check("'use strict';"
780 "let x0 = 100;"
781 "x0 + eval('x0') + (1,eval)('x0') + "
782 " d0() + f0() + g0() + h0();",
783 EXPECT_RESULT, Number::New(isolate, 730));
784 context.Check("x0 + eval('x0') + (1,eval)('x0') + "
785 " d0() + f0() + g0() + h0();",
786 EXPECT_RESULT, Number::New(isolate, 730));
787 context.Check("delete this.x0;"
788 "x0 + eval('x0') + (1,eval)('x0') + "
789 " d0() + f0() + g0() + h0();",
790 EXPECT_RESULT, Number::New(isolate, 730));
791 context.Check("this.x1 = 666;"
792 "x1 + eval('x1') + (1,eval)('x1') + f1() + g1() + h1();",
793 EXPECT_RESULT, Number::New(isolate, 36));
794 context.Check("delete this.x1;"
795 "x1 + eval('x1') + (1,eval)('x1') + f1() + g1() + h1();",
796 EXPECT_RESULT, Number::New(isolate, 36));
797 }
798
799 // Check that caching does respect scopes.
800 {
801 SimpleContext context;
802 const char* script1 = "(function(){ return y1 })()";
803 const char* script2 = "(function(){ return y2 })()";
804
805 context.Check(script1, EXPECT_EXCEPTION);
806 context.Check("this.y1 = 1; this.y2 = 2; 0;",
807 EXPECT_RESULT, Number::New(isolate, 0));
808 context.Check(script1,
809 EXPECT_RESULT, Number::New(isolate, 1));
810 context.Check("'use strict'; let y1 = 3; 0;",
811 EXPECT_RESULT, Number::New(isolate, 0));
812 // TODO(dslomov): still returns 1 not 3
813 // context.Check(script1,
814 // EXPECT_RESULT, Number::New(isolate, 3));
815 context.Check("y1 = 4;",
816 EXPECT_RESULT, Number::New(isolate, 4));
817 // TODO(dslomov): still returns 1 not 4
818 // context.Check(script1,
819 // EXPECT_RESULT, Number::New(isolate, 4));
820
821 context.Check(script2,
822 EXPECT_RESULT, Number::New(isolate, 2));
823 context.Check("'use strict'; let y2 = 5; 0;",
824 EXPECT_RESULT, Number::New(isolate, 0));
825 // TODO(dslomov): still returns 1 not 4
826 // context.Check(script1,
827 // EXPECT_RESULT, Number::New(isolate, 4));
828 // TODO(dslomov): still returns 2 not 5
829 // context.Check(script2,
830 // EXPECT_RESULT, Number::New(isolate, 5));
831 }
832 }
833
834
835 TEST(GlobalLexicalOSR) {
686 i::FLAG_use_strict = true; 836 i::FLAG_use_strict = true;
687 i::FLAG_harmony_scoping = true; 837 i::FLAG_harmony_scoping = true;
688 i::FLAG_harmony_modules = true; 838 i::FLAG_harmony_modules = true;
689 839
690 v8::Isolate* isolate = CcTest::isolate(); 840 v8::Isolate* isolate = CcTest::isolate();
691 HandleScope scope(isolate); 841 HandleScope scope(isolate);
842 SimpleContext context;
692 843
693 const char* decs[] = { 844 context.Check("'use strict';"
694 "var x = 1; x", "x", "this.x", 845 "let x = 1; x;",
695 "function x() { return 1 }; x()", "x()", "this.x()", 846 EXPECT_RESULT, Number::New(isolate, 1));
696 "let x = 1; x", "x", "this.x", 847 context.Check("'use strict';"
697 "const x = 1; x", "x", "this.x", 848 "let y = 2*x;"
698 "module x { export let a = 1 }; x.a", "x.a", "this.x.a", 849 "++x;"
699 NULL 850 "let z = 0;"
700 }; 851 "const limit = 100000;"
701 852 "for (var i = 0; i < limit; ++i) {"
702 for (int i = 0; decs[i] != NULL; i += 3) { 853 " z += x + y;"
703 SimpleContext context; 854 "}"
704 context.Check(decs[i], EXPECT_RESULT, Number::New(isolate, 1)); 855 "z;",
705 context.Check(decs[i+1], EXPECT_RESULT, Number::New(isolate, 1)); 856 EXPECT_RESULT, Number::New(isolate, 400000));
706 // TODO(rossberg): The current ES6 draft spec does not reflect lexical
707 // bindings on the global object. However, this will probably change, in
708 // which case we reactivate the following test.
709 if (i/3 < 2) {
710 context.Check(decs[i+2], EXPECT_RESULT, Number::New(isolate, 1));
711 }
712 }
713 } 857 }
714 858
715 859
716 TEST(CrossScriptConflicts) { 860 TEST(CrossScriptConflicts) {
717 i::FLAG_use_strict = true; 861 i::FLAG_use_strict = true;
718 i::FLAG_harmony_scoping = true; 862 i::FLAG_harmony_scoping = true;
719 i::FLAG_harmony_modules = true; 863 i::FLAG_harmony_modules = true;
720 864
721 HandleScope scope(CcTest::isolate()); 865 HandleScope scope(CcTest::isolate());
722 866
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 EXPECT_RESULT, Number::New(CcTest::isolate(), 1)); 999 EXPECT_RESULT, Number::New(CcTest::isolate(), 1));
856 context.Check( 1000 context.Check(
857 "'use strict';" 1001 "'use strict';"
858 "g({});x", 1002 "g({});x",
859 EXPECT_RESULT, Number::New(CcTest::isolate(), 15)); 1003 EXPECT_RESULT, Number::New(CcTest::isolate(), 15));
860 context.Check("h({})", EXPECT_RESULT, number_string); 1004 context.Check("h({})", EXPECT_RESULT, number_string);
861 context.Check("f({})", EXPECT_RESULT, Number::New(CcTest::isolate(), 15)); 1005 context.Check("f({})", EXPECT_RESULT, Number::New(CcTest::isolate(), 15));
862 context.Check("h({})", EXPECT_RESULT, number_string); 1006 context.Check("h({})", EXPECT_RESULT, number_string);
863 } 1007 }
864 } 1008 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698