Title: [98617] trunk
Revision
98617
Author
podivi...@chromium.org
Date
2011-10-27 12:22:31 -0700 (Thu, 27 Oct 2011)

Log 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:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (98616 => 98617)


--- trunk/LayoutTests/ChangeLog	2011-10-27 19:16:15 UTC (rev 98616)
+++ trunk/LayoutTests/ChangeLog	2011-10-27 19:22:31 UTC (rev 98617)
@@ -1,3 +1,15 @@
+2011-10-27  Pavel Podivilov  <podivi...@chromium.org>
+
+        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.
+
+        * fast/canvas/canvas-putImageData-expected.txt: expectation was wrong, context.putImageData({}, 0, 0) should throw Type Error.
+        * fast/canvas/canvas-putImageData.js:
+
 2011-10-27  John Gregg  <john...@google.com>
 
         unreviewed, test expectations

Modified: trunk/LayoutTests/fast/canvas/canvas-putImageData-expected.txt (98616 => 98617)


--- trunk/LayoutTests/fast/canvas/canvas-putImageData-expected.txt	2011-10-27 19:16:15 UTC (rev 98616)
+++ trunk/LayoutTests/fast/canvas/canvas-putImageData-expected.txt	2011-10-27 19:22:31 UTC (rev 98617)
@@ -144,7 +144,7 @@
 PASS getPixel(9,9) is [0,128,0,255]
 PASS getPixel(1,1) is [0,128,0,255]
 PASS getPixel(9,9) is [0,128,0,255]
-PASS context.putImageData({}, 0, 0) threw exception Error: TYPE_MISMATCH_ERR: DOM Exception 17.
+PASS context.putImageData({}, 0, 0) threw exception TypeError: Type error.
 PASS context.putImageData(buffer, NaN, 0, 0, 0, 0, 0) threw exception Error: NOT_SUPPORTED_ERR: DOM Exception 9.
 PASS context.putImageData(buffer, 0, NaN, 0, 0, 0, 0) threw exception Error: NOT_SUPPORTED_ERR: DOM Exception 9.
 PASS context.putImageData(buffer, 0, 0, NaN, 0, 0, 0) threw exception Error: NOT_SUPPORTED_ERR: DOM Exception 9.

Modified: trunk/LayoutTests/fast/canvas/canvas-putImageData.js (98616 => 98617)


--- trunk/LayoutTests/fast/canvas/canvas-putImageData.js	2011-10-27 19:16:15 UTC (rev 98616)
+++ trunk/LayoutTests/fast/canvas/canvas-putImageData.js	2011-10-27 19:22:31 UTC (rev 98617)
@@ -201,7 +201,7 @@
 pixelShouldBe(9, 9, [0, 128,0,255]);
 
 
-shouldThrow("context.putImageData({}, 0, 0)", "'Error: TYPE_MISMATCH_ERR: DOM Exception 17'");
+shouldThrow("context.putImageData({}, 0, 0)", "'TypeError: Type error'");
 shouldThrow("context.putImageData(buffer, NaN, 0, 0, 0, 0, 0)", "'Error: NOT_SUPPORTED_ERR: DOM Exception 9'");
 shouldThrow("context.putImageData(buffer, 0, NaN, 0, 0, 0, 0)", "'Error: NOT_SUPPORTED_ERR: DOM Exception 9'");
 shouldThrow("context.putImageData(buffer, 0, 0, NaN, 0, 0, 0)", "'Error: NOT_SUPPORTED_ERR: DOM Exception 9'");

Modified: trunk/Source/WebCore/ChangeLog (98616 => 98617)


--- trunk/Source/WebCore/ChangeLog	2011-10-27 19:16:15 UTC (rev 98616)
+++ trunk/Source/WebCore/ChangeLog	2011-10-27 19:22:31 UTC (rev 98617)
@@ -1,3 +1,28 @@
+2011-10-27  Pavel Podivilov  <podivi...@chromium.org>
+
+        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.
+
+        * 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:
+
 2011-10-27  Antti Koivisto  <an...@apple.com>
 
         REGRESSION(r98542): tables/mozilla_expected_failures/bugs/bug14007-2.html

