// 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, Zone* zone, 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, zone, module_start, module_end, false, origin); std::unique_ptr module(decoding_result.val); if (decoding_result.failed()) { // Module verification failed. throw. thrower->Error("WASM.compileRun() failed: %s", decoding_result.error_msg.get()); return nullptr; } if (thrower->error()) return nullptr; return module.release(); } const Handle InstantiateModuleForTesting(Isolate* isolate, ErrorThrower* thrower, const WasmModule* module) { CHECK(module != nullptr); if (module->import_table.size() > 0) { thrower->Error("Not supported: module has imports."); } if (module->export_table.size() == 0) { thrower->Error("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. MaybeHandle module_object = CreateModuleObjectFromBytes( isolate, module->module_start, module->module_end, thrower, ModuleOrigin::kWasmOrigin, Handle