node version | (function() {}).toString() output
---|---
0.12.0 | function () {}
6.5 | function () {}
9.11.1 | function () {}
10.0.0 | function() {}
I can't find any mention of this in the node v10.0.0 release notes, so I guess this wasn't intentional.
v10.0.0 seems to maintain formatting from the original code, e.g.:
> (function() {}).toString()
'function() {}'
> (function () {}).toString()
'function () {}'
> (function () {}).toString()
'function () {}'
On older versions, the spaces preceding () are always reduced/expanded to a single space.
I guess people shouldn't be relying on specific formatting of Function.toString() output, but if this is not seen as a bug then I think it's at least worth mentioning.
https://tc39.github.io/ecma262/#sec-function.prototype.tostring says:
“The use and placement of white space, line terminators, and semicolons within the representation String is implementation-dependent.”
So, as far as the current spec is concerned, this isn’t really anything to rely on.
I can't find any mention of this in the node v10.0.0 release notes
Maybe that’s a policy we could revisit at some point, but we don’t usually point out changes that are coming from the JS engine itself – there’s quite a bunch of progress on language features in Node 10 on the V8 side.
I guess this wasn't intentional.
I assume this particular change happened as part of implementing https://tc39.github.io/Function-prototype-toString-revision/ in V8, the general idea being that the result of .toString() is becoming standardized to be a literal substring of the original source text.
Thanks @addaleax - that's very clear 🙂
The V8 team documented this change in the blog post for V8 6.6: https://v8project.blogspot.ch/2018/03/v8-release-66.html
Most helpful comment
https://tc39.github.io/ecma262/#sec-function.prototype.tostring says:
So, as far as the current spec is concerned, this isn’t really anything to rely on.
Maybe that’s a policy we could revisit at some point, but we don’t usually point out changes that are coming from the JS engine itself – there’s quite a bunch of progress on language features in Node 10 on the V8 side.
I assume this particular change happened as part of implementing https://tc39.github.io/Function-prototype-toString-revision/ in V8, the general idea being that the result of
.toString()is becoming standardized to be a literal substring of the original source text.