Skip to content

Commit e517340

Browse files
pmarchiniBridgeARNiharPhansalkar
committed
assert: use isError instead of instanceof in innerOk to define message type
Co-Authored-By: Ruben Bridgewater <ruben@bridgewater.de> Co-Authored-By: Nihar Phansalkar <phansalkarnihar@gmail.com>
1 parent befbe69 commit e517340

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/assert.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ function innerOk(fn, argLen, value, message) {
393393
} else if (message == null) {
394394
generatedMessage = true;
395395
message = getErrMessage(message, fn);
396-
} else if (message instanceof Error) {
396+
} else if (isError(message)) {
397397
throw message;
398398
}
399399

test/parallel/test-assert.js

+10
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ assert.throws(() => a.ok(false), a.AssertionError, 'ok(false)');
5555
assert.ok(threw, 'Error: ok(false)');
5656
}
5757

58+
// Errors created in different contexts are handled as any other custom error
59+
{
60+
const context = vm.createContext();
61+
const error = vm.runInContext('new SyntaxError("custom error")', context);
62+
63+
assert.throws(() => assert(false, error), {
64+
message: 'custom error',
65+
name: 'SyntaxError'
66+
});
67+
}
5868

5969
a(true);
6070
a('test', 'ok(\'test\')');

0 commit comments

Comments
 (0)