mirror of
https://github.com/denoland/deno.git
synced 2025-08-03 10:33:54 +00:00
BREAKING: Remove support for .wasm imports (#5135)
Importing .wasm files is non-standardized therefore deciding to support current functionality past 1.0 release is risky. Besides that .wasm import posed many challenges in our codebase due to complex interactions with TS compiler which spawned thread for each encountered .wasm import. This commit removes: - cli/compilers/wasm.rs - cli/compilers/wasm_wrap.js - two integration tests related to .wasm imports
This commit is contained in:
parent
93cf3bd534
commit
2b66b8a03e
20 changed files with 5 additions and 388 deletions
|
@ -4,10 +4,9 @@
|
|||
// This module is the entry point for "compiler" isolate, ie. the one
|
||||
// that is created when Deno needs to compile TS/WASM to JS.
|
||||
//
|
||||
// It provides a two functions that should be called by Rust:
|
||||
// It provides a single functions that should be called by Rust:
|
||||
// - `bootstrapTsCompilerRuntime`
|
||||
// - `bootstrapWasmCompilerRuntime`
|
||||
// Either of these functions must be called when creating isolate
|
||||
// This functions must be called when creating isolate
|
||||
// to properly setup runtime.
|
||||
|
||||
// NOTE: this import has side effects!
|
||||
|
@ -22,7 +21,6 @@ import { sendAsync, sendSync } from "./ops/dispatch_json.ts";
|
|||
import { bootstrapWorkerRuntime } from "./runtime_worker.ts";
|
||||
import { assert, log } from "./util.ts";
|
||||
import * as util from "./util.ts";
|
||||
import { atob } from "./web/text_encoding.ts";
|
||||
import { TextDecoder, TextEncoder } from "./web/text_encoding.ts";
|
||||
import { core } from "./core.ts";
|
||||
|
||||
|
@ -1123,16 +1121,6 @@ function commonPath(paths: string[], sep = "/"): string {
|
|||
return prefix.endsWith(sep) ? prefix : `${prefix}${sep}`;
|
||||
}
|
||||
|
||||
function base64ToUint8Array(data: string): Uint8Array {
|
||||
const binString = atob(data);
|
||||
const size = binString.length;
|
||||
const bytes = new Uint8Array(size);
|
||||
for (let i = 0; i < size; i++) {
|
||||
bytes[i] = binString.charCodeAt(i);
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
let rootExports: string[] | undefined;
|
||||
|
||||
function normalizeUrl(rootName: string): string {
|
||||
|
@ -1585,43 +1573,11 @@ async function tsCompilerOnMessage({
|
|||
// Currently Rust shuts down worker after single request
|
||||
}
|
||||
|
||||
async function wasmCompilerOnMessage({
|
||||
data: binary,
|
||||
}: {
|
||||
data: string;
|
||||
}): Promise<void> {
|
||||
const buffer = base64ToUint8Array(binary);
|
||||
// @ts-ignore
|
||||
const compiled = await WebAssembly.compile(buffer);
|
||||
|
||||
util.log(">>> WASM compile start");
|
||||
|
||||
const importList = Array.from(
|
||||
// @ts-ignore
|
||||
new Set(WebAssembly.Module.imports(compiled).map(({ module }) => module))
|
||||
);
|
||||
const exportList = Array.from(
|
||||
// @ts-ignore
|
||||
new Set(WebAssembly.Module.exports(compiled).map(({ name }) => name))
|
||||
);
|
||||
|
||||
globalThis.postMessage({ importList, exportList });
|
||||
|
||||
util.log("<<< WASM compile end");
|
||||
|
||||
// Currently Rust shuts down worker after single request
|
||||
}
|
||||
|
||||
function bootstrapTsCompilerRuntime(): void {
|
||||
bootstrapWorkerRuntime("TS", false);
|
||||
globalThis.onmessage = tsCompilerOnMessage;
|
||||
}
|
||||
|
||||
function bootstrapWasmCompilerRuntime(): void {
|
||||
bootstrapWorkerRuntime("WASM", false);
|
||||
globalThis.onmessage = wasmCompilerOnMessage;
|
||||
}
|
||||
|
||||
// Removes the `__proto__` for security reasons. This intentionally makes
|
||||
// Deno non compliant with ECMA-262 Annex B.2.2.1
|
||||
//
|
||||
|
@ -1632,7 +1588,6 @@ Object.defineProperties(globalThis, {
|
|||
bootstrap: {
|
||||
value: {
|
||||
...globalThis.bootstrap,
|
||||
wasmCompilerRuntime: bootstrapWasmCompilerRuntime,
|
||||
tsCompilerRuntime: bootstrapTsCompilerRuntime,
|
||||
},
|
||||
configurable: true,
|
||||
|
|
|
@ -147,7 +147,6 @@ declare global {
|
|||
workerRuntime: ((name: string) => Promise<void> | void) | undefined;
|
||||
// Assigned to `self` global - compiler
|
||||
tsCompilerRuntime: (() => void) | undefined;
|
||||
wasmCompilerRuntime: (() => void) | undefined;
|
||||
};
|
||||
|
||||
var onerror:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue