diff --git a/lib/fs.js b/lib/fs.js index d0de4a9bdc9c..85fdd0890604 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -790,7 +790,7 @@ function openSync(path, flags, mode) { */ function openAsBlob(path, options = kEmptyObject) { validateObject(options, 'options'); - const type = options.type || ''; + const { type = '' } = options; validateString(type, 'options.type'); const h = vfsState.handlers; @@ -816,7 +816,7 @@ function openAsBlob(path, options = kEmptyObject) { */ function openAsBlobSync(path, options = kEmptyObject) { validateObject(options, 'options'); - const type = options.type || ''; + const { type = '' } = options; validateString(type, 'options.type'); path = getValidatedPath(path); diff --git a/test/parallel/test-fs-openAsBlobSync.js b/test/parallel/test-fs-openAsBlobSync.js index aa135eb1fd5b..d0cbf12766b4 100644 --- a/test/parallel/test-fs-openAsBlobSync.js +++ b/test/parallel/test-fs-openAsBlobSync.js @@ -23,9 +23,14 @@ assert.throws(() => fs.openAsBlobSync(1), { assert.throws(() => fs.openAsBlobSync(testfile, null), { code: 'ERR_INVALID_ARG_TYPE', }); -assert.throws(() => fs.openAsBlobSync(testfile, { type: 1 }), { - code: 'ERR_INVALID_ARG_TYPE', -}); +for (const type of [1, 0, false, null, NaN, {}]) { + assert.throws(() => fs.openAsBlobSync(testfile, { type }), { + code: 'ERR_INVALID_ARG_TYPE', + }); + assert.throws(() => fs.openAsBlob(testfile, { type }), { + code: 'ERR_INVALID_ARG_TYPE', + }); +} assert.throws(() => fs.openAsBlobSync(missing), { code: 'ENOENT', syscall: 'stat',