mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
fs: use assert in fsCall argument checking
In the user perspective, it's not an arguemnt type error. Replace it with an `assert` expression. PR-URL: https://github.com/nodejs/node/pull/38519 Refs: https://coverage.nodejs.org/coverage-68e6673224365120/lib/internal/fs/promises.js.html#L268 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
committed by
James M Snell
parent
7eb28e3176
commit
8231cc4d42
@@ -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');
|
||||
@@ -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
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user