Bug 1442039 part 11. Remove all the non-static bits from nsDOMClassInfo. r=peterv
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 21 Mar 2018 23:13:29 -0400
changeset 409446 e609ee0164b016c3ecdb3425383455392accbf73
parent 409445 58c5cfca84ff41574e9971142720ac65f2aae1b7
child 409447 a9a5c2206177b487b3b3dc4ed7e93c14e7551e29
push id33687
push userapavel@mozilla.com
push dateThu, 22 Mar 2018 09:31:48 +0000
treeherdermozilla-central@7771df14ea18 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspeterv
bugs1442039
milestone61.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 1442039 part 11. Remove all the non-static bits from nsDOMClassInfo. r=peterv MozReview-Commit-ID: 7J8hsPuYtPa
dom/base/nsDOMClassInfo.cpp
dom/base/nsDOMClassInfo.h
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -162,90 +162,21 @@ nsDOMClassInfo::DefineStaticJSVals()
       return NS_ERROR_OUT_OF_MEMORY;
 
   SET_JSID_TO_STRING(sConstructor_id,     cx, "constructor");
   SET_JSID_TO_STRING(sWrappedJSObject_id, cx, "wrappedJSObject");
 
   return NS_OK;
 }
 
-// static
-bool
-nsDOMClassInfo::ObjectIsNativeWrapper(JSContext* cx, JSObject* obj)
-{
-  return xpc::WrapperFactory::IsXrayWrapper(obj) &&
-         xpc::AccessCheck::wrapperSubsumes(obj);
-}
-
-nsDOMClassInfo::nsDOMClassInfo(nsDOMClassInfoData* aData) : mData(aData)
-{
-}
-
-NS_IMPL_ADDREF(nsDOMClassInfo)
-NS_IMPL_RELEASE(nsDOMClassInfo)
-
-NS_INTERFACE_MAP_BEGIN(nsDOMClassInfo)
-  if (aIID.Equals(NS_GET_IID(nsXPCClassInfo)))
-    foundInterface = static_cast<nsIClassInfo*>(
-                                    static_cast<nsXPCClassInfo*>(this));
-  else
-  NS_INTERFACE_MAP_ENTRY(nsIXPCScriptable)
-  NS_INTERFACE_MAP_ENTRY(nsIClassInfo)
-  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIClassInfo)
-NS_INTERFACE_MAP_END
-
-
 static const JSClass sDOMConstructorProtoClass = {
   "DOM Constructor.prototype", 0
 };
 