Modified: trunk/Source/WebCore/bindings/js/JSCanvasRenderingContext2DCustom.cpp (98616 => 98617)


--- trunk/Source/WebCore/bindings/js/JSCanvasRenderingContext2DCustom.cpp	2011-10-27 19:16:15 UTC (rev 98616)
+++ trunk/Source/WebCore/bindings/js/JSCanvasRenderingContext2DCustom.cpp	2011-10-27 19:22:31 UTC (rev 98617)
@@ -140,24 +140,6 @@
     return toJS(exec, globalObject(), WTF::getPtr(imageData));
 }
 
-JSValue JSCanvasRenderingContext2D::putImageData(ExecState* exec)
-{
-    // putImageData has two variants
-    // putImageData(ImageData, x, y)
-    // putImageData(ImageData, x, y, dirtyX, dirtyY, dirtyWidth, dirtyHeight)
-    CanvasRenderingContext2D* context = static_cast<CanvasRenderingContext2D*>(impl());
-
-    ExceptionCode ec = 0;
-    if (exec->argumentCount() >= 7)
-        context->putImageData(toImageData(exec->argument(0)), exec->argument(1).toFloat(exec), exec->argument(2).toFloat(exec), 
-                              exec->argument(3).toFloat(exec), exec->argument(4).toFloat(exec), exec->argument(5).toFloat(exec), exec->argument(6).toFloat(exec), ec);
-    else
-        context->putImageData(toImageData(exec->argument(0)), exec->argument(1).toFloat(exec), exec->argument(2).toFloat(exec), ec);
-
-    setDOMException(exec, ec);
-    return jsUndefined();
-}
-
 JSValue JSCanvasRenderingContext2D::webkitLineDash(ExecState* exec) const
 {
     CanvasRenderingContext2D* context = static_cast<CanvasRenderingContext2D*>(impl());

Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm (98616 => 98617)


--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm	2011-10-27 19:16:15 UTC (rev 98616)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm	2011-10-27 19:22:31 UTC (rev 98617)
@@ -909,10 +909,10 @@
     if ($numCustomFunctions > 0) {
         push(@headerContent, "\n    // Custom functions\n");
         foreach my $function (@{$dataNode->functions}) {
-            if ($function->signature->extendedAttributes->{"Custom"} || $function->signature->extendedAttributes->{"JSCCustom"}) {
-                my $functionImplementationName = $function->signature->extendedAttributes->{"ImplementationFunction"} || $codeGenerator->WK_lcfirst($function->signature->name);
-                push(@headerContent, "    JSC::JSValue " . $functionImplementationName . "(JSC::ExecState*);\n");
-            }
+            next unless $function->signature->extendedAttributes->{"Custom"} or $function->signature->extendedAttributes->{"JSCCustom"};
+            next if $function->{overloads} && $function->{overloadIndex} != 1;
+            my $functionImplementationName = $function->signature->extendedAttributes->{"ImplementationFunction"} || $codeGenerator->WK_lcfirst($function->signature->name);
+            push(@headerContent, "    JSC::JSValue " . $functionImplementationName . "(JSC::ExecState*);\n");
         }
     }
 
@@ -1948,8 +1948,12 @@
             AddIncludesForTypeInImpl($function->signature->type);
 
             my $functionName = $codeGenerator->WK_lcfirst($className) . "PrototypeFunction" . $codeGenerator->WK_ucfirst($function->signature->name);
+            my $isCustom = $function->signature->extendedAttributes->{"Custom"} || $function->signature->extendedAttributes->{"JSCCustom"};
+            my $isOverloaded = $function->{overloads} && @{$function->{overloads}} > 1;
 
-            if ($function->{overloads} && @{$function->{overloads}} > 1) {
+            next if $isCustom && $isOverloaded && $function->{overloadIndex} > 1;
+
+            if (!$isCustom && $isOverloaded) {
                 # Append a number to an overloaded method's name to make it unique:
                 $functionName = $functionName . $function->{overloadIndex};
                 # Make this function static to avoid compiler warnings, since we
@@ -1992,7 +1996,7 @@
                 push(@implContent, "        return JSValue::encode(jsUndefined());\n");
             }
 
-            if ($function->signature->extendedAttributes->{"Custom"} || $function->signature->extendedAttributes->{"JSCCustom"}) {
+            if ($isCustom) {
                 push(@implContent, "    return JSValue::encode(castedThis->" . $functionImplementationName . "(exec));\n");
             } else {
                 push(@implContent, "    $implType* imp = static_cast<$implType*>(castedThis->impl());\n");
@@ -2029,7 +2033,7 @@
 
             push(@implContent, "}\n\n");
 
-            if ($function->{overloads} && @{$function->{overloads}} > 1 && $function->{overloadIndex} == @{$function->{overloads}}) {
+            if (!$isCustom && $isOverloaded && $function->{overloadIndex} == @{$function->{overloads}}) {
                 # Generate a function dispatching call to the rest of the overloads.
                 GenerateOverloadedPrototypeFunction($function, $dataNode, $implClassName);
             }

Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm (98616 => 98617)


--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm	2011-10-27 19:16:15 UTC (rev 98616)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm	2011-10-27 19:22:31 UTC (rev 98617)
@@ -264,6 +264,7 @@
     # Copy contents of parent classes except the first parent or if it is
     # EventTarget.
     $codeGenerator->AddMethodsConstantsAndAttributesFromParentClasses($dataNode, \@allParents, 1);
+    $codeGenerator->LinkOverloadedFunctions($dataNode);
 
     my $hasDependentLifetime = $dataNode->extendedAttributes->{"V8DependentLifetime"} || $dataNode->extendedAttributes->{"ActiveDOMObject"} || $className =~ /SVG/;
     if (!$hasDependentLifetime) {
@@ -371,7 +372,7 @@
         my $name = $function->signature->name;
         my $attrExt = $function->signature->extendedAttributes;
 
-        if ($attrExt->{"Custom"} || $attrExt->{"V8Custom"}) {
+        if (($attrExt->{"Custom"} || $attrExt->{"V8Custom"}) && $function->{overloadIndex} == 1) {
             push(@headerContent, <<END);
     static v8::Handle<v8::Value> ${name}Callback(const v8::Arguments&);
 END
@@ -1384,6 +1385,17 @@
     my $function = shift;
     my $dataNode = shift;
 
+    my $numMandatoryParams = 0;
+    my $optionalSeen = 0;
+    foreach my $param (@{$function->parameters}) {
+        if ($param->extendedAttributes->{"Optional"}) {
+            $optionalSeen = 1;
+        } else {
+            die "An argument must not be declared to be optional unless all subsequent arguments to the operation are also optional." if $optionalSeen;
+            $numMandatoryParams++;
+        }
+    }
+
     my $argumentsCountCheckString = "";
     my $requiresAllArguments;
     my $requiresAllArgumentsDefault = "";
@@ -1391,23 +1403,13 @@
         $requiresAllArgumentsDefault = "Raise";
     }
     $requiresAllArguments = $function->signature->extendedAttributes->{"RequiresAllArguments"} || $requiresAllArgumentsDefault;
-    if ($requiresAllArguments) {
-        my $numMandatoryParams = @{$function->parameters};
-        foreach my $param (reverse(@{$function->parameters})) {
-            if ($param->extendedAttributes->{"Optional"}) {
-                $numMandatoryParams--;
-            } else {
-                last;
-            }
+    if ($requiresAllArguments && $numMandatoryParams >= 1) {
+        $argumentsCountCheckString .= "    if (args.Length() < $numMandatoryParams)\n";
+        if ($requiresAllArguments eq "Raise") {
+            $argumentsCountCheckString .= "        return throwError(\"Not enough arguments\", V8Proxy::TypeError);\n";
+        } else {
+            $argumentsCountCheckString .= "        return v8::Handle<v8::Value>();\n";
         }
-        if ($numMandatoryParams >= 1) {
-            $argumentsCountCheckString .= "    if (args.Length() < $numMandatoryParams)\n";
-            if ($requiresAllArguments eq "Raise") {
-                $argumentsCountCheckString .= "        return throwError(\"Not enough arguments\", V8Proxy::TypeError);\n";
-            } else {
-                $argumentsCountCheckString .= "        return v8::Handle<v8::Value>();\n";
-            }
-        }
     }
     return $argumentsCountCheckString;
 }
@@ -2005,13 +2007,12 @@
         GenerateConstructorGetter($implClassName);
     }
 
-    $codeGenerator->LinkOverloadedFunctions($dataNode);
-
     my $indexer;
     my $namedPropertyGetter;
     # Generate methods for functions.
     foreach my $function (@{$dataNode->functions}) {
-        if (!($function->signature->extendedAttributes->{"Custom"} || $function->signature->extendedAttributes->{"V8Custom"})) {
+        my $isCustom = $function->signature->extendedAttributes->{"Custom"} || $function->signature->extendedAttributes->{"V8Custom"};
+        if (!$isCustom) {
             GenerateFunctionCallback($function, $dataNode, $implClassName);
             if ($function->{overloadIndex} > 1 && $function->{overloadIndex} == @{$function->{overloads}}) {
                 GenerateOverloadedFunctionCallback($function, $dataNode, $implClassName);
@@ -2030,7 +2031,9 @@
         # generate an access getter that returns different function objects
         # for different calling context.
         if (($dataNode->extendedAttributes->{"CheckDomainSecurity"} || ($interfaceName eq "DOMWindow")) && $function->signature->extendedAttributes->{"DoNotCheckDomainSecurity"}) {
-            GenerateDomainSafeFunctionGetter($function, $implClassName);
+            if (!$isCustom || $function->{overloadIndex} == 1) {
+                GenerateDomainSafeFunctionGetter($function, $implClassName);
+            }
         }
     }
 

Modified: trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp (98616 => 98617)


--- trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp	2011-10-27 19:16:15 UTC (rev 98616)
+++ trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp	2011-10-27 19:22:31 UTC (rev 98617)
@@ -1556,6 +1556,11 @@
     int opt1(exec->argument(1).toInt32(exec));
     if (exec->hadException())
         return JSValue::encode(jsUndefined());
+    if (argsCount <= 2) {
+        imp->methodWithNonOptionalArgAndTwoOptionalArgs(nonOpt, opt1);
+        return JSValue::encode(jsUndefined());
+    }
+
     int opt2(exec->argument(2).toInt32(exec));
     if (exec->hadException())
         return JSValue::encode(jsUndefined());

Modified: trunk/Source/WebCore/bindings/scripts/test/TestObj.idl (98616 => 98617)


--- trunk/Source/WebCore/bindings/scripts/test/TestObj.idl	2011-10-27 19:16:15 UTC (rev 98616)
+++ trunk/Source/WebCore/bindings/scripts/test/TestObj.idl	2011-10-27 19:22:31 UTC (rev 98617)
@@ -119,7 +119,7 @@
         // 'Optional' extended attribute
         void    methodWithOptionalArg(in [Optional] long opt);
         void    methodWithNonOptionalArgAndOptionalArg(in long nonOpt, in [Optional] long opt);
-        void    methodWithNonOptionalArgAndTwoOptionalArgs(in long nonOpt, in [Optional] long opt1, in long opt2);
+        void    methodWithNonOptionalArgAndTwoOptionalArgs(in long nonOpt, in [Optional] long opt1, in [Optional] long opt2);
 
 #if defined(TESTING_V8) || defined(TESTING_JS)
         // 'Callback' extended attribute

Modified: trunk/Source/WebCore/bindings/scripts/test/V8/V8TestObj.cpp (98616 => 98617)


--- trunk/Source/WebCore/bindings/scripts/test/V8/V8TestObj.cpp	2011-10-27 19:16:15 UTC (rev 98616)
+++ trunk/Source/WebCore/bindings/scripts/test/V8/V8TestObj.cpp	2011-10-27 19:22:31 UTC (rev 98617)
@@ -1042,6 +1042,10 @@
         return v8::Handle<v8::Value>();
     }
     EXCEPTION_BLOCK(int, opt1, toInt32(MAYBE_MISSING_PARAMETER(args, 1, MissingIsUndefined)));
+    if (args.Length() <= 2) {
+        imp->methodWithNonOptionalArgAndTwoOptionalArgs(nonOpt, opt1);
+        return v8::Handle<v8::Value>();
+    }
     EXCEPTION_BLOCK(int, opt2, toInt32(MAYBE_MISSING_PARAMETER(args, 2, MissingIsUndefined)));
     imp->methodWithNonOptionalArgAndTwoOptionalArgs(nonOpt, opt1, opt2);
     return v8::Handle<v8::Value>();

Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.idl (98616 => 98617)


--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.idl	2011-10-27 19:16:15 UTC (rev 98616)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.idl	2011-10-27 19:22:31 UTC (rev 98617)
@@ -152,13 +152,16 @@
         void setShadow(in float width, in float height, in float blur, in float r, in float g, in float b, in float a);
         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);
 
+        void putImageData(in ImageData imagedata, in float dx, in float dy)
+            raises(DOMException);
+        void putImageData(in ImageData imagedata, in float dx, in float dy, in float dirtyX, in float dirtyY, in float dirtyWidth, in float dirtyHeight)
+            raises(DOMException);
+
 #if defined(V8_BINDING) && V8_BINDING
         CanvasPattern createPattern(in HTMLCanvasElement canvas, in [ConvertNullToNullString] DOMString repetitionType)
             raises (DOMException);
         CanvasPattern createPattern(in HTMLImageElement image, in [ConvertNullToNullString] DOMString repetitionType)
             raises (DOMException);
-        void putImageData(in ImageData imagedata, in float dx, in float dy, in [Optional] float dirtyX, in float dirtyY, in float dirtyWidth, in float dirtyHeight)
-            raises(DOMException);
         ImageData createImageData(in ImageData imagedata)
             raises (DOMException);
         ImageData createImageData(in float sw, in float sh)
@@ -166,7 +169,6 @@
 #else
         // FIXME: Remove 'else' once JSC supports overloads too.
         [Custom] void createPattern(/* 2 */);
-        [Custom] void putImageData(/* in ImageData imagedata, in float dx, in float dy [, in float dirtyX, in float dirtyY, in float dirtyWidth, in float dirtyHeight] */);
         [Custom] ImageData createImageData(/* 3 */);
 #endif // defined(V8_BINDING)
 

Modified: trunk/Source/WebCore/page/DOMWindow.idl (98616 => 98617)


--- trunk/Source/WebCore/page/DOMWindow.idl	2011-10-27 19:16:15 UTC (rev 98616)
+++ trunk/Source/WebCore/page/DOMWindow.idl	2011-10-27 19:22:31 UTC (rev 98617)
@@ -212,10 +212,15 @@
 
         // cross-document messaging
 #if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT
-        [DoNotCheckDomainSecurity, Custom] void postMessage(in SerializedScriptValue message, in [Optional] Array messagePorts, in DOMString targetOrigin)
+        [DoNotCheckDomainSecurity, Custom] void postMessage(in SerializedScriptValue message, in DOMString targetOrigin)
             raises(DOMException);
-        [DoNotCheckDomainSecurity, Custom] void webkitPostMessage(in SerializedScriptValue message, in [Optional] Array transferList, in DOMString targetOrigin)
+        [DoNotCheckDomainSecurity, Custom] void postMessage(in SerializedScriptValue message, in Array messagePorts, in DOMString targetOrigin)
             raises(DOMException);
+
+        [DoNotCheckDomainSecurity, Custom] void webkitPostMessage(in SerializedScriptValue message, in DOMString targetOrigin)
+            raises(DOMException);
+        [DoNotCheckDomainSecurity, Custom] void webkitPostMessage(in SerializedScriptValue message, in Array transferList, in DOMString targetOrigin)
+            raises(DOMException);
 #else
         // There's no good way to expose an array via the ObjC bindings, so for now just allow passing in a single port.
         [DoNotCheckDomainSecurity, Custom] void postMessage(in SerializedScriptValue message, in [Optional] MessagePort messagePort, in DOMString targetOrigin)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to