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 = {};
36 WebInspector.DebuggerModel.prototype = {
37 setOneTimeBreakpoint: function(sourceID, line)
39 var breakpoint = new WebInspector.Breakpoint(this, sourceID, undefined, line, true, undefined);
40 if (this._breakpoints[breakpoint.id])
42 if (this._oneTimeBreakpoint)
43 InspectorBackend.removeBreakpoint(this._oneTimeBreakpoint.sourceID, this._oneTimeBreakpoint.line);
44 this._oneTimeBreakpoint = breakpoint;
45 // FIXME(40669): one time breakpoint will be persisted in inspector settings if not hit.
46 this._setBreakpointOnBackend(breakpoint, true);
49 removeOneTimeBreakpoint: function()
51 if (this._oneTimeBreakpoint) {
52 InspectorBackend.removeBreakpoint(this._oneTimeBreakpoint.sourceID, this._oneTimeBreakpoint.line);
53 delete this._oneTimeBreakpoint;
57 setBreakpoint: function(sourceID, url, line, enabled, condition)
59 var breakpoint = this._setBreakpoint(sourceID, url, line, enabled, condition);
61 this._setBreakpointOnBackend(breakpoint);
64 breakpointRestored: function(sourceID, url, line, enabled, condition)
66 this._setBreakpoint(sourceID, url, line, enabled, condition);
69 queryBreakpoints: function(filter)
72 for (var id in this._breakpoints) {
73 var breakpoint = this._breakpoints[id];
74 if (filter(breakpoint))
75 breakpoints.push(breakpoint);
80 findBreakpoint: function(sourceID, lineNumber)
82 var breakpointId = WebInspector.Breakpoint.jsBreakpointId(sourceID, lineNumber);
83 return this._breakpoints[breakpointId];
88 this._breakpoints = {};
89 delete this._oneTimeBreakpoint;
92 _setBreakpoint: function(sourceID, url, line, enabled, condition)
94 var breakpoint = new WebInspector.Breakpoint(this, sourceID, url, line, enabled, condition);
95 if (this._breakpoints[breakpoint.id])
97 if (this._oneTimeBreakpoint && (this._oneTimeBreakpoint.id == breakpoint.id))
98 delete this._oneTimeBreakpoint;
99 this._breakpoints[breakpoint.id] = breakpoint;
100 breakpoint.addEventListener("removed", this._breakpointRemoved, this);
101 this.dispatchEventToListeners("breakpoint-added", breakpoint);
105 _breakpointRemoved: function(event)
107 delete this._breakpoints[event.target.id];
110 _setBreakpointOnBackend: function(breakpoint, isOneTime)
112 function didSetBreakpoint(success, line)
114 if (success && line == breakpoint.line)
118 this._oneTimeBreakpoint.line = line;
120 delete this._oneTimeBreakpoint;
124 this._setBreakpoint(breakpoint.sourceID, breakpoint.url, line, breakpoint.enabled, breakpoint.condition);
127 InspectorBackend.setBreakpoint(breakpoint.sourceID, breakpoint.line, breakpoint.enabled, breakpoint.condition, didSetBreakpoint.bind(this));
130 debuggerPaused: function(details)
132 this.dispatchEventToListeners("debugger-paused", details.callFrames);
134 if (details.eventType === WebInspector.DebuggerEventTypes.JavaScriptPause)
136 if (details.eventType === WebInspector.DebuggerEventTypes.NativeBreakpoint) {
137 this.dispatchEventToListeners("native-breakpoint-hit", details.eventData);
141 var breakpointId = WebInspector.Breakpoint.jsBreakpointId(details.callFrames[0].sourceID, details.callFrames[0].line);
142 var breakpoint = this._breakpoints[breakpointId];
145 breakpoint.hit = true;
146 this._lastHitBreakpoint = breakpoint;
147 this.dispatchEventToListeners("script-breakpoint-hit", breakpoint);
150 debuggerResumed: function()
152 this.dispatchEventToListeners("debugger-resumed");
154 if (!this._lastHitBreakpoint)
156 this._lastHitBreakpoint.hit = false;
157 delete this._lastHitBreakpoint;
161 WebInspector.DebuggerModel.prototype.__proto__ = WebInspector.Object.prototype;
163 WebInspector.DebuggerEventTypes = {
165 JavaScriptBreakpoint: 1,