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

@ -257,6 +257,25 @@ const validateObject = hideStackFrames(
}
});
/**
* @callback validateDictionary - We are using the Web IDL Standard definition
* of "dictionary" here, which means any value
* whose Type is either Undefined, Null, or
* Object (which includes functions).
* @param {*} value
* @param {string} name
* @see https://webidl.spec.whatwg.org/#es-dictionary
* @see https://tc39.es/ecma262/#table-typeof-operator-results
*/
/** @type {validateDictionary} */
const validateDictionary = hideStackFrames(
(value, name) => {
if (value != null && typeof value !== 'object' && typeof value !== 'function') {
throw new ERR_INVALID_ARG_TYPE(name, 'a dictionary', value);
}
});
/**
* @callback validateArray
* @param {*} value
@ -511,6 +530,7 @@ module.exports = {
validateBooleanArray,
validateBoolean,
validateBuffer,
validateDictionary,
validateEncoding,
validateFunction,
validateInt32,