mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-02 22:37:50 +00:00
Back out changeset e7e44c2d6d72 (bug 860027) because of Ts and MaxHeap regressions
This commit is contained in:
parent
40b69bb3d8
commit
5a89eb1225
@ -34,7 +34,6 @@
|
||||
#include "nsJSEnvironment.h"
|
||||
#include "nsXMLHttpRequest.h"
|
||||
#include "mozilla/Telemetry.h"
|
||||
#include "mozilla/XPTInterfaceInfoManager.h"
|
||||
#include "nsDOMClassInfoID.h"
|
||||
|
||||
using namespace mozilla;
|
||||
@ -121,7 +120,7 @@ public:
|
||||
virtual ~nsXPCComponents_Interfaces();
|
||||
|
||||
private:
|
||||
nsCOMArray<nsIInterfaceInfo> mInterfaces;
|
||||
nsCOMPtr<nsIInterfaceInfoManager> mManager;
|
||||
};
|
||||
|
||||
/* void getInterfaces (out uint32_t count, [array, size_is (count), retval]
|
||||
@ -216,9 +215,9 @@ nsXPCComponents_Interfaces::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
nsXPCComponents_Interfaces::nsXPCComponents_Interfaces()
|
||||
nsXPCComponents_Interfaces::nsXPCComponents_Interfaces() :
|
||||
mManager(do_GetService(NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID))
|
||||
{
|
||||
XPTInterfaceInfoManager::GetSingleton()->GetScriptableInterfaces(mInterfaces);
|
||||
}
|
||||
|
||||
nsXPCComponents_Interfaces::~nsXPCComponents_Interfaces()
|
||||
@ -255,36 +254,64 @@ nsXPCComponents_Interfaces::NewEnumerate(nsIXPConnectWrappedNative *wrapper,
|
||||
uint32_t enum_op, jsval * statep,
|
||||
jsid * idp, bool *_retval)
|
||||
{
|
||||
nsIEnumerator* e;
|
||||
|
||||
switch (enum_op) {
|
||||
case JSENUMERATE_INIT:
|
||||
case JSENUMERATE_INIT_ALL:
|
||||
{
|
||||
*statep = JSVAL_ZERO;
|
||||
if (!mManager ||
|
||||
NS_FAILED(mManager->EnumerateInterfaces(&e)) || !e ||
|
||||
NS_FAILED(e->First()))
|
||||
|
||||
{
|
||||
*statep = JSVAL_NULL;
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
*statep = PRIVATE_TO_JSVAL(e);
|
||||
if (idp)
|
||||
*idp = INT_TO_JSID(mInterfaces.Length());
|
||||
*idp = INT_TO_JSID(0); // indicate that we don't know the count
|
||||
return NS_OK;
|
||||
}
|
||||
case JSENUMERATE_NEXT:
|
||||
{
|
||||
uint32_t idx = JSVAL_TO_INT(*statep);
|
||||
nsIInterfaceInfo* interface = mInterfaces.SafeElementAt(idx);
|
||||
*statep = UINT_TO_JSVAL(idx + 1);
|
||||
nsCOMPtr<nsISupports> isup;
|
||||
|
||||
if (interface) {
|
||||
JSString* idstr;
|
||||
const char* name;
|
||||
e = (nsIEnumerator*) JSVAL_TO_PRIVATE(*statep);
|
||||
|
||||
if (NS_SUCCEEDED(interface->GetNameShared(&name)) && name &&
|
||||
nullptr != (idstr = JS_NewStringCopyZ(cx, name)) &&
|
||||
JS_ValueToId(cx, STRING_TO_JSVAL(idstr), idp)) {
|
||||
return NS_OK;
|
||||
while (1) {
|
||||
if (static_cast<nsresult>(NS_ENUMERATOR_FALSE) == e->IsDone() &&
|
||||
NS_SUCCEEDED(e->CurrentItem(getter_AddRefs(isup))) && isup) {
|
||||
e->Next();
|
||||
nsCOMPtr<nsIInterfaceInfo> iface(do_QueryInterface(isup));
|
||||
if (iface) {
|
||||
JSString* idstr;
|
||||
const char* name;
|
||||
bool scriptable;
|
||||
|
||||
if (NS_SUCCEEDED(iface->IsScriptable(&scriptable)) &&
|
||||
!scriptable) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(iface->GetNameShared(&name)) && name &&
|
||||
nullptr != (idstr = JS_NewStringCopyZ(cx, name)) &&
|
||||
JS_ValueToId(cx, STRING_TO_JSVAL(idstr), idp)) {
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
// else...
|
||||
break;
|
||||
}
|
||||
// fall through
|
||||
// FALL THROUGH
|
||||
}
|
||||
|
||||
case JSENUMERATE_DESTROY:
|
||||
default:
|
||||
e = (nsIEnumerator*) JSVAL_TO_PRIVATE(*statep);
|
||||
NS_IF_RELEASE(e);
|
||||
*statep = JSVAL_NULL;
|
||||
return NS_OK;
|
||||
}
|
||||
@ -300,7 +327,7 @@ nsXPCComponents_Interfaces::NewResolve(nsIXPConnectWrappedNative *wrapper,
|
||||
RootedObject obj(cx, objArg);
|
||||
RootedId id(cx, idArg);
|
||||
|
||||
if (!JSID_IS_STRING(id))
|
||||
if (!mManager || !JSID_IS_STRING(id))
|
||||
return NS_OK;
|
||||
|
||||
JSAutoByteString name;
|
||||
@ -309,8 +336,7 @@ nsXPCComponents_Interfaces::NewResolve(nsIXPConnectWrappedNative *wrapper,
|
||||
// we only allow interfaces by name here
|
||||
if (name.encodeLatin1(cx, str) && name.ptr()[0] != '{') {
|
||||
nsCOMPtr<nsIInterfaceInfo> info;
|
||||
XPTInterfaceInfoManager::GetSingleton()->
|
||||
GetInfoForName(name.ptr(), getter_AddRefs(info));
|
||||
mManager->GetInfoForName(name.ptr(), getter_AddRefs(info));
|
||||
if (!info)
|
||||
return NS_OK;
|
||||
|
||||
@ -402,7 +428,7 @@ public:
|
||||
virtual ~nsXPCComponents_InterfacesByID();
|
||||
|
||||
private:
|
||||
nsCOMArray<nsIInterfaceInfo> mInterfaces;
|
||||
nsCOMPtr<nsIInterfaceInfoManager> mManager;
|
||||
};
|
||||
|
||||
/***************************************************************************/
|
||||
@ -498,9 +524,9 @@ nsXPCComponents_InterfacesByID::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
nsXPCComponents_InterfacesByID::nsXPCComponents_InterfacesByID()
|
||||
nsXPCComponents_InterfacesByID::nsXPCComponents_InterfacesByID() :
|
||||
mManager(do_GetService(NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID))
|
||||
{
|
||||
XPTInterfaceInfoManager::GetSingleton()->GetScriptableInterfaces(mInterfaces);
|
||||
}
|
||||
|
||||
nsXPCComponents_InterfacesByID::~nsXPCComponents_InterfacesByID()
|
||||
@ -535,38 +561,68 @@ nsXPCComponents_InterfacesByID::NewEnumerate(nsIXPConnectWrappedNative *wrapper,
|
||||
uint32_t enum_op, jsval * statep,
|
||||
jsid * idp, bool *_retval)
|
||||
{
|
||||
nsIEnumerator* e;
|
||||
|
||||
switch (enum_op) {
|
||||
case JSENUMERATE_INIT:
|
||||
case JSENUMERATE_INIT_ALL:
|
||||
{
|
||||
*statep = JSVAL_ZERO;
|
||||
if (!mManager ||
|
||||
NS_FAILED(mManager->EnumerateInterfaces(&e)) || !e ||
|
||||
NS_FAILED(e->First()))
|
||||
|
||||
{
|
||||
*statep = JSVAL_NULL;
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
*statep = PRIVATE_TO_JSVAL(e);
|
||||
if (idp)
|
||||
*idp = INT_TO_JSID(mInterfaces.Length());
|
||||
*idp = INT_TO_JSID(0); // indicate that we don't know the count
|
||||
return NS_OK;
|
||||
}
|
||||
case JSENUMERATE_NEXT:
|
||||
{
|
||||
uint32_t idx = JSVAL_TO_INT(*statep);
|
||||
nsIInterfaceInfo* interface = mInterfaces.SafeElementAt(idx);
|
||||
*statep = UINT_TO_JSVAL(idx + 1);
|
||||
if (interface) {
|
||||
nsIID const *iid;
|
||||
char idstr[NSID_LENGTH];
|
||||
JSString* jsstr;
|
||||
nsCOMPtr<nsISupports> isup;
|
||||
|
||||
if (NS_SUCCEEDED(interface->GetIIDShared(&iid))) {
|
||||
iid->ToProvidedString(idstr);
|
||||
jsstr = JS_NewStringCopyZ(cx, idstr);
|
||||
if (jsstr && JS_ValueToId(cx, STRING_TO_JSVAL(jsstr), idp)) {
|
||||
return NS_OK;
|
||||
e = (nsIEnumerator*) JSVAL_TO_PRIVATE(*statep);
|
||||
|
||||
while (1) {
|
||||
if (static_cast<nsresult>(NS_ENUMERATOR_FALSE) == e->IsDone() &&
|
||||
NS_SUCCEEDED(e->CurrentItem(getter_AddRefs(isup))) && isup) {
|
||||
e->Next();
|
||||
nsCOMPtr<nsIInterfaceInfo> iface(do_QueryInterface(isup));
|
||||
if (iface) {
|
||||
nsIID const *iid;
|
||||
char idstr[NSID_LENGTH];
|
||||
JSString* jsstr;
|
||||
bool scriptable;
|
||||
|
||||
if (NS_SUCCEEDED(iface->IsScriptable(&scriptable)) &&
|
||||
!scriptable) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(iface->GetIIDShared(&iid))) {
|
||||
iid->ToProvidedString(idstr);
|
||||
jsstr = JS_NewStringCopyZ(cx, idstr);
|
||||
if (jsstr &&
|
||||
JS_ValueToId(cx, STRING_TO_JSVAL(jsstr), idp)) {
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// else...
|
||||
break;
|
||||
}
|
||||
// FALL THROUGH
|
||||
}
|
||||
|
||||
case JSENUMERATE_DESTROY:
|
||||
default:
|
||||
e = (nsIEnumerator*) JSVAL_TO_PRIVATE(*statep);
|
||||
NS_IF_RELEASE(e);
|
||||
*statep = JSVAL_NULL;
|
||||
return NS_OK;
|
||||
}
|
||||
@ -581,6 +637,10 @@ nsXPCComponents_InterfacesByID::NewResolve(nsIXPConnectWrappedNative *wrapper,
|
||||
{
|
||||
RootedObject obj(cx, objArg);
|
||||
RootedId id(cx, idArg);
|
||||
|
||||
if (!mManager || !JSID_IS_STRING(id))
|
||||
return NS_OK;
|
||||
|
||||
RootedString str(cx, JSID_TO_STRING(id));
|
||||
if (38 != JS_GetStringLength(str))
|
||||
return NS_OK;
|
||||
@ -591,8 +651,7 @@ nsXPCComponents_InterfacesByID::NewResolve(nsIXPConnectWrappedNative *wrapper,
|
||||
return NS_OK;
|
||||
|
||||
nsCOMPtr<nsIInterfaceInfo> info;
|
||||
XPTInterfaceInfoManager::GetSingleton()->
|
||||
GetInfoForIID(&iid, getter_AddRefs(info));
|
||||
mManager->GetInfoForIID(&iid, getter_AddRefs(info));
|
||||
if (!info)
|
||||
return NS_OK;
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include "nsISimpleEnumerator.idl"
|
||||
|
||||
/* this is NOT intended to be scriptable */
|
||||
[uuid(1d53d8d9-1d92-428f-b5cc-198b55e897d7)]
|
||||
[uuid(8B161900-BE2B-11d2-9831-006008962422)]
|
||||
interface nsIInterfaceInfoManager : nsISupports
|
||||
{
|
||||
nsIInterfaceInfo getInfoForIID(in nsIIDPtr iid);
|
||||
@ -21,6 +21,8 @@ interface nsIInterfaceInfoManager : nsISupports
|
||||
nsIIDPtr getIIDForName(in string name);
|
||||
string getNameForIID(in nsIIDPtr iid);
|
||||
|
||||
nsIEnumerator enumerateInterfaces();
|
||||
|
||||
void autoRegisterInterfaces();
|
||||
|
||||
nsIEnumerator enumerateInterfacesWhoseNamesStartWith(in string prefix);
|
||||
|
@ -268,31 +268,32 @@ XPTInterfaceInfoManager::GetNameForIID(const nsIID * iid, char **_retval)
|
||||
static PLDHashOperator
|
||||
xpti_ArrayAppender(const char* name, xptiInterfaceEntry* entry, void* arg)
|
||||
{
|
||||
nsCOMArray<nsIInterfaceInfo>* array = static_cast<nsCOMArray<nsIInterfaceInfo>*>(arg);
|
||||
nsISupportsArray* array = (nsISupportsArray*) arg;
|
||||
|
||||
nsCOMPtr<nsIInterfaceInfo> ii;
|
||||
if (NS_SUCCEEDED(EntryToInfo(entry, getter_AddRefs(ii)))) {
|
||||
bool scriptable = false;
|
||||
ii->IsScriptable(&scriptable);
|
||||
if (scriptable) {
|
||||
if (NS_SUCCEEDED(EntryToInfo(entry, getter_AddRefs(ii))))
|
||||
array->AppendElement(ii);
|
||||
}
|
||||
}
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
/* nsIEnumerator enumerateInterfaces (); */
|
||||
void
|
||||
XPTInterfaceInfoManager::GetScriptableInterfaces(nsCOMArray<nsIInterfaceInfo>& aInterfaces)
|
||||
NS_IMETHODIMP
|
||||
XPTInterfaceInfoManager::EnumerateInterfaces(nsIEnumerator **_retval)
|
||||
{
|
||||
// I didn't want to incur the size overhead of using nsHashtable just to
|
||||
// make building an enumerator easier. So, this code makes a snapshot of
|
||||
// the table using an nsISupportsArray and builds an enumerator for that.
|
||||
// We can afford this transient cost.
|
||||
|
||||
nsCOMPtr<nsISupportsArray> array;
|
||||
NS_NewISupportsArray(getter_AddRefs(array));
|
||||
if (!array)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
ReentrantMonitorAutoEnter monitor(mWorkingSet.mTableReentrantMonitor);
|
||||
aInterfaces.SetCapacity(mWorkingSet.mNameTable.Count());
|
||||
mWorkingSet.mNameTable.EnumerateRead(xpti_ArrayAppender, &aInterfaces);
|
||||
mWorkingSet.mNameTable.EnumerateRead(xpti_ArrayAppender, array);
|
||||
|
||||
return array->Enumerate(_retval);
|
||||
}
|
||||
|
||||
struct ArrayAndPrefix
|
||||
|
Loading…
x
Reference in New Issue
Block a user