-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src: add maybe versions of EmitExit and EmitBeforeExit
This addresses a TODO comment, and removes invalid `.ToLocalChecked()` calls from our code base. PR-URL: #35486 Backport-PR-URL: #38786 Reviewed-By: James M Snell <[email protected]>
- Loading branch information
Showing
8 changed files
with
105 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
common.skipIfWorker(); | ||
|
||
// Test that 'exit' is emitted if 'beforeExit' throws. | ||
|
||
process.on('exit', common.mustCall(() => { | ||
process.exitCode = 0; | ||
})); | ||
process.on('beforeExit', common.mustCall(() => { | ||
throw new Error(); | ||
})); |
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,28 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const { Worker } = require('worker_threads'); | ||
|
||
// Test that 'exit' is emitted if 'beforeExit' throws, both inside the Worker. | ||
|
||
const workerData = new Uint8Array(new SharedArrayBuffer(2)); | ||
const w = new Worker(` | ||
const { workerData } = require('worker_threads'); | ||
process.on('exit', () => { | ||
workerData[0] = 100; | ||
}); | ||
process.on('beforeExit', () => { | ||
workerData[1] = 200; | ||
throw new Error('banana'); | ||
}); | ||
`, { eval: true, workerData }); | ||
|
||
w.on('error', common.mustCall((err) => { | ||
assert.strictEqual(err.message, 'banana'); | ||
})); | ||
|
||
w.on('exit', common.mustCall((code) => { | ||
assert.strictEqual(code, 1); | ||
assert.strictEqual(workerData[0], 100); | ||
assert.strictEqual(workerData[1], 200); | ||
})); |