Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function.prototype.name getter brokes function name getter #454

Closed
ColCh opened this issue Mar 7, 2019 · 2 comments
Closed

Function.prototype.name getter brokes function name getter #454

ColCh opened this issue Mar 7, 2019 · 2 comments

Comments

@ColCh
Copy link

ColCh commented Mar 7, 2019

This code breaks Function.prototype.name in 100% of cases

var funcNameBeforeProtoCall = (function bar() {}).name
var funcNameBeforeProtoCallEquals = funcNameBeforeProtoCall === 'bar';
debugger;
Function.prototype.name;
var funcNameAfterProtoCall = (function foo() {}).name
var funcNameAfterProtoCallEquals = funcNameAfterProtoCall === 'foo';
debugger

launchable code: https://codepen.io/ColCh/pen/Oqpqqp

Try it in IE 11 and this would be resulted in this:

image

WHY ?!

Because this code is executed against this variable of Function.prototype

es6-shim/es6-sham.js

Lines 158 to 159 in 271142c

var match = _call(_strMatch, str, /\s*function\s+([^(\s]*)\s*/);
var name = match && match[1];

and this code assigns getter with for Function.prototype name property with null value.

es6-shim/es6-sham.js

Lines 160 to 165 in 271142c

Object.defineProperty(this, 'name', {
configurable: true,
enumerable: false,
writable: false,
value: name
});

Solution: skip defineProperty for null names

@ColCh ColCh changed the title Function.prototype.name getter brokes function Function.prototype.name getter brokes function name getter Mar 7, 2019
@ljharb
Copy link
Collaborator

ljharb commented Mar 7, 2019

ah, that's a really good catch - I don't think we ever expected anyone would refer to the name getter directly. Fix incoming.

@ljharb ljharb closed this as completed in 003ee5d Mar 7, 2019
@ColCh
Copy link
Author

ColCh commented Mar 7, 2019

Omg that was fast! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants