- a/Source/WebCore/ChangeLog +21 lines
Lines 1-3 a/Source/WebCore/ChangeLog_sec1
1
2012-01-09  Kentaro Hara  <haraken@chromium.org>
2
3
        [Refactoring] Use join(", ", @arguments) to build a method argument string
4
        in CodeGeneratorJS.pm
5
        https://bugs.webkit.org/show_bug.cgi?id=75830
6
7
        Reviewed by NOBODY (OOPS!).
8
9
        The code in CodeGeneratorJS.pm to build a method argument string is dirty
10
        and error-prone. It is concatenating arguments one by one judging whether
11
        ", " is necessary or not. This patch refactors the code so that it pushes
12
        all arguments into @arguments and then builds a method string by
13
        join(", ", @arguments).
14
15
        Test: bindings/scripts/test/*
16
17
        * bindings/scripts/CodeGeneratorJS.pm:
18
        (GenerateImplementation):
19
        (GenerateParametersCheck):
20
        (GenerateImplementationFunctionCall):
21
1
2012-01-08  ChangSeok Oh  <shivamidow@gmail.com>
22
2012-01-08  ChangSeok Oh  <shivamidow@gmail.com>
2
23
3
        Memory allocation mismatch by using adoptArrayPtr in GraphicsContext3DOpenGL.cpp
24
        Memory allocation mismatch by using adoptArrayPtr in GraphicsContext3DOpenGL.cpp
- a/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm -28 / +25 lines
Lines 2181-2188 sub GenerateImplementation a/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm_sec1
2181
                    push(@implContent, GenerateEventListenerCall($className, "remove"));
2181
                    push(@implContent, GenerateEventListenerCall($className, "remove"));
2182
                } else {
2182
                } else {
2183
                    my $numParameters = @{$function->parameters};
2183
                    my $numParameters = @{$function->parameters};
2184
                    my ($functionString, $paramIndex) = GenerateParametersCheck(\@implContent, $function, $dataNode, $numParameters, $implClassName, $functionImplementationName, $svgPropertyType, $svgPropertyOrListPropertyType, $svgListPropertyType);
2184
                    my ($functionString, $dummy) = GenerateParametersCheck(\@implContent, $function, $dataNode, $numParameters, $implClassName, $functionImplementationName, $svgPropertyType, $svgPropertyOrListPropertyType, $svgListPropertyType);
2185
                    GenerateImplementationFunctionCall($function, $functionString, $paramIndex, "    ", $svgPropertyType, $implClassName);
2185
                    GenerateImplementationFunctionCall($function, $functionString, "    ", $svgPropertyType, $implClassName);
2186
                }
2186
                }
2187
            }
2187
            }
2188
2188
Lines 2419-2425 sub GenerateParametersCheck a/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm_sec2
2419
    my $svgPropertyOrListPropertyType = shift;
2419
    my $svgPropertyOrListPropertyType = shift;
2420
    my $svgListPropertyType = shift;
2420
    my $svgListPropertyType = shift;
2421
2421
2422
    my $paramIndex = 0;
2423
    my $argsIndex = 0;
2422
    my $argsIndex = 0;
2424
    my $hasOptionalArguments = 0;
2423
    my $hasOptionalArguments = 0;
2425
2424
Lines 2431-2437 sub GenerateParametersCheck a/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm_sec3
2431
    } else {
2430
    } else {
2432
        $functionBase = "impl->";
2431
        $functionBase = "impl->";
2433
    }
2432
    }
2434
    my $functionString = "$functionBase$functionImplementationName(";
2433
    my $functionName = "$functionBase$functionImplementationName";
2434
    my @arguments;
2435
2435
2436
    if ($function->signature->extendedAttributes->{"CustomArgumentHandling"} and !$function->isStatic) {
2436
    if ($function->signature->extendedAttributes->{"CustomArgumentHandling"} and !$function->isStatic) {
2437
        push(@$outputArray, "    RefPtr<ScriptArguments> scriptArguments(createScriptArguments(exec, $numParameters));\n");
2437
        push(@$outputArray, "    RefPtr<ScriptArguments> scriptArguments(createScriptArguments(exec, $numParameters));\n");
Lines 2452-2460 sub GenerateParametersCheck a/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm_sec4
2452
            push(@$outputArray, "        return JSValue::encode(jsUndefined());\n");
2452
            push(@$outputArray, "        return JSValue::encode(jsUndefined());\n");
2453
            $callWithArg = "scriptContext"; 
2453
            $callWithArg = "scriptContext"; 
2454
        }
2454
        }
2455
        $functionString .= ", " if $paramIndex;
2455
        push @arguments, $callWithArg;
2456
        $functionString .= $callWithArg;
2457
        $paramIndex++;
2458
    }
2456
    }
2459
2457
2460
    $implIncludes{"ExceptionCode.h"} = 1;
2458
    $implIncludes{"ExceptionCode.h"} = 1;
Lines 2473-2479 sub GenerateParametersCheck a/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm_sec5
2473
                $hasOptionalArguments = 1;
2471
                $hasOptionalArguments = 1;
2474
            }
2472
            }
2475
            push(@$outputArray, "    if (argsCount <= $argsIndex) {\n");
2473
            push(@$outputArray, "    if (argsCount <= $argsIndex) {\n");
2476
            GenerateImplementationFunctionCall($function, $functionString, $paramIndex, "    " x 2, $svgPropertyType, $implClassName);
2474
2475
            my @optionalCallbackArguments = @arguments;
2476
            if ($function->signature->extendedAttributes->{"CustomArgumentHandling"}) {
2477
                push @optionalCallbackArguments, "scriptArguments, callStack";
2478
            }
2479
            if (@{$function->raisesExceptions}) {
2480
                push @optionalCallbackArguments, "ec";
2481
            }
2482
            my $functionString = "$functionName(" . join(", ", @optionalCallbackArguments) . ")";
2483
            GenerateImplementationFunctionCall($function, $functionString, "    " x 2, $svgPropertyType, $implClassName);
2477
            push(@$outputArray, "    }\n\n");
2484
            push(@$outputArray, "    }\n\n");
2478
        }
2485
        }
2479
2486
Lines 2554-2573 sub GenerateParametersCheck a/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm_sec6
2554
            }
2561
            }
2555
        }
2562
        }
2556
2563
2557
        $functionString .= ", " if $paramIndex;
2558
2559
        if ($argType eq "NodeFilter") {
2564
        if ($argType eq "NodeFilter") {
2560
            $functionString .= "$name.get()";
2565
            push @arguments, "$name.get()";
2561
        } elsif ($codeGenerator->IsSVGTypeNeedingTearOff($argType) and not $implClassName =~ /List$/) {
2566
        } elsif ($codeGenerator->IsSVGTypeNeedingTearOff($argType) and not $implClassName =~ /List$/) {
2562
            $functionString .= "$name->propertyReference()";
2567
            push @arguments, "$name->propertyReference()";
2563
        } else {
2568
        } else {
2564
            $functionString .= $name;
2569
            push @arguments, $name;
2565
        }
2570
        }
2566
        $argsIndex++;
2571
        $argsIndex++;
2567
        $paramIndex++;
2568
    }
2572
    }
2569
2573
2570
    return ($functionString, $paramIndex);
2574
    if ($function->signature->extendedAttributes->{"CustomArgumentHandling"}) {
2575
        push @arguments, "scriptArguments, callStack";
2576
    }
2577
    if (@{$function->raisesExceptions}) {
2578
        push @arguments, "ec";
2579
    }
2580
    return ("$functionName(" . join(", ", @arguments) . ")", scalar @arguments);
2571
}
2581
}
2572
2582
2573
sub GenerateCallbackHeader
2583
sub GenerateCallbackHeader
Lines 2732-2754 sub GenerateImplementationFunctionCall() a/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm_sec7
2732
{
2742
{
2733
    my $function = shift;
2743
    my $function = shift;
2734
    my $functionString = shift;
2744
    my $functionString = shift;
2735
    my $paramIndex = shift;
2736
    my $indent = shift;
2745
    my $indent = shift;
2737
    my $svgPropertyType = shift;
2746
    my $svgPropertyType = shift;
2738
    my $implClassName = shift;
2747
    my $implClassName = shift;
2739
2748
2740
    if ($function->signature->extendedAttributes->{"CustomArgumentHandling"}) {
2741
        $functionString .= ", " if $paramIndex;
2742
        $paramIndex += 2;
2743
        $functionString .= "scriptArguments, callStack";
2744
    }
2745
2746
    if (@{$function->raisesExceptions}) {
2747
        $functionString .= ", " if $paramIndex;
2748
        $functionString .= "ec";
2749
    }
2750
    $functionString .= ")";
2751
2752
    if ($function->signature->type eq "void") {
2749
    if ($function->signature->type eq "void") {
2753
        push(@implContent, $indent . "$functionString;\n");
2750
        push(@implContent, $indent . "$functionString;\n");
2754
        push(@implContent, $indent . "setDOMException(exec, ec);\n") if @{$function->raisesExceptions};
2751
        push(@implContent, $indent . "setDOMException(exec, ec);\n") if @{$function->raisesExceptions};

Return to Bug 75830