tc39 / Function-prototype-toString-revision

:fishing_pole_and_fish: ECMA-262 proposal to update Function.prototype.toString
https://tc39.github.io/Function-prototype-toString-revision
26 stars 10 forks source link

Web reality #17

Open bakkot opened 7 years ago

bakkot commented 7 years ago

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:

michaelficarra commented 7 years ago

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?

bakkot commented 7 years ago

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.

gsathya commented 6 years ago

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 commented 6 years ago

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

littledan commented 6 years ago

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

claudepache commented 5 years ago

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