2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com>
4 * Copyright (C) 2009 Google Inc. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
16 * its contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "ConsoleMessage.h"
34 #include "JSInspectedObjectWrapper.h"
35 #include "ScriptCallStack.h"
36 #include "ScriptCallFrame.h"
37 #include "ScriptFunctionCall.h"
38 #include "ScriptObjectQuarantine.h"
39 #include "ScriptString.h"
43 ConsoleMessage::ConsoleMessage(MessageSource s, MessageLevel l, const String& m, unsigned li, const String& u, unsigned g)
54 ConsoleMessage::ConsoleMessage(MessageSource s, MessageLevel l, ScriptCallStack* callStack, unsigned g, bool storeTrace)
57 , m_wrappedArguments(callStack->at(0).argumentCount())
58 , m_frames(storeTrace ? callStack->size() : 0)
62 const ScriptCallFrame& lastCaller = callStack->at(0);
63 m_line = lastCaller.lineNumber();
64 m_url = lastCaller.sourceURL().string();
66 // FIXME: For now, just store function names as strings.
67 // As ScriptCallStack start storing line number and source URL for all
68 // frames, refactor to use that, as well.
70 for (unsigned i = 0; i < callStack->size(); ++i)
71 m_frames[i] = callStack->at(i).functionName();
74 for (unsigned i = 0; i < lastCaller.argumentCount(); ++i)
75 m_wrappedArguments[i] = quarantineValue(callStack->state(), lastCaller.argumentAt(i));
78 void ConsoleMessage::addToConsole(ScriptState* scriptState, const ScriptObject& webInspector)
80 ScriptFunctionCall messageConstructor(scriptState, webInspector, "ConsoleMessage");
81 messageConstructor.appendArgument(static_cast<unsigned int>(m_source));
82 messageConstructor.appendArgument(static_cast<unsigned int>(m_level));
83 messageConstructor.appendArgument(m_line);
84 messageConstructor.appendArgument(m_url);
85 messageConstructor.appendArgument(m_groupLevel);
86 messageConstructor.appendArgument(m_repeatCount);
88 if (!m_frames.isEmpty()) {
89 for (unsigned i = 0; i < m_frames.size(); ++i)
90 messageConstructor.appendArgument(m_frames[i]);
91 } else if (!m_wrappedArguments.isEmpty()) {
92 for (unsigned i = 0; i < m_wrappedArguments.size(); ++i)
93 messageConstructor.appendArgument(m_wrappedArguments[i]);
95 messageConstructor.appendArgument(m_message);
97 bool hadException = false;
98 ScriptObject message = messageConstructor.construct(hadException);
102 ScriptFunctionCall addMessageToConsole(scriptState, webInspector, "addMessageToConsole");
103 addMessageToConsole.appendArgument(message);
104 addMessageToConsole.call(hadException);
107 bool ConsoleMessage::isEqual(ScriptState* state, ConsoleMessage* msg) const
109 if (msg->m_wrappedArguments.size() != m_wrappedArguments.size() ||
110 (!state && msg->m_wrappedArguments.size()))
113 ASSERT_ARG(state, state);
115 for (size_t i = 0; i < msg->m_wrappedArguments.size(); ++i)
116 if (!m_wrappedArguments[i].isEqual(state, msg->m_wrappedArguments[i]))
119 size_t frameCount = msg->m_frames.size();
120 if (frameCount != m_frames.size())
123 for (size_t i = 0; i < frameCount; ++i)
124 if (m_frames[i] != msg->m_frames[i])
127 return msg->m_source == m_source
128 && msg->m_level == m_level
129 && msg->m_message == m_message
130 && msg->m_line == m_line
131 && msg->m_url == m_url
132 && msg->m_groupLevel == m_groupLevel;
135 } // namespace WebCore