[WebKitIDL] Optional dictionary types should have default values of empty dictionary
authorjsbell@chromium.org <jsbell@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 26 Oct 2012 21:55:18 +0000 (21:55 +0000)
committerjsbell@chromium.org <jsbell@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 26 Oct 2012 21:55:18 +0000 (21:55 +0000)
https://bugs.webkit.org/show_bug.cgi?id=100547

Reviewed by Adam Barth.

Per WebIDL, "Optional dictionary type arguments are always considered to have a default
value of an empty dictionary." WebKitIDL already supported this via the extended attribute
[Optional=DefaultIsUndefined] but make this the default for Dictionary.

Binding test expectations updated.

* Modules/filesystem/DirectoryEntry.h: Remove default parameters.
(DirectoryEntry):
* Modules/indexeddb/IDBDatabase.h: Remove overloads.
(IDBDatabase):
* Modules/indexeddb/IDBObjectStore.h: Remove overloads.
(IDBObjectStore):
* Modules/mediastream/RTCPeerConnection.idl: Remove DefaultIsUndefined annotations.
* bindings/scripts/CodeGeneratorJS.pm: Special case for Optional Dictionary.
(GenerateParametersCheck):
* bindings/scripts/CodeGeneratorV8.pm: Ditto.
(GenerateParametersCheck):
* bindings/scripts/test/JS/JSTestObj.cpp:
(WebCore::jsTestObjPrototypeFunctionOptionsObject): Updated expectation - no early call.
* bindings/scripts/test/V8/V8TestObj.cpp:
(WebCore::TestObjV8Internal::optionsObjectCallback): Ditto.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@132698 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/Modules/filesystem/DirectoryEntry.h
Source/WebCore/Modules/indexeddb/IDBDatabase.h
Source/WebCore/Modules/indexeddb/IDBObjectStore.h
Source/WebCore/Modules/mediastream/RTCPeerConnection.idl
Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
Source/WebCore/bindings/scripts/CodeGeneratorV8.pm
Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp
Source/WebCore/bindings/scripts/test/V8/V8TestObj.cpp

index 4ee0b32..58a3e8d 100644 (file)
@@ -1,3 +1,32 @@
+2012-10-26  Joshua Bell  <jsbell@chromium.org>
+
+        [WebKitIDL] Optional dictionary types should have default values of empty dictionary
+        https://bugs.webkit.org/show_bug.cgi?id=100547
+
+        Reviewed by Adam Barth.
+
+        Per WebIDL, "Optional dictionary type arguments are always considered to have a default
+        value of an empty dictionary." WebKitIDL already supported this via the extended attribute
+        [Optional=DefaultIsUndefined] but make this the default for Dictionary.
+
+        Binding test expectations updated.
+
+        * Modules/filesystem/DirectoryEntry.h: Remove default parameters.
+        (DirectoryEntry):
+        * Modules/indexeddb/IDBDatabase.h: Remove overloads.
+        (IDBDatabase):
+        * Modules/indexeddb/IDBObjectStore.h: Remove overloads.
+        (IDBObjectStore):
+        * Modules/mediastream/RTCPeerConnection.idl: Remove DefaultIsUndefined annotations.
+        * bindings/scripts/CodeGeneratorJS.pm: Special case for Optional Dictionary.
+        (GenerateParametersCheck):
+        * bindings/scripts/CodeGeneratorV8.pm: Ditto.
+        (GenerateParametersCheck):
+        * bindings/scripts/test/JS/JSTestObj.cpp:
+        (WebCore::jsTestObjPrototypeFunctionOptionsObject): Updated expectation - no early call.
+        * bindings/scripts/test/V8/V8TestObj.cpp:
+        (WebCore::TestObjV8Internal::optionsObjectCallback): Ditto.
+
 2012-10-26  Vincent Scheib  <scheib@chromium.org>
 
         Generated should not be supported for things with a shadow
