Title: [92104] trunk
Revision
92104
Author
pfeld...@chromium.org
Date
2011-08-01 01:13:55 -0700 (Mon, 01 Aug 2011)

Log 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:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (92103 => 92104)


--- trunk/LayoutTests/ChangeLog	2011-08-01 08:04:11 UTC (rev 92103)
+++ trunk/LayoutTests/ChangeLog	2011-08-01 08:13:55 UTC (rev 92104)
@@ -1,3 +1,12 @@
+2011-07-28  Pavel Feldman  <pfeld...@google.com>
+
+        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.
+
+        * inspector/report-protocol-errors-expected.txt:
+
 2011-07-31  Adam Barth  <aba...@webkit.org>
 
         These results appear to differ only in text rendering.

Modified: trunk/LayoutTests/inspector/report-API-errors-expected.txt (92103 => 92104)


--- trunk/LayoutTests/inspector/report-API-errors-expected.txt	2011-08-01 08:04:11 UTC (rev 92103)
+++ trunk/LayoutTests/inspector/report-API-errors-expected.txt	2011-08-01 08:13:55 UTC (rev 92104)
@@ -1,8 +1,8 @@
 Tests that InspectorBackendStub is catching incorrect arguments.
 
-Protocol Error: Invalid type of argument 'enabled' for method 'ConsoleAgent.setMonitoringXHREnabled' call. It should be 'boolean' but it is 'number'.
-Protocol Error: Invalid number of arguments for method 'ConsoleAgent.setMonitoringXHREnabled' call. It should have the next arguments '{"enabled":{"optional":false,"type":"boolean"}}'.
-Protocol Error: Optional callback argument for method 'ConsoleAgent.setMonitoringXHREnabled' call should be a function but its type is 'string'.
+Protocol Error: Invalid type of argument 'enabled' for method 'ConsoleAgent.setMonitoringXHREnabled' call. It must be 'boolean' but it is 'number'.
+Protocol Error: Invalid number of arguments for method 'ConsoleAgent.setMonitoringXHREnabled' call. It must have the next arguments '{"enabled":{"optional":false,"type":"boolean"}}'.
+Protocol Error: Optional callback argument for method 'ConsoleAgent.setMonitoringXHREnabled' call must be a function but its type is 'string'.
 Protocol Error: the message is for non-existing domain 'wrongDomain'
 Protocol Error: Attempted to dispatch an unimplemented method 'Inspector.something-strange'
 

Modified: trunk/LayoutTests/inspector/report-protocol-errors-expected.txt (92103 => 92104)


--- trunk/LayoutTests/inspector/report-protocol-errors-expected.txt	2011-08-01 08:04:11 UTC (rev 92103)
+++ trunk/LayoutTests/inspector/report-protocol-errors-expected.txt	2011-08-01 08:13:55 UTC (rev 92104)
@@ -3,13 +3,13 @@
 {
     error : {
         code : -32700
-        message : "Message should be in JSON format"
+        message : "Message must be in JSON format"
     }
     id : null
 }
 error.code: -32700
