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 (iterable != undefined) iterate(iterable, that[ADDER], { that: that, AS_ENTRIES: IS_MAP });
});
+ var Prototype = Constructor.prototype;
+
var getInternalState = internalStateGetterFor(CONSTRUCTOR_NAME);
var define = function (that, key, value) {
}
};
- redefineAll(C.prototype, {
- // 23.1.3.1 Map.prototype.clear()
- // 23.2.3.2 Set.prototype.clear()
+ redefineAll(Prototype, {
+ // `{ Map, Set }.prototype.clear()` methods
+ // https://tc39.es/ecma262/#sec-map.prototype.clear
+ // https://tc39.es/ecma262/#sec-set.prototype.clear
clear: function clear() {
var that = this;
var state = getInternalState(that);
if (DESCRIPTORS) state.size = 0;
else that.size = 0;
},
- // 23.1.3.3 Map.prototype.delete(key)
- // 23.2.3.4 Set.prototype.delete(value)
+ // `{ Map, Set }.prototype.delete(key)` methods
+ // https://tc39.es/ecma262/#sec-map.prototype.delete
+ // https://tc39.es/ecma262/#sec-set.prototype.delete
'delete': function (key) {
var that = this;
var state = getInternalState(that);
else that.size--;
} return !!entry;
},
- // 23.2.3.6 Set.prototype.forEach(callbackfn, thisArg = undefined)
- // 23.1.3.5 Map.prototype.forEach(callbackfn, thisArg = undefined)
+ // `{ Map, Set }.prototype.forEach(callbackfn, thisArg = undefined)` methods
+ // https://tc39.es/ecma262/#sec-map.prototype.foreach
+ // 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);
while (entry && entry.removed) entry = entry.previous;
}
},
- // 23.1.3.7 Map.prototype.has(key)
- // 23.2.3.7 Set.prototype.has(value)
+ // `{ Map, Set}.prototype.has(key)` methods
+ // https://tc39.es/ecma262/#sec-map.prototype.has
+ // https://tc39.es/ecma262/#sec-set.prototype.has
has: function has(key) {
return !!getEntry(this, key);
}
});
- redefineAll(C.prototype, IS_MAP ? {
- // 23.1.3.6 Map.prototype.get(key)
+ redefineAll(Prototype, IS_MAP ? {
+ // `Map.prototype.get(key)` method
+ // https://tc39.es/ecma262/#sec-map.prototype.get
get: function get(key) {
var entry = getEntry(this, key);
return entry && entry.value;
},
- // 23.1.3.9 Map.prototype.set(key, value)
+ // `Map.prototype.set(key, value)` method
+ // https://tc39.es/ecma262/#sec-map.prototype.set
set: function set(key, value) {
return define(this, key === 0 ? 0 : key, value);
}
} : {
- // 23.2.3.1 Set.prototype.add(value)
+ // `Set.prototype.add(value)` method
+ // https://tc39.es/ecma262/#sec-set.prototype.add
add: function add(value) {
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);
- // add .keys, .values, .entries, [@@iterator]
- // 23.1.3.4, 23.1.3.8, 23.1.3.11, 23.1.3.12, 23.2.3.5, 23.2.3.8, 23.2.3.10, 23.2.3.11
- defineIterator(C, CONSTRUCTOR_NAME, function (iterated, kind) {
+ // `{ Map, Set }.prototype.{ keys, values, entries, @@iterator }()` methods
+ // https://tc39.es/ecma262/#sec-map.prototype.entries
+ // https://tc39.es/ecma262/#sec-map.prototype.keys
+ // https://tc39.es/ecma262/#sec-map.prototype.values
+ // https://tc39.es/ecma262/#sec-map.prototype-@@iterator
+ // https://tc39.es/ecma262/#sec-set.prototype.entries
+ // 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(Constructor, CONSTRUCTOR_NAME, function (iterated, kind) {
setInternalState(this, {
type: ITERATOR_NAME,
target: iterated,
return { value: [entry.key, entry.value], done: false };
}, IS_MAP ? 'entries' : 'values', !IS_MAP, true);
- // add [@@species], 23.1.2.2, 23.2.2.2
+ // `{ Map, Set }.prototype[@@species]` accessors
+ // https://tc39.es/ecma262/#sec-get-map-@@species
+ // https://tc39.es/ecma262/#sec-get-set-@@species
setSpecies(CONSTRUCTOR_NAME);
}
};