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

Side by Side Diff: sky/engine/core/frame/ConsoleBase.cpp

Issue 922893002: Merge the Sky Engine changes from the SkyDart branch (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 months 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
« no previous file with comments | « sky/engine/core/frame/ConsoleBase.h ('k') | sky/engine/core/frame/ConsoleBase.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 "sky/engine/config.h"
30 #include "sky/engine/core/frame/Console.h"
31
32 #include "sky/engine/bindings/core/v8/ScriptCallStackFactory.h"
33 #include "sky/engine/core/inspector/ConsoleMessage.h"
34 #include "sky/engine/core/inspector/ScriptArguments.h"
35 #include "sky/engine/platform/TraceEvent.h"
36 #include "sky/engine/wtf/text/CString.h"
37 #include "sky/engine/wtf/text/WTFString.h"
38
39 namespace blink {
40
41 ConsoleBase::~ConsoleBase()
42 {
43 }
44
45 void ConsoleBase::debug(ScriptState* scriptState, PassRefPtr<ScriptArguments> ar guments)
46 {
47 internalAddMessage(LogMessageType, DebugMessageLevel, scriptState, arguments );
48 }
49
50 void ConsoleBase::error(ScriptState* scriptState, PassRefPtr<ScriptArguments> ar guments)
51 {
52 internalAddMessage(LogMessageType, ErrorMessageLevel, scriptState, arguments );
53 }
54
55 void ConsoleBase::info(ScriptState* scriptState, PassRefPtr<ScriptArguments> arg uments)
56 {
57 internalAddMessage(LogMessageType, InfoMessageLevel, scriptState, arguments) ;
58 }
59
60 void ConsoleBase::log(ScriptState* scriptState, PassRefPtr<ScriptArguments> argu ments)
61 {
62 internalAddMessage(LogMessageType, LogMessageLevel, scriptState, arguments);
63 }
64
65 void ConsoleBase::warn(ScriptState* scriptState, PassRefPtr<ScriptArguments> arg uments)
66 {
67 internalAddMessage(LogMessageType, WarningMessageLevel, scriptState, argumen ts);
68 }
69
70 void ConsoleBase::dir(ScriptState* scriptState, PassRefPtr<ScriptArguments> argu ments)
71 {
72 internalAddMessage(DirMessageType, LogMessageLevel, scriptState, arguments);
73 }
74
75 void ConsoleBase::dirxml(ScriptState* scriptState, PassRefPtr<ScriptArguments> a rguments)
76 {
77 internalAddMessage(DirXMLMessageType, LogMessageLevel, scriptState, argument s);
78 }
79
80 void ConsoleBase::table(ScriptState* scriptState, PassRefPtr<ScriptArguments> ar guments)
81 {
82 internalAddMessage(TableMessageType, LogMessageLevel, scriptState, arguments );
83 }
84
85 void ConsoleBase::clear(ScriptState* scriptState, PassRefPtr<ScriptArguments> ar guments)
86 {
87 internalAddMessage(ClearMessageType, LogMessageLevel, scriptState, arguments , true);
88 }
89
90 void ConsoleBase::trace(ScriptState* scriptState, PassRefPtr<ScriptArguments> ar guments)
91 {
92 internalAddMessage(TraceMessageType, LogMessageLevel, scriptState, arguments , true, true);
93 }
94
95 void ConsoleBase::assertCondition(ScriptState* scriptState, PassRefPtr<ScriptArg uments> arguments, bool condition)
96 {
97 if (condition)
98 return;
99
100 internalAddMessage(AssertMessageType, ErrorMessageLevel, scriptState, argume nts, true);
101 }
102
103 void ConsoleBase::count(ScriptState* scriptState, PassRefPtr<ScriptArguments> ar guments)
104 {
105 RefPtr<ScriptCallStack> callStack(createScriptCallStack(1));
106 const ScriptCallFrame& lastCaller = callStack->at(0);
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(lastCaller.sourceURL() + ':' + String::number(lastCaller.lineNumber()))
112 : String(title + '@');
113
114 HashCountedSet<String>::AddResult result = m_counts.add(identifier);
115 String message = title + ": " + String::number(result.storedValue->value);
116
117 RefPtr<ConsoleMessage> consoleMessage = ConsoleMessage::create(ConsoleAPIMes sageSource, DebugMessageLevel, message);
118 consoleMessage->setType(CountMessageType);
119 consoleMessage->setScriptState(scriptState);
120 reportMessageToConsole(consoleMessage.release());
121 }
122
123 void ConsoleBase::markTimeline(const String& title)
124 {
125 timeStamp(title);
126 }
127
128 void ConsoleBase::profile(const String& title)
129 {
130 }
131
132 void ConsoleBase::profileEnd(const String& title)
133 {
134 }
135
136 void ConsoleBase::time(const String& title)
137 {
138 TRACE_EVENT_COPY_ASYNC_BEGIN0("blink.console", title.utf8().data(), this);
139
140 if (title.isNull())
141 return;
142
143 m_times.add(title, monotonicallyIncreasingTime());
144 }
145
146 void ConsoleBase::timeEnd(ScriptState* scriptState, const String& title)
147 {
148 TRACE_EVENT_COPY_ASYNC_END0("blink.console", title.utf8().data(), this);
149
150 // Follow Firebug's behavior of requiring a title that is not null or
151 // undefined for timing functions
152 if (title.isNull())
153 return;
154
155 HashMap<String, double>::iterator it = m_times.find(title);
156 if (it == m_times.end())
157 return;
158
159 double startTime = it->value;
160 m_times.remove(it);
161
162 double elapsed = monotonicallyIncreasingTime() - startTime;
163 String message = title + String::format(": %.3fms", elapsed * 1000);
164
165 RefPtr<ConsoleMessage> consoleMessage = ConsoleMessage::create(ConsoleAPIMes sageSource, DebugMessageLevel, message);
166 consoleMessage->setType(TimeEndMessageType);
167 consoleMessage->setScriptState(scriptState);
168 reportMessageToConsole(consoleMessage.release());
169 }
170
171 void ConsoleBase::timeStamp(const String& title)
172 {
173 }
174
175 void ConsoleBase::timeline(ScriptState* scriptState, const String& title)
176 {
177 }
178
179 void ConsoleBase::timelineEnd(ScriptState* scriptState, const String& title)
180 {
181 }
182
183 void ConsoleBase::group(ScriptState* scriptState, PassRefPtr<ScriptArguments> ar guments)
184 {
185 internalAddMessage(StartGroupMessageType, LogMessageLevel, scriptState, argu ments, true);
186 }
187
188 void ConsoleBase::groupCollapsed(ScriptState* scriptState, PassRefPtr<ScriptArgu ments> arguments)
189 {
190 internalAddMessage(StartGroupCollapsedMessageType, LogMessageLevel, scriptSt ate, arguments, true);
191 }
192
193 void ConsoleBase::groupEnd()
194 {
195 internalAddMessage(EndGroupMessageType, LogMessageLevel, nullptr, nullptr, t rue);
196 }
197
198 void ConsoleBase::internalAddMessage(MessageType type, MessageLevel level, Scrip tState* scriptState, PassRefPtr<ScriptArguments> scriptArguments, bool acceptNoA rguments, bool printTrace)
199 {
200 RefPtr<ScriptArguments> arguments = scriptArguments;
201 if (!acceptNoArguments && (!arguments || !arguments->argumentCount()))
202 return;
203
204 String message;
205 bool gotStringMessage = arguments ? arguments->getFirstArgumentAsString(mess age) : false;
206
207 RefPtr<ConsoleMessage> consoleMessage = ConsoleMessage::create(ConsoleAPIMes sageSource, level, gotStringMessage? message : String());
208 consoleMessage->setType(type);
209 consoleMessage->setScriptState(scriptState);
210 consoleMessage->setScriptArguments(arguments);
211
212 size_t stackSize = printTrace ? ScriptCallStack::maxCallStackSizeToCapture : 1;
213 RefPtr<ScriptCallStack> callStack(createScriptCallStackForConsole(stackSize) );
214 consoleMessage->setCallStack(callStack);
215
216 reportMessageToConsole(consoleMessage.release());
217 }
218
219 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/frame/ConsoleBase.h ('k') | sky/engine/core/frame/ConsoleBase.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698