forked from denoland/deno_core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.deno_core.d.ts
337 lines (286 loc) · 12 KB
/
lib.deno_core.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// deno-lint-ignore-file ban-types no-explicit-any
/// <reference no-default-lib="true" />
/// <reference lib="esnext" />
declare namespace Deno {
namespace core {
/** Returns a proxy that generates the fast versions of sync and async ops. */
function ensureFastOps(keep?: boolean): any;
/** 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 refOpPromise<T>(promise: Promise<T>): void;
/** Mark following promise as "unref", ie. event loop will exit
* if there are only "unref" promises left. */
function unrefOpPromise<T>(promise: Promise<T>): void;
/**
* 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.
*/
function setOpCallTracingEnabled(enabled: boolean);
function isOpCallTracingEnabled(): boolean;
/**
* Returns the origin stack trace of the given async op promise. The promise
* must be ongoing.
*/
function getOpCallTraceForPromise<T>(promise: Promise<T>): string | null;
/**
* Returns a map containing traces for all ongoing async ops. The key is the promise id.
* Tracing only occurs when `Deno.core.setOpCallTracingEnabled()` was previously
* enabled.
*/
function getAllOpCallTraces(): Map<number, string>;
/**
* List of all registered ops, in the form of a map that maps op
* name to function.
*/
const ops: Record<string, (...args: unknown[]) => any>;
/**
* 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;
/**
* 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>;
/**
* Write to a (stream) resource that implements write()
*/
function writeAll(rid: number, buf: Uint8Array): Promise<void>;
/**
* 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;
/**
* Print a message to stdout or stderr
*/
function print(message: string, is_err?: boolean): void;
/**
* Shutdown a resource
*/
function shutdown(rid: number): Promise<void>;
/** Encode a string to its Uint8Array representation. */
function encode(input: string): Uint8Array;
/** Decode a string from its Uint8Array representation. */
function decode(input: Uint8Array): string;
/**
* 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.
* - `op_wasm_streaming_set_url`. Sets a source URL for the wasm module.
* Takes the rid and a string.
* - To indicate the end of the resource, use `Deno.core.close()` with the
* rid.
*/
function setWasmStreamingCallback(
cb: (source: any, rid: number) => void,
): void;
/**
* 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(): boolean;
/** Set a value telling the runtime if there are "next ticks" scheduled */
function setHasNextTickScheduled(value: boolean): void;
/** Enqueue a timer at the given depth, optionally repeating. */
function queueTimer(
depth: number,
repeat: boolean,
delay: number,
callback: () => void,
): number;
/** Cancel a timer with a given ID. */
function cancelTimer(id: number);
/** Ref a timer with a given ID, blocking the runtime from exiting if the timer is still running. */
function refTimer(id: number);
/** Unref a timer with a given ID, allowing the runtime to exit if the timer is still running. */
function unrefTimer(id: number);
/** Gets the current timer depth. */
function getTimerDepth(): number;
/**
* Set a callback that will be called after resolving ops and "next ticks".
*/
function setMacrotaskCallback(
cb: () => boolean,
): void;
/**
* Sets the unhandled promise rejection handler. The handler returns 'true' if the
* rejection has been handled. If the handler returns 'false', the promise is considered
* unhandled, and the runtime then raises an uncatchable error and halts.
*/
function setUnhandledPromiseRejectionHandler(
cb: PromiseRejectCallback,
): PromiseRejectCallback;
export type PromiseRejectCallback = (
promise: Promise<unknown>,
reason: any,
) => boolean;
/**
* Sets the handled promise rejection handler.
*/
function setHandledPromiseRejectionHandler(
cb: PromiseHandledCallback,
): PromiseHandledCallback;
export type PromiseHandledCallback = (
promise: Promise<unknown>,
reason: any,
) => void;
/**
* Report an exception that was not handled by any runtime handler, and escaped to the
* top level. This terminates the runtime.
*/
function reportUnhandledException(e: Error): void;
/**
* Report an unhandled promise rejection that was not handled by any runtime handler, and
* escaped to the top level. This terminates the runtime.
*/
function reportUnhandledPromiseRejection(e: Error): 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;
export class BadResource extends Error {}
export const BadResourcePrototype: typeof BadResource.prototype;
export class Interrupted extends Error {}
export const InterruptedPrototype: typeof Interrupted.prototype;
function serialize(
value: any,
options?: any,
errorCallback?,
): Uint8Array;
function deserialize(buffer: Uint8Array, options?: any): any;
/**
* 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;
function isAnyArrayBuffer(
value: unknown,
): value is ArrayBuffer | SharedArrayBuffer;
function isArgumentsObject(value: unknown): value is IArguments;
function isArrayBuffer(value: unknown): value is ArrayBuffer;
function isArrayBufferView(value: unknown): value is ArrayBufferView;
function isAsyncFunction(
value: unknown,
): value is (
...args: unknown[]
) => Promise<unknown> | AsyncGeneratorFunction;
function isBigIntObject(value: unknown): value is BigInt;
function isBooleanObject(value: unknown): value is Boolean;
function isBoxedPrimitive(
value: unknown,
): value is BigInt | Boolean | Number | String | Symbol;
function isDataView(value: unknown): value is DataView;
function isDate(value: unknown): value is Date;
function isGeneratorFunction(
value: unknown,
): value is GeneratorFunction | AsyncGeneratorFunction;
function isGeneratorObject(value: unknown): value is Generator;
function isMap(value: unknown): value is Map<unknown, unknown>;
function isMapIterator(value: unknown): value is IterableIterator<unknown>;
function isModuleNamespaceObject(value: unknown): value is object;
function isNativeError(value: unknown): value is Error;
function isNumberObject(value: unknown): value is Number;
function isPromise(value: unknown): value is Promise<unknown>;
function isProxy(value: unknown): value is object;
function isRegExp(value: unknown): value is RegExp;
function isSet(value: unknown): value is Set<unknown>;
function isSetIterator(value: unknown): value is IterableIterator<unknown>;
function isSharedArrayBuffer(value: unknown): value is SharedArrayBuffer;
function isStringObject(value: unknown): value is String;
function isSymbolObject(value: unknown): value is Symbol;
function isTypedArray(
value: unknown,
): value is
| Uint8Array
| Uint8ClampedArray
| Uint16Array
| Uint32Array
| Int8Array
| Int16Array
| Int32Array
| Float32Array
| Float64Array
| BigUint64Array
| BigInt64Array;
function isWeakMap(value: unknown): value is WeakMap<WeakKey, unknown>;
function isWeakSet(value: unknown): value is WeakSet<WeakKey>;
function propWritable(value: unknown): PropertyDescriptor;
function propNonEnumerable(value: unknown): PropertyDescriptor;
function propReadOnly(value: unknown): PropertyDescriptor;
function propGetterOnly(value: unknown): PropertyDescriptor;
function propWritableLazyLoaded<T>(
getter: (loadedValue: T) => unknown,
loadFn: LazyLoader<T>,
): PropertyDescriptor;
function propNonEnumerableLazyLoaded<T>(
getter: (loadedValue: T) => unknown,
loadFn: LazyLoader<T>,
): PropertyDescriptor;
type LazyLoader<T> = () => T;
function createLazyLoader<T = unknown>(specifier: string): LazyLoader<T>;
function createCancelHandle(): number;
function encodeBinaryString(data: Uint8Array): string;
const build: {
target: string;
arch: string;
os: string;
vendor: string;
env: string | undefined;
};
}
}