wallet-core/node_modules/core-js/modules/es6.weak-map.js

60 lines
1.9 KiB
JavaScript
Raw Normal View History

2016-10-10 03:43:44 +02:00
'use strict';
2017-08-14 05:01:11 +02:00
var each = require('./_array-methods')(0);
var redefine = require('./_redefine');
var meta = require('./_meta');
var assign = require('./_object-assign');
var weak = require('./_collection-weak');
var isObject = require('./_is-object');
var fails = require('./_fails');
var validate = require('./_validate-collection');
var WEAK_MAP = 'WeakMap';
var getWeak = meta.getWeak;
var isExtensible = Object.isExtensible;
var uncaughtFrozenStore = weak.ufstore;
var tmp = {};
var InternalMap;
2016-10-10 03:43:44 +02:00
2017-08-14 05:01:11 +02:00
var wrapper = function (get) {
return function WeakMap() {
2017-05-27 17:36:13 +02:00
return get(this, arguments.length > 0 ? arguments[0] : undefined);
};
};
var methods = {
2016-10-10 03:43:44 +02:00
// 23.3.3.3 WeakMap.prototype.get(key)
2017-08-14 05:01:11 +02:00
get: function get(key) {
if (isObject(key)) {
2017-05-27 17:36:13 +02:00
var data = getWeak(key);
2017-08-14 05:01:11 +02:00
if (data === true) return uncaughtFrozenStore(validate(this, WEAK_MAP)).get(key);
2017-05-27 17:36:13 +02:00
return data ? data[this._i] : undefined;
2016-10-10 03:43:44 +02:00
}
},
// 23.3.3.5 WeakMap.prototype.set(key, value)
2017-08-14 05:01:11 +02:00
set: function set(key, value) {
return weak.def(validate(this, WEAK_MAP), key, value);
2016-10-10 03:43:44 +02:00
}
2017-05-27 17:36:13 +02:00
};
// 23.3 WeakMap Objects
2017-08-14 05:01:11 +02:00
var $WeakMap = module.exports = require('./_collection')(WEAK_MAP, wrapper, methods, weak, true, true);
2016-10-10 03:43:44 +02:00
// IE11 WeakMap frozen keys fix
2017-08-14 05:01:11 +02:00
if (fails(function () { return new $WeakMap().set((Object.freeze || Object)(tmp), 7).get(tmp) != 7; })) {
InternalMap = weak.getConstructor(wrapper, WEAK_MAP);
2017-05-27 17:36:13 +02:00
assign(InternalMap.prototype, methods);
meta.NEED = true;
2017-08-14 05:01:11 +02:00
each(['delete', 'has', 'get', 'set'], function (key) {
var proto = $WeakMap.prototype;
var method = proto[key];
redefine(proto, key, function (a, b) {
2017-05-27 17:36:13 +02:00
// store frozen objects on internal weakmap shim
2017-08-14 05:01:11 +02:00
if (isObject(a) && !isExtensible(a)) {
if (!this._f) this._f = new InternalMap();
2017-05-27 17:36:13 +02:00
var result = this._f[key](a, b);
2016-10-10 03:43:44 +02:00
return key == 'set' ? this : result;
// store all the rest on native weakmap
} return method.call(this, a, b);
});
});
2017-08-14 05:01:11 +02:00
}