This repository was archived by the owner on Dec 21, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathDebugger.js
More file actions
164 lines (137 loc) · 4.73 KB
/
Copy pathDebugger.js
File metadata and controls
164 lines (137 loc) · 4.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
* Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
define(function (require, exports) {
'use strict';
var Inspector = brackets.getModule('LiveDevelopment/Inspector/Inspector'),
ScriptAgent = brackets.getModule('LiveDevelopment/Agents/ScriptAgent');
var Breakpoint = require('Breakpoint');
var $exports = $(exports);
var _paused;
/** Actions **************************************************************/
// pause the debugger
function pause() {
// if there is no pause before the next reload, press pause again
Inspector.Debugger.pause();
}
// resume the debugger
function resume() {
Inspector.Debugger.resume();
}
// step over the current line
function stepOver() {
Inspector.Debugger.stepOver();
}
// step into the function at the current line
function stepInto() {
Inspector.Debugger.stepInto();
}
// step out
function stepOut() {
Inspector.Debugger.stepOut();
}
// toggle a breakpoint
function toggleBreakpoint(location) {
var breakpoint = Breakpoint.find(location);
if (!breakpoint) {
breakpoint = new Breakpoint.Breakpoint(location);
$(breakpoint)
.on('resolve', _onResolveBreakpoint)
.on('remove', _onRemoveBreakpoint);
}
breakpoint.toggle();
return breakpoint;
}
// evaluate an expression in the active call frame
function evaluate(expression, callback) {
if (_paused) {
Inspector.Debugger.evaluateOnCallFrame(_paused.callFrames[0].callFrameId, expression, callback);
} else {
Inspector.Runtime.evaluate(expression, callback);
}
}
/** Event Handlers *******************************************************/
// WebInspector Event: Debugger.paused
function _onPaused(event, res) {
// res = {callFrames, reason, data}
// ignore DOM breakpoints - they are handled by the ScriptAgent
if (res.reason === 'DOM') {
return;
}
// gather some info about this pause
_paused = { location: res.callFrames[0].location, callFrames: res.callFrames };
// trigger the 'paused' event
$exports.triggerHandler('paused', _paused);
}
// WebInspector Event: Debugger.resumed
function _onResumed() {
// res = {}
// send the 'resumed' event with the info from the pause
if (_paused) {
$exports.triggerHandler('resumed', _paused);
_paused = undefined;
}
}
// Breakpoint Event: breakpoint resolved
function _onResolveBreakpoint(event, breakpoint, location) {
location.url = ScriptAgent.scriptWithId(location.scriptId).url;
$exports.triggerHandler('setBreakpoint', location);
}
// Breakpoint Event: breakpoint removed
function _onRemoveBreakpoint(event, breakpoint) {
breakpoint.resolvedLocations.forEach(function (location) {
location.url = ScriptAgent.scriptWithId(location.scriptId).url;
$exports.triggerHandler('removeBreakpoint', location);
});
}
// Inspector Event: we are connected to a live session
function _onConnect() {
Inspector.Debugger.enable();
}
// Inspector Event: we are disconnected
function _onDisconnect() {
}
/** Init Functions *******************************************************/
// init
function init() {
$(Inspector).on('connect.debugger', _onConnect);
$(Inspector).on('disconnect.debugger', _onDisconnect);
$(Inspector.Debugger).on('paused.debugger', _onPaused);
$(Inspector.Debugger).on('resumed.debugger', _onResumed);
}
function unload() {
$(Inspector).off('.debugger');
$(Inspector.Debugger).off('.debugger');
$exports.off();
_onDisconnect();
}
// public methods
exports.init = init;
exports.unload = unload;
exports.pause = pause;
exports.resume = resume;
exports.stepOver = stepOver;
exports.stepInto = stepInto;
exports.stepOut = stepOut;
exports.toggleBreakpoint = toggleBreakpoint;
exports.evaluate = evaluate;
});