Changeset 91472 in webkit


Ignore:
Timestamp:
Jul 21, 2011, 8:49:30 AM (14 years ago)
Author:
pfeldman@chromium.org
Message:

Web Inspector: RuntimeAgent.evaluateOn should not require "return X;" syntax.
https://bugs.webkit.org/show_bug.cgi?id=64691

Reviewed by Yury Semikhatsky.

Source/WebCore:

I'm introducing callFunctionOn that receives function declaration in order
to make call site syntax clear.

Test: inspector/runtime/runtime-callFunctionOn.html

  • inspector/InjectedScript.cpp:

(WebCore::InjectedScript::callFunctionOn):

  • inspector/InjectedScript.h:
  • inspector/InjectedScriptSource.js:

(.):

  • inspector/Inspector.json:
  • inspector/InspectorRuntimeAgent.cpp:

(WebCore::InspectorRuntimeAgent::callFunctionOn):

  • inspector/InspectorRuntimeAgent.h:
  • inspector/front-end/ElementsTreeOutline.js:

(WebInspector.ElementsTreeElement.prototype._createTooltipForNode.resolvedNode.dimensions):
(WebInspector.ElementsTreeElement.prototype._createTooltipForNode.resolvedNode):
(WebInspector.ElementsTreeElement.prototype._createTooltipForNode):

  • inspector/front-end/PropertiesSidebarPane.js:

(WebInspector.PropertiesSidebarPane.prototype.update.nodeResolved.protoList):
(WebInspector.PropertiesSidebarPane.prototype.update.nodeResolved):

  • inspector/front-end/RemoteObject.js:

(WebInspector.RemoteObject.prototype.callFunction):

LayoutTests:

  • inspector/protocol/runtime-agent-expected.txt:
  • inspector/protocol/runtime-agent.html:
  • inspector/runtime/runtime-callFunctionOn-expected.txt: Added.
  • inspector/runtime/runtime-callFunctionOn.html: Added.
