From ca797116103790a9554549b0958110dafefa7164 Mon Sep 17 00:00:00 2001 From: Zalim Bashorov Date: Fri, 27 Jan 2023 00:04:52 +0100 Subject: [PATCH] [Wasm] Generate .mjs compatible with other standalone js & wasm VMs: SpiderMonkey and JavaScriptCore in addition to V8 #KT-56166 In-Progress --- .../org/jetbrains/kotlin/backend/wasm/compiler.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/compiler.kt b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/compiler.kt index a5d6f17f006..ef8e2908fc6 100644 --- a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/compiler.kt +++ b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/compiler.kt @@ -245,10 +245,15 @@ $jsCodeBodyIndented let wasmExports; const isNodeJs = (typeof process !== 'undefined') && (process.release.name === 'node'); - const isD8 = !isNodeJs && (typeof d8 !== 'undefined'); - const isBrowser = !isNodeJs && !isD8 && (typeof window !== 'undefined'); + const isStandaloneJsVM = + !isNodeJs && ( + typeof d8 !== 'undefined' // V8 + || typeof inIon !== 'undefined' // SpiderMonkey + || typeof jscOptions !== 'undefined' // JavaScriptCore + ); + const isBrowser = !isNodeJs && !isStandaloneJsVM && (typeof window !== 'undefined'); - if (!isNodeJs && !isD8 && !isBrowser) { + if (!isNodeJs && !isStandaloneJsVM && !isBrowser) { throw "Supported JS engine not detected"; } @@ -271,7 +276,7 @@ $imports wasmInstance = new WebAssembly.Instance(wasmModule, importObject); } - if (isD8) { + if (isStandaloneJsVM) { const wasmBuffer = read(wasmFilePath, 'binary'); const wasmModule = new WebAssembly.Module(wasmBuffer); wasmInstance = new WebAssembly.Instance(wasmModule, importObject);