Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/bindings/PresentationConsoleMessageHelper.js

Issue 2466123002: DevTools: reformat front-end code to match chromium style. (Closed)
Patch Set: all done Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
11 * copyright notice, this list of conditions and the following disclaimer 11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the 12 * in the documentation and/or other materials provided with the
13 * distribution. 13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its 14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from 15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission. 16 * this software without specific prior written permission.
17 * 17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30
31 /** 30 /**
32 * @constructor 31 * @unrestricted
33 * @param {!WebInspector.Workspace} workspace
34 */ 32 */
35 WebInspector.PresentationConsoleMessageHelper = function(workspace) 33 WebInspector.PresentationConsoleMessageHelper = class {
36 { 34 /**
35 * @param {!WebInspector.Workspace} workspace
36 */
37 constructor(workspace) {
37 this._workspace = workspace; 38 this._workspace = workspace;
38 39
39 /** @type {!Object.<string, !Array.<!WebInspector.ConsoleMessage>>} */ 40 /** @type {!Object.<string, !Array.<!WebInspector.ConsoleMessage>>} */
40 this._pendingConsoleMessages = {}; 41 this._pendingConsoleMessages = {};
41 42
42 /** @type {!Array.<!WebInspector.PresentationConsoleMessage>} */ 43 /** @type {!Array.<!WebInspector.PresentationConsoleMessage>} */
43 this._presentationConsoleMessages = []; 44 this._presentationConsoleMessages = [];
44 45
45 WebInspector.multitargetConsoleModel.addEventListener(WebInspector.ConsoleMo del.Events.ConsoleCleared, this._consoleCleared, this); 46 WebInspector.multitargetConsoleModel.addEventListener(
46 WebInspector.multitargetConsoleModel.addEventListener(WebInspector.ConsoleMo del.Events.MessageAdded, this._onConsoleMessageAdded, this); 47 WebInspector.ConsoleModel.Events.ConsoleCleared, this._consoleCleared, t his);
48 WebInspector.multitargetConsoleModel.addEventListener(
49 WebInspector.ConsoleModel.Events.MessageAdded, this._onConsoleMessageAdd ed, this);
47 WebInspector.multitargetConsoleModel.messages().forEach(this._consoleMessage Added, this); 50 WebInspector.multitargetConsoleModel.messages().forEach(this._consoleMessage Added, this);
48 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI nspector.DebuggerModel.Events.ParsedScriptSource, this._parsedScriptSource, this ); 51 WebInspector.targetManager.addModelListener(
49 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI nspector.DebuggerModel.Events.FailedToParseScriptSource, this._parsedScriptSourc e, this); 52 WebInspector.DebuggerModel, WebInspector.DebuggerModel.Events.ParsedScri ptSource, this._parsedScriptSource,
50 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI nspector.DebuggerModel.Events.GlobalObjectCleared, this._debuggerReset, this); 53 this);
54 WebInspector.targetManager.addModelListener(
55 WebInspector.DebuggerModel, WebInspector.DebuggerModel.Events.FailedToPa rseScriptSource,
56 this._parsedScriptSource, this);
57 WebInspector.targetManager.addModelListener(
58 WebInspector.DebuggerModel, WebInspector.DebuggerModel.Events.GlobalObje ctCleared, this._debuggerReset, this);
51 59
52 this._locationPool = new WebInspector.LiveLocationPool(); 60 this._locationPool = new WebInspector.LiveLocationPool();
53 }; 61 }
54 62
55 WebInspector.PresentationConsoleMessageHelper.prototype = { 63 /**
56 /** 64 * @param {!WebInspector.Event} event
57 * @param {!WebInspector.Event} event 65 */
58 */ 66 _onConsoleMessageAdded(event) {
59 _onConsoleMessageAdded: function(event) 67 var message = /** @type {!WebInspector.ConsoleMessage} */ (event.data);
60 { 68 this._consoleMessageAdded(message);
61 var message = /** @type {!WebInspector.ConsoleMessage} */ (event.data); 69 }
62 this._consoleMessageAdded(message);
63 },
64 70
65 /** 71 /**
66 * @param {!WebInspector.ConsoleMessage} message 72 * @param {!WebInspector.ConsoleMessage} message
67 */ 73 */
68 _consoleMessageAdded: function(message) 74 _consoleMessageAdded(message) {
69 { 75 if (!message.isErrorOrWarning())
70 if (!message.isErrorOrWarning()) 76 return;
71 return;
72 77
73 var rawLocation = this._rawLocation(message); 78 var rawLocation = this._rawLocation(message);
74 if (rawLocation) 79 if (rawLocation)
75 this._addConsoleMessageToScript(message, rawLocation); 80 this._addConsoleMessageToScript(message, rawLocation);
76 else 81 else
77 this._addPendingConsoleMessage(message); 82 this._addPendingConsoleMessage(message);
78 }, 83 }
79 84
80 /** 85 /**
81 * @param {!WebInspector.ConsoleMessage} message 86 * @param {!WebInspector.ConsoleMessage} message
82 * @return {?WebInspector.DebuggerModel.Location} 87 * @return {?WebInspector.DebuggerModel.Location}
83 */ 88 */
84 _rawLocation: function(message) 89 _rawLocation(message) {
85 { 90 var debuggerModel = WebInspector.DebuggerModel.fromTarget(message.target());
86 var debuggerModel = WebInspector.DebuggerModel.fromTarget(message.target ()); 91 if (!debuggerModel)
87 if (!debuggerModel) 92 return null;
88 return null; 93 if (message.scriptId)
89 if (message.scriptId) 94 return debuggerModel.createRawLocationByScriptId(message.scriptId, message .line, message.column);
90 return debuggerModel.createRawLocationByScriptId(message.scriptId, m essage.line, message.column); 95 var callFrame = message.stackTrace && message.stackTrace.callFrames ? messag e.stackTrace.callFrames[0] : null;
91 var callFrame = message.stackTrace && message.stackTrace.callFrames ? me ssage.stackTrace.callFrames[0] : null; 96 if (callFrame)
92 if (callFrame) 97 return debuggerModel.createRawLocationByScriptId(
93 return debuggerModel.createRawLocationByScriptId(callFrame.scriptId, callFrame.lineNumber, callFrame.columnNumber); 98 callFrame.scriptId, callFrame.lineNumber, callFrame.columnNumber);
94 if (message.url) 99 if (message.url)
95 return debuggerModel.createRawLocationByURL(message.url, message.lin e, message.column); 100 return debuggerModel.createRawLocationByURL(message.url, message.line, mes sage.column);
96 return null; 101 return null;
97 }, 102 }
98 103
99 /** 104 /**
100 * @param {!WebInspector.ConsoleMessage} message 105 * @param {!WebInspector.ConsoleMessage} message
101 * @param {!WebInspector.DebuggerModel.Location} rawLocation 106 * @param {!WebInspector.DebuggerModel.Location} rawLocation
102 */ 107 */
103 _addConsoleMessageToScript: function(message, rawLocation) 108 _addConsoleMessageToScript(message, rawLocation) {
104 { 109 this._presentationConsoleMessages.push(
105 this._presentationConsoleMessages.push(new WebInspector.PresentationCons oleMessage(message, rawLocation, this._locationPool)); 110 new WebInspector.PresentationConsoleMessage(message, rawLocation, this._ locationPool));
106 }, 111 }
107 112
108 /** 113 /**
109 * @param {!WebInspector.ConsoleMessage} message 114 * @param {!WebInspector.ConsoleMessage} message
110 */ 115 */
111 _addPendingConsoleMessage: function(message) 116 _addPendingConsoleMessage(message) {
112 { 117 if (!message.url)
113 if (!message.url) 118 return;
114 return; 119 if (!this._pendingConsoleMessages[message.url])
115 if (!this._pendingConsoleMessages[message.url]) 120 this._pendingConsoleMessages[message.url] = [];
116 this._pendingConsoleMessages[message.url] = []; 121 this._pendingConsoleMessages[message.url].push(message);
117 this._pendingConsoleMessages[message.url].push(message); 122 }
118 },
119 123
120 /** 124 /**
121 * @param {!WebInspector.Event} event 125 * @param {!WebInspector.Event} event
122 */ 126 */
123 _parsedScriptSource: function(event) 127 _parsedScriptSource(event) {
124 { 128 var script = /** @type {!WebInspector.Script} */ (event.data);
125 var script = /** @type {!WebInspector.Script} */ (event.data);
126 129
127 var messages = this._pendingConsoleMessages[script.sourceURL]; 130 var messages = this._pendingConsoleMessages[script.sourceURL];
128 if (!messages) 131 if (!messages)
129 return; 132 return;
130 133
131 var pendingMessages = []; 134 var pendingMessages = [];
132 for (var i = 0; i < messages.length; i++) { 135 for (var i = 0; i < messages.length; i++) {
133 var message = messages[i]; 136 var message = messages[i];
134 var rawLocation = this._rawLocation(message); 137 var rawLocation = this._rawLocation(message);
135 if (!rawLocation) 138 if (!rawLocation)
136 continue; 139 continue;
137 if (script.target() === message.target() && script.scriptId === rawL ocation.scriptId) 140 if (script.target() === message.target() && script.scriptId === rawLocatio n.scriptId)
138 this._addConsoleMessageToScript(message, rawLocation); 141 this._addConsoleMessageToScript(message, rawLocation);
139 else 142 else
140 pendingMessages.push(message); 143 pendingMessages.push(message);
141 } 144 }
142 145
143 if (pendingMessages.length) 146 if (pendingMessages.length)
144 this._pendingConsoleMessages[script.sourceURL] = pendingMessages; 147 this._pendingConsoleMessages[script.sourceURL] = pendingMessages;
145 else 148 else
146 delete this._pendingConsoleMessages[script.sourceURL]; 149 delete this._pendingConsoleMessages[script.sourceURL];
147 }, 150 }
148 151
149 _consoleCleared: function() 152 _consoleCleared() {
150 { 153 this._pendingConsoleMessages = {};
151 this._pendingConsoleMessages = {}; 154 for (var i = 0; i < this._presentationConsoleMessages.length; ++i)
152 for (var i = 0; i < this._presentationConsoleMessages.length; ++i) 155 this._presentationConsoleMessages[i].dispose();
153 this._presentationConsoleMessages[i].dispose(); 156 this._presentationConsoleMessages = [];
154 this._presentationConsoleMessages = []; 157 this._locationPool.disposeAll();
155 this._locationPool.disposeAll(); 158 }
156 },
157 159
158 _debuggerReset: function() 160 _debuggerReset() {
159 { 161 this._consoleCleared();
160 this._consoleCleared(); 162 }
161 }
162 }; 163 };
163 164
164 /** 165 /**
165 * @constructor 166 * @unrestricted
166 * @param {!WebInspector.ConsoleMessage} message
167 * @param {!WebInspector.DebuggerModel.Location} rawLocation
168 * @param {!WebInspector.LiveLocationPool} locationPool
169 */ 167 */
170 WebInspector.PresentationConsoleMessage = function(message, rawLocation, locatio nPool) 168 WebInspector.PresentationConsoleMessage = class {
171 { 169 /**
170 * @param {!WebInspector.ConsoleMessage} message
171 * @param {!WebInspector.DebuggerModel.Location} rawLocation
172 * @param {!WebInspector.LiveLocationPool} locationPool
173 */
174 constructor(message, rawLocation, locationPool) {
172 this._text = message.messageText; 175 this._text = message.messageText;
173 this._level = message.level === WebInspector.ConsoleMessage.MessageLevel.Err or ? WebInspector.UISourceCode.Message.Level.Error : WebInspector.UISourceCode.M essage.Level.Warning; 176 this._level = message.level === WebInspector.ConsoleMessage.MessageLevel.Err or ?
174 WebInspector.debuggerWorkspaceBinding.createLiveLocation(rawLocation, this._ updateLocation.bind(this), locationPool); 177 WebInspector.UISourceCode.Message.Level.Error :
175 }; 178 WebInspector.UISourceCode.Message.Level.Warning;
179 WebInspector.debuggerWorkspaceBinding.createLiveLocation(
180 rawLocation, this._updateLocation.bind(this), locationPool);
181 }
176 182
177 WebInspector.PresentationConsoleMessage.prototype = { 183 /**
178 /** 184 * @param {!WebInspector.LiveLocation} liveLocation
179 * @param {!WebInspector.LiveLocation} liveLocation 185 */
180 */ 186 _updateLocation(liveLocation) {
181 _updateLocation: function(liveLocation) 187 if (this._uiMessage)
182 { 188 this._uiMessage.remove();
183 if (this._uiMessage) 189 var uiLocation = liveLocation.uiLocation();
184 this._uiMessage.remove(); 190 if (!uiLocation)
185 var uiLocation = liveLocation.uiLocation(); 191 return;
186 if (!uiLocation) 192 this._uiMessage =
187 return; 193 uiLocation.uiSourceCode.addLineMessage(this._level, this._text, uiLocati on.lineNumber, uiLocation.columnNumber);
188 this._uiMessage = uiLocation.uiSourceCode.addLineMessage(this._level, th is._text, uiLocation.lineNumber, uiLocation.columnNumber); 194 }
189 },
190 195
191 dispose: function() 196 dispose() {
192 { 197 if (this._uiMessage)
193 if (this._uiMessage) 198 this._uiMessage.remove();
194 this._uiMessage.remove(); 199 }
195 }
196 }; 200 };
197 201
198 /** @type {!WebInspector.PresentationConsoleMessageHelper} */ 202 /** @type {!WebInspector.PresentationConsoleMessageHelper} */
199 WebInspector.presentationConsoleMessageHelper; 203 WebInspector.presentationConsoleMessageHelper;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698