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 826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
837 | 837 |
838 { | 838 { |
839 SimpleContext context; | 839 SimpleContext context; |
840 Local<String> undefined_string = String::NewFromUtf8( | 840 Local<String> undefined_string = String::NewFromUtf8( |
841 CcTest::isolate(), "undefined", String::kInternalizedString); | 841 CcTest::isolate(), "undefined", String::kInternalizedString); |
842 Local<String> number_string = String::NewFromUtf8( | 842 Local<String> number_string = String::NewFromUtf8( |
843 CcTest::isolate(), "number", String::kInternalizedString); | 843 CcTest::isolate(), "number", String::kInternalizedString); |
844 | 844 |
845 context.Check( | 845 context.Check( |
846 "function f(o) { return x; }" | 846 "function f(o) { return x; }" |
847 "function g(o) { x = 15; }" | 847 "function g(v) { x = v; }" |
848 "function h(o) { return typeof x; }", | 848 "function h(o) { return typeof x; }", |
849 EXPECT_RESULT, Undefined(CcTest::isolate())); | 849 EXPECT_RESULT, Undefined(CcTest::isolate())); |
850 context.Check("h({})", EXPECT_RESULT, undefined_string); | 850 context.Check("h({})", EXPECT_RESULT, undefined_string); |
851 context.Check( | 851 context.Check( |
852 "'use strict';" | 852 "'use strict';" |
853 "let x = 1;" | 853 "let x = 1;" |
854 "f({})", | 854 "f({})", |
855 EXPECT_RESULT, Number::New(CcTest::isolate(), 1)); | 855 EXPECT_RESULT, Number::New(CcTest::isolate(), 1)); |
856 context.Check( | 856 context.Check( |
857 "'use strict';" | 857 "'use strict';" |
858 "g({});x", | 858 "g(15);x", |
859 EXPECT_RESULT, Number::New(CcTest::isolate(), 15)); | 859 EXPECT_RESULT, Number::New(CcTest::isolate(), 15)); |
860 context.Check("h({})", EXPECT_RESULT, number_string); | 860 context.Check("h({})", EXPECT_RESULT, number_string); |
861 context.Check("f({})", EXPECT_RESULT, Number::New(CcTest::isolate(), 15)); | 861 context.Check("f({})", EXPECT_RESULT, Number::New(CcTest::isolate(), 15)); |
862 context.Check("h({})", EXPECT_RESULT, number_string); | 862 context.Check("h({})", EXPECT_RESULT, number_string); |
863 } | 863 } |
864 } | 864 } |
865 | |
866 | |
867 TEST(CrossScriptICs) { | |
868 i::FLAG_harmony_scoping = true; | |
869 i::FLAG_allow_natives_syntax = true; | |
870 | |
871 HandleScope handle_scope(CcTest::isolate()); | |
872 | |
873 { | |
874 SimpleContext context; | |
875 context.Check( | |
876 "x = 15;" | |
877 "function f() { return x; }" | |
878 "function g() { return x; }" | |
879 "f()", | |
880 EXPECT_RESULT, Number::New(CcTest::isolate(), 15)); | |
881 context.Check( | |
882 "'use strict';" | |
883 "let x = 5;" | |
884 "f()", | |
885 EXPECT_RESULT, Number::New(CcTest::isolate(), 5)); | |
886 for (int k = 0; k < 3; k++) { | |
887 context.Check("g()", EXPECT_RESULT, Number::New(CcTest::isolate(), 5)); | |
888 } | |
889 for (int k = 0; k < 3; k++) { | |
890 context.Check("f()", EXPECT_RESULT, Number::New(CcTest::isolate(), 5)); | |
891 } | |
892 context.Check("%OptimizeFunctionOnNextCall(g); g()", EXPECT_RESULT, | |
Igor Sheludko
2014/11/11 09:49:51
What about also trying to optimize f() and g() bef
Dmitry Lomov (no reviews)
2014/11/11 11:16:20
Done.
| |
893 Number::New(CcTest::isolate(), 5)); | |
894 context.Check("%OptimizeFunctionOnNextCall(f); f()", EXPECT_RESULT, | |
895 Number::New(CcTest::isolate(), 5)); | |
896 } | |
897 } | |
OLD | NEW |