Closed Xotic750 closed 8 years ago
That's a Safari bug, then, and not much es6-shim can do about it.
node/v8 has a similar version of the bug -- the ES6 says that f.hasOwnProperty('name')
should return false
if f
is an anonymous function. But in the latest node, f.name
is an own property, with the value ''. (Function.prototype.name = ''
so the value is right, it just should be inherited from the prototype, not be an own property.)
Anyway, I don't think there's anything we can do about it -- everyone seems to correctly implement f.name
as not writable, so we can't fix it.
Thanks. There seem to be quite a few non-fixable bugs within ES6. At least it is documented. ;)
Said differently -- "JavaScript engines have a ways to go before they faithfully implement all of ES6."
I don't know if there is a bug report with Safari for this, actually not even sure where to look.
I tried submitting a bug via their Bug Reporter, but my pointer just spins and spins and spins. :/
I'm going to close this since function name stuff is unshimmable.
I was looking into how we could polyfill Function.prototype.name
and have come across a partial implementation --
var fnNamePrefixRegex = /^[\S\s]*?function\s*/;
var fnNameSuffixRegex = /[\s\(\/][\S\s]+$/;
Object.defineProperty(Function.prototype, "name", {
get: name
});
function name() {
var name = "";
if (this === Function || this === Function.prototype.constructor) {
name = "Function";
}
else if (this !== Function.prototype) {
name = ("" + this).replace(fnNamePrefixRegex, "").replace(fnNameSuffixRegex, "");
}
return name;
}
@ljharb By unshimmable do you mean it is not feasible or do you mean impossible?
@JakeChampion impossible. The property is nonconfigurable in everything but IE (prior to ES6, which makes it configurable). However, in IE 9 - 11, you could probably add that getter, but I suspect there would be many edge cases, including "native code" functions.
In Safari 9 I notice that it behaves differently to all other environments I have tested so far.
https://jsfiddle.net/Xotic750/mqabqdm0/ On Safari this alerts
'anonymous'
, but everywhere else I have tested it alerts''
https://saucelabs.com/beta/tests/e755ffaa8c744824b288d2ec6b6b0366/watch