Bug 761707 part 1. Rip out the various infrastructure for allowing different slot indices on different DOMJSClass instances. r=bholley
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 06 Jun 2012 15:59:46 -0400
changeset 98725 d15b364be513ab84dd144cc49d21d1e8d85b94c9
parent 98724 3b1f2455579acc95bcc9883f13084878f5b80f63
child 98726 1a2c4e651e306c25b80a7b5801e35ccc58e9ea33
push id1729
push userlsblakk@mozilla.com
push dateMon, 16 Jul 2012 20:02:43 +0000
treeherdermozilla-aurora@f4e75e148951 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs761707
milestone16.0a1
Bug 761707 part 1. Rip out the various infrastructure for allowing different slot indices on different DOMJSClass instances. r=bholley
dom/bindings/BindingUtils.h
dom/bindings/Codegen.py
dom/bindings/DOMJSClass.h
dom/workers/Worker.cpp
dom/workers/WorkerScope.cpp
--- a/dom/bindings/BindingUtils.h
+++ b/dom/bindings/BindingUtils.h
@@ -59,26 +59,17 @@ IsDOMClass(const JSClass* clasp)
 {
   return clasp->flags & JSCLASS_IS_DOMJSCLASS;
 }
 
 template <class T>
 inline T*
 UnwrapDOMObject(JSObject* obj, const JSClass* clasp)
 {
-  MOZ_ASSERT(IsDOMClass(clasp));
-  MOZ_ASSERT(JS_GetClass(obj) == clasp);
-
-  size_t slot = DOMJSClass::FromJSClass(clasp)->mNativeSlot;
-  MOZ_ASSERT((slot == DOM_OBJECT_SLOT &&
-              !(clasp->flags & JSCLASS_DOM_GLOBAL)) ||
-             (slot == DOM_GLOBAL_OBJECT_SLOT &&
-              (clasp->flags & JSCLASS_DOM_GLOBAL)));
-
-  JS::Value val = js::GetReservedSlot(obj, slot);
+  JS::Value val = js::GetReservedSlot(obj, DOM_OBJECT_SLOT);
   // XXXbz/khuey worker code tries to unwrap interface objects (which have
   // nothing here).  That needs to stop.
   // XXX We don't null-check UnwrapObject's result; aren't we going to crash
   // anyway?
   if (val.isUndefined()) {
     return NULL;
   }
   
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -112,17 +112,17 @@ DOMJSClass Class = {
     NULL,                  /* checkAccess */
     NULL,                  /* call */
     NULL,                  /* hasInstance */
     NULL,                  /* construct */
     %s, /* trace */
     JSCLASS_NO_INTERNAL_MEMBERS
   },
   { %s },
-  -1, %s, DOM_OBJECT_SLOT,
+  -1, %s,
   %s
 };
 """ % (self.descriptor.interface.identifier.name,
        ADDPROPERTY_HOOK_NAME if self.descriptor.concrete and not self.descriptor.workers else 'JS_PropertyStub',
        FINALIZE_HOOK_NAME, traceHook, prototypeChainString,
        str(self.descriptor.nativeIsISupports).lower(),
        nativeHooks)
 
--- a/dom/bindings/DOMJSClass.h
+++ b/dom/bindings/DOMJSClass.h
@@ -6,24 +6,24 @@
 #ifndef mozilla_dom_DOMJSClass_h
 #define mozilla_dom_DOMJSClass_h
 
 #include "jsapi.h"
 #include "jsfriendapi.h"
 
 #include "mozilla/dom/PrototypeList.h" // auto-generated
 
-// For non-global objects we use slot 0 for holding the raw object.
+// We use slot 0 for holding the raw object.  This is safe for both
+// globals and non-globals.
 #define DOM_OBJECT_SLOT 0
 
-// All DOM globals must have two slots at DOM_GLOBAL_OBJECT_SLOT and
-// DOM_PROTOTYPE_SLOT. We have to start at 1 past JSCLASS_GLOBAL_SLOT_COUNT
-// because XPConnect uses that one.
-#define DOM_GLOBAL_OBJECT_SLOT (JSCLASS_GLOBAL_SLOT_COUNT + 1)
-#define DOM_PROTOTYPE_SLOT (JSCLASS_GLOBAL_SLOT_COUNT + 2)
+// All DOM globals must have a slot at DOM_PROTOTYPE_SLOT. We have to
+// start at 1 past JSCLASS_GLOBAL_SLOT_COUNT because XPConnect uses
+// that one.
+#define DOM_PROTOTYPE_SLOT (JSCLASS_GLOBAL_SLOT_COUNT + 1)
 
 // We use these flag bits for the new bindings.
 #define JSCLASS_IS_DOMJSCLASS JSCLASS_USERBIT1
 #define JSCLASS_DOM_GLOBAL JSCLASS_USERBIT2
 
 namespace mozilla {
 namespace dom {
 
@@ -59,19 +59,16 @@ struct DOMJSClass
   // XXXkhuey this is unused and needs to die.
   const int16_t mGetWrapperCacheVTableOffset;
 
   // We store the DOM object in a reserved slot whose index is mNativeSlot.
   // Sometimes it's an nsISupports and sometimes it's not; this class tells
   // us which it is.
   const bool mDOMObjectIsISupports;
 
-  // The slot to use to get the object reference from the object
-  const size_t mNativeSlot;
-
   const NativePropertyHooks* mNativeHooks;
 
   static DOMJSClass* FromJSClass(JSClass* base) {
     MOZ_ASSERT(base->flags & JSCLASS_IS_DOMJSCLASS);
     return reinterpret_cast<DOMJSClass*>(base);
   }
   static const DOMJSClass* FromJSClass(const JSClass* base) {
     MOZ_ASSERT(base->flags & JSCLASS_IS_DOMJSCLASS);
--- a/dom/workers/Worker.cpp
+++ b/dom/workers/Worker.cpp
@@ -282,17 +282,17 @@ DOMJSClass Worker::sClass = {
     JSCLASS_IS_DOMJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(1) |
     JSCLASS_IMPLEMENTS_BARRIERS,
     JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
     JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, Finalize,
     NULL, NULL, NULL, NULL, Trace
   },
   { prototypes::id::EventTarget_workers, prototypes::id::_ID_Count,
     prototypes::id::_ID_Count },
-  -1, false, DOM_OBJECT_SLOT
+  -1, false, NULL
 };
 
 JSPropertySpec Worker::sProperties[] = {
   { sEventStrings[STRING_onerror], STRING_onerror, PROPERTY_FLAGS,
     GetEventListener, SetEventListener },
   { sEventStrings[STRING_onmessage], STRING_onmessage, PROPERTY_FLAGS,
     GetEventListener, SetEventListener },
   { 0, 0, 0, NULL, NULL }
@@ -400,17 +400,17 @@ DOMJSClass ChromeWorker::sClass = {
     JSCLASS_IS_DOMJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(1) |
     JSCLASS_IMPLEMENTS_BARRIERS,
     JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
     JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, Finalize,
     NULL, NULL, NULL, NULL, Trace,
   },
   { prototypes::id::EventTarget_workers, prototypes::id::_ID_Count,
     prototypes::id::_ID_Count },
-  -1, false, DOM_OBJECT_SLOT
+  -1, false, NULL
 };
 
 WorkerPrivate*
 Worker::GetInstancePrivate(JSContext* aCx, JSObject* aObj,
                            const char* aFunctionName)
 {
   JSClass* classPtr = JS_GetClass(aObj);
   if (classPtr == Class() || classPtr == ChromeWorker::Class()) {
--- a/dom/workers/WorkerScope.cpp
+++ b/dom/workers/WorkerScope.cpp
@@ -676,17 +676,17 @@ public:
   {
     JS_ASSERT(JS_GetClass(aObj) == Class());
 
     dom::AllocateProtoOrIfaceCache(aObj);
 
     nsRefPtr<DedicatedWorkerGlobalScope> scope =
       new DedicatedWorkerGlobalScope(aCx, aWorkerPrivate);
 
-    js::SetReservedSlot(aObj, DOM_GLOBAL_OBJECT_SLOT, PRIVATE_TO_JSVAL(scope));
+    js::SetReservedSlot(aObj, DOM_OBJECT_SLOT, PRIVATE_TO_JSVAL(scope));
 
     scope->SetIsDOMBinding();
     scope->SetWrapper(aObj);
 
     scope.forget();
     return true;
   }
 
@@ -854,17 +854,17 @@ DOMJSClass DedicatedWorkerGlobalScope::s
     JSCLASS_DOM_GLOBAL | JSCLASS_IS_DOMJSCLASS | JSCLASS_IMPLEMENTS_BARRIERS |
     JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(3) | JSCLASS_NEW_RESOLVE,
     JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
     JS_EnumerateStub, reinterpret_cast<JSResolveOp>(Resolve), JS_ConvertStub,
     Finalize, NULL, NULL, NULL, NULL, Trace
   },
   { prototypes::id::EventTarget_workers, prototypes::id::_ID_Count,
     prototypes::id::_ID_Count },
-  -1, false, DOM_GLOBAL_OBJECT_SLOT
+  -1, false, NULL
 };
 
 JSPropertySpec DedicatedWorkerGlobalScope::sProperties[] = {
   { sEventStrings[STRING_onmessage], STRING_onmessage, PROPERTY_FLAGS,
     GetEventListener, SetEventListener },
   { 0, 0, 0, NULL, NULL }
 };