(script, line, condition, silent)
| 742 | } |
| 743 | |
| 744 | function setBreakpoint(script, line, condition, silent) { |
| 745 | function registerBreakpoint({ breakpointId, actualLocation }) { |
| 746 | handleBreakpointResolved({ breakpointId, location: actualLocation }); |
| 747 | if (actualLocation?.scriptId) { |
| 748 | if (!silent) return getSourceSnippet(actualLocation, 5); |
| 749 | } else { |
| 750 | print(`Warning: script '${script}' was not loaded yet.`); |
| 751 | } |
| 752 | return undefined; |
| 753 | } |
| 754 | |
| 755 | // setBreakpoint(): set breakpoint at current location |
| 756 | if (script === undefined) { |
| 757 | return PromisePrototypeThen( |
| 758 | Debugger.setBreakpoint({ location: getCurrentLocation(), condition }), |
| 759 | registerBreakpoint); |
| 760 | } |
| 761 | |
| 762 | // setBreakpoint(line): set breakpoint in current script at specific line |
| 763 | if (line === undefined && typeof script === 'number') { |
| 764 | const location = { |
| 765 | scriptId: getCurrentLocation().scriptId, |
| 766 | lineNumber: script - 1, |
| 767 | }; |
| 768 | return PromisePrototypeThen( |
| 769 | Debugger.setBreakpoint({ location, condition }), |
| 770 | registerBreakpoint); |
| 771 | } |
| 772 | |
| 773 | validateString(script, 'script'); |
| 774 | |
| 775 | // setBreakpoint('fn()'): Break when a function is called |
| 776 | if (StringPrototypeEndsWith(script, '()')) { |
| 777 | const debugExpr = `debug(${script.slice(0, -2)})`; |
| 778 | const debugCall = selectedFrame ? |
| 779 | Debugger.evaluateOnCallFrame({ |
| 780 | callFrameId: selectedFrame.callFrameId, |
| 781 | expression: debugExpr, |
| 782 | includeCommandLineAPI: true, |
| 783 | }) : |
| 784 | Runtime.evaluate({ |
| 785 | expression: debugExpr, |
| 786 | includeCommandLineAPI: true, |
| 787 | }); |
| 788 | return PromisePrototypeThen(debugCall, ({ result, wasThrown }) => { |
| 789 | if (wasThrown) return convertResultToError(result); |
| 790 | return undefined; // This breakpoint can't be removed the same way |
| 791 | }); |
| 792 | } |
| 793 | |
| 794 | // setBreakpoint('scriptname') |
| 795 | let scriptId = null; |
| 796 | let ambiguous = false; |
| 797 | if (knownScripts[script]) { |
| 798 | scriptId = script; |
| 799 | } else { |
| 800 | ArrayPrototypeForEach(ObjectKeys(knownScripts), (id) => { |
| 801 | const scriptUrl = knownScripts[id].url; |
no test coverage detected