Skip to content

Commit 9beaff6

Browse files
committed
src: set function names in SetFastMethod helpers
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: #67826 Signed-off-by: Yohannes Desta <yohannesdestagebru10@gmail.com>
1 parent 68fad2c commit 9beaff6

2 files changed

Lines changed: 22 additions & 15 deletions

File tree

‎src/util.cc‎

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -371,15 +371,12 @@ Local<FunctionTemplate> NewMethodTemplate(
371371
void SetMethodFromTemplate(Local<Context> context,
372372
Local<Object> that,
373373
const std::string_view name,
374-
Local<FunctionTemplate> t,
375-
bool set_function_name) {
374+
Local<FunctionTemplate> t) {
376375
Isolate* isolate = Isolate::GetCurrent();
377376
Local<Function> function = t->GetFunction(context).ToLocalChecked();
378377
Local<String> name_string = NewMethodName(isolate, name);
379378
that->Set(context, name_string, function).Check();
380-
if (set_function_name) {
381-
function->SetName(name_string); // NODE_SET_METHOD() compatibility.
382-
}
379+
function->SetName(name_string); // NODE_SET_METHOD() compatibility.
383380
}
384381

385382
// Installs `t` on the prototype or instance template of `that` as `name`.
@@ -403,8 +400,7 @@ void SetMethod(Local<Context> context,
403400
that,
404401
name,
405402
NewMethodTemplate(
406-
Isolate::GetCurrent(), callback, SideEffectType::kHasSideEffect),
407-
true);
403+
Isolate::GetCurrent(), callback, SideEffectType::kHasSideEffect));
408404
}
409405

410406
void SetMethod(Isolate* isolate,
@@ -438,8 +434,7 @@ void SetFastMethod(Local<Context> context,
438434
NewMethodTemplate(Isolate::GetCurrent(),
439435
slow_callback,
440436
SideEffectType::kHasSideEffect,
441-
c_function),
442-
false);
437+
c_function));
443438
}
444439

445440
void SetFastMethodNoSideEffect(Local<Context> context,
@@ -453,8 +448,7 @@ void SetFastMethodNoSideEffect(Local<Context> context,
453448
NewMethodTemplate(Isolate::GetCurrent(),
454449
slow_callback,
455450
SideEffectType::kHasNoSideEffect,
456-
c_function),
457-
false);
451+
c_function));
458452
}
459453

460454
void SetFastMethodNoSideEffect(Isolate* isolate,
@@ -502,8 +496,7 @@ void SetFastMethodNoSideEffect(Local<Context> context,
502496
NewMethodTemplate(Isolate::GetCurrent(),
503497
slow_callback,
504498
SideEffectType::kHasNoSideEffect,
505-
methods),
506-
false);
499+
methods));
507500
}
508501

509502
void SetMethodNoSideEffect(Local<Context> context,
@@ -515,8 +508,7 @@ void SetMethodNoSideEffect(Local<Context> context,
515508
that,
516509
name,
517510
NewMethodTemplate(
518-
Isolate::GetCurrent(), callback, SideEffectType::kHasNoSideEffect),
519-
true);
511+
Isolate::GetCurrent(), callback, SideEffectType::kHasNoSideEffect));
520512
}
521513

522514
void SetMethodNoSideEffect(Isolate* isolate,
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict';
2+
3+
// The functions in util.types should be named after the property that
4+
// exposes them, including the ones implemented in C++.
5+
// Refs: https://github.com/nodejs/node/issues/67826
6+
7+
require('../common');
8+
const assert = require('assert');
9+
const { types } = require('util');
10+
11+
for (const [key, fn] of Object.entries(types)) {
12+
// isArrayBufferView is ArrayBuffer.isView.
13+
if (key === 'isArrayBufferView') continue;
14+
assert.strictEqual(fn.name, key);
15+
}

0 commit comments

Comments
 (0)