Web Inspector: use dedicated type for object id in the protocol.
authorpfeldman@chromium.org <pfeldman@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 25 Jul 2011 15:10:43 +0000 (15:10 +0000)
committerpfeldman@chromium.org <pfeldman@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 25 Jul 2011 15:10:43 +0000 (15:10 +0000)
https://bugs.webkit.org/show_bug.cgi?id=65110

Reviewed by Yury Semikhatsky.

Source/WebCore:

* inspector/InjectedScript.cpp:
(WebCore::InjectedScript::callFunctionOn):
* inspector/InjectedScript.h:
* inspector/InjectedScriptSource.js:
(.):
* inspector/Inspector.json:
* inspector/InspectorRuntimeAgent.cpp:
(WebCore::InspectorRuntimeAgent::callFunctionOn):

LayoutTests:

* inspector/runtime/runtime-callFunctionOn-expected.txt:
* inspector/runtime/runtime-callFunctionOn.html:

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

LayoutTests/ChangeLog
LayoutTests/inspector/runtime/runtime-callFunctionOn-expected.txt
LayoutTests/inspector/runtime/runtime-callFunctionOn.html
Source/WebCore/ChangeLog
Source/WebCore/inspector/InjectedScript.cpp
Source/WebCore/inspector/InjectedScript.h
Source/WebCore/inspector/InjectedScriptSource.js
Source/WebCore/inspector/Inspector.json
Source/WebCore/inspector/InspectorRuntimeAgent.cpp

index 318f306..a9f6d3b 100644 (file)
@@ -1,5 +1,15 @@
 2011-07-25  Pavel Feldman  <pfeldman@google.com>
 
+        Web Inspector: use dedicated type for object id in the protocol.
+        https://bugs.webkit.org/show_bug.cgi?id=65110
+
+        Reviewed by Yury Semikhatsky.
+
+        * inspector/runtime/runtime-callFunctionOn-expected.txt:
+        * inspector/runtime/runtime-callFunctionOn.html:
+
+2011-07-25  Pavel Feldman  <pfeldman@google.com>
+
         Web Inspector: refactor remote object structure to contain value for primitive values.
         https://bugs.webkit.org/show_bug.cgi?id=65103
 
index 76f60bc..3fa0419 100644 (file)
@@ -37,13 +37,13 @@ function test()
 
             function step1(error, result, wasThrown)
             {
-                function format(aobj1, aobj2)
+                function format(aobj1, aobj2, val, undef)
                 {
-                    return JSON.stringify(this) + "\n" + JSON.stringify(aobj1) + "\n" + JSON.stringify(aobj2);
+                    return JSON.stringify(this) + "\n" + JSON.stringify(aobj1) + "\n" + JSON.stringify(aobj2) + "\n" + val + "\n" + undef;
                 }
 
                 obj2 = result;
-                RuntimeAgent.callFunctionOn(obj1.objectId, format.toString(), [obj1.objectId, obj2.objectId], step2);
+                RuntimeAgent.callFunctionOn(obj1.objectId, format.toString(), [obj1, obj2, {value:4}, {}], step2);
             }
 
             function step2(error, result, wasThrown)
index 9a3d94e..e86787a 100644 (file)
@@ -1,3 +1,19 @@
+2011-07-25  Pavel Feldman  <pfeldman@google.com>
+
+        Web Inspector: use dedicated type for object id in the protocol.
+        https://bugs.webkit.org/show_bug.cgi?id=65110
+
+        Reviewed by Yury Semikhatsky.
+
+        * inspector/InjectedScript.cpp:
+        (WebCore::InjectedScript::callFunctionOn):
+        * inspector/InjectedScript.h:
+        * inspector/InjectedScriptSource.js:
+        (.):
+        * inspector/Inspector.json:
+        * inspector/InspectorRuntimeAgent.cpp:
+        (WebCore::InspectorRuntimeAgent::callFunctionOn):
+
 2011-07-25  Yury Semikhatsky  <yurys@chromium.org>
 
         [Chromium] Web Inspector: live edit error should be revealed in Console
index 40b615c..6cf65e8 100644 (file)
@@ -63,19 +63,12 @@ void InjectedScript::evaluate(ErrorString* errorString, const String& expression
     makeEvalCall(errorString, function, result, wasThrown);
 }
 
-void InjectedScript::callFunctionOn(ErrorString* errorString, const String& objectId, const String& expression, PassRefPtr<InspectorArray> arguments, RefPtr<InspectorObject>* result, bool* wasThrown)
+void InjectedScript::callFunctionOn(ErrorString* errorString, const String& objectId, const String& expression, const String& arguments, RefPtr<InspectorObject>* result, bool* wasThrown)
 {
     ScriptFunctionCall function(m_injectedScriptObject, "callFunctionOn");
     function.appendArgument(objectId);
     function.appendArgument(expression);
-    for (unsigned i = 0; i < arguments->length(); ++i) {
-        String argumentId;
-        if (!arguments->get(i)->asString(&argumentId)) {
-            *errorString = "Call argument should be an object id";
-            return;
-        }
-        function.appendArgument(argumentId);
-    }
+    function.appendArgument(arguments);
     makeEvalCall(errorString, function, result, wasThrown);
 }
 
index 9c1d45f..c944715 100644 (file)
@@ -56,7 +56,7 @@ public:
     bool hasNoValue() const { return m_injectedScriptObject.hasNoValue(); }
 
     void evaluate(ErrorString*, const String& expression, const String& objectGroup, bool includeCommandLineAPI, RefPtr<InspectorObject>* result, bool* wasThrown);
-    void callFunctionOn(ErrorString*, const String& objectId, const String& expression, PassRefPtr<InspectorArray> arguments, RefPtr<InspectorObject>* result, bool* wasThrown);
+    void callFunctionOn(ErrorString*, const String& objectId, const String& expression, const String& arguments, RefPtr<InspectorObject>* result, bool* wasThrown);
     void evaluateOnCallFrame(ErrorString*, const ScriptValue& callFrames, const String& callFrameId, const String& expression, const String& objectGroup, bool includeCommandLineAPI, RefPtr<InspectorObject>* result, bool* wasThrown);
     void getProperties(ErrorString*, const String& objectId, bool ignoreHasOwnProperty, RefPtr<InspectorArray>* result);
     Node* nodeForObjectId(const String& objectId);
index 6449747..35bd115 100644 (file)
@@ -277,24 +277,33 @@ InjectedScript.prototype = {
         return this._evaluateAndWrap(InjectedScriptHost.evaluate, InjectedScriptHost, expression, objectGroup, false, injectCommandLineAPI);
     },
 
