Skip to content

Node 10.0.0 Function 's toString method behaves differently than in previous versions #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sadasant opened this issue May 1, 2018 · 11 comments

Comments

@sadasant
Copy link

sadasant commented May 1, 2018

Node 10.0.0 yields an unexpected result when functions are converted to strings through the toString method. Here's what happens:

  • 10.0.0: (function () { }).toString() results in: 'function () { }'.
  • 9.5.0: (function(){ }).toString() results in: 'function (){ }'.

The affected line is: https://github.com/nodegit/promisify-node/blob/master/utils/args.js#L9
A possible solution is to change the RegExp to: /function.*?\(([^)]*)\)/ (for example).

@awwright
Copy link

awwright commented May 6, 2018

While V8 should be conservative in what it emits, I would point out this module should also be liberal in what it accepts. Both return values are indeed valid ECMAScript, and the module here should be prepared to accept any valid function, even input not directly from Function#toString.

Perhaps a full ECMAScript parser would be overkill (note that constructions such as function/**/name/**/(a)/**/{} are valid, since comments are considered whitespace), but using \s* would certainly be better.

I would propose .match(/function\s*([^(]*)\s*\(([^)]*)\)/)[2]

@jmls
Copy link

jmls commented May 15, 2018

is there any expection of when this is due to be fixed ?

@sadasant
Copy link
Author

Well, nothing is broken if we don't upgrade to Node 10, but eventually we will want to update. It's really up to the availability of whoever can push here 🌞

@getify
Copy link

getify commented May 19, 2018

Many of us are on node10 now, and this is a big blocker to be incompatible. Please patch this regex quickly.

@lenovouser
Copy link

This is still an issue. @awwright do you want to submit a PR with your proposed regex?

@awwright
Copy link

I actually know very little about node-git, I'm here because I've stumbled across this before.

I don't know if the regexp would even work.

Also it appears V8 will, in fact, embed comments inside Function#toString() e.g.

> foo.toString().match(/function\s*([^(]*)\s*\(([^)]*)\)/)[2]
'a, b,c, /*c*/c'

(note there's no space in b,c, which the function also expects to split arguments)

@jsilvermist
Copy link

@tbranyen Any update on this issue? It's causing some pretty widespread issues.

jsilvermist added a commit to jsilvermist/sl-gallery that referenced this issue Jun 5, 2018
@tbranyen
Copy link
Member

tbranyen commented Jun 5, 2018

I can check into it today, it was always a hack, but I'm a little surprised this changed. Since it's a V8 change and could break parts of the existing web.

@tbranyen
Copy link
Member

tbranyen commented Jun 5, 2018

Fixed via #02fc47c

@tbranyen tbranyen closed this as completed Jun 5, 2018
@jsilvermist
Copy link

@tbranyen Thanks!

@sadasant
Copy link
Author

@tbranyen thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants