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

Code before:
    evalResult(event, resultValue);
});

addEventListener("getPossibleBreakpoints", event => {
    const {spidermonkeyId} = event;
    const script = sourceIdsToScripts.get(spidermonkeyId);
    const result = [];
    walkScriptTree(script, (currentScript) => {
        for (const location of currentScript.getPossibleBreakpoints()) {
            location["scriptId"] = currentScript.sourceStart;
            result.push(location);
        }
    });
    getPossibleBreakpointsResult(event, result);
});

function handlePauseFrame(frame, is_breakpoint) {
    // Get the pipeline ID for this debuggee
    const pipelineId = debuggeesToPipelineIds.get(frame.script.global);
    if (!pipelineId) {
        console.error("[debugger] No pipeline ID for frame's global");
        return undefined;
    }

    // TODO: Some properties throw if terminated is true
    // TODO: Check if start line / column is correct or we need the proper breakpoint
    const 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,
    };

    // Notify devtools and enter pause loop. This blocks until Resume.
    pauseFrame(pipelineId, result, is_breakpoint);

    // <https://firefox-source-docs.mozilla.org/js/Debugger/Conventions.html#resumption-values>
    // Return undefined to continue execution normally after resume.
    return undefined;
}

addEventListener("setBreakpoint", event => {
    const {spidermonkeyId, scriptId, offset} = event;
    const script = sourceIdsToScripts.get(spidermonkeyId);
    const target = findScriptById(script, scriptId);
    if (target) {

Review comment (bug):
let's remove this comment, it's not entirely valid for debugger.js. we mostly handle this on devtools side

Code after:
    evalResult(event, resultValue);
});

addEventListener("getPossibleBreakpoints", event => {
    const {spidermonkeyId} = event;
    const script = sourceIdsToScripts.get(spidermonkeyId);
    const result = [];
    walkScriptTree(script, (currentScript) => {
        for (const location of currentScript.getPossibleBreakpoints()) {
            location["scriptId"] = currentScript.sourceStart;
            result.push(location);
        }
    });
    getPossibleBreakpointsResult(event, result);
});

function handlePauseAndRespond(frame, is_breakpoint) {
    // Get the pipeline ID for this debuggee
    const pipelineId = debuggeesToPipelineIds.get(frame.script.global);
    if (!pipelineId) {
        console.error("[debugger] No pipeline ID for frame's global");
        return undefined;
    }

    // TODO: Some properties throw if terminated is true
    const 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,
    };

    // Notify devtools and enter pause loop. This blocks until Resume.
    pauseAndRespond(pipelineId, result, is_breakpoint);

    // <https://firefox-source-docs.mozilla.org/js/Debugger/Conventions.html#resumption-values>
    // Return undefined to continue execution normally after resume.
    return undefined;
}

addEventListener("setBreakpoint", event => {
    const {spidermonkeyId, scriptId, offset} = event;
    const script = sourceIdsToScripts.get(spidermonkeyId);
    const target = findScriptById(script, scriptId);
    if (target) {
        target.setBreakpoint(offset, {