Repository navigation
src: set function names in SetFastMethod helpers - #67869
yohannesjoya wants to merge 1 commit into
Conversation
SetMethodFromTemplate() only set the function name when asked to, and the SetFastMethod() and SetFastMethodNoSideEffect() overloads that install a function on an object did not ask. Functions registered through them had an empty name, which is visible in util.types since its predicates became fast API calls. Always set the name, as SetMethod() and SetMethodNoSideEffect() already did, and drop the now unused parameter. Fixes: nodejs#67826 Signed-off-by: Yohannes Desta <yohannesdestagebru10@gmail.com>
There was a problem hiding this comment.
There are many more Set*Method overloads that are missing this. Also, the disposer helpers should name their methods eg. "[Symbol.dispose]" as per https://tc39.es/ecma262/multipage/ordinary-and-exotic-objects-behaviours.html#sec-setfunctionname
There was a problem hiding this comment.
I have this ready locally (template overloads set the class name via SetClassMethodFromTemplate(), dispose helpers named [Symbol.dispose]/[Symbol.asyncDispose], test removed). I'll push it once @jasnell confirms there's no reason to keep those unnamed, or I can do it in a follow-up PR if that's preferred.
There was a problem hiding this comment.
It has approval so feel free to carry on!
There was a problem hiding this comment.
We don't need to add tests for these (the same has been true for adding assignFunctionName() in lib, eg. #58180)
24a762b to
9beaff6
Compare
|
@jasnell this comes on the back of your refactor – other than preserving existing behaviour, was there a compelling reason for keeping some of these helpers as registering methods without function names? |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #67869 +/- ##
=======================================
Coverage 90.57% 90.57%
=======================================
Files 802 802
Lines 286210 286208 -2
Branches 55288 55289 +1
=======================================
+ Hits 259226 259231 +5
- Misses 17072 17075 +3
+ Partials 9912 9902 -10
🚀 New features to boost your workflow:
|
SetMethodFromTemplate()only callsfunction->SetName()when itsset_function_nameargument is true.SetMethod()andSetMethodNoSideEffect()passtrue, but the threeSetFastMethod()/SetFastMethodNoSideEffect()overloads that install a function on an object passfalse, so the functions they register have an emptyname. This shows inutil.types: v22 moved its predicates fromSetMethodNoSideEffect()toSetFastMethodNoSideEffect(), and since thenutil.types.isProxy.nameand most of the other C++ predicates are''.This makes
SetMethodFromTemplate()always set the name and drops the parameter. Thanks to konard for the report.Fixes: #67826
The new test checks that every
util.typesfunction is named after its property (exceptisArrayBufferView, which isArrayBuffer.isView). It fails with v25.6.1 and passes with this change. Since other bindings registered through these helpers now get names too, I rantools/test.pyforparallel/test-{util,process,buffer,v8,bootstrap,url,perf,timers,crypto}*locally (545 tests), and they pass, as domake format-cpp, cpplint andtools/checkimports.py. The tests above ran on a build of an earlier main with the equivalent change, becauseSetMethodFromTemplate()was introduced after that (#67496); on current main I checked thatsrc/util.cccompiles.AI disclosure: I used an AI assistant to help write the test and this description. I reproduced the issue, reviewed the change and ran the tests above myself.