1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-26 16:09:27 -05:00
denoland-deno/core/lib.deno_core.d.ts
Andreu Botella 4d6f412b0b
refactor(core): Turn the wasm_streaming_feed binding into ops (#11985)
Async WebAssembly compilation was implemented by adding two
bindings: `set_wasm_streaming_callback`, which registered a callback to
be called whenever a streaming wasm compilation was started, and
`wasm_streaming_feed`, which let the JS callback modify the state of the
v8 wasm compiler.

`set_wasm_streaming_callback` cannot currently be implemented as
anything other than a binding, but `wasm_streaming_feed` does not really
need to use anything specific to bindings, and could indeed be
implemented as one or more ops. This PR does that, resulting in a
simplification of the relevant code.

There are three operations on the state of the v8 wasm compiler that
`wasm_streaming_feed` allowed: feeding new bytes into the compiler,
letting it know that there are no more bytes coming from the network,
and aborting the compilation. This PR provides `op_wasm_streaming_feed`
to feed new bytes into the compiler, and `op_wasm_streaming_abort` to
abort the compilation. It doesn't provide an op to let v8 know that the
response is finished, but closing the resource with `Deno.core.close()`
will achieve that.
2021-09-13 14:27:54 +02:00

73 lines
2.4 KiB
TypeScript

// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
// deno-lint-ignore-file no-explicit-any
/// <reference no-default-lib="true" />
/// <reference lib="esnext" />
declare namespace Deno {
declare namespace core {
/** Call an op in Rust, and synchronously receive the result. */
function opSync(
opName: string,
a?: any,
b?: any,
): any;
/** Call an op in Rust, and asynchronously receive the result. */
function opAsync(
opName: string,
a?: any,
b?: any,
): Promise<any>;
/**
* Retrieve a list of all registered ops, in the form of a map that maps op
* name to internal numerical op id.
*/
function ops(): Record<string, number>;
/**
* Retrieve a list of all open resources, in the form of a map that maps
* resource id to the resource name.
*/
function resources(): Record<string, string>;
/**
* Close the resource with the specified op id. Throws `BadResource` error
* if resource doesn't exist in resource table.
*/
function close(rid: number): void;
/**
* Try close the resource with the specified op id; if resource with given
* id doesn't exist do nothing.
*/
function tryClose(rid: number): void;
/** Get heap stats for current isolate/worker */
function heapStats(): Record<string, number>;
/** Encode a string to its Uint8Array representation. */
function encode(input: string): Uint8Array;
/**
* Set a callback that will be called when the WebAssembly streaming APIs
* (`WebAssembly.compileStreaming` and `WebAssembly.instantiateStreaming`)
* are called in order to feed the source's bytes to the wasm compiler.
* The callback is called with the source argument passed to the streaming
* APIs and an rid to use with the wasm streaming ops.
*
* The callback should eventually invoke the following ops:
* - `op_wasm_streaming_feed`. Feeds bytes from the wasm resource to the
* compiler. Takes the rid and a `Uint8Array`.
* - `op_wasm_streaming_abort`. Aborts the wasm compilation. Takes the rid
* and an exception. Invalidates the resource.
* - To indicate the end of the resource, use `Deno.core.close()` with the
* rid.
*/
function setWasmStreamingCallback(
cb: (source: any, rid: number) => void,
): void;
}
}