[WasmJs] Generate a wrapper that run in Deno

Fixed #KT-65713
This commit is contained in:
Igor Yakovlev
2024-02-19 16:58:00 +01:00
committed by Space Team
parent 96b5d47e68
commit eea3c3624c
7 changed files with 18 additions and 9 deletions
@@ -289,15 +289,16 @@ $jsCodeBodyIndented
let wasmExports;
const isNodeJs = (typeof process !== 'undefined') && (process.release.name === 'node');
const isDeno = !isNodeJs && (typeof Deno !== 'undefined')
const isStandaloneJsVM =
!isNodeJs && (
!isDeno && !isNodeJs && (
typeof d8 !== 'undefined' // V8
|| typeof inIon !== 'undefined' // SpiderMonkey
|| typeof jscOptions !== 'undefined' // JavaScriptCore
);
const isBrowser = !isNodeJs && !isStandaloneJsVM && (typeof window !== 'undefined');
const isBrowser = !isNodeJs && !isDeno && !isStandaloneJsVM && (typeof window !== 'undefined');
if (!isNodeJs && !isStandaloneJsVM && !isBrowser) {
if (!isNodeJs && !isDeno && !isStandaloneJsVM && !isBrowser) {
throw "Supported JS engine not detected";
}
@@ -321,6 +322,14 @@ $imports
wasmInstance = new WebAssembly.Instance(wasmModule, importObject);
}
if (isDeno) {
const path = await import(/* webpackIgnore: true */'https://deno.land/std/path/mod.ts');
const dirpath = path.dirname(path.fromFileUrl(import.meta.url));
const binary = Deno.readFileSync(path.resolve(dirpath, wasmFilePath));
const module = await WebAssembly.compile(binary);
wasmInstance = await WebAssembly.instantiate(module, importObject);
}
if (isStandaloneJsVM) {
const wasmBuffer = read(wasmFilePath, 'binary');
const wasmModule = new WebAssembly.Module(wasmBuffer);
+1 -1
View File
@@ -2,7 +2,7 @@
// RUN_THIRD_PARTY_OPTIMIZER
// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 12_773
// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 4_921
// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 5_411
// WASM_OPT_EXPECTED_OUTPUT_SIZE: 2_640
// FILE: test.kt
+1 -1
View File
@@ -2,7 +2,7 @@
// RUN_THIRD_PARTY_OPTIMIZER
// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 35_154
// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 4_941
// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 5_431
// WASM_OPT_EXPECTED_OUTPUT_SIZE: 8_586
fun box(): String {
+1 -1
View File
@@ -2,7 +2,7 @@
// RUN_THIRD_PARTY_OPTIMIZER
// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 14_178
// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 5_478
// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 5_968
// WASM_OPT_EXPECTED_OUTPUT_SIZE: 4_317
// FILE: test.kt
+1 -1
View File
@@ -2,7 +2,7 @@
// RUN_THIRD_PARTY_OPTIMIZER
// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 17_907
// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 4_787
// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 5_277
// WASM_OPT_EXPECTED_OUTPUT_SIZE: 5_841
object Simple
+1 -1
View File
@@ -2,7 +2,7 @@
// RUN_THIRD_PARTY_OPTIMIZER
// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 12_856
// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 4_787
// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 5_277
// WASM_OPT_EXPECTED_OUTPUT_SIZE: 3_743
fun box() = "OK"
+1 -1
View File
@@ -3,7 +3,7 @@
// RUN_THIRD_PARTY_OPTIMIZER
// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 13_321
// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 4_787
// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 5_277
// WASM_OPT_EXPECTED_OUTPUT_SIZE: 3_900
interface I {