Repository: servo/servo
File: resources/debugger.js (JavaScript)

Code before:
    }
    setBreakpointRecursive(script);
});

// <https://firefox-source-docs.mozilla.org/js/Debugger/Debugger.Frame.html>
addEventListener("pause", event => {
    dbg.onEnterFrame = function(frame) {
        dbg.onEnterFrame = undefined;
        // TODO: Some properties throw if terminated is true
        // TODO: Check if start line / column is correct or we need the proper breakpoint
        let result = {
           // TODO: arguments: frame.arguments,
           column: frame.script.startColumn,
           displayName: frame.script.displayName,
           line: frame.script.startLine,
           onStack: frame.onStack,
           oldest: frame.older == null,
           terminated: frame.terminated,
           type_: frame.type,
           url: frame.script.url,
        };
        getFrameResult(event, result);
    };
});

// <https://firefox-source-docs.mozilla.org/js/Debugger/Debugger.Script.html#clearbreakpoint-handler-offset>
addEventListener("clearBreakpoint", event => {
    const {spidermonkeyId, scriptId, offset} = event;
    const script = sourceIdsToScripts.get(spidermonkeyId);

    function setClearBreakpointRecursive(script) {
        if (script.sourceStart == scriptId) {
            // <https://firefox-source-docs.mozilla.org/js/Debugger/Debugger.Script.html#clearallbreakpoints-offset>
            // If the instance refers to a JSScript, remove all breakpoints set in this script
            script.clearAllBreakpoints(offset);
            return;
        }
        for (const child of script.getChildScripts()) {
            setClearBreakpointRecursive(child);
        }
    }
    setClearBreakpointRecursive(script);
});


Review comment (refactor):
If we add the note below about breakpoints with different handlers I would move this link to that note instead of here.

Code after:
    }
    setBreakpointRecursive(script);
});

// <https://firefox-source-docs.mozilla.org/js/Debugger/Debugger.Frame.html>
addEventListener("pause", event => {
    dbg.onEnterFrame = function(frame) {
        dbg.onEnterFrame = undefined;
        // TODO: Some properties throw if terminated is true
        // TODO: Check if start line / column is correct or we need the proper breakpoint
        let result = {
           // TODO: arguments: frame.arguments,
           column: frame.script.startColumn,
           displayName: frame.script.displayName,
           line: frame.script.startLine,
           onStack: frame.onStack,
           oldest: frame.older == null,
           terminated: frame.terminated,
           type_: frame.type,
           url: frame.script.url,
        };
        getFrameResult(event, result);
    };
});

// <https://firefox-source-docs.mozilla.org/js/Debugger/Debugger.Script.html#clearbreakpoint-handler-offset>
// There may be more than one breakpoint at the same offset with different handlers, but we don’t handle that case for now.
addEventListener("clearBreakpoint", event => {
    const {spidermonkeyId, scriptId, offset} = event;
    const script = sourceIdsToScripts.get(spidermonkeyId);

    function setClearBreakpointRecursive(script) {
        if (script.sourceStart == scriptId) {
            // <https://firefox-source-docs.mozilla.org/js/Debugger/Debugger.Script.html#clearallbreakpoints-offset>
            // If the instance refers to a JSScript, remove all breakpoints set in this script at that offset.
            script.clearAllBreakpoints(offset);
            return;
        }
        for (const child of script.getChildScripts()) {
            setClearBreakpointRecursive(child);
        }
    }
    setClearBreakpointRecursive(script);
});