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 3075 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3086 std::string source( | 3086 std::string source( |
3087 InterpreterTester::SourceForBody(to_name_tests[i].first)); | 3087 InterpreterTester::SourceForBody(to_name_tests[i].first)); |
3088 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 3088 InterpreterTester tester(handles.main_isolate(), source.c_str()); |
3089 auto callable = tester.GetCallable<>(); | 3089 auto callable = tester.GetCallable<>(); |
3090 | 3090 |
3091 Handle<i::Object> return_value = callable().ToHandleChecked(); | 3091 Handle<i::Object> return_value = callable().ToHandleChecked(); |
3092 CHECK(return_value->SameValue(*to_name_tests[i].second)); | 3092 CHECK(return_value->SameValue(*to_name_tests[i].second)); |
3093 } | 3093 } |
3094 } | 3094 } |
3095 | 3095 |
| 3096 |
| 3097 TEST(InterpreterLookupSlot) { |
| 3098 HandleAndZoneScope handles; |
| 3099 i::Isolate* isolate = handles.main_isolate(); |
| 3100 i::Factory* factory = isolate->factory(); |
| 3101 |
| 3102 // TODO(mythria): Add more tests when we have support for eval/with. |
| 3103 const char* function_prologue = "var f;" |
| 3104 "var x = 1;" |
| 3105 "function f1() {" |
| 3106 " eval(\"function t() {"; |
| 3107 const char* function_epilogue = " }; f = t;\");" |
| 3108 "}" |
| 3109 "f1();"; |
| 3110 |
| 3111 |
| 3112 std::pair<const char*, Handle<Object>> lookup_slot[] = { |
| 3113 {"return x;", handle(Smi::FromInt(1), isolate)}, |
| 3114 {"return typeof x;", factory->NewStringFromStaticChars("number")}, |
| 3115 {"x = 10; return x;", handle(Smi::FromInt(10), isolate)}, |
| 3116 {"'use strict'; x = 20; return x;", handle(Smi::FromInt(20), isolate)}, |
| 3117 }; |
| 3118 |
| 3119 for (size_t i = 0; i < arraysize(lookup_slot); i++) { |
| 3120 std::string script = std::string(function_prologue) + |
| 3121 std::string(lookup_slot[i].first) + |
| 3122 std::string(function_epilogue); |
| 3123 |
| 3124 InterpreterTester tester(handles.main_isolate(), script.c_str(), "t"); |
| 3125 auto callable = tester.GetCallable<>(); |
| 3126 |
| 3127 Handle<i::Object> return_value = callable().ToHandleChecked(); |
| 3128 CHECK(return_value->SameValue(*lookup_slot[i].second)); |
| 3129 } |
| 3130 } |
| 3131 |
3096 } // namespace interpreter | 3132 } // namespace interpreter |
3097 } // namespace internal | 3133 } // namespace internal |
3098 } // namespace v8 | 3134 } // namespace v8 |
OLD | NEW |