forked from denoland/deno
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ext/node): dispatch beforeExit/exit events irrespective of listen…
…ers (denoland#23382) Closes denoland#23342 Closes denoland#21757
- Loading branch information
1 parent
bc89d83
commit b484f49
Showing
11 changed files
with
164 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
beforeunload emitted from addEventListener | ||
beforeunload emitted from addEventListener | ||
beforeunload emitted from addEventListener | ||
beforeExit emitted from process.on | ||
more work done! 1 | ||
beforeunload emitted from addEventListener | ||
beforeExit emitted from process.on | ||
more work done! 2 | ||
beforeunload emitted from addEventListener | ||
beforeExit emitted from process.on | ||
unload emitted from addEventListener | ||
exit emitted from process.on |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import process from "node:process"; | ||
|
||
let count = 0; | ||
process.on("beforeExit", () => { | ||
if (count === 0 || count === 1) { | ||
setTimeout(() => console.log("more work done!", count), 10); | ||
} | ||
count++; | ||
console.log("beforeExit emitted from process.on"); | ||
}); | ||
process.on("exit", () => console.log("exit emitted from process.on")); | ||
|
||
let countWeb = 0; | ||
addEventListener("beforeunload", (event) => { | ||
if (countWeb == 0 || countWeb == 1) { | ||
event.preventDefault(); | ||
} | ||
countWeb++; | ||
console.log("beforeunload emitted from addEventListener"); | ||
}); | ||
|
||
addEventListener( | ||
"unload", | ||
() => console.log("unload emitted from addEventListener"), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
beforeExit emitted from processEmit | ||
exit emitted from processEmit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import process from "node:process"; | ||
|
||
const originalEmit = process.emit; | ||
process.emit = function (event, ...args) { | ||
if (event === "exit" || event === "beforeExit") { | ||
console.log(`${event} emitted from processEmit`); | ||
} | ||
return originalEmit.call(this, event, ...args); | ||
}; |