diff --git a/packages/core-js/internals/export.js b/packages/core-js/internals/export.js index 57d777641c24..f4c46c20a2e0 100644 --- a/packages/core-js/internals/export.js +++ b/packages/core-js/internals/export.js @@ -1,5 +1,6 @@ var global = require('core-js-internals/global'); var redefine = require('../internals/redefine'); +var setGlobal = require('../internals/set-global'); /* options.target - name of the target object @@ -18,7 +19,7 @@ module.exports = function (options, source) { if (options.global) { target = global; } else if (options.stat) { - target = global[name] || (global[name] = {}); + target = global[name] || setGlobal(name, {}); } else { target = (global[name] || {}).prototype; } diff --git a/packages/core-js/internals/redefine.js b/packages/core-js/internals/redefine.js index ab620295f85d..524708b12286 100644 --- a/packages/core-js/internals/redefine.js +++ b/packages/core-js/internals/redefine.js @@ -1,6 +1,7 @@ var global = require('core-js-internals/global'); var hide = require('../internals/hide'); var has = require('core-js-internals/has'); +var setGlobal = require('../internals/set-global'); var $ = require('../internals/state'); var TO_STRING = 'toString'; var nativeFunctionToString = Function[TO_STRING]; @@ -16,7 +17,7 @@ require('core-js-internals/shared')('inspectSource', function (it) { $(value, true).source = has(O, key) ? String(O[key]) : TEMPLATE.join(String(key)); } if (O === global) { - O[key] = value; + setGlobal(key, value); } else if (!unsafe) { delete O[key]; hide(O, key, value); diff --git a/packages/core-js/internals/set-global.js b/packages/core-js/internals/set-global.js new file mode 100644 index 000000000000..2501bae447d9 --- /dev/null +++ b/packages/core-js/internals/set-global.js @@ -0,0 +1,10 @@ +var global = require('core-js-internals/global'); +var hide = require('../internals/hide'); + +module.exports = function (key, value) { + try { + hide(global, key, value); + } catch (e) { + global[key] = value; + } return value; +};