'use strict';
+var uncurryThis = require('../internals/function-uncurry-this');
var redefineAll = require('../internals/redefine-all');
var getWeakData = require('../internals/internal-metadata').getWeakData;
var anObject = require('../internals/an-object');
var anInstance = require('../internals/an-instance');
var iterate = require('../internals/iterate');
var ArrayIterationModule = require('../internals/array-iteration');
-var $has = require('../internals/has');
+var hasOwn = require('../internals/has-own-property');
var InternalStateModule = require('../internals/internal-state');
var setInternalState = InternalStateModule.set;
var internalStateGetterFor = InternalStateModule.getterFor;
var find = ArrayIterationModule.find;
var findIndex = ArrayIterationModule.findIndex;
+var splice = uncurryThis([].splice);
var id = 0;
// fallback for uncaught frozen keys
var index = findIndex(this.entries, function (it) {
return it[0] === key;
});
- if (~index) this.entries.splice(index, 1);
+ if (~index) splice(this.entries, index, 1);
return !!~index;
}
};
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,
id: id++,
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) {
return that;
};
- redefineAll(C.prototype, {
- // 23.3.3.2 WeakMap.prototype.delete(key)
- // 23.4.3.3 WeakSet.prototype.delete(value)
+ redefineAll(Prototype, {
+ // `{ WeakMap, WeakSet }.prototype.delete(key)` methods
+ // https://tc39.es/ecma262/#sec-weakmap.prototype.delete
+ // https://tc39.es/ecma262/#sec-weakset.prototype.delete
'delete': function (key) {
var state = getInternalState(this);
if (!isObject(key)) return false;
var data = getWeakData(key);
if (data === true) return uncaughtFrozenStore(state)['delete'](key);
- return data && $has(data, state.id) && delete data[state.id];
+ return data && hasOwn(data, state.id) && delete data[state.id];
},
- // 23.3.3.4 WeakMap.prototype.has(key)
- // 23.4.3.4 WeakSet.prototype.has(value)
+ // `{ WeakMap, WeakSet }.prototype.has(key)` methods
+ // https://tc39.es/ecma262/#sec-weakmap.prototype.has
+ // https://tc39.es/ecma262/#sec-weakset.prototype.has
has: function has(key) {
var state = getInternalState(this);
if (!isObject(key)) return false;
var data = getWeakData(key);
if (data === true) return uncaughtFrozenStore(state).has(key);
- return data && $has(data, state.id);
+ return data && hasOwn(data, state.id);
}
});
- redefineAll(C.prototype, IS_MAP ? {
- // 23.3.3.3 WeakMap.prototype.get(key)
+ redefineAll(Prototype, IS_MAP ? {
+ // `WeakMap.prototype.get(key)` method
+ // https://tc39.es/ecma262/#sec-weakmap.prototype.get
get: function get(key) {
var state = getInternalState(this);
if (isObject(key)) {
return data ? data[state.id] : undefined;
}
},
- // 23.3.3.5 WeakMap.prototype.set(key, value)
+ // `WeakMap.prototype.set(key, value)` method
+ // https://tc39.es/ecma262/#sec-weakmap.prototype.set
set: function set(key, value) {
return define(this, key, value);
}
} : {
- // 23.4.3.1 WeakSet.prototype.add(value)
+ // `WeakSet.prototype.add(value)` method
+ // https://tc39.es/ecma262/#sec-weakset.prototype.add
add: function add(value) {
return define(this, value, true);
}
});
- return C;
+ return Constructor;
}
};