Changeset 63891 in webkit
- Timestamp:
- Jul 22, 2010 7:33:54 AM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r63889 r63891 1 2010-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 1 41 2010-07-22 Alexander Pavlov <apavlov@chromium.org> 2 42 -
trunk/WebCore/bindings/js/ScriptValue.cpp
r57738 r63891 30 30 #include "ScriptValue.h" 31 31 32 #include "InspectorValues.h" 32 33 #include "SerializedScriptValue.h" 33 34 … … 94 95 } 95 96 97 static 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 148 PassRefPtr<InspectorValue> ScriptValue::toInspectorValue(ScriptState* scriptState) const 149 { 150 return jsToInspectorValue(scriptState, m_value.get()); 151 } 152 96 153 } // namespace WebCore -
trunk/WebCore/bindings/js/ScriptValue.h
r57738 r63891 41 41 namespace WebCore { 42 42 43 class InspectorValue; 43 44 class SerializedScriptValue; 44 45 … … 62 63 static ScriptValue undefined() { return ScriptValue(JSC::jsUndefined()); } 63 64 65 PassRefPtr<InspectorValue> toInspectorValue(ScriptState*) const; 66 64 67 private: 65 68 JSC::ProtectedJSValue m_value; -
trunk/WebCore/bindings/v8/ScriptValue.cpp
r61748 r63891 32 32 #include "ScriptValue.h" 33 33 34 #include "InspectorValues.h" 34 35 #include "ScriptScope.h" 35 36 #include "SerializedScriptValue.h" … … 67 68 } 68 69 70 static 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 121 PassRefPtr<InspectorValue> ScriptValue::toInspectorValue(ScriptState*) const 122 { 123 return v8ToInspectorValue(m_value); 124 } 125 69 126 } // namespace WebCore -
trunk/WebCore/bindings/v8/ScriptValue.h
r56049 r63891 44 44 namespace WebCore { 45 45 46 class InspectorValue; 46 47 class SerializedScriptValue; 47 48 … … 152 153 String toString(ScriptState*) const; 153 154 155 PassRefPtr<InspectorValue> toInspectorValue(ScriptState*) const; 156 154 157 private: 155 158 mutable v8::Persistent<v8::Value> m_value; -
trunk/WebCore/inspector/ConsoleMessage.cpp
r63805 r63891 35 35 #include "InjectedScriptHost.h" 36 36 #include "InspectorFrontend.h" 37 #include "InspectorValues.h" 38 #include "RemoteInspectorFrontend.h" 37 39 #include "ScriptCallStack.h" 38 40 #include "ScriptObject.h" 39 #include "SerializedScriptValue.h"40 41 41 42 namespace WebCore { … … 60 61 } 61 62 62 ScriptObject ConsoleMessage::CallFrame::buildObject(InspectorFrontend* frontend) const63 PassRefPtr<InspectorObject> ConsoleMessage::CallFrame::buildInspectorObject() const 63 64 { 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); 68 69 return frame; 69 70 } … … 110 111 111 112 #if ENABLE(INSPECTOR) 112 void ConsoleMessage::addToFrontend( InspectorFrontend* frontend, InjectedScriptHost* injectedScriptHost)113 void ConsoleMessage::addToFrontend(RemoteInspectorFrontend* frontend, InjectedScriptHost* injectedScriptHost) 113 114 { 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); 123 124 if (!m_arguments.isEmpty()) { 124 ScriptArray jsonArgs = frontend->newScriptArray();125 RefPtr<InspectorArray> jsonArgs = InspectorArray::create(); 125 126 InjectedScript injectedScript = injectedScriptHost->injectedScriptFor(m_scriptState.get()); 126 127 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) { 129 130 ASSERT_NOT_REACHED(); 130 131 return; 131 132 } 133 jsonArgs->push(inspectorValue); 132 134 } 133 jsonObj .set("parameters", jsonArgs);135 jsonObj->set("parameters", jsonArgs); 134 136 } 135 137 if (!m_frames.isEmpty()) { 136 ScriptArray frames = frontend->newScriptArray();138 RefPtr<InspectorArray> frames = InspectorArray::create(); 137 139 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); 140 142 } 141 143 frontend->addConsoleMessage(jsonObj); 142 144 } 143 145 144 void ConsoleMessage::updateRepeatCountInConsole( InspectorFrontend* frontend)146 void ConsoleMessage::updateRepeatCountInConsole(RemoteInspectorFrontend* frontend) 145 147 { 146 148 frontend->updateConsoleMessageRepeatCount(m_repeatCount); -
trunk/WebCore/inspector/ConsoleMessage.h
r63662 r63891 41 41 namespace WebCore { 42 42 class InjectedScriptHost; 43 class InspectorFrontend; 43 class InspectorObject; 44 class RemoteInspectorFrontend; 44 45 class ScriptCallFrame; 45 46 class ScriptCallStack; … … 52 53 53 54 #if ENABLE(INSPECTOR) 54 void addToFrontend( InspectorFrontend*, InjectedScriptHost*);55 void updateRepeatCountInConsole( InspectorFrontend* frontend);55 void addToFrontend(RemoteInspectorFrontend*, InjectedScriptHost*); 56 void updateRepeatCountInConsole(RemoteInspectorFrontend* frontend); 56 57 #endif 57 58 void incrementCount() { ++m_repeatCount; } … … 67 68 CallFrame(); 68 69 bool isEqual(const CallFrame& o) const; 69 ScriptObject buildObject(InspectorFrontend* frontend) const;70 PassRefPtr<InspectorObject> buildInspectorObject() const; 70 71 71 72 private: -
trunk/WebCore/inspector/InjectedScript.cpp
r56841 r63891 34 34 #if ENABLE(INSPECTOR) 35 35 36 #include "InspectorValues.h" 36 37 #include "PlatformString.h" 37 38 #include "SerializedScriptValue.h" … … 74 75 #endif 75 76 76 PassRefPtr< SerializedScriptValue> InjectedScript::wrapForConsole(ScriptValue value)77 PassRefPtr<InspectorValue> InjectedScript::wrapForConsole(ScriptValue value) 77 78 { 78 79 ASSERT(!hasNoValue()); … … 83 84 ScriptValue r = wrapFunction.call(hadException); 84 85 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()); 87 88 } 88 89 -
trunk/WebCore/inspector/InjectedScript.h
r56841 r63891 39 39 namespace WebCore { 40 40 41 class InspectorValue; 41 42 class SerializedScriptValue; 42 43 class String; … … 53 54 PassRefPtr<SerializedScriptValue> callFrames(); 54 55 #endif 55 PassRefPtr< SerializedScriptValue> wrapForConsole(ScriptValue);56 PassRefPtr<InspectorValue> wrapForConsole(ScriptValue); 56 57 void releaseWrapperObjectGroup(const String&); 57 58 -
trunk/WebCore/inspector/Inspector.idl
r63886 r63891 33 33 module core { 34 34 interface [Conditional=INSPECTOR] Inspector { 35 [notify] void addConsoleMessage(out Object messageObj); 35 36 [notify] void addRecordToTimeline(out Object record); 36 37 [notify] void addNodesToSearchResult(out Array nodeIds); … … 42 43 [notify] void setDetachedRoot(out Object root); 43 44 [notify] void setDocument(out Value root); 45 [notify] void updateConsoleMessageExpiredCount(out unsigned long count); 46 [notify] void updateConsoleMessageRepeatCount(out unsigned long count); 44 47 45 48 void storeLastActivePanel(in String panelName); … … 118 121 void pushNodeByPathToFrontend(in long callId, in String path, out long nodeId); 119 122 120 void clearConsoleMessages( );123 void clearConsoleMessages(in long callId); 121 124 122 125 void highlightDOMNode(in long nodeId); -
trunk/WebCore/inspector/InspectorBackend.cpp
r63886 r63891 50 50 #include "Page.h" 51 51 #include "Pasteboard.h" 52 #include "RemoteInspectorFrontend.h" 52 53 #include "ScriptArray.h" 53 54 #include "ScriptBreakpoint.h" … … 413 414 } 414 415 415 void InspectorBackend::clearConsoleMessages( )416 { 417 if (m_inspectorController) 416 void InspectorBackend::clearConsoleMessages(long callId) 417 { 418 if (m_inspectorController) { 418 419 m_inspectorController->clearConsoleMessages(); 420 if (RemoteInspectorFrontend* frontend = remoteFrontend()) 421 frontend->didClearConsoleMessages(callId); 422 } 419 423 } 420 424 … … 598 602 } 599 603 604 RemoteInspectorFrontend* InspectorBackend::remoteFrontend() 605 { 606 if (!m_inspectorController) 607 return 0; 608 return m_inspectorController->m_remoteFrontend.get(); 609 } 610 600 611 void InspectorBackend::addScriptToEvaluateOnLoad(const String& source) 601 612 { -
trunk/WebCore/inspector/InspectorBackend.h
r63886 r63891 44 44 class InspectorFrontend; 45 45 class Node; 46 class RemoteInspectorFrontend; 46 47 class Storage; 47 48 … … 134 135 void pushNodeByPathToFrontend(long callId, const String& path); 135 136 136 void clearConsoleMessages( );137 void clearConsoleMessages(long callId); 137 138 138 139 void getStyles(long callId, long nodeId, bool authOnly); … … 180 181 #endif 181 182 InspectorFrontend* inspectorFrontend(); 183 RemoteInspectorFrontend* remoteFrontend(); 182 184 Node* nodeForId(long nodeId); 183 185 -
trunk/WebCore/inspector/InspectorBackend.idl
r63886 r63891 108 108 void pushNodeByPathToFrontend(in long callId, in DOMString path); 109 109 110 void clearConsoleMessages( );110 void clearConsoleMessages(in long callId); 111 111 112 112 void highlightDOMNode(in long nodeId); -
trunk/WebCore/inspector/InspectorController.cpp
r63805 r63891 364 364 m_previousMessage->incrementCount(); 365 365 if (m_frontend) 366 m_previousMessage->updateRepeatCountInConsole(m_ frontend.get());366 m_previousMessage->updateRepeatCountInConsole(m_remoteFrontend.get()); 367 367 } else { 368 368 m_previousMessage = consoleMessage.get(); 369 369 m_consoleMessages.append(consoleMessage); 370 370 if (m_frontend) 371 m_previousMessage->addToFrontend(m_ frontend.get(), m_injectedScriptHost.get());371 m_previousMessage->addToFrontend(m_remoteFrontend.get(), m_injectedScriptHost.get()); 372 372 } 373 373 … … 387 387 if (m_domAgent) 388 388 m_domAgent->releaseDanglingNodes(); 389 if (m_frontend)390 m_frontend->clearConsoleMessages();391 389 } 392 390 … … 657 655 658 656 if (m_expiredConsoleMessageCount) 659 m_ frontend->updateConsoleMessageExpiredCount(m_expiredConsoleMessageCount);657 m_remoteFrontend->updateConsoleMessageExpiredCount(m_expiredConsoleMessageCount); 660 658 unsigned messageCount = m_consoleMessages.size(); 661 659 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()); 663 661 664 662 #if ENABLE(JAVASCRIPT_DEBUGGER) -
trunk/WebCore/inspector/front-end/ConsoleView.js
r63805 r63891 297 297 requestClearMessages: function() 298 298 { 299 InspectorBackend.clearConsoleMessages( );299 InspectorBackend.clearConsoleMessages(WebInspector.Callback.wrap(this.clearMessages.bind(this))); 300 300 }, 301 301 … … 1128 1128 } 1129 1129 } 1130 1131 WebInspector.didClearConsoleMessages = WebInspector.Callback.processCallback; -
trunk/WebCore/inspector/front-end/inspector.js
r63741 r63891 1128 1128 { 1129 1129 this.currentPanel = this.panels.audits; 1130 }1131 1132 WebInspector.clearConsoleMessages = function()1133 {1134 WebInspector.console.clearMessages();1135 1130 } 1136 1131
Note: See TracChangeset
for help on using the changeset viewer.