Bug 864727 part 2. Pass a handle for the scope object to union conversions. r=ms2ger,terrence
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 25 Apr 2013 12:29:52 -0400
changeset 140835 27c89b2200adc341f7606846a568c729ac09ad45
parent 140834 a67479723670f4be9ab542f60880fb8e2ddc8dcb
child 140836 d13e71853e55348494a954403ef3f81c519d3daf
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)
reviewersms2ger, terrence
bugs864727
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 864727 part 2. Pass a handle for the scope object to union conversions. r=ms2ger,terrence
dom/bindings/CallbackObject.h
dom/bindings/Codegen.py
--- a/dom/bindings/CallbackObject.h
+++ b/dom/bindings/CallbackObject.h
@@ -25,16 +25,17 @@
 #include "mozilla/Assertions.h"
 #include "mozilla/ErrorResult.h"
 #include "mozilla/Util.h"
 #include "nsContentUtils.h" // nsCxPusher
 #include "nsWrapperCache.h"
 #include "nsJSEnvironment.h"
 #include "xpcpublic.h"
 #include "nsLayoutStatics.h"
+#include "js/RootingAPI.h"
 
 namespace mozilla {
 namespace dom {
 
 #define DOM_CALLBACKOBJECT_IID \
 { 0xbe74c190, 0x6d76, 0x4991, \
  { 0x84, 0xb9, 0x65, 0x06, 0x99, 0xe6, 0x93, 0x2b } }
 
@@ -51,33 +52,35 @@ public:
     Init(aCallback);
   }
 
   virtual ~CallbackObject()
   {
     DropCallback();
   }
 
-  JSObject* Callback() const
+  JS::Handle<JSObject*> Callback() const
   {
     xpc_UnmarkGrayObject(mCallback);
-    return mCallback;
+    return CallbackPreserveColor();
   }
 
   /*
    * This getter does not change the color of the JSObject meaning that the
    * object returned is not guaranteed to be kept alive past the next CC.
    *
    * This should only be called if you are certain that the return value won't
    * be passed into a JS API function and that it won't be stored without being
    * rooted (or otherwise signaling the stored value to the CC).
+   *
+   * This can return a handle because we trace our mCallback.
    */
-  JSObject* CallbackPreserveColor() const
+  JS::Handle<JSObject*> CallbackPreserveColor() const
   {
-    return mCallback;
+    return JS::Handle<JSObject*>::fromMarkedLocation(&mCallback);
   }
 
   enum ExceptionHandling {
     eReportExceptions,
     eRethrowExceptions
   };
 
 protected:
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -5363,17 +5363,17 @@ public:
 ${callDestructors}
       case eUninitialized:
         break;
     }
   }
 
 ${methods}
 
-  bool ToJSVal(JSContext* cx, JSObject* scopeObj, JS::Value* vp) const;
+  bool ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::Value* vp) const;
 
 private:
   friend class ${structName}Argument;
 
 ${destructors}
 
   enum Type {
     eUninitialized,
@@ -5406,17 +5406,17 @@ private:
                                    "      *vp = JS::NullValue();\n"
                                    "      return true;\n"
                                    "    }")
         conversionsToJS.extend(
             map(self.getConversionToJS,
                 zip(templateVars, self.type.flatMemberTypes)))
 
         return string.Template("""bool
-${structName}::ToJSVal(JSContext* cx, JSObject* scopeObj, JS::Value* vp) const
+${structName}::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::Value* vp) const
 {
   switch (mType) {
 ${doConversionsToJS}
 
     case eUninitialized:
     {
       break;
     }
@@ -8800,18 +8800,19 @@ class CallbackMember(CGNativeMember):
         conversion = prepend + wrapForType(
             arg.type, self.descriptor,
             {
                 'result' : result,
                 'successCode' : "continue;" if arg.variadic else "break;",
                 'jsvalRef' : "argv[%s]" % jsvalIndex,
                 'jsvalPtr' : "&argv[%s]" % jsvalIndex,
                 # XXXbz we don't have anything better to use for 'obj',
-                # really...
-                'obj' : 'mCallback',
+                # really...  It's OK to use CallbackPreserveColor because
+                # CallSetup already handled the unmark-gray bits for us.
+                'obj' : 'CallbackPreserveColor()',
                 'isCreator': False,
                 'exceptionCode' : self.exceptionCode
                 })
         if arg.variadic:
             conversion = string.Template(
                 "for (uint32_t idx = 0; idx < ${arg}.Length(); ++idx) {\n" +
                 CGIndenter(CGGeneric(conversion)).define() + "\n"
                 "}\n"