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

Side by Side Diff: test/common/wasm/wasm-module-runner.cc

Issue 2424623002: [wasm] Use a Managed<WasmModule> to hold metadata about modules. (Closed)
Patch Set: [wasm] Use a Managed<WasmModule> to hold metadata about modules. 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
« no previous file with comments | « test/common/wasm/wasm-module-runner.h ('k') | test/fuzzer/wasm-code.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/common/wasm/wasm-module-runner.h" 5 #include "test/common/wasm/wasm-module-runner.h"
6 6
7 #include "src/handles.h" 7 #include "src/handles.h"
8 #include "src/isolate.h" 8 #include "src/isolate.h"
9 #include "src/objects.h" 9 #include "src/objects.h"
10 #include "src/property-descriptor.h" 10 #include "src/property-descriptor.h"
11 #include "src/wasm/module-decoder.h" 11 #include "src/wasm/module-decoder.h"
12 #include "src/wasm/wasm-interpreter.h" 12 #include "src/wasm/wasm-interpreter.h"
13 #include "src/wasm/wasm-js.h" 13 #include "src/wasm/wasm-js.h"
14 #include "src/wasm/wasm-module.h" 14 #include "src/wasm/wasm-module.h"
15 #include "src/wasm/wasm-result.h" 15 #include "src/wasm/wasm-result.h"
16 16
17 namespace v8 { 17 namespace v8 {
18 namespace internal { 18 namespace internal {
19 namespace wasm { 19 namespace wasm {
20 namespace testing { 20 namespace testing {
21 21
22 uint32_t GetMinModuleMemSize(const WasmModule* module) { 22 uint32_t GetMinModuleMemSize(const WasmModule* module) {
23 return WasmModule::kPageSize * module->min_mem_pages; 23 return WasmModule::kPageSize * module->min_mem_pages;
24 } 24 }
25 25
26 const WasmModule* DecodeWasmModuleForTesting(Isolate* isolate, Zone* zone, 26 const WasmModule* DecodeWasmModuleForTesting(Isolate* isolate,
27 ErrorThrower* thrower, 27 ErrorThrower* thrower,
28 const byte* module_start, 28 const byte* module_start,
29 const byte* module_end, 29 const byte* module_end,
30 ModuleOrigin origin) { 30 ModuleOrigin origin) {
31 // Decode the module, but don't verify function bodies, since we'll 31 // Decode the module, but don't verify function bodies, since we'll
32 // be compiling them anyway. 32 // be compiling them anyway.
33 ModuleResult decoding_result = 33 ModuleResult decoding_result =
34 DecodeWasmModule(isolate, zone, module_start, module_end, false, origin); 34 DecodeWasmModule(isolate, module_start, module_end, false, origin);
35 35
36 std::unique_ptr<const WasmModule> module(decoding_result.val);
37 if (decoding_result.failed()) { 36 if (decoding_result.failed()) {
38 // Module verification failed. throw. 37 // Module verification failed. throw.
39 thrower->CompileError("WASM.compileRun() failed: %s", 38 thrower->CompileError("WASM.compileRun() failed: %s",
40 decoding_result.error_msg.get()); 39 decoding_result.error_msg.get());
40 }
41
42 if (thrower->error()) {
43 if (decoding_result.val) delete decoding_result.val;
41 return nullptr; 44 return nullptr;
42 } 45 }
43 46 return decoding_result.val;
44 if (thrower->error()) return nullptr;
45 return module.release();
46 } 47 }
47 48
48 const Handle<JSObject> InstantiateModuleForTesting(Isolate* isolate, 49 const Handle<JSObject> InstantiateModuleForTesting(Isolate* isolate,
49 ErrorThrower* thrower, 50 ErrorThrower* thrower,
50 const WasmModule* module) { 51 const WasmModule* module) {
51 CHECK(module != nullptr); 52 CHECK(module != nullptr);
52 53
53 if (module->import_table.size() > 0) { 54 if (module->import_table.size() > 0) {
54 thrower->CompileError("Not supported: module has imports."); 55 thrower->CompileError("Not supported: module has imports.");
55 } 56 }
(...skipping 15 matching lines...) Expand all
71 isolate, thrower, module_object.ToHandleChecked(), 72 isolate, thrower, module_object.ToHandleChecked(),
72 Handle<JSReceiver>::null(), Handle<JSArrayBuffer>::null()); 73 Handle<JSReceiver>::null(), Handle<JSArrayBuffer>::null());
73 Handle<JSObject> instance; 74 Handle<JSObject> instance;
74 if (!maybe_instance.ToHandle(&instance)) { 75 if (!maybe_instance.ToHandle(&instance)) {
75 return Handle<JSObject>::null(); 76 return Handle<JSObject>::null();
76 } 77 }
77 return instance; 78 return instance;
78 } 79 }
79 80
80 const Handle<JSObject> CompileInstantiateWasmModuleForTesting( 81 const Handle<JSObject> CompileInstantiateWasmModuleForTesting(
81 Isolate* isolate, ErrorThrower* thrower, Zone* zone, 82 Isolate* isolate, ErrorThrower* thrower, const byte* module_start,
82 const byte* module_start, const byte* module_end, ModuleOrigin origin) { 83 const byte* module_end, ModuleOrigin origin) {
83 std::unique_ptr<const WasmModule> module(DecodeWasmModuleForTesting( 84 const WasmModule* module = DecodeWasmModuleForTesting(
84 isolate, zone, thrower, module_start, module_end, origin)); 85 isolate, thrower, module_start, module_end, origin);
85 86
86 if (module == nullptr) { 87 if (module == nullptr) {
87 thrower->CompileError("Wasm module decoding failed"); 88 thrower->CompileError("Wasm module decoding failed");
88 return Handle<JSObject>::null(); 89 return Handle<JSObject>::null();
89 } 90 }
90 return InstantiateModuleForTesting(isolate, thrower, module.get()); 91 return InstantiateModuleForTesting(isolate, thrower, module);
91 } 92 }
92 93
93 int32_t RunWasmModuleForTesting(Isolate* isolate, Handle<JSObject> instance, 94 int32_t RunWasmModuleForTesting(Isolate* isolate, Handle<JSObject> instance,
94 int argc, Handle<Object> argv[], 95 int argc, Handle<Object> argv[],
95 ModuleOrigin origin) { 96 ModuleOrigin origin) {
96 ErrorThrower thrower(isolate, "RunWasmModule"); 97 ErrorThrower thrower(isolate, "RunWasmModule");
97 const char* f_name = origin == ModuleOrigin::kAsmJsOrigin ? "caller" : "main"; 98 const char* f_name = origin == ModuleOrigin::kAsmJsOrigin ? "caller" : "main";
98 return CallWasmFunctionForTesting(isolate, instance, &thrower, f_name, argc, 99 return CallWasmFunctionForTesting(isolate, instance, &thrower, f_name, argc,
99 argv, origin); 100 argv, origin);
100 } 101 }
101 102
102 int32_t CompileAndRunWasmModule(Isolate* isolate, const byte* module_start, 103 int32_t CompileAndRunWasmModule(Isolate* isolate, const byte* module_start,
103 const byte* module_end, ModuleOrigin origin) { 104 const byte* module_end, ModuleOrigin origin) {
104 HandleScope scope(isolate); 105 HandleScope scope(isolate);
105 Zone zone(isolate->allocator(), ZONE_NAME);
106 ErrorThrower thrower(isolate, "CompileAndRunWasmModule"); 106 ErrorThrower thrower(isolate, "CompileAndRunWasmModule");
107 Handle<JSObject> instance = CompileInstantiateWasmModuleForTesting( 107 Handle<JSObject> instance = CompileInstantiateWasmModuleForTesting(
108 isolate, &thrower, &zone, module_start, module_end, origin); 108 isolate, &thrower, module_start, module_end, origin);
109 if (instance.is_null()) { 109 if (instance.is_null()) {
110 return -1; 110 return -1;
111 } 111 }
112 return RunWasmModuleForTesting(isolate, instance, 0, nullptr, origin); 112 return RunWasmModuleForTesting(isolate, instance, 0, nullptr, origin);
113 } 113 }
114 114
115 int32_t InterpretWasmModule(Isolate* isolate, ErrorThrower* thrower, 115 int32_t InterpretWasmModule(Isolate* isolate, ErrorThrower* thrower,
116 const WasmModule* module, int function_index, 116 const WasmModule* module, int function_index,
117 WasmVal* args) { 117 WasmVal* args) {
118 CHECK(module != nullptr); 118 CHECK(module != nullptr);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 221
222 void SetupIsolateForWasmModule(Isolate* isolate) { 222 void SetupIsolateForWasmModule(Isolate* isolate) {
223 WasmJs::InstallWasmMapsIfNeeded(isolate, isolate->native_context()); 223 WasmJs::InstallWasmMapsIfNeeded(isolate, isolate->native_context());
224 WasmJs::InstallWasmModuleSymbolIfNeeded(isolate, isolate->global_object(), 224 WasmJs::InstallWasmModuleSymbolIfNeeded(isolate, isolate->global_object(),
225 isolate->native_context()); 225 isolate->native_context());
226 } 226 }
227 } // namespace testing 227 } // namespace testing
228 } // namespace wasm 228 } // namespace wasm
229 } // namespace internal 229 } // namespace internal
230 } // namespace v8 230 } // namespace v8
OLDNEW
« no previous file with comments | « test/common/wasm/wasm-module-runner.h ('k') | test/fuzzer/wasm-code.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698