Node 10.0.0 Function 's toString method behaves differently than in previous versions
See original GitHub issueNode 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:
- Created 5 years ago
- Reactions:4
- Comments:11 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Fixed via #02fc47c
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]