debian-mirror-gitlab/core-js/internals/redefine.js

35 lines
1.5 KiB
JavaScript
Raw Normal View History

2019-09-25 13:30:05 +05:30
var global = require('../internals/global');
2019-10-31 01:37:42 +05:30
var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
2019-09-25 13:30:05 +05:30
var has = require('../internals/has');
var setGlobal = require('../internals/set-global');
2019-12-04 20:38:33 +05:30
var inspectSource = require('../internals/inspect-source');
2019-09-25 13:30:05 +05:30
var InternalStateModule = require('../internals/internal-state');
var getInternalState = InternalStateModule.get;
var enforceInternalState = InternalStateModule.enforce;
2019-12-04 20:38:33 +05:30
var TEMPLATE = String(String).split('String');
2019-09-25 13:30:05 +05:30
(module.exports = function (O, key, value, options) {
var unsafe = options ? !!options.unsafe : false;
var simple = options ? !!options.enumerable : false;
var noTargetGet = options ? !!options.noTargetGet : false;
if (typeof value == 'function') {
2019-10-31 01:37:42 +05:30
if (typeof key == 'string' && !has(value, 'name')) createNonEnumerableProperty(value, 'name', key);
2019-09-25 13:30:05 +05:30
enforceInternalState(value).source = TEMPLATE.join(typeof key == 'string' ? key : '');
}
if (O === global) {
if (simple) O[key] = value;
else setGlobal(key, value);
return;
} else if (!unsafe) {
delete O[key];
} else if (!noTargetGet && O[key]) {
simple = true;
}
if (simple) O[key] = value;
2019-10-31 01:37:42 +05:30
else createNonEnumerableProperty(O, key, value);
2019-09-25 13:30:05 +05:30
// add fake Function#toString for correct work wrapped methods / constructors with methods like LoDash isNative
})(Function.prototype, 'toString', function toString() {
2019-12-04 20:38:33 +05:30
return typeof this == 'function' && getInternalState(this).source || inspectSource(this);
2019-09-25 13:30:05 +05:30
});