Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb3a2726

Browse files
pmarchiniBridgeARNiharPhansalkar
authored andcommitted
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:#53980Fixes:#50780Reviewed-By: James M Snell <jasnell@gmail.com>Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
1 parent8e64c02 commitb3a2726

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

‎lib/assert.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ function innerOk(fn, argLen, value, message) {
393393
}elseif(message==null){
394394
generatedMessage=true;
395395
message=getErrMessage(message,fn);
396-
}elseif(messageinstanceofError){
396+
}elseif(isError(message)){
397397
throwmessage;
398398
}
399399

‎test/parallel/test-assert.js

Lines changed: 10 additions & 0 deletions
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+
constcontext=vm.createContext();
61+
consterror=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)

[8]ページ先頭

©2009-2025 Movatter.jp