[d24f17c] | 1 | 'use strict';
|
---|
| 2 | var FREEZING = require('../internals/freezing');
|
---|
| 3 | var global = require('../internals/global');
|
---|
| 4 | var uncurryThis = require('../internals/function-uncurry-this');
|
---|
| 5 | var defineBuiltIns = require('../internals/define-built-ins');
|
---|
| 6 | var InternalMetadataModule = require('../internals/internal-metadata');
|
---|
| 7 | var collection = require('../internals/collection');
|
---|
| 8 | var collectionWeak = require('../internals/collection-weak');
|
---|
| 9 | var isObject = require('../internals/is-object');
|
---|
| 10 | var enforceInternalState = require('../internals/internal-state').enforce;
|
---|
| 11 | var fails = require('../internals/fails');
|
---|
| 12 | var NATIVE_WEAK_MAP = require('../internals/weak-map-basic-detection');
|
---|
| 13 |
|
---|
| 14 | var $Object = Object;
|
---|
| 15 | // eslint-disable-next-line es/no-array-isarray -- safe
|
---|
| 16 | var isArray = Array.isArray;
|
---|
| 17 | // eslint-disable-next-line es/no-object-isextensible -- safe
|
---|
| 18 | var isExtensible = $Object.isExtensible;
|
---|
| 19 | // eslint-disable-next-line es/no-object-isfrozen -- safe
|
---|
| 20 | var isFrozen = $Object.isFrozen;
|
---|
| 21 | // eslint-disable-next-line es/no-object-issealed -- safe
|
---|
| 22 | var isSealed = $Object.isSealed;
|
---|
| 23 | // eslint-disable-next-line es/no-object-freeze -- safe
|
---|
| 24 | var freeze = $Object.freeze;
|
---|
| 25 | // eslint-disable-next-line es/no-object-seal -- safe
|
---|
| 26 | var seal = $Object.seal;
|
---|
| 27 |
|
---|
| 28 | var IS_IE11 = !global.ActiveXObject && 'ActiveXObject' in global;
|
---|
| 29 | var InternalWeakMap;
|
---|
| 30 |
|
---|
| 31 | var wrapper = function (init) {
|
---|
| 32 | return function WeakMap() {
|
---|
| 33 | return init(this, arguments.length ? arguments[0] : undefined);
|
---|
| 34 | };
|
---|
| 35 | };
|
---|
| 36 |
|
---|
| 37 | // `WeakMap` constructor
|
---|
| 38 | // https://tc39.es/ecma262/#sec-weakmap-constructor
|
---|
| 39 | var $WeakMap = collection('WeakMap', wrapper, collectionWeak);
|
---|
| 40 | var WeakMapPrototype = $WeakMap.prototype;
|
---|
| 41 | var nativeSet = uncurryThis(WeakMapPrototype.set);
|
---|
| 42 |
|
---|
| 43 | // Chakra Edge bug: adding frozen arrays to WeakMap unfreeze them
|
---|
| 44 | var hasMSEdgeFreezingBug = function () {
|
---|
| 45 | return FREEZING && fails(function () {
|
---|
| 46 | var frozenArray = freeze([]);
|
---|
| 47 | nativeSet(new $WeakMap(), frozenArray, 1);
|
---|
| 48 | return !isFrozen(frozenArray);
|
---|
| 49 | });
|
---|
| 50 | };
|
---|
| 51 |
|
---|
| 52 | // IE11 WeakMap frozen keys fix
|
---|
| 53 | // We can't use feature detection because it crash some old IE builds
|
---|
| 54 | // https://github.com/zloirock/core-js/issues/485
|
---|
| 55 | if (NATIVE_WEAK_MAP) if (IS_IE11) {
|
---|
| 56 | InternalWeakMap = collectionWeak.getConstructor(wrapper, 'WeakMap', true);
|
---|
| 57 | InternalMetadataModule.enable();
|
---|
| 58 | var nativeDelete = uncurryThis(WeakMapPrototype['delete']);
|
---|
| 59 | var nativeHas = uncurryThis(WeakMapPrototype.has);
|
---|
| 60 | var nativeGet = uncurryThis(WeakMapPrototype.get);
|
---|
| 61 | defineBuiltIns(WeakMapPrototype, {
|
---|
| 62 | 'delete': function (key) {
|
---|
| 63 | if (isObject(key) && !isExtensible(key)) {
|
---|
| 64 | var state = enforceInternalState(this);
|
---|
| 65 | if (!state.frozen) state.frozen = new InternalWeakMap();
|
---|
| 66 | return nativeDelete(this, key) || state.frozen['delete'](key);
|
---|
| 67 | } return nativeDelete(this, key);
|
---|
| 68 | },
|
---|
| 69 | has: function has(key) {
|
---|
| 70 | if (isObject(key) && !isExtensible(key)) {
|
---|
| 71 | var state = enforceInternalState(this);
|
---|
| 72 | if (!state.frozen) state.frozen = new InternalWeakMap();
|
---|
| 73 | return nativeHas(this, key) || state.frozen.has(key);
|
---|
| 74 | } return nativeHas(this, key);
|
---|
| 75 | },
|
---|
| 76 | get: function get(key) {
|
---|
| 77 | if (isObject(key) && !isExtensible(key)) {
|
---|
| 78 | var state = enforceInternalState(this);
|
---|
| 79 | if (!state.frozen) state.frozen = new InternalWeakMap();
|
---|
| 80 | return nativeHas(this, key) ? nativeGet(this, key) : state.frozen.get(key);
|
---|
| 81 | } return nativeGet(this, key);
|
---|
| 82 | },
|
---|
| 83 | set: function set(key, value) {
|
---|
| 84 | if (isObject(key) && !isExtensible(key)) {
|
---|
| 85 | var state = enforceInternalState(this);
|
---|
| 86 | if (!state.frozen) state.frozen = new InternalWeakMap();
|
---|
| 87 | nativeHas(this, key) ? nativeSet(this, key, value) : state.frozen.set(key, value);
|
---|
| 88 | } else nativeSet(this, key, value);
|
---|
| 89 | return this;
|
---|
| 90 | }
|
---|
| 91 | });
|
---|
| 92 | // Chakra Edge frozen keys fix
|
---|
| 93 | } else if (hasMSEdgeFreezingBug()) {
|
---|
| 94 | defineBuiltIns(WeakMapPrototype, {
|
---|
| 95 | set: function set(key, value) {
|
---|
| 96 | var arrayIntegrityLevel;
|
---|
| 97 | if (isArray(key)) {
|
---|
| 98 | if (isFrozen(key)) arrayIntegrityLevel = freeze;
|
---|
| 99 | else if (isSealed(key)) arrayIntegrityLevel = seal;
|
---|
| 100 | }
|
---|
| 101 | nativeSet(this, key, value);
|
---|
| 102 | if (arrayIntegrityLevel) arrayIntegrityLevel(key);
|
---|
| 103 | return this;
|
---|
| 104 | }
|
---|
| 105 | });
|
---|
| 106 | }
|
---|