summaryrefslogtreecommitdiff
path: root/core/lib.deno_core.d.ts
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2021-11-28 00:46:12 +0100
committerGitHub <noreply@github.com>2021-11-28 00:46:12 +0100
commit2d830c263b0a3519c7fb75199a6ad1b8f10d2b51 (patch)
tree71a045c5b66b13ddaf1f4c43fc6031e0dfa41a8a /core/lib.deno_core.d.ts
parent993a1dd41ae5f96bdb24b09757e24c2ac24126d0 (diff)
feat(core): intercept unhandled promise rejections (#12910)
Provide a programmatic means of intercepting rejected promises without a .catch() handler. Needed for Node compat mode. Also do a first pass at uncaughtException support because they're closely intertwined in Node. It's like that Frank Sinatra song: you can't have one without the other. Stepping stone for #7013.
Diffstat (limited to 'core/lib.deno_core.d.ts')
-rw-r--r--core/lib.deno_core.d.ts26
1 files changed, 26 insertions, 0 deletions
diff --git a/core/lib.deno_core.d.ts b/core/lib.deno_core.d.ts
index 59b2df542..240284c88 100644
--- a/core/lib.deno_core.d.ts
+++ b/core/lib.deno_core.d.ts
@@ -115,5 +115,31 @@ declare namespace Deno {
function setMacrotaskCallback(
cb: () => bool,
): void;
+
+ /**
+ * 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;
}
}