• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
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.
18  *
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.
29  */
30 
31 #include "config.h"
32 #include "ConsoleMessage.h"
33 
34 #include "InspectorFrontend.h"
35 #include "ScriptCallStack.h"
36 #include "ScriptObject.h"
37 #include "ScriptObjectQuarantine.h"
38 
39 namespace WebCore {
40 
ConsoleMessage(MessageSource s,MessageType t,MessageLevel l,const String & m,unsigned li,const String & u,unsigned g)41 ConsoleMessage::ConsoleMessage(MessageSource s, MessageType t, MessageLevel l, const String& m, unsigned li, const String& u, unsigned g)
42     : m_source(s)
43     , m_type(t)
44     , m_level(l)
45     , m_message(m)
46     , m_line(li)
47     , m_url(u)
48     , m_groupLevel(g)
49     , m_repeatCount(1)
50 {
51 }
52 
ConsoleMessage(MessageSource s,MessageType t,MessageLevel l,ScriptCallStack * callStack,unsigned g,bool storeTrace)53 ConsoleMessage::ConsoleMessage(MessageSource s, MessageType t, MessageLevel l, ScriptCallStack* callStack, unsigned g, bool storeTrace)
54     : m_source(s)
55     , m_type(t)
56     , m_level(l)
57     , m_wrappedArguments(callStack->at(0).argumentCount())
58     , m_frames(storeTrace ? callStack->size() : 0)
59     , m_groupLevel(g)
60     , m_repeatCount(1)
61 {
62     const ScriptCallFrame& lastCaller = callStack->at(0);
63     m_line = lastCaller.lineNumber();
64     m_url = lastCaller.sourceURL().string();
65 
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.
69     if (storeTrace) {
70         for (unsigned i = 0; i < callStack->size(); ++i)
71             m_frames[i] = callStack->at(i).functionName();
72     }
73 
74     for (unsigned i = 0; i < lastCaller.argumentCount(); ++i)
75         m_wrappedArguments[i] = quarantineValue(callStack->state(), lastCaller.argumentAt(i));
76 }
77 
addToConsole(InspectorFrontend * frontend)78 void ConsoleMessage::addToConsole(InspectorFrontend* frontend)
79 {
80     ScriptObject jsonObj = frontend->newScriptObject();
81     jsonObj.set("source", static_cast<int>(m_source));
82     jsonObj.set("type", static_cast<int>(m_type));
83     jsonObj.set("level", static_cast<int>(m_level));
84     jsonObj.set("line", static_cast<int>(m_line));
85     jsonObj.set("url", m_url);
86     jsonObj.set("groupLevel", static_cast<int>(m_groupLevel));
87     jsonObj.set("repeatCount", static_cast<int>(m_repeatCount));
88     frontend->addMessageToConsole(jsonObj, m_frames, m_wrappedArguments,  m_message);
89 }
90 
isEqual(ScriptState * state,ConsoleMessage * msg) const91 bool ConsoleMessage::isEqual(ScriptState* state, ConsoleMessage* msg) const
92 {
93     if (msg->m_wrappedArguments.size() != m_wrappedArguments.size())
94         return false;
95     if (!state && msg->m_wrappedArguments.size())
96         return false;
97 
98     ASSERT_ARG(state, state || msg->m_wrappedArguments.isEmpty());
99 
100     for (size_t i = 0; i < msg->m_wrappedArguments.size(); ++i) {
101         if (!m_wrappedArguments[i].isEqual(state, msg->m_wrappedArguments[i]))
102             return false;
103     }
104 
105     size_t frameCount = msg->m_frames.size();
106     if (frameCount != m_frames.size())
107         return false;
108 
109     for (size_t i = 0; i < frameCount; ++i) {
110         if (m_frames[i] != msg->m_frames[i])
111             return false;
112     }
113 
114     return msg->m_source == m_source
115         && msg->m_type == m_type
116         && msg->m_level == m_level
117         && msg->m_message == m_message
118         && msg->m_line == m_line
119         && msg->m_url == m_url
120         && msg->m_groupLevel == m_groupLevel;
121 }
122 
123 } // namespace WebCore
124