From 07ed959422d379bfeac33a06ee96d5de68ff70c6 Mon Sep 17 00:00:00 2001 From: phosit Date: Fri, 30 May 2025 12:28:19 +0200 Subject: [PATCH] Remove IIFE in ReportDraw Since variables declared with `var` don't respect all scopes, when used in a loop it doesn't create a new variable each iteration. The initializer value is always assigned to the same variable. That makes problems when the variable is used in a callback. To work around that the variable is copied in to a IIFE. When not using `var` the iife isn't required. Ref: #7812 --- source/tools/profiler2/ReportDraw.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/source/tools/profiler2/ReportDraw.js b/source/tools/profiler2/ReportDraw.js index d8ee94932b..db5aaf6501 100644 --- a/source/tools/profiler2/ReportDraw.js +++ b/source/tools/profiler2/ReportDraw.js @@ -126,9 +126,9 @@ function display_frames(data, canvas, range) ctx.fillStyle = 'rgb(255, 255, 255)'; for (var i = 0; i < data.frames.length; ++i) { - var frame = data.frames[i]; + const frame = data.frames[i]; - var duration = frame.t1 - frame.t0; + const duration = frame.t1 - frame.t0; var x0 = xpadding + dx*(frame.t0 - tmin); var x1 = x0 + dx*duration; var y1 = canvas.height; @@ -141,7 +141,7 @@ function display_frames(data, canvas, range) canvas._tooltips.push({ 'x0': x0, 'x1': x1, 'y0': y0, 'y1': y1, - 'text': function(frame, duration) { return function() { + 'text': function() { var t = 'Frame
'; t += 'Length: ' + time_label(duration) + '
'; if (frame.attrs) @@ -152,7 +152,7 @@ function display_frames(data, canvas, range) }); } return t; - };} (frame, duration) + } }); } @@ -191,7 +191,7 @@ function display_events(data, canvas) for (var i = 0; i < data.events.length; ++i) { - var event = data.events[i]; + const event = data.events[i]; if (event.id == '__framestart') continue; @@ -218,7 +218,7 @@ function display_events(data, canvas) canvas._tooltips.push({ 'x0': x0, 'x1': x1, 'y0': y0, 'y1': y1, - 'text': function(event) { return function() { + 'text': function() { var t = '' + event.id + '
'; if (event.attrs) { @@ -227,7 +227,7 @@ function display_events(data, canvas) }); } return t; - };} (event) + } }); } @@ -304,7 +304,7 @@ function display_hierarchy(main_data, data, canvas, range, zoom) for (var i = 0; i < data.intervals.length; ++i) { - var interval = data.intervals[i]; + const interval = data.intervals[i]; if (interval.tmax <= tmin || interval.tmin > tmax) continue; @@ -339,7 +339,7 @@ function display_hierarchy(main_data, data, canvas, range, zoom) canvas._tooltips.push({ 'x0': x0, 'x1': x1, 'y0': y0, 'y1': y1, - 'text': function(interval) { return function() { + 'text': function() { var t = '' + interval.id + '
'; t += 'Length: ' + time_label(interval.duration) + '
'; if (interval.attrs) @@ -349,7 +349,7 @@ function display_hierarchy(main_data, data, canvas, range, zoom) }); } return t; - };} (interval) + } }); }