buffer: fix validation of options in Blob constructor

PR-URL: https://github.com/nodejs/node/pull/45156
Refs: https://webidl.spec.whatwg.org/#es-dictionary
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
This commit is contained in:
Antoine du Hamel 2022-10-31 18:47:51 -05:00 committed by GitHub
parent 17ae2ab750
commit d6ee27445b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 4 deletions

View file

@ -61,8 +61,8 @@ const {
} = require('internal/errors');
const {
validateObject,
isUint32,
validateDictionary,
} = require('internal/validators');
const kHandle = Symbol('kHandle');
@ -138,17 +138,17 @@ class Blob {
* }} [options]
* @constructs {Blob}
*/
constructor(sources = [], options = kEmptyObject) {
constructor(sources = [], options) {
if (sources === null ||
typeof sources[SymbolIterator] !== 'function' ||
typeof sources === 'string') {
throw new ERR_INVALID_ARG_TYPE('sources', 'a sequence', sources);
}
validateObject(options, 'options');
validateDictionary(options, 'options');
let {
type = '',
endings = 'transparent',
} = options;
} = options ?? kEmptyObject;
endings = `${endings}`;
if (endings !== 'transparent' && endings !== 'native')