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

Code before:
        // 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 (suggestion):
```suggestion
            // If the instance refers to a JSScript, remove all breakpoints set in this script at that offset.
```

I would also maybe add a note that there may be more than one breakpoint at the same offset with different handlers, but that we don't handle that case for now, and pointing to `clearBreakpoint` so we know where to look in the future.

Code after:
        // 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);
});