@@ -8,6 +8,7 @@ var uncurryThis = require('../internals/function-uncurry-this');
8
8
var DESCRIPTORS = require ( '../internals/descriptors' ) ;
9
9
var USE_NATIVE_URL = require ( '../internals/url-constructor-detection' ) ;
10
10
var defineBuiltIn = require ( '../internals/define-built-in' ) ;
11
+ var defineBuiltInAccessor = require ( '../internals/define-built-in-accessor' ) ;
11
12
var defineBuiltIns = require ( '../internals/define-built-ins' ) ;
12
13
var setToStringTag = require ( '../internals/set-to-string-tag' ) ;
13
14
var createIteratorConstructor = require ( '../internals/iterator-create-constructor' ) ;
@@ -203,7 +204,8 @@ URLSearchParamsState.prototype = {
203
204
var URLSearchParamsConstructor = function URLSearchParams ( /* init */ ) {
204
205
anInstance ( this , URLSearchParamsPrototype ) ;
205
206
var init = arguments . length > 0 ? arguments [ 0 ] : undefined ;
206
- setInternalState ( this , new URLSearchParamsState ( init ) ) ;
207
+ var state = setInternalState ( this , new URLSearchParamsState ( init ) ) ;
208
+ if ( ! DESCRIPTORS ) this . length = state . entries . length ;
207
209
} ;
208
210
209
211
var URLSearchParamsPrototype = URLSearchParamsConstructor . prototype ;
@@ -215,6 +217,7 @@ defineBuiltIns(URLSearchParamsPrototype, {
215
217
validateArgumentsLength ( arguments . length , 2 ) ;
216
218
var state = getInternalParamsState ( this ) ;
217
219
push ( state . entries , { key : $toString ( name ) , value : $toString ( value ) } ) ;
220
+ if ( ! DESCRIPTORS ) this . length ++ ;
218
221
state . updateURL ( ) ;
219
222
} ,
220
223
// `URLSearchParams.prototype.delete` method
@@ -229,6 +232,7 @@ defineBuiltIns(URLSearchParamsPrototype, {
229
232
if ( entries [ index ] . key === key ) splice ( entries , index , 1 ) ;
230
233
else index ++ ;
231
234
}
235
+ if ( ! DESCRIPTORS ) this . length = entries . length ;
232
236
state . updateURL ( ) ;
233
237
} ,
234
238
// `URLSearchParams.prototype.get` method
@@ -290,6 +294,7 @@ defineBuiltIns(URLSearchParamsPrototype, {
290
294
}
291
295
}
292
296
if ( ! found ) push ( entries , { key : key , value : val } ) ;
297
+ if ( ! DESCRIPTORS ) this . length = entries . length ;
293
298
state . updateURL ( ) ;
294
299
} ,
295
300
// `URLSearchParams.prototype.sort` method
@@ -335,6 +340,16 @@ defineBuiltIn(URLSearchParamsPrototype, 'toString', function toString() {
335
340
return getInternalParamsState ( this ) . serialize ( ) ;
336
341
} , { enumerable : true } ) ;
337
342
343
+ // `URLSearchParams.prototype.size` getter
344
+ // https://github.com/whatwg/url/pull/734
345
+ if ( DESCRIPTORS ) defineBuiltInAccessor ( URLSearchParamsPrototype , 'size' , {
346
+ get : function size ( ) {
347
+ return getInternalParamsState ( this ) . entries . length ;
348
+ } ,
349
+ configurable : true ,
350
+ enumerable : true
351
+ } ) ;
352
+
338
353
setToStringTag ( URLSearchParamsConstructor , URL_SEARCH_PARAMS ) ;
339
354
340
355
$ ( { global : true , constructor : true , forced : ! USE_NATIVE_URL } , {
0 commit comments