test-wasm.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. /*
  2. * Copyright (c) 2021, Ali Mohammad Pur <mpfard@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/MemoryStream.h>
  7. #include <LibTest/JavaScriptTestRunner.h>
  8. #include <LibWasm/AbstractMachine/BytecodeInterpreter.h>
  9. #include <LibWasm/Types.h>
  10. #include <string.h>
  11. TEST_ROOT("Userland/Libraries/LibWasm/Tests");
  12. TESTJS_GLOBAL_FUNCTION(read_binary_wasm_file, readBinaryWasmFile)
  13. {
  14. auto& realm = *vm.current_realm();
  15. auto error_code_to_string = [](int code) {
  16. auto const* error_string = strerror(code);
  17. return StringView { error_string, strlen(error_string) };
  18. };
  19. auto filename = TRY(vm.argument(0).to_byte_string(vm));
  20. auto file = Core::File::open(filename, Core::File::OpenMode::Read);
  21. if (file.is_error())
  22. return vm.throw_completion<JS::TypeError>(error_code_to_string(file.error().code()));
  23. auto file_size = file.value()->size();
  24. if (file_size.is_error())
  25. return vm.throw_completion<JS::TypeError>(error_code_to_string(file_size.error().code()));
  26. auto array = TRY(JS::Uint8Array::create(realm, file_size.value()));
  27. auto read = file.value()->read_until_filled(array->data());
  28. if (read.is_error())
  29. return vm.throw_completion<JS::TypeError>(error_code_to_string(read.error().code()));
  30. return JS::Value(array);
  31. }
  32. class WebAssemblyModule final : public JS::Object {
  33. JS_OBJECT(WebAssemblyModule, JS::Object);
  34. public:
  35. explicit WebAssemblyModule(JS::Object& prototype)
  36. : JS::Object(ConstructWithPrototypeTag::Tag, prototype)
  37. {
  38. m_machine.enable_instruction_count_limit();
  39. }
  40. static Wasm::AbstractMachine& machine() { return m_machine; }
  41. Wasm::Module& module() { return *m_module; }
  42. Wasm::ModuleInstance& module_instance() { return *m_module_instance; }
  43. static JS::ThrowCompletionOr<WebAssemblyModule*> create(JS::Realm& realm, NonnullRefPtr<Wasm::Module> module, HashMap<Wasm::Linker::Name, Wasm::ExternValue> const& imports)
  44. {
  45. auto& vm = realm.vm();
  46. auto instance = realm.heap().allocate<WebAssemblyModule>(realm, realm.intrinsics().object_prototype());
  47. instance->m_module = move(module);
  48. Wasm::Linker linker(*instance->m_module);
  49. linker.link(imports);
  50. linker.link(spec_test_namespace());
  51. auto link_result = linker.finish();
  52. if (link_result.is_error())
  53. return vm.throw_completion<JS::TypeError>("Link failed"sv);
  54. auto result = machine().instantiate(*instance->m_module, link_result.release_value());
  55. if (result.is_error())
  56. return vm.throw_completion<JS::TypeError>(result.release_error().error);
  57. instance->m_module_instance = result.release_value();
  58. return instance.ptr();
  59. }
  60. void initialize(JS::Realm&) override;
  61. ~WebAssemblyModule() override = default;
  62. private:
  63. JS_DECLARE_NATIVE_FUNCTION(get_export);
  64. JS_DECLARE_NATIVE_FUNCTION(wasm_invoke);
  65. static HashMap<Wasm::Linker::Name, Wasm::ExternValue> const& spec_test_namespace()
  66. {
  67. Wasm::FunctionType print_type { {}, {} };
  68. auto address_print = alloc_noop_function(print_type);
  69. s_spec_test_namespace.set({ "spectest", "print", print_type }, Wasm::ExternValue { *address_print });
  70. Wasm::FunctionType print_i32_type { { Wasm::ValueType(Wasm::ValueType::I32) }, {} };
  71. auto address_i32 = alloc_noop_function(print_i32_type);
  72. s_spec_test_namespace.set({ "spectest", "print_i32", print_i32_type }, Wasm::ExternValue { *address_i32 });
  73. Wasm::FunctionType print_i64_type { { Wasm::ValueType(Wasm::ValueType::I64) }, {} };
  74. auto address_i64 = alloc_noop_function(print_i64_type);
  75. s_spec_test_namespace.set({ "spectest", "print_i64", print_i64_type }, Wasm::ExternValue { *address_i64 });
  76. Wasm::FunctionType print_f32_type { { Wasm::ValueType(Wasm::ValueType::F32) }, {} };
  77. auto address_f32 = alloc_noop_function(print_f32_type);
  78. s_spec_test_namespace.set({ "spectest", "print_f32", print_f32_type }, Wasm::ExternValue { *address_f32 });
  79. Wasm::FunctionType print_f64_type { { Wasm::ValueType(Wasm::ValueType::F64) }, {} };
  80. auto address_f64 = alloc_noop_function(print_f64_type);
  81. s_spec_test_namespace.set({ "spectest", "print_f64", print_f64_type }, Wasm::ExternValue { *address_f64 });
  82. Wasm::FunctionType print_i32_f32_type { { Wasm::ValueType(Wasm::ValueType::I32), Wasm::ValueType(Wasm::ValueType::F32) }, {} };
  83. auto address_i32_f32 = alloc_noop_function(print_i32_f32_type);
  84. s_spec_test_namespace.set({ "spectest", "print_i32_f32", print_i32_f32_type }, Wasm::ExternValue { *address_i32_f32 });
  85. Wasm::FunctionType print_f64_f64_type { { Wasm::ValueType(Wasm::ValueType::F64), Wasm::ValueType(Wasm::ValueType::F64) }, {} };
  86. auto address_f64_f64 = alloc_noop_function(print_f64_f64_type);
  87. s_spec_test_namespace.set({ "spectest", "print_f64_f64", print_f64_f64_type }, Wasm::ExternValue { *address_f64_f64 });
  88. Wasm::TableType table_type { Wasm::ValueType(Wasm::ValueType::FunctionReference), Wasm::Limits(10, 20) };
  89. auto table_address = m_machine.store().allocate(table_type);
  90. s_spec_test_namespace.set({ "spectest", "table", table_type }, Wasm::ExternValue { *table_address });
  91. Wasm::MemoryType memory_type { Wasm::Limits(1, 2) };
  92. auto memory_address = m_machine.store().allocate(memory_type);
  93. s_spec_test_namespace.set({ "spectest", "memory", memory_type }, Wasm::ExternValue { *memory_address });
  94. Wasm::GlobalType global_i32 { Wasm::ValueType(Wasm::ValueType::I32), false };
  95. auto global_i32_address = m_machine.store().allocate(global_i32, Wasm::Value(666));
  96. s_spec_test_namespace.set({ "spectest", "global_i32", global_i32 }, Wasm::ExternValue { *global_i32_address });
  97. Wasm::GlobalType global_i64 { Wasm::ValueType(Wasm::ValueType::I64), false };
  98. auto global_i64_address = m_machine.store().allocate(global_i64, Wasm::Value((i64)666));
  99. s_spec_test_namespace.set({ "spectest", "global_i64", global_i64 }, Wasm::ExternValue { *global_i64_address });
  100. Wasm::GlobalType global_f32 { Wasm::ValueType(Wasm::ValueType::F32), false };
  101. auto global_f32_address = m_machine.store().allocate(global_f32, Wasm::Value(666.6f));
  102. s_spec_test_namespace.set({ "spectest", "global_f32", global_f32 }, Wasm::ExternValue { *global_f32_address });
  103. Wasm::GlobalType global_f64 { Wasm::ValueType(Wasm::ValueType::F64), false };
  104. auto global_f64_address = m_machine.store().allocate(global_f64, Wasm::Value(666.6));
  105. s_spec_test_namespace.set({ "spectest", "global_f64", global_f64 }, Wasm::ExternValue { *global_f64_address });
  106. return s_spec_test_namespace;
  107. }
  108. static Optional<Wasm::FunctionAddress> alloc_noop_function(Wasm::FunctionType type)
  109. {
  110. return m_machine.store().allocate(Wasm::HostFunction {
  111. [](auto&, auto&) -> Wasm::Result {
  112. // Noop, this just needs to exist.
  113. return Wasm::Result { Vector<Wasm::Value> {} };
  114. },
  115. type,
  116. "__TEST" });
  117. }
  118. static HashMap<Wasm::Linker::Name, Wasm::ExternValue> s_spec_test_namespace;
  119. static Wasm::AbstractMachine m_machine;
  120. RefPtr<Wasm::Module> m_module;
  121. OwnPtr<Wasm::ModuleInstance> m_module_instance;
  122. };
  123. Wasm::AbstractMachine WebAssemblyModule::m_machine;
  124. HashMap<Wasm::Linker::Name, Wasm::ExternValue> WebAssemblyModule::s_spec_test_namespace;
  125. TESTJS_GLOBAL_FUNCTION(parse_webassembly_module, parseWebAssemblyModule)
  126. {
  127. auto& realm = *vm.current_realm();
  128. auto object = TRY(vm.argument(0).to_object(vm));
  129. if (!is<JS::Uint8Array>(*object))
  130. return vm.throw_completion<JS::TypeError>("Expected a Uint8Array argument to parse_webassembly_module"sv);
  131. auto& array = static_cast<JS::Uint8Array&>(*object);
  132. FixedMemoryStream stream { array.data() };
  133. auto result = Wasm::Module::parse(stream);
  134. if (result.is_error())
  135. return vm.throw_completion<JS::SyntaxError>(Wasm::parse_error_to_byte_string(result.error()));
  136. HashMap<Wasm::Linker::Name, Wasm::ExternValue> imports;
  137. auto import_value = vm.argument(1);
  138. if (import_value.is_object()) {
  139. auto& import_object = import_value.as_object();
  140. for (auto& property : import_object.shape().property_table()) {
  141. auto value = import_object.get_without_side_effects(property.key);
  142. if (!value.is_object() || !is<WebAssemblyModule>(value.as_object()))
  143. continue;
  144. auto& module_object = static_cast<WebAssemblyModule&>(value.as_object());
  145. for (auto& entry : module_object.module_instance().exports()) {
  146. // FIXME: Don't pretend that everything is a function
  147. imports.set({ property.key.as_string(), entry.name(), Wasm::TypeIndex(0) }, entry.value());
  148. }
  149. }
  150. }
  151. return JS::Value(TRY(WebAssemblyModule::create(realm, result.release_value(), imports)));
  152. }
  153. TESTJS_GLOBAL_FUNCTION(compare_typed_arrays, compareTypedArrays)
  154. {
  155. auto lhs = TRY(vm.argument(0).to_object(vm));
  156. if (!is<JS::TypedArrayBase>(*lhs))
  157. return vm.throw_completion<JS::TypeError>("Expected a TypedArray"sv);
  158. auto& lhs_array = static_cast<JS::TypedArrayBase&>(*lhs);
  159. auto rhs = TRY(vm.argument(1).to_object(vm));
  160. if (!is<JS::TypedArrayBase>(*rhs))
  161. return vm.throw_completion<JS::TypeError>("Expected a TypedArray"sv);
  162. auto& rhs_array = static_cast<JS::TypedArrayBase&>(*rhs);
  163. return JS::Value(lhs_array.viewed_array_buffer()->buffer() == rhs_array.viewed_array_buffer()->buffer());
  164. }
  165. static bool _is_canonical_nan32(u32 value)
  166. {
  167. return value == 0x7FC00000 || value == 0xFFC00000;
  168. }
  169. static bool _is_canonical_nan64(u64 value)
  170. {
  171. return value == 0x7FF8000000000000 || value == 0xFFF8000000000000;
  172. }
  173. TESTJS_GLOBAL_FUNCTION(is_canonical_nan32, isCanonicalNaN32)
  174. {
  175. auto value = TRY(vm.argument(0).to_u32(vm));
  176. return _is_canonical_nan32(value);
  177. }
  178. TESTJS_GLOBAL_FUNCTION(is_canonical_nan64, isCanonicalNaN64)
  179. {
  180. auto value = TRY(vm.argument(0).to_bigint_uint64(vm));
  181. return _is_canonical_nan64(value);
  182. }
  183. TESTJS_GLOBAL_FUNCTION(is_arithmetic_nan32, isArithmeticNaN32)
  184. {
  185. auto value = bit_cast<float>(TRY(vm.argument(0).to_u32(vm)));
  186. return isnan(value);
  187. }
  188. TESTJS_GLOBAL_FUNCTION(is_arithmetic_nan64, isArithmeticNaN64)
  189. {
  190. auto value = bit_cast<double>(TRY(vm.argument(0).to_bigint_uint64(vm)));
  191. return isnan(value);
  192. }
  193. TESTJS_GLOBAL_FUNCTION(test_simd_vector, testSIMDVector)
  194. {
  195. auto expected = TRY(vm.argument(0).to_object(vm));
  196. if (!is<JS::Array>(*expected))
  197. return vm.throw_completion<JS::TypeError>("Expected an Array"sv);
  198. auto& expected_array = static_cast<JS::Array&>(*expected);
  199. auto got = TRY(vm.argument(1).to_object(vm));
  200. if (!is<JS::TypedArrayBase>(*got))
  201. return vm.throw_completion<JS::TypeError>("Expected a TypedArray"sv);
  202. auto& got_array = static_cast<JS::TypedArrayBase&>(*got);
  203. auto element_size = 128 / TRY(TRY(expected_array.get("length")).to_u32(vm));
  204. size_t i = 0;
  205. for (auto it = expected_array.indexed_properties().begin(false); it != expected_array.indexed_properties().end(); ++it) {
  206. auto got_value = TRY(got_array.get(i++));
  207. u64 got = got_value.is_bigint() ? TRY(got_value.to_bigint_uint64(vm)) : (u64)TRY(got_value.to_index(vm));
  208. auto expect = TRY(expected_array.get(it.index()));
  209. if (expect.is_string()) {
  210. if (element_size != 32 && element_size != 64)
  211. return vm.throw_completion<JS::TypeError>("Expected element of size 32 or 64"sv);
  212. auto string = expect.as_string().utf8_string();
  213. if (string == "nan:canonical") {
  214. auto is_canonical = element_size == 32 ? _is_canonical_nan32(got) : _is_canonical_nan64(got);
  215. if (!is_canonical)
  216. return false;
  217. continue;
  218. }
  219. if (string == "nan:arithmetic") {
  220. auto is_arithmetic = element_size == 32 ? isnan(bit_cast<float>((u32)got)) : isnan(bit_cast<double>((u64)got));
  221. if (!is_arithmetic)
  222. return false;
  223. continue;
  224. }
  225. return vm.throw_completion<JS::TypeError>(ByteString::formatted("Bad SIMD float expectation: {}"sv, string));
  226. }
  227. u64 expect_value = expect.is_bigint() ? TRY(expect.to_bigint_uint64(vm)) : (u64)TRY(expect.to_index(vm));
  228. if (got != expect_value)
  229. return false;
  230. }
  231. return true;
  232. }
  233. void WebAssemblyModule::initialize(JS::Realm& realm)
  234. {
  235. Base::initialize(realm);
  236. define_native_function(realm, "getExport", get_export, 1, JS::default_attributes);
  237. define_native_function(realm, "invoke", wasm_invoke, 1, JS::default_attributes);
  238. }
  239. JS_DEFINE_NATIVE_FUNCTION(WebAssemblyModule::get_export)
  240. {
  241. auto name = TRY(vm.argument(0).to_byte_string(vm));
  242. auto this_value = vm.this_value();
  243. auto object = TRY(this_value.to_object(vm));
  244. if (!is<WebAssemblyModule>(*object))
  245. return vm.throw_completion<JS::TypeError>("Not a WebAssemblyModule"sv);
  246. auto& instance = static_cast<WebAssemblyModule&>(*object);
  247. for (auto& entry : instance.module_instance().exports()) {
  248. if (entry.name() == name) {
  249. auto& value = entry.value();
  250. if (auto ptr = value.get_pointer<Wasm::FunctionAddress>())
  251. return JS::Value(static_cast<unsigned long>(ptr->value()));
  252. if (auto v = value.get_pointer<Wasm::GlobalAddress>()) {
  253. auto global = m_machine.store().get(*v);
  254. switch (global->type().type().kind()) {
  255. case Wasm::ValueType::I32:
  256. return JS::Value(static_cast<double>(global->value().to<i32>()));
  257. case Wasm::ValueType::I64:
  258. return JS::BigInt::create(vm, Crypto::SignedBigInteger { global->value().to<i64>() });
  259. case Wasm::ValueType::F32:
  260. return JS::Value(static_cast<double>(global->value().to<float>()));
  261. case Wasm::ValueType::F64:
  262. return JS::Value(global->value().to<double>());
  263. case Wasm::ValueType::V128: {
  264. auto value = global->value().to<u128>();
  265. return JS::BigInt::create(vm, Crypto::SignedBigInteger::import_data(bit_cast<u8 const*>(&value), sizeof(u128)));
  266. }
  267. case Wasm::ValueType::FunctionReference:
  268. case Wasm::ValueType::ExternReference:
  269. auto ref = global->value().to<Wasm::Reference>();
  270. return ref.ref().visit(
  271. [&](Wasm::Reference::Null const&) -> JS::Value { return JS::js_null(); },
  272. [&](auto const& ref) -> JS::Value { return JS::Value(static_cast<double>(ref.address.value())); });
  273. }
  274. }
  275. return vm.throw_completion<JS::TypeError>(TRY_OR_THROW_OOM(vm, String::formatted("'{}' does not refer to a function or a global", name)));
  276. }
  277. }
  278. return vm.throw_completion<JS::TypeError>(TRY_OR_THROW_OOM(vm, String::formatted("'{}' could not be found", name)));
  279. }
  280. JS_DEFINE_NATIVE_FUNCTION(WebAssemblyModule::wasm_invoke)
  281. {
  282. auto address = static_cast<unsigned long>(TRY(vm.argument(0).to_double(vm)));
  283. Wasm::FunctionAddress function_address { address };
  284. auto function_instance = WebAssemblyModule::machine().store().get(function_address);
  285. if (!function_instance)
  286. return vm.throw_completion<JS::TypeError>("Invalid function address"sv);
  287. Wasm::FunctionType const* type { nullptr };
  288. function_instance->visit([&](auto& value) { type = &value.type(); });
  289. if (!type)
  290. return vm.throw_completion<JS::TypeError>("Invalid function found at given address"sv);
  291. Vector<Wasm::Value> arguments;
  292. if (type->parameters().size() + 1 > vm.argument_count())
  293. return vm.throw_completion<JS::TypeError>(TRY_OR_THROW_OOM(vm, String::formatted("Expected {} arguments for call, but found {}", type->parameters().size() + 1, vm.argument_count())));
  294. size_t index = 1;
  295. for (auto& param : type->parameters()) {
  296. auto argument = vm.argument(index++);
  297. double double_value = 0;
  298. if (!argument.is_bigint() && !argument.is_object())
  299. double_value = TRY(argument.to_double(vm));
  300. switch (param.kind()) {
  301. case Wasm::ValueType::Kind::I32:
  302. arguments.append(Wasm::Value(static_cast<i64>(double_value)));
  303. break;
  304. case Wasm::ValueType::Kind::I64:
  305. if (argument.is_bigint()) {
  306. auto value = TRY(argument.to_bigint_int64(vm));
  307. arguments.append(Wasm::Value(value));
  308. } else {
  309. arguments.append(Wasm::Value(static_cast<i64>(double_value)));
  310. }
  311. break;
  312. case Wasm::ValueType::Kind::F32:
  313. arguments.append(Wasm::Value(bit_cast<float>(static_cast<u32>(double_value))));
  314. break;
  315. case Wasm::ValueType::Kind::F64:
  316. if (argument.is_bigint()) {
  317. auto value = TRY(argument.to_bigint_uint64(vm));
  318. arguments.append(Wasm::Value(bit_cast<double>(value)));
  319. } else {
  320. arguments.append(Wasm::Value(double_value));
  321. }
  322. break;
  323. case Wasm::ValueType::Kind::V128: {
  324. auto object = MUST(argument.to_object(vm));
  325. if (!is<JS::TypedArrayBase>(*object))
  326. return vm.throw_completion<JS::TypeError>("Expected typed array"sv);
  327. auto& array = static_cast<JS::TypedArrayBase&>(*object);
  328. u128 bits = 0;
  329. auto* ptr = bit_cast<u8*>(&bits);
  330. memcpy(ptr, array.viewed_array_buffer()->buffer().data(), 16);
  331. arguments.append(Wasm::Value(bits));
  332. break;
  333. }
  334. case Wasm::ValueType::Kind::FunctionReference: {
  335. if (argument.is_null()) {
  336. arguments.append(Wasm::Value(Wasm::Reference { Wasm::Reference::Null { Wasm::ValueType(Wasm::ValueType::Kind::FunctionReference) } }));
  337. break;
  338. }
  339. Wasm::FunctionAddress addr = static_cast<u64>(double_value);
  340. arguments.append(Wasm::Value(Wasm::Reference { Wasm::Reference::Func { addr, machine().store().get_module_for(addr) } }));
  341. break;
  342. }
  343. case Wasm::ValueType::Kind::ExternReference:
  344. if (argument.is_null()) {
  345. arguments.append(Wasm::Value(Wasm::Reference { Wasm::Reference::Null { Wasm::ValueType(Wasm::ValueType::Kind::ExternReference) } }));
  346. break;
  347. }
  348. arguments.append(Wasm::Value(Wasm::Reference { Wasm::Reference::Extern { static_cast<u64>(double_value) } }));
  349. break;
  350. }
  351. }
  352. auto functype = WebAssemblyModule::machine().store().get(function_address)->visit([&](auto& func) { return func.type(); });
  353. auto result = WebAssemblyModule::machine().invoke(function_address, arguments);
  354. if (result.is_trap())
  355. return vm.throw_completion<JS::TypeError>(TRY_OR_THROW_OOM(vm, String::formatted("Execution trapped: {}", result.trap().reason)));
  356. if (result.is_completion())
  357. return result.completion();
  358. if (result.values().is_empty())
  359. return JS::js_null();
  360. auto to_js_value = [&](Wasm::Value const& value, Wasm::ValueType type) {
  361. switch (type.kind()) {
  362. case Wasm::ValueType::I32:
  363. return JS::Value(static_cast<double>(value.to<i32>()));
  364. case Wasm::ValueType::I64:
  365. return JS::Value(JS::BigInt::create(vm, Crypto::SignedBigInteger { value.to<i64>() }));
  366. case Wasm::ValueType::F32:
  367. return JS::Value(static_cast<double>(bit_cast<u32>(value.to<float>())));
  368. case Wasm::ValueType::F64:
  369. return JS::Value(JS::BigInt::create(vm, Crypto::SignedBigInteger { Crypto::UnsignedBigInteger { bit_cast<u64>(value.to<double>()) } }));
  370. case Wasm::ValueType::V128: {
  371. u128 val = value.to<u128>();
  372. // FIXME: remove the MUST here
  373. auto buf = MUST(JS::ArrayBuffer::create(*vm.current_realm(), 16));
  374. memcpy(buf->buffer().data(), val.bytes().data(), 16);
  375. return JS::Value(buf);
  376. }
  377. case Wasm::ValueType::FunctionReference:
  378. case Wasm::ValueType::ExternReference:
  379. return (value.to<Wasm::Reference>()).ref().visit([&](Wasm::Reference::Null) { return JS::js_null(); }, [&](auto const& ref) { return JS::Value(static_cast<double>(ref.address.value())); });
  380. }
  381. VERIFY_NOT_REACHED();
  382. };
  383. if (result.values().size() == 1)
  384. return to_js_value(result.values().first(), functype.results().first());
  385. size_t i = 0;
  386. return JS::Array::create_from<Wasm::Value>(*vm.current_realm(), result.values(), [&](Wasm::Value value) {
  387. auto value_type = type->results()[i++];
  388. return to_js_value(value, value_type);
  389. });
  390. }