Bug 1113827 part 1. Automatically mark Web IDL [NewObject] methods that return a JS type as fallible. r=peterv
authorBoris Zbarsky <bzbarsky@mit.edu>
Mon, 12 Jan 2015 11:52:21 -0500
changeset 249203 7e3abaf18602116c8f643a790f6e93c597010e35
parent 249202 b2aff7ebf9b45444997a83d8aeccc3339897cb41
child 249204 560fcd0679e8e83d0d41dfe647a8fa2513f22699
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspeterv
bugs1113827
milestone37.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1113827 part 1. Automatically mark Web IDL [NewObject] methods that return a JS type as fallible. r=peterv
dom/bindings/Configuration.py
--- a/dom/bindings/Configuration.py
+++ b/dom/bindings/Configuration.py
@@ -280,16 +280,28 @@ class DescriptorProvider:
     def getDescriptor(self, interfaceName):
         """
         Gets the appropriate descriptor for the given interface name given the
         context of the current descriptor. This selects the appropriate
         implementation for cases like workers.
         """
         return self.config.getDescriptor(interfaceName, self.workers)
 
+def methodReturnsJSObject(method):
+    assert method.isMethod()
+    if method.returnsPromise():
+        return True
+
+    for signature in method.signatures():
+        returnType = signature[0]
+        if returnType.isObject() or returnType.isSpiderMonkeyInterface():
+            return True
+
+    return False
+
 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
 
@@ -617,16 +629,21 @@ class Descriptor(DescriptorProvider):
                 (throws is not True and
                  ('Workers' not in throws or not self.workers) and
                  ('MainThread' not in throws or self.workers))):
                 attrs.append("infallible")
 
         name = member.identifier.name
         throws = self.interface.isJSImplemented() or member.getExtendedAttribute("Throws")
         if member.isMethod():
+            # JSObject-returning [NewObject] methods must be fallible,
+            # since they have to (fallibly) allocate the new JSObject.
+            if (member.getExtendedAttribute("NewObject") and
+                methodReturnsJSObject(member)):
+                throws = True
             attrs = self.extendedAttributes['all'].get(name, [])
             maybeAppendInfallibleToAttrs(attrs, throws)
             return attrs
 
         assert member.isAttr()
         assert bool(getter) != bool(setter)
         key = 'getterOnly' if getter else 'setterOnly'
         attrs = self.extendedAttributes['all'].get(name, []) + self.extendedAttributes[key].get(name, [])