Bug 1251655 - Remove support for JavaScript-global-constructor-prototype-alias. r=bz.
authorPeter Van der Beken <peterv@propagandism.org>
Sat, 13 Feb 2016 14:59:46 +0100
changeset 285927 d8bb98d26a6a8fb44ea6004f2f1dbe775ed085c8
parent 285926 f73aa13cfa3ec6f38be79a2a39ccced6a0697974
child 285928 9ed6e0039901b943c48f7e9eac6d61d28a923980
push id30036
push usercbook@mozilla.com
push dateMon, 29 Feb 2016 10:35:59 +0000
treeherdermozilla-central@9da51cb4974e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1251655
milestone47.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 1251655 - Remove support for JavaScript-global-constructor-prototype-alias. r=bz.
dom/base/nsDOMClassInfo.cpp
dom/base/nsIScriptNameSpaceManager.h
dom/base/nsScriptNameSpaceManager.cpp
dom/base/nsScriptNameSpaceManager.h
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -1199,18 +1199,16 @@ BaseStubConstructor(nsIWeakReference* aW
   MOZ_ASSERT(cx == nsContentUtils::GetCurrentJSContext());
 
   nsresult rv;
   nsCOMPtr<nsISupports> native;
   if (name_struct->mType == nsGlobalNameStruct::eTypeClassConstructor) {
     rv = NS_ERROR_NOT_AVAILABLE;
   } else if (name_struct->mType == nsGlobalNameStruct::eTypeExternalConstructor) {
     native = do_CreateInstance(name_struct->mCID, &rv);
-  } else if (name_struct->mType == nsGlobalNameStruct::eTypeExternalConstructorAlias) {
-    native = do_CreateInstance(name_struct->mAlias->mCID, &rv);
   } else {
     native = do_CreateInstance(*name_struct->mData->mConstructorCID, &rv);
   }
   if (NS_FAILED(rv)) {
     NS_ERROR("Failed to create the object");
     return rv;
   }
 
@@ -1347,18 +1345,17 @@ private:
   }
   static bool IsConstructable(const nsGlobalNameStruct *aNameStruct)
   {
     return
       (aNameStruct->mType == nsGlobalNameStruct::eTypeClassConstructor &&
        IsConstructable(&sClassInfoData[aNameStruct->mDOMClassInfoID])) ||
       (aNameStruct->mType == nsGlobalNameStruct::eTypeExternalClassInfo &&
        IsConstructable(aNameStruct->mData)) ||
-      aNameStruct->mType == nsGlobalNameStruct::eTypeExternalConstructor ||
-      aNameStruct->mType == nsGlobalNameStruct::eTypeExternalConstructorAlias;
+      aNameStruct->mType == nsGlobalNameStruct::eTypeExternalConstructor;
   }
 
   const char16_t*   mClassName;
   const bool mConstructable;
   nsWeakPtr          mWeakOwner;
 };
 
 //static
@@ -1509,74 +1506,45 @@ nsDOMConstructor::HasInstance(nsIXPConne
         break;
       }
     }
 
     return NS_OK;
   }
 
   if (name_struct->mType != nsGlobalNameStruct::eTypeClassConstructor &&
-      name_struct->mType != nsGlobalNameStruct::eTypeExternalClassInfo &&
-      name_struct->mType != nsGlobalNameStruct::eTypeExternalConstructorAlias) {
+      name_struct->mType != nsGlobalNameStruct::eTypeExternalClassInfo) {
     // Doesn't have DOM interfaces.
     return NS_OK;
   }
 
   const nsGlobalNameStruct *class_name_struct = GetNameStruct();
   NS_ENSURE_TRUE(class_name_struct, NS_ERROR_FAILURE);
 
   if (name_struct == class_name_struct) {
     *bp = true;
 
     return NS_OK;
   }
 
-  nsScriptNameSpaceManager *nameSpaceManager = GetNameSpaceManager();
-  NS_ASSERTION(nameSpaceManager, "Can't get namespace manager?");
-
   const nsIID *class_iid;
   if (class_name_struct->mType == nsGlobalNameStruct::eTypeInterface ||
       class_name_struct->mType == nsGlobalNameStruct::eTypeClassProto) {
     class_iid = &class_name_struct->mIID;
   } else if (class_name_struct->mType == nsGlobalNameStruct::eTypeClassConstructor) {
     class_iid =
       sClassInfoData[class_name_struct->mDOMClassInfoID].mProtoChainInterface;
   } else if (class_name_struct->mType == nsGlobalNameStruct::eTypeExternalClassInfo) {
     class_iid = class_name_struct->mData->mProtoChainInterface;
-  } else if (class_name_struct->mType == nsGlobalNameStruct::eTypeExternalConstructorAlias) {
-    const nsGlobalNameStruct* alias_struct =
-      nameSpaceManager->GetConstructorProto(class_name_struct);
-    if (!alias_struct) {
-      NS_ERROR("Couldn't get constructor prototype.");
-      return NS_ERROR_UNEXPECTED;
-    }
-
-    if (alias_struct->mType == nsGlobalNameStruct::eTypeClassConstructor) {
-      class_iid =
-        sClassInfoData[alias_struct->mDOMClassInfoID].mProtoChainInterface;
-    } else if (alias_struct->mType == nsGlobalNameStruct::eTypeExternalClassInfo) {
-      class_iid = alias_struct->mData->mProtoChainInterface;
-    } else {
-      NS_ERROR("Expected eTypeClassConstructor or eTypeExternalClassInfo.");
-      return NS_ERROR_UNEXPECTED;
-    }
   } else {
     *bp = false;
 
     return NS_OK;
   }
 
