Skip to content

Commit

Permalink
assert: use isError instead of instanceof in innerOk
Browse files Browse the repository at this point in the history
Co-Authored-By: Ruben Bridgewater <[email protected]>
Co-Authored-By: Nihar Phansalkar <[email protected]>
PR-URL: #53980
Fixes: #50780
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Marco Ippolito <[email protected]>
  • Loading branch information
3 people authored and marco-ippolito committed Aug 19, 2024
1 parent c711c98 commit 64ca138
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
10 changes: 10 additions & 0 deletions test/parallel/test-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -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\')');
Expand Down

0 comments on commit 64ca138

Please sign in to comment.