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 <tuple> |
| 6 |
5 #include "src/v8.h" | 7 #include "src/v8.h" |
6 | 8 |
7 #include "src/execution.h" | 9 #include "src/execution.h" |
8 #include "src/handles.h" | 10 #include "src/handles.h" |
9 #include "src/interpreter/bytecode-array-builder.h" | 11 #include "src/interpreter/bytecode-array-builder.h" |
10 #include "src/interpreter/bytecode-array-iterator.h" | 12 #include "src/interpreter/bytecode-array-iterator.h" |
11 #include "src/interpreter/bytecode-label.h" | 13 #include "src/interpreter/bytecode-label.h" |
12 #include "src/interpreter/interpreter.h" | 14 #include "src/interpreter/interpreter.h" |
13 #include "test/cctest/cctest.h" | 15 #include "test/cctest/cctest.h" |
14 #include "test/cctest/interpreter/interpreter-tester.h" | 16 #include "test/cctest/interpreter/interpreter-tester.h" |
(...skipping 3840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3855 std::string(function_epilogue); | 3857 std::string(function_epilogue); |
3856 | 3858 |
3857 InterpreterTester tester(isolate, script.c_str(), "t"); | 3859 InterpreterTester tester(isolate, script.c_str(), "t"); |
3858 auto callable = tester.GetCallable<>(); | 3860 auto callable = tester.GetCallable<>(); |
3859 | 3861 |
3860 Handle<i::Object> return_value = callable().ToHandleChecked(); | 3862 Handle<i::Object> return_value = callable().ToHandleChecked(); |
3861 CHECK(return_value->SameValue(*lookup_slot[i].second)); | 3863 CHECK(return_value->SameValue(*lookup_slot[i].second)); |
3862 } | 3864 } |
3863 } | 3865 } |
3864 | 3866 |
| 3867 TEST(InterpreterLookupContextSlot) { |
| 3868 HandleAndZoneScope handles; |
| 3869 Isolate* isolate = handles.main_isolate(); |
| 3870 |
| 3871 const char* inner_function_prologue = "function inner() {"; |
| 3872 const char* inner_function_epilogue = "};"; |
| 3873 const char* outer_function_epilogue = "return inner();"; |
| 3874 |
| 3875 std::tuple<const char*, const char*, Handle<Object>> lookup_slot[] = { |
| 3876 // Eval in inner context. |
| 3877 std::make_tuple("var x = 0;", "eval(''); return x;", |
| 3878 handle(Smi::FromInt(0), isolate)), |
| 3879 std::make_tuple("var x = 0;", "eval('var x = 1'); return x;", |
| 3880 handle(Smi::FromInt(1), isolate)), |
| 3881 std::make_tuple("var x = 0;", |
| 3882 "'use strict'; eval('var x = 1'); return x;", |
| 3883 handle(Smi::FromInt(0), isolate)), |
| 3884 // Eval in outer context. |
| 3885 std::make_tuple("var x = 0; eval('');", "return x;", |
| 3886 handle(Smi::FromInt(0), isolate)), |
| 3887 std::make_tuple("var x = 0; eval('var x = 1');", "return x;", |
| 3888 handle(Smi::FromInt(1), isolate)), |
| 3889 std::make_tuple("'use strict'; var x = 0; eval('var x = 1');", |
| 3890 "return x;", handle(Smi::FromInt(0), isolate)), |
| 3891 }; |
| 3892 |
| 3893 for (size_t i = 0; i < arraysize(lookup_slot); i++) { |
| 3894 std::string body = std::string(std::get<0>(lookup_slot[i])) + |
| 3895 std::string(inner_function_prologue) + |
| 3896 std::string(std::get<1>(lookup_slot[i])) + |
| 3897 std::string(inner_function_epilogue) + |
| 3898 std::string(outer_function_epilogue); |
| 3899 std::string script = InterpreterTester::SourceForBody(body.c_str()); |
| 3900 |
| 3901 InterpreterTester tester(isolate, script.c_str()); |
| 3902 auto callable = tester.GetCallable<>(); |
| 3903 |
| 3904 Handle<i::Object> return_value = callable().ToHandleChecked(); |
| 3905 CHECK(return_value->SameValue(*std::get<2>(lookup_slot[i]))); |
| 3906 } |
| 3907 } |
3865 | 3908 |
3866 TEST(InterpreterCallLookupSlot) { | 3909 TEST(InterpreterCallLookupSlot) { |
3867 HandleAndZoneScope handles; | 3910 HandleAndZoneScope handles; |
3868 Isolate* isolate = handles.main_isolate(); | 3911 Isolate* isolate = handles.main_isolate(); |
3869 | 3912 |
3870 std::pair<const char*, Handle<Object>> call_lookup[] = { | 3913 std::pair<const char*, Handle<Object>> call_lookup[] = { |
3871 {"g = function(){ return 2 }; eval(''); return g();", | 3914 {"g = function(){ return 2 }; eval(''); return g();", |
3872 handle(Smi::FromInt(2), isolate)}, | 3915 handle(Smi::FromInt(2), isolate)}, |
3873 {"g = function(){ return 2 }; eval('g = function() {return 3}');\n" | 3916 {"g = function(){ return 2 }; eval('g = function() {return 3}');\n" |
3874 "return g();", | 3917 "return g();", |
(...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4721 auto callable = tester.GetCallable<>(); | 4764 auto callable = tester.GetCallable<>(); |
4722 | 4765 |
4723 Handle<i::Object> return_value = callable().ToHandleChecked(); | 4766 Handle<i::Object> return_value = callable().ToHandleChecked(); |
4724 CHECK(return_value->SameValue(*tests[i].second)); | 4767 CHECK(return_value->SameValue(*tests[i].second)); |
4725 } | 4768 } |
4726 } | 4769 } |
4727 | 4770 |
4728 } // namespace interpreter | 4771 } // namespace interpreter |
4729 } // namespace internal | 4772 } // namespace internal |
4730 } // namespace v8 | 4773 } // namespace v8 |
OLD | NEW |