Introduce GetProtoArray function that asserts that the object has the correct flag; r=bz
authorMs2ger <ms2ger@gmail.com>
Mon, 30 Jan 2012 17:27:22 +0100
changeset 85184 376ae400530fad30ca8e1c2ae45c7d34fd2391be
parent 85183 06eeb17df2d844ce56b59360e2f875fed3a4a92f
child 85185 8f00788a9a5a5e267b9a3730ce725b16793167ac
push id80
push userMs2ger@gmail.com
push dateMon, 30 Jan 2012 16:27:33 +0000
reviewersbz
milestone12.0a1
Introduce GetProtoArray function that asserts that the object has the correct flag; r=bz
dom/bindings/Codegen.py
dom/bindings/Utils.h
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -251,18 +251,17 @@ class CGGetProtoObjectMethod(CGAbstractM
   /* Get the prototype object for this class.  This will create the prototype
      as needed. */
 
   /* Make sure our global is sane.  Hopefully we can remove this sometime */
   if (!(js::GetObjectClass(aGlobal)->flags & JSCLASS_DOM_GLOBAL)) {
     return NULL;
   }
   /* Check to see whether the prototype is already installed */
-  JSObject **protoArray =
-    static_cast<JSObject**>(js::GetReservedSlot(aGlobal, DOM_PROTOTYPE_SLOT).toPrivate());
+  JSObject **protoArray = GetProtoArray(aGlobal);
   JSObject *ourProto = protoArray[id::%s];
   if (!ourProto) {
     ourProto = protoArray[id::%s] = CreateProtoObject(aCx, aGlobal);
   }
 
   /* ourProto might _still_ be null, but that's OK */
   return ourProto;""" % (self.implementation.name, self.implementation.name)
 
--- a/dom/bindings/Utils.h
+++ b/dom/bindings/Utils.h
@@ -124,29 +124,36 @@ UnwrapInterfaceArg(JSContext *cx,
     }
   }
 
   // Fall back on unwrapping old-style arguments (possibly including
   // nodelist bindings).
   return xpc_qsUnwrapArg(cx, v, value, argRef, vp);
 }
 
+inline JSObject **
+GetProtoArray(JSObject *global)
+{
+  MOZ_ASSERT(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL);
+  return static_cast<JSObject**>(
+    js::GetReservedSlot(global, DOM_PROTOTYPE_SLOT).toPrivate());
+}
+
 inline void
 AllocateProtoCache(JSObject *obj)
 {
   // Important: The () at the end ensure zero-initialization
   JSObject** protoArray = new JSObject*[prototypes::id::Count]();
   js::SetReservedSlot(obj, DOM_PROTOTYPE_SLOT, JS::PrivateValue(protoArray));
 }
 
 inline void
 DestroyProtoCache(JSObject *obj)
 {
-  JSObject **protoArray = static_cast<JSObject**>(
-    js::GetReservedSlot(obj, DOM_PROTOTYPE_SLOT).toPrivate());
+  JSObject **protoArray = GetProtoArray(obj);
   delete [] protoArray;
 }
 
 inline JSObject*
 GetCanonicalObjectProto(JSContext *cx, JSObject *global)
 {
   JSObject* proto;
   if (!js_GetClassPrototype(cx, global, JSProto_Object, &proto)) {