Index: test/cctest/interpreter/test-bytecode-generator.cc |
diff --git a/test/cctest/interpreter/test-bytecode-generator.cc b/test/cctest/interpreter/test-bytecode-generator.cc |
index ead1fa1672bfb5c5b83295667419be7d003195d2..cf0f497b32b59730a11fec97bbaefcf172974e64 100644 |
--- a/test/cctest/interpreter/test-bytecode-generator.cc |
+++ b/test/cctest/interpreter/test-bytecode-generator.cc |
@@ -55,6 +55,21 @@ class BytecodeGeneratorHelper { |
return handle(js_function->shared()->bytecode_array(), CcTest::i_isolate()); |
} |
+ Handle<BytecodeArray> MakeBytecode(const char* script, const char* filter, |
+ const char* function_name) { |
+ const char* old_ignition_filter = i::FLAG_ignition_filter; |
+ i::FLAG_ignition_filter = filter; |
+ CompileRun(script); |
+ i::FLAG_ignition_filter = old_ignition_filter; |
+ v8::Local<v8::Context> context = |
+ v8::Isolate::GetCurrent()->GetCurrentContext(); |
+ Local<Function> function = Local<Function>::Cast( |
+ CcTest::global()->Get(context, v8_str(function_name)).ToLocalChecked()); |
+ i::Handle<i::JSFunction> js_function = |
+ i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*function)); |
+ return handle(js_function->shared()->bytecode_array(), CcTest::i_isolate()); |
rmcilroy
2015/12/15 16:44:33
nit - pull out common code with MakeTopLevelByteco
mythria
2015/12/16 09:54:21
Done.
|
+ } |
+ |
Handle<BytecodeArray> MakeBytecodeForFunctionBody(const char* body) { |
ScopedVector<char> program(3072); |
SNPrintF(program, "function %s() { %s }\n%s();", kFunctionName, body, |
@@ -5518,6 +5533,79 @@ TEST(AssignmentsInBinaryExpression) { |
} |
} |
+ |
+TEST(LookupSlotInEval) { |
+ InitializedHandleScope handle_scope; |
+ BytecodeGeneratorHelper helper; |
+ |
+ const char* function_prologue = "var f;" |
+ "var x = 1;" |
+ "function f1() {" |
+ " eval(\"function t() {"; |
rmcilroy
2015/12/15 16:44:33
nit - use ' instead of \"
mythria
2015/12/16 09:54:21
I use 'use strict'; in function body in one exampl
|
+ const char* function_epilogue = " }; f = t; f();\");" |
+ "}" |
+ "f1();"; |
+ |
+ ExpectedSnippet<const char*> snippets[] = { |
+ {"return x;", |
+ 0 * kPointerSize, |
+ 1, |
+ 3, |
+ { |
+ B(LdaLookupSlot), U8(0), // |
+ B(Return) // |
+ }, |
+ 1, |
+ {"x"}}, |
+ {"x = 10;", |
+ 0 * kPointerSize, |
+ 1, |
+ 6, |
+ { |
+ B(LdaSmi8), U8(10), // |
+ B(StaLookupSlotSloppy), U8(0), // |
+ B(LdaUndefined), // |
+ B(Return), // |
+ }, |
+ 1, |
+ {"x"}}, |
+ {"'use strict'; x = 10;", |
+ 0 * kPointerSize, |
+ 1, |
+ 6, |
+ { |
+ B(LdaSmi8), U8(10), // |
+ B(StaLookupSlotStrict), U8(0), // |
+ B(LdaUndefined), // |
+ B(Return), // |
+ }, |
+ 1, |
+ {"x"}}, |
+ {"return typeof x;", |
+ 0 * kPointerSize, |
+ 1, |
+ 4, |
+ { |
+ B(LdaLookupSlotInsideTypeof), U8(0), // |
+ B(TypeOf), // |
+ B(Return), // |
+ }, |
+ 1, |
+ {"x"}}, |
+ }; |
+ |
+ for (size_t i = 0; i < arraysize(snippets); i++) { |
+ std::string script = std::string(function_prologue) + |
+ std::string(snippets[i].code_snippet) + |
+ std::string(function_epilogue); |
+ // TODO(mythria): use * as filter when function declarations are supported |
+ // inside eval. |
+ Handle<BytecodeArray> bytecode_array = |
+ helper.MakeBytecode(script.c_str(), "t", "f"); |
+ CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
+ } |
+} |
+ |
} // namespace interpreter |
} // namespace internal |
} // namespace v8 |