-  if (name_struct->mType == nsGlobalNameStruct::eTypeExternalConstructorAlias) {
-    name_struct = nameSpaceManager->GetConstructorProto(name_struct);
-    if (!name_struct) {
-      NS_ERROR("Couldn't get constructor prototype.");
-      return NS_ERROR_UNEXPECTED;
-    }
-  }
-
   NS_ASSERTION(name_struct->mType == nsGlobalNameStruct::eTypeClassConstructor ||
                name_struct->mType == nsGlobalNameStruct::eTypeExternalClassInfo,
                "The constructor was set up with a struct of the wrong type.");
 
   const nsDOMClassInfoData *ci_data = nullptr;
   if (name_struct->mType == nsGlobalNameStruct::eTypeClassConstructor &&
       name_struct->mDOMClassInfoID >= 0) {
     ci_data = &sClassInfoData[name_struct->mDOMClassInfoID];
@@ -2148,44 +2116,16 @@ nsWindowSH::GlobalResolve(nsGlobalWindow
   if (name_struct->mType == nsGlobalNameStruct::eTypeClassProto) {
     // We don't have a XPConnect prototype object, let ResolvePrototype create
     // one.
     return ResolvePrototype(nsDOMClassInfo::sXPConnect, aWin, cx, obj,
                             class_name, nullptr,
                             name_struct, nameSpaceManager, nullptr, desc);
   }
 
-  if (name_struct->mType == nsGlobalNameStruct::eTypeExternalConstructorAlias) {
-    const nsGlobalNameStruct *alias_struct =
-      nameSpaceManager->GetConstructorProto(name_struct);
-    NS_ENSURE_TRUE(alias_struct, NS_ERROR_UNEXPECTED);
-
-    // We need to use the XPConnect prototype for the DOM class that this
-    // constructor is an alias for (for example for Image we need the prototype
-    // for HTMLImageElement).
-    JS::Rooted<JSObject*> dot_prototype(cx);
-    rv = GetXPCProto(nsDOMClassInfo::sXPConnect, cx, aWin, alias_struct,
-                     &dot_prototype);
-    NS_ENSURE_SUCCESS(rv, rv);
-    MOZ_ASSERT(dot_prototype);
-
-    const nsDOMClassInfoData *ci_data;
-    if (alias_struct->mType == nsGlobalNameStruct::eTypeClassConstructor) {
-      ci_data = &sClassInfoData[alias_struct->mDOMClassInfoID];
-    } else if (alias_struct->mType == nsGlobalNameStruct::eTypeExternalClassInfo) {
-      ci_data = alias_struct->mData;
-    } else {
-      return NS_ERROR_UNEXPECTED;
-    }
-
-    return ResolvePrototype(nsDOMClassInfo::sXPConnect, aWin, cx, obj,
-                            class_name, ci_data,
-                            name_struct, nameSpaceManager, nullptr, desc);
-  }
-
   if (name_struct->mType == nsGlobalNameStruct::eTypeExternalConstructor) {
     RefPtr<nsDOMConstructor> constructor;
     rv = nsDOMConstructor::Create(class_name, nullptr, name_struct,
                                   aWin->AsInner(), getter_AddRefs(constructor));
     NS_ENSURE_SUCCESS(rv, rv);
 
     JS::Rooted<JS::Value> val(cx);
     js::AssertSameCompartment(cx, obj);
--- a/dom/base/nsIScriptNameSpaceManager.h
+++ b/dom/base/nsIScriptNameSpaceManager.h
@@ -5,19 +5,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsIScriptNameSpaceManager_h__
 #define nsIScriptNameSpaceManager_h__
 
 #define JAVASCRIPT_GLOBAL_CONSTRUCTOR_CATEGORY \
   "JavaScript-global-constructor"
 
-#define JAVASCRIPT_GLOBAL_CONSTRUCTOR_PROTO_ALIAS_CATEGORY \
-  "JavaScript-global-constructor-prototype-alias"
-
 #define JAVASCRIPT_GLOBAL_PROPERTY_CATEGORY \
   "JavaScript-global-property"
 
 // a global property that is only accessible to privileged script 
 #define JAVASCRIPT_GLOBAL_PRIVILEGED_PROPERTY_CATEGORY \
   "JavaScript-global-privileged-property"
 
 #define JAVASCRIPT_NAVIGATOR_PROPERTY_CATEGORY \
--- a/dom/base/nsScriptNameSpaceManager.cpp
+++ b/dom/base/nsScriptNameSpaceManager.cpp
@@ -68,19 +68,16 @@ GlobalNameHashClearEntry(PLDHashTable *t
     // the nsDOMClassInfoData structure, if not we do it here.
     if (!ci || e->mGlobalName.mData->u.mExternalConstructorFptr) {
       delete e->mGlobalName.mData;
     }
 
     // Release our pointer to the helper.
     NS_IF_RELEASE(ci);
   }
-  else if (e->mGlobalName.mType == nsGlobalNameStruct::eTypeExternalConstructorAlias) {
-    delete e->mGlobalName.mAlias;
-  }
 
   // This will set e->mGlobalName.mType to
   // nsGlobalNameStruct::eTypeNotInitialized
   memset(&e->mGlobalName, 0, sizeof(nsGlobalNameStruct));
 }
 
 static void
 GlobalNameHashInitEntry(PLDHashEntryHdr *entry, const void *key)
@@ -146,31 +143,16 @@ nsScriptNameSpaceManager::AddToHash(PLDH
 
 void
 nsScriptNameSpaceManager::RemoveFromHash(PLDHashTable *aTable,
                                          const nsAString *aKey)
 {
   aTable->Remove(aKey);
 }
 
-nsGlobalNameStruct*
-nsScriptNameSpaceManager::GetConstructorProto(const nsGlobalNameStruct* aStruct)
-{
-  NS_ASSERTION(aStruct->mType == nsGlobalNameStruct::eTypeExternalConstructorAlias,
-               "This function only works on constructor aliases!");
-  if (!aStruct->mAlias->mProto) {
-    auto proto = static_cast<GlobalNameMapEntry*>
-                            (mGlobalNames.Search(&aStruct->mAlias->mProtoName));
-    if (proto) {
-      aStruct->mAlias->mProto = &proto->mGlobalName;
-    }
-  }
-  return aStruct->mAlias->mProto;
-}
-
 nsresult
 nsScriptNameSpaceManager::FillHash(nsICategoryManager *aCategoryManager,
                                    const char *aCategory)
 {
   nsCOMPtr<nsISimpleEnumerator> e;
   nsresult rv = aCategoryManager->EnumerateCategory(aCategory,
                                                     getter_AddRefs(e));
   NS_ENSURE_SUCCESS(rv, rv);
@@ -586,41 +568,16 @@ nsScriptNameSpaceManager::OperateCategor
     return NS_OK;
   }
 
   // Copy CID onto the stack, so we can free it right away and avoid having
   // to add cleanup code at every exit point from this function.
   nsCID cid = *cidPtr;
   free(cidPtr);
 
-  if (type == nsGlobalNameStruct::eTypeExternalConstructor) {
-    nsXPIDLCString constructorProto;
-    rv = aCategoryManager->GetCategoryEntry(JAVASCRIPT_GLOBAL_CONSTRUCTOR_PROTO_ALIAS_CATEGORY,
-                                            categoryEntry.get(),
-                                            getter_Copies(constructorProto));
-    if (NS_SUCCEEDED(rv)) {
-      nsGlobalNameStruct *s = AddToHash(&mGlobalNames, categoryEntry.get());
-      NS_ENSURE_TRUE(s, NS_ERROR_OUT_OF_MEMORY);
-
-      if (s->mType == nsGlobalNameStruct::eTypeNotInitialized ||
-          s->mType == nsGlobalNameStruct::eTypeNewDOMBinding) {
-        s->mAlias = new nsGlobalNameStruct::ConstructorAlias;
-        s->mType = nsGlobalNameStruct::eTypeExternalConstructorAlias;
-        s->mChromeOnly = false;
-        s->mAlias->mCID = cid;
-        AppendASCIItoUTF16(constructorProto, s->mAlias->mProtoName);
-        s->mAlias->mProto = nullptr;
-      } else {
-        NS_WARNING("Global script name not overwritten!");
-      }
-
-      return NS_OK;
-    }
-  }
-
   nsGlobalNameStruct *s = AddToHash(table, categoryEntry.get());
   NS_ENSURE_TRUE(s, NS_ERROR_OUT_OF_MEMORY);
 
   if (s->mType == nsGlobalNameStruct::eTypeNotInitialized ||
       s->mType == nsGlobalNameStruct::eTypeNewDOMBinding) {
     s->mType = type;
     s->mCID = cid;
     s->mChromeOnly =
--- a/dom/base/nsScriptNameSpaceManager.h
+++ b/dom/base/nsScriptNameSpaceManager.h
@@ -31,48 +31,39 @@
 #include "nsDOMClassInfo.h"
 #include "nsIObserver.h"
 #include "nsWeakReference.h"
 #include "xpcpublic.h"
 
 
 struct nsGlobalNameStruct
 {
-  struct ConstructorAlias
-  {
-    nsCID mCID;
-    nsString mProtoName;
-    nsGlobalNameStruct* mProto;    
-  };
-
   enum nametype {
     eTypeNotInitialized,
     eTypeNewDOMBinding,
     eTypeInterface,
     eTypeProperty,
     eTypeNavigatorProperty,
     eTypeExternalConstructor,
     eTypeClassConstructor,
     eTypeClassProto,
     eTypeExternalClassInfoCreator,
     eTypeExternalClassInfo,
-    eTypeExternalConstructorAlias
   } mType;
 
   // mChromeOnly is only used for structs that define non-WebIDL things
   // (possibly in addition to WebIDL ones).  In particular, it's not even
   // initialized for eTypeNewDOMBinding structs.
   bool mChromeOnly : 1;
   bool mAllowXBL : 1;
 
   union {
     int32_t mDOMClassInfoID; // eTypeClassConstructor
     nsIID mIID; // eTypeInterface, eTypeClassProto
     nsExternalDOMClassInfoData* mData; // eTypeExternalClassInfo
-    ConstructorAlias* mAlias; // eTypeExternalConstructorAlias
     nsCID mCID; // All other types except eTypeNewDOMBinding
   };
 
   // For new style DOM bindings.
   union {
     mozilla::dom::DefineInterface mDefineDOMInterface; // for window
     mozilla::dom::ConstructNavigatorProperty mConstructNavigatorProperty; // for navigator
   };
@@ -147,18 +138,16 @@ public:
   nsresult RegisterDOMCIData(const char *aName,
                              nsDOMClassInfoExternalConstructorFnc aConstructorFptr,
                              const nsIID *aProtoChainInterface,
                              const nsIID **aInterfaces,
                              uint32_t aScriptableFlags,
                              bool aHasClassInterface,
                              const nsCID *aConstructorCID);
 
-  nsGlobalNameStruct* GetConstructorProto(const nsGlobalNameStruct* aStruct);
-
   void RegisterDefineDOMInterface(const nsAFlatString& aName,
     mozilla::dom::DefineInterface aDefineDOMInterface,
     mozilla::dom::ConstructorEnabled* aConstructorEnabled);
   template<size_t N>
   void RegisterDefineDOMInterface(const char16_t (&aKey)[N],
     mozilla::dom::DefineInterface aDefineDOMInterface,
     mozilla::dom::ConstructorEnabled* aConstructorEnabled)
   {