@@ -45,16 +45,18 @@ export interface ExecutionContext {
45
45
46
46
export type Script = { scriptId : string , hash : string , source : Source , thread : Thread } ;
47
47
48
- export interface ThreadConfiguration {
49
- supportsCustomBreakpoints ?: boolean ;
50
- defaultScriptOffset ?: InlineScriptOffset ;
51
- }
52
-
53
48
export interface ThreadManagerDelegate {
54
- copyToClipboard ( text : string ) : void ;
55
49
executionContextForest ( ) : ExecutionContext [ ] | undefined ;
56
- canStopThread ( thread : Thread ) : boolean ;
57
- stopThread ( thread : Thread ) : void ;
50
+ copyToClipboard : ( text : string ) => void ;
51
+ }
52
+
53
+ export interface ThreadDelegate {
54
+ canStopThread ( ) : boolean ;
55
+ stopThread ( ) : void ;
56
+
57
+ supportsCustomBreakpoints ?: boolean ;
58
+ defaultScriptOffset ?: InlineScriptOffset ;
59
+ sourcePathResolver : SourcePathResolver ;
58
60
}
59
61
60
62
export type ScriptWithSourceMapHandler = ( script : Script , sources : Source [ ] ) => Promise < void > ;
@@ -76,17 +78,15 @@ export class ThreadManager {
76
78
readonly onThreadResumed = this . _onThreadResumedEmitter . event ;
77
79
readonly onExecutionContextsChanged = this . _onExecutionContextsChangedEmitter . event ;
78
80
readonly sourceContainer : SourceContainer ;
79
- _sourcePathResolver : SourcePathResolver ;
80
81
_delegate : ThreadManagerDelegate ;
81
82
_scriptWithSourceMapHandler ?: ScriptWithSourceMapHandler ;
82
83
_consoleIsDirty = false ;
83
84
84
85
// url => (hash => Source)
85
86
private _scriptSources = new Map < string , Map < string , Source > > ( ) ;
86
87
87
- constructor ( dap : Dap . Api , sourcePathResolver : SourcePathResolver , sourceContainer : SourceContainer , delegate : ThreadManagerDelegate ) {
88
+ constructor ( dap : Dap . Api , sourceContainer : SourceContainer , delegate : ThreadManagerDelegate ) {
88
89
this . _dap = dap ;
89
- this . _sourcePathResolver = sourcePathResolver ;
90
90
this . _pauseOnExceptionsState = 'none' ;
91
91
this . _customBreakpoints = new Set ( ) ;
92
92
this . sourceContainer = sourceContainer ;
@@ -97,8 +97,8 @@ export class ThreadManager {
97
97
return this . _threads . values ( ) . next ( ) . value ;
98
98
}
99
99
100
- createThread ( threadId : string , cdp : Cdp . Api , configuration : ThreadConfiguration ) : Thread {
101
- return new Thread ( this , threadId , cdp , this . _dap , configuration ) ;
100
+ createThread ( threadId : string , cdp : Cdp . Api , delegate : ThreadDelegate ) : Thread {
101
+ return new Thread ( this , threadId , cdp , this . _dap , delegate ) ;
102
102
}
103
103
104
104
setScriptSourceMapHandler ( handler ?: ScriptWithSourceMapHandler ) {
@@ -208,27 +208,27 @@ export class Thread implements VariableStoreDelegate {
208
208
private _pausedVariables ?: VariableStore ;
209
209
private _pausedForSourceMapScriptId ?: string ;
210
210
private _scripts : Map < string , Script > = new Map ( ) ;
211
- private _supportsCustomBreakpoints : boolean ;
212
- private _defaultScriptOffset ?: InlineScriptOffset ;
211
+ private _delegate : ThreadDelegate ;
213
212
private _executionContexts : Map < number , Cdp . Runtime . ExecutionContextDescription > = new Map ( ) ;
214
213
readonly replVariables : VariableStore ;
215
214
readonly manager : ThreadManager ;
216
215
readonly sourceContainer : SourceContainer ;
216
+ readonly sourcePathResolver : SourcePathResolver ;
217
217
readonly threadLog = new ThreadLog ( ) ;
218
218
private _eventListeners : eventUtils . Listener [ ] = [ ] ;
219
219
private _supportsSourceMapPause = false ;
220
220
private _serializedOutput : Promise < void > ;
221
221
_debuggerId ?: Cdp . Runtime . UniqueDebuggerId ;
222
222
223
- constructor ( manager : ThreadManager , threadId : string , cdp : Cdp . Api , dap : Dap . Api , configuration : ThreadConfiguration ) {
223
+ constructor ( manager : ThreadManager , threadId : string , cdp : Cdp . Api , dap : Dap . Api , delegate : ThreadDelegate ) {
224
224
this . manager = manager ;
225
225
this . sourceContainer = manager . sourceContainer ;
226
+ this . sourcePathResolver = delegate . sourcePathResolver ;
226
227
this . _cdp = cdp ;
227
228
this . _dap = dap ;
228
229
this . _threadId = threadId ;
229
230
this . _name = '' ;
230
- this . _supportsCustomBreakpoints = configuration . supportsCustomBreakpoints || false ;
231
- this . _defaultScriptOffset = configuration . defaultScriptOffset ;
231
+ this . _delegate = delegate ;
232
232
this . replVariables = new VariableStore ( this . _cdp , this ) ;
233
233
this . manager . _addThread ( this ) ;
234
234
this . _serializedOutput = Promise . resolve ( ) ;
@@ -302,11 +302,11 @@ export class Thread implements VariableStoreDelegate {
302
302
}
303
303
304
304
canStop ( ) : boolean {
305
- return this . manager . _delegate . canStopThread ( this ) ;
305
+ return this . _delegate . canStopThread ( ) ;
306
306
}
307
307
308
308
stop ( ) {
309
- this . manager . _delegate . stopThread ( this ) ;
309
+ this . _delegate . stopThread ( ) ;
310
310
}
311
311
312
312
initialize ( ) {
@@ -482,10 +482,10 @@ export class Thread implements VariableStoreDelegate {
482
482
const script = rawLocation . scriptId ? this . _scripts . get ( rawLocation . scriptId ) : undefined ;
483
483
let { lineNumber, columnNumber} = rawLocation ;
484
484
columnNumber = columnNumber || 0 ;
485
- if ( this . _defaultScriptOffset ) {
486
- lineNumber -= this . _defaultScriptOffset . lineOffset ;
485
+ if ( this . _delegate . defaultScriptOffset ) {
486
+ lineNumber -= this . _delegate . defaultScriptOffset . lineOffset ;
487
487
if ( ! lineNumber )
488
- columnNumber = Math . max ( columnNumber - this . _defaultScriptOffset . columnOffset , 0 ) ;
488
+ columnNumber = Math . max ( columnNumber - this . _delegate . defaultScriptOffset . columnOffset , 0 ) ;
489
489
}
490
490
// Note: cdp locations are 0-based, while ui locations are 1-based.
491
491
return this . sourceContainer . preferredLocation ( {
@@ -509,7 +509,7 @@ export class Thread implements VariableStoreDelegate {
509
509
async updateCustomBreakpoint ( id : CustomBreakpointId , enabled : boolean ) : Promise < boolean > {
510
510
// Do not fail for custom breakpoints, to account for
511
511
// future changes in cdp vs stale breakpoints saved in the workspace.
512
- if ( ! this . _supportsCustomBreakpoints )
512
+ if ( ! this . _delegate . supportsCustomBreakpoints )
513
513
return true ;
514
514
const breakpoint = customBreakpoints ( ) . get ( id ) ;
515
515
if ( ! breakpoint )
@@ -703,7 +703,7 @@ export class Thread implements VariableStoreDelegate {
703
703
}
704
704
705
705
_onScriptParsed ( event : Cdp . Debugger . ScriptParsedEvent ) {
706
- event . url = this . manager . _sourcePathResolver . scriptUrlToUrl ( event . url ) ;
706
+ event . url = this . sourcePathResolver . scriptUrlToUrl ( event . url ) ;
707
707
708
708
let source : Source | undefined ;
709
709
if ( event . url && event . hash )
@@ -727,7 +727,7 @@ export class Thread implements VariableStoreDelegate {
727
727
errors . reportToConsole ( this . _dap , `Could not load source map from ${ event . sourceMapURL } ` ) ;
728
728
}
729
729
730
- source = this . sourceContainer . addSource ( event . url , contentGetter , resolvedSourceMapUrl , inlineSourceOffset , event . hash ) ;
730
+ source = this . sourceContainer . addSource ( this . sourcePathResolver , event . url , contentGetter , resolvedSourceMapUrl , inlineSourceOffset , event . hash ) ;
731
731
this . manager . _addSourceForScript ( event . url , event . hash , source ) ;
732
732
}
733
733
0 commit comments