diff --git a/lib/fs.js b/lib/fs.js index 09b77c97be8..fa8e4f087a6 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -791,7 +791,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; @@ -817,7 +817,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 aa135eb1fd5..d0cbf12766b 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',