[6a3a178] | 1 | 'use strict';
|
---|
| 2 | var global = require('../internals/global');
|
---|
| 3 | var redefineAll = require('../internals/redefine-all');
|
---|
| 4 | var InternalMetadataModule = require('../internals/internal-metadata');
|
---|
| 5 | var collection = require('../internals/collection');
|
---|
| 6 | var collectionWeak = require('../internals/collection-weak');
|
---|
| 7 | var isObject = require('../internals/is-object');
|
---|
| 8 | var enforceIternalState = require('../internals/internal-state').enforce;
|
---|
| 9 | var NATIVE_WEAK_MAP = require('../internals/native-weak-map');
|
---|
| 10 |
|
---|
| 11 | var IS_IE11 = !global.ActiveXObject && 'ActiveXObject' in global;
|
---|
| 12 | // eslint-disable-next-line es/no-object-isextensible -- safe
|
---|
| 13 | var isExtensible = Object.isExtensible;
|
---|
| 14 | var InternalWeakMap;
|
---|
| 15 |
|
---|
| 16 | var wrapper = function (init) {
|
---|
| 17 | return function WeakMap() {
|
---|
| 18 | return init(this, arguments.length ? arguments[0] : undefined);
|
---|
| 19 | };
|
---|
| 20 | };
|
---|
| 21 |
|
---|
| 22 | // `WeakMap` constructor
|
---|
| 23 | // https://tc39.es/ecma262/#sec-weakmap-constructor
|
---|
| 24 | var $WeakMap = module.exports = collection('WeakMap', wrapper, collectionWeak);
|
---|
| 25 |
|
---|
| 26 | // IE11 WeakMap frozen keys fix
|
---|
| 27 | // We can't use feature detection because it crash some old IE builds
|
---|
| 28 | // https://github.com/zloirock/core-js/issues/485
|
---|
| 29 | if (NATIVE_WEAK_MAP && IS_IE11) {
|
---|
| 30 | InternalWeakMap = collectionWeak.getConstructor(wrapper, 'WeakMap', true);
|
---|
| 31 | InternalMetadataModule.enable();
|
---|
| 32 | var WeakMapPrototype = $WeakMap.prototype;
|
---|
| 33 | var nativeDelete = WeakMapPrototype['delete'];
|
---|
| 34 | var nativeHas = WeakMapPrototype.has;
|
---|
| 35 | var nativeGet = WeakMapPrototype.get;
|
---|
| 36 | var nativeSet = WeakMapPrototype.set;
|
---|
| 37 | redefineAll(WeakMapPrototype, {
|
---|
| 38 | 'delete': function (key) {
|
---|
| 39 | if (isObject(key) && !isExtensible(key)) {
|
---|
| 40 | var state = enforceIternalState(this);
|
---|
| 41 | if (!state.frozen) state.frozen = new InternalWeakMap();
|
---|
| 42 | return nativeDelete.call(this, key) || state.frozen['delete'](key);
|
---|
| 43 | } return nativeDelete.call(this, key);
|
---|
| 44 | },
|
---|
| 45 | has: function has(key) {
|
---|
| 46 | if (isObject(key) && !isExtensible(key)) {
|
---|
| 47 | var state = enforceIternalState(this);
|
---|
| 48 | if (!state.frozen) state.frozen = new InternalWeakMap();
|
---|
| 49 | return nativeHas.call(this, key) || state.frozen.has(key);
|
---|
| 50 | } return nativeHas.call(this, key);
|
---|
| 51 | },
|
---|
| 52 | get: function get(key) {
|
---|
| 53 | if (isObject(key) && !isExtensible(key)) {
|
---|
| 54 | var state = enforceIternalState(this);
|
---|
| 55 | if (!state.frozen) state.frozen = new InternalWeakMap();
|
---|
| 56 | return nativeHas.call(this, key) ? nativeGet.call(this, key) : state.frozen.get(key);
|
---|
| 57 | } return nativeGet.call(this, key);
|
---|
| 58 | },
|
---|
| 59 | set: function set(key, value) {
|
---|
| 60 | if (isObject(key) && !isExtensible(key)) {
|
---|
| 61 | var state = enforceIternalState(this);
|
---|
| 62 | if (!state.frozen) state.frozen = new InternalWeakMap();
|
---|
| 63 | nativeHas.call(this, key) ? nativeSet.call(this, key, value) : state.frozen.set(key, value);
|
---|
| 64 | } else nativeSet.call(this, key, value);
|
---|
| 65 | return this;
|
---|
| 66 | }
|
---|
| 67 | });
|
---|
| 68 | }
|
---|