OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/execution.h" | 7 #include "src/execution.h" |
8 #include "src/handles.h" | 8 #include "src/handles.h" |
9 #include "src/interpreter/bytecode-array-builder.h" | 9 #include "src/interpreter/bytecode-array-builder.h" |
10 #include "src/interpreter/interpreter.h" | 10 #include "src/interpreter/interpreter.h" |
(...skipping 1926 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1937 | 1937 |
1938 Handle<Object> return_val = callable().ToHandleChecked(); | 1938 Handle<Object> return_val = callable().ToHandleChecked(); |
1939 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(15)); | 1939 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(15)); |
1940 } | 1940 } |
1941 | 1941 |
1942 | 1942 |
1943 TEST(InterpreterContextVariables) { | 1943 TEST(InterpreterContextVariables) { |
1944 HandleAndZoneScope handles; | 1944 HandleAndZoneScope handles; |
1945 i::Isolate* isolate = handles.main_isolate(); | 1945 i::Isolate* isolate = handles.main_isolate(); |
1946 | 1946 |
1947 std::pair<const char*, Handle<Object>> context_vars[] = { | 1947 std::ostringstream unique_vars; |
| 1948 for (int i = 0; i < 250; i++) { |
| 1949 unique_vars << "var a" << i << " = 0;"; |
| 1950 } |
| 1951 std::pair<std::string, Handle<Object>> context_vars[] = { |
1948 std::make_pair("var a; (function() { a = 1; })(); return a;", | 1952 std::make_pair("var a; (function() { a = 1; })(); return a;", |
1949 handle(Smi::FromInt(1), isolate)), | 1953 handle(Smi::FromInt(1), isolate)), |
1950 std::make_pair("var a = 10; (function() { a; })(); return a;", | 1954 std::make_pair("var a = 10; (function() { a; })(); return a;", |
1951 handle(Smi::FromInt(10), isolate)), | 1955 handle(Smi::FromInt(10), isolate)), |
1952 std::make_pair("var a = 20; var b = 30;\n" | 1956 std::make_pair("var a = 20; var b = 30;\n" |
1953 "return (function() { return a + b; })();", | 1957 "return (function() { return a + b; })();", |
1954 handle(Smi::FromInt(50), isolate)), | 1958 handle(Smi::FromInt(50), isolate)), |
1955 std::make_pair("'use strict'; let a = 1;\n" | 1959 std::make_pair("'use strict'; let a = 1;\n" |
1956 "{ let b = 2; return (function() { return a + b; })(); }", | 1960 "{ let b = 2; return (function() { return a + b; })(); }", |
1957 handle(Smi::FromInt(3), isolate)), | 1961 handle(Smi::FromInt(3), isolate)), |
1958 std::make_pair("'use strict'; let a = 10;\n" | 1962 std::make_pair("'use strict'; let a = 10;\n" |
1959 "{ let b = 20; var c = function() { [a, b] };\n" | 1963 "{ let b = 20; var c = function() { [a, b] };\n" |
1960 " return a + b; }", | 1964 " return a + b; }", |
1961 handle(Smi::FromInt(30), isolate)), | 1965 handle(Smi::FromInt(30), isolate)), |
| 1966 std::make_pair("'use strict';" + unique_vars.str() + |
| 1967 "eval(); var b = 100; return b;", |
| 1968 handle(Smi::FromInt(100), isolate)), |
1962 }; | 1969 }; |
1963 | 1970 |
1964 for (size_t i = 0; i < arraysize(context_vars); i++) { | 1971 for (size_t i = 0; i < arraysize(context_vars); i++) { |
1965 std::string source(InterpreterTester::SourceForBody(context_vars[i].first)); | 1972 std::string source( |
| 1973 InterpreterTester::SourceForBody(context_vars[i].first.c_str())); |
1966 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 1974 InterpreterTester tester(handles.main_isolate(), source.c_str()); |
1967 auto callable = tester.GetCallable<>(); | 1975 auto callable = tester.GetCallable<>(); |
1968 | 1976 |
1969 Handle<i::Object> return_value = callable().ToHandleChecked(); | 1977 Handle<i::Object> return_value = callable().ToHandleChecked(); |
1970 CHECK(return_value->SameValue(*context_vars[i].second)); | 1978 CHECK(return_value->SameValue(*context_vars[i].second)); |
1971 } | 1979 } |
1972 } | 1980 } |
1973 | 1981 |
1974 | 1982 |
1975 TEST(InterpreterContextParameters) { | 1983 TEST(InterpreterContextParameters) { |
(...skipping 1534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3510 auto callable = tester.GetCallable<>(); | 3518 auto callable = tester.GetCallable<>(); |
3511 | 3519 |
3512 Handle<i::Object> return_value = callable().ToHandleChecked(); | 3520 Handle<i::Object> return_value = callable().ToHandleChecked(); |
3513 CHECK(return_value->SameValue(*eval_global[i].second)); | 3521 CHECK(return_value->SameValue(*eval_global[i].second)); |
3514 } | 3522 } |
3515 } | 3523 } |
3516 | 3524 |
3517 } // namespace interpreter | 3525 } // namespace interpreter |
3518 } // namespace internal | 3526 } // namespace internal |
3519 } // namespace v8 | 3527 } // namespace v8 |
OLD | NEW |