Title: [104443] trunk/Source/WebCore
Revision
104443
Author
[email protected]
Date
2012-01-09 01:38:37 -0800 (Mon, 09 Jan 2012)

Log Message

[Refactoring] Use join(", ", @arguments) to build a method argument string
in CodeGeneratorJS.pm
https://bugs.webkit.org/show_bug.cgi?id=75830

Reviewed by Adam Barth.

The code in CodeGeneratorJS.pm to build a method argument string is dirty
and error-prone. It is concatenating arguments one by one judging whether
", " is necessary or not. This patch refactors the code so that it pushes
all arguments into @arguments and then builds a method string by
join(", ", @arguments).

Test: bindings/scripts/test/*

* bindings/scripts/CodeGeneratorJS.pm:
(GenerateImplementation):
(GenerateParametersCheck):
(GenerateImplementationFunctionCall):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (104442 => 104443)


--- trunk/Source/WebCore/ChangeLog	2012-01-09 09:09:18 UTC (rev 104442)
+++ trunk/Source/WebCore/ChangeLog	2012-01-09 09:38:37 UTC (rev 104443)
@@ -1,3 +1,24 @@
+2012-01-09  Kentaro Hara  <[email protected]>
+
+        [Refactoring] Use join(", ", @arguments) to build a method argument string
+        in CodeGeneratorJS.pm
+        https://bugs.webkit.org/show_bug.cgi?id=75830
+
+        Reviewed by Adam Barth.
+
+        The code in CodeGeneratorJS.pm to build a method argument string is dirty
+        and error-prone. It is concatenating arguments one by one judging whether
+        ", " is necessary or not. This patch refactors the code so that it pushes
+        all arguments into @arguments and then builds a method string by
+        join(", ", @arguments).
+
+        Test: bindings/scripts/test/*
+
+        * bindings/scripts/CodeGeneratorJS.pm:
+        (GenerateImplementation):
+        (GenerateParametersCheck):
+        (GenerateImplementationFunctionCall):
+
 2012-01-09  Andreas Kling  <[email protected]>
 
         CSSMutableStyleDeclaration: Remove propertiesEqual().

Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm (104442 => 104443)


--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm	2012-01-09 09:09:18 UTC (rev 104442)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm	2012-01-09 09:38:37 UTC (rev 104443)
@@ -2181,8 +2181,8 @@
                     push(@implContent, GenerateEventListenerCall($className, "remove"));
                 } else {
                     my $numParameters = @{$function->parameters};
-                    my ($functionString, $paramIndex) = GenerateParametersCheck(\@implContent, $function, $dataNode, $numParameters, $implClassName, $functionImplementationName, $svgPropertyType, $svgPropertyOrListPropertyType, $svgListPropertyType);
-                    GenerateImplementationFunctionCall($function, $functionString, $paramIndex, "    ", $svgPropertyType, $implClassName);
+                    my ($functionString, $dummy) = GenerateParametersCheck(\@implContent, $function, $dataNode, $numParameters, $implClassName, $functionImplementationName, $svgPropertyType, $svgPropertyOrListPropertyType, $svgListPropertyType);
+                    GenerateImplementationFunctionCall($function, $functionString, "    ", $svgPropertyType, $implClassName);
                 }
             }
 
@@ -2419,7 +2419,6 @@
     my $svgPropertyOrListPropertyType = shift;
     my $svgListPropertyType = shift;
 
-    my $paramIndex = 0;
     my $argsIndex = 0;
     my $hasOptionalArguments = 0;
 
@@ -2431,7 +2430,8 @@
     } else {
         $functionBase = "impl->";
     }
-    my $functionString = "$functionBase$functionImplementationName(";
+    my $functionName = "$functionBase$functionImplementationName";
+    my @arguments;
 
     if ($function->signature->extendedAttributes->{"CustomArgumentHandling"} and !$function->isStatic) {
         push(@$outputArray, "    RefPtr<ScriptArguments> scriptArguments(createScriptArguments(exec, $numParameters));\n");
@@ -2452,9 +2452,7 @@
             push(@$outputArray, "        return JSValue::encode(jsUndefined());\n");
             $callWithArg = "scriptContext"; 
         }
-        $functionString .= ", " if $paramIndex;
-        $functionString .= $callWithArg;
-        $paramIndex++;
+        push @arguments, $callWithArg;
     }
 
     $implIncludes{"ExceptionCode.h"} = 1;
@@ -2473,7 +2471,16 @@
                 $hasOptionalArguments = 1;
             }
             push(@$outputArray, "    if (argsCount <= $argsIndex) {\n");
-            GenerateImplementationFunctionCall($function, $functionString, $paramIndex, "    " x 2, $svgPropertyType, $implClassName);
+
+            my @optionalCallbackArguments = @arguments;
+            if ($function->signature->extendedAttributes->{"CustomArgumentHandling"}) {
+                push @optionalCallbackArguments, "scriptArguments, callStack";
+            }
+            if (@{$function->raisesExceptions}) {
+                push @optionalCallbackArguments, "ec";
+            }
+            my $functionString = "$functionName(" . join(", ", @optionalCallbackArguments) . ")";
+            GenerateImplementationFunctionCall($function, $functionString, "    " x 2, $svgPropertyType, $implClassName);
             push(@$outputArray, "    }\n\n");
         }
 
@@ -2554,20 +2561,23 @@
             }
         }
 
-        $functionString .= ", " if $paramIndex;
-
         if ($argType eq "NodeFilter") {
-            $functionString .= "$name.get()";
+            push @arguments, "$name.get()";
         } elsif ($codeGenerator->IsSVGTypeNeedingTearOff($argType) and not $implClassName =~ /List$/) {
-            $functionString .= "$name->propertyReference()";
+            push @arguments, "$name->propertyReference()";
         } else {
-            $functionString .= $name;
+            push @arguments, $name;
         }
         $argsIndex++;
-        $paramIndex++;
     }
 
-    return ($functionString, $paramIndex);
+    if ($function->signature->extendedAttributes->{"CustomArgumentHandling"}) {
+        push @arguments, "scriptArguments, callStack";
+    }
+    if (@{$function->raisesExceptions}) {
+        push @arguments, "ec";
+    }
+    return ("$functionName(" . join(", ", @arguments) . ")", scalar @arguments);
 }
 
 sub GenerateCallbackHeader
@@ -2732,23 +2742,10 @@
 {
     my $function = shift;
     my $functionString = shift;
-    my $paramIndex = shift;
     my $indent = shift;
     my $svgPropertyType = shift;
     my $implClassName = shift;
 
-    if ($function->signature->extendedAttributes->{"CustomArgumentHandling"}) {
-        $functionString .= ", " if $paramIndex;
-        $paramIndex += 2;
-        $functionString .= "scriptArguments, callStack";
-    }
-
-    if (@{$function->raisesExceptions}) {
-        $functionString .= ", " if $paramIndex;
-        $functionString .= "ec";
-    }
-    $functionString .= ")";
-
     if ($function->signature->type eq "void") {
         push(@implContent, $indent . "$functionString;\n");
         push(@implContent, $indent . "setDOMException(exec, ec);\n") if @{$function->raisesExceptions};
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to