Index: test/cctest/interpreter/bytecode-expectations-printer.cc |
diff --git a/test/cctest/interpreter/bytecode-expectations-printer.cc b/test/cctest/interpreter/bytecode-expectations-printer.cc |
index a1e3ce62381d4d8ce825e1ab8dd4e894d06e383f..81be1c0028c7c4d82a412f85236610e047c845a2 100644 |
--- a/test/cctest/interpreter/bytecode-expectations-printer.cc |
+++ b/test/cctest/interpreter/bytecode-expectations-printer.cc |
@@ -46,13 +46,19 @@ std::string BytecodeExpectationsPrinter::WrapCodeInFunction( |
return program_stream.str(); |
} |
-v8::Local<v8::Script> BytecodeExpectationsPrinter::Compile( |
+v8::Local<v8::Script> BytecodeExpectationsPrinter::CompileScript( |
const char* program) const { |
v8::Local<v8::String> source = V8StringFromUTF8(program); |
return v8::Script::Compile(isolate_->GetCurrentContext(), source) |
.ToLocalChecked(); |
} |
+v8::Local<v8::Module> BytecodeExpectationsPrinter::CompileModule( |
+ const char* program) const { |
+ v8::ScriptCompiler::Source source(V8StringFromUTF8(program)); |
+ return v8::ScriptCompiler::CompileModule(isolate_, &source).ToLocalChecked(); |
+} |
+ |
void BytecodeExpectationsPrinter::Run(v8::Local<v8::Script> script) const { |
(void)script->Run(isolate_->GetCurrentContext()); |
} |
@@ -74,6 +80,13 @@ BytecodeExpectationsPrinter::GetBytecodeArrayForGlobal( |
} |
i::Handle<i::BytecodeArray> |
+BytecodeExpectationsPrinter::GetBytecodeArrayForModule( |
+ v8::Local<v8::Module> module) const { |
+ i::Handle<i::Module> i_module = v8::Utils::OpenHandle(*module); |
+ return i::handle(i_module->shared()->bytecode_array(), i_isolate()); |
+} |
+ |
+i::Handle<i::BytecodeArray> |
BytecodeExpectationsPrinter::GetBytecodeArrayForScript( |
v8::Local<v8::Script> script) const { |
i::Handle<i::JSFunction> js_function = v8::Utils::OpenHandle(*script); |
@@ -326,14 +339,19 @@ void BytecodeExpectationsPrinter::PrintExpectation( |
wrap_ ? WrapCodeInFunction(test_function_name_.c_str(), snippet) |
: snippet; |
- v8::Local<v8::Script> script = Compile(source_code.c_str()); |
- |
i::Handle<i::BytecodeArray> bytecode_array; |
- if (top_level_) { |
- bytecode_array = GetBytecodeArrayForScript(script); |
+ if (module_) { |
+ CHECK(top_level_ && !wrap_); |
+ v8::Local<v8::Module> module = CompileModule(source_code.c_str()); |
+ bytecode_array = GetBytecodeArrayForModule(module); |
} else { |
- Run(script); |
- bytecode_array = GetBytecodeArrayForGlobal(test_function_name_.c_str()); |
+ v8::Local<v8::Script> script = CompileScript(source_code.c_str()); |
+ if (top_level_) { |
+ bytecode_array = GetBytecodeArrayForScript(script); |
+ } else { |
+ Run(script); |
+ bytecode_array = GetBytecodeArrayForGlobal(test_function_name_.c_str()); |
+ } |
} |
stream << "---\n"; |