Skip to content

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

Closed
@ColCh

Description

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

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions