tc39 / Function-prototype-toString-revision

:fishing_pole_and_fish: ECMA-262 proposal to update Function.prototype.toString

Home Page:https://tc39.github.io/Function-prototype-toString-revision

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Web reality

bakkot opened this issue · comments

In all of {V8, SpiderMonkey, JavaScriptCore, Chakra}, the snippet

(function /**/ \u0061 /**/ ( /**/ ) { /**/ }).toString()

produces

function a( /**/ ){ /**/ }

which differs from this proposal's required

function /**/ \u0061 /**/ ( /**/ ){ /**/ }

The same occurs for function declarations. It appears that all browsers save only the source text from the parameters onwards, and synthesize text appearing prior to them.

😢

I think this is okay. We'll have to see if it actually breaks any real programs. @bakkot What kinds of JS idioms would you expect to be broken by this discrepancy?

Ah, I don't know if it'd break much code in the wild, and unfortunately it's hard to know ahead of time. But I can imagine code doing something like

function getActualFunctionName(fn) {
  return fn.toString().match(/function ([^(]*)/)[1];
}

which in all browsers will give you the original name of the function even if its name property has been redefined.

We got breakage reported on Chrome:
https://bugs.chromium.org/p/chromium/issues/detail?id=835209

I've asked for their current status, let's wait for them to get back before making any changes.

looks like @littledan opened a new bug here: #33

Note, the incompatibility reported in that bug is a different one from what this bug started with.

Now, both Chrome and Firefox conform to the proposal for (function /**/ \u0061 /**/ ( /**/ ) { /**/ }).toString(); so that this gh-issue seems obsolete.