// Copyright 2010 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. import type * as ProtocolProxyApi from '../../generated/protocol-proxy-api.js'; import * as Protocol from '../../generated/protocol.js'; import * as Common from '../common/common.js'; import * as i18n from '../i18n/i18n.js'; import type * as Platform from '../platform/platform.js'; import * as Root from '../root/root.js'; import type {PageResourceLoadInitiator} from './PageResourceLoader.js'; import {type GetPropertiesResult, type RemoteObject, RemoteObjectProperty, ScopeRef} from './RemoteObject.js'; import {Events as ResourceTreeModelEvents, ResourceTreeModel} from './ResourceTreeModel.js'; import {type EvaluationOptions, type EvaluationResult, type ExecutionContext, RuntimeModel} from './RuntimeModel.js'; import {Script} from './Script.js'; import {SDKModel} from './SDKModel.js'; import {SourceMap} from './SourceMap.js'; import {SourceMapManager} from './SourceMapManager.js'; import {Capability, type Target} from './Target.js'; const UIStrings = { /** * @description Title of a section in the debugger showing local JavaScript variables. */ local: 'Local', /** * @description Text that refers to closure as a programming term */ closure: 'Closure', /** * @description Noun that represents a section or block of code in the Debugger Model. Shown in the Sources tab, while paused on a breakpoint. */ block: 'Block', /** * @description Label for a group of JavaScript files */ script: 'Script', /** * @description Title of a section in the debugger showing JavaScript variables from the a 'with' *block. Block here means section of code, 'with' refers to a JavaScript programming concept and *is a fixed term. */ withBlock: '`With` block', /** * @description Title of a section in the debugger showing JavaScript variables from the a 'catch' *block. Block here means section of code, 'catch' refers to a JavaScript programming concept and *is a fixed term. */ catchBlock: '`Catch` block', /** * @description Title of a section in the debugger showing JavaScript variables from the global scope. */ global: 'Global', /** * @description Text for a JavaScript module, the programming concept */ module: 'Module', /** * @description Text describing the expression scope in WebAssembly */ expression: 'Expression', /** * @description Text in Scope Chain Sidebar Pane of the Sources panel */ exception: 'Exception', /** * @description Text in Scope Chain Sidebar Pane of the Sources panel */ returnValue: 'Return value', } as const; const str_ = i18n.i18n.registerUIStrings('core/sdk/DebuggerModel.ts', UIStrings); const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_); export function sortAndMergeRanges(locationRanges: Protocol.Debugger.LocationRange[]): Protocol.Debugger.LocationRange[] { function compare(p1: Protocol.Debugger.ScriptPosition, p2: Protocol.Debugger.ScriptPosition): number { return (p1.lineNumber - p2.lineNumber) || (p1.columnNumber - p2.columnNumber); } function overlap(r1: Protocol.Debugger.LocationRange, r2: Protocol.Debugger.LocationRange): boolean { if (r1.scriptId !== r2.scriptId) { return false; } const n = compare(r1.start, r2.start); if (n < 0) { return compare(r1.end, r2.start) >= 0; } if (n > 0) { return compare(r1.start, r2.end) <= 0; } return true; } if (locationRanges.length === 0) { return []; } locationRanges.sort((r1, r2) => { if (r1.scriptId < r2.scriptId) { return -1; } if (r1.scriptId > r2.scriptId) { return 1; } return compare(r1.start, r2.start) || compare(r1.end, r2.end); }); let prev = locationRanges[0]; const merged = []; for (let i = 1; i < locationRanges.length; ++i) { const curr = locationRanges[i]; if (overlap(prev, curr)) { if (compare(prev.end, curr.end) <= 0) { prev = {...prev, end: curr.end}; } } else { merged.push(prev); prev = curr; } } merged.push(prev); return merged; } export const enum StepMode { STEP_INTO = 'StepInto', STEP_OUT = 'StepOut', STEP_OVER = 'StepOver', } export const WASM_SYMBOLS_PRIORITY = [ Protocol.Debugger.DebugSymbolsType.ExternalDWARF, Protocol.Debugger.DebugSymbolsType.EmbeddedDWARF, Protocol.Debugger.DebugSymbolsType.SourceMap, ]; export class DebuggerModel extends SDKModel { readonly agent: ProtocolProxyApi.DebuggerApi; #runtimeModel: RuntimeModel; readonly #sourceMapManager: SourceMapManager