summaryrefslogtreecommitdiff
path: root/ext/node/polyfills/process.ts
diff options
context:
space:
mode:
authorSatya Rohith <me@satyarohith.com>2024-04-16 19:15:41 +0530
committerGitHub <noreply@github.com>2024-04-16 13:45:41 +0000
commit50223c5c532332f4a296b12b027f85429f529690 (patch)
tree75d4494d1ade596038ad52ac0241addcc3a124c2 /ext/node/polyfills/process.ts
parent0a7f46b8c29d67b579e4ffd4681aa5d0b7e30c6b (diff)
fix(ext/node): dispatch beforeExit/exit events irrespective of listeners (#23382)
Closes https://github.com/denoland/deno/issues/23342 Closes https://github.com/denoland/deno/issues/21757
Diffstat (limited to 'ext/node/polyfills/process.ts')
-rw-r--r--ext/node/polyfills/process.ts20
1 files changed, 5 insertions, 15 deletions
diff --git a/ext/node/polyfills/process.ts b/ext/node/polyfills/process.ts
index 70c516c96..b89b7af52 100644
--- a/ext/node/polyfills/process.ts
+++ b/ext/node/polyfills/process.ts
@@ -802,15 +802,13 @@ function processOnError(event: ErrorEvent) {
uncaughtExceptionHandler(event.error, "uncaughtException");
}
-function processOnBeforeUnload(event: Event) {
+function dispatchProcessBeforeExitEvent() {
process.emit("beforeExit", process.exitCode || 0);
processTicksAndRejections();
- if (core.eventLoopHasMoreWork()) {
- event.preventDefault();
- }
+ return core.eventLoopHasMoreWork();
}
-function processOnUnload() {
+function dispatchProcessExitEvent() {
if (!process._exiting) {
process._exiting = true;
process.emit("exit", process.exitCode || 0);
@@ -856,16 +854,6 @@ function synchronizeListeners() {
} else {
globalThis.removeEventListener("error", processOnError);
}
- if (beforeExitListenerCount > 0) {
- globalThis.addEventListener("beforeunload", processOnBeforeUnload);
- } else {
- globalThis.removeEventListener("beforeunload", processOnBeforeUnload);
- }
- if (exitListenerCount > 0) {
- globalThis.addEventListener("unload", processOnUnload);
- } else {
- globalThis.removeEventListener("unload", processOnUnload);
- }
}
// Overwrites the 1st and 2nd items with getters.
@@ -880,6 +868,8 @@ Object.defineProperty(argv, "1", {
},
});
+internals.dispatchProcessBeforeExitEvent = dispatchProcessBeforeExitEvent;
+internals.dispatchProcessExitEvent = dispatchProcessExitEvent;
// Should be called only once, in `runtime/js/99_main.js` when the runtime is
// bootstrapped.
internals.__bootstrapNodeProcess = function (