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

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

Issue 2446593002: [wasm] Fix memory leak in wasm-module-runner.cc (Closed)
Patch Set: Add a todo 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 | « no previous file | 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 if (module->import_table.size() > 0) { 54 if (module->import_table.size() > 0) {
55 thrower->CompileError("Not supported: module has imports."); 55 thrower->CompileError("Not supported: module has imports.");
56 } 56 }
57 if (module->export_table.size() == 0) { 57 if (module->export_table.size() == 0) {
58 thrower->CompileError("Not supported: module has no exports."); 58 thrower->CompileError("Not supported: module has no exports.");
59 } 59 }
60 if (thrower->error()) return Handle<JSObject>::null(); 60 if (thrower->error()) return Handle<JSObject>::null();
61 61
62 // Although we decoded the module for some pre-validation, run the bytes 62 // Although we decoded the module for some pre-validation, run the bytes
63 // again through the normal pipeline. 63 // again through the normal pipeline.
64 // TODO(wasm): Use {module} instead of decoding the module bytes again.
64 MaybeHandle<JSObject> module_object = CreateModuleObjectFromBytes( 65 MaybeHandle<JSObject> module_object = CreateModuleObjectFromBytes(
65 isolate, module->module_start, module->module_end, thrower, 66 isolate, module->module_start, module->module_end, thrower,
66 ModuleOrigin::kWasmOrigin, Handle<Script>::null(), nullptr, nullptr); 67 ModuleOrigin::kWasmOrigin, Handle<Script>::null(), nullptr, nullptr);
67 if (module_object.is_null()) { 68 if (module_object.is_null()) {
68 thrower->CompileError("Module pre-validation failed."); 69 thrower->CompileError("Module pre-validation failed.");
69 return Handle<JSObject>::null(); 70 return Handle<JSObject>::null();
70 } 71 }
71 MaybeHandle<JSObject> maybe_instance = WasmModule::Instantiate( 72 MaybeHandle<JSObject> maybe_instance = WasmModule::Instantiate(
72 isolate, thrower, module_object.ToHandleChecked(), 73 isolate, thrower, module_object.ToHandleChecked(),
73 Handle<JSReceiver>::null(), Handle<JSArrayBuffer>::null()); 74 Handle<JSReceiver>::null(), Handle<JSArrayBuffer>::null());
74 Handle<JSObject> instance; 75 Handle<JSObject> instance;
75 if (!maybe_instance.ToHandle(&instance)) { 76 if (!maybe_instance.ToHandle(&instance)) {
76 return Handle<JSObject>::null(); 77 return Handle<JSObject>::null();
77 } 78 }
78 return instance; 79 return instance;
79 } 80 }
80 81
81 const Handle<JSObject> CompileInstantiateWasmModuleForTesting( 82 const Handle<JSObject> CompileInstantiateWasmModuleForTesting(
82 Isolate* isolate, ErrorThrower* thrower, const byte* module_start, 83 Isolate* isolate, ErrorThrower* thrower, const byte* module_start,
83 const byte* module_end, ModuleOrigin origin) { 84 const byte* module_end, ModuleOrigin origin) {
84 const WasmModule* module = DecodeWasmModuleForTesting( 85 std::unique_ptr<const WasmModule> module(DecodeWasmModuleForTesting(
85 isolate, thrower, module_start, module_end, origin); 86 isolate, thrower, module_start, module_end, origin));
86 87
87 if (module == nullptr) { 88 if (module == nullptr) {
88 thrower->CompileError("Wasm module decoding failed"); 89 thrower->CompileError("Wasm module decoding failed");
89 return Handle<JSObject>::null(); 90 return Handle<JSObject>::null();
90 } 91 }
91 return InstantiateModuleForTesting(isolate, thrower, module); 92 return InstantiateModuleForTesting(isolate, thrower, module.get());
92 } 93 }
93 94
94 int32_t RunWasmModuleForTesting(Isolate* isolate, Handle<JSObject> instance, 95 int32_t RunWasmModuleForTesting(Isolate* isolate, Handle<JSObject> instance,
95 int argc, Handle<Object> argv[], 96 int argc, Handle<Object> argv[],
96 ModuleOrigin origin) { 97 ModuleOrigin origin) {
97 ErrorThrower thrower(isolate, "RunWasmModule"); 98 ErrorThrower thrower(isolate, "RunWasmModule");
98 const char* f_name = origin == ModuleOrigin::kAsmJsOrigin ? "caller" : "main"; 99 const char* f_name = origin == ModuleOrigin::kAsmJsOrigin ? "caller" : "main";
99 return CallWasmFunctionForTesting(isolate, instance, &thrower, f_name, argc, 100 return CallWasmFunctionForTesting(isolate, instance, &thrower, f_name, argc,
100 argv, origin); 101 argv, origin);
101 } 102 }
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 223
223 void SetupIsolateForWasmModule(Isolate* isolate) { 224 void SetupIsolateForWasmModule(Isolate* isolate) {
224 WasmJs::InstallWasmMapsIfNeeded(isolate, isolate->native_context()); 225 WasmJs::InstallWasmMapsIfNeeded(isolate, isolate->native_context());
225 WasmJs::InstallWasmModuleSymbolIfNeeded(isolate, isolate->global_object(), 226 WasmJs::InstallWasmModuleSymbolIfNeeded(isolate, isolate->global_object(),
226 isolate->native_context()); 227 isolate->native_context());
227 } 228 }
228 } // namespace testing 229 } // namespace testing
229 } // namespace wasm 230 } // namespace wasm
230 } // namespace internal 231 } // namespace internal
231 } // namespace v8 232 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698