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

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

Issue 2510673002: [wasm] Use more precise types for some WASM objects. (Closed)
Patch Set: Address review comment. Created 4 years, 1 month 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') | no next file » | 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"
(...skipping 27 matching lines...) Expand all
38 decoding_result.error_msg.get()); 38 decoding_result.error_msg.get());
39 } 39 }
40 40
41 if (thrower->error()) { 41 if (thrower->error()) {
42 if (decoding_result.val) delete decoding_result.val; 42 if (decoding_result.val) delete decoding_result.val;
43 return nullptr; 43 return nullptr;
44 } 44 }
45 return decoding_result.val; 45 return decoding_result.val;
46 } 46 }
47 47
48 const Handle<JSObject> InstantiateModuleForTesting(Isolate* isolate, 48 const Handle<WasmInstanceObject> InstantiateModuleForTesting(
49 ErrorThrower* thrower, 49 Isolate* isolate, ErrorThrower* thrower, const WasmModule* module) {
50 const WasmModule* module) {
51 CHECK(module != nullptr); 50 CHECK(module != nullptr);
52 51
53 if (module->import_table.size() > 0) { 52 if (module->import_table.size() > 0) {
54 thrower->CompileError("Not supported: module has imports."); 53 thrower->CompileError("Not supported: module has imports.");
55 } 54 }
56 55
57 if (thrower->error()) return Handle<JSObject>::null(); 56 if (thrower->error()) return Handle<WasmInstanceObject>::null();
58 57
59 // Although we decoded the module for some pre-validation, run the bytes 58 // Although we decoded the module for some pre-validation, run the bytes
60 // again through the normal pipeline. 59 // again through the normal pipeline.
61 // TODO(wasm): Use {module} instead of decoding the module bytes again. 60 // TODO(wasm): Use {module} instead of decoding the module bytes again.
62 MaybeHandle<WasmModuleObject> module_object = CreateModuleObjectFromBytes( 61 MaybeHandle<WasmModuleObject> module_object = CreateModuleObjectFromBytes(
63 isolate, module->module_start, module->module_end, thrower, 62 isolate, module->module_start, module->module_end, thrower,
64 ModuleOrigin::kWasmOrigin, Handle<Script>::null(), nullptr, nullptr); 63 ModuleOrigin::kWasmOrigin, Handle<Script>::null(), nullptr, nullptr);
65 if (module_object.is_null()) { 64 if (module_object.is_null()) {
66 thrower->CompileError("Module pre-validation failed."); 65 thrower->CompileError("Module pre-validation failed.");
67 return Handle<JSObject>::null(); 66 return Handle<WasmInstanceObject>::null();
68 } 67 }
69 MaybeHandle<JSObject> maybe_instance = WasmModule::Instantiate( 68 MaybeHandle<WasmInstanceObject> maybe_instance = WasmModule::Instantiate(
70 isolate, thrower, module_object.ToHandleChecked(), 69 isolate, thrower, module_object.ToHandleChecked(),
71 Handle<JSReceiver>::null(), Handle<JSArrayBuffer>::null()); 70 Handle<JSReceiver>::null(), Handle<JSArrayBuffer>::null());
72 Handle<JSObject> instance; 71 Handle<WasmInstanceObject> instance;
73 if (!maybe_instance.ToHandle(&instance)) { 72 if (!maybe_instance.ToHandle(&instance)) {
74 return Handle<JSObject>::null(); 73 return Handle<WasmInstanceObject>::null();
75 } 74 }
76 return instance; 75 return instance;
77 } 76 }
78 77
79 const Handle<JSObject> CompileInstantiateWasmModuleForTesting( 78 const Handle<WasmInstanceObject> CompileInstantiateWasmModuleForTesting(
80 Isolate* isolate, ErrorThrower* thrower, const byte* module_start, 79 Isolate* isolate, ErrorThrower* thrower, const byte* module_start,
81 const byte* module_end, ModuleOrigin origin) { 80 const byte* module_end, ModuleOrigin origin) {
82 std::unique_ptr<const WasmModule> module(DecodeWasmModuleForTesting( 81 std::unique_ptr<const WasmModule> module(DecodeWasmModuleForTesting(
83 isolate, thrower, module_start, module_end, origin)); 82 isolate, thrower, module_start, module_end, origin));
84 83
85 if (module == nullptr) { 84 if (module == nullptr) {
86 thrower->CompileError("Wasm module decoding failed"); 85 thrower->CompileError("Wasm module decoding failed");
87 return Handle<JSObject>::null(); 86 return Handle<WasmInstanceObject>::null();
88 } 87 }
89 return InstantiateModuleForTesting(isolate, thrower, module.get()); 88 return InstantiateModuleForTesting(isolate, thrower, module.get());
90 } 89 }
91 90
92 int32_t RunWasmModuleForTesting(Isolate* isolate, Handle<JSObject> instance, 91 int32_t RunWasmModuleForTesting(Isolate* isolate, Handle<JSObject> instance,
93 int argc, Handle<Object> argv[], 92 int argc, Handle<Object> argv[],
94 ModuleOrigin origin) { 93 ModuleOrigin origin) {
95 ErrorThrower thrower(isolate, "RunWasmModule"); 94 ErrorThrower thrower(isolate, "RunWasmModule");
96 const char* f_name = origin == ModuleOrigin::kAsmJsOrigin ? "caller" : "main"; 95 const char* f_name = origin == ModuleOrigin::kAsmJsOrigin ? "caller" : "main";
97 return CallWasmFunctionForTesting(isolate, instance, &thrower, f_name, argc, 96 return CallWasmFunctionForTesting(isolate, instance, &thrower, f_name, argc,
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 202
204 void SetupIsolateForWasmModule(Isolate* isolate) { 203 void SetupIsolateForWasmModule(Isolate* isolate) {
205 WasmJs::InstallWasmMapsIfNeeded(isolate, isolate->native_context()); 204 WasmJs::InstallWasmMapsIfNeeded(isolate, isolate->native_context());
206 WasmJs::InstallWasmModuleSymbolIfNeeded(isolate, isolate->global_object(), 205 WasmJs::InstallWasmModuleSymbolIfNeeded(isolate, isolate->global_object(),
207 isolate->native_context()); 206 isolate->native_context());
208 } 207 }
209 } // namespace testing 208 } // namespace testing
210 } // namespace wasm 209 } // namespace wasm
211 } // namespace internal 210 } // namespace internal
212 } // namespace v8 211 } // namespace v8
OLDNEW
« no previous file with comments | « test/common/wasm/wasm-module-runner.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698