web.url-search-params.size.js 713 B

123456789101112131415161718192021
  1. 'use strict';
  2. var DESCRIPTORS = require('../internals/descriptors');
  3. var uncurryThis = require('../internals/function-uncurry-this');
  4. var defineBuiltInAccessor = require('../internals/define-built-in-accessor');
  5. var URLSearchParamsPrototype = URLSearchParams.prototype;
  6. var forEach = uncurryThis(URLSearchParamsPrototype.forEach);
  7. // `URLSearchParams.prototype.size` getter
  8. // https://github.com/whatwg/url/pull/734
  9. if (DESCRIPTORS && !('size' in URLSearchParamsPrototype)) {
  10. defineBuiltInAccessor(URLSearchParamsPrototype, 'size', {
  11. get: function size() {
  12. var count = 0;
  13. forEach(this, function () { count++; });
  14. return count;
  15. },
  16. configurable: true,
  17. enumerable: true
  18. });
  19. }