| | |
| | | 'use strict'; |
| | | var defineProperty = require('../internals/object-define-property').f; |
| | | var create = require('../internals/object-create'); |
| | | var redefineAll = require('../internals/redefine-all'); |
| | | var defineBuiltIns = require('../internals/define-built-ins'); |
| | | var bind = require('../internals/function-bind-context'); |
| | | var anInstance = require('../internals/an-instance'); |
| | | var iterate = require('../internals/iterate'); |
| | |
| | | |
| | | module.exports = { |
| | | getConstructor: function (wrapper, CONSTRUCTOR_NAME, IS_MAP, ADDER) { |
| | | var C = wrapper(function (that, iterable) { |
| | | anInstance(that, C, CONSTRUCTOR_NAME); |
| | | var Constructor = wrapper(function (that, iterable) { |
| | | anInstance(that, Prototype); |
| | | setInternalState(that, { |
| | | type: CONSTRUCTOR_NAME, |
| | | index: create(null), |
| | |
| | | if (!DESCRIPTORS) that.size = 0; |
| | | if (iterable != undefined) iterate(iterable, that[ADDER], { that: that, AS_ENTRIES: IS_MAP }); |
| | | }); |
| | | |
| | | var Prototype = Constructor.prototype; |
| | | |
| | | var getInternalState = internalStateGetterFor(CONSTRUCTOR_NAME); |
| | | |
| | |
| | | } |
| | | }; |
| | | |
| | | redefineAll(C.prototype, { |
| | | defineBuiltIns(Prototype, { |
| | | // `{ Map, Set }.prototype.clear()` methods |
| | | // https://tc39.es/ecma262/#sec-map.prototype.clear |
| | | // https://tc39.es/ecma262/#sec-set.prototype.clear |
| | |
| | | // https://tc39.es/ecma262/#sec-set.prototype.foreach |
| | | forEach: function forEach(callbackfn /* , that = undefined */) { |
| | | var state = getInternalState(this); |
| | | var boundFunction = bind(callbackfn, arguments.length > 1 ? arguments[1] : undefined, 3); |
| | | var boundFunction = bind(callbackfn, arguments.length > 1 ? arguments[1] : undefined); |
| | | var entry; |
| | | while (entry = entry ? entry.next : state.first) { |
| | | boundFunction(entry.value, entry.key, this); |
| | |
| | | } |
| | | }); |
| | | |
| | | redefineAll(C.prototype, IS_MAP ? { |
| | | defineBuiltIns(Prototype, IS_MAP ? { |
| | | // `Map.prototype.get(key)` method |
| | | // https://tc39.es/ecma262/#sec-map.prototype.get |
| | | get: function get(key) { |
| | |
| | | return define(this, value = value === 0 ? 0 : value, value); |
| | | } |
| | | }); |
| | | if (DESCRIPTORS) defineProperty(C.prototype, 'size', { |
| | | if (DESCRIPTORS) defineProperty(Prototype, 'size', { |
| | | get: function () { |
| | | return getInternalState(this).size; |
| | | } |
| | | }); |
| | | return C; |
| | | return Constructor; |
| | | }, |
| | | setStrong: function (C, CONSTRUCTOR_NAME, IS_MAP) { |
| | | setStrong: function (Constructor, CONSTRUCTOR_NAME, IS_MAP) { |
| | | var ITERATOR_NAME = CONSTRUCTOR_NAME + ' Iterator'; |
| | | var getInternalCollectionState = internalStateGetterFor(CONSTRUCTOR_NAME); |
| | | var getInternalIteratorState = internalStateGetterFor(ITERATOR_NAME); |
| | |
| | | // https://tc39.es/ecma262/#sec-set.prototype.keys |
| | | // https://tc39.es/ecma262/#sec-set.prototype.values |
| | | // https://tc39.es/ecma262/#sec-set.prototype-@@iterator |
| | | defineIterator(C, CONSTRUCTOR_NAME, function (iterated, kind) { |
| | | defineIterator(Constructor, CONSTRUCTOR_NAME, function (iterated, kind) { |
| | | setInternalState(this, { |
| | | type: ITERATOR_NAME, |
| | | target: iterated, |