Changeset 65058 in webkit


Ignore:
Timestamp:
Aug 10, 2010 1:41:17 AM (14 years ago)
Author:
loislo@chromium.org
Message:

2010-08-09 Ilya Tikhonovsky <loislo@chromium.org>

Reviewed by Yury Semikhatsky.

Web Inspector: small refactoring for CodeGeneratorInspector.
A number of push calls were replaced by embedded text.
Just for improve code readability.
https://bugs.webkit.org/show_bug.cgi?id=43770

  • inspector/CodeGeneratorInspector.pm:
Location:
trunk/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r65056 r65058  
     12010-08-09  Ilya Tikhonovsky  <loislo@chromium.org>
     2
     3        Reviewed by Yury Semikhatsky.
     4
     5        Web Inspector: small refactoring for CodeGeneratorInspector.
     6        A number of push calls were replaced by embedded text.
     7        Just for improve code readability.
     8        https://bugs.webkit.org/show_bug.cgi?id=43770
     9
     10        * inspector/CodeGeneratorInspector.pm:
     11
    1122010-08-09  Eric Seidel  <eric@webkit.org>
    213
  • trunk/WebCore/inspector/CodeGeneratorInspector.pm

    r65052 r65058  
    387387    my @body;
    388388    my @methods = map($backendMethods{$_}, keys %backendMethods);
    389     my @mapEntries = map("dispatchMap.add(\"$_\", &${backendClassName}::$_);", @methods);
    390 
    391     push(@body, "void ${backendClassName}::dispatch(const String& message)");
    392     push(@body, "{");
    393     push(@body, "    typedef void (${backendClassName}::*CallHandler)(PassRefPtr<InspectorArray> args);");
    394     push(@body, "    typedef HashMap<String, CallHandler> DispatchMap;");
    395     push(@body, "    DEFINE_STATIC_LOCAL(DispatchMap, dispatchMap, );");
    396     push(@body, "    if (dispatchMap.isEmpty()) {");
    397     push(@body, map("        $_", @mapEntries));
    398     push(@body, "    }");
    399     push(@body, "");
    400     push(@body, "    RefPtr<InspectorValue> parsedMessage = InspectorValue::parseJSON(message);");
    401     push(@body, "    if (!parsedMessage) {");
    402     push(@body, "        ASSERT_NOT_REACHED();");
    403     push(@body, "        reportProtocolError(0, \"dispatch\", \"Error: Invalid message format. Message should be in JSON format.\");");
    404     push(@body, "        return;");
    405     push(@body, "    }");
    406     push(@body, "");
    407     push(@body, "    RefPtr<InspectorArray> messageArray = parsedMessage->asArray();");
    408     push(@body, "    if (!messageArray) {");
    409     push(@body, "        ASSERT_NOT_REACHED();");
    410     push(@body, "        reportProtocolError(0, \"dispatch\", \"Error: Invalid message format. The message should be a JSONified array of arguments.\");");
    411     push(@body, "        return;");
    412     push(@body, "    }");
    413     push(@body, "");
    414     push(@body, "    if (!messageArray->length()) {");
    415     push(@body, "        ASSERT_NOT_REACHED();");
    416     push(@body, "        reportProtocolError(0, \"dispatch\", \"Error: Invalid message format. Empty message was received.\");");
    417     push(@body, "        return;");
    418     push(@body, "    }");
    419     push(@body, "");
    420     push(@body, "    String methodName;");
    421     push(@body, "    if (!messageArray->get(0)->asString(&methodName)) {");
    422     push(@body, "        ASSERT_NOT_REACHED();");
    423     push(@body, "        reportProtocolError(0, \"dispatch\", \"Error: Invalid message format. The first element of the message should be method name.\");");
    424     push(@body, "        return;");
    425     push(@body, "    }");
    426     push(@body, "");
    427     push(@body, "    HashMap<String, CallHandler>::iterator it = dispatchMap.find(methodName);");
    428     push(@body, "    if (it == dispatchMap.end()) {");
    429     push(@body, "        ASSERT_NOT_REACHED();");
    430     push(@body, "        reportProtocolError(0, \"dispatch\", String::format(\"Error: Invalid method name. '%s' wasn't found.\", methodName.utf8().data()));");
    431     push(@body, "        return;");
    432     push(@body, "    }");
    433     push(@body, "");
    434     push(@body, "    ((*this).*it->second)(messageArray);");
    435     push(@body, "}");
    436     return @body;
     389    my @mapEntries = map("        dispatchMap.add(\"$_\", &${backendClassName}::$_);", @methods);
     390    my $mapEntries = join("\n", @mapEntries);
     391
     392    my $backendDispatcherBody = << "EOF";
     393void ${backendClassName}::dispatch(const String& message)
     394{
     395    typedef void (${backendClassName}::*CallHandler)(PassRefPtr<InspectorArray> args);
     396    typedef HashMap<String, CallHandler> DispatchMap;
     397    DEFINE_STATIC_LOCAL(DispatchMap, dispatchMap, );
     398    if (dispatchMap.isEmpty()) {
     399$mapEntries
     400    }
     401
     402    RefPtr<InspectorValue> parsedMessage = InspectorValue::parseJSON(message);
     403    if (!parsedMessage) {
     404        ASSERT_NOT_REACHED();
     405        reportProtocolError(0, "dispatch", "Error: Invalid message format. Message should be in JSON format.");
     406        return;
     407    }
     408
     409    RefPtr<InspectorArray> messageArray = parsedMessage->asArray();
     410    if (!messageArray) {
     411        ASSERT_NOT_REACHED();
     412        reportProtocolError(0, "dispatch", "Error: Invalid message format. The message should be a JSONified array of arguments.");
     413        return;
     414    }
     415
     416    if (!messageArray->length()) {
     417        ASSERT_NOT_REACHED();
     418        reportProtocolError(0, "dispatch", "Error: Invalid message format. Empty message was received.");
     419        return;
     420    }
     421
     422    String methodName;
     423    if (!messageArray->get(0)->asString(&methodName)) {
     424        ASSERT_NOT_REACHED();
     425        reportProtocolError(0, "dispatch", "Error: Invalid message format. The first element of the message should be method name.");
     426        return;
     427    }
     428
     429    HashMap<String, CallHandler>::iterator it = dispatchMap.find(methodName);
     430    if (it == dispatchMap.end()) {
     431        ASSERT_NOT_REACHED();
     432        reportProtocolError(0, "dispatch", String::format("Error: Invalid method name. '%s' wasn't found.", methodName.utf8().data()));
     433        return;
     434    }
     435
     436    ((*this).*it->second)(messageArray);
     437}
     438EOF
     439    return split("\n", $backendDispatcherBody);
    437440}
    438441
Note: See TracChangeset for help on using the changeset viewer.