| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e1b8c85 commit 112518f
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,10 +20,6 @@ const { | |||
| 20 | 20 | isHistogram | |
| 21 | 21 | } = require('internal/histogram'); | |
| 22 | 22 | ||
| 23 | - const { | ||
| 24 | - isConstructor, | ||
| 25 | - } = internalBinding('util'); | ||
| 26 | - | ||
| 27 | 23 | const { | |
| 28 | 24 | codes: { | |
| 29 | 25 | ERR_INVALID_ARG_TYPE, | |
@@ -72,14 +68,13 @@ function timerify(fn, options = kEmptyObject) { | |||
| 72 | 68 | histogram); | |
| 73 | 69 | } | |
| 74 | 70 | ||
| 75 | - const constructor = isConstructor(fn); | ||
| 76 | - | ||
| 77 | 71 | function timerified(...args) { | |
| 72 | + const isConstructorCall = new.target !== undefined; | ||
| 78 | 73 | const start = now(); | |
| 79 | - const result = constructor ? | ||
| 74 | + const result = isConstructorCall ? | ||
| 80 | 75 | ReflectConstruct(fn, args, fn) : | |
| 81 | 76 | ReflectApply(fn, this, args); | |
| 82 | - if (!constructor && typeof result?.finally === 'function') { | ||
| 77 | + if (!isConstructorCall && typeof result?.finally === 'function') { | ||
| 83 | 78 | return result.finally( | |
| 84 | 79 | FunctionPrototypeBind( | |
| 85 | 80 | processComplete, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -289,11 +289,6 @@ static void GuessHandleType(const FunctionCallbackInfo<Value>& args) { | |||
| 289 | 289 | args.GetReturnValue().Set(OneByteString(env->isolate(), type)); | |
| 290 | 290 | } | |
| 291 | 291 | ||
| 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 | - | ||
| 297 | 292 | static void ToUSVString(const FunctionCallbackInfo<Value>& args) { | |
| 298 | 293 | Environment* env = Environment::GetCurrent(args); | |
| 299 | 294 | CHECK_GE(args.Length(), 2); | |
@@ -344,7 +339,6 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) { | |||
| 344 | 339 | registry->Register(WeakReference::IncRef); | |
| 345 | 340 | registry->Register(WeakReference::DecRef); | |
| 346 | 341 | registry->Register(GuessHandleType); | |
| 347 | - registry->Register(IsConstructor); | ||
| 348 | 342 | registry->Register(ToUSVString); | |
| 349 | 343 | } | |
| 350 | 344 | ||
@@ -384,7 +378,6 @@ void Initialize(Local<Object> target, | |||
| 384 | 378 | env->SetMethodNoSideEffect(target, "getConstructorName", GetConstructorName); | |
| 385 | 379 | env->SetMethodNoSideEffect(target, "getExternalValue", GetExternalValue); | |
| 386 | 380 | env->SetMethod(target, "sleep", Sleep); | |
| 387 | - env->SetMethodNoSideEffect(target, "isConstructor", IsConstructor); | ||
| 388 | 381 | ||
| 389 | 382 | env->SetMethod(target, "arrayBufferViewHasBuffer", ArrayBufferViewHasBuffer); | |
| 390 | 383 | Local<Object> constants = Object::New(env->isolate()); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -123,3 +123,22 @@ const { | |||
| 123 | 123 | }); | |
| 124 | 124 | }); | |
| 125 | 125 | })().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 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments