OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 20 matching lines...) Expand all Loading... |
31 /** | 31 /** |
32 * @unrestricted | 32 * @unrestricted |
33 */ | 33 */ |
34 Bindings.PresentationConsoleMessageHelper = class { | 34 Bindings.PresentationConsoleMessageHelper = class { |
35 /** | 35 /** |
36 * @param {!Workspace.Workspace} workspace | 36 * @param {!Workspace.Workspace} workspace |
37 */ | 37 */ |
38 constructor(workspace) { | 38 constructor(workspace) { |
39 this._workspace = workspace; | 39 this._workspace = workspace; |
40 | 40 |
41 /** @type {!Object.<string, !Array.<!SDK.ConsoleMessage>>} */ | 41 /** @type {!Object.<string, !Array.<!ConsoleModel.ConsoleMessage>>} */ |
42 this._pendingConsoleMessages = {}; | 42 this._pendingConsoleMessages = {}; |
43 | 43 |
44 /** @type {!Array.<!Bindings.PresentationConsoleMessage>} */ | 44 /** @type {!Array.<!Bindings.PresentationConsoleMessage>} */ |
45 this._presentationConsoleMessages = []; | 45 this._presentationConsoleMessages = []; |
46 | 46 |
47 SDK.consoleModel.addEventListener(SDK.ConsoleModel.Events.ConsoleCleared, th
is._consoleCleared, this); | 47 ConsoleModel.consoleModel.addEventListener( |
48 SDK.consoleModel.addEventListener(SDK.ConsoleModel.Events.MessageAdded, this
._onConsoleMessageAdded, this); | 48 ConsoleModel.ConsoleModel.Events.ConsoleCleared, this._consoleCleared, t
his); |
49 SDK.consoleModel.messages().forEach(this._consoleMessageAdded, this); | 49 ConsoleModel.consoleModel.addEventListener( |
| 50 ConsoleModel.ConsoleModel.Events.MessageAdded, this._onConsoleMessageAdd
ed, this); |
| 51 ConsoleModel.consoleModel.messages().forEach(this._consoleMessageAdded, this
); |
50 // TODO(dgozman): setImmediate because we race with DebuggerWorkspaceBinding
on ParsedScriptSource event delivery. | 52 // TODO(dgozman): setImmediate because we race with DebuggerWorkspaceBinding
on ParsedScriptSource event delivery. |
51 SDK.targetManager.addModelListener( | 53 SDK.targetManager.addModelListener( |
52 SDK.DebuggerModel, SDK.DebuggerModel.Events.ParsedScriptSource, | 54 SDK.DebuggerModel, SDK.DebuggerModel.Events.ParsedScriptSource, |
53 event => setImmediate(this._parsedScriptSource.bind(this, event))); | 55 event => setImmediate(this._parsedScriptSource.bind(this, event))); |
54 SDK.targetManager.addModelListener( | 56 SDK.targetManager.addModelListener( |
55 SDK.DebuggerModel, SDK.DebuggerModel.Events.FailedToParseScriptSource, | 57 SDK.DebuggerModel, SDK.DebuggerModel.Events.FailedToParseScriptSource, |
56 event => setImmediate(this._parsedScriptSource.bind(this, event))); | 58 event => setImmediate(this._parsedScriptSource.bind(this, event))); |
57 SDK.targetManager.addModelListener( | 59 SDK.targetManager.addModelListener( |
58 SDK.DebuggerModel, SDK.DebuggerModel.Events.GlobalObjectCleared, this._d
ebuggerReset, this); | 60 SDK.DebuggerModel, SDK.DebuggerModel.Events.GlobalObjectCleared, this._d
ebuggerReset, this); |
59 | 61 |
60 this._locationPool = new Bindings.LiveLocationPool(); | 62 this._locationPool = new Bindings.LiveLocationPool(); |
61 } | 63 } |
62 | 64 |
63 /** | 65 /** |
64 * @param {!Common.Event} event | 66 * @param {!Common.Event} event |
65 */ | 67 */ |
66 _onConsoleMessageAdded(event) { | 68 _onConsoleMessageAdded(event) { |
67 var message = /** @type {!SDK.ConsoleMessage} */ (event.data); | 69 var message = /** @type {!ConsoleModel.ConsoleMessage} */ (event.data); |
68 this._consoleMessageAdded(message); | 70 this._consoleMessageAdded(message); |
69 } | 71 } |
70 | 72 |
71 /** | 73 /** |
72 * @param {!SDK.ConsoleMessage} message | 74 * @param {!ConsoleModel.ConsoleMessage} message |
73 */ | 75 */ |
74 _consoleMessageAdded(message) { | 76 _consoleMessageAdded(message) { |
75 if (!message.isErrorOrWarning()) | 77 if (!message.isErrorOrWarning()) |
76 return; | 78 return; |
77 | 79 |
78 var rawLocation = this._rawLocation(message); | 80 var rawLocation = this._rawLocation(message); |
79 if (rawLocation) | 81 if (rawLocation) |
80 this._addConsoleMessageToScript(message, rawLocation); | 82 this._addConsoleMessageToScript(message, rawLocation); |
81 else | 83 else |
82 this._addPendingConsoleMessage(message); | 84 this._addPendingConsoleMessage(message); |
83 } | 85 } |
84 | 86 |
85 /** | 87 /** |
86 * @param {!SDK.ConsoleMessage} message | 88 * @param {!ConsoleModel.ConsoleMessage} message |
87 * @return {?SDK.DebuggerModel.Location} | 89 * @return {?SDK.DebuggerModel.Location} |
88 */ | 90 */ |
89 _rawLocation(message) { | 91 _rawLocation(message) { |
90 var debuggerModel = SDK.DebuggerModel.fromTarget(message.target()); | 92 var debuggerModel = SDK.DebuggerModel.fromTarget(message.target()); |
91 if (!debuggerModel) | 93 if (!debuggerModel) |
92 return null; | 94 return null; |
93 if (message.scriptId) | 95 if (message.scriptId) |
94 return debuggerModel.createRawLocationByScriptId(message.scriptId, message
.line, message.column); | 96 return debuggerModel.createRawLocationByScriptId(message.scriptId, message
.line, message.column); |
95 var callFrame = message.stackTrace && message.stackTrace.callFrames ? messag
e.stackTrace.callFrames[0] : null; | 97 var callFrame = message.stackTrace && message.stackTrace.callFrames ? messag
e.stackTrace.callFrames[0] : null; |
96 if (callFrame) { | 98 if (callFrame) { |
97 return debuggerModel.createRawLocationByScriptId( | 99 return debuggerModel.createRawLocationByScriptId( |
98 callFrame.scriptId, callFrame.lineNumber, callFrame.columnNumber); | 100 callFrame.scriptId, callFrame.lineNumber, callFrame.columnNumber); |
99 } | 101 } |
100 if (message.url) | 102 if (message.url) |
101 return debuggerModel.createRawLocationByURL(message.url, message.line, mes
sage.column); | 103 return debuggerModel.createRawLocationByURL(message.url, message.line, mes
sage.column); |
102 return null; | 104 return null; |
103 } | 105 } |
104 | 106 |
105 /** | 107 /** |
106 * @param {!SDK.ConsoleMessage} message | 108 * @param {!ConsoleModel.ConsoleMessage} message |
107 * @param {!SDK.DebuggerModel.Location} rawLocation | 109 * @param {!SDK.DebuggerModel.Location} rawLocation |
108 */ | 110 */ |
109 _addConsoleMessageToScript(message, rawLocation) { | 111 _addConsoleMessageToScript(message, rawLocation) { |
110 if (message.source === SDK.ConsoleMessage.MessageSource.Violation) | 112 if (message.source === ConsoleModel.ConsoleMessage.MessageSource.Violation) |
111 return; | 113 return; |
112 this._presentationConsoleMessages.push( | 114 this._presentationConsoleMessages.push( |
113 new Bindings.PresentationConsoleMessage(message, rawLocation, this._loca
tionPool)); | 115 new Bindings.PresentationConsoleMessage(message, rawLocation, this._loca
tionPool)); |
114 } | 116 } |
115 | 117 |
116 /** | 118 /** |
117 * @param {!SDK.ConsoleMessage} message | 119 * @param {!ConsoleModel.ConsoleMessage} message |
118 */ | 120 */ |
119 _addPendingConsoleMessage(message) { | 121 _addPendingConsoleMessage(message) { |
120 if (!message.url) | 122 if (!message.url) |
121 return; | 123 return; |
122 if (!this._pendingConsoleMessages[message.url]) | 124 if (!this._pendingConsoleMessages[message.url]) |
123 this._pendingConsoleMessages[message.url] = []; | 125 this._pendingConsoleMessages[message.url] = []; |
124 this._pendingConsoleMessages[message.url].push(message); | 126 this._pendingConsoleMessages[message.url].push(message); |
125 } | 127 } |
126 | 128 |
127 /** | 129 /** |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 _debuggerReset() { | 165 _debuggerReset() { |
164 this._consoleCleared(); | 166 this._consoleCleared(); |
165 } | 167 } |
166 }; | 168 }; |
167 | 169 |
168 /** | 170 /** |
169 * @unrestricted | 171 * @unrestricted |
170 */ | 172 */ |
171 Bindings.PresentationConsoleMessage = class { | 173 Bindings.PresentationConsoleMessage = class { |
172 /** | 174 /** |
173 * @param {!SDK.ConsoleMessage} message | 175 * @param {!ConsoleModel.ConsoleMessage} message |
174 * @param {!SDK.DebuggerModel.Location} rawLocation | 176 * @param {!SDK.DebuggerModel.Location} rawLocation |
175 * @param {!Bindings.LiveLocationPool} locationPool | 177 * @param {!Bindings.LiveLocationPool} locationPool |
176 */ | 178 */ |
177 constructor(message, rawLocation, locationPool) { | 179 constructor(message, rawLocation, locationPool) { |
178 this._text = message.messageText; | 180 this._text = message.messageText; |
179 this._level = message.level === SDK.ConsoleMessage.MessageLevel.Error ? | 181 this._level = message.level === ConsoleModel.ConsoleMessage.MessageLevel.Err
or ? |
180 Workspace.UISourceCode.Message.Level.Error : | 182 Workspace.UISourceCode.Message.Level.Error : |
181 Workspace.UISourceCode.Message.Level.Warning; | 183 Workspace.UISourceCode.Message.Level.Warning; |
182 Bindings.debuggerWorkspaceBinding.createLiveLocation(rawLocation, this._upda
teLocation.bind(this), locationPool); | 184 Bindings.debuggerWorkspaceBinding.createLiveLocation(rawLocation, this._upda
teLocation.bind(this), locationPool); |
183 } | 185 } |
184 | 186 |
185 /** | 187 /** |
186 * @param {!Bindings.LiveLocation} liveLocation | 188 * @param {!Bindings.LiveLocation} liveLocation |
187 */ | 189 */ |
188 _updateLocation(liveLocation) { | 190 _updateLocation(liveLocation) { |
189 if (this._uiMessage) | 191 if (this._uiMessage) |
190 this._uiMessage.remove(); | 192 this._uiMessage.remove(); |
191 var uiLocation = liveLocation.uiLocation(); | 193 var uiLocation = liveLocation.uiLocation(); |
192 if (!uiLocation) | 194 if (!uiLocation) |
193 return; | 195 return; |
194 this._uiMessage = | 196 this._uiMessage = |
195 uiLocation.uiSourceCode.addLineMessage(this._level, this._text, uiLocati
on.lineNumber, uiLocation.columnNumber); | 197 uiLocation.uiSourceCode.addLineMessage(this._level, this._text, uiLocati
on.lineNumber, uiLocation.columnNumber); |
196 } | 198 } |
197 | 199 |
198 dispose() { | 200 dispose() { |
199 if (this._uiMessage) | 201 if (this._uiMessage) |
200 this._uiMessage.remove(); | 202 this._uiMessage.remove(); |
201 } | 203 } |
202 }; | 204 }; |
203 | 205 |
204 /** @type {!Bindings.PresentationConsoleMessageHelper} */ | 206 /** @type {!Bindings.PresentationConsoleMessageHelper} */ |
205 Bindings.presentationConsoleMessageHelper; | 207 Bindings.presentationConsoleMessageHelper; |
OLD | NEW |