-
Notifications
You must be signed in to change notification settings - Fork 28.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
n-api: emit uncaught-exception on unhandled tsfn callbacks
- Loading branch information
1 parent
2ba8728
commit f156f87
Showing
9 changed files
with
211 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict'; | ||
// Flags: --expose-gc --no-concurrent-array-buffer-freeing --no-concurrent-array-buffer-sweeping | ||
|
||
const common = require('../../common'); | ||
const test_reference = require(`./build/${common.buildType}/test_reference`); | ||
const assert = require('assert'); | ||
|
||
process.on('uncaughtException', common.mustCall((err) => { | ||
assert.throws(() => { throw err; }, /finalizer error/); | ||
})); | ||
|
||
(async function() { | ||
{ | ||
test_reference.createExternalWithJsFinalize( | ||
common.mustCall(() => { | ||
throw new Error('finalizer error'); | ||
})); | ||
} | ||
global.gc(); | ||
})().then(common.mustCall()); |
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,21 @@ | ||
'use strict'; | ||
// Flags: --expose-gc --no-concurrent-array-buffer-freeing --no-concurrent-array-buffer-sweeping | ||
|
||
const common = require('../../common'); | ||
const binding = require(`./build/${common.buildType}/test_buffer`); | ||
const assert = require('assert'); | ||
const tick = require('util').promisify(require('../../common/tick')); | ||
|
||
process.on('uncaughtException', common.mustCall((err) => { | ||
assert.throws(() => { throw err; }, /finalizer error/); | ||
})); | ||
|
||
(async function() { | ||
{ | ||
binding.malignFinalizerBuffer(common.mustCall(() => { | ||
throw new Error('finalizer error'); | ||
})); | ||
} | ||
global.gc(); | ||
await tick(10); | ||
})().then(common.mustCall()); |
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
26 changes: 26 additions & 0 deletions
26
test/node-api/test_threadsafe_function/test_uncaught_exception.js
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,26 @@ | ||
'use strict'; | ||
|
||
const common = require('../../common'); | ||
const assert = require('assert'); | ||
const binding = require(`./build/${common.buildType}/binding`); | ||
|
||
const callbackCheck = common.mustCall((err) => { | ||
assert.throws(() => { throw err; }, /callback error/); | ||
process.removeListener('uncaughtException', callbackCheck); | ||
process.on('uncaughtException', finalizerCheck); | ||
}); | ||
const finalizerCheck = common.mustCall((err) => { | ||
assert.throws(() => { throw err; }, /finalizer error/); | ||
}); | ||
process.on('uncaughtException', callbackCheck); | ||
|
||
binding.CallIntoModule( | ||
common.mustCall(() => { | ||
throw new Error('callback error'); | ||
}), | ||
{}, | ||
'resource_name', | ||
common.mustCall(function finalizer() { | ||
throw new Error('finalizer error'); | ||
}) | ||
); |