Bug 779046. Have saner defaults for the nativeType of a WebIDL bindings. r=peterv
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 28 Aug 2012 13:10:09 -0400
changeset 105712 561f1e6ccdc9e7efe9a4e17e35a1cc0d937a4522
parent 105711 cfd19083d2989e51e367f6ff0d9341ad3e8b2c75
child 105713 41b8acc383568b521ae0efd691ebd30ca92c10b1
push id55
push usershu@rfrn.org
push dateThu, 30 Aug 2012 01:33:09 +0000
reviewerspeterv
bugs779046
milestone18.0a1
Bug 779046. Have saner defaults for the nativeType of a WebIDL bindings. r=peterv
dom/bindings/Bindings.conf
dom/bindings/Configuration.py
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -5,17 +5,24 @@
 # DOM Bindings Configuration.
 #
 # The WebIDL interfaces are defined in dom/webidl. For each such interface, there
 # is a corresponding entry in the configuration table below. The configuration
 # table maps each interface name to a |descriptor| or list of |descriptor|s.
 #
 # Valid fields for all descriptors:
 #   * nativeType - The native type (concrete class or XPCOM interface) that
-#                  instances of this interface will unwrap to (required).
+#                  instances of this interface will unwrap to.  If not
+#                  specified, defaults to "mozilla::dom::InterfaceName" for
+#                  non-worker non-external-or-callback interfaces, to
+#                  "mozilla::dom::workers::InterfaceName" for worker
+#                  non-external interfaces, to 'nsIDOM' followed by the
+#                  interface name for non-worker external-or-callback
+#                  interfaces, and to "JSObject" for worker external-or-callback
+#                  interfaces.
 #   * headerFile - The file in which the nativeType is declared (defaults
 #                  to an educated guess).
 #   * castable - Indicates whether the value in the wrapper can be cast to
 #                nativeType, or whether it needs to be QI-ed (defaults to True
 #                for everything but callback interfaces and external interfaces,
 #                for which it defaults to false and is not allowed to be set
 #                at all).
 #   * concrete - Indicates whether there exist objects with this interface as
