2019-09-25 13:30:05 +05:30
|
|
|
var global = require('../internals/global');
|
|
|
|
var shared = require('../internals/shared');
|
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');
|
|
|
|
var nativeFunctionToString = require('../internals/function-to-string');
|
|
|
|
var InternalStateModule = require('../internals/internal-state');
|
|
|
|
|
|
|
|
var getInternalState = InternalStateModule.get;
|
|
|
|
var enforceInternalState = InternalStateModule.enforce;
|
|
|
|
var TEMPLATE = String(nativeFunctionToString).split('toString');
|
|
|
|
|
|
|
|
shared('inspectSource', function (it) {
|
|
|
|
return nativeFunctionToString.call(it);
|
|
|
|
});
|
|
|
|
|
|
|
|
(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() {
|
|
|
|
return typeof this == 'function' && getInternalState(this).source || nativeFunctionToString.call(this);
|
|
|
|
});
|