Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fixup! node-api: enable uncaught exceptions policy by default
  • Loading branch information
legendecas committed Sep 21, 2023
commit 8e9cae0e103232dac0c5006aa0320caaf74ae0fd
2 changes: 1 addition & 1 deletion doc/api/n-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6249,7 +6249,7 @@ napi_create_threadsafe_function(napi_env env,

* Experimental (`NAPI_EXPERIMENTAL` is defined):

Uncaught exceptions thrown in `call_js_cb` is handled with the
Uncaught exceptions thrown in `call_js_cb` are handled with the
[`'uncaughtException'`][] event, instead of being ignored.

### `napi_get_threadsafe_function_context`
Expand Down
23 changes: 2 additions & 21 deletions test/node-api/test_threadsafe_function/test_uncaught_exception.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,7 @@
'use strict';

const common = require('../../common');
const assert = require('assert');
const binding = require(`./build/${common.buildType}/test_uncaught_exception`);
const { testUncaughtException } = require('./uncaught_exception');

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');
}),
);
testUncaughtException(binding);
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,7 @@
// Flags: --force-node-api-uncaught-exceptions-policy

const common = require('../../common');
const assert = require('assert');
const binding = require(`./build/${common.buildType}/test_uncaught_exception_v9`);
const { testUncaughtException } = require('./uncaught_exception');

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');
}),
);
testUncaughtException(binding);
31 changes: 31 additions & 0 deletions test/node-api/test_threadsafe_function/uncaught_exception.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

const common = require('../../common');
const assert = require('assert');

function testUncaughtException(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');
}),
);
}

module.exports = {
testUncaughtException,
};