6
6
ArrayPrototypeShift,
7
7
ArrayPrototypeSlice,
8
8
ArrayPrototypePush,
9
- ObjectDefineProperty,
10
9
ObjectEntries,
11
10
ObjectPrototypeHasOwnProperty : ObjectHasOwn ,
12
11
StringPrototypeCharAt,
@@ -117,19 +116,9 @@ function checkOptionUsage(longOption, optionValue, options,
117
116
*/
118
117
function storeOption ( longOption , optionValue , options , values ) {
119
118
if ( longOption === '__proto__' ) {
120
- return ;
119
+ return ; // No. Just no.
121
120
}
122
121
123
- // Can be removed when value has a null prototype
124
- const safeAssignProperty = ( obj , prop , value ) => {
125
- ObjectDefineProperty ( obj , prop , {
126
- value,
127
- writable : true ,
128
- enumerable : true ,
129
- configurable : true
130
- } ) ;
131
- } ;
132
-
133
122
// We store based on the option value rather than option type,
134
123
// preserving the users intent for author to deal with.
135
124
const newValue = optionValue ?? true ;
@@ -138,13 +127,14 @@ function storeOption(longOption, optionValue, options, values) {
138
127
// values[longOption] starts out not present,
139
128
// first value is added as new array [newValue],
140
129
// subsequent values are pushed to existing array.
141
- if ( ObjectHasOwn ( values , longOption ) ) {
130
+ // (note: values has null prototype, so simpler usage)
131
+ if ( values [ longOption ] ) {
142
132
ArrayPrototypePush ( values [ longOption ] , newValue ) ;
143
133
} else {
144
- safeAssignProperty ( values , longOption , [ newValue ] ) ;
134
+ values [ longOption ] = [ newValue ] ;
145
135
}
146
136
} else {
147
- safeAssignProperty ( values , longOption , newValue ) ;
137
+ values [ longOption ] = newValue ;
148
138
}
149
139
}
150
140
@@ -184,7 +174,7 @@ const parseArgs = (config = { __proto__: null }) => {
184
174
) ;
185
175
186
176
const result = {
187
- values : { } ,
177
+ values : { __proto__ : null } ,
188
178
positionals : [ ]
189
179
} ;
190
180
0 commit comments