You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
886 B
25 lines
886 B
var DESCRIPTORS = require('../internals/descriptors'); |
|
var FUNCTION_NAME_EXISTS = require('../internals/function-name').EXISTS; |
|
var uncurryThis = require('../internals/function-uncurry-this'); |
|
var defineProperty = require('../internals/object-define-property').f; |
|
|
|
var FunctionPrototype = Function.prototype; |
|
var functionToString = uncurryThis(FunctionPrototype.toString); |
|
var nameRE = /function\b(?:\s|\/\*[\S\s]*?\*\/|\/\/[^\n\r]*[\n\r]+)*([^\s(/]*)/; |
|
var regExpExec = uncurryThis(nameRE.exec); |
|
var NAME = 'name'; |
|
|
|
// Function instances `.name` property |
|
// https://tc39.es/ecma262/#sec-function-instances-name |
|
if (DESCRIPTORS && !FUNCTION_NAME_EXISTS) { |
|
defineProperty(FunctionPrototype, NAME, { |
|
configurable: true, |
|
get: function () { |
|
try { |
|
return regExpExec(nameRE, functionToString(this))[1]; |
|
} catch (error) { |
|
return ''; |
|
} |
|
} |
|
}); |
|
}
|
|
|