9
9
NumberMAX_SAFE_INTEGER,
10
10
NumberMIN_SAFE_INTEGER,
11
11
NumberParseInt,
12
+ ObjectPrototypeHasOwnProperty,
12
13
RegExpPrototypeTest,
13
14
String,
14
15
StringPrototypeToUpperCase,
@@ -140,6 +141,10 @@ function validateBoolean(value, name) {
140
141
throw new ERR_INVALID_ARG_TYPE ( name , 'boolean' , value ) ;
141
142
}
142
143
144
+ function getOwnPropertyValueOrDefault ( options , key , defaultValue ) {
145
+ return options == null || ! ObjectPrototypeHasOwnProperty ( options , key ) ? defaultValue : options [ key ] ;
146
+ }
147
+
143
148
/**
144
149
* @param {unknown } value
145
150
* @param {string } name
@@ -151,10 +156,9 @@ function validateBoolean(value, name) {
151
156
*/
152
157
const validateObject = hideStackFrames (
153
158
( value , name , options ) => {
154
- const useDefaultOptions = options == null ;
155
- const allowArray = useDefaultOptions ? false : options . allowArray ;
156
- const allowFunction = useDefaultOptions ? false : options . allowFunction ;
157
- const nullable = useDefaultOptions ? false : options . nullable ;
159
+ const allowArray = getOwnPropertyValueOrDefault ( options , 'allowArray' , false ) ;
160
+ const allowFunction = getOwnPropertyValueOrDefault ( options , 'allowFunction' , false ) ;
161
+ const nullable = getOwnPropertyValueOrDefault ( options , 'nullable' , false ) ;
158
162
if ( ( ! nullable && value === null ) ||
159
163
( ! allowArray && ArrayIsArray ( value ) ) ||
160
164
( typeof value !== 'object' && (
0 commit comments