// Copyright 2016 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "test/common/wasm/wasm-module-runner.h" #include "src/handles.h" #include "src/isolate.h" #include "src/objects.h" #include "src/property-descriptor.h" #include "src/wasm/module-decoder.h" #include "src/wasm/wasm-interpreter.h" #include "src/wasm/wasm-js.h" #include "src/wasm/wasm-module.h" #include "src/wasm/wasm-result.h" namespace v8 { namespace internal { namespace wasm { namespace testing { uint32_t GetMinModuleMemSize(const WasmModule* module) { return WasmModule::kPageSize * module->min_mem_pages; } const WasmModule* DecodeWasmModuleForTesting(Isolate* isolate, ErrorThrower* thrower, const byte* module_start, const byte* module_end, ModuleOrigin origin) { // Decode the module, but don't verify function bodies, since we'll // be compiling them anyway. ModuleResult decoding_result = DecodeWasmModule(isolate, module_start, module_end, false, origin); if (decoding_result.failed()) { // Module verification failed. throw. thrower->CompileError("WASM.compileRun() failed: %s", decoding_result.error_msg.get()); } if (thrower->error()) { if (decoding_result.val) delete decoding_result.val; return nullptr; } return decoding_result.val; } const Handle InstantiateModuleForTesting(Isolate* isolate, ErrorThrower* thrower, const WasmModule* module) { CHECK(module != nullptr); if (module->import_table.size() > 0) { thrower->CompileError("Not supported: module has imports."); } if (module->export_table.size() == 0) { thrower->CompileError("Not supported: module has no exports."); } if (thrower->error()) return Handle::null(); // Although we decoded the module for some pre-validation, run the bytes // again through the normal pipeline. // TODO(wasm): Use {module} instead of decoding the module bytes again. MaybeHandle module_object = CreateModuleObjectFromBytes( isolate, module->module_start, module->module_end, thrower, ModuleOrigin::kWasmOrigin, Handle