| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 5260f53 commit 121f74c
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -66,6 +66,7 @@ const { | |||
| 66 | 66 | const { inspect } = require('util'); | |
| 67 | 67 | ||
| 68 | 68 | const { now } = require('internal/perf/utils'); | |
| 69 | + const { convertToInt } = require('internal/webidl'); | ||
| 69 | 70 | ||
| 70 | 71 | const kDispatch = Symbol('kDispatch'); | |
| 71 | 72 | const kMaybeBuffer = Symbol('kMaybeBuffer'); | |
@@ -430,6 +431,8 @@ function bufferResourceTiming(entry) { | |||
| 430 | 431 | ||
| 431 | 432 | // https://w3c.github.io/resource-timing/#dom-performance-setresourcetimingbuffersize | |
| 432 | 433 | function setResourceTimingBufferSize(maxSize) { | |
| 434 | + // unsigned long | ||
| 435 | + maxSize = convertToInt('maxSize', maxSize, 32); | ||
| 433 | 436 | // If the maxSize parameter is less than resource timing buffer current | |
| 434 | 437 | // size, no PerformanceResourceTiming objects are to be removed from the | |
| 435 | 438 | // performance entry buffer. | |
| Original file line number | Diff line number | Diff 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); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,6 +30,17 @@ const initiatorType = ''; | |||
| 30 | 30 | const cacheMode = ''; | |
| 31 | 31 | ||
| 32 | 32 | 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 | + | ||
| 33 | 44 | performance.setResourceTimingBufferSize(1); | |
| 34 | 45 | performance.markResourceTiming(timingInfo, requestedUrl, initiatorType, globalThis, cacheMode); | |
| 35 | 46 | // Trigger a resourcetimingbufferfull event. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments