UNPKG

1.64 kBJavaScriptView Raw
1var _debugger = require('./extern/_debugger');
2
3var Client = _debugger.Client;
4var Interface = _debugger.Interface;
5
6Client.prototype.setBreakpoint = function(target, line, callback) {
7 var req = {
8 command: 'setbreakpoint',
9 arguments: { type: 'script',
10 target: target,
11 line: line
12 }
13 };
14
15 this.req(req, function(res) {
16 if (callback) {
17 callback(res);
18 }
19 });
20};
21
22// Connect to the existing debug server instead of spawning one
23Interface.prototype.connect = function(port, delay, cb) {
24 var self = this;
25 port = port || _debugger.port;
26 delay = delay || 100;
27
28 setTimeout(function() {
29 var client = self.client = new Client();
30 client.connect(port);
31
32 client.once('ready', function() {
33 if (cb) {
34 cb(null, client);
35 }
36 });
37
38 client.on('close', function() {
39 self.client = null;
40 self.killChild();
41 self.term.close();
42 });
43
44 client.on('unhandledResponse', function(res) {
45 console.log('\r\nunhandled res:');
46 console.log(res);
47 });
48
49 client.on('error', function(err) {
50 console.log('error: ' + err);
51 });
52
53 client.on('break', function(res) {
54 self.handleBreak(res.body);
55 });
56 }, delay);
57};
58
59Interface.prototype._getScript = function(scriptName) {
60 var scripts, script;
61 scripts = this.client.scripts;
62
63 for (var key in scripts) {
64 if (scripts.hasOwnProperty(key)) {
65 script = scripts[key];
66
67 if (script && script.name.indexOf(scriptName) !== -1) {
68 return script;
69 }
70 }
71 }
72
73 return false;
74};
75
76exports.Client = Client;
77exports.Interface = Interface;