* Add the resource timing entry to the global buffer if the buffer size is not * exceeding the buffer limit, or dispatch a buffer full event on the global * performance object. * * See also https://www.w3.org/TR/resource-timing-2/#dfn-add-a-performanceresourcetiming-entry
(entry)
| 435 | * See also https://www.w3.org/TR/resource-timing-2/#dfn-add-a-performanceresourcetiming-entry |
| 436 | */ |
| 437 | function bufferResourceTiming(entry) { |
| 438 | if (resourceTimingBuffer.length < resourceTimingBufferSizeLimit && !resourceTimingBufferFullPending) { |
| 439 | ArrayPrototypePush(resourceTimingBuffer, entry); |
| 440 | return; |
| 441 | } |
| 442 | |
| 443 | if (!resourceTimingBufferFullPending) { |
| 444 | resourceTimingBufferFullPending = true; |
| 445 | setImmediate(() => { |
| 446 | while (resourceTimingSecondaryBuffer.length > 0) { |
| 447 | const excessNumberBefore = resourceTimingSecondaryBuffer.length; |
| 448 | dispatchBufferFull('resourcetimingbufferfull'); |
| 449 | |
| 450 | // Calculate the number of items to be pushed to the global buffer. |
| 451 | const numbersToPreserve = MathMax( |
| 452 | MathMin(resourceTimingBufferSizeLimit - resourceTimingBuffer.length, resourceTimingSecondaryBuffer.length), |
| 453 | 0, |
| 454 | ); |
| 455 | const excessNumberAfter = resourceTimingSecondaryBuffer.length - numbersToPreserve; |
| 456 | for (let idx = 0; idx < numbersToPreserve; idx++) { |
| 457 | ArrayPrototypePush(resourceTimingBuffer, resourceTimingSecondaryBuffer[idx]); |
| 458 | } |
| 459 | |
| 460 | if (excessNumberBefore <= excessNumberAfter) { |
| 461 | resourceTimingSecondaryBuffer = []; |
| 462 | } |
| 463 | } |
| 464 | resourceTimingBufferFullPending = false; |
| 465 | }); |
| 466 | } |
| 467 | |
| 468 | ArrayPrototypePush(resourceTimingSecondaryBuffer, entry); |
| 469 | } |
| 470 | |
| 471 | // https://w3c.github.io/resource-timing/#dom-performance-setresourcetimingbuffersize |
| 472 | function setResourceTimingBufferSize(maxSize) { |
no test coverage detected