-    callFunctionOn: function(objectId, expression)
+    callFunctionOn: function(objectId, expression, args)
     {
         var parsedObjectId = this._parseObjectId(objectId);
         var object = this._objectForId(parsedObjectId);
         if (!object)
             return "Could not find object with given id";
 
-        var resolvedArgs = [];
-        for (var i = 2; i < arguments.length; ++i) {
-            var parsedArgId = this._parseObjectId(arguments[i]);
-            if (!parsedArgId || parsedArgId.injectedScriptId !== injectedScriptId)
-                return "Arguments should belong to the same JavaScript world as the target object.";
-            
-            var resolvedArg = this._objectForId(parsedArgId);
-            if (!resolvedArg)
-                return "Could not find object with given id";
-
-            resolvedArgs.push(resolvedArg);
+        if (args) {
+            var resolvedArgs = [];
+            args = InjectedScriptHost.evaluate(args);
+            for (var i = 0; i < args.length; ++i) {
+                var objectId = args[i].objectId;
+                if (objectId) {
+                    var parsedArgId = this._parseObjectId(objectId);
+                    if (!parsedArgId || parsedArgId.injectedScriptId !== injectedScriptId)
+                        return "Arguments should belong to the same JavaScript world as the target object.";
+
+                    var resolvedArg = this._objectForId(parsedArgId);
+                    if (!resolvedArg)
+                        return "Could not find object with given id";
+
+                    resolvedArgs.push(resolvedArg);
+                } else if (args[i].value)
+                    resolvedArgs.push(args[i].value);
+                else
+                    resolvedArgs.push(undefined);
+            }
         }
 
         try {
index 36feafa..a7bcf21 100644 (file)
         "description": "Runtime domain exposes JavaScript runtime by means of remote evaluation and mirror objects. Evaluation results are returned as mirror object that expose type, string representation and unique identifier that can be used for further object interaction. Original objects are maintained in memory unless they are either explicitly released or are released along with the other objects in their object group.",
         "types": [
             {
+                "id": "RemoteObjectId",
+                "type": "string",
+                "description": "Unique object identifier."
+            },
+            {
                 "id": "RemoteObject",
                 "type": "object",
                 "description": "Mirror object referencing original JavaScript object.",
                     { "name": "className", "type": "string", "optional": true, "description": "Object class (constructor) name. Specified for <code>object</code> type values only." },
                     { "name": "value", "type": "any", "optional": true, "description": "Remote object value (in case of primitive values)." },
                     { "name": "description", "type": "string", "optional": true, "description": "String representation of the object." },
-                    { "name": "objectId", "type": "string", "optional": true, "description": "Unique object identifier (for non-primitive values)." }
+                    { "name": "objectId", "$ref": "RemoteObjectId", "optional": true, "description": "Unique object identifier (for non-primitive values)." }
                 ]
             },
             {
                     { "name": "wasThrown", "type": "boolean", "optional": true, "description": "True if exception was thrown on attempt to get the property value, in that case the value propery will contain thrown value." },
                     { "name": "isGetter", "type": "boolean", "optional": true, "description": "True if this property is getter." }
                 ]
+            },
+            {
+                "id": "CallArgument",
+                "type": "object",
+                "description": "Represents function call argument. Either remote object id <code>objectId</code> or primitive <code>value</code> or neither of (for undefined) them should be specified.",
+                "properties": [
+                    { "name": "value", "type": "any", "optional": true, "description": "Primitive value." },
+                    { "name": "objectId", "$ref": "RemoteObject", "optional": true, "description": "Remote object handle." }
+                ]
             }
         ],
         "commands": [
                     { "name": "result", "$ref": "RemoteObject", "description": "Evaluation result." },
                     { "name": "wasThrown", "type": "boolean", "optional": true, "description": "True iff the result was thrown during the evaluation." }
                 ],
-                "description": "Evaluate expression on global object."
+                "description": "Evaluates expression on global object."
             },
             {
                 "name": "callFunctionOn",
                 "parameters": [
-                    { "name": "objectId", "type": "string", "description": "Identifier of the object to call function on." },
+                    { "name": "objectId", "$ref": "RemoteObjectId", "description": "Identifier of the object to call function on." },
                     { "name": "functionDeclaration", "type": "string", "description": "Declaration of the function to call." },
-                    { "name": "arguments", "type": "array", "items": { "type": "string", "description": "Identifier of the argument." }, "optional": true, "description": "Call arguments. All call arguments must belong to the same JavaScript world as the target object." }
+                    { "name": "arguments", "type": "array", "items": { "$ref": "CallArgument", "description": "Call argument." }, "optional": true, "description": "Call arguments. All call arguments must belong to the same JavaScript world as the target object." }
                 ],
                 "returns": [
                     { "name": "result", "$ref": "RemoteObject", "description": "Call result." },
                     { "name": "wasThrown", "type": "boolean", "optional": true, "description": "True iff the result was thrown during the evaluation." }
                 ],
-                "description": "Call function with given declaration on the given object."
+                "description": "Calls function with given declaration on the given object."
             },
             {
                 "name": "getProperties",
                 "parameters": [
-                    { "name": "objectId", "type": "string", "description": "Identifier of the object to return properties for." },
+                    { "name": "objectId", "$ref": "RemoteObjectId", "description": "Identifier of the object to return properties for." },
                     { "name": "ignoreHasOwnProperty", "type": "boolean", "description": "If true, returns properties belonging to any element of the prototype chain." }
                 ],
                 "returns": [
             {
                 "name": "setPropertyValue",
                 "parameters": [
-                    { "name": "objectId", "type": "string", "description": "Identifier of the object to set property on." },
+                    { "name": "objectId", "$ref": "RemoteObjectId", "description": "Identifier of the object to set property on." },
                     { "name": "propertyName", "type": "string", "description": "Property name to set value for." },
                     { "name": "expression", "type": "string", "description": "Expression to evaluate." }
                 ],
             {
                 "name": "releaseObject",
                 "parameters": [
-                    { "name": "objectId", "type": "string", "description": "Identifier of the object to release." }
+                    { "name": "objectId", "$ref": "RemoteObjectId", "description": "Identifier of the object to release." }
                 ],
                 "description": "Releases remote object with given id."
             },
             {
                 "name": "pushNodeToFrontend",
                 "parameters": [
-                    { "name": "objectId", "type": "string", "description": "JavaScript object id to convert into node." }
+                    { "name": "objectId", "$ref": "Runtime.RemoteObjectId", "description": "JavaScript object id to convert into node." }
                 ],
                 "returns": [
                     { "name": "nodeId", "type": "integer", "description": "Node id for given object." }
             {
                 "name": "start",
                 "parameters": [
-                    { "name": "maxCallStackDepth", "optional": true, "type": "integer", "description": "Samples JavaScript stack traces up to <code>maxCallStackDepth</code>, defaults to 5." },
+                    { "name": "maxCallStackDepth", "optional": true, "type": "integer", "description": "Samples JavaScript stack traces up to <code>maxCallStackDepth</code>, defaults to 5." }
                 ],
                 "description": "Starts capturing instrumentation events."
             },
index 9186310..28aea76 100644 (file)
@@ -89,11 +89,9 @@ void InspectorRuntimeAgent::callFunctionOn(ErrorString* errorString, const Strin
         *errorString = "Inspected frame has gone";
         return;
     }
-    RefPtr<InspectorArray> arguments = InspectorArray::create();
-    if (optionalArguments) {
-        for (unsigned i = 0; i < (*optionalArguments)->length(); ++i)
-            arguments->pushValue((*optionalArguments)->get(i));
-    }
+    String arguments;
+    if (optionalArguments)
+        arguments = (*optionalArguments)->toJSONString();
     injectedScript.callFunctionOn(errorString, objectId, expression, arguments, result, wasThrown);
 }