⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 98617 in webkit


Ignore:
Timestamp:
Oct 27, 2011, 12:22:31 PM (15 years ago)
Author:
podivilov@chromium.org
Message:

Get rid of optional parameters in the middle in IDLs.
https://bugs.webkit.org/show_bug.cgi?id=70816

Reviewed by Adam Barth.

Optional parameters in the middle are prohibited by WebIDL spec.

Source/WebCore:

  • bindings/js/JSCanvasRenderingContext2DCustom.cpp:
  • bindings/scripts/CodeGeneratorJS.pm:

(GenerateHeader):
(GenerateImplementation):

  • bindings/scripts/CodeGeneratorV8.pm:

(GenerateHeader):
(GenerateArgumentsCountCheck):
(GenerateImplementation):

  • bindings/scripts/test/JS/JSTestObj.cpp:

(WebCore::jsTestObjPrototypeFunctionMethodWithNonOptionalArgAndTwoOptionalArgs):

  • bindings/scripts/test/TestObj.idl:
  • bindings/scripts/test/V8/V8TestObj.cpp:

(WebCore::TestObjInternal::methodWithNonOptionalArgAndTwoOptionalArgsCallback):

  • html/canvas/CanvasRenderingContext2D.idl:
  • page/DOMWindow.idl:

LayoutTests:

  • fast/canvas/canvas-putImageData-expected.txt: expectation was wrong, context.putImageData({}, 0, 0) should throw Type Error.
  • fast/canvas/canvas-putImageData.js:
Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r98616 r98617  
     12011-10-27  Pavel Podivilov  <podivilov@chromium.org>
     2
     3        Get rid of optional parameters in the middle in IDLs.
     4        https://bugs.webkit.org/show_bug.cgi?id=70816
     5
     6        Reviewed by Adam Barth.
     7
     8        Optional parameters in the middle are prohibited by WebIDL spec.
     9
     10        * fast/canvas/canvas-putImageData-expected.txt: expectation was wrong, context.putImageData({}, 0, 0) should throw Type Error.
     11        * fast/canvas/canvas-putImageData.js:
     12
    1132011-10-27  John Gregg  <johnnyg@google.com>
    214
  • trunk/LayoutTests/fast/canvas/canvas-putImageData-expected.txt

    r98434 r98617  
    145145PASS getPixel(1,1) is [0,128,0,255]
    146146PASS getPixel(9,9) is [0,128,0,255]
    147 PASS context.putImageData({}, 0, 0) threw exception Error: TYPE_MISMATCH_ERR: DOM Exception 17.
     147PASS context.putImageData({}, 0, 0) threw exception TypeError: Type error.
    148148PASS context.putImageData(buffer, NaN, 0, 0, 0, 0, 0) threw exception Error: NOT_SUPPORTED_ERR: DOM Exception 9.
    149149PASS context.putImageData(buffer, 0, NaN, 0, 0, 0, 0) threw exception Error: NOT_SUPPORTED_ERR: DOM Exception 9.
  • trunk/LayoutTests/fast/canvas/canvas-putImageData.js

    r98434 r98617  
    202202
    203203
    204 shouldThrow("context.putImageData({}, 0, 0)", "'Error: TYPE_MISMATCH_ERR: DOM Exception 17'");
     204shouldThrow("context.putImageData({}, 0, 0)", "'TypeError: Type error'");
    205205shouldThrow("context.putImageData(buffer, NaN, 0, 0, 0, 0, 0)", "'Error: NOT_SUPPORTED_ERR: DOM Exception 9'");
    206206shouldThrow("context.putImageData(buffer, 0, NaN, 0, 0, 0, 0)", "'Error: NOT_SUPPORTED_ERR: DOM Exception 9'");
  • trunk/Source/WebCore/ChangeLog

    r98615 r98617  
     12011-10-27  Pavel Podivilov  <podivilov@chromium.org>
     2
     3        Get rid of optional parameters in the middle in IDLs.
     4        https://bugs.webkit.org/show_bug.cgi?id=70816
     5
     6        Reviewed by Adam Barth.
     7
     8        Optional parameters in the middle are prohibited by WebIDL spec.
     9
     10        * bindings/js/JSCanvasRenderingContext2DCustom.cpp:
     11        * bindings/scripts/CodeGeneratorJS.pm:
     12        (GenerateHeader):
     13        (GenerateImplementation):
     14        * bindings/scripts/CodeGeneratorV8.pm:
     15        (GenerateHeader):
     16        (GenerateArgumentsCountCheck):
     17        (GenerateImplementation):
     18        * bindings/scripts/test/JS/JSTestObj.cpp:
     19        (WebCore::jsTestObjPrototypeFunctionMethodWithNonOptionalArgAndTwoOptionalArgs):
     20        * bindings/scripts/test/TestObj.idl:
     21        * bindings/scripts/test/V8/V8TestObj.cpp:
     22        (WebCore::TestObjInternal::methodWithNonOptionalArgAndTwoOptionalArgsCallback):
     23        * html/canvas/CanvasRenderingContext2D.idl:
     24        * page/DOMWindow.idl:
     25
    1262011-10-27  Antti Koivisto  <antti@apple.com>
    227
  • trunk/Source/WebCore/bindings/js/JSCanvasRenderingContext2DCustom.cpp

    r96626 r98617  
    141141}
    142142
    143 JSValue JSCanvasRenderingContext2D::putImageData(ExecState* exec)
    144 {
    145     // putImageData has two variants
    146     // putImageData(ImageData, x, y)
    147     // putImageData(ImageData, x, y, dirtyX, dirtyY, dirtyWidth, dirtyHeight)
    148     CanvasRenderingContext2D* context = static_cast<CanvasRenderingContext2D*>(impl());
    149 
    150     ExceptionCode ec = 0;
    151     if (exec->argumentCount() >= 7)
    152         context->putImageData(toImageData(exec->argument(0)), exec->argument(1).toFloat(exec), exec->argument(2).toFloat(exec),
    153                               exec->argument(3).toFloat(exec), exec->argument(4).toFloat(exec), exec->argument(5).toFloat(exec), exec->argument(6).toFloat(exec), ec);
    154     else
    155         context->putImageData(toImageData(exec->argument(0)), exec->argument(1).toFloat(exec), exec->argument(2).toFloat(exec), ec);
    156 
    157     setDOMException(exec, ec);
    158     return jsUndefined();
    159 }
    160 
    161143JSValue JSCanvasRenderingContext2D::webkitLineDash(ExecState* exec) const
    162144{
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm

    r98563 r98617  
    910910        push(@headerContent, "\n    // Custom functions\n");
    911911        foreach my $function (@{$dataNode->functions}) {
    912             if ($function->signature->extendedAttributes->{"Custom"} || $function->signature->extendedAttributes->{"JSCCustom"}) {
    913                 my $functionImplementationName = $function->signature->extendedAttributes->{"ImplementationFunction"} || $codeGenerator->WK_lcfirst($function->signature->name);
    914                 push(@headerContent, "    JSC::JSValue " . $functionImplementationName . "(JSC::ExecState*);\n");
    915             }
     912            next unless $function->signature->extendedAttributes->{"Custom"} or $function->signature->extendedAttributes->{"JSCCustom"};
     913            next if $function->{overloads} && $function->{overloadIndex} != 1;
     914            my $functionImplementationName = $function->signature->extendedAttributes->{"ImplementationFunction"} || $codeGenerator->WK_lcfirst($function->signature->name);
     915            push(@headerContent, "    JSC::JSValue " . $functionImplementationName . "(JSC::ExecState*);\n");
    916916        }
    917917    }
     
    19491949
    19501950            my $functionName = $codeGenerator->WK_lcfirst($className) . "PrototypeFunction" . $codeGenerator->WK_ucfirst($function->signature->name);
    1951 
    1952             if ($function->{overloads} && @{$function->{overloads}} > 1) {
     1951            my $isCustom = $function->signature->extendedAttributes->{"Custom"} || $function->signature->extendedAttributes->{"JSCCustom"};
     1952            my $isOverloaded = $function->{overloads} && @{$function->{overloads}} > 1;
     1953
     1954            next if $isCustom && $isOverloaded && $function->{overloadIndex} > 1;
     1955
     1956            if (!$isCustom && $isOverloaded) {
    19531957                # Append a number to an overloaded method's name to make it unique:
    19541958                $functionName = $functionName . $function->{overloadIndex};
     
    19931997            }
    19941998
    1995             if ($function->signature->extendedAttributes->{"Custom"} || $function->signature->extendedAttributes->{"JSCCustom"}) {
     1999            if ($isCustom) {
    19962000                push(@implContent, "    return JSValue::encode(castedThis->" . $functionImplementationName . "(exec));\n");
    19972001            } else {
     
    20302034            push(@implContent, "}\n\n");
    20312035
    2032             if ($function->{overloads} && @{$function->{overloads}} > 1 && $function->{overloadIndex} == @{$function->{overloads}}) {
     2036            if (!$isCustom && $isOverloaded && $function->{overloadIndex} == @{$function->{overloads}}) {
    20332037                # Generate a function dispatching call to the rest of the overloads.
    20342038                GenerateOverloadedPrototypeFunction($function, $dataNode, $implClassName);
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm

    r98563 r98617  
    265265    # EventTarget.
    266266    $codeGenerator->AddMethodsConstantsAndAttributesFromParentClasses($dataNode, \@allParents, 1);
     267    $codeGenerator->LinkOverloadedFunctions($dataNode);
    267268
    268269    my $hasDependentLifetime = $dataNode->extendedAttributes->{"V8DependentLifetime"} || $dataNode->extendedAttributes->{"ActiveDOMObject"} || $className =~ /SVG/;
     
    372373        my $attrExt = $function->signature->extendedAttributes;
    373374
    374         if ($attrExt->{"Custom"} || $attrExt->{"V8Custom"}) {
     375        if (($attrExt->{"Custom"} || $attrExt->{"V8Custom"}) && $function->{overloadIndex} == 1) {
    375376            push(@headerContent, <<END);
    376377    static v8::Handle<v8::Value> ${name}Callback(const v8::Arguments&);
     
    13851386    my $dataNode = shift;
    13861387
     1388    my $numMandatoryParams = 0;
     1389    my $optionalSeen = 0;
     1390    foreach my $param (@{$function->parameters}) {
     1391        if ($param->extendedAttributes->{"Optional"}) {
     1392            $optionalSeen = 1;
     1393        } else {
     1394            die "An argument must not be declared to be optional unless all subsequent arguments to the operation are also optional." if $optionalSeen;
     1395            $numMandatoryParams++;
     1396        }
     1397    }
     1398
    13871399    my $argumentsCountCheckString = "";
    13881400    my $requiresAllArguments;
     
    13921404    }
    13931405    $requiresAllArguments = $function->signature->extendedAttributes->{"RequiresAllArguments"} || $requiresAllArgumentsDefault;
    1394     if ($requiresAllArguments) {
    1395         my $numMandatoryParams = @{$function->parameters};
    1396         foreach my $param (reverse(@{$function->parameters})) {
    1397             if ($param->extendedAttributes->{"Optional"}) {
    1398                 $numMandatoryParams--;
    1399             } else {
    1400                 last;
    1401             }
    1402         }
    1403         if ($numMandatoryParams >= 1) {
    1404             $argumentsCountCheckString .= "    if (args.Length() < $numMandatoryParams)\n";
    1405             if ($requiresAllArguments eq "Raise") {
    1406                 $argumentsCountCheckString .= "        return throwError(\"Not enough arguments\", V8Proxy::TypeError);\n";
    1407             } else {
    1408                 $argumentsCountCheckString .= "        return v8::Handle<v8::Value>();\n";
    1409             }
     1406    if ($requiresAllArguments && $numMandatoryParams >= 1) {
     1407        $argumentsCountCheckString .= "    if (args.Length() < $numMandatoryParams)\n";
     1408        if ($requiresAllArguments eq "Raise") {
     1409            $argumentsCountCheckString .= "        return throwError(\"Not enough arguments\", V8Proxy::TypeError);\n";
     1410        } else {
     1411            $argumentsCountCheckString .= "        return v8::Handle<v8::Value>();\n";
    14101412        }
    14111413    }
     
    20062008    }
    20072009
    2008     $codeGenerator->LinkOverloadedFunctions($dataNode);
    2009 
    20102010    my $indexer;
    20112011    my $namedPropertyGetter;
    20122012    # Generate methods for functions.
    20132013    foreach my $function (@{$dataNode->functions}) {
    2014         if (!($function->signature->extendedAttributes->{"Custom"} || $function->signature->extendedAttributes->{"V8Custom"})) {
     2014        my $isCustom = $function->signature->extendedAttributes->{"Custom"} || $function->signature->extendedAttributes->{"V8Custom"};
     2015        if (!$isCustom) {
    20152016            GenerateFunctionCallback($function, $dataNode, $implClassName);
    20162017            if ($function->{overloadIndex} > 1 && $function->{overloadIndex} == @{$function->{overloads}}) {
     
    20312032        # for different calling context.
    20322033        if (($dataNode->extendedAttributes->{"CheckDomainSecurity"} || ($interfaceName eq "DOMWindow")) && $function->signature->extendedAttributes->{"DoNotCheckDomainSecurity"}) {
    2033             GenerateDomainSafeFunctionGetter($function, $implClassName);
     2034            if (!$isCustom || $function->{overloadIndex} == 1) {
     2035                GenerateDomainSafeFunctionGetter($function, $implClassName);
     2036            }
    20342037        }
    20352038    }
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp

    r98563 r98617  
    15571557    if (exec->hadException())
    15581558        return JSValue::encode(jsUndefined());
     1559    if (argsCount <= 2) {
     1560        imp->methodWithNonOptionalArgAndTwoOptionalArgs(nonOpt, opt1);
     1561        return JSValue::encode(jsUndefined());
     1562    }
     1563
    15591564    int opt2(exec->argument(2).toInt32(exec));
    15601565    if (exec->hadException())
  • trunk/Source/WebCore/bindings/scripts/test/TestObj.idl

    r98563 r98617  
    120120        void    methodWithOptionalArg(in [Optional] long opt);
    121121        void    methodWithNonOptionalArgAndOptionalArg(in long nonOpt, in [Optional] long opt);
    122         void    methodWithNonOptionalArgAndTwoOptionalArgs(in long nonOpt, in [Optional] long opt1, in long opt2);
     122        void    methodWithNonOptionalArgAndTwoOptionalArgs(in long nonOpt, in [Optional] long opt1, in [Optional] long opt2);
    123123
    124124#if defined(TESTING_V8) || defined(TESTING_JS)
  • trunk/Source/WebCore/bindings/scripts/test/V8/V8TestObj.cpp

    r98563 r98617  
    10431043    }
    10441044    EXCEPTION_BLOCK(int, opt1, toInt32(MAYBE_MISSING_PARAMETER(args, 1, MissingIsUndefined)));
     1045    if (args.Length() <= 2) {
     1046        imp->methodWithNonOptionalArgAndTwoOptionalArgs(nonOpt, opt1);
     1047        return v8::Handle<v8::Value>();
     1048    }
    10451049    EXCEPTION_BLOCK(int, opt2, toInt32(MAYBE_MISSING_PARAMETER(args, 2, MissingIsUndefined)));
    10461050    imp->methodWithNonOptionalArgAndTwoOptionalArgs(nonOpt, opt1, opt2);
  • trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.idl

    r98434 r98617  
    153153        void setShadow(in float width, in float height, in float blur, in float c, in float m, in float y, in float k, in float a);
    154154
     155        void putImageData(in ImageData imagedata, in float dx, in float dy)
     156            raises(DOMException);
     157        void putImageData(in ImageData imagedata, in float dx, in float dy, in float dirtyX, in float dirtyY, in float dirtyWidth, in float dirtyHeight)
     158            raises(DOMException);
     159
    155160#if defined(V8_BINDING) && V8_BINDING
    156161        CanvasPattern createPattern(in HTMLCanvasElement canvas, in [ConvertNullToNullString] DOMString repetitionType)
     
    158163        CanvasPattern createPattern(in HTMLImageElement image, in [ConvertNullToNullString] DOMString repetitionType)
    159164            raises (DOMException);
    160         void putImageData(in ImageData imagedata, in float dx, in float dy, in [Optional] float dirtyX, in float dirtyY, in float dirtyWidth, in float dirtyHeight)
    161             raises(DOMException);
    162165        ImageData createImageData(in ImageData imagedata)
    163166            raises (DOMException);
     
    167170        // FIXME: Remove 'else' once JSC supports overloads too.
    168171        [Custom] void createPattern(/* 2 */);
    169         [Custom] void putImageData(/* in ImageData imagedata, in float dx, in float dy [, in float dirtyX, in float dirtyY, in float dirtyWidth, in float dirtyHeight] */);
    170172        [Custom] ImageData createImageData(/* 3 */);
    171173#endif // defined(V8_BINDING)
  • trunk/Source/WebCore/page/DOMWindow.idl

    r98507 r98617  
    213213        // cross-document messaging
    214214#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT
    215         [DoNotCheckDomainSecurity, Custom] void postMessage(in SerializedScriptValue message, in [Optional] Array messagePorts, in DOMString targetOrigin)
     215        [DoNotCheckDomainSecurity, Custom] void postMessage(in SerializedScriptValue message, in DOMString targetOrigin)
    216216            raises(DOMException);
    217         [DoNotCheckDomainSecurity, Custom] void webkitPostMessage(in SerializedScriptValue message, in [Optional] Array transferList, in DOMString targetOrigin)
     217        [DoNotCheckDomainSecurity, Custom] void postMessage(in SerializedScriptValue message, in Array messagePorts, in DOMString targetOrigin)
     218            raises(DOMException);
     219
     220        [DoNotCheckDomainSecurity, Custom] void webkitPostMessage(in SerializedScriptValue message, in DOMString targetOrigin)
     221            raises(DOMException);
     222        [DoNotCheckDomainSecurity, Custom] void webkitPostMessage(in SerializedScriptValue message, in Array transferList, in DOMString targetOrigin)
    218223            raises(DOMException);
    219224#else
Note: See TracChangeset for help on using the changeset viewer.