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