assert: use isError instead of instanceof in innerOk

Co-Authored-By: Ruben Bridgewater <ruben@bridgewater.de>
Co-Authored-By: Nihar Phansalkar <phansalkarnihar@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/53980
Fixes: https://github.com/nodejs/node/issues/50780
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
This commit is contained in:
Pietro Marchini 2024-07-28 15:13:59 +02:00 committed by GitHub
parent 69a69f6ca3
commit e4263dad96
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 1 deletions

View File

@ -393,7 +393,7 @@ function innerOk(fn, argLen, value, message) {
} else if (message == null) {
generatedMessage = true;
message = getErrMessage(message, fn);
} else if (message instanceof Error) {
} else if (isError(message)) {
throw message;
}

View File

@ -55,6 +55,16 @@ assert.throws(() => a.ok(false), a.AssertionError, 'ok(false)');
assert.ok(threw, 'Error: ok(false)');
}
// Errors created in different contexts are handled as any other custom error
{
const context = vm.createContext();
const error = vm.runInContext('new SyntaxError("custom error")', context);
assert.throws(() => assert(false, error), {
message: 'custom error',
name: 'SyntaxError'
});
}
a(true);
a('test', 'ok(\'test\')');