Changeset 92104 in webkit


Ignore:
Timestamp:
Aug 1, 2011 1:13:55 AM (13 years ago)
Author:
pfeldman@chromium.org
Message:

Web Inspector: [protocol] methods where all parameters are optional should not require empty params object.
https://bugs.webkit.org/show_bug.cgi?id=65331

Reviewed by Yury Semikhatsky.

Source/WebCore:

  • inspector/CodeGeneratorInspector.pm:

(generateBackendFunction):
(generateArgumentGetters):

LayoutTests:

  • inspector/report-protocol-errors-expected.txt:
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r92101 r92104  
     12011-07-28  Pavel Feldman  <pfeldman@google.com>
     2
     3        Web Inspector: [protocol] methods where all parameters are optional should not require empty params object.
     4        https://bugs.webkit.org/show_bug.cgi?id=65331
     5
     6        Reviewed by Yury Semikhatsky.
     7
     8        * inspector/report-protocol-errors-expected.txt:
     9
    1102011-07-31  Adam Barth  <abarth@webkit.org>
    211
  • trunk/LayoutTests/inspector/report-API-errors-expected.txt

    r83171 r92104  
    11Tests that InspectorBackendStub is catching incorrect arguments.
    22
    3 Protocol Error: Invalid type of argument 'enabled' for method 'ConsoleAgent.setMonitoringXHREnabled' call. It should be 'boolean' but it is 'number'.
    4 Protocol Error: Invalid number of arguments for method 'ConsoleAgent.setMonitoringXHREnabled' call. It should have the next arguments '{"enabled":{"optional":false,"type":"boolean"}}'.
    5 Protocol Error: Optional callback argument for method 'ConsoleAgent.setMonitoringXHREnabled' call should be a function but its type is 'string'.
     3Protocol Error: Invalid type of argument 'enabled' for method 'ConsoleAgent.setMonitoringXHREnabled' call. It must be 'boolean' but it is 'number'.
     4Protocol Error: Invalid number of arguments for method 'ConsoleAgent.setMonitoringXHREnabled' call. It must have the next arguments '{"enabled":{"optional":false,"type":"boolean"}}'.
     5Protocol Error: Optional callback argument for method 'ConsoleAgent.setMonitoringXHREnabled' call must be a function but its type is 'string'.
    66Protocol Error: the message is for non-existing domain 'wrongDomain'
    77Protocol Error: Attempted to dispatch an unimplemented method 'Inspector.something-strange'
  • trunk/LayoutTests/inspector/report-protocol-errors-expected.txt

    r90110 r92104  
    44    error : {
    55        code : -32700
    6         message : "Message should be in JSON format"
     6        message : "Message must be in JSON format"
    77    }
    88    id : null
    99}
    1010error.code: -32700
    11 error.getMessage(): Message should be in JSON format
    12 error.toString(): Parse error(-32700): Message should be in JSON format.
     11error.getMessage(): Message must be in JSON format
     12error.toString(): Parse error(-32700): Message must be in JSON format.
    1313-------------------------------------------------------
    1414{
     
    2626    error : {
    2727        code : -32600
    28         message : "The type of 'id' property should be number"
     28        message : "The type of 'id' property must be number"
    2929    }
    3030    id : null
    3131}
    3232error.code: -32600
    33 error.getMessage(): The type of 'id' property should be number
    34 error.toString(): Invalid Request(-32600): The type of 'id' property should be number.
     33error.getMessage(): The type of 'id' property must be number
     34error.toString(): Invalid Request(-32600): The type of 'id' property must be number.
    3535-------------------------------------------------------
    3636{
    3737    error : {
    3838        code : -32600
    39         message : "The type of 'method' property should be string"
     39        message : "The type of 'method' property must be string"
    4040    }
    4141    id : 1
    4242}
    4343error.code: -32600
    44 error.getMessage(): The type of 'method' property should be string
    45 error.toString(): Invalid Request(-32600): The type of 'method' property should be string.
     44error.getMessage(): The type of 'method' property must be string
     45error.toString(): Invalid Request(-32600): The type of 'method' property must be string.
    4646-------------------------------------------------------
    4747{
     
    7272        message : "Some arguments of method 'Page.getResourceContent' can't be processed"
    7373        data : [
    74             "'params' property with type 'object' was not found."
     74            "'params' object must contain required parameter 'frameId' with type 'String'."
     75            "'params' object must contain required parameter 'url' with type 'String'."
    7576        ]
    7677    }
     
    7980error.code: -32602
    8081error.getMessage(): Some arguments of method 'Page.getResourceContent' can't be processed
    81 error.toString(): Invalid params(-32602): Some arguments of method 'Page.getResourceContent' can't be processed. 'params' property with type 'object' was not found.
    82 -------------------------------------------------------
    83 {
    84     error : {
    85         code : -32602
    86         message : "Some arguments of method 'Page.getResourceContent' can't be processed"
    87         data : [
    88             "'params' property with type 'object' was not found."
     82error.toString(): Invalid params(-32602): Some arguments of method 'Page.getResourceContent' can't be processed. 'params' object must contain required parameter 'frameId' with type 'String'. 'params' object must contain required parameter 'url' with type 'String'.
     83-------------------------------------------------------
     84{
     85    error : {
     86        code : -32602
     87        message : "Some arguments of method 'Page.getResourceContent' can't be processed"
     88        data : [
     89            "'params' object must contain required parameter 'frameId' with type 'String'."
     90            "'params' object must contain required parameter 'url' with type 'String'."
    8991        ]
    9092    }
     
    9395error.code: -32602
    9496error.getMessage(): Some arguments of method 'Page.getResourceContent' can't be processed
    95 error.toString(): Invalid params(-32602): Some arguments of method 'Page.getResourceContent' can't be processed. 'params' property with type 'object' was not found.
     97error.toString(): Invalid params(-32602): Some arguments of method 'Page.getResourceContent' can't be processed. 'params' object must contain required parameter 'frameId' with type 'String'. 'params' object must contain required parameter 'url' with type 'String'.
    9698-------------------------------------------------------
    9799{
  • trunk/Source/WebCore/ChangeLog

    r92103 r92104  
     12011-07-28  Pavel Feldman  <pfeldman@google.com>
     2
     3        Web Inspector: [protocol] methods where all parameters are optional should not require empty params object.
     4        https://bugs.webkit.org/show_bug.cgi?id=65331
     5
     6        Reviewed by Yury Semikhatsky.
     7
     8        * inspector/CodeGeneratorInspector.pm:
     9        (generateBackendFunction):
     10        (generateArgumentGetters):
     11
    1122011-08-01  Adam Barth  <abarth@webkit.org>
    213
  • trunk/Source/WebCore/inspector/CodeGeneratorInspector.pm

    r90558 r92104  
    457457    my $indent = "";
    458458    if (scalar(@inArgs)) {
    459         push(@function, "    if (RefPtr<InspectorObject> paramsContainer = requestMessageObject->getObject(\"params\")) {");
    460         push(@function, "        InspectorObject* paramsContainerPtr = paramsContainer.get();");
    461         push(@function, "        InspectorArray* protocolErrorsPtr = protocolErrors.get();");
     459        push(@function, "    RefPtr<InspectorObject> paramsContainer = requestMessageObject->getObject(\"params\");");
     460        push(@function, "    InspectorObject* paramsContainerPtr = paramsContainer.get();");
     461        push(@function, "    InspectorArray* protocolErrorsPtr = protocolErrors.get();");
    462462
    463463        foreach my $parameter (@inArgs) {
     
    467467            my $optionalFlagArgument = "0";
    468468            if ($parameter->extendedAttributes->{"optional"}) {
    469                 push(@function, "        bool ${name}_valueFound = false;");
     469                push(@function, "    bool ${name}_valueFound = false;");
    470470                $optionalFlagArgument = "&${name}_valueFound";
    471471            }
    472             push(@function, "        " . typeTraits($type, "variable") . " in_$name = get$typeString(paramsContainerPtr, \"$name\", $optionalFlagArgument, protocolErrorsPtr);");
     472            push(@function, "    " . typeTraits($type, "variable") . " in_$name = get$typeString(paramsContainerPtr, \"$name\", $optionalFlagArgument, protocolErrorsPtr);");
    473473        }
    474474        push(@function, "");
     
    483483                     map("&out_" . $_->name, @outArgs)));
    484484
    485     push(@function, "$indent    if (!protocolErrors->length())");
    486     push(@function, "$indent        $domainAccessor->$functionName($args);");
    487     if (scalar(@inArgs)) {
    488         push(@function, "    } else");
    489         push(@function, "        protocolErrors->pushString(\"'params' property with type 'object' was not found.\");");
    490     }
     485    push(@function, $indent . "if (!protocolErrors->length())");
     486    push(@function, $indent . "    $domainAccessor->$functionName($args);");
    491487    push(@function, "");
    492488    push(@function, "    RefPtr<InspectorObject> result = InspectorObject::create();");
     
    591587$return InspectorBackendDispatcher::get$typeString(InspectorObject* object, const String& name, bool* valueFound, InspectorArray* protocolErrors)
    592588{
    593     ASSERT(object);
    594589    ASSERT(protocolErrors);
    595590
     
    598593
    599594    $variable value = $defaultValue;
     595
     596    if (!object) {
     597        if (!valueFound) {
     598            // Required parameter in missing params container.
     599            protocolErrors->pushString(String::format("'params' object must contain required parameter '\%s' with type '$json'.", name.utf8().data()));
     600        }
     601        return value;
     602    }
     603
    600604    InspectorObject::const_iterator end = object->end();
    601605    InspectorObject::const_iterator valueIterator = object->find(name);
     
    608612
    609613    if (!valueIterator->second->as$json(&value))
    610         protocolErrors->pushString(String::format("Parameter '\%s' has wrong type. It should be '$json'.", name.utf8().data()));
     614        protocolErrors->pushString(String::format("Parameter '\%s' has wrong type. It must be '$json'.", name.utf8().data()));
    611615    else
    612616        if (valueFound)
     
    645649    RefPtr<InspectorValue> parsedMessage = InspectorValue::parseJSON(message);
    646650    if (!parsedMessage) {
    647         reportProtocolError(0, ParseError, "Message should be in JSON format");
     651        reportProtocolError(0, ParseError, "Message must be in JSON format");
    648652        return;
    649653    }
     
    651655    RefPtr<InspectorObject> messageObject = parsedMessage->asObject();
    652656    if (!messageObject) {
    653         reportProtocolError(0, InvalidRequest, "Message should be a JSONified object");
     657        reportProtocolError(0, InvalidRequest, "Message must be a JSONified object");
    654658        return;
    655659    }
     
    662666
    663667    if (!callIdValue->asNumber(&callId)) {
    664         reportProtocolError(0, InvalidRequest, "The type of 'id' property should be number");
     668        reportProtocolError(0, InvalidRequest, "The type of 'id' property must be number");
    665669        return;
    666670    }
     
    674678    String method;
    675679    if (!methodValue->asString(&method)) {
    676         reportProtocolError(&callId, InvalidRequest, "The type of 'method' property should be string");
     680        reportProtocolError(&callId, InvalidRequest, "The type of 'method' property must be string");
    677681        return;
    678682    }
     
    793797        var agentMethod = domainAndMethod[0] + "Agent." + domainAndMethod[1];
    794798
     799        var hasParams = false;
    795800        if (request.params) {
    796801            for (var key in request.params) {
     
    799804
    800805                if (args.length === 0 && !optionalFlag) {
    801                     console.error("Protocol Error: Invalid number of arguments for method '" + agentMethod + "' call. It should have the next arguments '" + JSON.stringify(request.params) + "'.");
     806                    console.error("Protocol Error: Invalid number of arguments for method '" + agentMethod + "' call. It must have the next arguments '" + JSON.stringify(request.params) + "'.");
    802807                    return;
    803808                }
     
    810815
    811816                if (typeof value !== typeName) {
    812                     console.error("Protocol Error: Invalid type of argument '" + key + "' for method '" + agentMethod + "' call. It should be '" + typeName + "' but it is '" + typeof value + "'.");
     817                    console.error("Protocol Error: Invalid type of argument '" + key + "' for method '" + agentMethod + "' call. It must be '" + typeName + "' but it is '" + typeof value + "'.");
    813818                    return;
    814819                }
    815820
    816821                request.params[key] = value;
     822                hasParams = true;
    817823            }
     824            if (!hasParams)
     825                delete request.params;
    818826        }
    819827
    820828        if (args.length === 1 && !callback) {
    821829            if (typeof args[0] !== "undefined") {
    822                 console.error("Protocol Error: Optional callback argument for method '" + agentMethod + "' call should be a function but its type is '" + typeof args[0] + "'.");
     830                console.error("Protocol Error: Optional callback argument for method '" + agentMethod + "' call must be a function but its type is '" + typeof args[0] + "'.");
    823831                return;
    824832            }
Note: See TracChangeset for help on using the changeset viewer.