diff options
author | himself65 <himself65@outlook.com> | 2020-04-04 11:41:34 +0300 |
---|---|---|
committer | Michaƫl Zasso <targos@protonmail.com> | 2020-04-12 14:00:55 +0300 |
commit | 1a01ac34254fe3057061670cafb23d121ce06911 (patch) | |
tree | 6e218f0dd46f6d3a6e4716c2432ccc90dcc4526e /src/node_perf.cc | |
parent | 180e43711c88a51c5eb9a2447df79168ae2e561b (diff) |
perf_hooks: allow omitted parameters in 'performance.measure'
Make `startMark` and `endMark` parameters optional.
PR-URL: https://github.com/nodejs/node/pull/32651
Fixes: https://github.com/nodejs/node/issues/32647
Refs: https://www.w3.org/TR/user-timing-2/#measure-method
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/node_perf.cc')
-rw-r--r-- | src/node_perf.cc | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/node_perf.cc b/src/node_perf.cc index e54edb5fe6d..4b8bf2a8a7c 100644 --- a/src/node_perf.cc +++ b/src/node_perf.cc @@ -172,7 +172,6 @@ void Measure(const FunctionCallbackInfo<Value>& args) { HandleScope scope(env->isolate()); Utf8Value name(env->isolate(), args[0]); Utf8Value startMark(env->isolate(), args[1]); - Utf8Value endMark(env->isolate(), args[2]); AliasedFloat64Array& milestones = env->performance_state()->milestones; @@ -186,11 +185,17 @@ void Measure(const FunctionCallbackInfo<Value>& args) { startTimestamp = milestones[milestone]; } - uint64_t endTimestamp = GetPerformanceMark(env, *endMark); - if (endTimestamp == 0) { - PerformanceMilestone milestone = ToPerformanceMilestoneEnum(*endMark); - if (milestone != NODE_PERFORMANCE_MILESTONE_INVALID) - endTimestamp = milestones[milestone]; + uint64_t endTimestamp = 0; + if (args[2]->IsUndefined()) { + endTimestamp = PERFORMANCE_NOW(); + } else { + Utf8Value endMark(env->isolate(), args[2]); + endTimestamp = GetPerformanceMark(env, *endMark); + if (endTimestamp == 0) { + PerformanceMilestone milestone = ToPerformanceMilestoneEnum(*endMark); + if (milestone != NODE_PERFORMANCE_MILESTONE_INVALID) + endTimestamp = milestones[milestone]; + } } if (endTimestamp < startTimestamp) |