1
1
import * as http from 'http' ;
2
- import { EventEmitter } from 'events' ;
3
- import { Services } from '../../services/debugAdapterServices' ;
2
+ import { EventEmitter } from 'events' ;
3
+ import { Services } from '../../services/debugAdapterServices' ;
4
4
import * as Net from 'net' ;
5
5
import { INSDebugConnection } from './INSDebugConnection' ;
6
6
7
+ import { ChromeConnection } from 'vscode-chrome-debug-core' ;
8
+
7
9
8
10
interface IMessageWithId {
9
11
id : number ;
@@ -17,7 +19,7 @@ class Callbacks {
17
19
18
20
public wrap ( callback : any ) : number {
19
21
var callbackId = this . lastId ++ ;
20
- this . callbacks [ callbackId ] = callback || function ( ) { } ;
22
+ this . callbacks [ callbackId ] = callback || function ( ) { } ;
21
23
return callbackId ;
22
24
}
23
25
@@ -60,15 +62,15 @@ class ResReqNetSocket extends EventEmitter {
60
62
return new Promise < void > ( ( resolve , reject ) => {
61
63
62
64
that . conn = Net . createConnection ( port , url ) ,
63
- that . conn . setEncoding ( 'utf8' ) ;
65
+ that . conn . setEncoding ( 'utf8' ) ;
64
66
65
67
setTimeout ( ( ) => {
66
68
reject ( 'Connection timed out' )
67
69
} , timeout ) ;
68
70
69
71
that . conn . on ( 'error' , reject ) ;
70
72
71
- that . conn . on ( 'connect' , function ( ) {
73
+ that . conn . on ( 'connect' , function ( ) {
72
74
// Replace the promise-rejecting handler
73
75
that . conn . removeListener ( 'error' , reject ) ;
74
76
@@ -89,23 +91,22 @@ class ResReqNetSocket extends EventEmitter {
89
91
that . emit ( 'error' , e ) ;
90
92
} ) ;
91
93
92
- that . conn . on ( 'data' , function ( data ) {
94
+ that . conn . on ( 'data' , function ( data ) {
93
95
that . debugBuffer += data ;
94
- that . parse ( function ( ) {
95
- that . connected = true ;
96
- that . emit ( 'connect' ) ;
97
- resolve ( ) ;
96
+ that . parse ( function ( ) {
97
+ that . connected = true ;
98
+ that . emit ( 'connect' ) ;
99
+ resolve ( ) ;
98
100
} ) ;
99
101
} ) ;
100
102
101
103
102
- that . conn . on ( 'end' , function ( ) {
104
+ that . conn . on ( 'end' , function ( ) {
103
105
that . close ( ) ;
104
106
} ) ;
105
107
106
- that . conn . on ( 'close' , function ( ) {
107
- if ( ! that . connected )
108
- {
108
+ that . conn . on ( 'close' , function ( ) {
109
+ if ( ! that . connected ) {
109
110
reject ( "Can't connect. Check the application is running on the device" ) ;
110
111
that . emit ( 'close' , that . lastError || 'Debugged process exited.' ) ;
111
112
return ;
@@ -184,7 +185,7 @@ class ResReqNetSocket extends EventEmitter {
184
185
Services . logger ( ) . log ( 'To target: ' + data ) ;
185
186
this . conn . write ( 'Content-Length: ' + data . length + '\r\n\r\n' + data ) ;
186
187
this . hasNewDataMessage = true ;
187
- if ( ! this . isMessageFlushLoopStarted ) {
188
+ if ( ! this . isMessageFlushLoopStarted ) {
188
189
this . isMessageFlushLoopStarted = true ;
189
190
setInterval ( ( ) => {
190
191
if ( this . hasNewDataMessage ) {
@@ -209,13 +210,17 @@ class ResReqNetSocket extends EventEmitter {
209
210
}
210
211
211
212
if ( params ) {
212
- Object . keys ( params ) . forEach ( function ( key ) {
213
+ Object . keys ( params ) . forEach ( function ( key ) {
213
214
msg [ key ] = params [ key ] ;
214
215
} ) ;
215
216
}
216
217
this . send ( JSON . stringify ( msg ) ) ;
217
218
}
218
219
220
+ public sendMessage ( message : any ) {
221
+ this . send ( message ) ;
222
+ }
223
+
219
224
public close ( ) {
220
225
if ( this . conn ) {
221
226
this . conn . end ( ) ;
@@ -235,7 +240,7 @@ export class AndroidConnection implements INSDebugConnection {
235
240
let that = this ;
236
241
this . _socket = new ResReqNetSocket ( ) ;
237
242
238
- this . _socket . on ( "afterCompile" , function ( params ) {
243
+ this . _socket . on ( "afterCompile" , function ( params ) {
239
244
240
245
let scriptData = < WebKitProtocol . Debugger . Script > {
241
246
scriptId : String ( params . body . script . id ) ,
@@ -248,15 +253,15 @@ export class AndroidConnection implements INSDebugConnection {
248
253
} ) ;
249
254
250
255
251
- this . _socket . on ( "break" , function ( params ) {
256
+ this . _socket . on ( "break" , function ( params ) {
252
257
that . handleBreakEvent ( params ) ;
253
258
} ) ;
254
259
255
- this . _socket . on ( "exception" , function ( params ) {
260
+ this . _socket . on ( "exception" , function ( params ) {
256
261
that . handleBreakEvent ( params ) ;
257
262
} ) ;
258
263
259
- this . _socket . on ( "messageAdded" , function ( params ) {
264
+ this . _socket . on ( "messageAdded" , function ( params ) {
260
265
that . _socket . emit ( "Console.messageAdded" , params . body ) ;
261
266
} ) ;
262
267
}
@@ -342,7 +347,7 @@ export class AndroidConnection implements INSDebugConnection {
342
347
if ( name && name . length > 1 ) {
343
348
desc = name [ 1 ] ;
344
349
if ( desc === 'Array' || desc === 'Buffer' ) {
345
- size = ref . properties . filter ( function ( p ) { return / ^ \d + $ / . test ( p . name ) ; } ) . length ;
350
+ size = ref . properties . filter ( function ( p ) { return / ^ \d + $ / . test ( p . name ) ; } ) . length ;
346
351
desc += '[' + size + ']' ;
347
352
}
348
353
} else if ( ref . className === 'Date' ) {
@@ -400,8 +405,8 @@ export class AndroidConnection implements INSDebugConnection {
400
405
} )
401
406
. then ( response => {
402
407
var debuggerFrames = < Array < any > > response . frames || [ ] ;
403
- let frames = debuggerFrames . map ( function ( frame ) {
404
- var scopeChain = frame . scopes . map ( function ( scope ) {
408
+ let frames = debuggerFrames . map ( function ( frame ) {
409
+ var scopeChain = frame . scopes . map ( function ( scope ) {
405
410
return {
406
411
object : {
407
412
type : 'object' ,
@@ -481,7 +486,7 @@ export class AndroidConnection implements INSDebugConnection {
481
486
482
487
return this . request ( "clearbreakpoint" , {
483
488
breakpoint : breakpointId
484
- } )
489
+ } )
485
490
. then ( response => {
486
491
return < WebKitProtocol . Response > { } ;
487
492
} ) ;
@@ -568,9 +573,9 @@ export class AndroidConnection implements INSDebugConnection {
568
573
let that = this ;
569
574
return this . request ( "evaluate" , requestParams ) . then ( response => {
570
575
return < WebKitProtocol . Debugger . EvaluateOnCallFrameResponse > {
571
- result : {
572
- result : that . v8ResultToInspectorResult ( response ) ,
573
- wasThrown : false
576
+ result : {
577
+ result : that . v8ResultToInspectorResult ( response ) ,
578
+ wasThrown : false
574
579
}
575
580
}
576
581
} ) ;
@@ -615,12 +620,10 @@ export class AndroidConnection implements INSDebugConnection {
615
620
}
616
621
617
622
let source = undefined ;
618
- if ( Array . isArray ( response ) )
619
- {
623
+ if ( Array . isArray ( response ) ) {
620
624
source = response [ 0 ] . source ;
621
625
}
622
- else if ( response . result )
623
- {
626
+ else if ( response . result ) {
624
627
source = response . result [ 0 ] . source ;
625
628
}
626
629
else if ( response . source ) {
@@ -653,7 +656,7 @@ export class AndroidConnection implements INSDebugConnection {
653
656
if ( response . refs ) {
654
657
655
658
let refsLookup = { } ;
656
- response . refs . forEach ( function ( r ) { refsLookup [ r . handle ] = r ; } ) ;
659
+ response . refs . forEach ( function ( r ) { refsLookup [ r . handle ] = r ; } ) ;
657
660
658
661
//TODO: response.body may be undefined in that case set it to {} here
659
662
response . body . refsLookup = refsLookup ;
@@ -748,7 +751,7 @@ export class AndroidConnection implements INSDebugConnection {
748
751
props = obj . properties ;
749
752
750
753
if ( props ) {
751
- props = props . map ( function ( p ) {
754
+ props = props . map ( function ( p ) {
752
755
var ref = response . refsLookup [ p . ref ] ;
753
756
return {
754
757
name : String ( p . name ) ,
@@ -776,13 +779,13 @@ export class AndroidConnection implements INSDebugConnection {
776
779
throw new Error ( "Not implemented" ) ;
777
780
}
778
781
779
- // private sendMessage(method: any, params?: any): Promise<WebKitProtocol.Response> {
780
- // return this._socket.sendMessage({
781
- // id: this._nextId++,
782
- // method,
783
- // params
784
- // });
785
- // }
782
+ private sendMessage ( method : any , params ?: any ) : Promise < WebKitProtocol . Response > {
783
+ return this . _socket . sendMessage ( {
784
+ id : this . _nextId ++ ,
785
+ method,
786
+ params
787
+ } ) ;
788
+ }
786
789
}
787
790
788
791
/**
0 commit comments