-
-#define _DOM_CLASSINFO_MAP_BEGIN(_class, _ifptr, _has_class_if)               \
-  {                                                                           \
-    nsDOMClassInfoData &d = sClassInfoData[eDOMClassInfo_##_class##_id];      \
-    d.mProtoChainInterface = _ifptr;                                          \
-    d.mHasClassInterface = _has_class_if;                                     \
-    static const nsIID *interface_list[] = {
-
-#define DOM_CLASSINFO_MAP_BEGIN(_class, _interface)                           \
-  _DOM_CLASSINFO_MAP_BEGIN(_class, &NS_GET_IID(_interface), true)
-
-#define DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(_class, _interface)               \
-  _DOM_CLASSINFO_MAP_BEGIN(_class, &NS_GET_IID(_interface), false)
-
-#define DOM_CLASSINFO_MAP_ENTRY(_if)                                          \
-      &NS_GET_IID(_if),
-
-#define DOM_CLASSINFO_MAP_CONDITIONAL_ENTRY(_if, _cond)                       \
-      (_cond) ? &NS_GET_IID(_if) : nullptr,
-
-#define DOM_CLASSINFO_MAP_END                                                 \
-      nullptr                                                                  \
-    };                                                                        \
-                                                                              \
-    /* Compact the interface list */                                          \
-    size_t count = ArrayLength(interface_list);                               \
-    /* count is the number of array entries, which is one greater than the */ \
-    /* number of interfaces due to the terminating null */                    \
-    for (size_t i = 0; i < count - 1; ++i) {                                  \
-      if (!interface_list[i]) {                                               \
-        /* We are moving the element at index i+1 and successors, */          \
-        /* so we must move only count - (i+1) elements total. */              \
-        memmove(&interface_list[i], &interface_list[i+1],                     \
-                sizeof(nsIID*) * (count - (i+1)));                            \
-        /* Make sure to examine the new pointer we ended up with at this */   \
-        /* slot, since it may be null too */                                  \
-        --i;                                                                  \
-        --count;                                                              \
-      }                                                                       \
-    }                                                                         \
-                                                                              \
-    d.mInterfaces = interface_list;                                           \
-  }
-
+// static
 nsresult
 nsDOMClassInfo::Init()
 {
   /* Errors that can trigger early returns are done first,
      otherwise nsDOMClassInfo is left in a half inited state. */
   static_assert(sizeof(uintptr_t) == sizeof(void*),
                 "BAD! You'll need to adjust the size of uintptr_t to the "
                 "size of a pointer on your platform.");
@@ -263,221 +194,16 @@ nsDOMClassInfo::Init()
   // Initialize static JSString's
   DefineStaticJSVals();
 
   sIsInitialized = true;
 
   return NS_OK;
 }
 
-NS_IMETHODIMP
-nsDOMClassInfo::GetInterfaces(uint32_t *aCount, nsIID ***aArray)
-{
-  uint32_t count = 0;
-
-  while (mData->mInterfaces[count]) {
-    count++;
-  }
-
-  *aCount = count;
-
-  if (!count) {
-    *aArray = nullptr;
-
-    return NS_OK;
-  }
-
-  *aArray = static_cast<nsIID **>(moz_xmalloc(count * sizeof(nsIID *)));
-
-  uint32_t i;
-  for (i = 0; i < count; i++) {
-    *((*aArray) + i) = mData->mInterfaces[i]->Clone();
-  }
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsDOMClassInfo::GetScriptableHelper(nsIXPCScriptable **_retval)
-{
-  nsCOMPtr<nsIXPCScriptable> rval = this;
-  rval.forget(_retval);
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsDOMClassInfo::GetContractID(nsACString& aContractID)
-{
-  aContractID.SetIsVoid(true);
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsDOMClassInfo::GetClassDescription(nsACString& aClassDescription)
-{
-  return GetClassName(aClassDescription);
-}
-
-NS_IMETHODIMP
-nsDOMClassInfo::GetClassID(nsCID **aClassID)
-{
-  *aClassID = nullptr;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsDOMClassInfo::GetClassIDNoAlloc(nsCID *aClassID)
-{
-  return NS_ERROR_NOT_AVAILABLE;
-}
-
-NS_IMETHODIMP
-nsDOMClassInfo::GetFlags(uint32_t *aFlags)
-{
-  *aFlags = DOMCLASSINFO_STANDARD_FLAGS;
-
-  return NS_OK;
-}
-
-// nsIXPCScriptable
-
-NS_IMETHODIMP
-nsDOMClassInfo::GetClassName(nsACString& aClassName)
-{
-  aClassName.Assign(mData->mClass.name);
-  return NS_OK;
-}
-
-// virtual
-uint32_t
-nsDOMClassInfo::GetScriptableFlags()
-{
-  return mData->mScriptableFlags;
-}
-
-// virtual
-const js::Class*
-nsDOMClassInfo::GetClass()
-{
-    return &mData->mClass;
-}
-
-// virtual
-const JSClass*
-nsDOMClassInfo::GetJSClass()
-{
-    return Jsvalify(&mData->mClass);
-}
-
-NS_IMETHODIMP
-nsDOMClassInfo::PreCreate(nsISupports *nativeObj, JSContext *cx,
-                          JSObject *globalObj, JSObject **parentObj)
-{
-  *parentObj = globalObj;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsDOMClassInfo::Enumerate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
-                          JSObject *obj, bool *_retval)
-{
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsDOMClassInfo::NewEnumerate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
-                             JSObject *obj, JS::AutoIdVector &properties,
-                             bool *_retval)
-{
-  NS_WARNING("nsDOMClassInfo::NewEnumerate Don't call me!");
-
-  return NS_ERROR_UNEXPECTED;
-}
-
-NS_IMETHODIMP
-nsDOMClassInfo::Resolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
-                        JSObject *aObj, jsid aId, bool *resolvedp, bool *_retval)
-{
-  JS::Rooted<JSObject*> obj(cx, aObj);
-  JS::Rooted<jsid> id(cx, aId);
-
-  if (id != sConstructor_id) {
-    *resolvedp = false;
-    return NS_OK;
-  }
-
-  JS::Rooted<JSObject*> global(cx, ::JS_GetGlobalForObject(cx, obj));
-
-  JS::Rooted<JS::PropertyDescriptor> desc(cx);
-  if (!JS_GetPropertyDescriptor(cx, global, mData->mClass.name, &desc)) {
-    return NS_ERROR_UNEXPECTED;
-  }
-
-  if (desc.object() && !desc.hasGetterOrSetter() && desc.value().isObject()) {
-    // If val is not an (non-null) object there either is no
-    // constructor for this class, or someone messed with
-    // window.classname, just fall through and let the JS engine
-    // return the Object constructor.
-    if (!::JS_DefinePropertyById(cx, obj, id, desc.value(),
-                                 JSPROP_ENUMERATE)) {
-      return NS_ERROR_UNEXPECTED;
-    }
-
-    *resolvedp = true;
-  }
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsDOMClassInfo::Finalize(nsIXPConnectWrappedNative *wrapper, JSFreeOp *fop,
-                         JSObject *obj)
-{
-  NS_WARNING("nsDOMClassInfo::Finalize Don't call me!");
-
-  return NS_ERROR_UNEXPECTED;
-}
-
-NS_IMETHODIMP
-nsDOMClassInfo::Call(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
-                     JSObject *obj, const JS::CallArgs &args, bool *_retval)
-{
-  NS_WARNING("nsDOMClassInfo::Call Don't call me!");
-
-  return NS_ERROR_UNEXPECTED;
-}
-
-NS_IMETHODIMP
-nsDOMClassInfo::Construct(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
-                          JSObject *obj, const JS::CallArgs &args,
-                          bool *_retval)
-{
-  NS_WARNING("nsDOMClassInfo::Construct Don't call me!");
-
-  return NS_ERROR_UNEXPECTED;
-}
-
-NS_IMETHODIMP
-nsDOMClassInfo::HasInstance(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
-                            JSObject *obj, JS::Handle<JS::Value> val, bool *bp,
-                            bool *_retval)
-{
-  NS_WARNING("nsDOMClassInfo::HasInstance Don't call me!");
-
-  return NS_ERROR_UNEXPECTED;
-}
-
-NS_IMETHODIMP
-nsDOMClassInfo::PostCreatePrototype(JSContext * cx, JSObject * aProto)
-{
-  // Return NS_OK for now because we can temporarily get hit when
-  // people look up "DOMConstructor".
-  return NS_OK;
-}
-
 // static
 void
 nsDOMClassInfo::ShutDown()
 {
   sConstructor_id     = JSID_VOID;
   sWrappedJSObject_id = JSID_VOID;
 
   NS_IF_RELEASE(sXPConnect);
--- a/dom/base/nsDOMClassInfo.h
+++ b/dom/base/nsDOMClassInfo.h
@@ -18,91 +18,27 @@
 #ifdef XP_WIN
 #undef GetClassName
 #endif
 
 struct nsGlobalNameStruct;
 class nsGlobalWindowInner;
 class nsGlobalWindowOuter;
 
-struct nsDOMClassInfoData;
-
-typedef nsIClassInfo* (*nsDOMClassInfoConstructorFnc)
-  (nsDOMClassInfoData* aData);
-
-typedef nsresult (*nsDOMConstructorFunc)(nsISupports** aNewObject);
-
-struct nsDOMClassInfoData
-{
-  // The ASCII name is available as mClass.name.
-  const char16_t *mNameUTF16;
-  const js::ClassOps mClassOps;
-  const js::Class mClass;
-  nsDOMClassInfoConstructorFnc mConstructorFptr;
-
-  nsIClassInfo *mCachedClassInfo;
-  const nsIID *mProtoChainInterface;
-  const nsIID **mInterfaces;
-  uint32_t mScriptableFlags : 31; // flags must not use more than 31 bits!
-  uint32_t mHasClassInterface : 1;
-  bool mDisabled : 1;
-#ifdef DEBUG
-  uint32_t mDebugID;
-#endif
-};
-
 class nsWindowSH;
 
-class nsDOMClassInfo : public nsXPCClassInfo
+class nsDOMClassInfo
 {
   friend class nsWindowSH;
 
-protected:
-  virtual ~nsDOMClassInfo() {};
-
 public:
-  explicit nsDOMClassInfo(nsDOMClassInfoData* aData);
-
-  NS_DECL_NSIXPCSCRIPTABLE
-
-  NS_DECL_ISUPPORTS
-
-  NS_DECL_NSICLASSINFO
-
   static nsresult Init();
   static void ShutDown();
 
-  static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
-  {
-    return new nsDOMClassInfo(aData);
-  }
-
-  /*
-   * The following two functions exist because of the way that Xray wrappers
-   * work. In order to allow scriptable helpers to define non-IDL defined but
-   * still "safe" properties for Xray wrappers, we call into the scriptable
-   * helper with |obj| being the wrapper.
-   *
-   * Ideally, that would be the end of the story, however due to complications
-   * dealing with document.domain, it's possible to end up in a scriptable
-   * helper with a wrapper, even though we should be treating the lookup as a
-   * transparent one.
-   *
-   * Note: So ObjectIsNativeWrapper(cx, obj) check usually means "through xray
-   * wrapper this part is not visible".
-   */
-  static bool ObjectIsNativeWrapper(JSContext* cx, JSObject* obj);
-
 protected:
-  const nsDOMClassInfoData* mData;
-
-  virtual void PreserveWrapper(nsISupports *aNative) override
-  {
-  }
-
   static nsIXPConnect *sXPConnect;
 
   // nsIXPCScriptable code
   static nsresult DefineStaticJSVals();
 
   static bool sIsInitialized;
 
 public: