File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -78,6 +78,7 @@ const { promisify } = require('internal/util');
78
78
const { EventEmitterMixin } = require ( 'internal/event_target' ) ;
79
79
const { watch } = require ( 'internal/fs/watchers' ) ;
80
80
const { isIterable } = require ( 'internal/streams/utils' ) ;
81
+ const assert = require ( 'internal/assert' ) ;
81
82
82
83
const kHandle = Symbol ( 'kHandle' ) ;
83
84
const kFd = Symbol ( 'kFd' ) ;
@@ -251,9 +252,8 @@ class FileHandle extends EventEmitterMixin(JSTransferable) {
251
252
}
252
253
253
254
async function fsCall ( fn , handle , ...args ) {
254
- if ( handle [ kRefs ] === undefined ) {
255
- throw new ERR_INVALID_ARG_TYPE ( 'filehandle' , 'FileHandle' , handle ) ;
256
- }
255
+ assert ( handle [ kRefs ] !== undefined ,
256
+ 'handle must be an instance of FileHandle' ) ;
257
257
258
258
if ( handle . fd === - 1 ) {
259
259
// eslint-disable-next-line no-restricted-syntax
Original file line number Diff line number Diff line change @@ -452,6 +452,16 @@ async function getHandle(dest) {
452
452
assert . strictEqual ( ret . bytesWritten , 2 ) ;
453
453
await handle . close ( ) ;
454
454
}
455
+
456
+ // Test prototype methods calling with contexts other than FileHandle
457
+ {
458
+ const handle = await getHandle ( dest ) ;
459
+ assert . rejects ( ( ) => handle . stat . call ( { } ) , {
460
+ code : 'ERR_INTERNAL_ASSERTION' ,
461
+ message : / h a n d l e m u s t b e a n i n s t a n c e o f F i l e H a n d l e /
462
+ } ) ;
463
+ await handle . close ( ) ;
464
+ }
455
465
}
456
466
457
467
doTest ( ) . then ( common . mustCall ( ) ) ;
You can’t perform that action at this time.
0 commit comments