(oldScript, newScript)
| 667 | } |
| 668 | |
| 669 | function mergeCoverageScripts(oldScript, newScript) { |
| 670 | // Merge the functions from the new coverage into the functions from the |
| 671 | // existing (merged) coverage. |
| 672 | for (let i = 0; i < newScript.functions.length; ++i) { |
| 673 | const newFn = newScript.functions[i]; |
| 674 | let found = false; |
| 675 | |
| 676 | for (let j = 0; j < oldScript.functions.length; ++j) { |
| 677 | const oldFn = oldScript.functions[j]; |
| 678 | |
| 679 | if (newFn.functionName === oldFn.functionName && |
| 680 | newFn.ranges?.[0].startOffset === oldFn.ranges?.[0].startOffset && |
| 681 | newFn.ranges?.[0].endOffset === oldFn.ranges?.[0].endOffset) { |
| 682 | // These are the same functions. |
| 683 | found = true; |
| 684 | |
| 685 | // If newFn is block level coverage, then it will: |
| 686 | // - Replace oldFn if oldFn is not block level coverage. |
| 687 | // - Merge with oldFn if it is also block level coverage. |
| 688 | // If newFn is not block level coverage, then it has no new data. |
| 689 | if (newFn.isBlockCoverage) { |
| 690 | if (oldFn.isBlockCoverage) { |
| 691 | // Merge the oldFn ranges with the newFn ranges. |
| 692 | mergeCoverageRanges(oldFn, newFn); |
| 693 | } else { |
| 694 | // Replace oldFn with newFn. |
| 695 | oldFn.isBlockCoverage = true; |
| 696 | oldFn.ranges = newFn.ranges; |
| 697 | } |
| 698 | } |
| 699 | |
| 700 | break; |
| 701 | } |
| 702 | } |
| 703 | |
| 704 | if (!found) { |
| 705 | // This is a new function to track. This is possible because V8 can |
| 706 | // generate a different list of functions depending on which code paths |
| 707 | // are executed. For example, if a code path dynamically creates a |
| 708 | // function, but that code path is not executed then the function does |
| 709 | // not show up in the coverage report. Unfortunately, this also means |
| 710 | // that the function counts in the coverage summary can never be |
| 711 | // guaranteed to be 100% accurate. |
| 712 | ArrayPrototypePush(oldScript.functions, newFn); |
| 713 | } |
| 714 | } |
| 715 | } |
| 716 | |
| 717 | function mergeCoverageRanges(oldFn, newFn) { |
| 718 | const mergedRanges = new SafeSet(); |
no test coverage detected
searching dependent graphs…