index 58c9e7f..5055c63 100644 (file)
@@ -56,8 +56,8 @@ public:
     virtual bool isDirectory() const { return true; }
 
     PassRefPtr<DirectoryReader> createReader();
-    void getFile(const String& path, const Dictionary& = Dictionary(), PassRefPtr<EntryCallback> = 0, PassRefPtr<ErrorCallback> = 0);
-    void getDirectory(const String& path, const Dictionary& = Dictionary(), PassRefPtr<EntryCallback> = 0, PassRefPtr<ErrorCallback> = 0);
+    void getFile(const String& path, const Dictionary&, PassRefPtr<EntryCallback> = 0, PassRefPtr<ErrorCallback> = 0);
+    void getDirectory(const String& path, const Dictionary&, PassRefPtr<EntryCallback> = 0, PassRefPtr<ErrorCallback> = 0);
     void removeRecursively(PassRefPtr<VoidCallback> successCallback = 0, PassRefPtr<ErrorCallback> = 0) const;
 
 private:
index b8ba194..5816167 100644 (file)
@@ -62,8 +62,6 @@ public:
     PassRefPtr<IDBAny> version() const;
     PassRefPtr<DOMStringList> objectStoreNames() const;
 
-    // FIXME: Try to modify the code generator so this is unneeded.
-    PassRefPtr<IDBObjectStore> createObjectStore(const String& name, ExceptionCode& ec) { return createObjectStore(name, Dictionary(), ec); }
     PassRefPtr<IDBObjectStore> createObjectStore(const String& name, const Dictionary&, ExceptionCode&);
     PassRefPtr<IDBTransaction> transaction(ScriptExecutionContext*, PassRefPtr<DOMStringList>, const String& mode, ExceptionCode&);
     PassRefPtr<IDBTransaction> transaction(ScriptExecutionContext*, const String&, const String& mode, ExceptionCode&);
index 2a8cfcf..9f027ea 100644 (file)
@@ -81,11 +81,8 @@ public:
     PassRefPtr<IDBRequest> deleteFunction(ScriptExecutionContext*, PassRefPtr<IDBKey> key, ExceptionCode&);
     PassRefPtr<IDBRequest> clear(ScriptExecutionContext*, ExceptionCode&);
 
-    // FIXME: Try to modify the code generator so this duplication is unneeded.
     PassRefPtr<IDBIndex> createIndex(ScriptExecutionContext*, const String& name, const String& keyPath, const Dictionary&, ExceptionCode&);
-    PassRefPtr<IDBIndex> createIndex(ScriptExecutionContext* context, const String& name, const String& keyPath, ExceptionCode& ec) { return createIndex(context, name, keyPath, Dictionary(), ec); }
     PassRefPtr<IDBIndex> createIndex(ScriptExecutionContext*, const String& name, PassRefPtr<DOMStringList> keyPath, const Dictionary&, ExceptionCode&);
-    PassRefPtr<IDBIndex> createIndex(ScriptExecutionContext* context, const String& name, PassRefPtr<DOMStringList> keyPath, ExceptionCode& ec) { return createIndex(context, name, keyPath, Dictionary(), ec); }
     PassRefPtr<IDBIndex> createIndex(ScriptExecutionContext*, const String&, const IDBKeyPath&, const Dictionary&, ExceptionCode&);
 
     PassRefPtr<IDBIndex> index(const String& name, ExceptionCode&);
