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

Web compatibility issue reported

Open littledan opened this issue 7 years ago • 4 comments

A bug was filed against Chrome for the Function.prototype.toString change. The reporter claims it breaks their site, and is recommending users to switch to IE. The reporter said,

We have .replace() code specifically looking for .replace('function anonymous() {', '') which no longer works since upgrading to version 66 of Chrome

What do we make of this "compatibility issue"? Should we reconsider https://github.com/tc39/Function-prototype-toString-revision/pull/13 ? cc @gsathya

littledan avatar Jun 06 '18 18:06 littledan

Can the reporter be evangelized to change their site, or do we think this is a more widespread problem?

ljharb avatar Jun 06 '18 19:06 ljharb

It's very likely no programmer will expect extra newline before ), especially old browsers never add it. So it's very likely many old codes of reflection of functions will potentially fail! You don't get many reports just because there is rare use of new Function() and even rare cases of combination of new Function and reflections. So the risk of it will likely to be underestimated.

And, IMO, the reason of append newline is flawed, see my comment: https://github.com/tc39/Function-prototype-toString-revision/pull/13#issuecomment-403441040

hax avatar Jul 09 '18 11:07 hax

@littledan Perhaps, if we discover that this is a common enough pattern, we should special-case empty parameter lists to omit the newline? Or even go a step further and test for trailing line comments (though this may be hard to do spec-wise).

michaelficarra avatar Jul 10 '18 23:07 michaelficarra

Or even go a step further and test for trailing line comments (though this may be hard to do spec-wise).

What's the hard part about this? Could we remove trailing line comments from each parameter, in the Function.prototype.toString representation, for example?


I'm not sure why @hax 's comment was marked as off-topic; it seems relevant to me.

littledan avatar Jul 11 '18 22:07 littledan