// 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-inl.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-objects.h" #include "src/wasm/wasm-result.h" namespace v8 { namespace internal { namespace wasm { namespace testing { uint32_t GetInitialMemSize(const WasmModule* module) { return WasmModule::kPageSize * module->initial_pages; } std::unique_ptr DecodeWasmModuleForTesting( Isolate* isolate, ErrorThrower* thrower, const byte* module_start, const byte* module_end, ModuleOrigin origin, bool verify_functions) { // Decode the module, but don't verify function bodies, since we'll // be compiling them anyway. ModuleResult decoding_result = SyncDecodeWasmModule( isolate, module_start, module_end, verify_functions, origin); if (decoding_result.failed()) { // Module verification failed. throw. thrower->CompileError("DecodeWasmModule failed: %s", decoding_result.error_msg().c_str()); } return std::move(decoding_result.val); } int32_t RunWasmModuleForTesting(Isolate* isolate, Handle instance, int argc, Handle argv[]) { ErrorThrower thrower(isolate, "RunWasmModule"); return CallWasmFunctionForTesting(isolate, instance, &thrower, "main", argc, argv); } int32_t CompileAndRunWasmModule(Isolate* isolate, const byte* module_start, const byte* module_end) { HandleScope scope(isolate); ErrorThrower thrower(isolate, "CompileAndRunWasmModule"); MaybeHandle instance = SyncCompileAndInstantiate( isolate, &thrower, ModuleWireBytes(module_start, module_end), {}, {}); if (instance.is_null()) { return -1; } return RunWasmModuleForTesting(isolate, instance.ToHandleChecked(), 0, nullptr); } int32_t CompileAndRunAsmWasmModule(Isolate* isolate, const byte* module_start, const byte* module_end) { HandleScope scope(isolate); ErrorThrower thrower(isolate, "CompileAndRunAsmWasmModule"); MaybeHandle module = wasm::SyncCompileTranslatedAsmJs( isolate, &thrower, ModuleWireBytes(module_start, module_end), Handle