OLD | NEW |
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" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 isolate, thrower, module_object.ToHandleChecked(), | 71 isolate, thrower, module_object.ToHandleChecked(), |
72 Handle<JSReceiver>::null(), Handle<JSArrayBuffer>::null()); | 72 Handle<JSReceiver>::null(), Handle<JSArrayBuffer>::null()); |
73 Handle<JSObject> instance; | 73 Handle<JSObject> instance; |
74 if (!maybe_instance.ToHandle(&instance)) { | 74 if (!maybe_instance.ToHandle(&instance)) { |
75 return Handle<JSObject>::null(); | 75 return Handle<JSObject>::null(); |
76 } | 76 } |
77 return instance; | 77 return instance; |
78 } | 78 } |
79 | 79 |
80 const Handle<JSObject> CompileInstantiateWasmModuleForTesting( | 80 const Handle<JSObject> CompileInstantiateWasmModuleForTesting( |
81 Isolate* isolate, Zone* zone, const byte* module_start, | 81 Isolate* isolate, ErrorThrower* thrower, Zone* zone, |
82 const byte* module_end, ModuleOrigin origin) { | 82 const byte* module_start, const byte* module_end, ModuleOrigin origin) { |
83 ErrorThrower thrower(isolate, "CompileInstantiateWasmModule"); | |
84 std::unique_ptr<const WasmModule> module(DecodeWasmModuleForTesting( | 83 std::unique_ptr<const WasmModule> module(DecodeWasmModuleForTesting( |
85 isolate, zone, &thrower, module_start, module_end, origin)); | 84 isolate, zone, thrower, module_start, module_end, origin)); |
86 | 85 |
87 if (module == nullptr) { | 86 if (module == nullptr) { |
88 thrower.Error("Wasm module decode failed"); | 87 thrower->Error("Wasm module decode failed"); |
89 return Handle<JSObject>::null(); | 88 return Handle<JSObject>::null(); |
90 } | 89 } |
91 return InstantiateModuleForTesting(isolate, &thrower, module.get()); | 90 return InstantiateModuleForTesting(isolate, thrower, module.get()); |
92 } | 91 } |
93 | 92 |
94 int32_t RunWasmModuleForTesting(Isolate* isolate, Handle<JSObject> instance, | 93 int32_t RunWasmModuleForTesting(Isolate* isolate, Handle<JSObject> instance, |
95 int argc, Handle<Object> argv[], | 94 int argc, Handle<Object> argv[], |
96 ModuleOrigin origin) { | 95 ModuleOrigin origin) { |
97 ErrorThrower thrower(isolate, "RunWasmModule"); | 96 ErrorThrower thrower(isolate, "RunWasmModule"); |
98 const char* f_name = origin == ModuleOrigin::kAsmJsOrigin ? "caller" : "main"; | 97 const char* f_name = origin == ModuleOrigin::kAsmJsOrigin ? "caller" : "main"; |
99 return CallWasmFunctionForTesting(isolate, instance, &thrower, f_name, argc, | 98 return CallWasmFunctionForTesting(isolate, instance, &thrower, f_name, argc, |
100 argv, origin); | 99 argv, origin); |
101 } | 100 } |
102 | 101 |
103 int32_t CompileAndRunWasmModule(Isolate* isolate, const byte* module_start, | 102 int32_t CompileAndRunWasmModule(Isolate* isolate, const byte* module_start, |
104 const byte* module_end, ModuleOrigin origin) { | 103 const byte* module_end, ModuleOrigin origin) { |
105 HandleScope scope(isolate); | 104 HandleScope scope(isolate); |
106 Zone zone(isolate->allocator()); | 105 Zone zone(isolate->allocator()); |
107 | 106 ErrorThrower thrower(isolate, "CompileAndRunWasmModule"); |
108 Handle<JSObject> instance = CompileInstantiateWasmModuleForTesting( | 107 Handle<JSObject> instance = CompileInstantiateWasmModuleForTesting( |
109 isolate, &zone, module_start, module_end, origin); | 108 isolate, &thrower, &zone, module_start, module_end, origin); |
110 if (instance.is_null()) { | 109 if (instance.is_null()) { |
111 return -1; | 110 return -1; |
112 } | 111 } |
113 return RunWasmModuleForTesting(isolate, instance, 0, nullptr, origin); | 112 return RunWasmModuleForTesting(isolate, instance, 0, nullptr, origin); |
114 } | 113 } |
115 | 114 |
116 int32_t InterpretWasmModule(Isolate* isolate, ErrorThrower* thrower, | 115 int32_t InterpretWasmModule(Isolate* isolate, ErrorThrower* thrower, |
117 const WasmModule* module, int function_index, | 116 const WasmModule* module, int function_index, |
118 WasmVal* args) { | 117 WasmVal* args) { |
119 CHECK(module != nullptr); | 118 CHECK(module != nullptr); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 } | 216 } |
218 thrower->Error("WASM.compileRun() failed: Return value should be number"); | 217 thrower->Error("WASM.compileRun() failed: Return value should be number"); |
219 return -1; | 218 return -1; |
220 } | 219 } |
221 | 220 |
222 void SetupIsolateForWasmModule(Isolate* isolate) { | 221 void SetupIsolateForWasmModule(Isolate* isolate) { |
223 WasmJs::InstallWasmMapsIfNeeded(isolate, isolate->native_context()); | 222 WasmJs::InstallWasmMapsIfNeeded(isolate, isolate->native_context()); |
224 WasmJs::InstallWasmModuleSymbolIfNeeded(isolate, isolate->global_object(), | 223 WasmJs::InstallWasmModuleSymbolIfNeeded(isolate, isolate->global_object(), |
225 isolate->native_context()); | 224 isolate->native_context()); |
226 } | 225 } |
227 | |
228 } // namespace testing | 226 } // namespace testing |
229 } // namespace wasm | 227 } // namespace wasm |
230 } // namespace internal | 228 } // namespace internal |
231 } // namespace v8 | 229 } // namespace v8 |
OLD | NEW |