question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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).

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
tbranyencommented, Jun 5, 2018

Fixed via #02fc47c

1reaction
awwrightcommented, 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]

Read more comments on GitHub >

github_iconTop Results From Across the Web

Buffer | Node.js v19.3.0 Documentation
toString () is incompatible with its TypedArray equivalent. A number of methods, e.g. buf.indexOf() , support additional arguments. There are two ways to...
Read more >
node js overriding toString - Stack Overflow
Show activity on this post. I see, I was thinking when I console. log an object it always calls the toString method. but...
Read more >
Alert: peacenotwar module sabotages npm developers in the ...
Vue.js users using the dependency “node-ipc” are experiencing a supply chain attack protesting the invasion of Ukraine, from a package named ...
Read more >
NodeJS 10: The New, The Changed, and the Deprecated
Node.js 10 comes packed with significant performance improvements ... According to IETF documentation, ChaCha20 is a high-speed cipher (much ...
Read more >
Changelog - Sinon.JS
The main purpose of these archives is to make old versions and documentation available ... Remove functions shadowing time related sandbox methods (#1802) ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found