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 121f74c

Browse filesBrowse files
legendecasruyadorno
authored andcommitted
perf_hooks: convert maxSize to IDL value in setResourceTimingBufferSize
ECMAScript values of WebIDL interface parameters should be converted to IDL representatives before the actual implementation, as defined in step 11.5 of the WebIDL Overload resolution algorithm. Backport-PR-URL: #45829 Refs: https://webidl.spec.whatwg.org/#dfn-create-operation-function Refs: https://webidl.spec.whatwg.org/#es-overloads PR-URL: #44902 Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 5260f53 commit 121f74c
Copy full SHA for 121f74c

File tree

Expand file treeCollapse file tree

3 files changed

+72
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+72
-0
lines changed
Open diff view settings
Collapse file

‎lib/internal/perf/observe.js‎

Copy file name to clipboardExpand all lines: lib/internal/perf/observe.js
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ const {
6666
const { inspect } = require('util');
6767

6868
const { now } = require('internal/perf/utils');
69+
const { convertToInt } = require('internal/webidl');
6970

7071
const kDispatch = Symbol('kDispatch');
7172
const kMaybeBuffer = Symbol('kMaybeBuffer');
@@ -430,6 +431,8 @@ function bufferResourceTiming(entry) {
430431

431432
// https://w3c.github.io/resource-timing/#dom-performance-setresourcetimingbuffersize
432433
function setResourceTimingBufferSize(maxSize) {
434+
// unsigned long
435+
maxSize = convertToInt('maxSize', maxSize, 32);
433436
// If the maxSize parameter is less than resource timing buffer current
434437
// size, no PerformanceResourceTiming objects are to be removed from the
435438
// performance entry buffer.
Collapse file
+58Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Flags: --expose-internals
2+
'use strict';
3+
4+
require('../common');
5+
const assert = require('assert');
6+
const { convertToInt, evenRound } = require('internal/webidl');
7+
8+
assert.strictEqual(evenRound(-0.5), 0);
9+
assert.strictEqual(evenRound(0.5), 0);
10+
assert.strictEqual(evenRound(-1.5), -2);
11+
assert.strictEqual(evenRound(1.5), 2);
12+
assert.strictEqual(evenRound(3.4), 3);
13+
assert.strictEqual(evenRound(4.6), 5);
14+
assert.strictEqual(evenRound(5), 5);
15+
assert.strictEqual(evenRound(6), 6);
16+
17+
// https://webidl.spec.whatwg.org/#abstract-opdef-converttoint
18+
assert.strictEqual(convertToInt('x', 0, 64), 0);
19+
assert.strictEqual(convertToInt('x', 1, 64), 1);
20+
assert.strictEqual(convertToInt('x', -0.5, 64), 0);
21+
assert.strictEqual(convertToInt('x', -0.5, 64, { signed: true }), 0);
22+
assert.strictEqual(convertToInt('x', -1.5, 64, { signed: true }), -1);
23+
24+
// EnforceRange
25+
const OutOfRangeValues = [ NaN, Infinity, -Infinity, 2 ** 53, -(2 ** 53) ];
26+
for (const value of OutOfRangeValues) {
27+
assert.throws(() => convertToInt('x', value, 64, { enforceRange: true }), {
28+
name: 'TypeError',
29+
code: 'ERR_INVALID_ARG_VALUE',
30+
});
31+
}
32+
33+
// Out of range: clamp
34+
assert.strictEqual(convertToInt('x', NaN, 64, { clamp: true }), 0);
35+
assert.strictEqual(convertToInt('x', Infinity, 64, { clamp: true }), Number.MAX_SAFE_INTEGER);
36+
assert.strictEqual(convertToInt('x', -Infinity, 64, { clamp: true }), 0);
37+
assert.strictEqual(convertToInt('x', -Infinity, 64, { signed: true, clamp: true }), Number.MIN_SAFE_INTEGER);
38+
assert.strictEqual(convertToInt('x', 0x1_0000_0000, 32, { clamp: true }), 0xFFFF_FFFF);
39+
assert.strictEqual(convertToInt('x', 0xFFFF_FFFF, 32, { clamp: true }), 0xFFFF_FFFF);
40+
assert.strictEqual(convertToInt('x', 0x8000_0000, 32, { clamp: true, signed: true }), 0x7FFF_FFFF);
41+
assert.strictEqual(convertToInt('x', 0xFFFF_FFFF, 32, { clamp: true, signed: true }), 0x7FFF_FFFF);
42+
assert.strictEqual(convertToInt('x', 0.5, 64, { clamp: true }), 0);
43+
assert.strictEqual(convertToInt('x', 1.5, 64, { clamp: true }), 2);
44+
assert.strictEqual(convertToInt('x', -0.5, 64, { clamp: true }), 0);
45+
assert.strictEqual(convertToInt('x', -0.5, 64, { signed: true, clamp: true }), 0);
46+
assert.strictEqual(convertToInt('x', -1.5, 64, { signed: true, clamp: true }), -2);
47+
48+
// Out of range, step 8.
49+
assert.strictEqual(convertToInt('x', NaN, 64), 0);
50+
assert.strictEqual(convertToInt('x', Infinity, 64), 0);
51+
assert.strictEqual(convertToInt('x', -Infinity, 64), 0);
52+
assert.strictEqual(convertToInt('x', 0x1_0000_0000, 32), 0);
53+
assert.strictEqual(convertToInt('x', 0x1_0000_0001, 32), 1);
54+
assert.strictEqual(convertToInt('x', 0xFFFF_FFFF, 32), 0xFFFF_FFFF);
55+
56+
// Out of range, step 11.
57+
assert.strictEqual(convertToInt('x', 0x8000_0000, 32, { signed: true }), -0x8000_0000);
58+
assert.strictEqual(convertToInt('x', 0xFFF_FFFF, 32, { signed: true }), 0xFFF_FFFF);
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-performance-resourcetimingbuffersize.js
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ const initiatorType = '';
3030
const cacheMode = '';
3131

3232
async function main() {
33+
// Invalid buffer size values are converted to 0.
34+
const invalidValues = [ null, undefined, true, false, -1, 0.5, Infinity, NaN, '', 'foo', {}, [], () => {} ];
35+
for (const value of invalidValues) {
36+
performance.setResourceTimingBufferSize(value);
37+
performance.markResourceTiming(timingInfo, requestedUrl, initiatorType, globalThis, cacheMode);
38+
assert.strictEqual(performance.getEntriesByType('resource').length, 0);
39+
performance.clearResourceTimings();
40+
}
41+
// Wait for the buffer full event to be cleared.
42+
await waitBufferFullEvent();
43+
3344
performance.setResourceTimingBufferSize(1);
3445
performance.markResourceTiming(timingInfo, requestedUrl, initiatorType, globalThis, cacheMode);
3546
// Trigger a resourcetimingbufferfull event.

0 commit comments

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