mirror of
https://github.com/denoland/deno.git
synced 2025-09-29 13:44:47 +00:00
feat(ext/web): add globalThis.reportError() (#13799)
This commit is contained in:
parent
a64e63c361
commit
c30d95f2e3
10 changed files with 93 additions and 17 deletions
|
@ -1367,6 +1367,20 @@
|
|||
reportExceptionStackedCalls--;
|
||||
}
|
||||
|
||||
function checkThis(thisArg) {
|
||||
if (thisArg !== null && thisArg !== undefined && thisArg !== globalThis) {
|
||||
throw new TypeError("Illegal invocation");
|
||||
}
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/#dom-reporterror
|
||||
function reportError(error) {
|
||||
checkThis(this);
|
||||
const prefix = "Failed to call 'reportError'";
|
||||
webidl.requiredArguments(arguments.length, 1, { prefix });
|
||||
reportException(error);
|
||||
}
|
||||
|
||||
window.Event = Event;
|
||||
window.EventTarget = EventTarget;
|
||||
window.ErrorEvent = ErrorEvent;
|
||||
|
@ -1377,6 +1391,7 @@
|
|||
window.dispatchEvent = EventTarget.prototype.dispatchEvent;
|
||||
window.addEventListener = EventTarget.prototype.addEventListener;
|
||||
window.removeEventListener = EventTarget.prototype.removeEventListener;
|
||||
window.reportError = reportError;
|
||||
window.__bootstrap.eventTarget = {
|
||||
EventTarget,
|
||||
setEventTargetData,
|
||||
|
|
19
ext/web/lib.deno_web.d.ts
vendored
19
ext/web/lib.deno_web.d.ts
vendored
|
@ -890,3 +890,22 @@ declare class DecompressionStream {
|
|||
readonly readable: ReadableStream<Uint8Array>;
|
||||
readonly writable: WritableStream<Uint8Array>;
|
||||
}
|
||||
|
||||
/** Dispatch an uncaught exception. Similar to a synchronous version of:
|
||||
* ```ts
|
||||
* setTimeout(() => { throw error; }, 0);
|
||||
* ```
|
||||
* The error can not be caught with a `try/catch` block. An error event will
|
||||
* be dispatched to the global scope. You can prevent the error from being
|
||||
* reported to the console with `Event.prototype.preventDefault()`:
|
||||
* ```ts
|
||||
* addEventListener("error", (event) => {
|
||||
* event.preventDefault();
|
||||
* });
|
||||
* reportError(new Error("foo")); // Will not be reported.
|
||||
* ```
|
||||
* In Deno, this error will terminate the process if not intercepted like above.
|
||||
*/
|
||||
declare function reportError(
|
||||
error: any,
|
||||
): void;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue