Changeset 63891 in webkit


Ignore:
Timestamp:
Jul 22, 2010 7:33:54 AM (14 years ago)
Author:
yurys@chromium.org
Message:

2010-07-22 Yury Semikhatsky <yurys@chromium.org>

Reviewed by Pavel Feldman.

Web Inspector: should be possible to convert console message arguments to InspectorValues
https://bugs.webkit.org/show_bug.cgi?id=42457

Now it is possible to convert simple JavaScript objects to
InspectorValues.

  • bindings/js/ScriptValue.cpp: (WebCore::jsToInspectorValue): (WebCore::ScriptValue::toInspectorValue):
  • bindings/js/ScriptValue.h:
  • bindings/v8/ScriptValue.cpp: (WebCore::v8ToInspectorValue): (WebCore::ScriptValue::toInspectorValue):
  • bindings/v8/ScriptValue.h:
  • inspector/ConsoleMessage.cpp: console notifications are pushed to RemoteInspectorFrontend instead of InspectorFrontend. (WebCore::ConsoleMessage::CallFrame::buildInspectorObject): (WebCore::ConsoleMessage::addToFrontend): (WebCore::ConsoleMessage::updateRepeatCountInConsole):
  • inspector/ConsoleMessage.h:
  • inspector/InjectedScript.cpp: (WebCore::InjectedScript::wrapForConsole): return InspectorValue instead of SerializedScriptValue
  • inspector/InjectedScript.h:
  • inspector/Inspector.idl:
  • inspector/InspectorBackend.cpp: (WebCore::InspectorBackend::clearConsoleMessages): send response directly from the backend (WebCore::InspectorBackend::remoteFrontend):
  • inspector/InspectorBackend.h:
  • inspector/InspectorController.cpp: (WebCore::InspectorController::addConsoleMessage): (WebCore::InspectorController::clearConsoleMessages): don't send notification to the front end, it will be send either from InspectorBackend.cpp if it was a user request or reset message will be send to the front end if the messages are cleared due to page navigation. (WebCore::InspectorController::populateScriptObjects):
  • inspector/front-end/ConsoleView.js:
  • inspector/front-end/inspector.js:
Location:
trunk/WebCore
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r63889 r63891  
     12010-07-22  Yury Semikhatsky  <yurys@chromium.org>
     2
     3        Reviewed by Pavel Feldman.
     4
     5        Web Inspector: should be possible to convert console message arguments to InspectorValues
     6        https://bugs.webkit.org/show_bug.cgi?id=42457
     7
     8        Now it is possible to convert simple JavaScript objects to
     9        InspectorValues.
     10
     11        * bindings/js/ScriptValue.cpp:
     12        (WebCore::jsToInspectorValue):
     13        (WebCore::ScriptValue::toInspectorValue):
     14        * bindings/js/ScriptValue.h:
     15        * bindings/v8/ScriptValue.cpp:
     16        (WebCore::v8ToInspectorValue):
     17        (WebCore::ScriptValue::toInspectorValue):
     18        * bindings/v8/ScriptValue.h:
     19        * inspector/ConsoleMessage.cpp: console notifications are pushed to RemoteInspectorFrontend instead of InspectorFrontend.
     20        (WebCore::ConsoleMessage::CallFrame::buildInspectorObject):
     21        (WebCore::ConsoleMessage::addToFrontend):
     22        (WebCore::ConsoleMessage::updateRepeatCountInConsole):
     23        * inspector/ConsoleMessage.h:
     24        * inspector/InjectedScript.cpp:
     25        (WebCore::InjectedScript::wrapForConsole): return InspectorValue instead of SerializedScriptValue
     26        * inspector/InjectedScript.h:
     27        * inspector/Inspector.idl:
     28        * inspector/InspectorBackend.cpp:
     29        (WebCore::InspectorBackend::clearConsoleMessages): send response directly from the backend
     30        (WebCore::InspectorBackend::remoteFrontend):
     31        * inspector/InspectorBackend.h:
     32        * inspector/InspectorController.cpp:
     33        (WebCore::InspectorController::addConsoleMessage):
     34        (WebCore::InspectorController::clearConsoleMessages): don't send notification to the front end,
     35        it will be send either from InspectorBackend.cpp if it was a user request or reset message will
     36        be send to the front end if the messages are cleared due to page navigation.
     37        (WebCore::InspectorController::populateScriptObjects):
     38        * inspector/front-end/ConsoleView.js:
     39        * inspector/front-end/inspector.js:
     40
    1412010-07-22  Alexander Pavlov  <apavlov@chromium.org>
    242
  • trunk/WebCore/bindings/js/ScriptValue.cpp

    r57738 r63891  
    3030#include "ScriptValue.h"
    3131
     32#include "InspectorValues.h"
    3233#include "SerializedScriptValue.h"
    3334
     
    9495}
    9596
     97static PassRefPtr<InspectorValue> jsToInspectorValue(ScriptState* scriptState, JSValue value)
     98{
     99    if (!value) {
     100        ASSERT_NOT_REACHED();
     101        return 0;
     102    }
     103    if (value.isNull() || value.isUndefined())
     104        return InspectorValue::null();
     105    if (value.isBoolean())
     106        return InspectorBasicValue::create(value.getBoolean());
     107    if (value.isNumber())
     108        return InspectorBasicValue::create(value.uncheckedGetNumber());
     109    if (value.isString()) {
     110        UString s = value.getString(scriptState);
     111        return InspectorString::create(String(s.data(), s.size()));
     112    }
     113    if (value.isObject()) {
     114        if (isJSArray(&scriptState->globalData(), value)) {
     115            RefPtr<InspectorArray> inspectorArray = InspectorArray::create();
     116            JSArray* array = asArray(value);
     117            unsigned length = array->length();
     118            for (unsigned i = 0; i < length; i++) {
     119                JSValue element = array->getIndex(i);
     120                RefPtr<InspectorValue> elementValue = jsToInspectorValue(scriptState, element);
     121                if (!elementValue) {
     122                    ASSERT_NOT_REACHED();
     123                    elementValue = InspectorValue::null();
     124                }
     125                inspectorArray->push(elementValue);
     126            }
     127            return inspectorArray;
     128        }
     129        RefPtr<InspectorObject> inspectorObject = InspectorObject::create();
     130        JSObject* object = value.getObject();
     131        PropertyNameArray propertyNames(scriptState);
     132        object->getOwnPropertyNames(scriptState, propertyNames);
     133        for (size_t i = 0; i < propertyNames.size(); i++) {
     134            const Identifier& name =  propertyNames[i];
     135            JSValue propertyValue = object->get(scriptState, name);
     136            RefPtr<InspectorValue> inspectorValue = jsToInspectorValue(scriptState, propertyValue);
     137            if (!inspectorValue) {
     138                ASSERT_NOT_REACHED();
     139                inspectorValue = InspectorValue::null();
     140            }
     141            inspectorObject->set(String(name.data(), name.size()), inspectorValue);
     142        }
     143        return inspectorObject;
     144    }
     145    return 0;
     146}
     147
     148PassRefPtr<InspectorValue> ScriptValue::toInspectorValue(ScriptState* scriptState) const
     149{
     150    return jsToInspectorValue(scriptState, m_value.get());
     151}
     152
    96153} // namespace WebCore
  • trunk/WebCore/bindings/js/ScriptValue.h

    r57738 r63891  
    4141namespace WebCore {
    4242
     43class InspectorValue;
    4344class SerializedScriptValue;
    4445
     
    6263    static ScriptValue undefined() { return ScriptValue(JSC::jsUndefined()); }
    6364
     65    PassRefPtr<InspectorValue> toInspectorValue(ScriptState*) const;
     66
    6467private:
    6568    JSC::ProtectedJSValue m_value;
  • trunk/WebCore/bindings/v8/ScriptValue.cpp

    r61748 r63891  
    3232#include "ScriptValue.h"
    3333
     34#include "InspectorValues.h"
    3435#include "ScriptScope.h"
    3536#include "SerializedScriptValue.h"
     
    6768}
    6869
     70static PassRefPtr<InspectorValue> v8ToInspectorValue(v8::Handle<v8::Value> value)
     71{
     72    if (value.IsEmpty()) {
     73        ASSERT_NOT_REACHED();
     74        return 0;
     75    }
     76    if (value->IsNull() || value->IsUndefined())
     77        return InspectorValue::null();
     78    if (value->IsBoolean())
     79        return InspectorBasicValue::create(value->BooleanValue());
     80    if (value->IsNumber())
     81        return InspectorBasicValue::create(value->NumberValue());
     82    if (value->IsString())
     83        return InspectorString::create(toWebCoreString(value));
     84    if (value->IsArray()) {
     85        v8::HandleScope handleScope;
     86        v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(value);
     87        RefPtr<InspectorArray> inspectorArray = InspectorArray::create();
     88        uint32_t length = array->Length();
     89        for (uint32_t i = 0; i < length; i++) {
     90            v8::Local<v8::Value> value = array->Get(v8::Int32::New(i));
     91            RefPtr<InspectorValue> element = v8ToInspectorValue(value);
     92            if (!element) {
     93                ASSERT_NOT_REACHED();
     94                element = InspectorValue::null();
     95            }
     96            inspectorArray->push(element);
     97        }
     98        return inspectorArray;
     99    }
     100    if (value->IsObject()) {
     101        RefPtr<InspectorObject> inspectorObject = InspectorObject::create();
     102
     103        v8::HandleScope handleScope;
     104        v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(value);
     105        v8::Local<v8::Array> propertyNames = object->GetPropertyNames();
     106        uint32_t length = propertyNames->Length();
     107        for (uint32_t i = 0; i < length; i++) {
     108            v8::Local<v8::Value> name = propertyNames->Get(v8::Int32::New(i));
     109            RefPtr<InspectorValue> propertyValue = v8ToInspectorValue(object->Get(name));
     110            if (!propertyValue) {
     111                ASSERT_NOT_REACHED();
     112                continue;
     113            }
     114            inspectorObject->set(toWebCoreStringWithNullCheck(name), propertyValue);
     115        }
     116        return inspectorObject;
     117    }
     118    return 0;
     119}
     120
     121PassRefPtr<InspectorValue> ScriptValue::toInspectorValue(ScriptState*) const
     122{
     123    return v8ToInspectorValue(m_value);
     124}
     125
    69126} // namespace WebCore
  • trunk/WebCore/bindings/v8/ScriptValue.h

    r56049 r63891  
    4444namespace WebCore {
    4545
     46class InspectorValue;
    4647class SerializedScriptValue;
    4748
     
    152153    String toString(ScriptState*) const;
    153154
     155    PassRefPtr<InspectorValue> toInspectorValue(ScriptState*) const;
     156
    154157private:
    155158    mutable v8::Persistent<v8::Value> m_value;
  • trunk/WebCore/inspector/ConsoleMessage.cpp

    r63805 r63891  
    3535#include "InjectedScriptHost.h"
    3636#include "InspectorFrontend.h"
     37#include "InspectorValues.h"
     38#include "RemoteInspectorFrontend.h"
    3739#include "ScriptCallStack.h"
    3840#include "ScriptObject.h"
    39 #include "SerializedScriptValue.h"
    4041
    4142namespace WebCore {
     
    6061}
    6162
    62 ScriptObject ConsoleMessage::CallFrame::buildObject(InspectorFrontend* frontend) const
     63PassRefPtr<InspectorObject> ConsoleMessage::CallFrame::buildInspectorObject() const
    6364{
    64     ScriptObject frame = frontend->newScriptObject();
    65     frame.set("functionName", m_functionName);
    66     frame.set("sourceURL", m_sourceURL.string());
    67     frame.set("lineNumber", m_lineNumber);
     65    RefPtr<InspectorObject> frame = InspectorObject::create();
     66    frame->setString("functionName", m_functionName);
     67    frame->setString("sourceURL", m_sourceURL.string());
     68    frame->setNumber("lineNumber", m_lineNumber);
    6869    return frame;
    6970}
     
    110111
    111112#if ENABLE(INSPECTOR)
    112 void ConsoleMessage::addToFrontend(InspectorFrontend* frontend, InjectedScriptHost* injectedScriptHost)
     113void ConsoleMessage::addToFrontend(RemoteInspectorFrontend* frontend, InjectedScriptHost* injectedScriptHost)
    113114{
    114     ScriptObject jsonObj = frontend->newScriptObject();
    115     jsonObj.set("source", static_cast<int>(m_source));
    116     jsonObj.set("type", static_cast<int>(m_type));
    117     jsonObj.set("level", static_cast<int>(m_level));
    118     jsonObj.set("line", static_cast<int>(m_line));
    119     jsonObj.set("url", m_url);
    120     jsonObj.set("groupLevel", static_cast<int>(m_groupLevel));
    121     jsonObj.set("repeatCount", static_cast<int>(m_repeatCount));
    122     jsonObj.set("message", m_message);
     115    RefPtr<InspectorObject> jsonObj = InspectorObject::create();
     116    jsonObj->setNumber("source", static_cast<int>(m_source));
     117    jsonObj->setNumber("type", static_cast<int>(m_type));
     118    jsonObj->setNumber("level", static_cast<int>(m_level));
     119    jsonObj->setNumber("line", static_cast<int>(m_line));
     120    jsonObj->setString("url", m_url);
     121    jsonObj->setNumber("groupLevel", static_cast<int>(m_groupLevel));
     122    jsonObj->setNumber("repeatCount", static_cast<int>(m_repeatCount));
     123    jsonObj->setString("message", m_message);
    123124    if (!m_arguments.isEmpty()) {
    124         ScriptArray jsonArgs = frontend->newScriptArray();
     125        RefPtr<InspectorArray> jsonArgs = InspectorArray::create();
    125126        InjectedScript injectedScript = injectedScriptHost->injectedScriptFor(m_scriptState.get());
    126127        for (unsigned i = 0; i < m_arguments.size(); ++i) {
    127             RefPtr<SerializedScriptValue> serializedValue = injectedScript.wrapForConsole(m_arguments[i]);
    128             if (!jsonArgs.set(i, serializedValue.get())) {
     128            RefPtr<InspectorValue> inspectorValue = injectedScript.wrapForConsole(m_arguments[i]);
     129            if (!inspectorValue) {
    129130                ASSERT_NOT_REACHED();
    130131                return;
    131132            }
     133            jsonArgs->push(inspectorValue);
    132134        }
    133         jsonObj.set("parameters", jsonArgs);
     135        jsonObj->set("parameters", jsonArgs);
    134136    }
    135137    if (!m_frames.isEmpty()) {
    136         ScriptArray frames = frontend->newScriptArray();
     138        RefPtr<InspectorArray> frames = InspectorArray::create();
    137139        for (unsigned i = 0; i < m_frames.size(); i++)
    138             frames.set(i, m_frames.at(i).buildObject(frontend));
    139         jsonObj.set("stackTrace", frames);
     140            frames->push(m_frames.at(i).buildInspectorObject());
     141        jsonObj->set("stackTrace", frames);
    140142    }
    141143    frontend->addConsoleMessage(jsonObj);
    142144}
    143145
    144 void ConsoleMessage::updateRepeatCountInConsole(InspectorFrontend* frontend)
     146void ConsoleMessage::updateRepeatCountInConsole(RemoteInspectorFrontend* frontend)
    145147{
    146148    frontend->updateConsoleMessageRepeatCount(m_repeatCount);
  • trunk/WebCore/inspector/ConsoleMessage.h

    r63662 r63891  
    4141namespace WebCore {
    4242class InjectedScriptHost;
    43 class InspectorFrontend;
     43class InspectorObject;
     44class RemoteInspectorFrontend;
    4445class ScriptCallFrame;
    4546class ScriptCallStack;
     
    5253
    5354#if ENABLE(INSPECTOR)
    54     void addToFrontend(InspectorFrontend*, InjectedScriptHost*);
    55     void updateRepeatCountInConsole(InspectorFrontend* frontend);
     55    void addToFrontend(RemoteInspectorFrontend*, InjectedScriptHost*);
     56    void updateRepeatCountInConsole(RemoteInspectorFrontend* frontend);
    5657#endif
    5758    void incrementCount() { ++m_repeatCount; }
     
    6768        CallFrame();
    6869        bool isEqual(const CallFrame& o) const;
    69         ScriptObject buildObject(InspectorFrontend* frontend) const;
     70        PassRefPtr<InspectorObject> buildInspectorObject() const;
    7071
    7172    private:
  • trunk/WebCore/inspector/InjectedScript.cpp

    r56841 r63891  
    3434#if ENABLE(INSPECTOR)
    3535
     36#include "InspectorValues.h"
    3637#include "PlatformString.h"
    3738#include "SerializedScriptValue.h"
     
    7475#endif
    7576
    76 PassRefPtr<SerializedScriptValue> InjectedScript::wrapForConsole(ScriptValue value)
     77PassRefPtr<InspectorValue> InjectedScript::wrapForConsole(ScriptValue value)
    7778{
    7879    ASSERT(!hasNoValue());
     
    8384    ScriptValue r = wrapFunction.call(hadException);
    8485    if (hadException)
    85         return SerializedScriptValue::create("<exception>");
    86     return r.serialize(m_injectedScriptObject.scriptState());
     86        return InspectorString::create("<exception>");
     87    return r.toInspectorValue(m_injectedScriptObject.scriptState());
    8788}
    8889
  • trunk/WebCore/inspector/InjectedScript.h

    r56841 r63891  
    3939namespace WebCore {
    4040
     41class InspectorValue;
    4142class SerializedScriptValue;
    4243class String;
     
    5354    PassRefPtr<SerializedScriptValue> callFrames();
    5455#endif
    55     PassRefPtr<SerializedScriptValue> wrapForConsole(ScriptValue);
     56    PassRefPtr<InspectorValue> wrapForConsole(ScriptValue);
    5657    void releaseWrapperObjectGroup(const String&);
    5758
  • trunk/WebCore/inspector/Inspector.idl

    r63886 r63891  
    3333module core {
    3434    interface [Conditional=INSPECTOR] Inspector {
     35        [notify] void addConsoleMessage(out Object messageObj);
    3536        [notify] void addRecordToTimeline(out Object record);
    3637        [notify] void addNodesToSearchResult(out Array nodeIds);
     
    4243        [notify] void setDetachedRoot(out Object root);
    4344        [notify] void setDocument(out Value root);
     45        [notify] void updateConsoleMessageExpiredCount(out unsigned long count);
     46        [notify] void updateConsoleMessageRepeatCount(out unsigned long count);
    4447
    4548        void storeLastActivePanel(in String panelName);
     
    118121        void pushNodeByPathToFrontend(in long callId, in String path, out long nodeId);
    119122
    120         void clearConsoleMessages();
     123        void clearConsoleMessages(in long callId);
    121124
    122125        void highlightDOMNode(in long nodeId);
  • trunk/WebCore/inspector/InspectorBackend.cpp

    r63886 r63891  
    5050#include "Page.h"
    5151#include "Pasteboard.h"
     52#include "RemoteInspectorFrontend.h"
    5253#include "ScriptArray.h"
    5354#include "ScriptBreakpoint.h"
     
    413414}
    414415
    415 void InspectorBackend::clearConsoleMessages()
    416 {
    417     if (m_inspectorController)
     416void InspectorBackend::clearConsoleMessages(long callId)
     417{
     418    if (m_inspectorController) {
    418419        m_inspectorController->clearConsoleMessages();
     420        if (RemoteInspectorFrontend* frontend = remoteFrontend())
     421            frontend->didClearConsoleMessages(callId);
     422    }
    419423}
    420424
     
    598602}
    599603
     604RemoteInspectorFrontend* InspectorBackend::remoteFrontend()
     605{
     606    if (!m_inspectorController)
     607        return 0;
     608    return m_inspectorController->m_remoteFrontend.get();
     609}
     610
    600611void InspectorBackend::addScriptToEvaluateOnLoad(const String& source)
    601612{
  • trunk/WebCore/inspector/InspectorBackend.h

    r63886 r63891  
    4444class InspectorFrontend;
    4545class Node;
     46class RemoteInspectorFrontend;
    4647class Storage;
    4748
     
    134135    void pushNodeByPathToFrontend(long callId, const String& path);
    135136
    136     void clearConsoleMessages();
     137    void clearConsoleMessages(long callId);
    137138
    138139    void getStyles(long callId, long nodeId, bool authOnly);
     
    180181#endif
    181182    InspectorFrontend* inspectorFrontend();
     183    RemoteInspectorFrontend* remoteFrontend();
    182184    Node* nodeForId(long nodeId);
    183185
  • trunk/WebCore/inspector/InspectorBackend.idl

    r63886 r63891  
    108108        void pushNodeByPathToFrontend(in long callId, in DOMString path);
    109109
    110         void clearConsoleMessages();
     110        void clearConsoleMessages(in long callId);
    111111
    112112        void highlightDOMNode(in long nodeId);
  • trunk/WebCore/inspector/InspectorController.cpp

    r63805 r63891  
    364364        m_previousMessage->incrementCount();
    365365        if (m_frontend)
    366             m_previousMessage->updateRepeatCountInConsole(m_frontend.get());
     366            m_previousMessage->updateRepeatCountInConsole(m_remoteFrontend.get());
    367367    } else {
    368368        m_previousMessage = consoleMessage.get();
    369369        m_consoleMessages.append(consoleMessage);
    370370        if (m_frontend)
    371             m_previousMessage->addToFrontend(m_frontend.get(), m_injectedScriptHost.get());
     371            m_previousMessage->addToFrontend(m_remoteFrontend.get(), m_injectedScriptHost.get());
    372372    }
    373373
     
    387387    if (m_domAgent)
    388388        m_domAgent->releaseDanglingNodes();
    389     if (m_frontend)
    390         m_frontend->clearConsoleMessages();
    391389}
    392390
     
    657655
    658656    if (m_expiredConsoleMessageCount)
    659         m_frontend->updateConsoleMessageExpiredCount(m_expiredConsoleMessageCount);
     657        m_remoteFrontend->updateConsoleMessageExpiredCount(m_expiredConsoleMessageCount);
    660658    unsigned messageCount = m_consoleMessages.size();
    661659    for (unsigned i = 0; i < messageCount; ++i)
    662         m_consoleMessages[i]->addToFrontend(m_frontend.get(), m_injectedScriptHost.get());
     660        m_consoleMessages[i]->addToFrontend(m_remoteFrontend.get(), m_injectedScriptHost.get());
    663661
    664662#if ENABLE(JAVASCRIPT_DEBUGGER)
  • trunk/WebCore/inspector/front-end/ConsoleView.js

    r63805 r63891  
    297297    requestClearMessages: function()
    298298    {
    299         InspectorBackend.clearConsoleMessages();
     299        InspectorBackend.clearConsoleMessages(WebInspector.Callback.wrap(this.clearMessages.bind(this)));
    300300    },
    301301
     
    11281128    }
    11291129}
     1130
     1131WebInspector.didClearConsoleMessages = WebInspector.Callback.processCallback;
  • trunk/WebCore/inspector/front-end/inspector.js

    r63741 r63891  
    11281128{
    11291129    this.currentPanel = this.panels.audits;
    1130 }
    1131 
    1132 WebInspector.clearConsoleMessages = function()
    1133 {
    1134     WebInspector.console.clearMessages();
    11351130}
    11361131
Note: See TracChangeset for help on using the changeset viewer.