Skip to content

Commit

Permalink
make globals non-enumerable where it's possible
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed May 4, 2018
1 parent 25da55c commit 63d71b5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/core-js/internals/export.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/core-js/internals/redefine.js
Original file line number Diff line number Diff line change
@@ -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];
Expand All @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions packages/core-js/internals/set-global.js
Original file line number Diff line number Diff line change
@@ -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;
};

0 comments on commit 63d71b5

Please sign in to comment.