Index: test/cctest/interpreter/test-interpreter.cc |
diff --git a/test/cctest/interpreter/test-interpreter.cc b/test/cctest/interpreter/test-interpreter.cc |
index 26c11890f52d7b1b2cfbf027f6249b506c36e94f..99b99734ae280bc770f3ae0922fd6cbc8eb07ffc 100644 |
--- a/test/cctest/interpreter/test-interpreter.cc |
+++ b/test/cctest/interpreter/test-interpreter.cc |
@@ -2,6 +2,8 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
+#include <tuple> |
+ |
#include "src/v8.h" |
#include "src/execution.h" |
@@ -3862,6 +3864,47 @@ TEST(InterpreterLookupSlot) { |
} |
} |
+TEST(InterpreterLookupContextSlot) { |
+ HandleAndZoneScope handles; |
+ Isolate* isolate = handles.main_isolate(); |
+ |
+ const char* inner_function_prologue = "function inner() {"; |
+ const char* inner_function_epilogue = "};"; |
+ const char* outer_function_epilogue = "return inner();"; |
+ |
+ std::tuple<const char*, const char*, Handle<Object>> lookup_slot[] = { |
+ // Eval in inner context. |
+ std::make_tuple("var x = 0;", "eval(''); return x;", |
+ handle(Smi::FromInt(0), isolate)), |
+ std::make_tuple("var x = 0;", "eval('var x = 1'); return x;", |
+ handle(Smi::FromInt(1), isolate)), |
+ std::make_tuple("var x = 0;", |
+ "'use strict'; eval('var x = 1'); return x;", |
+ handle(Smi::FromInt(0), isolate)), |
+ // Eval in outer context. |
+ std::make_tuple("var x = 0; eval('');", "return x;", |
+ handle(Smi::FromInt(0), isolate)), |
+ std::make_tuple("var x = 0; eval('var x = 1');", "return x;", |
+ handle(Smi::FromInt(1), isolate)), |
+ std::make_tuple("'use strict'; var x = 0; eval('var x = 1');", |
+ "return x;", handle(Smi::FromInt(0), isolate)), |
+ }; |
+ |
+ for (size_t i = 0; i < arraysize(lookup_slot); i++) { |
+ std::string body = std::string(std::get<0>(lookup_slot[i])) + |
+ std::string(inner_function_prologue) + |
+ std::string(std::get<1>(lookup_slot[i])) + |
+ std::string(inner_function_epilogue) + |
+ std::string(outer_function_epilogue); |
+ std::string script = InterpreterTester::SourceForBody(body.c_str()); |
+ |
+ InterpreterTester tester(isolate, script.c_str()); |
+ auto callable = tester.GetCallable<>(); |
+ |
+ Handle<i::Object> return_value = callable().ToHandleChecked(); |
+ CHECK(return_value->SameValue(*std::get<2>(lookup_slot[i]))); |
+ } |
+} |
TEST(InterpreterCallLookupSlot) { |
HandleAndZoneScope handles; |