2023-01-02 16:00:42 -05:00
|
|
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
2021-01-28 15:37:21 -05:00
|
|
|
|
|
|
|
// deno-lint-ignore-file no-explicit-any
|
|
|
|
|
|
|
|
/// <reference no-default-lib="true" />
|
|
|
|
/// <reference lib="esnext" />
|
|
|
|
|
|
|
|
declare namespace Deno {
|
2022-01-06 04:58:44 -05:00
|
|
|
namespace core {
|
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,
|
2022-08-11 09:56:56 -04:00
|
|
|
...args: 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. */
|
2023-02-22 14:09:59 -05:00
|
|
|
function unrefOp(promiseId: number): void;
|
2021-11-25 13:49:09 -05:00
|
|
|
|
2021-01-28 15:37:21 -05:00
|
|
|
/**
|
2022-08-11 09:56:56 -04:00
|
|
|
* List of all registered ops, in the form of a map that maps op
|
2021-01-28 15:37:21 -05:00
|
|
|
* name to internal numerical op id.
|
|
|
|
*/
|
2022-08-11 09:56:56 -04:00
|
|
|
const ops: Record<string, (...args: unknown[]) => any>;
|
2021-01-28 15:37:21 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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>;
|
|
|
|
|
2022-10-10 04:28:35 -04:00
|
|
|
/**
|
|
|
|
* Write to a (stream) resource that implements write()
|
|
|
|
*/
|
|
|
|
function writeAll(rid: number, buf: Uint8Array): Promise<void>;
|
|
|
|
|
2023-04-05 18:14:16 -04:00
|
|
|
/**
|
|
|
|
* Synchronously read from a (stream) resource that implements readSync().
|
|
|
|
*/
|
|
|
|
function readSync(rid: number, buf: Uint8Array): number;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Synchronously write to a (stream) resource that implements writeSync().
|
|
|
|
*/
|
|
|
|
function writeSync(rid: number, buf: Uint8Array): number;
|
|
|
|
|
2022-07-31 16:15:29 -04:00
|
|
|
/**
|
|
|
|
* Print a message to stdout or stderr
|
|
|
|
*/
|
|
|
|
function print(message: string, is_err?: boolean): void;
|
|
|
|
|
2021-11-09 13:26:17 -05:00
|
|
|
/**
|
|
|
|
* Shutdown a resource
|
|
|
|
*/
|
|
|
|
function shutdown(rid: number): Promise<void>;
|
|
|
|
|
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". */
|
2022-01-06 04:58:44 -05:00
|
|
|
function hasNextTickScheduled(): boolean;
|
2021-11-16 14:23:12 -05:00
|
|
|
|
|
|
|
/** Set a value telling the runtime if there are "next ticks" scheduled */
|
2022-01-06 04:58:44 -05:00
|
|
|
function setHasNextTickScheduled(value: boolean): void;
|
2021-11-16 14:23:12 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a callback that will be called after resolving ops and "next ticks".
|
|
|
|
*/
|
|
|
|
function setMacrotaskCallback(
|
2022-01-06 04:58:44 -05:00
|
|
|
cb: () => boolean,
|
2021-11-16 14:23:12 -05:00
|
|
|
): 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,
|
2022-01-06 04:58:44 -05:00
|
|
|
promise: Promise<unknown>,
|
2021-11-27 18:46:12 -05:00
|
|
|
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;
|
2022-02-16 13:53:17 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Enables collection of stack traces of all async ops. This allows for
|
|
|
|
* debugging of where a given async op was started. Deno CLI uses this for
|
|
|
|
* improving error message in op sanitizer errors for `deno test`.
|
|
|
|
*
|
|
|
|
* **NOTE:** enabling tracing has a significant negative performance impact.
|
|
|
|
* To get high level metrics on async ops with no added performance cost,
|
|
|
|
* use `Deno.core.metrics()`.
|
|
|
|
*/
|
|
|
|
function enableOpCallTracing(): void;
|
|
|
|
|
|
|
|
export interface OpCallTrace {
|
|
|
|
opName: string;
|
|
|
|
stack: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A map containing traces for all ongoing async ops. The key is the op id.
|
|
|
|
* Tracing only occurs when `Deno.core.enableOpCallTracing()` was previously
|
|
|
|
* enabled.
|
|
|
|
*/
|
|
|
|
const opCallTraces: Map<number, OpCallTrace>;
|
2022-09-28 10:09:33 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a callback for the given Promise event. If this function is called
|
|
|
|
* multiple times, the callbacks are called in the order they were added.
|
|
|
|
* - `init_hook` is called when a new promise is created. When a new promise
|
|
|
|
* is created as part of the chain in the case of `Promise.then` or in the
|
|
|
|
* intermediate promises created by `Promise.{race, all}`/`AsyncFunctionAwait`,
|
|
|
|
* we pass the parent promise otherwise we pass undefined.
|
|
|
|
* - `before_hook` is called at the beginning of the promise reaction.
|
|
|
|
* - `after_hook` is called at the end of the promise reaction.
|
|
|
|
* - `resolve_hook` is called at the beginning of resolve or reject function.
|
|
|
|
*/
|
|
|
|
function setPromiseHooks(
|
|
|
|
init_hook?: (
|
|
|
|
promise: Promise<unknown>,
|
|
|
|
parentPromise?: Promise<unknown>,
|
|
|
|
) => void,
|
|
|
|
before_hook?: (promise: Promise<unknown>) => void,
|
|
|
|
after_hook?: (promise: Promise<unknown>) => void,
|
|
|
|
resolve_hook?: (promise: Promise<unknown>) => void,
|
|
|
|
): void;
|
2023-03-05 17:46:37 -05:00
|
|
|
|
|
|
|
const build: {
|
|
|
|
target: string;
|
|
|
|
arch: string;
|
|
|
|
os: string;
|
|
|
|
vendor: string;
|
|
|
|
env: string | undefined;
|
|
|
|
};
|
2021-01-28 15:37:21 -05:00
|
|
|
}
|
|
|
|
}
|