[Wasm] Generate .mjs compatible with other standalone js & wasm VMs: SpiderMonkey and JavaScriptCore in addition to V8

#KT-56166 In-Progress
This commit is contained in:
Zalim Bashorov
2023-01-27 00:04:52 +01:00
parent 802a8ec326
commit ca79711610
@@ -245,10 +245,15 @@ $jsCodeBodyIndented
let wasmExports; let wasmExports;
const isNodeJs = (typeof process !== 'undefined') && (process.release.name === 'node'); const isNodeJs = (typeof process !== 'undefined') && (process.release.name === 'node');
const isD8 = !isNodeJs && (typeof d8 !== 'undefined'); const isStandaloneJsVM =
const isBrowser = !isNodeJs && !isD8 && (typeof window !== 'undefined'); !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"; throw "Supported JS engine not detected";
} }
@@ -271,7 +276,7 @@ $imports
wasmInstance = new WebAssembly.Instance(wasmModule, importObject); wasmInstance = new WebAssembly.Instance(wasmModule, importObject);
} }
if (isD8) { if (isStandaloneJsVM) {
const wasmBuffer = read(wasmFilePath, 'binary'); const wasmBuffer = read(wasmFilePath, 'binary');
const wasmModule = new WebAssembly.Module(wasmBuffer); const wasmModule = new WebAssembly.Module(wasmBuffer);
wasmInstance = new WebAssembly.Instance(wasmModule, importObject); wasmInstance = new WebAssembly.Instance(wasmModule, importObject);