Skip to content

Commit

Permalink
add a workaround for IE11 crash, #485
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Feb 6, 2019
1 parent 1b62c52 commit a710f68
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
7 changes: 3 additions & 4 deletions packages/core-js/internals/internal-state.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
var global = require('../internals/global');
var nativeFunctionToString = require('../internals/function-to-string');
var NATIVE_WEAK_MAP = require('../internals/native-weak-map');
var isObject = require('../internals/is-object');
var hide = require('../internals/hide');
var objectHas = require('../internals/has');
var sharedKey = require('../internals/shared-key');
var hiddenKeys = require('../internals/hidden-keys');
var WeakMap = global.WeakMap;
var WeakMap = require('../internals/global').WeakMap;
var set, get, has;

var enforce = function (it) {
Expand All @@ -21,7 +20,7 @@ var getterFor = function (TYPE) {
};
};

if (typeof WeakMap == 'function' && /native code/.test(nativeFunctionToString.call(WeakMap))) {
if (NATIVE_WEAK_MAP) {
var store = new WeakMap();
var wmget = store.get;
var wmhas = store.has;
Expand Down
4 changes: 4 additions & 0 deletions packages/core-js/internals/native-weak-map.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var nativeFunctionToString = require('../internals/function-to-string');
var WeakMap = require('../internals/global').WeakMap;

module.exports = typeof WeakMap === 'function' && /native code/.test(nativeFunctionToString.call(WeakMap));
14 changes: 8 additions & 6 deletions packages/core-js/modules/es.weak-map.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use strict';
var global = require('../internals/global');
var redefineAll = require('../internals/redefine-all');
var InternalMetadataModule = require('../internals/internal-metadata');
var weak = require('../internals/collection-weak');
var isObject = require('../internals/is-object');
var fails = require('../internals/fails');
var enforceIternalState = require('../internals/internal-state').enforce;
var WEAK_MAP = 'WeakMap';
var NATIVE_WEAK_MAP = require('../internals/native-weak-map');
var IS_IE11 = !global.ActiveXObject && 'ActiveXObject' in global;
var isExtensible = Object.isExtensible;
var test = {};
var InternalWeakMap;

var wrapper = function (get) {
Expand All @@ -18,11 +18,13 @@ var wrapper = function (get) {

// `WeakMap` constructor
// https://tc39.github.io/ecma262/#sec-weakmap-constructor
var $WeakMap = module.exports = require('../internals/collection')(WEAK_MAP, wrapper, weak, true, true);
var $WeakMap = module.exports = require('../internals/collection')('WeakMap', wrapper, weak, true, true);

// IE11 WeakMap frozen keys fix
if (fails(function () { return new $WeakMap().set((Object.freeze || Object)(test), 7).get(test) != 7; })) {
InternalWeakMap = weak.getConstructor(wrapper, WEAK_MAP, true);
// We can't use feature detection because it crash some old IE builds
// https://github.com/zloirock/core-js/issues/485
if (NATIVE_WEAK_MAP && IS_IE11) {
InternalWeakMap = weak.getConstructor(wrapper, 'WeakMap', true);
InternalMetadataModule.REQUIRED = true;
var WeakMapPrototype = $WeakMap.prototype;
var nativeDelete = WeakMapPrototype['delete'];
Expand Down

0 comments on commit a710f68

Please sign in to comment.