Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/internal/fs/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const { promisify } = require('internal/util');
const { EventEmitterMixin } = require('internal/event_target');
const { watch } = require('internal/fs/watchers');
const { isIterable } = require('internal/streams/utils');
const assert = require('internal/assert');

const kHandle = Symbol('kHandle');
const kFd = Symbol('kFd');
Expand Down Expand Up @@ -266,9 +267,8 @@ async function handleFdClose(fileOpPromise, closeFunc) {
}

async function fsCall(fn, handle, ...args) {
if (handle[kRefs] === undefined) {
throw new ERR_INVALID_ARG_TYPE('filehandle', 'FileHandle', handle);
}
assert(handle[kRefs] !== undefined,
'handle must be an instance of FileHandle');

if (handle.fd === -1) {
// eslint-disable-next-line no-restricted-syntax
Expand Down
10 changes: 10 additions & 0 deletions test/parallel/test-fs-promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,16 @@ async function getHandle(dest) {
assert.strictEqual(ret.bytesWritten, 2);
await handle.close();
}

// Test prototype methods calling with contexts other than FileHandle
{
const handle = await getHandle(dest);
assert.rejects(() => handle.stat.call({}), {
code: 'ERR_INTERNAL_ASSERTION',
message: /handle must be an instance of FileHandle/
});
await handle.close();
}
}

doTest().then(common.mustCall());
Expand Down