Bug 1370640. Get rid of ProtoAndIfaceCache::EntrySlotIfExists. r=peterv
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 07 Jun 2017 12:56:27 -0400
changeset 410853 37f50095e77ef92ede26761f9e8c9835d60879e8
parent 410852 b84707ac2dfeec9de7d16ccf17d8a703844a59e7
child 410854 1cd8ff73215749a74bd9ae5b8a7b12ea21d28381
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspeterv
bugs1370640
milestone55.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 1370640. Get rid of ProtoAndIfaceCache::EntrySlotIfExists. r=peterv
dom/bindings/BindingUtils.cpp
dom/bindings/BindingUtils.h
--- a/dom/bindings/BindingUtils.cpp
+++ b/dom/bindings/BindingUtils.cpp
@@ -1538,21 +1538,25 @@ ResolvePrototypeOrConstructor(JSContext*
                               size_t protoAndIfaceCacheIndex, unsigned attrs,
                               JS::MutableHandle<JS::PropertyDescriptor> desc,
                               bool& cacheOnHolder)
 {
   JS::Rooted<JSObject*> global(cx, js::GetGlobalForObjectCrossCompartment(obj));
   {
     JSAutoCompartment ac(cx, global);
     ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
+    // This function is called when resolving the "constructor" and "prototype"
+    // properties of Xrays for DOM prototypes and constructors respectively.
+    // This means the relevant Xray exists, which means its _target_ exists.
+    // And that means we managed to successfullly create the prototype or
+    // constructor, respectively, and hence must have managed to create the
+    // thing it's pointing to as well.  So our entry slot must exist.
     JSObject* protoOrIface =
-      protoAndIfaceCache.EntrySlotIfExists(protoAndIfaceCacheIndex);
-    if (!protoOrIface) {
-      return false;
-    }
+      protoAndIfaceCache.EntrySlotMustExist(protoAndIfaceCacheIndex);
+    MOZ_RELEASE_ASSERT(protoOrIface, "How can this object not exist?");
 
     cacheOnHolder = true;
 
     desc.object().set(wrapper);
     desc.setAttributes(attrs);
     desc.setGetter(nullptr);
     desc.setSetter(nullptr);
     desc.value().set(JS::ObjectValue(*protoOrIface));
--- a/dom/bindings/BindingUtils.h
+++ b/dom/bindings/BindingUtils.h
@@ -264,20 +264,16 @@ class ProtoAndIfaceCache
   // with.  For a window-like global, we want everything to be as fast as
   // possible, so we use a flat array, indexed by prototype/constructor ID.
   // For everything else (e.g. globals for JSMs), space is more important than
   // speed, so we use a two-level lookup table.
 
   class ArrayCache : public Array<JS::Heap<JSObject*>, kProtoAndIfaceCacheCount>
   {
   public:
-    JSObject* EntrySlotIfExists(size_t i) {
-      return (*this)[i];
-    }
-
     bool HasEntryInSlot(size_t i) {
       return (*this)[i];
     }
 
     JS::Heap<JSObject*>& EntrySlotOrCreate(size_t i) {
       return (*this)[i];
     }
 
@@ -304,27 +300,16 @@ class ProtoAndIfaceCache
     }
 
     ~PageTableCache() {
       for (size_t i = 0; i < ArrayLength(mPages); ++i) {
         delete mPages[i];
       }
     }
 
-    JSObject* EntrySlotIfExists(size_t i) {
-      MOZ_ASSERT(i < kProtoAndIfaceCacheCount);
-      size_t pageIndex = i / kPageSize;
-      size_t leafIndex = i % kPageSize;
-      Page* p = mPages[pageIndex];
-      if (!p) {
-        return nullptr;
-      }
-      return (*p)[leafIndex];
-    }
-
     bool HasEntryInSlot(size_t i) {
       MOZ_ASSERT(i < kProtoAndIfaceCacheCount);
       size_t pageIndex = i / kPageSize;
       size_t leafIndex = i % kPageSize;
       Page* p = mPages[pageIndex];
       if (!p) {
         return false;
       }
@@ -407,22 +392,16 @@ public:
   do {                                               \
     if (mKind == WindowLike) {                       \
       return mArrayCache->opName args;               \
     } else {                                         \
       return mPageTableCache->opName args;           \
     }                                                \
   } while(0)
 
-  // Return the JSObject stored in slot i, if that slot exists.  If
-  // the slot does not exist, return null.
-  JSObject* EntrySlotIfExists(size_t i) {
-    FORWARD_OPERATION(EntrySlotIfExists, (i));
-  }
-
   // Return whether slot i contains an object.  This doesn't return the object
   // itself because in practice consumers just want to know whether it's there
   // or not, and that doesn't require barriering, which returning the object
   // pointer does.
   bool HasEntryInSlot(size_t i) {
     FORWARD_OPERATION(HasEntryInSlot, (i));
   }