2021-01-28 15:37:21 -05:00
|
|
|
// 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 {
|
2021-04-12 15:55:05 -04:00
|
|
|
/** Call an op in Rust, and synchronously receive the result. */
|
|
|
|
function opSync(
|
2021-01-28 15:37:21 -05:00
|
|
|
opName: string,
|
2021-06-05 17:10:07 -04:00
|
|
|
a?: any,
|
|
|
|
b?: any,
|
2021-01-28 15:37:21 -05:00
|
|
|
): any;
|
|
|
|
|
2021-04-12 15:55:05 -04:00
|
|
|
/** Call an op in Rust, and asynchronously receive the result. */
|
|
|
|
function opAsync(
|
2021-01-28 15:37:21 -05:00
|
|
|
opName: string,
|
2021-06-05 17:10:07 -04:00
|
|
|
a?: any,
|
|
|
|
b?: any,
|
2021-01-28 15:37:21 -05:00
|
|
|
): Promise<any>;
|
|
|
|
|
2021-11-25 13:49:09 -05:00
|
|
|
/** Mark following promise as "ref", ie. event loop won't exit
|
|
|
|
* until all "ref" promises are resolved. All async ops are "ref" by default. */
|
|
|
|
function refOp(promiseId: number): void;
|
|
|
|
|
|
|
|
/** Mark following promise as "unref", ie. event loop will exit
|
|
|
|
* if there are only "unref" promises left. */
|
|
|
|
function unrefOps(promiseId: number): void;
|
|
|
|
|
2021-01-28 15:37:21 -05:00
|
|
|
/**
|
|
|
|
* 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>;
|
|
|
|
|
2021-09-10 20:54:37 -04:00
|
|
|
/**
|
|
|
|
* Close the resource with the specified op id. Throws `BadResource` error
|
|
|
|
* if resource doesn't exist in resource table.
|
|
|
|
*/
|
2021-01-28 15:37:21 -05:00
|
|
|
function close(rid: number): void;
|
2021-03-23 10:33:06 -04:00
|
|
|
|
2021-09-10 20:54:37 -04:00
|
|
|
/**
|
|
|
|
* Try close the resource with the specified op id; if resource with given
|
|
|
|
* id doesn't exist do nothing.
|
|
|
|
*/
|
|
|
|
function tryClose(rid: number): void;
|
|
|
|
|
2021-11-09 13:26:17 -05:00
|
|
|
/**
|
|
|
|
* Read from a (stream) resource that implements read()
|
|
|
|
*/
|
|
|
|
function read(rid: number, buf: Uint8Array): Promise<number>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write to a (stream) resource that implements write()
|
|
|
|
*/
|
|
|
|
function write(rid: number, buf: Uint8Array): Promise<number>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shutdown a resource
|
|
|
|
*/
|
|
|
|
function shutdown(rid: number): Promise<void>;
|
|
|
|
|
2021-03-23 10:33:06 -04:00
|
|
|
/** Get heap stats for current isolate/worker */
|
|
|
|
function heapStats(): Record<string, number>;
|
2021-06-05 17:10:07 -04:00
|
|
|
|
|
|
|
/** Encode a string to its Uint8Array representation. */
|
|
|
|
function encode(input: string): Uint8Array;
|
2021-07-03 17:33:36 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
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 08:27:54 -04:00
|
|
|
* 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.
|
2021-10-10 10:03:23 -04:00
|
|
|
* - `op_wasm_streaming_set_url`. Sets a source URL for the wasm module.
|
|
|
|
* Takes the rid and a string.
|
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 08:27:54 -04:00
|
|
|
* - To indicate the end of the resource, use `Deno.core.close()` with the
|
|
|
|
* rid.
|
2021-07-03 17:33:36 -04:00
|
|
|
*/
|
|
|
|
function setWasmStreamingCallback(
|
|
|
|
cb: (source: any, rid: number) => void,
|
|
|
|
): void;
|
2021-11-16 14:23:12 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a callback that will be called after resolving ops and before resolving
|
|
|
|
* macrotasks.
|
|
|
|
*/
|
|
|
|
function setNextTickCallback(
|
|
|
|
cb: () => void,
|
|
|
|
): void;
|
|
|
|
|
|
|
|
/** Check if there's a scheduled "next tick". */
|
|
|
|
function hasNextTickScheduled(): bool;
|
|
|
|
|
|
|
|
/** Set a value telling the runtime if there are "next ticks" scheduled */
|
|
|
|
function setHasNextTickScheduled(value: bool): void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a callback that will be called after resolving ops and "next ticks".
|
|
|
|
*/
|
|
|
|
function setMacrotaskCallback(
|
|
|
|
cb: () => bool,
|
|
|
|
): void;
|
2021-11-27 18:46:12 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a callback that will be called when a promise without a .catch
|
|
|
|
* handler is rejected. Returns the old handler or undefined.
|
|
|
|
*/
|
|
|
|
function setPromiseRejectCallback(
|
|
|
|
cb: PromiseRejectCallback,
|
|
|
|
): undefined | PromiseRejectCallback;
|
|
|
|
|
|
|
|
export type PromiseRejectCallback = (
|
|
|
|
type: number,
|
|
|
|
promise: Promise,
|
|
|
|
reason: any,
|
|
|
|
) => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a callback that will be called when an exception isn't caught
|
|
|
|
* by any try/catch handlers. Currently only invoked when the callback
|
|
|
|
* to setPromiseRejectCallback() throws an exception but that is expected
|
|
|
|
* to change in the future. Returns the old handler or undefined.
|
|
|
|
*/
|
|
|
|
function setUncaughtExceptionCallback(
|
|
|
|
cb: UncaughtExceptionCallback,
|
|
|
|
): undefined | UncaughtExceptionCallback;
|
|
|
|
|
|
|
|
export type UncaughtExceptionCallback = (err: any) => void;
|
2021-01-28 15:37:21 -05:00
|
|
|
}
|
|
|
|
}
|