Location:
trunk
Files:
3 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r91471 r91472  
     12011-07-21  Pavel Feldman  <pfeldman@google.com>
     2
     3        Web Inspector: RuntimeAgent.evaluateOn should not require "return X;" syntax.
     4        https://bugs.webkit.org/show_bug.cgi?id=64691
     5
     6        Reviewed by Yury Semikhatsky.
     7
     8        * inspector/protocol/runtime-agent-expected.txt:
     9        * inspector/protocol/runtime-agent.html:
     10        * inspector/runtime/runtime-callFunctionOn-expected.txt: Added.
     11        * inspector/runtime/runtime-callFunctionOn.html: Added.
     12
    1132011-07-21  John Knottenbelt  <jknotten@chromium.org>
    214
  • trunk/LayoutTests/inspector/protocol/runtime-agent-expected.txt

    r86836 r91472  
    5757
    5858-----------------------------------------------------------
    59 RuntimeAgent.evaluateOn(<string>,"this.assignedByEvaluateOn = \"evaluateOn function works fine\";")
    60 
    61 request:
    62 {
    63     method : "Runtime.evaluateOn"
    64     params : {
    65         objectId : <string>
    66         expression : "this.assignedByEvaluateOn = "evaluateOn function works fine";"
     59RuntimeAgent.callFunctionOn(<string>,"function() { this.assignedByCallFunctionOn = \"callFunctionOn function works fine\"; return this.assignedByCallFunctionOn; }")
     60
     61request:
     62{
     63    method : "Runtime.callFunctionOn"
     64    params : {
     65        objectId : <string>
     66        functionDeclaration : "function() { this.assignedByCallFunctionOn = "callFunctionOn function works fine"; return this.assignedByCallFunctionOn; }"
    6767    }
    6868    id : <number>
     
    7373    result : {
    7474        result : {
    75             type : "undefined"
    76             description : "undefined"
     75            type : "string"
     76            description : "callFunctionOn function works fine"
    7777        }
    7878    }
     
    140140        result : [
    141141            {
    142                 name : "assignedByEvaluateOn"
     142                name : "assignedByCallFunctionOn"
    143143                value : {
    144144                    type : "string"
    145                     description : "evaluateOn function works fine"
     145                    description : "callFunctionOn function works fine"
    146146                }
    147147            }
     
    210210{
    211211    evaluate : "checked"
    212     evaluateOn : "checked"
     212    callFunctionOn : "checked"
    213213    getProperties : "checked"
    214214    setPropertyValue : "checked"
  • trunk/LayoutTests/inspector/protocol/runtime-agent.html

    r86836 r91472  
    2121            ["RuntimeAgent", "evaluate", 'testObject', 'test', false],
    2222            ["RuntimeAgent", "evaluate", 'testObject', 'test'],
    23             ["RuntimeAgent", "evaluateOn", result.objectId, 'this.assignedByEvaluateOn = "evaluateOn function works fine";'],
     23            ["RuntimeAgent", "callFunctionOn", result.objectId, 'function() { this.assignedByCallFunctionOn = "callFunctionOn function works fine"; return this.assignedByCallFunctionOn; }'],
    2424            ["RuntimeAgent", "setPropertyValue", result.objectId, 'assignedBySetPropertyValue', 'true'],
    2525            ["RuntimeAgent", "setPropertyValue", result.objectId, 'removedBySetPropertyValue', ''],
  • trunk/Source/WebCore/ChangeLog

    r91469 r91472  
     12011-07-21  Pavel Feldman  <pfeldman@google.com>
     2
     3        Web Inspector: RuntimeAgent.evaluateOn should not require "return X;" syntax.
     4        https://bugs.webkit.org/show_bug.cgi?id=64691
     5
     6        Reviewed by Yury Semikhatsky.
     7
     8        I'm introducing callFunctionOn that receives function declaration in order
     9        to make call site syntax clear.
     10
     11        Test: inspector/runtime/runtime-callFunctionOn.html
     12
     13        * inspector/InjectedScript.cpp:
     14        (WebCore::InjectedScript::callFunctionOn):
     15        * inspector/InjectedScript.h:
     16        * inspector/InjectedScriptSource.js:
     17        (.):
     18        * inspector/Inspector.json:
     19        * inspector/InspectorRuntimeAgent.cpp:
     20        (WebCore::InspectorRuntimeAgent::callFunctionOn):
     21        * inspector/InspectorRuntimeAgent.h:
     22        * inspector/front-end/ElementsTreeOutline.js:
     23        (WebInspector.ElementsTreeElement.prototype._createTooltipForNode.resolvedNode.dimensions):
     24        (WebInspector.ElementsTreeElement.prototype._createTooltipForNode.resolvedNode):
     25        (WebInspector.ElementsTreeElement.prototype._createTooltipForNode):
     26        * inspector/front-end/PropertiesSidebarPane.js:
     27        (WebInspector.PropertiesSidebarPane.prototype.update.nodeResolved.protoList):
     28        (WebInspector.PropertiesSidebarPane.prototype.update.nodeResolved):
     29        * inspector/front-end/RemoteObject.js:
     30        (WebInspector.RemoteObject.prototype.callFunction):
     31
    1322011-07-21  Andrew Wason  <rectalogic@rectalogic.com>
    233
  • trunk/Source/WebCore/inspector/InjectedScript.cpp

    r89429 r91472  
    6464}
    6565
    66 void InjectedScript::evaluateOn(ErrorString* errorString, const String& objectId, const String& expression, RefPtr<InspectorObject>* result, bool* wasThrown)
    67 {
    68     ScriptFunctionCall function(m_injectedScriptObject, "evaluateOn");
    69     function.appendArgument(objectId);
    70     function.appendArgument(expression);
     66void InjectedScript::callFunctionOn(ErrorString* errorString, const String& objectId, const String& expression, PassRefPtr<InspectorArray> arguments, RefPtr<InspectorObject>* result, bool* wasThrown)
     67{
     68    ScriptFunctionCall function(m_injectedScriptObject, "callFunctionOn");
     69    function.appendArgument(objectId);
     70    function.appendArgument(expression);
     71    for (unsigned i = 0; i < arguments->length(); ++i) {
     72        String argumentId;
     73        if (!arguments->get(i)->asString(&argumentId)) {
     74            *errorString = "Call argument should be an object id";
     75            return;
     76        }
     77        function.appendArgument(argumentId);
     78    }
    7179    makeEvalCall(errorString, function, result, wasThrown);
    7280}
  • trunk/Source/WebCore/inspector/InjectedScript.h

    r89429 r91472  
    5757
    5858    void evaluate(ErrorString*, const String& expression, const String& objectGroup, bool includeCommandLineAPI, RefPtr<InspectorObject>* result, bool* wasThrown);
    59     void evaluateOn(ErrorString*, const String& objectId, const String& expression, RefPtr<InspectorObject>* result, bool* wasThrown);
     59    void callFunctionOn(ErrorString*, const String& objectId, const String& expression, PassRefPtr<InspectorArray> arguments, RefPtr<InspectorObject>* result, bool* wasThrown);
    6060    void evaluateOnCallFrame(ErrorString*, const ScriptValue& callFrames, const String& callFrameId, const String& expression, const String& objectGroup, bool includeCommandLineAPI, RefPtr<InspectorObject>* result, bool* wasThrown);
    6161    void getProperties(ErrorString*, const String& objectId, bool ignoreHasOwnProperty, RefPtr<InspectorArray>* result);
  • trunk/Source/WebCore/inspector/InjectedScriptSource.js

    r90614 r91472  
    253253    },
    254254
    255     evaluateOn: function(objectId, expression)
     255    callFunctionOn: function(objectId, expression)
    256256    {
    257257        var parsedObjectId = this._parseObjectId(objectId);
     
    259259        if (!object)
    260260            return "Could not find object with given id";
     261
     262        var resolvedArgs = [];
     263        for (var i = 2; i < arguments.length; ++i) {
     264            var parsedArgId = this._parseObjectId(arguments[i]);
     265            if (!parsedArgId || parsedArgId.injectedScriptId !== injectedScriptId)
     266                return "Arguments should belong to the same JavaScript world as the target object.";
     267           
     268            var resolvedArg = this._objectForId(parsedArgId);
     269            if (!resolvedArg)
     270                return "Could not find object with given id";
     271
     272            resolvedArgs.push(resolvedArg);
     273        }
     274
    261275        try {
    262             inspectedWindow.console._objectToEvaluateOn = object;
    263             var objectGroupName = this._idToObjectGroupName[parsedObjectId.id];
    264             return this._evaluateAndWrap(inspectedWindow.eval, inspectedWindow, "(function() {" + expression + "}).call(window.console._objectToEvaluateOn)", objectGroupName, false, false);
    265         } finally {
    266             delete inspectedWindow.console._objectToEvaluateOn;
     276            var objectGroup = this._idToObjectGroupName[parsedObjectId.id];
     277            var func = InjectedScriptHost.evaluate("(" + expression + ")");
     278            if (typeof func !== "function")
     279                return "Given expression does not evaluate to a function";
     280
     281            return { wasThrown: false,
     282                     result: this._wrapObject(func.apply(object, resolvedArgs), objectGroup) };
     283        } catch (e) {
     284            return { wasThrown: true,
     285                     result: this._wrapObject(e, objectGroup) };
    267286        }
    268287    },
  • trunk/Source/WebCore/inspector/Inspector.json

    r91461 r91472  
    258258            },
    259259            {
    260                 "name": "evaluateOn",
    261                 "parameters": [
    262                     { "name": "objectId", "type": "string", "description": "Identifier of the object to evaluate expression on." },
    263                     { "name": "expression", "type": "string", "description": "Expression to evaluate." }
    264                 ],
    265                 "returns": [
    266                     { "name": "result", "$ref": "RemoteObject", "description": "Evaluation result." },
     260                "name": "callFunctionOn",
     261                "parameters": [
     262                    { "name": "objectId", "type": "string", "description": "Identifier of the object to call function on." },
     263                    { "name": "functionDeclaration", "type": "string", "description": "Declaration of the function to call." },
     264                    { "name": "arguments", "type": "array", "items": { "type": "objectId", "description": "Identifier of the argument." }, "optional": true, "description": "Call arguments. All call arguments must belong to the same JavaScript world as the target object." }
     265                ],
     266                "returns": [
     267                    { "name": "result", "$ref": "RemoteObject", "description": "Call result." },
    267268                    { "name": "wasThrown", "type": "boolean", "optional": true, "description": "True iff the result was thrown during the evaluation." }
    268269                ],
    269                 "description": "Evaluate expression on given object using it as <code>this</code>."
     270                "description": "Call function with given declaration on the given object."
    270271            },
    271272            {
     
    516517                ],
    517518                "description": "Toggles ignoring cache for each request. If <code>true</code>, cache will not be used."
    518             },
     519            }
    519520        ],
    520521        "events": [
     
    10171018                "parameters": [
    10181019                    { "name": "nodeId", "type": "integer", "description": "Id of the node to resolve." },
    1019                     { "name": "objectGroup", "type": "string", "optional": true, "description": "Symbolic group name that can be used to release multiple objects." },
     1020                    { "name": "objectGroup", "type": "string", "optional": true, "description": "Symbolic group name that can be used to release multiple objects." }
    10201021                ],
    10211022                "returns": [
  • trunk/Source/WebCore/inspector/InspectorRuntimeAgent.cpp

    r91176 r91472  
    8383}
    8484
    85 void InspectorRuntimeAgent::evaluateOn(ErrorString* errorString, const String& objectId, const String& expression, RefPtr<InspectorObject>* result, bool* wasThrown)
     85void InspectorRuntimeAgent::callFunctionOn(ErrorString* errorString, const String& objectId, const String& expression, const RefPtr<InspectorArray>* const optionalArguments, RefPtr<InspectorObject>* result, bool* wasThrown)
    8686{
    8787    InjectedScript injectedScript = m_injectedScriptManager->injectedScriptForObjectId(objectId);
     
    9090        return;
    9191    }
    92     injectedScript.evaluateOn(errorString, objectId, expression, result, wasThrown);
     92    RefPtr<InspectorArray> arguments = InspectorArray::create();
     93    if (optionalArguments) {
     94        for (unsigned i = 0; i < (*optionalArguments)->length(); ++i)
     95            arguments->pushValue((*optionalArguments)->get(i));
     96    }
     97    injectedScript.callFunctionOn(errorString, objectId, expression, arguments, result, wasThrown);
    9398}
    9499
  • trunk/Source/WebCore/inspector/InspectorRuntimeAgent.h

    r91176 r91472  
    5555    // Part of the protocol.
    5656    void evaluate(ErrorString*, const String& expression, const String* const objectGroup, const bool* const includeCommandLineAPI, const bool* const doNotPauseOnExceptions, RefPtr<InspectorObject>* result, bool* wasThrown);
    57     void evaluateOn(ErrorString*, const String& objectId, const String& expression, RefPtr<InspectorObject>* result, bool* wasThrown);
     57    void callFunctionOn(ErrorString*, const String& objectId, const String& expression, const RefPtr<InspectorArray>* const optionalArguments, RefPtr<InspectorObject>* result, bool* wasThrown);
    5858    void releaseObject(ErrorString*, const String& objectId);
    5959    void getProperties(ErrorString*, const String& objectId, bool ignoreHasOwnProperty, RefPtr<InspectorArray>* result);
  • trunk/Source/WebCore/inspector/front-end/ElementsTreeOutline.js

    r91179 r91472  
    605605                return;
    606606
    607             object.evaluate("return '[' + this.offsetWidth + ',' + this.offsetHeight + ',' + this.naturalWidth + ',' + this.naturalHeight + ']'", setTooltip.bind(this));
     607            function dimensions()
     608            {
     609                return "[" + this.offsetWidth + "," + this.offsetHeight + "," + this.naturalWidth + "," + this.naturalHeight + "]";
     610            }
     611
     612            object.callFunction(dimensions, setTooltip.bind(this));
    608613            object.release();
    609614        }
  • trunk/Source/WebCore/inspector/front-end/PropertiesSidebarPane.js

    r89429 r91472  
    5151            if (!object)
    5252                return;
    53             object.evaluate("var proto = this; result = {}; var counter = 1; while (proto) { result[counter++] = proto; proto = proto.__proto__ }; return result;", nodePrototypesReady.bind(this));
     53            function protoList()
     54            {
     55                var proto = this;
     56                var result = {};
     57                var counter = 1;
     58                while (proto) {
     59                    result[counter++] = proto;
     60                    proto = proto.__proto__;
     61                }
     62                return result;
     63            }
     64            object.callFunction(protoList, nodePrototypesReady.bind(this));
    5465            object.release();
    5566        }
  • trunk/Source/WebCore/inspector/front-end/RemoteObject.js

    r89429 r91472  
    149149    },
    150150
    151     evaluate: function(expression, callback)
    152     {
    153         RuntimeAgent.evaluateOn(this._objectId, expression, callback);
     151    callFunction: function(functionDeclaration, callback)
     152    {
     153        RuntimeAgent.callFunctionOn(this._objectId, functionDeclaration.toString(), undefined, callback);
    154154    },
    155155
Note: See TracChangeset for help on using the changeset viewer.