node icon indicating copy to clipboard operation
node copied to clipboard

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

Open konard opened this issue 6 days ago • 1 comments

Version

Reproduced on v22.23.5 and v26.13.1 on Linux x64. v20.20.2 retains the exported function names.

Reproduction

const { types } = require('node:util');

for (const key of ['isProxy', 'isRegExp', 'isDate', 'isAnyArrayBuffer', 'isTypedArray']) {
  console.log(key, JSON.stringify(types[key].name));
}

console.log(types.isProxy(new Proxy({}, {})), types.isProxy({}));

On v20.20.2, all five functions report their exported names. On v22.23.5 and v26.13.1, the first four functions report "", while isTypedArray still reports "isTypedArray". The last line prints true false in all three runtimes, so the predicate behavior itself remains correct.

This is observable in runtime diagnostics and code that identifies these built-ins by their names. A private compiler check in Router PR 811 currently retains Node 20 for the compiler process while the remaining checks run on Node 26.

The naming change coincides with the move from SetMethodNoSideEffect in the v20 registration to SetFastMethodNoSideEffect in the v26 registration. Would it make sense to preserve the exported classifying name when creating the fast-API binding? A util types test could assert types.isProxy.name === 'isProxy' and check that the predicate continues to distinguish proxies from plain objects.

konard avatar Nov 27 '26 14:11 konard

Reproduced on Linux. On v20.20.2 every util.types function has its exported name. On v22.20.0, v24.22.3, v25.6.1 and main, the predicates implemented in C++ (26–27 of 43, including isProxy, isDate, isPromise, isRegExp) have name === ''. The ones defined in JavaScript (isTypedArray, isDataView, the typed array checks) keep their names. The predicates still return the right results.

The cause is in src/util.cc: SetMethod() and SetMethodNoSideEffect() with a Local<Context> and Local<Object> call function->SetName(name_string) (commented "NODE_SET_METHOD() compatibility"), but the three SetFastMethod()/SetFastMethodNoSideEffect() overloads with the same parameters don't. Any binding registered through them gets an empty name, and util.types is where users see it.

I tried adding the same SetName() call to those three overloads in a local build of main: every util.types function gets its name back (the only remaining mismatch is isArrayBufferView reporting isView, as on v20), and test-util*, test-process-binding* and test-bootstrap-modules pass.

yohannesjoya avatar Nov 27 '26 19:11 yohannesjoya