@@ -51,23 +58,20 @@
 #                         that require a JSContext as the first argument
 #   * resultNotAddRefed - attributes and methods specified in the .webidl file
 #                         that do not AddRef the return value
 
 DOMInterfaces = {
 
 'Blob': [
 {
-    'nativeType': 'nsIDOMBlob',
     'headerFile': 'nsIDOMFile.h',
 },
 {
     'workers': True,
-    'nativeType': 'JSObject',
-    'headerFile': 'jsapi.h',
 }],
 
 'CanvasRenderingContext2D': [
 {
     'nativeType': 'nsCanvasRenderingContext2DAzure',
     # Making this non-prefable requires that we ensure that nothing takes this
     # type as an argument or that the non-Azure variant is removed.
     'prefable': True,
@@ -93,96 +97,77 @@ DOMInterfaces = {
 },
 
 'Document': [
 {
     'nativeType': 'nsIDocument',
 },
 {
     'workers': True,
-    'nativeType': 'JSObject',
-    'headerFile': 'jsapi.h',
 }],
 
 'Event': [
 {
-    'nativeType': 'nsIDOMEvent',
 },
 {
     'workers': True,
-    'nativeType': 'JSObject',
-    'headerFile': 'jsapi.h',
 }],
 
 'EventListener': [
 {
-    'nativeType': 'nsIDOMEventListener',
-    'prefable': True
 },
 {
     'workers': True,
-    'nativeType': 'JSObject',
-    'headerFile': 'jsapi.h'
 }],
 
 'EventTarget': [
 {
     'nativeType': 'nsDOMEventTargetHelper',
     'hasInstanceInterface': 'nsIDOMEventTarget',
     'concrete': False,
     'prefable': True,
 },
 {
     'workers': True,
-    'nativeType': 'mozilla::dom::workers::EventTarget',
     'headerFile': 'mozilla/dom/workers/bindings/EventTarget.h',
     'concrete': False
 }],
 
 'FormData': [
 {
-    'nativeType': 'nsIDOMFormData',
 },
 {
     'workers': True,
-    'nativeType': 'JSObject',
-    'headerFile': 'jsapi.h',
 }],
 
 'IID': [
 {
     'nativeType': 'nsIJSIID',
     'headerFile': 'xpcjsid.h',
 },
 {
     'workers': True,
-    'nativeType': 'JSObject',
-    'headerFile': 'jsapi.h',
 }],
 
 'InputStream': [
 {
     'nativeType': 'nsIInputStream',
     'notflattened': True
 },
 {
     'workers': True,
-    'nativeType': 'JSObject',
-    'headerFile': 'jsapi.h',
 }],
 
 'MozChannel': [
 {
     'nativeType': 'nsIChannel',
     'notflattened': True
 },
 {
     'workers': True,
-    'nativeType': 'JSObject',
-    'headerFile': 'jsapi.h',
 }],
 
 'Performance': {
     'nativeType': 'nsPerformance',
     'resultNotAddRefed': [ 'timing', 'navigation' ]
 },
 
 'PerformanceTiming': {
@@ -214,52 +199,48 @@ DOMInterfaces = {
 {
     'nativeType': 'nsXMLHttpRequest',
     'prefable': True,
     'implicitJSContext': [ 'constructor', ],
     'resultNotAddRefed': [ 'upload', 'responseXML' ]
 },
 {
     'workers': True,
-    'nativeType': 'mozilla::dom::workers::XMLHttpRequest',
     'headerFile': 'mozilla/dom/workers/bindings/XMLHttpRequest.h',
 }],
 
 'XMLHttpRequestEventTarget': [
 {
     'nativeType': 'nsXHREventTarget',
     'headerFile': 'nsXMLHttpRequest.h',
     'concrete': False,
     'prefable': True,
 },
 {
     'workers': True,
     'concrete': False,
-    'nativeType': 'mozilla::dom::workers::XMLHttpRequestEventTarget',
     'headerFile': 'mozilla/dom/workers/bindings/XMLHttpRequestEventTarget.h'
 }],
 
 'XMLHttpRequestUpload': [
 {
     'nativeType': 'nsXMLHttpRequestUpload',
     'headerFile': 'nsXMLHttpRequest.h',
     'prefable': True
 },
 {
     'workers': True,
-    'nativeType': 'mozilla::dom::workers::XMLHttpRequestUpload',
     'headerFile': 'mozilla/dom/workers/bindings/XMLHttpRequestUpload.h'
 }],
 
 ####################################
 # Test Interfaces of various sorts #
 ####################################
 
 'TestInterface' : {
-        'nativeType': 'mozilla::dom::TestInterface',
         'headerFile': 'TestBindingHeader.h',
         'register': False,
         'resultNotAddRefed': [ 'receiveWeakSelf', 'receiveWeakNullableSelf',
                                'receiveWeakOther', 'receiveWeakNullableOther',
                                'receiveWeakExternal', 'receiveWeakNullableExternal',
                                'ReceiveWeakCallbackInterface',
                                'ReceiveWeakNullableCallbackInterface',
                                'receiveWeakCastableObjectSequence',
@@ -267,111 +248,99 @@ DOMInterfaces = {
                                'receiveWeakCastableObjectNullableSequence',
                                'receiveWeakNullableCastableObjectNullableSequence' ],
         'binaryNames': { 'methodRenamedFrom': 'methodRenamedTo',
                          'attributeGetterRenamedFrom': 'attributeGetterRenamedTo',
                          'attributeRenamedFrom': 'attributeRenamedTo' }
         },
 
 'TestNonCastableInterface' : {
-        'nativeType': 'mozilla::dom::TestNonCastableInterface',
         'headerFile': 'TestBindingHeader.h',
         'register': False,
         'castable': False
         },
 
 'TestExternalInterface' : {
         'nativeType': 'mozilla::dom::TestExternalInterface',
         'headerFile': 'TestBindingHeader.h',
         'register': False
         },
 
 'TestNonWrapperCacheInterface' : {
-        'nativeType': 'mozilla::dom::TestNonWrapperCacheInterface',
         'headerFile': 'TestBindingHeader.h',
         'register': False,
         'wrapperCache': False
         },
 
 'TestCallbackInterface': {
         'nativeType': 'mozilla::dom::TestCallbackInterface',
         'headerFile': 'TestBindingHeader.h',
         'register': False
         },
 
 'IndirectlyImplementedInterface': {
-        'nativeType': 'mozilla::dom::IndirectlyImplementedInterface',
         'headerFile': 'TestBindingHeader.h',
         'register': False,
         'castable': False,
         'concrete': False
         },
 
 'OnlyForUseInConstructor' : {
-        'nativeType': 'mozilla::dom::OnlyForUseInConstructor',
         'headerFile': 'TestBindingHeader.h',
         'register': False
         },
 
 
 'TestIndexedGetterInterface' : {
-        'nativeType': 'mozilla::dom::TestIndexedGetterInterface',
         'headerFile': 'TestBindingHeader.h',
         'register': False,
         'infallible': [ 'length' ]
         },
 
 'TestNamedGetterInterface' : {
-        'nativeType': 'mozilla::dom::TestNamedGetterInterface',
         'headerFile': 'TestBindingHeader.h',
         'register': False
         },
 
 'TestIndexedAndNamedGetterInterface' : {
-        'nativeType': 'mozilla::dom::TestIndexedAndNamedGetterInterface',
         'headerFile': 'TestBindingHeader.h',
         'register': False,
         'infallible': [ 'length' ]
         },
 
 'TestIndexedSetterInterface' : {
-        'nativeType': 'mozilla::dom::TestIndexedSetterInterface',
         'headerFile': 'TestBindingHeader.h',
         'register': False
         },
 
 'TestNamedSetterInterface' : {
-        'nativeType': 'mozilla::dom::TestNamedSetterInterface',
         'headerFile': 'TestBindingHeader.h',
         'register': False
         },
 
 'TestIndexedAndNamedSetterInterface' : {
-        'nativeType': 'mozilla::dom::TestIndexedAndNamedSetterInterface',
         'headerFile': 'TestBindingHeader.h',
         'register': False
         },
 
 'TestIndexedAndNamedGetterAndSetterInterface' : {
-        'nativeType': 'mozilla::dom::TestIndexedAndNamedGetterAndSetterInterface',
         'headerFile': 'TestBindingHeader.h',
         'register': False,
         'infallible': [ 'length', '__stringifier' ],
         'binaryNames': { '__stringifier': 'Stringify' }
         },
 }
 
 # These are temporary, until they've been converted to use new DOM bindings
 def addExternalIface(iface, nativeType=None, headerFile=None):
-    if nativeType is None:
-        nativeType = 'nsIDOM' + iface
     domInterface = {
-        'nativeType': nativeType,
         'concrete': False
     }
+    if not nativeType is None:
+        domInterface['nativeType'] = nativeType
     if not headerFile is None:
         domInterface['headerFile'] = headerFile
     DOMInterfaces[iface] = domInterface
 
 # If you add one of these, you need to make sure nsDOMQS.h has the relevant
 # macros added for it
 def addExternalHTMLElement(element):
    nativeElement = 'ns' + element
--- a/dom/bindings/Configuration.py
+++ b/dom/bindings/Configuration.py
@@ -122,21 +122,37 @@ class Descriptor(DescriptorProvider):
     """
     Represents a single descriptor for an interface. See Bindings.conf.
     """
     def __init__(self, config, interface, desc):
         DescriptorProvider.__init__(self, config, desc.get('workers', False))
         self.interface = interface
 
         # Read the desc, and fill in the relevant defaults.
-        self.nativeType = desc['nativeType']
+        ifaceName = self.interface.identifier.name
+        if self.interface.isExternal() or self.interface.isCallback():
+            if self.workers:
+                nativeTypeDefault = "JSObject"
+            else:
+                nativeTypeDefault = "nsIDOM" + ifaceName
+        else:
+            if self.workers:
+                nativeTypeDefault = "mozilla::dom::workers::" + ifaceName
+            else:
+                nativeTypeDefault = "mozilla::dom::" + ifaceName
+
+        self.nativeType = desc.get('nativeType', nativeTypeDefault)
         self.hasInstanceInterface = desc.get('hasInstanceInterface', None)
 
-        headerDefault = self.nativeType
-        headerDefault = headerDefault.replace("::", "/") + ".h"
+        # Do something sane for JSObject
+        if self.nativeType == "JSObject":
+            headerDefault = "jsapi.h"
+        else:
+            headerDefault = self.nativeType
+            headerDefault = headerDefault.replace("::", "/") + ".h"
         self.headerFile = desc.get('headerFile', headerDefault)
 
         if self.interface.isCallback() or self.interface.isExternal():
             if 'castable' in desc:
                 raise TypeError("%s is external or callback but has a castable "
                                 "setting" % self.interface.identifier.name)
             self.castable = False
         else: