Skip to content

src: set function names in SetFastMethod helpers - #67869

Open
yohannesjoya wants to merge 1 commit into
nodejs:mainfrom
yohannesjoya:src-fast-method-names
Open

yohannesjoya wants to merge 1 commit into
nodejs:mainfrom
yohannesjoya:src-fast-method-names

Conversation

@yohannesjoya

@yohannesjoya yohannesjoya commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

SetMethodFromTemplate() only calls function->SetName() when its set_function_name argument is true. SetMethod() and SetMethodNoSideEffect() pass true, but the three SetFastMethod()/SetFastMethodNoSideEffect() overloads that install a function on an object pass false, so the functions they register have an empty name. This shows in util.types: v22 moved its predicates from SetMethodNoSideEffect() to SetFastMethodNoSideEffect(), and since then util.types.isProxy.name and 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.types function is named after its property (except isArrayBufferView, which is ArrayBuffer.isView). It fails with v25.6.1 and passes with this change. Since other bindings registered through these helpers now get names too, I ran tools/test.py for parallel/test-{util,process,buffer,v8,bootstrap,url,perf,timers,crypto}* locally (545 tests), and they pass, as do make format-cpp, cpplint and tools/checkimports.py. The tests above ran on a build of an earlier main with the equivalent change, because SetMethodFromTemplate() was introduced after that (#67496); on current main I checked that src/util.cc compiles.

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.

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Nov 29, 2026
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>
Comment thread src/util.cc

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has approval so feel free to carry on!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to add tests for these (the same has been true for adding assignFunctionName() in lib, eg. #58180)

@Renegade334

Copy link
Copy Markdown
Member

@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

codecov Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.57%. Comparing base (02cca56) to head (9beaff6).
⚠️ Report is 23 commits behind head on main.

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     
Files with missing lines Coverage Δ
src/util.cc 88.29% <100.00%> (-0.06%) ⬇️

... and 33 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Some Set*Method helpers do not define the method's function name

4 participants