-error.getMessage(): Message should be in JSON format
-error.toString(): Parse error(-32700): Message should be in JSON format.
+error.getMessage(): Message must be in JSON format
+error.toString(): Parse error(-32700): Message must be in JSON format.
 -------------------------------------------------------
 {
     error : {
@@ -25,24 +25,24 @@
 {
     error : {
         code : -32600
-        message : "The type of 'id' property should be number"
+        message : "The type of 'id' property must be number"
     }
     id : null
 }
 error.code: -32600
-error.getMessage(): The type of 'id' property should be number
-error.toString(): Invalid Request(-32600): The type of 'id' property should be number.
+error.getMessage(): The type of 'id' property must be number
+error.toString(): Invalid Request(-32600): The type of 'id' property must be number.
 -------------------------------------------------------
 {
     error : {
         code : -32600
-        message : "The type of 'method' property should be string"
+        message : "The type of 'method' property must be string"
     }
     id : 1
 }
 error.code: -32600
-error.getMessage(): The type of 'method' property should be string
-error.toString(): Invalid Request(-32600): The type of 'method' property should be string.
+error.getMessage(): The type of 'method' property must be string
+error.toString(): Invalid Request(-32600): The type of 'method' property must be string.
 -------------------------------------------------------
 {
     error : {
@@ -71,28 +71,30 @@
         code : -32602
         message : "Some arguments of method 'Page.getResourceContent' can't be processed"
         data : [
-            "'params' property with type 'object' was not found."
+            "'params' object must contain required parameter 'frameId' with type 'String'."
+            "'params' object must contain required parameter 'url' with type 'String'."
         ]
     }
     id : 4
 }
 error.code: -32602
 error.getMessage(): Some arguments of method 'Page.getResourceContent' can't be processed
-error.toString(): Invalid params(-32602): Some arguments of method 'Page.getResourceContent' can't be processed. 'params' property with type 'object' was not found.
+error.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'.
 -------------------------------------------------------
 {
     error : {
         code : -32602
         message : "Some arguments of method 'Page.getResourceContent' can't be processed"
         data : [
-            "'params' property with type 'object' was not found."
+            "'params' object must contain required parameter 'frameId' with type 'String'."
+            "'params' object must contain required parameter 'url' with type 'String'."
         ]
     }
     id : 5
 }
 error.code: -32602
 error.getMessage(): Some arguments of method 'Page.getResourceContent' can't be processed
-error.toString(): Invalid params(-32602): Some arguments of method 'Page.getResourceContent' can't be processed. 'params' property with type 'object' was not found.
+error.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'.
 -------------------------------------------------------
 {
     error : {

Modified: trunk/Source/WebCore/ChangeLog (92103 => 92104)


--- trunk/Source/WebCore/ChangeLog	2011-08-01 08:04:11 UTC (rev 92103)
+++ trunk/Source/WebCore/ChangeLog	2011-08-01 08:13:55 UTC (rev 92104)
@@ -1,3 +1,14 @@
+2011-07-28  Pavel Feldman  <pfeld...@google.com>
+
+        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.
+
+        * inspector/CodeGeneratorInspector.pm:
+        (generateBackendFunction):
+        (generateArgumentGetters):
+
 2011-08-01  Adam Barth  <aba...@webkit.org>
 
         application/json MIME type shouldn't cause warnings in <script> tags

Modified: trunk/Source/WebCore/inspector/CodeGeneratorInspector.pm (92103 => 92104)


--- trunk/Source/WebCore/inspector/CodeGeneratorInspector.pm	2011-08-01 08:04:11 UTC (rev 92103)
+++ trunk/Source/WebCore/inspector/CodeGeneratorInspector.pm	2011-08-01 08:13:55 UTC (rev 92104)
@@ -456,9 +456,9 @@
 
     my $indent = "";
     if (scalar(@inArgs)) {
-        push(@function, "    if (RefPtr<InspectorObject> paramsContainer = requestMessageObject->getObject(\"params\")) {");
-        push(@function, "        InspectorObject* paramsContainerPtr = paramsContainer.get();");
-        push(@function, "        InspectorArray* protocolErrorsPtr = protocolErrors.get();");
+        push(@function, "    RefPtr<InspectorObject> paramsContainer = requestMessageObject->getObject(\"params\");");
+        push(@function, "    InspectorObject* paramsContainerPtr = paramsContainer.get();");
+        push(@function, "    InspectorArray* protocolErrorsPtr = protocolErrors.get();");
 
         foreach my $parameter (@inArgs) {
             my $name = $parameter->name;
@@ -466,10 +466,10 @@
             my $typeString = camelCase($parameter->type);
             my $optionalFlagArgument = "0";
             if ($parameter->extendedAttributes->{"optional"}) {
-                push(@function, "        bool ${name}_valueFound = false;");
+                push(@function, "    bool ${name}_valueFound = false;");
                 $optionalFlagArgument = "&${name}_valueFound";
             }
-            push(@function, "        " . typeTraits($type, "variable") . " in_$name = get$typeString(paramsContainerPtr, \"$name\", $optionalFlagArgument, protocolErrorsPtr);");
+            push(@function, "    " . typeTraits($type, "variable") . " in_$name = get$typeString(paramsContainerPtr, \"$name\", $optionalFlagArgument, protocolErrorsPtr);");
         }
         push(@function, "");
         $indent = "    ";
@@ -482,12 +482,8 @@
                           "in_" . $_->name), @inArgs),
                      map("&out_" . $_->name, @outArgs)));
 
-    push(@function, "$indent    if (!protocolErrors->length())");
-    push(@function, "$indent        $domainAccessor->$functionName($args);");
-    if (scalar(@inArgs)) {
-        push(@function, "    } else");
-        push(@function, "        protocolErrors->pushString(\"'params' property with type 'object' was not found.\");");
-    }
+    push(@function, $indent . "if (!protocolErrors->length())");
+    push(@function, $indent . "    $domainAccessor->$functionName($args);");
     push(@function, "");
     push(@function, "    RefPtr<InspectorObject> result = InspectorObject::create();");
     if (scalar(@outArgs)) {
@@ -590,13 +586,21 @@
 
 $return InspectorBackendDispatcher::get$typeString(InspectorObject* object, const String& name, bool* valueFound, InspectorArray* protocolErrors)
 {
-    ASSERT(object);
     ASSERT(protocolErrors);
 
     if (valueFound)
         *valueFound = false;
 
     $variable value = $defaultValue;
+
+    if (!object) {
+        if (!valueFound) {
+            // Required parameter in missing params container.
+            protocolErrors->pushString(String::format("'params' object must contain required parameter '\%s' with type '$json'.", name.utf8().data()));
+        }
+        return value;
+    }
+
     InspectorObject::const_iterator end = object->end();
     InspectorObject::const_iterator valueIterator = object->find(name);
 
@@ -607,7 +611,7 @@
     }
 
     if (!valueIterator->second->as$json(&value))
-        protocolErrors->pushString(String::format("Parameter '\%s' has wrong type. It should be '$json'.", name.utf8().data()));
+        protocolErrors->pushString(String::format("Parameter '\%s' has wrong type. It must be '$json'.", name.utf8().data()));
     else
         if (valueFound)
             *valueFound = true;
@@ -644,13 +648,13 @@
 
     RefPtr<InspectorValue> parsedMessage = InspectorValue::parseJSON(message);
     if (!parsedMessage) {
-        reportProtocolError(0, ParseError, "Message should be in JSON format");
+        reportProtocolError(0, ParseError, "Message must be in JSON format");
         return;
     }
 
     RefPtr<InspectorObject> messageObject = parsedMessage->asObject();
     if (!messageObject) {
-        reportProtocolError(0, InvalidRequest, "Message should be a JSONified object");
+        reportProtocolError(0, InvalidRequest, "Message must be a JSONified object");
         return;
     }
 
@@ -661,7 +665,7 @@
     }
 
     if (!callIdValue->asNumber(&callId)) {
-        reportProtocolError(0, InvalidRequest, "The type of 'id' property should be number");
+        reportProtocolError(0, InvalidRequest, "The type of 'id' property must be number");
         return;
     }
 
@@ -673,7 +677,7 @@
 
     String method;
     if (!methodValue->asString(&method)) {
-        reportProtocolError(&callId, InvalidRequest, "The type of 'method' property should be string");
+        reportProtocolError(&callId, InvalidRequest, "The type of 'method' property must be string");
         return;
     }
 
@@ -792,13 +796,14 @@
         var domainAndMethod = request.method.split(".");
         var agentMethod = domainAndMethod[0] + "Agent." + domainAndMethod[1];
 
+        var hasParams = false;
         if (request.params) {
             for (var key in request.params) {
                 var typeName = request.params[key].type;
                 var optionalFlag = request.params[key].optional;
 
                 if (args.length === 0 && !optionalFlag) {
-                    console.error("Protocol Error: Invalid number of arguments for method '" + agentMethod + "' call. It should have the next arguments '" + JSON.stringify(request.params) + "'.");
+                    console.error("Protocol Error: Invalid number of arguments for method '" + agentMethod + "' call. It must have the next arguments '" + JSON.stringify(request.params) + "'.");
                     return;
                 }
 
@@ -809,17 +814,20 @@
                 }
 
                 if (typeof value !== typeName) {
-                    console.error("Protocol Error: Invalid type of argument '" + key + "' for method '" + agentMethod + "' call. It should be '" + typeName + "' but it is '" + typeof value + "'.");
+                    console.error("Protocol Error: Invalid type of argument '" + key + "' for method '" + agentMethod + "' call. It must be '" + typeName + "' but it is '" + typeof value + "'.");
                     return;
                 }
 
                 request.params[key] = value;
+                hasParams = true;
             }
+            if (!hasParams)
+                delete request.params;
         }
 
         if (args.length === 1 && !callback) {
             if (typeof args[0] !== "undefined") {
-                console.error("Protocol Error: Optional callback argument for method '" + agentMethod + "' call should be a function but its type is '" + typeof args[0] + "'.");
+                console.error("Protocol Error: Optional callback argument for method '" + agentMethod + "' call must be a function but its type is '" + typeof args[0] + "'.");
                 return;
             }
         }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to