2 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 WebInspector.DebuggerModel = function()
33 this._breakpoints = {};
34 InspectorBackend.registerDomainDispatcher("Debugger", this);
37 WebInspector.DebuggerModel.prototype = {
38 setOneTimeBreakpoint: function(sourceID, line)
40 var breakpoint = new WebInspector.Breakpoint(this, sourceID, undefined, line, true, undefined);
41 if (this._breakpoints[breakpoint.id])
43 if (this._oneTimeBreakpoint)
44 InspectorBackend.removeBreakpoint(this._oneTimeBreakpoint.sourceID, this._oneTimeBreakpoint.line);
45 this._oneTimeBreakpoint = breakpoint;
46 // FIXME(40669): one time breakpoint will be persisted in inspector settings if not hit.
47 this._setBreakpointOnBackend(breakpoint, true);
50 removeOneTimeBreakpoint: function()
52 if (this._oneTimeBreakpoint) {
53 InspectorBackend.removeBreakpoint(this._oneTimeBreakpoint.sourceID, this._oneTimeBreakpoint.line);
54 delete this._oneTimeBreakpoint;
58 setBreakpoint: function(sourceID, url, line, enabled, condition)
60 var breakpoint = this._setBreakpoint(sourceID, url, line, enabled, condition);
62 this._setBreakpointOnBackend(breakpoint);
65 breakpointRestored: function(sourceID, url, line, enabled, condition)
67 this._setBreakpoint(sourceID, url, line, enabled, condition);
70 queryBreakpoints: function(filter)
73 for (var id in this._breakpoints) {
74 var breakpoint = this._breakpoints[id];
75 if (filter(breakpoint))
76 breakpoints.push(breakpoint);
81 findBreakpoint: function(sourceID, lineNumber)
83 var breakpointId = WebInspector.Breakpoint.jsBreakpointId(sourceID, lineNumber);
84 return this._breakpoints[breakpointId];
89 this._breakpoints = {};
90 delete this._oneTimeBreakpoint;
93 _setBreakpoint: function(sourceID, url, line, enabled, condition)
95 var breakpoint = new WebInspector.Breakpoint(this, sourceID, url, line, enabled, condition);
96 if (this._breakpoints[breakpoint.id])
98 if (this._oneTimeBreakpoint && (this._oneTimeBreakpoint.id == breakpoint.id))
99 delete this._oneTimeBreakpoint;
100 this._breakpoints[breakpoint.id] = breakpoint;
101 breakpoint.addEventListener("removed", this._breakpointRemoved, this);
102 this.dispatchEventToListeners("breakpoint-added", breakpoint);
106 _breakpointRemoved: function(event)
108 delete this._breakpoints[event.target.id];
111 _setBreakpointOnBackend: function(breakpoint, isOneTime)
113 function didSetBreakpoint(success, line)
115 if (success && line == breakpoint.line)
119 this._oneTimeBreakpoint.line = line;
121 delete this._oneTimeBreakpoint;
125 this._setBreakpoint(breakpoint.sourceID, breakpoint.url, line, breakpoint.enabled, breakpoint.condition);
128 InspectorBackend.setBreakpoint(breakpoint.sourceID, breakpoint.line, breakpoint.enabled, breakpoint.condition, didSetBreakpoint.bind(this));
131 pausedScript: function(details)
133 this.dispatchEventToListeners("debugger-paused", details.callFrames);
135 if (details.eventType === WebInspector.DebuggerEventTypes.JavaScriptPause)
137 if (details.eventType === WebInspector.DebuggerEventTypes.NativeBreakpoint) {
138 this.dispatchEventToListeners("native-breakpoint-hit", details.eventData);
142 var breakpointId = WebInspector.Breakpoint.jsBreakpointId(details.callFrames[0].sourceID, details.callFrames[0].line);
143 var breakpoint = this._breakpoints[breakpointId];
146 breakpoint.hit = true;
147 this._lastHitBreakpoint = breakpoint;
148 this.dispatchEventToListeners("script-breakpoint-hit", breakpoint);
151 resumedScript: function()
153 this.dispatchEventToListeners("debugger-resumed");
155 if (!this._lastHitBreakpoint)
157 this._lastHitBreakpoint.hit = false;
158 delete this._lastHitBreakpoint;
161 attachDebuggerWhenShown: function()
163 WebInspector.panels.scripts.attachDebuggerWhenShown();
166 debuggerWasEnabled: function()
168 WebInspector.panels.scripts.debuggerWasEnabled();
171 debuggerWasDisabled: function()
173 WebInspector.panels.scripts.debuggerWasDisabled();
176 parsedScriptSource: function(sourceID, sourceURL, source, startingLine, scriptWorldType)
178 WebInspector.panels.scripts.addScript(sourceID, sourceURL, source, startingLine, undefined, undefined, scriptWorldType);
181 failedToParseScriptSource: function(sourceURL, source, startingLine, errorLine, errorMessage)
183 WebInspector.panels.scripts.addScript(null, sourceURL, source, startingLine, errorLine, errorMessage);
186 didCreateWorker: function()
188 var workersPane = WebInspector.panels.scripts.sidebarPanes.workers;
189 workersPane.addWorker.apply(workersPane, arguments);
192 didDestroyWorker: function()
194 var workersPane = WebInspector.panels.scripts.sidebarPanes.workers;
195 workersPane.removeWorker.apply(workersPane, arguments);
199 WebInspector.DebuggerModel.prototype.__proto__ = WebInspector.Object.prototype;
201 WebInspector.DebuggerEventTypes = {
203 JavaScriptBreakpoint: 1,