Bug 865785 part 2. Fix rooting issues in JS-implemented webidl. r=mccr8
authorBoris Zbarsky <bzbarsky@mit.edu>
Sat, 04 May 2013 21:44:10 -0400
changeset 141817 1a60a6e9d9b8bd5f6efb50f35410974236a58e7b
parent 141816 1531a6ec12c179ea3b8614f10f4f231081081517
child 141818 ed26fdbe84444121879af267cb0871873ad395ad
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs865785
milestone23.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 865785 part 2. Fix rooting issues in JS-implemented webidl. r=mccr8
dom/bindings/Codegen.py
dom/bindings/test/TestCImplementedInterface.h
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -1088,17 +1088,19 @@ class CGClassConstructor(CGAbstractStati
 
 # Encapsulate the constructor in a helper method to share genConstructorBody with CGJSImplMethod.
 class CGConstructNavigatorObjectHelper(CGAbstractStaticMethod):
     """
     Construct a new JS-implemented WebIDL DOM object, for use on navigator.
     """
     def __init__(self, descriptor):
         name = "ConstructNavigatorObjectHelper"
-        args = [Argument('GlobalObject&', 'global'), Argument('ErrorResult&', 'aRv')]
+        args = [Argument('JSContext*', 'cx'),
+                Argument('GlobalObject&', 'global'),
+                Argument('ErrorResult&', 'aRv')]
         rtype = 'already_AddRefed<%s>' % descriptor.name
         CGAbstractStaticMethod.__init__(self, descriptor, name, rtype, args)
 
     def definition_body(self):
         return genConstructorBody(self.descriptor)
 
 class CGConstructNavigatorObject(CGAbstractMethod):
     """
@@ -1113,17 +1115,17 @@ class CGConstructNavigatorObject(CGAbstr
         if not self.descriptor.interface.isJSImplemented():
             raise TypeError("Only JS-implemented classes are currently supported "
                             "on navigator. See bug 856820.")
         return string.Template("""  GlobalObject global(aCx, aObj);
   if (global.Failed()) {
     return nullptr;
   }
   ErrorResult rv;
-  nsRefPtr<mozilla::dom::${descriptorName}> result = ConstructNavigatorObjectHelper(global, rv);
+  nsRefPtr<mozilla::dom::${descriptorName}> result = ConstructNavigatorObjectHelper(aCx, global, rv);
   rv.WouldReportJSException();
   if (rv.Failed()) {
     ThrowMethodFailedWithDetails<${mainThread}>(aCx, rv, "${descriptorName}", "navigatorConstructor");
     return nullptr;
   }
   JS::Rooted<JS::Value> v(aCx);
   if (!WrapNewBindingObject(aCx, aObj, result, v.address())) {
     MOZ_ASSERT(JS_IsExceptionPending(aCx));
@@ -8640,34 +8642,34 @@ def genConstructorBody(descriptor):
   MOZ_ASSERT(implISupports, "Failed to get JS implementation instance from contract ID.");
   if (!implISupports) {
     aRv.Throw(NS_ERROR_FAILURE);
     return nullptr;
   }
   // Initialize the object, if it implements nsIDOMGlobalPropertyInitializer.
   nsCOMPtr<nsIDOMGlobalPropertyInitializer> gpi = do_QueryInterface(implISupports);
   if (gpi) {
-    JS::Value initReturn = JSVAL_VOID;
-    nsresult rv = gpi->Init(window, &initReturn);
+    JS::Rooted<JS::Value> initReturn(cx);
+    nsresult rv = gpi->Init(window, initReturn.address());
     if (NS_FAILED(rv)) {
       aRv.Throw(rv);
       return nullptr;
     }
     MOZ_ASSERT(initReturn.isUndefined(),
                "Expected nsIDOMGlobalPropertyInitializer to return undefined");
   }
   // Extract the JS implementation from the XPCOM object.
   nsCOMPtr<nsIXPConnectWrappedJS> implWrapped = do_QueryInterface(implISupports);
   MOZ_ASSERT(implWrapped, "Failed to get wrapped JS from XPCOM component.");
   if (!implWrapped) {
     aRv.Throw(NS_ERROR_FAILURE);
     return nullptr;
   }
-  JSObject* jsImplObj;
-  if (NS_FAILED(implWrapped->GetJSObject(&jsImplObj))) {
+  JS::Rooted<JSObject*> jsImplObj(cx);
+  if (NS_FAILED(implWrapped->GetJSObject(jsImplObj.address()))) {
     aRv.Throw(NS_ERROR_FAILURE);
     return nullptr;
   }
   // Build the C++ implementation.
   nsRefPtr<${implClass}> impl = new ${implClass}(jsImplObj, window);
   return impl.forget();""").substitute({"implClass" : descriptor.name,
                  "contractId" : descriptor.interface.getJSImplementation()
                  })
@@ -8779,17 +8781,17 @@ class CGJSImplClass(CGBindingImplClass):
                 break
             parentInterface = parentInterface.parent
         if not parentInterface and descriptor.interface.parent:
             # We only have C++ ancestors, so only pass along the window
             baseConstructors.insert(0,
                                     "%s(aParent)" % parentClass)
 
         constructor = ClassConstructor(
-            [Argument("JSObject*", "aJSImplObject"),
+            [Argument("JS::Handle<JSObject*>", "aJSImplObject"),
              Argument("nsPIDOMWindow*", "aParent")],
             visibility="public",
             baseConstructors=baseConstructors,
             body=constructorBody)
 
         CGClass.__init__(self, descriptor.name,
                          bases=baseClasses,
                          constructors=[constructor],
--- a/dom/bindings/test/TestCImplementedInterface.h
+++ b/dom/bindings/test/TestCImplementedInterface.h
@@ -12,17 +12,18 @@
 class nsPIDOMWindow;
 
 namespace mozilla {
 namespace dom {
 
 class TestCImplementedInterface : public TestJSImplInterface
 {
 public:
-  TestCImplementedInterface(JSObject* aJSImpl, nsPIDOMWindow* aParent)
+  TestCImplementedInterface(JS::Handle<JSObject*> aJSImpl,
+                            nsPIDOMWindow* aParent)
     : TestJSImplInterface(aJSImpl, aParent)
   {}
 };
 
 class TestCImplementedInterface2 : public nsISupports,
                                    public nsWrapperCache
 {
 public: