Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Side by Side Diff: test/cctest/interpreter/bytecode-expectations-printer.cc

Issue 2393453003: [interpreter] Add some bytecode tests for modules. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 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 "test/cctest/interpreter/bytecode-expectations-printer.h" 5 #include "test/cctest/interpreter/bytecode-expectations-printer.h"
6 6
7 #include <iomanip> 7 #include <iomanip>
8 #include <iostream> 8 #include <iostream>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 28 matching lines...) Expand all
39 std::string BytecodeExpectationsPrinter::WrapCodeInFunction( 39 std::string BytecodeExpectationsPrinter::WrapCodeInFunction(
40 const char* function_name, const std::string& function_body) const { 40 const char* function_name, const std::string& function_body) const {
41 std::ostringstream program_stream; 41 std::ostringstream program_stream;
42 program_stream << "function " << function_name << "() {" << function_body 42 program_stream << "function " << function_name << "() {" << function_body
43 << "}\n" 43 << "}\n"
44 << function_name << "();"; 44 << function_name << "();";
45 45
46 return program_stream.str(); 46 return program_stream.str();
47 } 47 }
48 48
49 v8::Local<v8::Script> BytecodeExpectationsPrinter::Compile( 49 v8::Local<v8::Script> BytecodeExpectationsPrinter::CompileScript(
50 const char* program) const { 50 const char* program) const {
51 v8::Local<v8::String> source = V8StringFromUTF8(program); 51 v8::Local<v8::String> source = V8StringFromUTF8(program);
52 return v8::Script::Compile(isolate_->GetCurrentContext(), source) 52 return v8::Script::Compile(isolate_->GetCurrentContext(), source)
53 .ToLocalChecked(); 53 .ToLocalChecked();
54 } 54 }
55 55
56 v8::Local<v8::Module> BytecodeExpectationsPrinter::CompileModule(
57 const char* program) const {
58 v8::ScriptCompiler::Source source(V8StringFromUTF8(program));
59 return v8::ScriptCompiler::CompileModule(isolate_, &source).ToLocalChecked();
60 }
61
56 void BytecodeExpectationsPrinter::Run(v8::Local<v8::Script> script) const { 62 void BytecodeExpectationsPrinter::Run(v8::Local<v8::Script> script) const {
57 (void)script->Run(isolate_->GetCurrentContext()); 63 (void)script->Run(isolate_->GetCurrentContext());
58 } 64 }
59 65
60 i::Handle<v8::internal::BytecodeArray> 66 i::Handle<v8::internal::BytecodeArray>
61 BytecodeExpectationsPrinter::GetBytecodeArrayForGlobal( 67 BytecodeExpectationsPrinter::GetBytecodeArrayForGlobal(
62 const char* global_name) const { 68 const char* global_name) const {
63 const v8::Local<v8::Context>& context = isolate_->GetCurrentContext(); 69 const v8::Local<v8::Context>& context = isolate_->GetCurrentContext();
64 v8::Local<v8::String> v8_global_name = V8StringFromUTF8(global_name); 70 v8::Local<v8::String> v8_global_name = V8StringFromUTF8(global_name);
65 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( 71 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
66 context->Global()->Get(context, v8_global_name).ToLocalChecked()); 72 context->Global()->Get(context, v8_global_name).ToLocalChecked());
67 i::Handle<i::JSFunction> js_function = 73 i::Handle<i::JSFunction> js_function =
68 i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*function)); 74 i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*function));
69 75
70 i::Handle<i::BytecodeArray> bytecodes = 76 i::Handle<i::BytecodeArray> bytecodes =
71 i::handle(js_function->shared()->bytecode_array(), i_isolate()); 77 i::handle(js_function->shared()->bytecode_array(), i_isolate());
72 78
73 return bytecodes; 79 return bytecodes;
74 } 80 }
75 81
76 i::Handle<i::BytecodeArray> 82 i::Handle<i::BytecodeArray>
83 BytecodeExpectationsPrinter::GetBytecodeArrayForModule(
84 v8::Local<v8::Module> module) const {
85 i::Handle<i::Module> i_module = v8::Utils::OpenHandle(*module);
86 return i::handle(i_module->shared()->bytecode_array(), i_isolate());
87 }
88
89 i::Handle<i::BytecodeArray>
77 BytecodeExpectationsPrinter::GetBytecodeArrayForScript( 90 BytecodeExpectationsPrinter::GetBytecodeArrayForScript(
78 v8::Local<v8::Script> script) const { 91 v8::Local<v8::Script> script) const {
79 i::Handle<i::JSFunction> js_function = v8::Utils::OpenHandle(*script); 92 i::Handle<i::JSFunction> js_function = v8::Utils::OpenHandle(*script);
80 return i::handle(js_function->shared()->bytecode_array(), i_isolate()); 93 return i::handle(js_function->shared()->bytecode_array(), i_isolate());
81 } 94 }
82 95
83 void BytecodeExpectationsPrinter::PrintEscapedString( 96 void BytecodeExpectationsPrinter::PrintEscapedString(
84 std::ostream& stream, const std::string& string) const { 97 std::ostream& stream, const std::string& string) const {
85 for (char c : string) { 98 for (char c : string) {
86 switch (c) { 99 switch (c) {
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 PrintConstantPool(stream, bytecode_array->constant_pool()); 332 PrintConstantPool(stream, bytecode_array->constant_pool());
320 PrintHandlers(stream, bytecode_array); 333 PrintHandlers(stream, bytecode_array);
321 } 334 }
322 335
323 void BytecodeExpectationsPrinter::PrintExpectation( 336 void BytecodeExpectationsPrinter::PrintExpectation(
324 std::ostream& stream, const std::string& snippet) const { 337 std::ostream& stream, const std::string& snippet) const {
325 std::string source_code = 338 std::string source_code =
326 wrap_ ? WrapCodeInFunction(test_function_name_.c_str(), snippet) 339 wrap_ ? WrapCodeInFunction(test_function_name_.c_str(), snippet)
327 : snippet; 340 : snippet;
328 341
329 v8::Local<v8::Script> script = Compile(source_code.c_str());
330
331 i::Handle<i::BytecodeArray> bytecode_array; 342 i::Handle<i::BytecodeArray> bytecode_array;
332 if (top_level_) { 343 if (module_) {
333 bytecode_array = GetBytecodeArrayForScript(script); 344 CHECK(top_level_ && !wrap_);
345 v8::Local<v8::Module> module = CompileModule(source_code.c_str());
346 bytecode_array = GetBytecodeArrayForModule(module);
334 } else { 347 } else {
335 Run(script); 348 v8::Local<v8::Script> script = CompileScript(source_code.c_str());
336 bytecode_array = GetBytecodeArrayForGlobal(test_function_name_.c_str()); 349 if (top_level_) {
350 bytecode_array = GetBytecodeArrayForScript(script);
351 } else {
352 Run(script);
353 bytecode_array = GetBytecodeArrayForGlobal(test_function_name_.c_str());
354 }
337 } 355 }
338 356
339 stream << "---\n"; 357 stream << "---\n";
340 PrintCodeSnippet(stream, snippet); 358 PrintCodeSnippet(stream, snippet);
341 PrintBytecodeArray(stream, bytecode_array); 359 PrintBytecodeArray(stream, bytecode_array);
342 stream << '\n'; 360 stream << '\n';
343 } 361 }
344 362
345 } // namespace interpreter 363 } // namespace interpreter
346 } // namespace internal 364 } // namespace internal
347 } // namespace v8 365 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/interpreter/bytecode-expectations-printer.h ('k') | test/cctest/interpreter/bytecode_expectations/Modules.golden » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698