Web Inspector: Remove the references to Node in InjectedScript
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 21 Dec 2013 02:47:10 +0000 (02:47 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 21 Dec 2013 02:47:10 +0000 (02:47 +0000)
https://bugs.webkit.org/show_bug.cgi?id=126091

Patch by Joseph Pecoraro <pecoraro@apple.com> on 2013-12-20
Reviewed by Timothy Hatcher.

Remove the last DOM references from InjectedScript so that
InjectedScript can move down into JavaScriptCore. The only
remaining references were to Nodes, which are all just thin
wrappers around existing functions. Move Node / JSNode (JSValue)
conversion into InspectorDOMAgent, where it was used.

No new tests, no observable change in functionality.

* bindings/js/JSInjectedScriptHostCustom.cpp:
* inspector/InjectedScript.cpp:
(WebCore::InjectedScript::inspectObject):
(WebCore::InjectedScript::releaseObject):
* inspector/InjectedScript.h:
* inspector/InjectedScriptHost.h:
* inspector/InjectedScriptSource.js:
* inspector/InspectorDOMAgent.cpp:
(WebCore::InspectorDOMAgent::focusNode):
(WebCore::InspectorDOMAgent::highlightNode):
(WebCore::InspectorDOMAgent::requestNode):
(WebCore::InspectorDOMAgent::nodeForObjectId):
(WebCore::InspectorDOMAgent::resolveNode):
(WebCore::InspectorDOMAgent::scriptValueAsNode):
(WebCore::InspectorDOMAgent::nodeAsScriptValue):
* inspector/InspectorDOMAgent.h:
* inspector/PageConsoleAgent.cpp:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@160955 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSInjectedScriptHostCustom.cpp
Source/WebCore/inspector/InjectedScript.cpp
Source/WebCore/inspector/InjectedScript.h
Source/WebCore/inspector/InjectedScriptHost.h
Source/WebCore/inspector/InjectedScriptSource.js
Source/WebCore/inspector/InspectorDOMAgent.cpp
Source/WebCore/inspector/InspectorDOMAgent.h
Source/WebCore/inspector/PageConsoleAgent.cpp

index 7638c06..44422af 100644 (file)
@@ -1,3 +1,36 @@
+2013-12-20  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Web Inspector: Remove the references to Node in InjectedScript
+        https://bugs.webkit.org/show_bug.cgi?id=126091
+
+        Reviewed by Timothy Hatcher.
+
+        Remove the last DOM references from InjectedScript so that
+        InjectedScript can move down into JavaScriptCore. The only
+        remaining references were to Nodes, which are all just thin
+        wrappers around existing functions. Move Node / JSNode (JSValue)
+        conversion into InspectorDOMAgent, where it was used.
+
+        No new tests, no observable change in functionality.
+
+        * bindings/js/JSInjectedScriptHostCustom.cpp:
+        * inspector/InjectedScript.cpp:
+        (WebCore::InjectedScript::inspectObject):
+        (WebCore::InjectedScript::releaseObject):
+        * inspector/InjectedScript.h:
+        * inspector/InjectedScriptHost.h:
+        * inspector/InjectedScriptSource.js:
+        * inspector/InspectorDOMAgent.cpp:
+        (WebCore::InspectorDOMAgent::focusNode):
+        (WebCore::InspectorDOMAgent::highlightNode):
+        (WebCore::InspectorDOMAgent::requestNode):
+        (WebCore::InspectorDOMAgent::nodeForObjectId):
+        (WebCore::InspectorDOMAgent::resolveNode):
+        (WebCore::InspectorDOMAgent::scriptValueAsNode):
+        (WebCore::InspectorDOMAgent::nodeAsScriptValue):
+        * inspector/InspectorDOMAgent.h:
+        * inspector/PageConsoleAgent.cpp:
+
 2013-12-20  Myles C. Maxfield  <mmaxfield@apple.com>
 
         Faster implementation of text-decoration-skip: ink
index 7ff5d5f..996080f 100644 (file)
@@ -59,22 +59,6 @@ using namespace JSC;
 
 namespace WebCore {
 
-Node* InjectedScriptHost::scriptValueAsNode(Deprecated::ScriptValue value)
-{
-    if (!value.isObject() || value.isNull())
-        return 0;
-    return toNode(value.jsValue());
-}
-
-Deprecated::ScriptValue InjectedScriptHost::nodeAsScriptValue(JSC::ExecState* state, Node* node)
-{
-    if (!shouldAllowAccessToNode(state, node))
-        return Deprecated::ScriptValue(state->vm(), jsNull());
-
-    JSLockHolder lock(state);
-    return Deprecated::ScriptValue(state->vm(), toJS(state, deprecatedGlobalObjectForPrototype(state), node));
-}
-
 JSValue JSInjectedScriptHost::internalConstructorName(ExecState* exec)
 {
     if (exec->argumentCount() < 1)
index 99ba9df..d134a33 100644 (file)
@@ -144,29 +144,6 @@ void InjectedScript::getInternalProperties(ErrorString* errorString, const Strin
         *properties = array;
 }
 
-Node* InjectedScript::nodeForObjectId(const String& objectId)
-{
-    if (hasNoValue() || !canAccessInspectedWindow())
-        return 0;
-
-    Deprecated::ScriptFunctionCall function(injectedScriptObject(), "nodeForObjectId", WebCore::functionCallHandlerFromAnyThread);
-    function.appendArgument(objectId);
-
-    bool hadException = false;
-    Deprecated::ScriptValue resultValue = callFunctionWithEvalEnabled(function, hadException);
-    ASSERT(!hadException);
-
-    return InjectedScriptHost::scriptValueAsNode(resultValue);
-}
-
-void InjectedScript::releaseObject(const String& objectId)
-{
-    Deprecated::ScriptFunctionCall function(injectedScriptObject(), "releaseObject", WebCore::functionCallHandlerFromAnyThread);
-    function.appendArgument(objectId);
-    RefPtr<InspectorValue> result;
-    makeCall(function, &result);
-}
-
 #if ENABLE(JAVASCRIPT_DEBUGGER)
 PassRefPtr<Array<CallFrame>> InjectedScript::wrapCallFrames(const Deprecated::ScriptValue& callFrames)
 {
@@ -217,11 +194,6 @@ PassRefPtr<Inspector::TypeBuilder::Runtime::RemoteObject> InjectedScript::wrapTa
     return Inspector::TypeBuilder::Runtime::RemoteObject::runtimeCast(rawResult);
 }
 
-PassRefPtr<Inspector::TypeBuilder::Runtime::RemoteObject> InjectedScript::wrapNode(Node* node, const String& groupName)
-{
-    return wrapObject(nodeAsScriptValue(node), groupName);
-}
-
 Deprecated::ScriptValue InjectedScript::findObjectById(const String& objectId) const
 {
     ASSERT(!hasNoValue());
@@ -234,11 +206,19 @@ Deprecated::ScriptValue InjectedScript::findObjectById(const String& objectId) c
     return resultValue;
 }
 
-void InjectedScript::inspectNode(Node* node)
+void InjectedScript::inspectObject(Deprecated::ScriptValue value)
 {
     ASSERT(!hasNoValue());
-    Deprecated::ScriptFunctionCall function(injectedScriptObject(), "inspectNode", WebCore::functionCallHandlerFromAnyThread);
-    function.appendArgument(nodeAsScriptValue(node));
+    Deprecated::ScriptFunctionCall function(injectedScriptObject(), "inspectObject", WebCore::functionCallHandlerFromAnyThread);
+    function.appendArgument(value);
+    RefPtr<InspectorValue> result;
+    makeCall(function, &result);
+}
+
+void InjectedScript::releaseObject(const String& objectId)
+{
+    Deprecated::ScriptFunctionCall function(injectedScriptObject(), "releaseObject", WebCore::functionCallHandlerFromAnyThread);
+    function.appendArgument(objectId);
     RefPtr<InspectorValue> result;
     makeCall(function, &result);
 }
@@ -253,11 +233,6 @@ void InjectedScript::releaseObjectGroup(const String& objectGroup)
     ASSERT(!hadException);
 }
 
-Deprecated::ScriptValue InjectedScript::nodeAsScriptValue(Node* node)
-{
-    return InjectedScriptHost::nodeAsScriptValue(scriptState(), node);
-}
-
 } // namespace WebCore
 
 #endif // ENABLE(INSPECTOR)
index fd9b9e5..adfe4e0 100644 (file)
@@ -85,27 +85,23 @@ public:
     void getFunctionDetails(ErrorString*, const String& functionId, RefPtr<Inspector::TypeBuilder::Debugger::FunctionDetails>* result);
     void getProperties(ErrorString*, const String& objectId, bool ownProperties, RefPtr<Inspector::TypeBuilder::Array<Inspector::TypeBuilder::Runtime::PropertyDescriptor>>* result);
     void getInternalProperties(ErrorString*, const String& objectId, RefPtr<Inspector::TypeBuilder::Array<Inspector::TypeBuilder::Runtime::InternalPropertyDescriptor>>* result);
-    Node* nodeForObjectId(const String& objectId);
-    void releaseObject(const String& objectId);
 
 #if ENABLE(JAVASCRIPT_DEBUGGER)
     PassRefPtr<Inspector::TypeBuilder::Array<Inspector::TypeBuilder::Debugger::CallFrame>> wrapCallFrames(const Deprecated::ScriptValue&);
 #endif
-
     PassRefPtr<Inspector::TypeBuilder::Runtime::RemoteObject> wrapObject(const Deprecated::ScriptValue&, const String& groupName, bool generatePreview = false) const;
     PassRefPtr<Inspector::TypeBuilder::Runtime::RemoteObject> wrapTable(const Deprecated::ScriptValue& table, const Deprecated::ScriptValue& columns) const;
-    PassRefPtr<Inspector::TypeBuilder::Runtime::RemoteObject> wrapNode(Node*, const String& groupName);
+
     Deprecated::ScriptValue findObjectById(const String& objectId) const;
+    void inspectObject(Deprecated::ScriptValue);
 
-    void inspectNode(Node*);
-    void releaseObjectGroup(const String&);
+    void releaseObject(const String& objectId);
+    void releaseObjectGroup(const String& objectGroup);
 
 private:
     friend class InjectedScriptModule;
     friend InjectedScript InjectedScriptManager::injectedScriptFor(JSC::ExecState*);
     InjectedScript(Deprecated::ScriptObject, InspectedStateAccessCheck);
-
-    Deprecated::ScriptValue nodeAsScriptValue(Node*);
 };
 
 #endif
index a5097c6..3bb6cdc 100644 (file)
@@ -47,9 +47,6 @@ public:
     static PassRefPtr<InjectedScriptHost> create();
     ~InjectedScriptHost() { }
 
-    static Node* scriptValueAsNode(Deprecated::ScriptValue);
-    static Deprecated::ScriptValue nodeAsScriptValue(JSC::ExecState*, Node*);
-
 private:
     InjectedScriptHost() { }
 };
index 9c88c73..7bff7f6 100644 (file)
@@ -125,7 +125,7 @@ InjectedScript.prototype = {
     /**
      * @param {*} object
      */
-    inspectNode: function(object)
+    inspectObject: function(object)
     {
         if (this._commandLineAPIImpl)
             this._commandLineAPIImpl.inspect(object);
@@ -642,18 +642,6 @@ InjectedScript.prototype = {
     },
 
     /**
-     * @param {string} objectId
-     * @return {Node}
-     */
-    nodeForObjectId: function(objectId)
-    {
-        var object = this.findObjectById(objectId);
-        if (!object || this._subtype(object) !== "node")
-            return null;
-        return /** @type {Node} */ (object);
-    },
-
-    /**
      * @param {string} name
      * @return {Object}
      */
index 62071d2..7ee0507 100644 (file)
 #include "InstrumentingAgents.h"
 #include "IntRect.h"
 #include "JSEventListener.h"
+#include "JSNode.h"
 #include "MainFrame.h"
 #include "MutationEvent.h"
 #include "Node.h"
 #include "NodeList.h"
 #include "Page.h"
+#include "PageInjectedScriptManager.h"
 #include "Pasteboard.h"
 #include "RenderStyle.h"
 #include "RenderStyleConstants.h"
@@ -998,11 +1000,12 @@ void InspectorDOMAgent::focusNode()
     if (!frame)
         return;
 
-    InjectedScript injectedScript = m_injectedScriptManager->injectedScriptFor(mainWorldExecState(frame));
+    JSC::ExecState* scriptState = mainWorldExecState(frame);
+    InjectedScript injectedScript = m_injectedScriptManager->injectedScriptFor(scriptState);
     if (injectedScript.hasNoValue())
         return;
 
-    injectedScript.inspectNode(node.get());
+    injectedScript.inspectObject(InspectorDOMAgent::nodeAsScriptValue(scriptState, node.get()));
 }
 
 void InspectorDOMAgent::mouseDidMoveOverElement(const HitTestResult& result, unsigned)
@@ -1090,8 +1093,7 @@ void InspectorDOMAgent::highlightNode(ErrorString* errorString, const RefPtr<Ins
     if (nodeId) {
         node = assertNode(errorString, *nodeId);
     } else if (objectId) {
-        InjectedScript injectedScript = m_injectedScriptManager->injectedScriptForObjectId(*objectId);
-        node = injectedScript.nodeForObjectId(*objectId);
+        node = nodeForObjectId(*objectId);
         if (!node)
             *errorString = "Node for given objectId not found";
     } else
@@ -1241,8 +1243,7 @@ void InspectorDOMAgent::getAttributes(ErrorString* errorString, int nodeId, RefP
 
 void InspectorDOMAgent::requestNode(ErrorString*, const String& objectId, int* nodeId)
 {
-    InjectedScript injectedScript = m_injectedScriptManager->injectedScriptForObjectId(objectId);
-    Node* node = injectedScript.nodeForObjectId(objectId);
+    Node* node = nodeForObjectId(objectId);
     if (node)
         *nodeId = pushNodePathToFrontend(node);
     else
@@ -1706,6 +1707,13 @@ Node* InspectorDOMAgent::nodeForPath(const String& path)
     return node;
 }
 
+Node* InspectorDOMAgent::nodeForObjectId(const String& objectId)
+{
+    InjectedScript injectedScript = m_injectedScriptManager->injectedScriptForObjectId(objectId);
+    Deprecated::ScriptValue value = injectedScript.findObjectById(objectId);
+    return InspectorDOMAgent::scriptValueAsNode(value);
+}
+
 void InspectorDOMAgent::pushNodeByPathToFrontend(ErrorString* errorString, const String& path, int* nodeId)
 {
     if (Node* node = nodeForPath(path))
@@ -1737,11 +1745,29 @@ PassRefPtr<Inspector::TypeBuilder::Runtime::RemoteObject> InspectorDOMAgent::res
     if (!frame)
         return 0;
 
-    InjectedScript injectedScript = m_injectedScriptManager->injectedScriptFor(mainWorldExecState(frame));
+    JSC::ExecState* scriptState = mainWorldExecState(frame);
+    InjectedScript injectedScript = m_injectedScriptManager->injectedScriptFor(scriptState);
     if (injectedScript.hasNoValue())
         return 0;
 
-    return injectedScript.wrapNode(node, objectGroup);
+    return injectedScript.wrapObject(InspectorDOMAgent::nodeAsScriptValue(scriptState, node), objectGroup);
+}
+
+Node* InspectorDOMAgent::scriptValueAsNode(Deprecated::ScriptValue value)
+{
+    if (!value.isObject() || value.isNull())
+        return nullptr;
+
+    return toNode(value.jsValue());
+}
+
+Deprecated::ScriptValue InspectorDOMAgent::nodeAsScriptValue(JSC::ExecState* state, Node* node)
+{
+    if (!shouldAllowAccessToNode(state, node))
+        return Deprecated::ScriptValue(state->vm(), JSC::jsNull());
+
+    JSC::JSLockHolder lock(state);
+    return Deprecated::ScriptValue(state->vm(), toJS(state, deprecatedGlobalObjectForPrototype(state), node));
 }
 
 } // namespace WebCore
index 3c4ca3c..99dd0df 100644 (file)
@@ -208,6 +208,9 @@ public:
     Element* assertElement(ErrorString*, int nodeId);
     Document* assertDocument(ErrorString*, int nodeId);
 
+    static Node* scriptValueAsNode(Deprecated::ScriptValue);
+    static Deprecated::ScriptValue nodeAsScriptValue(JSC::ExecState*, Node*);
+
     // Methods called from other agents.
     InspectorPageAgent* pageAgent() { return m_pageAgent; }
 
@@ -238,6 +241,7 @@ private:
     PassRefPtr<Inspector::TypeBuilder::DOM::EventListener> buildObjectForEventListener(const RegisteredEventListener&, const AtomicString& eventType, Node*, const String* objectGroupId);
 
     Node* nodeForPath(const String& path);
+    Node* nodeForObjectId(const String& objectId);
 
     void discardBindings();
 
index 97d68d3..f3733dd 100644 (file)
@@ -70,7 +70,7 @@ public:
     explicit InspectableNode(Node* node) : m_node(node) { }
     virtual Deprecated::ScriptValue get(JSC::ExecState* state) OVERRIDE
     {
-        return InjectedScriptHost::nodeAsScriptValue(state, m_node);
+        return InspectorDOMAgent::nodeAsScriptValue(state, m_node);
     }
 private:
     Node* m_node;