Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 112518f

Browse filesBrowse files
cola119danielleadams
authored andcommitted
perf_hooks: fix function wrapped by timerify to work correctly
PR-URL: #43330 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent e1b8c85 commit 112518f
Copy full SHA for 112518f

File tree

Expand file treeCollapse file tree

3 files changed

+22
-15
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+22
-15
lines changed
Open diff view settings
Collapse file

‎lib/internal/perf/timerify.js‎

Copy file name to clipboardExpand all lines: lib/internal/perf/timerify.js
+3-8Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ const {
2020
isHistogram
2121
} = require('internal/histogram');
2222

23-
const {
24-
isConstructor,
25-
} = internalBinding('util');
26-
2723
const {
2824
codes: {
2925
ERR_INVALID_ARG_TYPE,
@@ -72,14 +68,13 @@ function timerify(fn, options = kEmptyObject) {
7268
histogram);
7369
}
7470

75-
const constructor = isConstructor(fn);
76-
7771
function timerified(...args) {
72+
const isConstructorCall = new.target !== undefined;
7873
const start = now();
79-
const result = constructor ?
74+
const result = isConstructorCall ?
8075
ReflectConstruct(fn, args, fn) :
8176
ReflectApply(fn, this, args);
82-
if (!constructor && typeof result?.finally === 'function') {
77+
if (!isConstructorCall && typeof result?.finally === 'function') {
8378
return result.finally(
8479
FunctionPrototypeBind(
8580
processComplete,
Collapse file

‎src/node_util.cc‎

Copy file name to clipboardExpand all lines: src/node_util.cc
-7Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,6 @@ static void GuessHandleType(const FunctionCallbackInfo<Value>& args) {
289289
args.GetReturnValue().Set(OneByteString(env->isolate(), type));
290290
}
291291

292-
static void IsConstructor(const FunctionCallbackInfo<Value>& args) {
293-
CHECK(args[0]->IsFunction());
294-
args.GetReturnValue().Set(args[0].As<v8::Function>()->IsConstructor());
295-
}
296-
297292
static void ToUSVString(const FunctionCallbackInfo<Value>& args) {
298293
Environment* env = Environment::GetCurrent(args);
299294
CHECK_GE(args.Length(), 2);
@@ -344,7 +339,6 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
344339
registry->Register(WeakReference::IncRef);
345340
registry->Register(WeakReference::DecRef);
346341
registry->Register(GuessHandleType);
347-
registry->Register(IsConstructor);
348342
registry->Register(ToUSVString);
349343
}
350344

@@ -384,7 +378,6 @@ void Initialize(Local<Object> target,
384378
env->SetMethodNoSideEffect(target, "getConstructorName", GetConstructorName);
385379
env->SetMethodNoSideEffect(target, "getExternalValue", GetExternalValue);
386380
env->SetMethod(target, "sleep", Sleep);
387-
env->SetMethodNoSideEffect(target, "isConstructor", IsConstructor);
388381

389382
env->SetMethod(target, "arrayBufferViewHasBuffer", ArrayBufferViewHasBuffer);
390383
Local<Object> constants = Object::New(env->isolate());
Collapse file

‎test/parallel/test-performance-function.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-performance-function.js
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,22 @@ const {
123123
});
124124
});
125125
})().then(common.mustCall());
126+
127+
// Regression tests for https://github.com/nodejs/node/issues/40623
128+
{
129+
assert.strictEqual(performance.timerify(function func() {
130+
return 1;
131+
})(), 1);
132+
assert.strictEqual(performance.timerify(function() {
133+
return 1;
134+
})(), 1);
135+
assert.strictEqual(performance.timerify(() => {
136+
return 1;
137+
})(), 1);
138+
class C {}
139+
const wrap = performance.timerify(C);
140+
assert.ok(new wrap() instanceof C);
141+
assert.throws(() => wrap(), {
142+
name: 'TypeError',
143+
});
144+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.