From bc262f7a478b1d0c0ba417b5938d36544b395ee9 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Fri, 9 Apr 2021 13:08:28 +0200 Subject: [PATCH 1/3] perf_hooks: fix loop delay resolution validation Fixes: https://github.com/nodejs/node/issues/38160 --- lib/internal/perf/event_loop_delay.js | 4 ++-- test/sequential/test-performance-eventloopdelay.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/internal/perf/event_loop_delay.js b/lib/internal/perf/event_loop_delay.js index f90bb9e4de7d58..94dfd841b6982e 100644 --- a/lib/internal/perf/event_loop_delay.js +++ b/lib/internal/perf/event_loop_delay.js @@ -9,7 +9,7 @@ const { } = internalBinding('performance'); const { - validateInteger, + validateInt32, validateObject, } = require('internal/validators'); @@ -47,7 +47,7 @@ function monitorEventLoopDelay(options = {}) { validateObject(options, 'options'); const { resolution = 10 } = options; - validateInteger(resolution, 'options.resolution', 1); + validateInt32(resolution, 'options.resolution', 1); return new ELDHistogram(new _ELDHistogram(resolution)); } diff --git a/test/sequential/test-performance-eventloopdelay.js b/test/sequential/test-performance-eventloopdelay.js index b12d3a72341ee9..594fce4c007ded 100644 --- a/test/sequential/test-performance-eventloopdelay.js +++ b/test/sequential/test-performance-eventloopdelay.js @@ -39,7 +39,7 @@ const { sleep } = require('internal/util'); ); }); - [-1, 0, Infinity].forEach((i) => { + [-1, 0, 2**31, Infinity].forEach((i) => { assert.throws( () => monitorEventLoopDelay({ resolution: i }), { From 667cc36204d31f319f0d5e2583c47dbb590bcfed Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Fri, 9 Apr 2021 13:17:35 +0200 Subject: [PATCH 2/3] fixup! perf_hooks: fix loop delay resolution validation --- test/sequential/test-performance-eventloopdelay.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/sequential/test-performance-eventloopdelay.js b/test/sequential/test-performance-eventloopdelay.js index 594fce4c007ded..0c7df54cb94bf2 100644 --- a/test/sequential/test-performance-eventloopdelay.js +++ b/test/sequential/test-performance-eventloopdelay.js @@ -39,7 +39,7 @@ const { sleep } = require('internal/util'); ); }); - [-1, 0, 2**31, Infinity].forEach((i) => { + [-1, 0, 2 ** 31, Infinity].forEach((i) => { assert.throws( () => monitorEventLoopDelay({ resolution: i }), { From 602db5350113261ae3db757a0336ab8f6b08db3d Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Fri, 9 Apr 2021 15:53:01 +0200 Subject: [PATCH 3/3] fixup! perf_hooks: fix loop delay resolution validation --- lib/internal/perf/event_loop_delay.js | 4 ++-- src/node_perf.cc | 4 ++-- src/node_perf.h | 2 +- test/sequential/test-performance-eventloopdelay.js | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/internal/perf/event_loop_delay.js b/lib/internal/perf/event_loop_delay.js index 94dfd841b6982e..f90bb9e4de7d58 100644 --- a/lib/internal/perf/event_loop_delay.js +++ b/lib/internal/perf/event_loop_delay.js @@ -9,7 +9,7 @@ const { } = internalBinding('performance'); const { - validateInt32, + validateInteger, validateObject, } = require('internal/validators'); @@ -47,7 +47,7 @@ function monitorEventLoopDelay(options = {}) { validateObject(options, 'options'); const { resolution = 10 } = options; - validateInt32(resolution, 'options.resolution', 1); + validateInteger(resolution, 'options.resolution', 1); return new ELDHistogram(new _ELDHistogram(resolution)); } diff --git a/src/node_perf.cc b/src/node_perf.cc index 2d6341e01136fe..c1a0b2cf3a14d7 100644 --- a/src/node_perf.cc +++ b/src/node_perf.cc @@ -237,7 +237,7 @@ void LoopIdleTime(const FunctionCallbackInfo& args) { void ELDHistogram::New(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); CHECK(args.IsConstructCall()); - int32_t resolution = args[0].As()->Value(); + int64_t resolution = args[0].As()->Value(); CHECK_GT(resolution, 0); new ELDHistogram(env, args.This(), resolution); } @@ -253,7 +253,7 @@ void ELDHistogram::Initialize(Environment* env, Local target) { ELDHistogram::ELDHistogram( Environment* env, Local wrap, - int32_t interval) + int64_t interval) : IntervalHistogram( env, wrap, diff --git a/src/node_perf.h b/src/node_perf.h index d0f1d68462265c..33cf9f2ec651bf 100644 --- a/src/node_perf.h +++ b/src/node_perf.h @@ -166,7 +166,7 @@ class ELDHistogram : public IntervalHistogram { ELDHistogram( Environment* env, v8::Local wrap, - int32_t interval); + int64_t interval); void OnInterval() override; diff --git a/test/sequential/test-performance-eventloopdelay.js b/test/sequential/test-performance-eventloopdelay.js index 0c7df54cb94bf2..f262e9de3fe6cb 100644 --- a/test/sequential/test-performance-eventloopdelay.js +++ b/test/sequential/test-performance-eventloopdelay.js @@ -39,7 +39,7 @@ const { sleep } = require('internal/util'); ); }); - [-1, 0, 2 ** 31, Infinity].forEach((i) => { + [-1, 0, 2 ** 53, Infinity].forEach((i) => { assert.throws( () => monitorEventLoopDelay({ resolution: i }), {