OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2007 Apple Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions | |
6 * are met: | |
7 * | |
8 * 1. Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * 2. Redistributions in binary form must reproduce the above copyright | |
11 * notice, this list of conditions and the following disclaimer in the | |
12 * documentation and/or other materials provided with the distribution. | |
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of | |
14 * its contributors may be used to endorse or promote products derived | |
15 * from this software without specific prior written permission. | |
16 * | |
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | |
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | |
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
27 */ | |
28 | |
29 #include "core/frame/Console.h" | |
30 | |
31 #include "bindings/core/v8/ScriptCallStack.h" | |
32 #include "core/inspector/ConsoleMessage.h" | |
33 #include "core/inspector/InspectorConsoleInstrumentation.h" | |
34 #include "core/inspector/InspectorTraceEvents.h" | |
35 #include "core/inspector/ScriptArguments.h" | |
36 #include "platform/TraceEvent.h" | |
37 #include "wtf/text/CString.h" | |
38 #include "wtf/text/WTFString.h" | |
39 | |
40 namespace blink { | |
41 | |
42 ConsoleBase::~ConsoleBase() | |
43 { | |
44 } | |
45 | |
46 void ConsoleBase::debug(ScriptState* scriptState, ScriptArguments* arguments) | |
47 { | |
48 internalAddMessage(LogMessageType, DebugMessageLevel, scriptState, arguments
); | |
49 } | |
50 | |
51 void ConsoleBase::error(ScriptState* scriptState, ScriptArguments* arguments) | |
52 { | |
53 internalAddMessage(LogMessageType, ErrorMessageLevel, scriptState, arguments
, false); | |
54 } | |
55 | |
56 void ConsoleBase::info(ScriptState* scriptState, ScriptArguments* arguments) | |
57 { | |
58 internalAddMessage(LogMessageType, InfoMessageLevel, scriptState, arguments)
; | |
59 } | |
60 | |
61 void ConsoleBase::log(ScriptState* scriptState, ScriptArguments* arguments) | |
62 { | |
63 internalAddMessage(LogMessageType, LogMessageLevel, scriptState, arguments); | |
64 } | |
65 | |
66 void ConsoleBase::warn(ScriptState* scriptState, ScriptArguments* arguments) | |
67 { | |
68 internalAddMessage(LogMessageType, WarningMessageLevel, scriptState, argumen
ts); | |
69 } | |
70 | |
71 void ConsoleBase::dir(ScriptState* scriptState, ScriptArguments* arguments) | |
72 { | |
73 internalAddMessage(DirMessageType, LogMessageLevel, scriptState, arguments); | |
74 } | |
75 | |
76 void ConsoleBase::dirxml(ScriptState* scriptState, ScriptArguments* arguments) | |
77 { | |
78 internalAddMessage(DirXMLMessageType, LogMessageLevel, scriptState, argument
s); | |
79 } | |
80 | |
81 void ConsoleBase::table(ScriptState* scriptState, ScriptArguments* arguments) | |
82 { | |
83 internalAddMessage(TableMessageType, LogMessageLevel, scriptState, arguments
); | |
84 } | |
85 | |
86 void ConsoleBase::clear(ScriptState* scriptState, ScriptArguments* arguments) | |
87 { | |
88 internalAddMessage(ClearMessageType, LogMessageLevel, scriptState, arguments
, true); | |
89 } | |
90 | |
91 void ConsoleBase::trace(ScriptState* scriptState, ScriptArguments* arguments) | |
92 { | |
93 internalAddMessage(TraceMessageType, LogMessageLevel, scriptState, arguments
, true); | |
94 } | |
95 | |
96 void ConsoleBase::assertCondition(ScriptState* scriptState, ScriptArguments* arg
uments, bool condition) | |
97 { | |
98 if (condition) | |
99 return; | |
100 | |
101 internalAddMessage(AssertMessageType, ErrorMessageLevel, scriptState, argume
nts, true); | |
102 } | |
103 | |
104 void ConsoleBase::count(ScriptState* scriptState, ScriptArguments* arguments) | |
105 { | |
106 RefPtr<ScriptCallStack> callStack(ScriptCallStack::capture(1)); | |
107 // Follow Firebug's behavior of counting with null and undefined title in | |
108 // the same bucket as no argument | |
109 String title; | |
110 arguments->getFirstArgumentAsString(title); | |
111 String identifier = title.isEmpty() ? String(callStack->topSourceURL() + ':'
+ String::number(callStack->topLineNumber())) | |
112 : String(title + '@'); | |
113 | |
114 HashCountedSet<String>::AddResult result = m_counts.add(identifier); | |
115 String message = title + ": " + String::number(result.storedValue->value); | |
116 | |
117 ConsoleMessage* consoleMessage = ConsoleMessage::create(ConsoleAPIMessageSou
rce, DebugMessageLevel, message); | |
118 consoleMessage->setType(CountMessageType); | |
119 consoleMessage->setScriptState(scriptState); | |
120 consoleMessage->setCallStack(callStack.release()); | |
121 reportMessageToConsole(consoleMessage); | |
122 } | |
123 | |
124 void ConsoleBase::markTimeline(const String& title) | |
125 { | |
126 timeStamp(title); | |
127 } | |
128 | |
129 void ConsoleBase::profile(const String& title) | |
130 { | |
131 InspectorInstrumentation::consoleProfile(context(), title); | |
132 } | |
133 | |
134 void ConsoleBase::profileEnd(const String& title) | |
135 { | |
136 InspectorInstrumentation::consoleProfileEnd(context(), title); | |
137 } | |
138 | |
139 void ConsoleBase::time(const String& title) | |
140 { | |
141 TRACE_EVENT_COPY_ASYNC_BEGIN0("blink.console", title.utf8().data(), this); | |
142 | |
143 if (title.isNull()) | |
144 return; | |
145 | |
146 m_times.add(title, monotonicallyIncreasingTime()); | |
147 } | |
148 | |
149 void ConsoleBase::timeEnd(ScriptState* scriptState, const String& title) | |
150 { | |
151 TRACE_EVENT_COPY_ASYNC_END0("blink.console", title.utf8().data(), this); | |
152 | |
153 // Follow Firebug's behavior of requiring a title that is not null or | |
154 // undefined for timing functions | |
155 if (title.isNull()) | |
156 return; | |
157 | |
158 HashMap<String, double>::iterator it = m_times.find(title); | |
159 if (it == m_times.end()) | |
160 return; | |
161 | |
162 double startTime = it->value; | |
163 m_times.remove(it); | |
164 | |
165 double elapsed = monotonicallyIncreasingTime() - startTime; | |
166 String message = title + String::format(": %.3fms", elapsed * 1000); | |
167 | |
168 ConsoleMessage* consoleMessage = ConsoleMessage::create(ConsoleAPIMessageSou
rce, DebugMessageLevel, message); | |
169 consoleMessage->setType(TimeEndMessageType); | |
170 consoleMessage->setScriptState(scriptState); | |
171 consoleMessage->setCallStack(ScriptCallStack::capture(1)); | |
172 reportMessageToConsole(consoleMessage); | |
173 } | |
174 | |
175 void ConsoleBase::timeStamp(const String& title) | |
176 { | |
177 TRACE_EVENT_INSTANT1("devtools.timeline", "TimeStamp", TRACE_EVENT_SCOPE_THR
EAD, "data", InspectorTimeStampEvent::data(context(), title)); | |
178 } | |
179 | |
180 static String formatTimelineTitle(const String& title) | |
181 { | |
182 return String::format("Timeline '%s'", title.utf8().data()); | |
183 } | |
184 | |
185 void ConsoleBase::timeline(ScriptState* scriptState, const String& title) | |
186 { | |
187 TRACE_EVENT_COPY_ASYNC_BEGIN0("blink.console", formatTimelineTitle(title).ut
f8().data(), this); | |
188 } | |
189 | |
190 void ConsoleBase::timelineEnd(ScriptState* scriptState, const String& title) | |
191 { | |
192 TRACE_EVENT_COPY_ASYNC_END0("blink.console", formatTimelineTitle(title).utf8
().data(), this); | |
193 } | |
194 | |
195 void ConsoleBase::group(ScriptState* scriptState, ScriptArguments* arguments) | |
196 { | |
197 internalAddMessage(StartGroupMessageType, LogMessageLevel, scriptState, argu
ments, true); | |
198 } | |
199 | |
200 void ConsoleBase::groupCollapsed(ScriptState* scriptState, ScriptArguments* argu
ments) | |
201 { | |
202 internalAddMessage(StartGroupCollapsedMessageType, LogMessageLevel, scriptSt
ate, arguments, true); | |
203 } | |
204 | |
205 void ConsoleBase::groupEnd() | |
206 { | |
207 internalAddMessage(EndGroupMessageType, LogMessageLevel, nullptr, nullptr, t
rue); | |
208 } | |
209 | |
210 void ConsoleBase::internalAddMessage(MessageType type, MessageLevel level, Scrip
tState* scriptState, ScriptArguments* scriptArguments, bool acceptNoArguments) | |
211 { | |
212 ScriptArguments* arguments = scriptArguments; | |
213 if (!acceptNoArguments && (!arguments || !arguments->argumentCount())) | |
214 return; | |
215 | |
216 if (scriptState && !scriptState->contextIsValid()) | |
217 arguments = nullptr; | |
218 String message; | |
219 if (arguments) | |
220 arguments->getFirstArgumentAsString(message); | |
221 | |
222 ConsoleMessage* consoleMessage = ConsoleMessage::create(ConsoleAPIMessageSou
rce, level, message); | |
223 consoleMessage->setType(type); | |
224 consoleMessage->setScriptState(scriptState); | |
225 consoleMessage->setScriptArguments(arguments); | |
226 consoleMessage->setCallStack(ScriptCallStack::captureForConsole()); | |
227 reportMessageToConsole(consoleMessage); | |
228 } | |
229 | |
230 } // namespace blink | |
OLD | NEW |