Function-prototype-toString-revision icon indicating copy to clipboard operation
Function-prototype-toString-revision copied to clipboard

Web reality

Open bakkot opened this issue 9 years ago • 6 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.

:cry:

bakkot avatar Aug 18 '16 16:08 bakkot

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?

michaelficarra avatar Aug 18 '16 17:08 michaelficarra

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.

bakkot avatar Aug 18 '16 17:08 bakkot

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.

gsathya avatar Jun 06 '18 18:06 gsathya

looks like @littledan opened a new bug here: https://github.com/tc39/Function-prototype-toString-revision/issues/33

gsathya avatar Jun 06 '18 19:06 gsathya

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

littledan avatar Jun 11 '18 01:06 littledan

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

claudepache avatar Sep 07 '18 22:09 claudepache