diff options
Diffstat (limited to 'WebCore/inspector/CodeGeneratorInspector.pm')
-rw-r--r-- | WebCore/inspector/CodeGeneratorInspector.pm | 95 |
1 files changed, 67 insertions, 28 deletions
diff --git a/WebCore/inspector/CodeGeneratorInspector.pm b/WebCore/inspector/CodeGeneratorInspector.pm index 550b5b4..177ca3b 100644 --- a/WebCore/inspector/CodeGeneratorInspector.pm +++ b/WebCore/inspector/CodeGeneratorInspector.pm @@ -92,6 +92,7 @@ $typeTransform{"Value"} = { $typeTransform{"String"} = { "param" => "const String&", "variable" => "String", + "return" => "String", "defaultValue" => "\"\"", "forwardHeader" => "wtf/Forward.h", "header" => "PlatformString.h", @@ -266,6 +267,12 @@ sub generateFunctions push(@backendMethodsImpl, generateBackendDispatcher()); push(@backendMethodsImpl, generateBackendReportProtocolError()); + foreach my $type (keys %backendTypes) { + if ($typeTransform{$type}{"JSONType"}) { + push(@backendMethodsImpl, generateArgumentGetters($type)); + } + } + @backendStubJS = generateBackendStubJS($interface); } @@ -301,6 +308,14 @@ sub generateFrontendFunction } } +sub camelCase +{ + my $value = shift; + $value =~ s/\b(\w)/\U$1/g; # make a camel-case name for type name + $value =~ s/ //g; + return $value; +} + sub generateBackendFunction { my $function = shift; @@ -332,43 +347,31 @@ sub generateBackendFunction push(@function, " protocolErrors->pushString(\"Protocol Error: $domain handler is not available.\");"); push(@function, ""); - if (scalar(@inArgs)) { - # declare variables for all 'in' args; - push(@function, map(" " . $typeTransform{$_->type}->{"variable"} . " " . $_->name . " = " . $typeTransform{$_->type}->{"defaultValue"} . ";", @inArgs)); + # declare local variables for out arguments. + push(@function, map(" " . $typeTransform{$_->type}->{"variable"} . " " . $_->name . " = " . $typeTransform{$_->type}->{"defaultValue"} . ";", @outArgs)); - push(@function, ""); - push(@function, " RefPtr<InspectorObject> argumentsContainer;"); - push(@function, " if (!(argumentsContainer = requestMessageObject->getObject(\"arguments\"))) {"); - push(@function, " protocolErrors->pushString(\"Protocol Error: 'arguments' property with type 'object' was not found.\");"); - push(@function, " } else {"); - push(@function, " InspectorObject::const_iterator argumentsEndIterator = argumentsContainer->end();"); + my $indent = ""; + if (scalar(@inArgs)) { + push(@function, " if (RefPtr<InspectorObject> argumentsContainer = requestMessageObject->getObject(\"arguments\")) {"); foreach my $parameter (@inArgs) { my $name = $parameter->name; my $type = $parameter->type; - my $variableType = $typeTransform{$type}->{"variable"}; - my $JSONType = $typeTransform{$type}->{"JSONType"}; - - push(@function, ""); - push(@function, " InspectorObject::const_iterator ${name}ValueIterator = argumentsContainer->find(\"$name\");"); - push(@function, " if (${name}ValueIterator == argumentsEndIterator) {"); - push(@function, " protocolErrors->pushString(\"Protocol Error: Argument '$name' with type '$JSONType' was not found.\");"); - push(@function, " } else {"); - push(@function, " if (!${name}ValueIterator->second->as$JSONType(&$name)) {"); - push(@function, " protocolErrors->pushString(\"Protocol Error: Argument '$name' has wrong type. It should be '$JSONType'.\");"); - push(@function, " }"); - push(@function, " }"); + my $typeString = camelCase($parameter->type); + push(@function, " " . $typeTransform{$type}->{"variable"} . " $name = get$typeString(argumentsContainer.get(), \"$name\", protocolErrors.get());"); } - push(@function, " }"); + push(@function, ""); + $indent = " "; } - # declare local variables for out arguments. - push(@function, map(" " . $typeTransform{$_->type}->{"variable"} . " " . $_->name . " = " . $typeTransform{$_->type}->{"defaultValue"} . ";", @outArgs)); - my $args = join(", ", (map($_->name, @inArgs), map("&" . $_->name, @outArgs))); - push(@function, " if (!protocolErrors->length())"); - push(@function, " $domainAccessor->$functionName($args);"); - push(@function, ""); + push(@function, "$indent if (!protocolErrors->length())"); + push(@function, "$indent $domainAccessor->$functionName($args);"); + if (scalar(@inArgs)) { + push(@function, " } else {"); + push(@function, " protocolErrors->pushString(\"Protocol Error: 'arguments' property with type 'object' was not found.\");"); + push(@function, " }"); + } push(@function, " // use InspectorFrontend as a marker of WebInspector availability"); push(@function, " if ((callId || protocolErrors->length()) && m_inspectorController->hasFrontend()) {"); @@ -412,6 +415,39 @@ EOF return split("\n", $reportProtocolError); } +sub generateArgumentGetters +{ + my $type = shift; + my $json = $typeTransform{$type}{"JSONType"}; + my $variable = $typeTransform{$type}{"variable"}; + my $defaultValue = $typeTransform{$type}{"defaultValue"}; + my $return = $typeTransform{$type}{"return"} ? $typeTransform{$type}{"return"} : $typeTransform{$type}{"param"}; + + my $typeString = camelCase($type); + push(@backendConstantDeclarations, "$return get$typeString(InspectorObject* object, const String& name, InspectorArray* protocolErrors);"); + my $getterBody = << "EOF"; + +$return InspectorBackendDispatcher::get$typeString(InspectorObject* object, const String& name, InspectorArray* protocolErrors) +{ + ASSERT(object); + ASSERT(protocolErrors); + + $variable value = $defaultValue; + InspectorObject::const_iterator end = object->end(); + InspectorObject::const_iterator valueIterator = object->find(name); + + if (valueIterator == end) + protocolErrors->pushString(String::format("Protocol Error: Argument '\%s' with type '$json' was not found.", name.utf8().data())); + else { + if (!valueIterator->second->as$json(&value)) + protocolErrors->pushString(String::format("Protocol Error: Argument '\%s' has wrong type. It should be '$json'.", name.utf8().data())); + } + return value; +} +EOF + + return split("\n", $getterBody); +} sub generateBackendDispatcher { @@ -563,6 +599,9 @@ WebInspector.InspectorBackendStub.prototype = { request.seq = WebInspector.Callback.wrap(args[0]); } + if (window.dumpInspectorProtocolMessages) + console.log("frontend: " + JSON.stringify(request)); + var message = JSON.stringify(request); InspectorFrontendHost.sendMessageToBackend(message); } |