Changeset 63962 in webkit


Ignore:
Timestamp:
Jul 23, 2010 4:58:54 AM (14 years ago)
Author:
yurys@chromium.org
Message:

2010-07-23 Yury Semikhatsky <yurys@chromium.org>

Reviewed by Pavel Feldman.

Web Inspector: error info propagation in InspectorBackendDispatch should be improved
https://bugs.webkit.org/show_bug.cgi?id=42873

  • inspector/CodeGeneratorInspector.pm: report wrong parameter count and wrong parametere type errror to the dispatch method caller
Location:
trunk/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r63961 r63962  
     12010-07-23  Yury Semikhatsky  <yurys@chromium.org>
     2
     3        Reviewed by Pavel Feldman.
     4
     5        Web Inspector: error info propagation in InspectorBackendDispatch should be improved
     6        https://bugs.webkit.org/show_bug.cgi?id=42873
     7
     8        * inspector/CodeGeneratorInspector.pm: report wrong parameter count and wrong
     9        parametere type errror to the dispatch method caller
     10
    1112010-07-23  Pavel Feldman  <pfeldman@chromium.org>
    212
  • trunk/WebCore/inspector/CodeGeneratorInspector.pm

    r63952 r63962  
    173173    $backendTypes{"Array"} = 1;
    174174
     175    generateBackendPrivateFunctions();
    175176    generateFunctions($interface);
    176177}
     
    223224}
    224225
     226sub generateBackendPrivateFunctions
     227{
     228    my $privateFunctions = << "EOF";
     229static String formatWrongArgumentsCountMessage(unsigned expected, unsigned actual)
     230{
     231    return String::format(\"Wrong number of parameters: %d (expected: %d)\", actual, expected);
     232}
     233
     234static String formatWrongArgumentTypeMessage(unsigned position, const char* name, const char* expectedType)
     235{
     236    return String::format(\"Failed to convert parameter %d (%s) to %s\", position, name, expectedType);
     237}
     238EOF
     239    push(@backendMethodsImpl, $privateFunctions);
     240}
     241
    225242sub generateBackendFunction
    226243{
     
    234251    my $arguments = join(", ", map($typeTransform{$_->type}->{"param"} . " " . $_->name, @argsFiltered));
    235252
    236     my $signature = "    void ${functionName}(PassRefPtr<InspectorArray> args);";
     253    my $signature = "    void ${functionName}(PassRefPtr<InspectorArray> args, String* exception);";
    237254    !$backendMethods{${signature}} || die "Duplicate function was detected for signature '$signature'.";
    238255    $backendMethods{${signature}} = $functionName;
    239256
    240257    my @function;
    241     # Skip parameter name if no arguments in the array. Just to avoid unused parameter warning.
    242     push(@function, "void ${backendClassName}::${functionName}(PassRefPtr<InspectorArray>" . ( scalar(@argsFiltered) ? " args)" : ")"));
     258    push(@function, "void ${backendClassName}::${functionName}(PassRefPtr<InspectorArray> args, String* exception)");
    243259    push(@function, "{");
    244260    my $i = 1; # zero element is the method name.
     261    my $expectedParametersCount = scalar(@argsFiltered);
     262    push(@function, "    if (args->length() != $expectedParametersCount) {");
     263    push(@function, "        *exception = formatWrongArgumentsCountMessage(args->length(), $expectedParametersCount);");
     264    push(@function, "        ASSERT_NOT_REACHED();");
     265    push(@function, "        return;");
     266    push(@function, "    }");
     267
    245268    foreach my $parameter (@argsFiltered) {
    246         push(@function, "    " . $typeTransform{$parameter->type}->{"retVal"} . " " . $parameter->name . ";");
    247         push(@function, "    if (!args->get(" . $i . ")->as" . $typeTransform{$parameter->type}->{"accessorSuffix"} . "(&" . $parameter->name . ")) {");
     269        my $parameterType = $parameter->type;
     270        push(@function, "    " . $typeTransform{$parameterType}->{"retVal"} . " " . $parameter->name . ";");
     271        push(@function, "    if (!args->get(" . $i . ")->as" . $typeTransform{$parameterType}->{"accessorSuffix"} . "(&" . $parameter->name . ")) {");
     272        push(@function, "        *exception = formatWrongArgumentTypeMessage($i, \"" . $parameter->name . "\", \"$parameterType\");");
    248273        push(@function, "        ASSERT_NOT_REACHED();");
    249274        push(@function, "        return;");
     
    265290    push(@body, "void ${backendClassName}::dispatch(const String& message, String* exception)");
    266291    push(@body, "{");
    267     push(@body, "    typedef void (${backendClassName}::*CallHandler)(PassRefPtr<InspectorArray> args);");
     292    push(@body, "    typedef void (${backendClassName}::*CallHandler)(PassRefPtr<InspectorArray> args, String* exception);");
    268293    push(@body, "    typedef HashMap<String, CallHandler> DispatchMap;");
    269294    push(@body, "    DEFINE_STATIC_LOCAL(DispatchMap, dispatchMap, );");
     
    302327    push(@body, "    if (it == dispatchMap.end()) {");
    303328    push(@body, "        ASSERT_NOT_REACHED();");
    304     push(@body, "        String::format(\"Error: Invalid method name. '%s' wasn't found.\", methodName.utf8().data());");
     329    push(@body, "        *exception = String::format(\"Error: Invalid method name. '%s' wasn't found.\", methodName.utf8().data());");
    305330    push(@body, "        return;");
    306331    push(@body, "    }");
    307332    push(@body, "");
    308     push(@body, "    ((*this).*it->second)(messageArray);");
     333    push(@body, "    ((*this).*it->second)(messageArray, exception);");
    309334    push(@body, "}");
    310335    return @body;
Note: See TracChangeset for help on using the changeset viewer.