index 4218243..81c628f 100644 (file)
 [
     Conditional=MEDIA_STREAM,
     ActiveDOMObject,
-    Constructor(in Dictionary rtcIceServers, in [Optional=DefaultIsUndefined] Dictionary mediaConstraints),
+    Constructor(in Dictionary rtcIceServers, in [Optional] Dictionary mediaConstraints),
     ConstructorRaisesException,
     CallWith=ScriptExecutionContext,
     EventTarget
 ] interface RTCPeerConnection {
-    void createOffer(in [Callback] RTCSessionDescriptionCallback successCallback, in [Callback,Optional=DefaultIsUndefined] RTCErrorCallback failureCallback, in [Optional=DefaultIsUndefined] Dictionary mediaConstraints)
+    void createOffer(in [Callback] RTCSessionDescriptionCallback successCallback, in [Callback,Optional=DefaultIsUndefined] RTCErrorCallback failureCallback, in [Optional] Dictionary mediaConstraints)
         raises(DOMException);
 
-    void createAnswer(in [Callback] RTCSessionDescriptionCallback successCallback, in [Callback, Optional=DefaultIsUndefined] RTCErrorCallback failureCallback, in [Optional=DefaultIsUndefined] Dictionary mediaConstraints)
+    void createAnswer(in [Callback] RTCSessionDescriptionCallback successCallback, in [Callback, Optional=DefaultIsUndefined] RTCErrorCallback failureCallback, in [Optional] Dictionary mediaConstraints)
         raises(DOMException);
 
     void setLocalDescription(in RTCSessionDescription description, in [Callback, Optional=DefaultIsUndefined] VoidCallback successCallback, in [Callback, Optional=DefaultIsUndefined] RTCErrorCallback failureCallback)
@@ -54,7 +54,7 @@
 
     readonly attribute DOMString readyState;
 
-    void updateIce(in [Optional=DefaultIsUndefined] Dictionary configuration, in [Optional=DefaultIsUndefined] Dictionary mediaConstraints)
+    void updateIce(in [Optional] Dictionary configuration, in [Optional] Dictionary mediaConstraints)
         raises(DOMException);
 
     void addIceCandidate(in RTCIceCandidate candidate)
     readonly attribute MediaStreamList localStreams;
     readonly attribute MediaStreamList remoteStreams;
 
-    [StrictTypeChecking] void addStream(in MediaStream stream, in [Optional=DefaultIsUndefined] Dictionary mediaConstraints)
+    [StrictTypeChecking] void addStream(in MediaStream stream, in [Optional] Dictionary mediaConstraints)
         raises(DOMException);
     [StrictTypeChecking] void removeStream(in MediaStream stream)
         raises(DOMException);
 
     void getStats(in [Callback] RTCStatsCallback successCallback, in [Optional=DefaultIsUndefined] MediaStreamTrack selector);
 
-    RTCDataChannel createDataChannel(in [TreatNullAs=NullString, TreatUndefinedAs=NullString] DOMString label, in [Optional=DefaultIsUndefined] Dictionary options)
+    RTCDataChannel createDataChannel(in [TreatNullAs=NullString, TreatUndefinedAs=NullString] DOMString label, in [Optional] Dictionary options)
          raises(DOMException);
 
     void close()
index b2a1649..28ea5db 100644 (file)
@@ -2652,10 +2652,13 @@ sub GenerateParametersCheck
     $implIncludes{"JSDOMBinding.h"} = 1;
 
     foreach my $parameter (@{$function->parameters}) {
+        my $argType = $codeGenerator->StripModule($parameter->type);
+
         # Optional arguments with [Optional] should generate an early call with fewer arguments.
         # Optional arguments with [Optional=...] should not generate the early call.
+        # Optional Dictionary arguments always considered to have default of empty dictionary.
         my $optional = $parameter->extendedAttributes->{"Optional"};
-        if ($optional && $optional ne "DefaultIsUndefined" && $optional ne "DefaultIsNullString" && !$parameter->extendedAttributes->{"Callback"}) {
+        if ($optional && $optional ne "DefaultIsUndefined" && $optional ne "DefaultIsNullString" && $argType ne "Dictionary" && !$parameter->extendedAttributes->{"Callback"}) {
             # Generate early call if there are enough parameters.
             if (!$hasOptionalArguments) {
                 push(@$outputArray, "\n    size_t argsCount = exec->argumentCount();\n");
@@ -2673,7 +2676,6 @@ sub GenerateParametersCheck
         }
 
         my $name = $parameter->name;
-        my $argType = $codeGenerator->StripModule($parameter->type);
 
         if ($argType eq "XPathNSResolver") {
             push(@$outputArray, "    RefPtr<XPathNSResolver> customResolver;\n");
index 5d5bb77..397d2c3 100644 (file)
@@ -1715,13 +1715,13 @@ sub GenerateParametersCheck
 
     foreach my $parameter (@{$function->parameters}) {
         TranslateParameter($parameter);
-
-        my $parameterName = $parameter->name;
+        my $nativeType = GetNativeTypeFromSignature($parameter, $paramIndex);
 
         # Optional arguments with [Optional] should generate an early call with fewer arguments.
         # Optional arguments with [Optional=...] should not generate the early call.
+        # Optional Dictionary arguments always considered to have default of empty dictionary.
         my $optional = $parameter->extendedAttributes->{"Optional"};
-        if ($optional && $optional ne "DefaultIsUndefined" && $optional ne "DefaultIsNullString" && !$parameter->extendedAttributes->{"Callback"}) {
+        if ($optional && $optional ne "DefaultIsUndefined" && $optional ne "DefaultIsNullString" && $nativeType ne "Dictionary" && !$parameter->extendedAttributes->{"Callback"}) {
             $parameterCheckString .= "    if (args.Length() <= $paramIndex) {\n";
             my $functionCall = GenerateFunctionCallString($function, $paramIndex, "    " x 2, $implClassName, %replacements);
             $parameterCheckString .= $functionCall;
@@ -1733,6 +1733,7 @@ sub GenerateParametersCheck
             $parameterDefaultPolicy = "DefaultIsNullString";
         }
 
+        my $parameterName = $parameter->name;
         if (GetIndexOf($parameterName, @paramTransferListNames) != -1) {
             $replacements{$parameterName} = "messagePortArray" . ucfirst($parameterName);
             $paramIndex++;
@@ -1740,7 +1741,6 @@ sub GenerateParametersCheck
         }
 
         AddToImplIncludes("ExceptionCode.h");
-        my $nativeType = GetNativeTypeFromSignature($parameter, $paramIndex);
         if ($parameter->extendedAttributes->{"Callback"}) {
             my $className = GetCallbackClassName($parameter->type);
             AddToImplIncludes("$className.h");
index e06d4bb..31955ba 100644 (file)
@@ -1636,13 +1636,6 @@ EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionOptionsObject(ExecState*
     Dictionary oo(exec, MAYBE_MISSING_PARAMETER(exec, 0, DefaultIsUndefined));
     if (exec->hadException())
         return JSValue::encode(jsUndefined());
-
-    size_t argsCount = exec->argumentCount();
-    if (argsCount <= 1) {
-        impl->optionsObject(oo);
-        return JSValue::encode(jsUndefined());
-    }
-
     Dictionary ooo(exec, MAYBE_MISSING_PARAMETER(exec, 1, DefaultIsUndefined));
     if (exec->hadException())
         return JSValue::encode(jsUndefined());
index 09129a4..2dc7366 100644 (file)
@@ -1173,10 +1173,6 @@ static v8::Handle<v8::Value> optionsObjectCallback(const v8::Arguments& args)
     EXCEPTION_BLOCK(Dictionary, oo, Dictionary(MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined), args.GetIsolate()));
     if (!oo.isUndefinedOrNull() && !oo.isObject())
         return throwTypeError("Not an object.", args.GetIsolate());
-    if (args.Length() <= 1) {
-        imp->optionsObject(oo);
-        return v8Undefined();
-    }
     EXCEPTION_BLOCK(Dictionary, ooo, Dictionary(MAYBE_MISSING_PARAMETER(args, 1, DefaultIsUndefined), args.GetIsolate()));
     if (!ooo.isUndefinedOrNull() && !ooo.isObject())
         return throwTypeError("Not an object.", args.GetIsolate());