Bug 688012 - Move the open-brace for if, else, for, while, and switch to the same line as the keyword or condition. r=mrbkap

xpcfix -bpc `find | grep -P "cpp$|h$" | perl -pe 's/\n/ /'`

This is a huge, repetitive patch, and I confess having only skimmed a lot of it. I'm reasonably confident in the tool here though.

Updated to fix 'else' as well.
This commit is contained in:
Bobby Holley 2011-10-14 10:52:48 -07:00
parent efc8a150ec
commit dfadea33ce
33 changed files with 1337 additions and 2674 deletions

View File

@ -232,8 +232,7 @@ mozJSSubScriptLoader::LoadSubScript (const PRUnichar * aURL
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
/* set mJSPrincipals if it's not here already */
if (!mSystemPrincipal)
{
if (!mSystemPrincipal) {
nsCOMPtr<nsIScriptSecurityManager> secman =
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID);
if (!secman)
@ -250,20 +249,17 @@ mozJSSubScriptLoader::LoadSubScript (const PRUnichar * aURL
JSObject *target_obj = nsnull;
jschar *charset = nsnull;
ok = JS_ConvertArguments (cx, argc, argv, "S / o W", &url, &target_obj, &charset);
if (!ok)
{
if (!ok) {
/* let the exception raised by JS_ConvertArguments show through */
return NS_OK;
}
JSAutoByteString urlbytes(cx, url);
if (!urlbytes)
{
if (!urlbytes) {
return NS_OK;
}
if (!target_obj)
{
if (!target_obj) {
/* if the user didn't provide an object to eval onto, find the global
* object by walking the parent chain of the calling object */
@ -287,8 +283,7 @@ mozJSSubScriptLoader::LoadSubScript (const PRUnichar * aURL
fprintf (stderr, "Parent chain: %p", target_obj);
#endif
JSObject *maybe_glob = JS_GetParent (cx, target_obj);
while (maybe_glob != nsnull)
{
while (maybe_glob != nsnull) {
#ifdef DEBUG_rginda
fprintf (stderr, ", %p", maybe_glob);
#endif
@ -308,8 +303,7 @@ mozJSSubScriptLoader::LoadSubScript (const PRUnichar * aURL
if (!target_obj)
return NS_ERROR_FAILURE;
if (target_obj != result_obj)
{
if (target_obj != result_obj) {
nsCOMPtr<nsIScriptSecurityManager> secman =
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID);
if (!secman)
@ -345,8 +339,7 @@ mozJSSubScriptLoader::LoadSubScript (const PRUnichar * aURL
script = JS_GetFrameScript(cx, frame);
} while (frame && !script);
if (!script)
{
if (!script) {
// No script means we don't know who's calling, bail.
return NS_ERROR_FAILURE;
@ -378,8 +371,7 @@ mozJSSubScriptLoader::LoadSubScript (const PRUnichar * aURL
return ReportError(cx, LOAD_ERROR_NOSCHEME);
}
if (!scheme.EqualsLiteral("chrome"))
{
if (!scheme.EqualsLiteral("chrome")) {
// This might be a URI to a local file, though!
nsCOMPtr<nsIURI> innerURI = NS_GetInnermostURI(uri);
nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(innerURI);

View File

@ -109,16 +109,14 @@ XPCCallContext::Init(XPCContext::LangType callerLanguage,
XPCJSContextStack* stack = mThreadData->GetJSContextStack();
JSContext* topJSContext;
if (!stack || NS_FAILED(stack->Peek(&topJSContext)))
{
if (!stack || NS_FAILED(stack->Peek(&topJSContext))) {
// If we don't have a stack we're probably in shutdown.
NS_ASSERTION(!stack, "Bad, Peek failed!");
mJSContext = nsnull;
return;
}
if (!mJSContext)
{
if (!mJSContext) {
// This is slightly questionable. If called without an explicit
// JSContext (generally a call to a wrappedJS) we will use the JSContext
// on the top of the JSContext stack - if there is one - *before*
@ -133,10 +131,8 @@ XPCCallContext::Init(XPCContext::LangType callerLanguage,
return;
}
if (topJSContext != mJSContext)
{
if (NS_FAILED(stack->Push(mJSContext)))
{
if (topJSContext != mJSContext) {
if (NS_FAILED(stack->Push(mJSContext))) {
NS_ERROR("bad!");
return;
}
@ -176,14 +172,12 @@ XPCCallContext::Init(XPCContext::LangType callerLanguage,
mState = HAVE_OBJECT;
mTearOff = nsnull;
if (wrapperInitOptions == INIT_SHOULD_LOOKUP_WRAPPER)
{
if (wrapperInitOptions == INIT_SHOULD_LOOKUP_WRAPPER) {
mWrapper = XPCWrappedNative::GetWrappedNativeOfJSObject(mJSContext, obj,
funobj,
&mFlattenedJSObject,
&mTearOff);
if (mWrapper)
{
if (mWrapper) {
DEBUG_CheckWrapperThreadSafety(mWrapper);
mFlattenedJSObject = mWrapper->GetFlatJSObject();
@ -193,8 +187,7 @@ XPCCallContext::Init(XPCContext::LangType callerLanguage,
else
mScriptableInfo = mWrapper->GetScriptableInfo();
}
else
{
else {
NS_ABORT_IF_FALSE(!mFlattenedJSObject || IS_SLIM_WRAPPER(mFlattenedJSObject),
"should have a slim wrapper");
}
@ -216,8 +209,7 @@ XPCCallContext::SetName(jsid name)
mName = name;
if (mTearOff)
{
if (mTearOff) {
mSet = nsnull;
mInterface = mTearOff->GetInterface();
mMember = mInterface->FindMember(name);
@ -225,8 +217,7 @@ XPCCallContext::SetName(jsid name)
if (mMember && !mMember->IsConstant())
mMethodIndex = mMember->GetIndex();
}
else
{
else {
mSet = mWrapper ? mWrapper->GetSet() : nsnull;
if (mSet &&
@ -234,13 +225,11 @@ XPCCallContext::SetName(jsid name)
mWrapper->HasProto() ?
mWrapper->GetProto()->GetSet() :
nsnull,
&mStaticMemberIsLocal))
{
&mStaticMemberIsLocal)) {
if (mMember && !mMember->IsConstant())
mMethodIndex = mMember->GetIndex();
}
else
{
else {
mMember = nsnull;
mInterface = nsnull;
mStaticMemberIsLocal = JS_FALSE;
@ -280,8 +269,7 @@ XPCCallContext::SetArgsAndResultPtr(uintN argc,
{
CHECK_STATE(HAVE_OBJECT);
if (mState < HAVE_NAME)
{
if (mState < HAVE_NAME) {
mSet = nsnull;
mInterface = nsnull;
mMember = nsnull;
@ -306,11 +294,9 @@ XPCCallContext::CanCallNow()
if (mState < HAVE_ARGS)
return NS_ERROR_UNEXPECTED;
if (!mTearOff)
{
if (!mTearOff) {
mTearOff = mWrapper->FindTearOff(*this, mInterface, JS_FALSE, &rv);
if (!mTearOff || mTearOff->GetInterface() != mInterface)
{
if (!mTearOff || mTearOff->GetInterface() != mInterface) {
mTearOff = nsnull;
return NS_FAILED(rv) ? rv : NS_ERROR_UNEXPECTED;
}
@ -343,8 +329,7 @@ XPCCallContext::~XPCCallContext()
bool shouldReleaseXPC = false;
if (mXPCContext)
{
if (mXPCContext) {
mXPCContext->SetCallingLangType(mPrevCallerLanguage);
#ifdef DEBUG
@ -361,12 +346,10 @@ XPCCallContext::~XPCCallContext()
if (mJSContext && mCallerLanguage == NATIVE_CALLER)
JS_EndRequest(mJSContext);
if (mContextPopRequired)
{
if (mContextPopRequired) {
XPCJSContextStack* stack = mThreadData->GetJSContextStack();
NS_ASSERTION(stack, "bad!");
if (stack)
{
if (stack) {
#ifdef DEBUG
JSContext* poppedCX;
nsresult rv = stack->Pop(&poppedCX);
@ -377,10 +360,8 @@ XPCCallContext::~XPCCallContext()
}
}
if (mJSContext)
{
if (mDestroyJSContextInDestructor)
{
if (mJSContext) {
if (mDestroyJSContextInDestructor) {
#ifdef DEBUG_xpc_hacker
printf("!xpc - doing deferred destruction of JSContext @ %p\n",
mJSContext);
@ -395,8 +376,7 @@ XPCCallContext::~XPCCallContext()
}
#ifdef DEBUG
for (PRUint32 i = 0; i < XPCCCX_STRING_CACHE_SIZE; ++i)
{
for (PRUint32 i = 0; i < XPCCCX_STRING_CACHE_SIZE; ++i) {
NS_ASSERTION(!mScratchStrings[i].mInUse, "Uh, string wrapper still in use!");
}
#endif
@ -408,12 +388,10 @@ XPCCallContext::~XPCCallContext()
XPCReadableJSStringWrapper *
XPCCallContext::NewStringWrapper(const PRUnichar *str, PRUint32 len)
{
for (PRUint32 i = 0; i < XPCCCX_STRING_CACHE_SIZE; ++i)
{
for (PRUint32 i = 0; i < XPCCCX_STRING_CACHE_SIZE; ++i) {
StringWrapperEntry& ent = mScratchStrings[i];
if (!ent.mInUse)
{
if (!ent.mInUse) {
ent.mInUse = PR_TRUE;
// Construct the string using placement new.
@ -430,11 +408,9 @@ XPCCallContext::NewStringWrapper(const PRUnichar *str, PRUint32 len)
void
XPCCallContext::DeleteString(nsAString *string)
{
for (PRUint32 i = 0; i < XPCCCX_STRING_CACHE_SIZE; ++i)
{
for (PRUint32 i = 0; i < XPCCCX_STRING_CACHE_SIZE; ++i) {
StringWrapperEntry& ent = mScratchStrings[i];
if (string == ent.mString.addr())
{
if (string == ent.mString.addr()) {
// One of our internal strings is no longer in use, mark
// it as such and destroy the string.

View File

@ -78,8 +78,7 @@ JSValIsInterfaceOfType(JSContext *cx, jsval v, REFNSIID iid)
nsnull != (xpc = nsXPConnect::GetXPConnect()) &&
NS_SUCCEEDED(xpc->GetWrappedNativeOfJSObject(cx, JSVAL_TO_OBJECT(v),
getter_AddRefs(wn))) && wn &&
NS_SUCCEEDED(wn->Native()->QueryInterface(iid, (void**)&iface)) && iface)
{
NS_SUCCEEDED(wn->Native()->QueryInterface(iid, (void**)&iface)) && iface) {
NS_RELEASE(iface);
return JS_TRUE;
}
@ -265,8 +264,7 @@ nsXPCComponents_Interfaces::NewEnumerate(nsIXPConnectWrappedNative *wrapper,
{
nsIEnumerator* e;
switch (enum_op)
{
switch (enum_op) {
case JSENUMERATE_INIT:
case JSENUMERATE_INIT_ALL:
{
@ -290,29 +288,24 @@ nsXPCComponents_Interfaces::NewEnumerate(nsIXPConnectWrappedNative *wrapper,
e = (nsIEnumerator*) JSVAL_TO_PRIVATE(*statep);
while (1)
{
while (1) {
if (NS_ENUMERATOR_FALSE == e->IsDone() &&
NS_SUCCEEDED(e->CurrentItem(getter_AddRefs(isup))) && isup)
{
NS_SUCCEEDED(e->CurrentItem(getter_AddRefs(isup))) && isup) {
e->Next();
nsCOMPtr<nsIInterfaceInfo> iface(do_QueryInterface(isup));
if (iface)
{
if (iface) {
JSString* idstr;
const char* name;
bool scriptable;
if (NS_SUCCEEDED(iface->IsScriptable(&scriptable)) &&
!scriptable)
{
!scriptable) {
continue;
}
if (NS_SUCCEEDED(iface->GetNameShared(&name)) && name &&
nsnull != (idstr = JS_NewStringCopyZ(cx, name)) &&
JS_ValueToId(cx, STRING_TO_JSVAL(idstr), idp))
{
JS_ValueToId(cx, STRING_TO_JSVAL(idstr), idp)) {
return NS_OK;
}
}
@ -343,8 +336,7 @@ nsXPCComponents_Interfaces::NewResolve(nsIXPConnectWrappedNative *wrapper,
if (mManager &&
JSID_IS_STRING(id) &&
name.encode(cx, JSID_TO_STRING(id)) &&
name.ptr()[0] != '{') // we only allow interfaces by name here
{
name.ptr()[0] != '{') { // we only allow interfaces by name here
nsCOMPtr<nsIInterfaceInfo> info;
mManager->GetInfoForName(name.ptr(), getter_AddRefs(info));
if (!info)
@ -353,21 +345,17 @@ nsXPCComponents_Interfaces::NewResolve(nsIXPConnectWrappedNative *wrapper,
nsCOMPtr<nsIJSIID> nsid =
dont_AddRef(static_cast<nsIJSIID*>(nsJSIID::NewID(info)));
if (nsid)
{
if (nsid) {
nsCOMPtr<nsIXPConnect> xpc;
wrapper->GetXPConnect(getter_AddRefs(xpc));
if (xpc)
{
if (xpc) {
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
if (NS_SUCCEEDED(xpc->WrapNative(cx, obj,
static_cast<nsIJSIID*>(nsid),
NS_GET_IID(nsIJSIID),
getter_AddRefs(holder))))
{
getter_AddRefs(holder)))) {
JSObject* idobj;
if (holder && NS_SUCCEEDED(holder->GetJSObject(&idobj)))
{
if (holder && NS_SUCCEEDED(holder->GetJSObject(&idobj))) {
*objp = obj;
*_retval = JS_DefinePropertyById(cx, obj, id,
OBJECT_TO_JSVAL(idobj),
@ -577,8 +565,7 @@ nsXPCComponents_InterfacesByID::NewEnumerate(nsIXPConnectWrappedNative *wrapper,
{
nsIEnumerator* e;
switch (enum_op)
{
switch (enum_op) {
case JSENUMERATE_INIT:
case JSENUMERATE_INIT_ALL:
{
@ -602,33 +589,27 @@ nsXPCComponents_InterfacesByID::NewEnumerate(nsIXPConnectWrappedNative *wrapper,
e = (nsIEnumerator*) JSVAL_TO_PRIVATE(*statep);
while (1)
{
while (1) {
if (NS_ENUMERATOR_FALSE == e->IsDone() &&
NS_SUCCEEDED(e->CurrentItem(getter_AddRefs(isup))) && isup)
{
NS_SUCCEEDED(e->CurrentItem(getter_AddRefs(isup))) && isup) {
e->Next();
nsCOMPtr<nsIInterfaceInfo> iface(do_QueryInterface(isup));
if (iface)
{
if (iface) {
nsIID const *iid;
char idstr[NSID_LENGTH];
JSString* jsstr;
bool scriptable;
if (NS_SUCCEEDED(iface->IsScriptable(&scriptable)) &&
!scriptable)
{
!scriptable) {
continue;
}
if (NS_SUCCEEDED(iface->GetIIDShared(&iid)))
{
if (NS_SUCCEEDED(iface->GetIIDShared(&iid))) {
iid->ToProvidedString(idstr);
jsstr = JS_NewStringCopyZ(cx, idstr);
if (jsstr &&
JS_ValueToId(cx, STRING_TO_JSVAL(jsstr), idp))
{
JS_ValueToId(cx, STRING_TO_JSVAL(jsstr), idp)) {
return NS_OK;
}
}
@ -661,8 +642,7 @@ nsXPCComponents_InterfacesByID::NewResolve(nsIXPConnectWrappedNative *wrapper,
if (mManager &&
JSID_IS_STRING(id) &&
38 == JS_GetStringLength(JSID_TO_STRING(id)) &&
nsnull != (name = JS_GetInternedStringChars(JSID_TO_STRING(id))))
{
nsnull != (name = JS_GetInternedStringChars(JSID_TO_STRING(id)))) {
nsID iid;
if (!iid.Parse(NS_ConvertUTF16toUTF8(name).get()))
return NS_OK;
@ -680,17 +660,14 @@ nsXPCComponents_InterfacesByID::NewResolve(nsIXPConnectWrappedNative *wrapper,
nsCOMPtr<nsIXPConnect> xpc;
wrapper->GetXPConnect(getter_AddRefs(xpc));
if (xpc)
{
if (xpc) {
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
if (NS_SUCCEEDED(xpc->WrapNative(cx, obj,
static_cast<nsIJSIID*>(nsid),
NS_GET_IID(nsIJSIID),
getter_AddRefs(holder))))
{
getter_AddRefs(holder)))) {
JSObject* idobj;
if (holder && NS_SUCCEEDED(holder->GetJSObject(&idobj)))
{
if (holder && NS_SUCCEEDED(holder->GetJSObject(&idobj))) {
*objp = obj;
*_retval =
JS_DefinePropertyById(cx, obj, id,
@ -895,15 +872,13 @@ nsXPCComponents_Classes::NewEnumerate(nsIXPConnectWrappedNative *wrapper,
{
nsISimpleEnumerator* e;
switch (enum_op)
{
switch (enum_op) {
case JSENUMERATE_INIT:
case JSENUMERATE_INIT_ALL:
{
nsCOMPtr<nsIComponentRegistrar> compMgr;
if (NS_FAILED(NS_GetComponentRegistrar(getter_AddRefs(compMgr))) || !compMgr ||
NS_FAILED(compMgr->EnumerateContractIDs(&e)) || !e )
{
NS_FAILED(compMgr->EnumerateContractIDs(&e)) || !e ) {
*statep = JSVAL_NULL;
return NS_ERROR_UNEXPECTED;
}
@ -920,18 +895,14 @@ nsXPCComponents_Classes::NewEnumerate(nsIXPConnectWrappedNative *wrapper,
e = (nsISimpleEnumerator*) JSVAL_TO_PRIVATE(*statep);
if (NS_SUCCEEDED(e->HasMoreElements(&hasMore)) && hasMore &&
NS_SUCCEEDED(e->GetNext(getter_AddRefs(isup))) && isup)
{
NS_SUCCEEDED(e->GetNext(getter_AddRefs(isup))) && isup) {
nsCOMPtr<nsISupportsCString> holder(do_QueryInterface(isup));
if (holder)
{
if (holder) {
nsCAutoString name;
if (NS_SUCCEEDED(holder->GetData(name)))
{
if (NS_SUCCEEDED(holder->GetData(name))) {
JSString* idstr = JS_NewStringCopyN(cx, name.get(), name.Length());
if (idstr &&
JS_ValueToId(cx, STRING_TO_JSVAL(idstr), idp))
{
JS_ValueToId(cx, STRING_TO_JSVAL(idstr), idp)) {
return NS_OK;
}
}
@ -961,25 +932,20 @@ nsXPCComponents_Classes::NewResolve(nsIXPConnectWrappedNative *wrapper,
if (JSID_IS_STRING(id) &&
name.encode(cx, JSID_TO_STRING(id)) &&
name.ptr()[0] != '{') // we only allow contractids here
{
name.ptr()[0] != '{') { // we only allow contractids here
nsCOMPtr<nsIJSCID> nsid =
dont_AddRef(static_cast<nsIJSCID*>(nsJSCID::NewID(name.ptr())));
if (nsid)
{
if (nsid) {
nsCOMPtr<nsIXPConnect> xpc;
wrapper->GetXPConnect(getter_AddRefs(xpc));
if (xpc)
{
if (xpc) {
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
if (NS_SUCCEEDED(xpc->WrapNative(cx, obj,
static_cast<nsIJSCID*>(nsid),
NS_GET_IID(nsIJSCID),
getter_AddRefs(holder))))
{
getter_AddRefs(holder)))) {
JSObject* idobj;
if (holder && NS_SUCCEEDED(holder->GetJSObject(&idobj)))
{
if (holder && NS_SUCCEEDED(holder->GetJSObject(&idobj))) {
*objp = obj;
*_retval = JS_DefinePropertyById(cx, obj, id,
OBJECT_TO_JSVAL(idobj),
@ -1145,15 +1111,13 @@ nsXPCComponents_ClassesByID::NewEnumerate(nsIXPConnectWrappedNative *wrapper,
{
nsISimpleEnumerator* e;
switch (enum_op)
{
switch (enum_op) {
case JSENUMERATE_INIT:
case JSENUMERATE_INIT_ALL:
{
nsCOMPtr<nsIComponentRegistrar> compMgr;
if (NS_FAILED(NS_GetComponentRegistrar(getter_AddRefs(compMgr))) || !compMgr ||
NS_FAILED(compMgr->EnumerateCIDs(&e)) || !e )
{
NS_FAILED(compMgr->EnumerateCIDs(&e)) || !e ) {
*statep = JSVAL_NULL;
return NS_ERROR_UNEXPECTED;
}
@ -1170,19 +1134,15 @@ nsXPCComponents_ClassesByID::NewEnumerate(nsIXPConnectWrappedNative *wrapper,
e = (nsISimpleEnumerator*) JSVAL_TO_PRIVATE(*statep);
if (NS_SUCCEEDED(e->HasMoreElements(&hasMore)) && hasMore &&
NS_SUCCEEDED(e->GetNext(getter_AddRefs(isup))) && isup)
{
NS_SUCCEEDED(e->GetNext(getter_AddRefs(isup))) && isup) {
nsCOMPtr<nsISupportsID> holder(do_QueryInterface(isup));
if (holder)
{
if (holder) {
char* name;
if (NS_SUCCEEDED(holder->ToString(&name)) && name)
{
if (NS_SUCCEEDED(holder->ToString(&name)) && name) {
JSString* idstr = JS_NewStringCopyZ(cx, name);
nsMemory::Free(name);
if (idstr &&
JS_ValueToId(cx, STRING_TO_JSVAL(idstr), idp))
{
JS_ValueToId(cx, STRING_TO_JSVAL(idstr), idp)) {
return NS_OK;
}
}
@ -1229,25 +1189,20 @@ nsXPCComponents_ClassesByID::NewResolve(nsIXPConnectWrappedNative *wrapper,
if (JSID_IS_STRING(id) &&
name.encode(cx, JSID_TO_STRING(id)) &&
name.ptr()[0] == '{' &&
IsRegisteredCLSID(name.ptr())) // we only allow canonical CLSIDs here
{
IsRegisteredCLSID(name.ptr())) { // we only allow canonical CLSIDs here
nsCOMPtr<nsIJSCID> nsid =
dont_AddRef(static_cast<nsIJSCID*>(nsJSCID::NewID(name.ptr())));
if (nsid)
{
if (nsid) {
nsCOMPtr<nsIXPConnect> xpc;
wrapper->GetXPConnect(getter_AddRefs(xpc));
if (xpc)
{
if (xpc) {
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
if (NS_SUCCEEDED(xpc->WrapNative(cx, obj,
static_cast<nsIJSCID*>(nsid),
NS_GET_IID(nsIJSCID),
getter_AddRefs(holder))))
{
getter_AddRefs(holder)))) {
JSObject* idobj;
if (holder && NS_SUCCEEDED(holder->GetJSObject(&idobj)))
{
if (holder && NS_SUCCEEDED(holder->GetJSObject(&idobj))) {
*objp = obj;
*_retval = JS_DefinePropertyById(cx, obj, id,
OBJECT_TO_JSVAL(idobj),
@ -1415,8 +1370,7 @@ nsXPCComponents_Results::NewEnumerate(nsIXPConnectWrappedNative *wrapper,
{
void** iter;
switch (enum_op)
{
switch (enum_op) {
case JSENUMERATE_INIT:
case JSENUMERATE_INIT_ALL:
{
@ -1432,8 +1386,7 @@ nsXPCComponents_Results::NewEnumerate(nsIXPConnectWrappedNative *wrapper,
{
const char* name;
iter = (void**) JSVAL_TO_PRIVATE(*statep);
if (nsXPCException::IterateNSResults(nsnull, &name, nsnull, iter))
{
if (nsXPCException::IterateNSResults(nsnull, &name, nsnull, iter)) {
JSString* idstr = JS_NewStringCopyZ(cx, name);
if (idstr && JS_ValueToId(cx, STRING_TO_JSVAL(idstr), idp))
return NS_OK;
@ -1460,15 +1413,12 @@ nsXPCComponents_Results::NewResolve(nsIXPConnectWrappedNative *wrapper,
{
JSAutoByteString name;
if (JSID_IS_STRING(id) && name.encode(cx, JSID_TO_STRING(id)))
{
if (JSID_IS_STRING(id) && name.encode(cx, JSID_TO_STRING(id))) {
const char* rv_name;
void* iter = nsnull;
nsresult rv;
while (nsXPCException::IterateNSResults(&rv, &rv_name, nsnull, &iter))
{
if (!strcmp(name.ptr(), rv_name))
{
while (nsXPCException::IterateNSResults(&rv, &rv_name, nsnull, &iter)) {
if (!strcmp(name.ptr(), rv_name)) {
jsval val;
*objp = obj;
@ -1477,8 +1427,7 @@ nsXPCComponents_Results::NewResolve(nsIXPConnectWrappedNative *wrapper,
nsnull, nsnull,
JSPROP_ENUMERATE |
JSPROP_READONLY |
JSPROP_PERMANENT))
{
JSPROP_PERMANENT)) {
return NS_ERROR_UNEXPECTED;
}
}
@ -1672,8 +1621,7 @@ nsXPCComponents_ID::CallOrConstruct(nsIXPConnectWrappedNative *wrapper,
nsIXPCSecurityManager* sm =
xpcc->GetAppropriateSecurityManager(nsIXPCSecurityManager::HOOK_CREATE_INSTANCE);
if (sm && NS_FAILED(sm->CanCreateInstance(cx, nsJSID::GetCID())))
{
if (sm && NS_FAILED(sm->CanCreateInstance(cx, nsJSID::GetCID()))) {
// the security manager vetoed. It should have set an exception.
*_retval = JS_FALSE;
return NS_OK;
@ -1687,8 +1635,7 @@ nsXPCComponents_ID::CallOrConstruct(nsIXPConnectWrappedNative *wrapper,
if (!(jsstr = JS_ValueToString(cx, argv[0])) ||
!bytes.encode(cx, jsstr) ||
!id.Parse(bytes.ptr()))
{
!id.Parse(bytes.ptr())) {
return ThrowAndFail(NS_ERROR_XPC_BAD_ID_STRING, cx, _retval);
}
@ -1894,8 +1841,7 @@ nsXPCComponents_Exception::CallOrConstruct(nsIXPConnectWrappedNative *wrapper,
nsIXPCSecurityManager* sm =
xpcc->GetAppropriateSecurityManager(nsIXPCSecurityManager::HOOK_CREATE_INSTANCE);
if (sm && NS_FAILED(sm->CanCreateInstance(cx, nsXPCException::GetCID())))
{
if (sm && NS_FAILED(sm->CanCreateInstance(cx, nsXPCException::GetCID()))) {
// the security manager vetoed. It should have set an exception.
*_retval = JS_FALSE;
return NS_OK;
@ -1909,17 +1855,14 @@ nsXPCComponents_Exception::CallOrConstruct(nsIXPConnectWrappedNative *wrapper,
nsCOMPtr<nsISupports> eData;
// all params are optional - grab any passed in
switch (argc)
{
switch (argc) {
default: // more than 4 - ignore extra
// ...fall through...
case 4: // argv[3] is object for eData
if (JSVAL_IS_NULL(argv[3]))
{
if (JSVAL_IS_NULL(argv[3])) {
// do nothing, leave eData as null
}
else
{
else {
if (JSVAL_IS_PRIMITIVE(argv[3]) ||
NS_FAILED(xpc->WrapJS(cx, JSVAL_TO_OBJECT(argv[3]),
NS_GET_IID(nsISupports),
@ -1928,12 +1871,10 @@ nsXPCComponents_Exception::CallOrConstruct(nsIXPConnectWrappedNative *wrapper,
}
// ...fall through...
case 3: // argv[2] is object for eStack
if (JSVAL_IS_NULL(argv[2]))
{
if (JSVAL_IS_NULL(argv[2])) {
// do nothing, leave eStack as null
}
else
{
else {
if (JSVAL_IS_PRIMITIVE(argv[2]) ||
NS_FAILED(xpc->WrapJS(cx, JSVAL_TO_OBJECT(argv[2]),
NS_GET_IID(nsIStackFrame),
@ -1966,8 +1907,7 @@ nsXPCComponents_Exception::CallOrConstruct(nsIXPConnectWrappedNative *wrapper,
if (NS_FAILED(xpc->WrapNative(cx, obj, e, NS_GET_IID(nsIXPCException),
getter_AddRefs(holder))) || !holder ||
NS_FAILED(holder->GetJSObject(&newObj)) || !newObj)
{
NS_FAILED(holder->GetJSObject(&newObj)) || !newObj) {
return ThrowAndFail(NS_ERROR_XPC_CANT_CREATE_WN, cx, _retval);
}
@ -2227,8 +2167,7 @@ nsXPCConstructor::CallOrConstruct(nsIXPConnectWrappedNative *wrapper,
NS_FAILED(cidHolder->GetJSObject(&cidObj)) || !cidObj ||
NS_FAILED(xpc->WrapNative(cx, obj, mInterfaceID, NS_GET_IID(nsIJSIID),
getter_AddRefs(iidHolder))) || !iidHolder ||
NS_FAILED(iidHolder->GetJSObject(&iidObj)) || !iidObj)
{
NS_FAILED(iidHolder->GetJSObject(&iidObj)) || !iidObj) {
return ThrowAndFail(NS_ERROR_XPC_CANT_CREATE_WN, cx, _retval);
}
@ -2236,8 +2175,7 @@ nsXPCConstructor::CallOrConstruct(nsIXPConnectWrappedNative *wrapper,
jsval val;
if (!JS_CallFunctionName(cx, cidObj, "createInstance", 1, ctorArgs, &val) ||
JSVAL_IS_PRIMITIVE(val))
{
JSVAL_IS_PRIMITIVE(val)) {
// createInstance will have thrown an exception
*_retval = JS_FALSE;
return NS_OK;
@ -2248,21 +2186,18 @@ nsXPCConstructor::CallOrConstruct(nsIXPConnectWrappedNative *wrapper,
*vp = val;
// call initializer method if supplied
if (mInitializer)
{
if (mInitializer) {
JSObject* newObj = JSVAL_TO_OBJECT(val);
jsval fun;
jsval ignored;
// first check existence of function property for better error reporting
if (!JS_GetProperty(cx, newObj, mInitializer, &fun) ||
JSVAL_IS_PRIMITIVE(fun))
{
JSVAL_IS_PRIMITIVE(fun)) {
return ThrowAndFail(NS_ERROR_XPC_BAD_INITIALIZER_NAME, cx, _retval);
}
if (!JS_CallFunctionValue(cx, newObj, fun, argc, argv, &ignored))
{
if (!JS_CallFunctionValue(cx, newObj, fun, argc, argv, &ignored)) {
// function should have thrown an exception
*_retval = JS_FALSE;
return NS_OK;
@ -2464,8 +2399,7 @@ nsXPCComponents_Constructor::CallOrConstruct(nsIXPConnectWrappedNative *wrapper,
nsIXPCSecurityManager* sm =
xpcc->GetAppropriateSecurityManager(nsIXPCSecurityManager::HOOK_CREATE_INSTANCE);
if (sm && NS_FAILED(sm->CanCreateInstance(cx, nsXPCConstructor::GetCID())))
{
if (sm && NS_FAILED(sm->CanCreateInstance(cx, nsXPCConstructor::GetCID()))) {
// the security manager vetoed. It should have set an exception.
*_retval = JS_FALSE;
return NS_OK;
@ -2477,16 +2411,14 @@ nsXPCComponents_Constructor::CallOrConstruct(nsIXPConnectWrappedNative *wrapper,
const char* cInitializer = nsnull;
JSAutoByteString cInitializerBytes;
if (argc >= 3)
{
if (argc >= 3) {
// argv[2] is an initializer function or property name
JSString* str = JS_ValueToString(cx, argv[2]);
if (!str || !(cInitializer = cInitializerBytes.encode(cx, str)))
return ThrowAndFail(NS_ERROR_XPC_BAD_CONVERT_JS, cx, _retval);
}
if (argc >= 2)
{
if (argc >= 2) {
// argv[1] is an iid name string
// XXXjband support passing "Components.interfaces.foo"?
@ -2502,8 +2434,7 @@ nsXPCComponents_Constructor::CallOrConstruct(nsIXPConnectWrappedNative *wrapper,
NS_FAILED(xpc->WrapNative(cx, obj, ifaces,
NS_GET_IID(nsIXPCComponents_Interfaces),
getter_AddRefs(holder))) || !holder ||
NS_FAILED(holder->GetJSObject(&ifacesObj)) || !ifacesObj)
{
NS_FAILED(holder->GetJSObject(&ifacesObj)) || !ifacesObj) {
return ThrowAndFail(NS_ERROR_XPC_UNEXPECTED, cx, _retval);
}
@ -2519,18 +2450,15 @@ nsXPCComponents_Constructor::CallOrConstruct(nsIXPConnectWrappedNative *wrapper,
nsCOMPtr<nsIXPConnectWrappedNative> wn;
if (NS_FAILED(xpc->GetWrappedNativeOfJSObject(cx, JSVAL_TO_OBJECT(val),
getter_AddRefs(wn))) || !wn ||
!(cInterfaceID = do_QueryWrappedNative(wn)))
{
!(cInterfaceID = do_QueryWrappedNative(wn))) {
return ThrowAndFail(NS_ERROR_XPC_UNEXPECTED, cx, _retval);
}
}
else
{
else {
nsCOMPtr<nsIInterfaceInfo> info;
xpc->GetInfoForIID(&NS_GET_IID(nsISupports), getter_AddRefs(info));
if (info)
{
if (info) {
cInterfaceID =
dont_AddRef(static_cast<nsIJSIID*>(nsJSIID::NewID(info)));
}
@ -2555,8 +2483,7 @@ nsXPCComponents_Constructor::CallOrConstruct(nsIXPConnectWrappedNative *wrapper,
NS_FAILED(xpc->WrapNative(cx, obj, classes,
NS_GET_IID(nsIXPCComponents_Classes),
getter_AddRefs(holder))) || !holder ||
NS_FAILED(holder->GetJSObject(&classesObj)) || !classesObj)
{
NS_FAILED(holder->GetJSObject(&classesObj)) || !classesObj) {
return ThrowAndFail(NS_ERROR_XPC_UNEXPECTED, cx, _retval);
}
@ -2572,8 +2499,7 @@ nsXPCComponents_Constructor::CallOrConstruct(nsIXPConnectWrappedNative *wrapper,
nsCOMPtr<nsIXPConnectWrappedNative> wn;
if (NS_FAILED(xpc->GetWrappedNativeOfJSObject(cx, JSVAL_TO_OBJECT(val),
getter_AddRefs(wn))) || !wn ||
!(cClassID = do_QueryWrappedNative(wn)))
{
!(cClassID = do_QueryWrappedNative(wn))) {
return ThrowAndFail(NS_ERROR_XPC_UNEXPECTED, cx, _retval);
}
}
@ -2589,8 +2515,7 @@ nsXPCComponents_Constructor::CallOrConstruct(nsIXPConnectWrappedNative *wrapper,
if (NS_FAILED(xpc->WrapNative(cx, obj, ctor, NS_GET_IID(nsIXPCConstructor),
getter_AddRefs(holder2))) || !holder2 ||
NS_FAILED(holder2->GetJSObject(&newObj)) || !newObj)
{
NS_FAILED(holder2->GetJSObject(&newObj)) || !newObj) {
return ThrowAndFail(NS_ERROR_XPC_CANT_CREATE_WN, cx, _retval);
}
@ -2875,8 +2800,7 @@ nsXPCComponents_Utils::ReportError()
const PRUint64 innerWindowID = nsJSUtils::GetCurrentlyRunningCodeInnerWindowID(cx);
JSErrorReport* err = JS_ErrorFromException(cx, argv[0]);
if (err)
{
if (err) {
// It's a proper JS Error
nsAutoString fileUni;
CopyUTF8toUTF16(err->filename, fileUni);
@ -2902,8 +2826,7 @@ nsXPCComponents_Utils::ReportError()
// It's not a JS Error object, so we synthesize as best we're able
JSString* msgstr = JS_ValueToString(cx, argv[0]);
if (msgstr)
{
if (msgstr) {
// Root the string during scripterr->Init
argv[0] = STRING_TO_JSVAL(msgstr);
@ -2914,8 +2837,7 @@ nsXPCComponents_Utils::ReportError()
nsXPIDLCString fileName;
PRInt32 lineNo = 0;
if (frame)
{
if (frame) {
frame->GetFilename(getter_Copies(fileName));
frame->GetLineNumber(&lineNo);
}
@ -2929,8 +2851,7 @@ nsXPCComponents_Utils::ReportError()
nsnull,
lineNo, 0, 0,
"XPConnect JavaScript", innerWindowID);
if (NS_SUCCEEDED(rv))
{
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIScriptError> logError = do_QueryInterface(scripterr);
console->LogMessage(logError);
}
@ -3437,8 +3358,7 @@ ContextHolder::ContextHolder(JSContext *aOuterCx, JSObject *aSandbox)
: mJSContext(JS_NewContext(JS_GetRuntime(aOuterCx), 1024)),
mOrigCx(aOuterCx)
{
if (mJSContext)
{
if (mJSContext) {
JSAutoRequest ar(mJSContext);
JS_SetOptions(mJSContext,
JS_GetOptions(mJSContext) |
@ -4300,20 +4220,17 @@ nsXPCComponents::GetProperty(nsIXPConnectWrappedNative *wrapper,
bool doResult = JS_FALSE;
nsresult res;
XPCJSRuntime* rt = xpcc->GetRuntime();
if (id == rt->GetStringID(XPCJSRuntime::IDX_LAST_RESULT))
{
if (id == rt->GetStringID(XPCJSRuntime::IDX_LAST_RESULT)) {
res = xpcc->GetLastResult();
doResult = JS_TRUE;
}
else if (id == rt->GetStringID(XPCJSRuntime::IDX_RETURN_CODE))
{
else if (id == rt->GetStringID(XPCJSRuntime::IDX_RETURN_CODE)) {
res = xpcc->GetPendingResult();
doResult = JS_TRUE;
}
nsresult rv = NS_OK;
if (doResult)
{
if (doResult) {
if (!JS_NewNumberValue(cx, (jsdouble) res, vp))
return NS_ERROR_OUT_OF_MEMORY;
rv = NS_SUCCESS_I_DID_SOMETHING;
@ -4336,11 +4253,9 @@ nsXPCComponents::SetProperty(nsIXPConnectWrappedNative *wrapper,
if (!rt)
return NS_ERROR_FAILURE;
if (id == rt->GetStringID(XPCJSRuntime::IDX_RETURN_CODE))
{
if (id == rt->GetStringID(XPCJSRuntime::IDX_RETURN_CODE)) {
nsresult rv;
if (JS_ValueToECMAUint32(cx, *vp, (uint32*)&rv))
{
if (JS_ValueToECMAUint32(cx, *vp, (uint32*)&rv)) {
xpcc->SetPendingResult(rv);
xpcc->SetLastResult(rv);
return NS_SUCCESS_I_DID_SOMETHING;

View File

@ -74,8 +74,7 @@ XPCContext::~XPCContext()
// Iterate over our scopes and tell them that we have been destroyed
for (PRCList *scopeptr = PR_NEXT_LINK(&mScopes);
scopeptr != &mScopes;
scopeptr = PR_NEXT_LINK(scopeptr))
{
scopeptr = PR_NEXT_LINK(scopeptr)) {
XPCWrappedNativeScope *scope = (XPCWrappedNativeScope *)scopeptr;
scope->SetContext(nsnull);
}
@ -99,8 +98,7 @@ XPCContext::DebugDump(PRInt16 depth)
XPC_LOG_ALWAYS(("mSecurityManagerFlags of %x", mSecurityManagerFlags));
XPC_LOG_ALWAYS(("mException @ %x", mException));
if (depth && mException)
{
if (depth && mException) {
// XXX show the exception here...
}

File diff suppressed because it is too large Load Diff

View File

@ -53,8 +53,7 @@ static const char* JSVAL2String(JSContext* cx, jsval val, JSBool* isString,
JSString* value_str = JS_ValueToString(cx, val);
if (value_str)
value = bytes->encode(cx, value_str);
if (value)
{
if (value) {
const char* found = strstr(value, "function ");
if (found && (value == found || value+1 == found || value+2 == found))
value = "[function]";
@ -93,16 +92,14 @@ static char* FormatJSFrame(JSContext* cx, JSStackFrame* fp,
if (!ac.enter(cx, JS_GetGlobalForFrame(fp)))
return buf;
if (script && pc)
{
if (script && pc) {
filename = JS_GetScriptFilename(cx, script);
lineno = (PRInt32) JS_PCToLineNumber(cx, script, pc);
fun = JS_GetFrameFunction(cx, fp);
if (fun)
funname = JS_GetFunctionId(fun);
if (showArgs || showLocals)
{
if (showArgs || showLocals) {
callObj = JS_GetFrameCallObject(cx, fp);
if (callObj)
if (!JS_GetPropertyDescArray(cx, callObj, &callProps))
@ -114,8 +111,7 @@ static char* FormatJSFrame(JSContext* cx, JSStackFrame* fp,
!showThisProps ||
JSVAL_IS_PRIMITIVE(thisVal) ||
!JS_GetPropertyDescArray(cx, JSVAL_TO_OBJECT(thisVal),
&thisProps))
{
&thisProps)) {
thisProps.array = nsnull; // just to be sure
}
}
@ -132,13 +128,10 @@ static char* FormatJSFrame(JSContext* cx, JSStackFrame* fp,
// print the function arguments
if (showArgs && callObj)
{
for (uint32 i = 0; i < callProps.length; i++)
{
if (showArgs && callObj) {
for (uint32 i = 0; i < callProps.length; i++) {
JSPropertyDesc* desc = &callProps.array[i];
if (desc->flags & JSPD_ARGUMENT)
{
if (desc->flags & JSPD_ARGUMENT) {
JSAutoByteString nameBytes;
const char* name = JSVAL2String(cx, desc->id, &isString, &nameBytes);
if (!isString)
@ -161,21 +154,17 @@ static char* FormatJSFrame(JSContext* cx, JSStackFrame* fp,
// print any unnamed trailing args (found in 'arguments' object)
if (JS_GetProperty(cx, callObj, "arguments", &val) &&
JSVAL_IS_OBJECT(val))
{
JSVAL_IS_OBJECT(val)) {
uint32 argCount;
JSObject* argsObj = JSVAL_TO_OBJECT(val);
if (JS_GetProperty(cx, argsObj, "length", &val) &&
JS_ValueToECMAUint32(cx, val, &argCount) &&
argCount > namedArgCount)
{
for (uint32 k = namedArgCount; k < argCount; k++)
{
argCount > namedArgCount) {
for (uint32 k = namedArgCount; k < argCount; k++) {
char number[8];
JS_snprintf(number, 8, "%d", (int) k);
if (JS_GetProperty(cx, argsObj, number, &val))
{
if (JS_GetProperty(cx, argsObj, number, &val)) {
JSAutoByteString valueBytes;
const char *value = JSVAL2String(cx, val, &isString, &valueBytes);
buf = JS_sprintf_append(buf, "%s%s%s%s",
@ -200,20 +189,16 @@ static char* FormatJSFrame(JSContext* cx, JSStackFrame* fp,
// print local variables
if (showLocals && callProps.array)
{
for (uint32 i = 0; i < callProps.length; i++)
{
if (showLocals && callProps.array) {
for (uint32 i = 0; i < callProps.length; i++) {
JSPropertyDesc* desc = &callProps.array[i];
if (desc->flags & JSPD_VARIABLE)
{
if (desc->flags & JSPD_VARIABLE) {
JSAutoByteString nameBytes;
JSAutoByteString valueBytes;
const char *name = JSVAL2String(cx, desc->id, nsnull, &nameBytes);
const char *value = JSVAL2String(cx, desc->value, &isString, &valueBytes);
if (name && value)
{
if (name && value) {
buf = JS_sprintf_append(buf, TAB "%s = %s%s%s\n",
name,
isString ? "\"" : "",
@ -227,16 +212,13 @@ static char* FormatJSFrame(JSContext* cx, JSStackFrame* fp,
// print the value of 'this'
if (showLocals)
{
if (gotThisVal)
{
if (showLocals) {
if (gotThisVal) {
JSString* thisValStr;
JSAutoByteString thisValBytes;
if (nsnull != (thisValStr = JS_ValueToString(cx, thisVal)) &&
thisValBytes.encode(cx, thisValStr))
{
thisValBytes.encode(cx, thisValStr)) {
buf = JS_sprintf_append(buf, TAB "this = %s\n", thisValBytes.ptr());
if (!buf) goto out;
}
@ -247,20 +229,16 @@ static char* FormatJSFrame(JSContext* cx, JSStackFrame* fp,
// print the properties of 'this', if it is an object
if (showThisProps && thisProps.array)
{
if (showThisProps && thisProps.array) {
for (uint32 i = 0; i < thisProps.length; i++)
{
for (uint32 i = 0; i < thisProps.length; i++) {
JSPropertyDesc* desc = &thisProps.array[i];
if (desc->flags & JSPD_ENUMERATE)
{
if (desc->flags & JSPD_ENUMERATE) {
JSAutoByteString nameBytes;
JSAutoByteString valueBytes;
const char *name = JSVAL2String(cx, desc->id, nsnull, &nameBytes);
const char *value = JSVAL2String(cx, desc->value, &isString, &valueBytes);
if (name && value)
{
if (name && value) {
buf = JS_sprintf_append(buf, TAB "this.%s = %s%s%s\n",
name,
isString ? "\"" : "",
@ -288,8 +266,7 @@ static char* FormatJSStackDump(JSContext* cx, char* buf,
JSStackFrame* iter = nsnull;
int num = 0;
while (nsnull != (fp = JS_FrameIterator(cx, &iter)))
{
while (nsnull != (fp = JS_FrameIterator(cx, &iter))) {
buf = FormatJSFrame(cx, fp, buf, num, showArgs, showLocals, showThisProps);
num++;
}
@ -303,8 +280,7 @@ static char* FormatJSStackDump(JSContext* cx, char* buf,
JSBool
xpc_DumpJSStack(JSContext* cx, JSBool showArgs, JSBool showLocals, JSBool showThisProps)
{
if (char* buf = xpc_PrintJSStack(cx, showArgs, showLocals, showThisProps))
{
if (char* buf = xpc_PrintJSStack(cx, showArgs, showLocals, showThisProps)) {
fputs(buf, stdout);
JS_smprintf_free(buf);
}
@ -346,23 +322,20 @@ xpc_DumpEvalInJSStackFrame(JSContext* cx, JSUint32 frameno, const char* text)
JSStackFrame* iter = nsnull;
JSUint32 num = 0;
if (!cx || !text)
{
if (!cx || !text) {
puts("invalid params passed to xpc_DumpEvalInJSStackFrame!");
return JS_FALSE;
}
printf("js[%d]> %s\n", frameno, text);
while (nsnull != (fp = JS_FrameIterator(cx, &iter)))
{
while (nsnull != (fp = JS_FrameIterator(cx, &iter))) {
if (num == frameno)
break;
num++;
}
if (!fp)
{
if (!fp) {
puts("invalid frame number!");
return JS_FALSE;
}
@ -377,8 +350,7 @@ xpc_DumpEvalInJSStackFrame(JSContext* cx, JSUint32 frameno, const char* text)
JSAutoByteString bytes;
if (JS_EvaluateInStackFrame(cx, fp, text, strlen(text), "eval", 1, &rval) &&
nsnull != (str = JS_ValueToString(cx, rval)) &&
bytes.encode(cx, str))
{
bytes.encode(cx, str)) {
printf("%s\n", bytes.ptr());
}
else
@ -457,8 +429,7 @@ static void PrintObject(JSObject* obj, int depth, ObjectPile* pile)
{
PrintObjectBasics(obj);
switch (pile->Visit(obj))
{
switch (pile->Visit(obj)) {
case ObjectPile::primary:
puts("");
break;

View File

@ -73,10 +73,8 @@ nsXPCException::NameAndFormatForNSResult(nsresult rv,
const char** format)
{
for (ResultMap* p = map; p->name; p++)
{
if (rv == p->rv)
{
for (ResultMap* p = map; p->name; p++) {
if (rv == p->rv) {
if (name) *name = p->name;
if (format) *format = p->format;
return JS_TRUE;
@ -99,8 +97,7 @@ nsXPCException::IterateNSResults(nsresult* rv,
p++;
if (!p->name)
p = nsnull;
else
{
else {
if (rv)
*rv = p->rv;
if (name)
@ -159,8 +156,7 @@ nsXPCException::~nsXPCException()
NS_IMETHODIMP
nsXPCException::StealJSVal(jsval *vp NS_OUTPARAM)
{
if (mThrownJSVal.IsHeld())
{
if (mThrownJSVal.IsHeld()) {
*vp = mThrownJSVal.Release();
return NS_OK;
}
@ -171,8 +167,7 @@ nsXPCException::StealJSVal(jsval *vp NS_OUTPARAM)
NS_IMETHODIMP
nsXPCException::StowJSVal(JSContext* cx, jsval v)
{
if (mThrownJSVal.Hold(cx))
{
if (mThrownJSVal.Hold(cx)) {
mThrownJSVal = v;
return NS_OK;
}
@ -182,18 +177,15 @@ nsXPCException::StowJSVal(JSContext* cx, jsval v)
void
nsXPCException::Reset()
{
if (mMessage)
{
if (mMessage) {
nsMemory::Free(mMessage);
mMessage = nsnull;
}
if (mName)
{
if (mName) {
nsMemory::Free(mName);
mName = nsnull;
}
if (mFilename)
{
if (mFilename) {
nsMemory::Free(mFilename);
mFilename = nsnull;
}
@ -315,15 +307,13 @@ nsXPCException::Initialize(const char *aMessage, nsresult aResult, const char *a
Reset();
if (aMessage)
{
if (aMessage) {
if (!(mMessage = (char*) nsMemory::Clone(aMessage,
sizeof(char)*(strlen(aMessage)+1))))
return NS_ERROR_OUT_OF_MEMORY;
}
if (aName)
{
if (aName) {
if (!(mName = (char*) nsMemory::Clone(aName,
sizeof(char)*(strlen(aName)+1))))
return NS_ERROR_OUT_OF_MEMORY;
@ -331,8 +321,7 @@ nsXPCException::Initialize(const char *aMessage, nsresult aResult, const char *a
mResult = aResult;
if (aLocation)
{
if (aLocation) {
mLocation = aLocation;
NS_ADDREF(mLocation);
// For now, fill in our location details from our stack frame.
@ -343,8 +332,7 @@ nsXPCException::Initialize(const char *aMessage, nsresult aResult, const char *a
if (NS_FAILED(rc = aLocation->GetLineNumber(&mLineNumber)))
return rc;
}
else
{
else {
nsresult rv;
nsXPConnect* xpc = nsXPConnect::GetXPConnect();
if (!xpc)
@ -354,13 +342,11 @@ nsXPCException::Initialize(const char *aMessage, nsresult aResult, const char *a
return rv;
}
if (aData)
{
if (aData) {
mData = aData;
NS_ADDREF(mData);
}
if (aInner)
{
if (aInner) {
mInner = aInner;
NS_ADDREF(mInner);
}
@ -385,8 +371,7 @@ nsXPCException::ToString(char **_retval)
char* indicatedLocation = nsnull;
if (mLocation)
{
if (mLocation) {
// we need to free this if it does not fail
nsresult rv = mLocation->ToString(&indicatedLocation);
if (NS_FAILED(rv))
@ -398,8 +383,7 @@ nsXPCException::ToString(char **_retval)
indicatedLocation : defaultLocation;
const char* resultName = mName;
if (!resultName && !NameAndFormatForNSResult(mResult, &resultName,
(!msg) ? &msg : nsnull))
{
(!msg) ? &msg : nsnull)) {
if (!msg)
msg = defaultMsg;
resultName = "<unknown>";
@ -411,8 +395,7 @@ nsXPCException::ToString(char **_retval)
nsMemory::Free(indicatedLocation);
char* final = nsnull;
if (temp)
{
if (temp) {
final = (char*) nsMemory::Clone(temp, sizeof(char)*(strlen(temp)+1));
JS_smprintf_free(temp);
}
@ -438,8 +421,7 @@ nsXPCException::NewException(const char *aMessage,
// This is bad because it means that wrapped exceptions will never have a
// shared prototype. So... We force one to be created via the factory
// *once* and then go about our business.
if (!sEverMadeOneFromFactory)
{
if (!sEverMadeOneFromFactory) {
nsCOMPtr<nsIXPCException> e =
do_CreateInstance(XPC_EXCEPTION_CONTRACTID);
sEverMadeOneFromFactory = JS_TRUE;
@ -447,27 +429,22 @@ nsXPCException::NewException(const char *aMessage,
nsresult rv;
nsXPCException* e = new nsXPCException();
if (e)
{
if (e) {
NS_ADDREF(e);
nsIStackFrame* location;
if (aLocation)
{
if (aLocation) {
location = aLocation;
NS_ADDREF(location);
}
else
{
else {
nsXPConnect* xpc = nsXPConnect::GetXPConnect();
if (!xpc)
{
if (!xpc) {
NS_RELEASE(e);
return NS_ERROR_FAILURE;
}
rv = xpc->GetCurrentJSStack(&location);
if (NS_FAILED(rv))
{
if (NS_FAILED(rv)) {
NS_RELEASE(e);
return NS_ERROR_FAILURE;
}
@ -479,15 +456,13 @@ nsXPCException::NewException(const char *aMessage,
}
// We want to trim off any leading native 'dataless' frames
if (location)
while (1)
{
while (1) {
PRUint32 language;
PRInt32 lineNumber;
if (NS_FAILED(location->GetLanguage(&language)) ||
language == nsIProgrammingLanguage::JAVASCRIPT ||
NS_FAILED(location->GetLineNumber(&lineNumber)) ||
lineNumber)
{
lineNumber) {
break;
}
nsCOMPtr<nsIStackFrame> caller;

View File

@ -56,8 +56,7 @@ xpc::PtrAndPrincipalHashKey::KeyEquals(const PtrAndPrincipalHashKey* aKey) const
return PR_TRUE;
bool equals;
if (NS_FAILED(mPrincipal->EqualsIgnoringDomain(aKey->mPrincipal, &equals)))
{
if (NS_FAILED(mPrincipal->EqualsIgnoringDomain(aKey->mPrincipal, &equals))) {
NS_ERROR("we failed, guessing!");
return PR_FALSE;
}
@ -418,10 +417,8 @@ XPCNativeSet::FindMember(jsid name, XPCNativeMember** pMember,
// look for interface names first
for (i = 0, iface = mInterfaces; i < count; i++, iface++)
{
if (name == (*iface)->GetName())
{
for (i = 0, iface = mInterfaces; i < count; i++, iface++) {
if (name == (*iface)->GetName()) {
if (pMember)
*pMember = nsnull;
if (pInterfaceIndex)
@ -431,11 +428,9 @@ XPCNativeSet::FindMember(jsid name, XPCNativeMember** pMember,
}
// look for method names
for (i = 0, iface = mInterfaces; i < count; i++, iface++)
{
for (i = 0, iface = mInterfaces; i < count; i++, iface++) {
XPCNativeMember* member = (*iface)->FindMember(name);
if (member)
{
if (member) {
if (pMember)
*pMember = member;
if (pInterfaceIndex)
@ -490,8 +485,7 @@ XPCNativeSet::FindNamedInterface(jsid name) const
{
XPCNativeInterface* const * pp = mInterfaces;
for (int i = (int) mInterfaceCount; i > 0; i--, pp++)
{
for (int i = (int) mInterfaceCount; i > 0; i--, pp++) {
XPCNativeInterface* iface = *pp;
if (name == iface->GetName())
@ -505,8 +499,7 @@ XPCNativeSet::FindInterfaceWithIID(const nsIID& iid) const
{
XPCNativeInterface* const * pp = mInterfaces;
for (int i = (int) mInterfaceCount; i > 0; i--, pp++)
{
for (int i = (int) mInterfaceCount; i > 0; i--, pp++) {
XPCNativeInterface* iface = *pp;
if (iface->GetIID()->Equals(iid))
@ -520,8 +513,7 @@ XPCNativeSet::HasInterface(XPCNativeInterface* aInterface) const
{
XPCNativeInterface* const * pp = mInterfaces;
for (int i = (int) mInterfaceCount; i > 0; i--, pp++)
{
for (int i = (int) mInterfaceCount; i > 0; i--, pp++) {
if (aInterface == *pp)
return JS_TRUE;
}
@ -559,8 +551,7 @@ XPCNativeSet::MatchesSetUpToInterface(const XPCNativeSet* other,
XPCNativeInterface* const * pp1 = mInterfaces;
XPCNativeInterface* const * pp2 = other->mInterfaces;
for (int i = (int) count; i > 0; i--, pp1++, pp2++)
{
for (int i = (int) count; i > 0; i--, pp1++, pp2++) {
XPCNativeInterface* cur = (*pp1);
if (cur != (*pp2))
return JS_FALSE;
@ -627,11 +618,9 @@ inline void
XPCWrappedNative::SweepTearOffs()
{
XPCWrappedNativeTearOffChunk* chunk;
for (chunk = &mFirstChunk; chunk; chunk = chunk->mNextChunk)
{
for (chunk = &mFirstChunk; chunk; chunk = chunk->mNextChunk) {
XPCWrappedNativeTearOff* to = chunk->mTearOffs;
for (int i = XPC_WRAPPED_NATIVE_TEAROFFS_PER_CHUNK; i > 0; i--, to++)
{
for (int i = XPC_WRAPPED_NATIVE_TEAROFFS_PER_CHUNK; i > 0; i--, to++) {
JSBool marked = to->IsMarked();
to->Unmark();
if (marked)
@ -639,11 +628,9 @@ XPCWrappedNative::SweepTearOffs()
// If this tearoff does not have a live dedicated JSObject,
// then let's recycle it.
if (!to->GetJSObject())
{
if (!to->GetJSObject()) {
nsISupports* obj = to->GetNative();
if (obj)
{
if (obj) {
obj->Release();
to->SetNative(nsnull);
}

View File

@ -103,8 +103,7 @@ nsJSID::GetNumber(char * *aNumber)
if (!aNumber)
return NS_ERROR_NULL_POINTER;
if (!mNumber)
{
if (!mNumber) {
if (!(mNumber = mID.ToString()))
mNumber = gNoString;
}
@ -135,8 +134,7 @@ nsJSID::Equals(nsIJSID *other, bool *_retval)
if (!_retval)
return NS_ERROR_NULL_POINTER;
if (!other || mID.Equals(GetInvalidIID()))
{
if (!other || mID.Equals(GetInvalidIID())) {
*_retval = PR_FALSE;
return NS_OK;
}
@ -151,14 +149,11 @@ nsJSID::Initialize(const char *idString)
if (!idString)
return NS_ERROR_NULL_POINTER;
if (*idString != '\0' && mID.Equals(GetInvalidIID()))
{
if (*idString != '\0' && mID.Equals(GetInvalidIID())) {
Reset();
if (idString[0] == '{')
{
if (mID.Parse(idString))
{
if (idString[0] == '{') {
if (mID.Parse(idString)) {
return NS_OK;
}
@ -201,15 +196,13 @@ nsJSID::GetInvalidIID() const
nsJSID*
nsJSID::NewID(const char* str)
{
if (!str)
{
if (!str) {
NS_ERROR("no string");
return nsnull;
}
nsJSID* idObj = new nsJSID();
if (idObj)
{
if (idObj) {
NS_ADDREF(idObj);
if (NS_FAILED(idObj->Initialize(str)))
NS_RELEASE(idObj);
@ -222,8 +215,7 @@ nsJSID*
nsJSID::NewID(const nsID& id)
{
nsJSID* idObj = new nsJSID();
if (idObj)
{
if (idObj) {
NS_ADDREF(idObj);
idObj->mID = id;
idObj->mName = nsnull;
@ -272,8 +264,7 @@ static nsIXPCScriptable* gSharedScriptableHelperForJSIID;
NS_METHOD GetSharedScriptableHelperForJSIID(PRUint32 language,
nsISupports **helper)
{
if (language == nsIProgrammingLanguage::JAVASCRIPT)
{
if (language == nsIProgrammingLanguage::JAVASCRIPT) {
NS_IF_ADDREF(gSharedScriptableHelperForJSIID);
*helper = gSharedScriptableHelperForJSIID;
}
@ -383,8 +374,7 @@ NS_IMETHODIMP nsJSIID::Equals(nsIJSID *other, bool *_retval)
if (!_retval)
return NS_ERROR_NULL_POINTER;
if (!other)
{
if (!other) {
*_retval = PR_FALSE;
return NS_OK;
}
@ -407,8 +397,7 @@ NS_IMETHODIMP nsJSIID::ToString(char **_retval)
nsJSIID*
nsJSIID::NewID(nsIInterfaceInfo* aInfo)
{
if (!aInfo)
{
if (!aInfo) {
NS_ERROR("no info");
return nsnull;
}
@ -443,8 +432,7 @@ nsJSIID::NewResolve(nsIXPConnectWrappedNative *wrapper,
return NS_OK;
XPCNativeMember* member = iface->FindMember(id);
if (member && member->IsConstant())
{
if (member && member->IsConstant()) {
jsval val;
if (!member->GetConstantValue(ccx, iface, &val))
return NS_ERROR_OUT_OF_MEMORY;
@ -478,12 +466,10 @@ nsJSIID::Enumerate(nsIXPConnectWrappedNative *wrapper,
return NS_OK;
PRUint16 count = iface->GetMemberCount();
for (PRUint16 i = 0; i < count; i++)
{
for (PRUint16 i = 0; i < count; i++) {
XPCNativeMember* member = iface->GetMemberAt(i);
if (member && member->IsConstant() &&
!xpc_ForcePropertyResolve(cx, obj, member->GetName()))
{
!xpc_ForcePropertyResolve(cx, obj, member->GetName())) {
return NS_ERROR_UNEXPECTED;
}
}
@ -499,8 +485,7 @@ nsJSIID::HasInstance(nsIXPConnectWrappedNative *wrapper,
*bp = JS_FALSE;
nsresult rv = NS_OK;
if (!JSVAL_IS_PRIMITIVE(val))
{
if (!JSVAL_IS_PRIMITIVE(val)) {
// we have a JSObject
JSObject* obj = JSVAL_TO_OBJECT(val);
@ -510,11 +495,9 @@ nsJSIID::HasInstance(nsIXPConnectWrappedNative *wrapper,
const nsIID* iid;
mInfo->GetIIDShared(&iid);
if (IS_SLIM_WRAPPER(obj))
{
if (IS_SLIM_WRAPPER(obj)) {
XPCWrappedNativeProto* proto = GetSlimWrapperProto(obj);
if (proto->GetSet()->HasInterfaceWithAncestor(iid))
{
if (proto->GetSet()->HasInterfaceWithAncestor(iid)) {
*bp = JS_TRUE;
return NS_OK;
}
@ -528,8 +511,7 @@ nsJSIID::HasInstance(nsIXPConnectWrappedNative *wrapper,
return NS_ERROR_FAILURE;
}
if (mozilla::dom::binding::instanceIsProxy(obj))
{
if (mozilla::dom::binding::instanceIsProxy(obj)) {
nsISupports *identity =
static_cast<nsISupports*>(js::GetProxyPrivate(obj).toPrivate());
nsCOMPtr<nsIClassInfo> ci = do_QueryInterface(identity);
@ -553,8 +535,7 @@ nsJSIID::HasInstance(nsIXPConnectWrappedNative *wrapper,
// We'll trust the interface set of the wrapper if this is known
// to be an interface that the objects *expects* to be able to
// handle.
if (other_wrapper->HasInterfaceNoQI(*iid))
{
if (other_wrapper->HasInterfaceNoQI(*iid)) {
*bp = JS_TRUE;
return NS_OK;
}
@ -668,32 +649,26 @@ nsJSCID::ResolveName()
nsJSCID*
nsJSCID::NewID(const char* str)
{
if (!str)
{
if (!str) {
NS_ERROR("no string");
return nsnull;
}
nsJSCID* idObj = new nsJSCID();
if (idObj)
{
if (idObj) {
bool success = false;
NS_ADDREF(idObj);
if (str[0] == '{')
{
if (str[0] == '{') {
if (NS_SUCCEEDED(idObj->Initialize(str)))
success = PR_TRUE;
}
else
{
else {
nsCOMPtr<nsIComponentRegistrar> registrar;
NS_GetComponentRegistrar(getter_AddRefs(registrar));
if (registrar)
{
if (registrar) {
nsCID *cid;
if (NS_SUCCEEDED(registrar->ContractIDToCID(str, &cid)))
{
if (NS_SUCCEEDED(registrar->ContractIDToCID(str, &cid))) {
success = idObj->mDetails.InitWithName(*cid, str);
nsMemory::Free(cid);
}
@ -711,14 +686,12 @@ GetIIDArg(PRUint32 argc, jsval* argv, JSContext* cx)
const nsID* iid;
// If an IID was passed in then use it
if (argc)
{
if (argc) {
JSObject* iidobj;
jsval val = *argv;
if (JSVAL_IS_PRIMITIVE(val) ||
!(iidobj = JSVAL_TO_OBJECT(val)) ||
!(iid = xpc_JSObjectToID(cx, iidobj)))
{
!(iid = xpc_JSObjectToID(cx, iidobj))) {
return nsnull;
}
}
@ -765,8 +738,7 @@ nsJSCID::CreateInstance(nsISupports **_retval)
nsIXPCSecurityManager* sm;
sm = xpcc->GetAppropriateSecurityManager(nsIXPCSecurityManager::HOOK_CREATE_INSTANCE);
if (sm && NS_FAILED(sm->CanCreateInstance(cx, mDetails.ID())))
{
if (sm && NS_FAILED(sm->CanCreateInstance(cx, mDetails.ID()))) {
NS_ERROR("how are we not being called from chrome here?");
return NS_OK;
}
@ -832,8 +804,7 @@ nsJSCID::GetService(nsISupports **_retval)
nsIXPCSecurityManager* sm;
sm = xpcc->GetAppropriateSecurityManager(nsIXPCSecurityManager::HOOK_GET_SERVICE);
if (sm && NS_FAILED(sm->CanCreateInstance(cx, mDetails.ID())))
{
if (sm && NS_FAILED(sm->CanCreateInstance(cx, mDetails.ID()))) {
NS_ASSERTION(JS_IsExceptionPending(cx),
"security manager vetoed GetService without setting exception");
return NS_OK;
@ -895,8 +866,7 @@ nsJSCID::HasInstance(nsIXPConnectWrappedNative *wrapper,
*bp = JS_FALSE;
nsresult rv = NS_OK;
if (!JSVAL_IS_PRIMITIVE(val))
{
if (!JSVAL_IS_PRIMITIVE(val)) {
// we have a JSObject
JSObject* obj = JSVAL_TO_OBJECT(val);
@ -916,8 +886,7 @@ nsJSCID::HasInstance(nsIXPConnectWrappedNative *wrapper,
// We consider CID equality to be the thing that matters here.
// This is perhaps debatable.
if (ci)
{
if (ci) {
nsID cid;
if (NS_SUCCEEDED(ci->GetClassIDNoAlloc(&cid)))
*bp = cid.Equals(mDetails.ID());
@ -936,18 +905,15 @@ xpc_NewIDObject(JSContext *cx, JSObject* jsobj, const nsID& aID)
nsCOMPtr<nsIJSID> iid =
dont_AddRef(static_cast<nsIJSID*>(nsJSID::NewID(aID)));
if (iid)
{
if (iid) {
nsXPConnect* xpc = nsXPConnect::GetXPConnect();
if (xpc)
{
if (xpc) {
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
nsresult rv = xpc->WrapNative(cx, jsobj,
static_cast<nsISupports*>(iid),
NS_GET_IID(nsIJSID),
getter_AddRefs(holder));
if (NS_SUCCEEDED(rv) && holder)
{
if (NS_SUCCEEDED(rv) && holder) {
holder->GetJSObject(&obj);
}
}
@ -968,8 +934,7 @@ xpc_JSObjectToID(JSContext *cx, JSObject* obj)
if (wrapper &&
(wrapper->HasInterfaceNoQI(NS_GET_IID(nsIJSID)) ||
wrapper->HasInterfaceNoQI(NS_GET_IID(nsIJSIID)) ||
wrapper->HasInterfaceNoQI(NS_GET_IID(nsIJSCID))))
{
wrapper->HasInterfaceNoQI(NS_GET_IID(nsIJSCID)))) {
return ((nsIJSID*)wrapper->GetIdentityObject())->GetID();
}
return nsnull;

View File

@ -106,10 +106,8 @@ WrappedJSDyingJSObjectFinder(JSDHashTable *table, JSDHashEntryHdr *hdr,
NS_ASSERTION(wrapper, "found a null JS wrapper!");
// walk the wrapper chain and find any whose JSObject is to be finalized
while (wrapper)
{
if (wrapper->IsSubjectToFinalization())
{
while (wrapper) {
if (wrapper->IsSubjectToFinalization()) {
js::AutoSwitchCompartment sc(data->cx,
wrapper->GetJSObjectPreserveColor());
if (JS_IsAboutToBeFinalized(data->cx,
@ -132,8 +130,7 @@ NativeInterfaceSweeper(JSDHashTable *table, JSDHashEntryHdr *hdr,
uint32 number, void *arg)
{
XPCNativeInterface* iface = ((IID2NativeInterfaceMap::Entry*)hdr)->value;
if (iface->IsMarked())
{
if (iface->IsMarked()) {
iface->Unmark();
return JS_DHASH_NEXT;
}
@ -168,8 +165,7 @@ NativeSetSweeper(JSDHashTable *table, JSDHashEntryHdr *hdr,
uint32 number, void *arg)
{
XPCNativeSet* set = ((NativeSetMap::Entry*)hdr)->key_value;
if (set->IsMarked())
{
if (set->IsMarked()) {
set->Unmark();
return JS_DHASH_NEXT;
}
@ -177,8 +173,7 @@ NativeSetSweeper(JSDHashTable *table, JSDHashEntryHdr *hdr,
#ifdef XPC_REPORT_NATIVE_INTERFACE_AND_SET_FLUSHING
printf("- Destroying XPCNativeSet for:\n");
PRUint16 count = set->GetInterfaceCount();
for (PRUint16 k = 0; k < count; k++)
{
for (PRUint16 k = 0; k < count; k++) {
XPCNativeInterface* iface = set->GetInterfaceAt(k);
fputs(" ", stdout);
JS_PutString(JSVAL_TO_STRING(iface->GetName()), stdout);
@ -196,8 +191,7 @@ JSClassSweeper(JSDHashTable *table, JSDHashEntryHdr *hdr,
{
XPCNativeScriptableShared* shared =
((XPCNativeScriptableSharedMap::Entry*) hdr)->key;
if (shared->IsMarked())
{
if (shared->IsMarked()) {
#ifdef off_XPC_REPORT_JSCLASS_FLUSHING
printf("+ Marked XPCNativeScriptableShared for: %s @ %x\n",
shared->GetJSClass()->name,
@ -243,15 +237,12 @@ static JSBool
ContextCallback(JSContext *cx, uintN operation)
{
XPCJSRuntime* self = nsXPConnect::GetRuntimeInstance();
if (self)
{
if (operation == JSCONTEXT_NEW)
{
if (self) {
if (operation == JSCONTEXT_NEW) {
if (!self->OnJSContextNew(cx))
return JS_FALSE;
}
else if (operation == JSCONTEXT_DESTROY)
{
else if (operation == JSCONTEXT_DESTROY) {
delete XPCContext::GetXPCContext(cx);
}
}
@ -276,8 +267,7 @@ CompartmentCallback(JSContext *cx, JSCompartment *compartment, uintN op)
if (!priv)
return JS_TRUE;
if (xpc::PtrAndPrincipalHashKey *key = priv->key)
{
if (xpc::PtrAndPrincipalHashKey *key = priv->key) {
XPCCompartmentMap &map = self->GetCompartmentMap();
#ifdef DEBUG
{
@ -288,8 +278,7 @@ CompartmentCallback(JSContext *cx, JSCompartment *compartment, uintN op)
#endif
map.Remove(key);
}
else
{
else {
nsISupports *ptr = priv->ptr;
XPCMTCompartmentMap &map = self->GetMTCompartmentMap();
#ifdef DEBUG
@ -348,8 +337,7 @@ void XPCJSRuntime::TraceBlackJS(JSTracer* trc, void* data)
// Skip this part if XPConnect is shutting down. We get into
// bad locking problems with the thread iteration otherwise.
if (!self->GetXPConnect()->IsShuttingDown())
{
if (!self->GetXPConnect()->IsShuttingDown()) {
Mutex* threadLock = XPCPerThreadData::GetLock();
if (threadLock)
{ // scoped lock
@ -359,8 +347,7 @@ void XPCJSRuntime::TraceBlackJS(JSTracer* trc, void* data)
XPCPerThreadData* thread;
while (nsnull != (thread =
XPCPerThreadData::IterateThreads(&iterp)))
{
XPCPerThreadData::IterateThreads(&iterp))) {
// Trace those AutoMarkingPtr lists!
thread->TraceJS(trc);
}
@ -391,8 +378,7 @@ static void
TraceJSObject(PRUint32 aLangID, void *aScriptThing, const char *name,
void *aClosure)
{
if (aLangID == nsIProgrammingLanguage::JAVASCRIPT)
{
if (aLangID == nsIProgrammingLanguage::JAVASCRIPT) {
JS_CALL_TRACER(static_cast<JSTracer*>(aClosure), aScriptThing,
js_GetGCThingTraceKind(aScriptThing), name);
}
@ -485,8 +471,7 @@ CheckParticipatesInCycleCollection(PRUint32 aLangID, void *aThing,
if (!closure->cycleCollectionEnabled &&
aLangID == nsIProgrammingLanguage::JAVASCRIPT &&
js_GetGCThingTraceKind(aThing) == JSTRACE_OBJECT)
{
js_GetGCThingTraceKind(aThing) == JSTRACE_OBJECT) {
closure->cycleCollectionEnabled =
xpc::ParticipatesInCycleCollection(closure->cx,
static_cast<JSObject*>(aThing));
@ -579,8 +564,7 @@ XPCJSRuntime::AddXPConnectRoots(JSContext* cx,
// collector.
JSContext *iter = nsnull, *acx;
while ((acx = JS_ContextIterator(GetJSRuntime(), &iter)))
{
while ((acx = JS_ContextIterator(GetJSRuntime(), &iter))) {
// Only skip JSContexts with outstanding requests if the
// callback does not want all traces (a debug feature).
// Otherwise, we do want to know about all JSContexts to get
@ -598,8 +582,7 @@ XPCJSRuntime::AddXPConnectRoots(JSContext* cx,
for (XPCRootSetElem *e = mVariantRoots; e ; e = e->GetNextRoot())
cb.NoteXPCOMRoot(static_cast<XPCTraceableVariant*>(e));
for (XPCRootSetElem *e = mWrappedJSRoots; e ; e = e->GetNextRoot())
{
for (XPCRootSetElem *e = mWrappedJSRoots; e ; e = e->GetNextRoot()) {
nsXPCWrappedJS *wrappedJS = static_cast<nsXPCWrappedJS*>(e);
JSObject *obj = wrappedJS->GetJSObjectPreserveColor();
@ -612,8 +595,7 @@ XPCJSRuntime::AddXPConnectRoots(JSContext* cx,
}
Closure closure = { cx, PR_TRUE, &cb };
if (mJSHolders.ops)
{
if (mJSHolders.ops) {
JS_DHashTableEnumerate(&mJSHolders, NoteJSHolder, &closure);
}
@ -624,11 +606,9 @@ XPCJSRuntime::AddXPConnectRoots(JSContext* cx,
template<class T> static void
DoDeferredRelease(nsTArray<T> &array)
{
while (1)
{
while (1) {
PRUint32 count = array.Length();
if (!count)
{
if (!count) {
array.Compact();
break;
}
@ -679,12 +659,10 @@ JSBool XPCJSRuntime::GCCallback(JSContext *cx, JSGCStatus status)
if (!self)
return JS_TRUE;
switch (status)
{
switch (status) {
case JSGC_BEGIN:
{
if (!NS_IsMainThread())
{
if (!NS_IsMainThread()) {
return JS_FALSE;
}
@ -770,8 +748,7 @@ JSBool XPCJSRuntime::GCCallback(JSContext *cx, JSGCStatus status)
// Skip this part if XPConnect is shutting down. We get into
// bad locking problems with the thread iteration otherwise.
if (!self->GetXPConnect()->IsShuttingDown())
{
if (!self->GetXPConnect()->IsShuttingDown()) {
Mutex* threadLock = XPCPerThreadData::GetLock();
if (threadLock)
{ // scoped lock
@ -781,26 +758,22 @@ JSBool XPCJSRuntime::GCCallback(JSContext *cx, JSGCStatus status)
XPCPerThreadData* thread;
while (nsnull != (thread =
XPCPerThreadData::IterateThreads(&iterp)))
{
XPCPerThreadData::IterateThreads(&iterp))) {
// Mark those AutoMarkingPtr lists!
thread->MarkAutoRootsAfterJSFinalize();
XPCCallContext* ccxp = thread->GetCallContext();
while (ccxp)
{
while (ccxp) {
// Deal with the strictness of callcontext that
// complains if you ask for a set when
// it is in a state where the set could not
// possibly be valid.
if (ccxp->CanGetSet())
{
if (ccxp->CanGetSet()) {
XPCNativeSet* set = ccxp->GetSet();
if (set)
set->Mark();
}
if (ccxp->CanGetInterface())
{
if (ccxp->CanGetInterface()) {
XPCNativeInterface* iface = ccxp->GetInterface();
if (iface)
iface->Mark();
@ -816,8 +789,7 @@ JSBool XPCJSRuntime::GCCallback(JSContext *cx, JSGCStatus status)
// We don't want to sweep the JSClasses at shutdown time.
// At this point there may be JSObjects using them that have
// been removed from the other maps.
if (!self->GetXPConnect()->IsShuttingDown())
{
if (!self->GetXPConnect()->IsShuttingDown()) {
self->mNativeScriptableSharedMap->
Enumerate(JSClassSweeper, nsnull);
}
@ -864,11 +836,9 @@ JSBool XPCJSRuntime::GCCallback(JSContext *cx, JSGCStatus status)
// Skip this part if XPConnect is shutting down. We get into
// bad locking problems with the thread iteration otherwise.
if (!self->GetXPConnect()->IsShuttingDown())
{
if (!self->GetXPConnect()->IsShuttingDown()) {
Mutex* threadLock = XPCPerThreadData::GetLock();
if (threadLock)
{
if (threadLock) {
// Do the marking...
{ // scoped lock
@ -878,17 +848,14 @@ JSBool XPCJSRuntime::GCCallback(JSContext *cx, JSGCStatus status)
XPCPerThreadData* thread;
while (nsnull != (thread =
XPCPerThreadData::IterateThreads(&iterp)))
{
XPCPerThreadData::IterateThreads(&iterp))) {
XPCCallContext* ccxp = thread->GetCallContext();
while (ccxp)
{
while (ccxp) {
// Deal with the strictness of callcontext that
// complains if you ask for a tearoff when
// it is in a state where the tearoff could not
// possibly be valid.
if (ccxp->CanGetTearOff())
{
if (ccxp->CanGetTearOff()) {
XPCWrappedNativeTearOff* to =
ccxp->GetTearOff();
if (to)
@ -987,13 +954,11 @@ XPCJSRuntime::WatchdogMain(void *arg)
AutoLockJSGC lock(self->mJSRuntime);
PRIntervalTime sleepInterval;
while (self->mWatchdogThread)
{
while (self->mWatchdogThread) {
// Sleep only 1 second if recently (or currently) active; otherwise, hibernate
if (self->mLastActiveTime == -1 || PR_Now() - self->mLastActiveTime <= PRTime(2*PR_USEC_PER_SEC))
sleepInterval = PR_TicksPerSecond();
else
{
else {
sleepInterval = PR_INTERVAL_NO_TIMEOUT;
self->mWatchdogHibernating = PR_TRUE;
}
@ -1003,8 +968,7 @@ XPCJSRuntime::WatchdogMain(void *arg)
PR_WaitCondVar(self->mWatchdogWakeup, sleepInterval);
JS_ASSERT(status == PR_SUCCESS);
JSContext* cx = nsnull;
while ((cx = js_NextActiveContext(self->mJSRuntime, cx)))
{
while ((cx = js_NextActiveContext(self->mJSRuntime, cx))) {
js::TriggerOperationCallback(cx);
}
}
@ -1020,8 +984,7 @@ XPCJSRuntime::ActivityCallback(void *arg, JSBool active)
XPCJSRuntime* self = static_cast<XPCJSRuntime*>(arg);
if (active) {
self->mLastActiveTime = -1;
if (self->mWatchdogHibernating)
{
if (self->mWatchdogHibernating) {
self->mWatchdogHibernating = PR_FALSE;
PR_NotifyCondVar(self->mWatchdogWakeup);
}
@ -1091,8 +1054,7 @@ XPCJSRuntime::GetJSCycleCollectionContext()
XPCJSRuntime::~XPCJSRuntime()
{
if (mWatchdogWakeup)
{
if (mWatchdogWakeup) {
// If the watchdog thread is running, tell it to terminate waking it
// up if necessary and wait until it signals that it finished. As we
// must release the lock before calling PR_DestroyCondVar, we use an
@ -1109,8 +1071,7 @@ XPCJSRuntime::~XPCJSRuntime()
mWatchdogWakeup = nsnull;
}
if (mJSCycleCollectionContext)
{
if (mJSCycleCollectionContext) {
JS_SetContextThread(mJSCycleCollectionContext);
JS_DestroyContextNoGC(mJSCycleCollectionContext);
}
@ -1128,8 +1089,7 @@ XPCJSRuntime::~XPCJSRuntime()
#endif
// clean up and destroy maps...
if (mWrappedJSMap)
{
if (mWrappedJSMap) {
#ifdef XPC_DUMP_AT_SHUTDOWN
uint32 count = mWrappedJSMap->Count();
if (count)
@ -1139,8 +1099,7 @@ XPCJSRuntime::~XPCJSRuntime()
delete mWrappedJSMap;
}
if (mWrappedJSClassMap)
{
if (mWrappedJSClassMap) {
#ifdef XPC_DUMP_AT_SHUTDOWN
uint32 count = mWrappedJSClassMap->Count();
if (count)
@ -1149,8 +1108,7 @@ XPCJSRuntime::~XPCJSRuntime()
delete mWrappedJSClassMap;
}
if (mIID2NativeInterfaceMap)
{
if (mIID2NativeInterfaceMap) {
#ifdef XPC_DUMP_AT_SHUTDOWN
uint32 count = mIID2NativeInterfaceMap->Count();
if (count)
@ -1159,8 +1117,7 @@ XPCJSRuntime::~XPCJSRuntime()
delete mIID2NativeInterfaceMap;
}
if (mClassInfo2NativeSetMap)
{
if (mClassInfo2NativeSetMap) {
#ifdef XPC_DUMP_AT_SHUTDOWN
uint32 count = mClassInfo2NativeSetMap->Count();
if (count)
@ -1169,8 +1126,7 @@ XPCJSRuntime::~XPCJSRuntime()
delete mClassInfo2NativeSetMap;
}
if (mNativeSetMap)
{
if (mNativeSetMap) {
#ifdef XPC_DUMP_AT_SHUTDOWN
uint32 count = mNativeSetMap->Count();
if (count)
@ -1182,8 +1138,7 @@ XPCJSRuntime::~XPCJSRuntime()
if (mMapLock)
XPCAutoLock::DestroyLock(mMapLock);
if (mThisTranslatorMap)
{
if (mThisTranslatorMap) {
#ifdef XPC_DUMP_AT_SHUTDOWN
uint32 count = mThisTranslatorMap->Count();
if (count)
@ -1193,8 +1148,7 @@ XPCJSRuntime::~XPCJSRuntime()
}
#ifdef XPC_CHECK_WRAPPERS_AT_SHUTDOWN
if (DEBUG_WrappedNativeHashtable)
{
if (DEBUG_WrappedNativeHashtable) {
int LiveWrapperCount = 0;
JS_DHashTableEnumerate(DEBUG_WrappedNativeHashtable,
DEBUG_WrapperChecker, &LiveWrapperCount);
@ -1204,8 +1158,7 @@ XPCJSRuntime::~XPCJSRuntime()
}
#endif
if (mNativeScriptableSharedMap)
{
if (mNativeScriptableSharedMap) {
#ifdef XPC_DUMP_AT_SHUTDOWN
uint32 count = mNativeScriptableSharedMap->Count();
if (count)
@ -1214,8 +1167,7 @@ XPCJSRuntime::~XPCJSRuntime()
delete mNativeScriptableSharedMap;
}
if (mDyingWrappedNativeProtoMap)
{
if (mDyingWrappedNativeProtoMap) {
#ifdef XPC_DUMP_AT_SHUTDOWN
uint32 count = mDyingWrappedNativeProtoMap->Count();
if (count)
@ -1224,8 +1176,7 @@ XPCJSRuntime::~XPCJSRuntime()
delete mDyingWrappedNativeProtoMap;
}
if (mDetachedWrappedNativeProtoMap)
{
if (mDetachedWrappedNativeProtoMap) {
#ifdef XPC_DUMP_AT_SHUTDOWN
uint32 count = mDetachedWrappedNativeProtoMap->Count();
if (count)
@ -1234,8 +1185,7 @@ XPCJSRuntime::~XPCJSRuntime()
delete mDetachedWrappedNativeProtoMap;
}
if (mExplicitNativeWrapperMap)
{
if (mExplicitNativeWrapperMap) {
#ifdef XPC_DUMP_AT_SHUTDOWN
uint32 count = mExplicitNativeWrapperMap->Count();
if (count)
@ -1249,14 +1199,12 @@ XPCJSRuntime::~XPCJSRuntime()
XPCConvert::RemoveXPCOMUCStringFinalizer();
if (mJSHolders.ops)
{
if (mJSHolders.ops) {
JS_DHashTableFinish(&mJSHolders);
mJSHolders.ops = nsnull;
}
if (mJSRuntime)
{
if (mJSRuntime) {
JS_DestroyRuntime(mJSRuntime);
JS_ShutDown();
#ifdef DEBUG_shaver_off
@ -1274,8 +1222,7 @@ namespace {
PRInt64
GetCompartmentTjitCodeSize(JSCompartment *c)
{
if (c->hasTraceMonitor())
{
if (c->hasTraceMonitor()) {
size_t total, frag_size, free_size;
c->traceMonitor()->getCodeAllocStats(total, frag_size, free_size);
return total;
@ -1360,8 +1307,7 @@ CellCallback(JSContext *cx, void *vdata, void *thing, JSGCTraceKind traceKind,
IterateData *data = static_cast<IterateData *>(vdata);
CompartmentStats *curr = data->currCompartmentStats;
curr->gcHeapKinds[traceKind] += thingSize;
switch (traceKind)
{
switch (traceKind) {
case JSTRACE_OBJECT:
{
JSObject *obj = static_cast<JSObject *>(thing);
@ -1541,24 +1487,19 @@ CompartmentStats::CompartmentStats(JSContext *cx, JSCompartment *c)
{
memset(this, 0, sizeof(*this));
if (c == cx->runtime->atomsCompartment)
{
if (c == cx->runtime->atomsCompartment) {
name.AssignLiteral("atoms");
}
else if (c->principals)
{
if (c->principals->codebase)
{
else if (c->principals) {
if (c->principals->codebase) {
name.Assign(c->principals->codebase);
// If it's the system compartment, append the address.
// This means that multiple system compartments (and there
// can be many) can be distinguished.
if (c->isSystemCompartment)
{
if (c->isSystemCompartment) {
if (c->data &&
!((xpc::CompartmentPrivate*)c->data)->location.IsEmpty())
{
!((xpc::CompartmentPrivate*)c->data)->location.IsEmpty()) {
name.AppendLiteral(", ");
name.Append(((xpc::CompartmentPrivate*)c->data)->location);
}
@ -1574,13 +1515,11 @@ CompartmentStats::CompartmentStats(JSContext *cx, JSCompartment *c)
// (such as about:memory) have to undo this change.
name.ReplaceChar('/', '\\');
}
else
{
else {
name.AssignLiteral("null-codebase");
}
}
else
{
else {
name.AssignLiteral("null-principal");
}
}
@ -1589,8 +1528,7 @@ JSBool
CollectCompartmentStatsForRuntime(JSRuntime *rt, IterateData *data)
{
JSContext *cx = JS_NewContext(rt, 0);
if (!cx)
{
if (!cx) {
NS_ERROR("couldn't create context for memory tracing");
return false;
}
@ -1632,8 +1570,7 @@ CollectCompartmentStatsForRuntime(JSRuntime *rt, IterateData *data)
for (PRUint32 index = 0;
index < data->compartmentStatsVector.Length();
index++)
{
index++) {
CompartmentStats &stats = data->compartmentStatsVector[index];
PRInt64 used = stats.gcHeapArenaHeaders +
@ -1892,8 +1829,7 @@ ReportJSRuntimeStats(const IterateData &data, const nsACString &pathPrefix,
{
for (PRUint32 index = 0;
index < data.compartmentStatsVector.Length();
index++)
{
index++) {
ReportCompartmentStats(data.compartmentStatsVector[index], pathPrefix,
callback, closure);
}
@ -2161,8 +2097,7 @@ XPCJSRuntime::newXPCJSRuntime(nsXPConnect* aXPConnect)
self->GetDyingWrappedNativeProtoMap() &&
self->GetExplicitNativeWrapperMap() &&
self->GetMapLock() &&
self->mWatchdogThread)
{
self->mWatchdogThread) {
return self;
}
@ -2179,18 +2114,15 @@ XPCJSRuntime::OnJSContextNew(JSContext *cx)
// if it is our first context then we need to generate our string ids
JSBool ok = JS_TRUE;
if (JSID_IS_VOID(mStrIDs[0]))
{
if (JSID_IS_VOID(mStrIDs[0])) {
JS_SetGCParameterForThread(cx, JSGC_MAX_CODE_CACHE_BYTES, 16 * 1024 * 1024);
{
// Scope the JSAutoRequest so it goes out of scope before calling
// mozilla::dom::binding::DefineStaticJSVals.
JSAutoRequest ar(cx);
for (uintN i = 0; i < IDX_TOTAL_COUNT; i++)
{
for (uintN i = 0; i < IDX_TOTAL_COUNT; i++) {
JSString* str = JS_InternString(cx, mStrings[i]);
if (!str || !JS_ValueToId(cx, STRING_TO_JSVAL(str), &mStrIDs[i]))
{
if (!str || !JS_ValueToId(cx, STRING_TO_JSVAL(str), &mStrIDs[i])) {
mStrIDs[0] = JSID_VOID;
ok = JS_FALSE;
break;
@ -2225,8 +2157,7 @@ XPCJSRuntime::DeferredRelease(nsISupports* obj)
{
NS_ASSERTION(obj, "bad param");
if (mNativesToReleaseArray.IsEmpty())
{
if (mNativesToReleaseArray.IsEmpty()) {
// This array sometimes has 1000's
// of entries, and usually has 50-200 entries. Avoid lots
// of incremental grows. We compact it down when we're done.
@ -2283,8 +2214,7 @@ XPCJSRuntime::DebugDump(PRInt16 depth)
XPC_LOG_ALWAYS(("%d JS context(s)", cxCount));
iter = nsnull;
while (JS_ContextIterator(mJSRuntime, &iter))
{
while (JS_ContextIterator(mJSRuntime, &iter)) {
XPCContext *xpc = XPCContext::GetXPCContext(iter);
XPC_LOG_INDENT();
xpc->DebugDump(depth);
@ -2295,8 +2225,7 @@ XPCJSRuntime::DebugDump(PRInt16 depth)
mWrappedJSClassMap, mWrappedJSClassMap ? \
mWrappedJSClassMap->Count() : 0));
// iterate wrappersclasses...
if (depth && mWrappedJSClassMap && mWrappedJSClassMap->Count())
{
if (depth && mWrappedJSClassMap && mWrappedJSClassMap->Count()) {
XPC_LOG_INDENT();
mWrappedJSClassMap->Enumerate(WrappedJSClassMapDumpEnumerator, &depth);
XPC_LOG_OUTDENT();
@ -2305,8 +2234,7 @@ XPCJSRuntime::DebugDump(PRInt16 depth)
mWrappedJSMap, mWrappedJSMap ? \
mWrappedJSMap->Count() : 0));
// iterate wrappers...
if (depth && mWrappedJSMap && mWrappedJSMap->Count())
{
if (depth && mWrappedJSMap && mWrappedJSMap->Count()) {
XPC_LOG_INDENT();
mWrappedJSMap->Enumerate(WrappedJSMapDumpEnumerator, &depth);
XPC_LOG_OUTDENT();
@ -2329,8 +2257,7 @@ XPCJSRuntime::DebugDump(PRInt16 depth)
mNativeSetMap->Count() : 0));
// iterate sets...
if (depth && mNativeSetMap && mNativeSetMap->Count())
{
if (depth && mNativeSetMap && mNativeSetMap->Count()) {
XPC_LOG_INDENT();
mNativeSetMap->Enumerate(NativeSetDumpEnumerator, &depth);
XPC_LOG_OUTDENT();
@ -2351,8 +2278,7 @@ XPCRootSetElem::AddToRootSet(XPCLock *lock, XPCRootSetElem **listHead)
mSelfp = listHead;
mNext = *listHead;
if (mNext)
{
if (mNext) {
NS_ASSERTION(mNext->mSelfp == listHead, "Must be list start");
mNext->mSelfp = &mNext;
}

View File

@ -123,16 +123,14 @@ xpcJSWeakReference::Get()
wrappedObj) {
JSObject *obj;
wrappedObj->GetJSObject(&obj);
if (obj)
{
if (obj) {
// Most users of XPCWrappedJS don't need to worry about
// re-wrapping because things are implicitly rewrapped by
// xpcconvert. However, because we're doing this directly
// through the native call context, we need to call
// JS_WrapObject().
if (!JS_WrapObject(cx, &obj))
{
if (!JS_WrapObject(cx, &obj)) {
return NS_ERROR_FAILURE;
}

View File

@ -60,8 +60,7 @@ static bool Init()
{
g_LogMod = PR_NewLogModule("xpclog");
g_Spaces = new char[SPACE_COUNT+1];
if (!g_LogMod || !g_Spaces || !PR_LOG_TEST(g_LogMod,1))
{
if (!g_LogMod || !g_Spaces || !PR_LOG_TEST(g_LogMod,1)) {
g_InitState = 1;
XPC_Log_Finish();
return PR_FALSE;
@ -75,8 +74,7 @@ static bool Init()
void
XPC_Log_Finish()
{
if (g_InitState == 1)
{
if (g_InitState == 1) {
delete [] g_Spaces;
// we'd like to properly cleanup the LogModule, but nspr owns that
g_LogMod = nsnull;
@ -132,8 +130,7 @@ void
LogSlimWrapperWillMorph(JSContext *cx, JSObject *obj, const char *propname,
const char *functionName)
{
if (obj && IS_SLIM_WRAPPER(obj))
{
if (obj && IS_SLIM_WRAPPER(obj)) {
XPCNativeScriptableInfo *si =
GetSlimWrapperProto(obj)->GetScriptableInfo();
printf("***** morphing %s from %s", si->GetJSClass()->name,

View File

@ -117,8 +117,7 @@ extern void LogSlimWrapperNotCreated(JSContext *cx, nsISupports *obj,
#define SLIM_LOG_WILL_MORPH_FOR_ID(cx, obj, id) \
PR_BEGIN_MACRO \
JSString* strId = ::JS_ValueToString(cx, id); \
if (strId) \
{ \
if (strId) { \
NS_ConvertUTF16toUTF8 name((PRUnichar*)::JS_GetStringChars(strId), \
::JS_GetStringLength(strId)); \
LOG_WILL_MORPH_FOR_PROP(cx, obj, name.get()); \

View File

@ -74,43 +74,36 @@ HashNativeKey(JSDHashTable *table, const void *key)
XPCNativeInterface* Addition;
PRUint16 Position;
if (Key->IsAKey())
{
if (Key->IsAKey()) {
Set = Key->GetBaseSet();
Addition = Key->GetAddition();
Position = Key->GetPosition();
}
else
{
else {
Set = (XPCNativeSet*) Key;
Addition = nsnull;
Position = 0;
}
if (!Set)
{
if (!Set) {
NS_ASSERTION(Addition, "bad key");
// This would be an XOR like below.
// But "0 ^ x == x". So it does not matter.
h = (JSHashNumber) NS_PTR_TO_INT32(Addition) >> 2;
}
else
{
else {
XPCNativeInterface** Current = Set->GetInterfaceArray();
PRUint16 count = Set->GetInterfaceCount();
if (Addition)
{
if (Addition) {
count++;
for (PRUint16 i = 0; i < count; i++)
{
for (PRUint16 i = 0; i < count; i++) {
if (i == Position)
h ^= (JSHashNumber) NS_PTR_TO_INT32(Addition) >> 2;
else
h ^= (JSHashNumber) NS_PTR_TO_INT32(*(Current++)) >> 2;
}
}
else
{
else {
for (PRUint16 i = 0; i < count; i++)
h ^= (JSHashNumber) NS_PTR_TO_INT32(*(Current++)) >> 2;
}
@ -307,8 +300,7 @@ NativeSetMap::Entry::Match(JSDHashTable *table,
XPCNativeSetKey* Key = (XPCNativeSetKey*) key;
// See the comment in the XPCNativeSetKey declaration in xpcprivate.h.
if (!Key->IsAKey())
{
if (!Key->IsAKey()) {
XPCNativeSet* Set1 = (XPCNativeSet*) key;
XPCNativeSet* Set2 = ((Entry*)entry)->key_value;
@ -321,8 +313,7 @@ NativeSetMap::Entry::Match(JSDHashTable *table,
XPCNativeInterface** Current1 = Set1->GetInterfaceArray();
XPCNativeInterface** Current2 = Set2->GetInterfaceArray();
for (PRUint16 i = 0; i < count; i++)
{
for (PRUint16 i = 0; i < count; i++) {
if (*(Current1++) != *(Current2++))
return JS_FALSE;
}
@ -334,8 +325,7 @@ NativeSetMap::Entry::Match(JSDHashTable *table,
XPCNativeSet* Set = Key->GetBaseSet();
XPCNativeInterface* Addition = Key->GetAddition();
if (!Set)
{
if (!Set) {
// This is a special case to deal with the invariant that says:
// "All sets have exactly one nsISupports interface and it comes first."
// See XPCNativeSet::NewInstance for details.
@ -361,15 +351,12 @@ NativeSetMap::Entry::Match(JSDHashTable *table,
PRUint16 Position = Key->GetPosition();
XPCNativeInterface** CurrentInTable = SetInTable->GetInterfaceArray();
XPCNativeInterface** Current = Set->GetInterfaceArray();
for (PRUint16 i = 0; i < count; i++)
{
if (Addition && i == Position)
{
for (PRUint16 i = 0; i < count; i++) {
if (Addition && i == Position) {
if (Addition != *(CurrentInTable++))
return JS_FALSE;
}
else
{
else {
if (*(Current++) != *(CurrentInTable++))
return JS_FALSE;
}
@ -561,8 +548,7 @@ XPCNativeScriptableSharedMap::GetNewOrUsed(JSUint32 flags,
XPCNativeScriptableShared* shared = entry->key;
if (!shared)
{
if (!shared) {
entry->key = shared =
new XPCNativeScriptableShared(flags, key.TransferNameOwnership(),
interfacesBitmap);
@ -664,13 +650,11 @@ WrappedNative2WrapperMap::MoveLink(JSDHashTable* table,
newEntry->key = oldEntry->key;
// Now update the list.
if (PR_CLIST_IS_EMPTY(&oldEntry->value))
{
if (PR_CLIST_IS_EMPTY(&oldEntry->value)) {
PR_INIT_CLIST(&newEntry->value);
newEntry->value.obj = oldEntry->value.obj;
}
else
{
else {
newEntry->value = oldEntry->value;
newEntry->value.next->prev = &newEntry->value;
newEntry->value.prev->next = &newEntry->value;
@ -715,8 +699,7 @@ WrappedNative2WrapperMap::Add(WrappedNative2WrapperMap* head,
NS_ASSERTION(!l->obj, "Uh, how'd this happen?");
if (!l->next)
{
if (!l->next) {
// Initialize the circular list. This case only happens when
// this == head.
PR_INIT_CLIST(l);
@ -724,11 +707,9 @@ WrappedNative2WrapperMap::Add(WrappedNative2WrapperMap* head,
l->obj = wrapper;
if (this != head)
{
if (this != head) {
Link* headLink = head->FindLink(wrappedObject);
if (!headLink)
{
if (!headLink) {
Entry* dummy = (Entry*)
JS_DHashTableOperate(head->mTable, wrappedObject, JS_DHASH_ADD);
dummy->key = wrappedObject;

View File

@ -49,8 +49,7 @@ static inline QITableEntry *
GetOffsets(nsISupports *identity, XPCWrappedNativeProto* proto)
{
QITableEntry* offsets = proto ? proto->GetOffsets() : nsnull;
if (!offsets)
{
if (!offsets) {
static NS_DEFINE_IID(kThisPtrOffsetsSID, NS_THISPTROFFSETS_SID);
identity->QueryInterface(kThisPtrOffsetsSID, (void**)&offsets);
}
@ -87,8 +86,7 @@ LookupInterfaceOrAncestor(PRUint32 tableSize, const xpc_qsHashEntry *table,
const nsID &iid)
{
const xpc_qsHashEntry *entry = LookupEntry(tableSize, table, iid);
if (!entry)
{
if (!entry) {
/*
* On a miss, we have to search for every interface the object
* supports, including ancestors.
@ -98,13 +96,11 @@ LookupInterfaceOrAncestor(PRUint32 tableSize, const xpc_qsHashEntry *table,
return nsnull;
const nsIID *piid;
for (;;)
{
for (;;) {
nsCOMPtr<nsIInterfaceInfo> parent;
if (NS_FAILED(info->GetParent(getter_AddRefs(parent))) ||
!parent ||
NS_FAILED(parent->GetIIDShared(&piid)))
{
NS_FAILED(parent->GetIIDShared(&piid))) {
break;
}
entry = LookupEntry(tableSize, table, *piid);
@ -223,8 +219,7 @@ ReifyPropertyOps(JSContext *cx, JSObject *obj, jsid id, uintN orig_attrs,
uintN attrs = JSPROP_SHARED | (orig_attrs & JSPROP_ENUMERATE);
JSObject *getterobj;
if (getter)
{
if (getter) {
getterobj = GeneratePropertyOp(cx, obj, id, 0, getter);
if (!getterobj)
return JS_FALSE;
@ -235,8 +230,7 @@ ReifyPropertyOps(JSContext *cx, JSObject *obj, jsid id, uintN orig_attrs,
getterobj = nsnull;
JSObject *setterobj;
if (setter)
{
if (setter) {
setterobj = GeneratePropertyOp(cx, obj, id, 1, setter);
if (!setterobj)
return JS_FALSE;
@ -261,8 +255,7 @@ LookupGetterOrSetter(JSContext *cx, JSBool wantGetter, uintN argc, jsval *vp)
{
XPC_QS_ASSERT_CONTEXT_OK(cx);
if (argc == 0)
{
if (argc == 0) {
JS_SET_RVAL(cx, vp, JSVAL_VOID);
return JS_TRUE;
}
@ -279,26 +272,21 @@ LookupGetterOrSetter(JSContext *cx, JSBool wantGetter, uintN argc, jsval *vp)
return JS_FALSE;
// No property at all means no getters or setters possible.
if (!desc.obj)
{
if (!desc.obj) {
JS_SET_RVAL(cx, vp, JSVAL_VOID);
return JS_TRUE;
}
// Inline obj_lookup[GS]etter here.
if (wantGetter)
{
if (desc.attrs & JSPROP_GETTER)
{
if (wantGetter) {
if (desc.attrs & JSPROP_GETTER) {
JS_SET_RVAL(cx, vp,
OBJECT_TO_JSVAL(JS_FUNC_TO_DATA_PTR(JSObject *, desc.getter)));
return JS_TRUE;
}
}
else
{
if (desc.attrs & JSPROP_SETTER)
{
else {
if (desc.attrs & JSPROP_SETTER) {
JS_SET_RVAL(cx, vp,
OBJECT_TO_JSVAL(JS_FUNC_TO_DATA_PTR(JSObject *, desc.setter)));
return JS_TRUE;
@ -314,16 +302,14 @@ LookupGetterOrSetter(JSContext *cx, JSBool wantGetter, uintN argc, jsval *vp)
!IS_PROTO_CLASS(js::GetObjectClass(desc.obj)) ||
(desc.attrs & (JSPROP_GETTER | JSPROP_SETTER)) ||
!(desc.getter || desc.setter) ||
desc.setter == js::GetObjectJSClass(desc.obj)->setProperty)
{
desc.setter == js::GetObjectJSClass(desc.obj)->setProperty) {
JS_SET_RVAL(cx, vp, JSVAL_VOID);
return JS_TRUE;
}
JSObject *getterobj, *setterobj;
if (!ReifyPropertyOps(cx, desc.obj, id, desc.attrs, desc.getter, desc.setter,
&getterobj, &setterobj))
{
&getterobj, &setterobj)) {
return JS_FALSE;
}
@ -415,22 +401,17 @@ xpc_qsDefineQuickStubs(JSContext *cx, JSObject *proto, uintN flags,
* front of 'interfaces' overwrite those toward the back.
*/
bool definedProperty = false;
for (uint32 i = ifacec; i-- != 0;)
{
for (uint32 i = ifacec; i-- != 0;) {
const nsID &iid = *interfaces[i];
const xpc_qsHashEntry *entry =
LookupInterfaceOrAncestor(tableSize, table, iid);
if (entry)
{
for (;;)
{
if (entry) {
for (;;) {
// Define quick stubs for attributes.
const xpc_qsPropertySpec *ps = entry->properties;
if (ps)
{
for (; ps->name; ps++)
{
if (ps) {
for (; ps->name; ps++) {
definedProperty = PR_TRUE;
if (!JS_DefineProperty(cx, proto, ps->name, JSVAL_VOID,
ps->getter, ps->setter,
@ -441,10 +422,8 @@ xpc_qsDefineQuickStubs(JSContext *cx, JSObject *proto, uintN flags,
// Define quick stubs for methods.
const xpc_qsFunctionSpec *fs = entry->functions;
if (fs)
{
for (; fs->name; fs++)
{
if (fs) {
for (; fs->name; fs++) {
if (!JS_DefineFunction(cx, proto, fs->name,
reinterpret_cast<JSNative>(fs->native),
fs->arity, flags))
@ -453,10 +432,8 @@ xpc_qsDefineQuickStubs(JSContext *cx, JSObject *proto, uintN flags,
}
const xpc_qsTraceableSpec *ts = entry->traceables;
if (ts)
{
for (; ts->name; ts++)
{
if (ts) {
for (; ts->name; ts++) {
if (!JS_DefineFunction(cx, proto, ts->name, ts->native, ts->arity,
flags | JSFUN_STUB_GSOPS | JSFUN_TRCINFO))
return JS_FALSE;
@ -516,20 +493,16 @@ GetMemberInfo(JSObject *obj, jsid memberId, const char **ifaceName)
js::GetObjectClass(obj) == &XPC_WN_Tearoff_JSClass,
"obj must be a wrapper");
XPCWrappedNativeProto *proto;
if (IS_SLIM_WRAPPER(obj))
{
if (IS_SLIM_WRAPPER(obj)) {
proto = GetSlimWrapperProto(obj);
}
else
{
else {
XPCWrappedNative *wrapper = (XPCWrappedNative *) js::GetObjectPrivate(obj);
proto = wrapper->GetProto();
}
if (proto)
{
if (proto) {
XPCNativeSet *set = proto->GetSet();
if (set)
{
if (set) {
XPCNativeMember *member;
XPCNativeInterface *iface;
@ -575,8 +548,7 @@ ThrowCallFailed(JSContext *cx, nsresult rv,
// else...
if (!nsXPCException::NameAndFormatForNSResult(NS_ERROR_XPC_NATIVE_RETURNED_FAILURE, nsnull, &format) ||
!format)
{
!format) {
format = "";
}
@ -587,13 +559,11 @@ ThrowCallFailed(JSContext *cx, nsresult rv,
: "unknown";
}
if (nsXPCException::NameAndFormatForNSResult(rv, &name, nsnull)
&& name)
{
&& name) {
sz = JS_smprintf("%s 0x%x (%s) [%s.%s]",
format, rv, name, ifaceName, memberName);
}
else
{
else {
sz = JS_smprintf("%s 0x%x [%s.%s]",
format, rv, ifaceName, memberName);
}
@ -743,15 +713,13 @@ xpc_qsACString::xpc_qsACString(JSContext *cx, jsval v, jsval *pval,
return;
size_t len = JS_GetStringEncodingLength(cx, s);
if (len == size_t(-1))
{
if (len == size_t(-1)) {
mValid = JS_FALSE;
return;
}
JSAutoByteString bytes(cx, s);
if (!bytes)
{
if (!bytes) {
mValid = JS_FALSE;
return;
}
@ -789,12 +757,9 @@ getNative(nsISupports *idobj,
jsval *vp)
{
// Try using the QITableEntry to avoid the extra AddRef and Release.
if (entries)
{
for (QITableEntry* e = entries; e->iid; e++)
{
if (e->iid->Equals(iid))
{
if (entries) {
for (QITableEntry* e = entries; e->iid; e++) {
if (e->iid->Equals(iid)) {
*ppThis = (char*) idobj + e->offset - entries[0].offset;
*vp = OBJECT_TO_JSVAL(obj);
*pThisRef = nsnull;
@ -832,8 +797,7 @@ getWrapper(JSContext *cx,
XPCWrappedNativeTearOff **tearoff)
{
if (XPCWrapper::IsSecurityWrapper(obj) &&
!(obj = XPCWrapper::Unwrap(cx, obj)))
{
!(obj = XPCWrapper::Unwrap(cx, obj))) {
return NS_ERROR_XPC_SECURITY_MANAGER_VETO;
}
@ -858,8 +822,7 @@ castNative(JSContext *cx,
jsval *vp,
XPCLazyCallContext *lccx)
{
if (wrapper)
{
if (wrapper) {
nsresult rv = getNativeFromWrapper(cx,wrapper, iid, ppThis, pThisRef,
vp);
@ -869,27 +832,22 @@ castNative(JSContext *cx,
if (rv != NS_ERROR_NO_INTERFACE)
return rv;
}
else if (cur)
{
else if (cur) {
nsISupports *native;
QITableEntry *entries;
if (IS_SLIM_WRAPPER(cur))
{
if (IS_SLIM_WRAPPER(cur)) {
native = static_cast<nsISupports*>(xpc_GetJSPrivate(cur));
entries = GetOffsetsFromSlimWrapper(cur);
}
else
{
else {
NS_ABORT_IF_FALSE(mozilla::dom::binding::instanceIsProxy(cur),
"what kind of wrapper is this?");
native = static_cast<nsISupports*>(js::GetProxyPrivate(cur).toPrivate());
entries = nsnull;
}
if (NS_SUCCEEDED(getNative(native, entries, cur, iid, ppThis, pThisRef, vp)))
{
if (lccx)
{
if (NS_SUCCEEDED(getNative(native, entries, cur, iid, ppThis, pThisRef, vp))) {
if (lccx) {
// This only matters for unwrapping of this objects, so we
// shouldn't end up here for the new DOM bindings.
NS_ABORT_IF_FALSE(IS_SLIM_WRAPPER(cur),
@ -927,15 +885,13 @@ xpc_qsUnwrapThisFromCcxImpl(XPCCallContext &ccx,
JSObject*
xpc_qsUnwrapObj(jsval v, nsISupports **ppArgRef, nsresult *rv)
{
if (JSVAL_IS_VOID(v) || JSVAL_IS_NULL(v))
{
if (JSVAL_IS_VOID(v) || JSVAL_IS_NULL(v)) {
*ppArgRef = nsnull;
*rv = NS_OK;
return nsnull;
}
if (!JSVAL_IS_OBJECT(v))
{
if (!JSVAL_IS_OBJECT(v)) {
*ppArgRef = nsnull;
*rv = ((JSVAL_IS_INT(v) && JSVAL_TO_INT(v) == 0)
? NS_ERROR_XPC_BAD_CONVERT_JS_ZERO_ISNOT_NULL
@ -957,8 +913,7 @@ xpc_qsUnwrapArgImpl(JSContext *cx,
{
nsresult rv;
JSObject *src = xpc_qsUnwrapObj(v, ppArgRef, &rv);
if (!src)
{
if (!src) {
*ppArg = nsnull;
return rv;
@ -967,19 +922,16 @@ xpc_qsUnwrapArgImpl(JSContext *cx,
XPCWrappedNative *wrapper;
XPCWrappedNativeTearOff *tearoff;
JSObject *obj2;
if (mozilla::dom::binding::instanceIsProxy(src))
{
if (mozilla::dom::binding::instanceIsProxy(src)) {
wrapper = nsnull;
obj2 = src;
}
else
{
else {
rv = getWrapper(cx, src, nsnull, &wrapper, &obj2, &tearoff);
NS_ENSURE_SUCCESS(rv, rv);
}
if (wrapper || obj2)
{
if (wrapper || obj2) {
if (NS_FAILED(castNative(cx, wrapper, obj2, tearoff, iid, ppArg,
ppArgRef, vp, nsnull)))
return NS_ERROR_XPC_BAD_CONVERT_JS;
@ -991,18 +943,15 @@ xpc_qsUnwrapArgImpl(JSContext *cx,
// XXX E4X breaks the world. Don't try wrapping E4X objects!
// This hack can be removed (or changed accordingly) when the
// DOM <-> E4X bindings are complete, see bug 270553
if (JS_TypeOfValue(cx, OBJECT_TO_JSVAL(src)) == JSTYPE_XML)
{
if (JS_TypeOfValue(cx, OBJECT_TO_JSVAL(src)) == JSTYPE_XML) {
*ppArgRef = nsnull;
return NS_ERROR_XPC_BAD_CONVERT_JS;
}
// Try to unwrap a slim wrapper.
nsISupports *iface;
if (XPCConvert::GetISupportsFromJSObject(src, &iface))
{
if (!iface || NS_FAILED(iface->QueryInterface(iid, ppArg)))
{
if (XPCConvert::GetISupportsFromJSObject(src, &iface)) {
if (!iface || NS_FAILED(iface->QueryInterface(iid, ppArg))) {
*ppArgRef = nsnull;
return NS_ERROR_XPC_BAD_CONVERT_JS;
}
@ -1013,8 +962,7 @@ xpc_qsUnwrapArgImpl(JSContext *cx,
// Create the ccx needed for quick stubs.
XPCCallContext ccx(JS_CALLER, cx);
if (!ccx.IsValid())
{
if (!ccx.IsValid()) {
*ppArgRef = nsnull;
return NS_ERROR_XPC_BAD_CONVERT_JS;
}
@ -1022,8 +970,7 @@ xpc_qsUnwrapArgImpl(JSContext *cx,
nsRefPtr<nsXPCWrappedJS> wrappedJS;
rv = nsXPCWrappedJS::GetNewOrUsed(ccx, src, iid, nsnull,
getter_AddRefs(wrappedJS));
if (NS_FAILED(rv) || !wrappedJS)
{
if (NS_FAILED(rv) || !wrappedJS) {
*ppArgRef = nsnull;
return rv;
}
@ -1033,8 +980,7 @@ xpc_qsUnwrapArgImpl(JSContext *cx,
// nsIPropertyBag. We must use AggregatedQueryInterface in cases where
// there is an outer to avoid nasty recursion.
rv = wrappedJS->QueryInterface(iid, ppArg);
if (NS_SUCCEEDED(rv))
{
if (NS_SUCCEEDED(rv)) {
*ppArgRef = static_cast<nsISupports*>(*ppArg);
*vp = OBJECT_TO_JSVAL(wrappedJS->GetJSObject());
}
@ -1047,16 +993,13 @@ xpc_qsJsvalToCharStr(JSContext *cx, jsval v, JSAutoByteString *bytes)
JSString *str;
JS_ASSERT(!bytes->ptr());
if (JSVAL_IS_STRING(v))
{
if (JSVAL_IS_STRING(v)) {
str = JSVAL_TO_STRING(v);
}
else if (JSVAL_IS_VOID(v) || JSVAL_IS_NULL(v))
{
else if (JSVAL_IS_VOID(v) || JSVAL_IS_NULL(v)) {
return true;
}
else
{
else {
if (!(str = JS_ValueToString(cx, v)))
return false;
}
@ -1068,17 +1011,14 @@ xpc_qsJsvalToWcharStr(JSContext *cx, jsval v, jsval *pval, PRUnichar **pstr)
{
JSString *str;
if (JSVAL_IS_STRING(v))
{
if (JSVAL_IS_STRING(v)) {
str = JSVAL_TO_STRING(v);
}
else if (JSVAL_IS_VOID(v) || JSVAL_IS_NULL(v))
{
else if (JSVAL_IS_VOID(v) || JSVAL_IS_NULL(v)) {
*pstr = NULL;
return JS_TRUE;
}
else
{
else {
if (!(str = JS_ValueToString(cx, v)))
return JS_FALSE;
*pval = STRING_TO_JSVAL(str); // Root the new string.
@ -1097,8 +1037,7 @@ JSBool
xpc_qsStringToJsval(JSContext *cx, nsString &str, jsval *rval)
{
// From the T_DOMSTRING case in XPCConvert::NativeData2JS.
if (str.IsVoid())
{
if (str.IsVoid()) {
*rval = JSVAL_NULL;
return JS_TRUE;
}
@ -1108,8 +1047,7 @@ xpc_qsStringToJsval(JSContext *cx, nsString &str, jsval *rval)
if (JSVAL_IS_NULL(jsstr))
return JS_FALSE;
*rval = jsstr;
if (sharedBuffer)
{
if (sharedBuffer) {
// The string was shared but ReadableToJSVal didn't addref it.
// Move the ownership from str to jsstr.
str.ForgetSharedBuffer();
@ -1121,8 +1059,7 @@ JSBool
xpc_qsStringToJsstring(JSContext *cx, nsString &str, JSString **rval)
{
// From the T_DOMSTRING case in XPCConvert::NativeData2JS.
if (str.IsVoid())
{
if (str.IsVoid()) {
*rval = nsnull;
return JS_TRUE;
}
@ -1132,8 +1069,7 @@ xpc_qsStringToJsstring(JSContext *cx, nsString &str, JSString **rval)
if (JSVAL_IS_NULL(jsstr))
return JS_FALSE;
*rval = JSVAL_TO_STRING(jsstr);
if (sharedBuffer)
{
if (sharedBuffer) {
// The string was shared but ReadableToJSVal didn't addref it.
// Move the ownership from str to jsstr.
str.ForgetSharedBuffer();
@ -1162,8 +1098,7 @@ xpc_qsXPCOMObjectToJsval(XPCLazyCallContext &lccx, qsObjectHelper &aHelper,
nsresult rv;
if (!XPCConvert::NativeInterface2JSObject(lccx, rval, nsnull,
aHelper, iid, iface,
PR_TRUE, OBJ_IS_NOT_GLOBAL, &rv))
{
PR_TRUE, OBJ_IS_NOT_GLOBAL, &rv)) {
// I can't tell if NativeInterface2JSObject throws JS exceptions
// or not. This is a sloppy stab at the right semantics; the
// method really ought to be fixed to behave consistently.
@ -1189,8 +1124,7 @@ xpc_qsVariantToJsval(XPCLazyCallContext &lccx,
{
// From the T_INTERFACE case in XPCConvert::NativeData2JS.
// Error handling is in XPCWrappedNative::CallMethod.
if (p)
{
if (p) {
nsresult rv;
JSBool ok = XPCVariant::VariantDataToJS(lccx, p, &rv, rval);
if (!ok)

View File

@ -139,8 +139,7 @@ public:
: xpcObjectHelper(ToSupports(aObject.get()),
ToCanonicalSupports(aObject.get()), aCache, QS_IS_NODE(T))
{
if (mCanonical)
{
if (mCanonical) {
// Transfer the strong reference.
mCanonicalStrong = dont_AddRef(mCanonical);
aObject.forget();
@ -152,8 +151,7 @@ public:
: xpcObjectHelper(ToSupports(aObject.get()),
ToCanonicalSupports(aObject.get()), aCache, QS_IS_NODE(T))
{
if (mCanonical)
{
if (mCanonical) {
// Transfer the strong reference.
mCanonicalStrong = dont_AddRef(mCanonical);
aObject.forget();
@ -355,27 +353,22 @@ protected:
StringificationBehavior nullBehavior,
StringificationBehavior undefinedBehavior) {
JSString *s;
if (JSVAL_IS_STRING(v))
{
if (JSVAL_IS_STRING(v)) {
s = JSVAL_TO_STRING(v);
}
else
{
else {
StringificationBehavior behavior = eStringify;
if (JSVAL_IS_NULL(v))
{
if (JSVAL_IS_NULL(v)) {
behavior = nullBehavior;
}
else if (JSVAL_IS_VOID(v))
{
else if (JSVAL_IS_VOID(v)) {
behavior = undefinedBehavior;
}
// If pval is null, that means the argument was optional and
// not passed; turn those into void strings if they're
// supposed to be stringified.
if (behavior != eStringify || !pval)
{
if (behavior != eStringify || !pval) {
// Here behavior == eStringify implies !pval, so both eNull and
// eStringify should end up with void strings.
(new(mBuf) implementation_type(traits::sEmptyBuffer, PRUint32(0)))->
@ -385,8 +378,7 @@ protected:
}
s = JS_ValueToString(cx, v);
if (!s)
{
if (!s) {
mValid = JS_FALSE;
return nsnull;
}
@ -567,29 +559,25 @@ castNativeFromWrapper(JSContext *cx,
XPCWrappedNativeTearOff *tearoff;
JSObject *cur;
if (!callee && IS_WRAPPER_CLASS(js::GetObjectClass(obj)))
{
if (!callee && IS_WRAPPER_CLASS(js::GetObjectClass(obj))) {
cur = obj;
wrapper = IS_WN_WRAPPER_OBJECT(cur) ?
(XPCWrappedNative*)xpc_GetJSPrivate(obj) :
nsnull;
tearoff = nsnull;
}
else
{
else {
*rv = getWrapper(cx, obj, callee, &wrapper, &cur, &tearoff);
if (NS_FAILED(*rv))
return nsnull;
}
nsISupports *native;
if (wrapper)
{
if (wrapper) {
native = wrapper->GetIdentityObject();
cur = wrapper->GetFlatJSObject();
}
else
{
else {
native = cur ?
static_cast<nsISupports*>(xpc_GetJSPrivate(cur)) :
nsnull;
@ -610,8 +598,7 @@ castNativeFromWrapper(JSContext *cx,
*pRef = nsnull;
*pVal = OBJECT_TO_JSVAL(cur);
if (lccx)
{
if (lccx) {
if (wrapper)
lccx->SetWrapper(wrapper, tearoff);
else

View File

@ -79,8 +79,7 @@ BackstagePass::NewResolve(nsIXPConnectWrappedNative *wrapper,
if (!*_retval)
return NS_OK;
if (resolved)
{
if (resolved) {
*objp = obj;
return NS_OK;
}

View File

@ -136,25 +136,19 @@ XPCJSStackFrame::CreateStack(JSContext* cx, JSStackFrame* fp,
nsRefPtr<XPCJSStackFrame> first = new XPCJSStackFrame();
nsRefPtr<XPCJSStackFrame> self = first;
while (fp && self)
{
if (!JS_IsScriptFrame(cx, fp))
{
while (fp && self) {
if (!JS_IsScriptFrame(cx, fp)) {
self->mLanguage = nsIProgrammingLanguage::CPLUSPLUS;
}
else
{
else {
self->mLanguage = nsIProgrammingLanguage::JAVASCRIPT;
JSScript* script = JS_GetFrameScript(cx, fp);
jsbytecode* pc = JS_GetFramePC(cx, fp);
if (script && pc)
{
if (script && pc) {
JS::AutoEnterFrameCompartment ac;
if (ac.enter(cx, fp))
{
if (ac.enter(cx, fp)) {
const char* filename = JS_GetScriptFilename(cx, script);
if (filename)
{
if (filename) {
self->mFilename = (char*)
nsMemory::Clone(filename,
sizeof(char)*(strlen(filename)+1));
@ -163,17 +157,13 @@ XPCJSStackFrame::CreateStack(JSContext* cx, JSStackFrame* fp,
self->mLineno = (PRInt32) JS_PCToLineNumber(cx, script, pc);
JSFunction* fun = JS_GetFrameFunction(cx, fp);
if (fun)
{
if (fun) {
JSString *funid = JS_GetFunctionId(fun);
if (funid)
{
if (funid) {
size_t length = JS_GetStringEncodingLength(cx, funid);
if (length != size_t(-1))
{
if (length != size_t(-1)) {
self->mFunname = static_cast<char *>(nsMemory::Alloc(length + 1));
if (self->mFunname)
{
if (self->mFunname) {
JS_EncodeStringToBuffer(funid, self->mFunname, length);
self->mFunname[length] = '\0';
}
@ -182,18 +172,15 @@ XPCJSStackFrame::CreateStack(JSContext* cx, JSStackFrame* fp,
}
}
}
else
{
else {
self->mLanguage = nsIProgrammingLanguage::CPLUSPLUS;
}
}
if (++numFrames > MAX_FRAMES)
{
if (++numFrames > MAX_FRAMES) {
fp = NULL;
}
else if (JS_FrameIterator(cx, &fp))
{
else if (JS_FrameIterator(cx, &fp)) {
XPCJSStackFrame* frame = new XPCJSStackFrame();
self->mCaller = frame;
self = frame;
@ -220,14 +207,12 @@ XPCJSStackFrame::CreateStackFrameLocation(PRUint32 aLanguage,
else
failed = JS_TRUE;
if (!failed)
{
if (!failed) {
self->mLanguage = aLanguage;
self->mLineno = aLineNumber;
}
if (!failed && aFilename)
{
if (!failed && aFilename) {
self->mFilename = (char*)
nsMemory::Clone(aFilename,
sizeof(char)*(strlen(aFilename)+1));
@ -235,8 +220,7 @@ XPCJSStackFrame::CreateStackFrameLocation(PRUint32 aLanguage,
failed = JS_TRUE;
}
if (!failed && aFunctionName)
{
if (!failed && aFunctionName) {
self->mFunname = (char*)
nsMemory::Clone(aFunctionName,
sizeof(char)*(strlen(aFunctionName)+1));
@ -244,13 +228,11 @@ XPCJSStackFrame::CreateStackFrameLocation(PRUint32 aLanguage,
failed = JS_TRUE;
}
if (!failed && aCaller)
{
if (!failed && aCaller) {
self->mCaller = aCaller;
}
if (failed && self)
{
if (failed && self) {
NS_RELEASE(self); // sets self to nsnull
}

View File

@ -88,18 +88,15 @@ XPCStringConvert::ReadableToJSVal(JSContext *cx,
PRUint32 length = readable.Length();
JSAtom *atom;
if (length == 0 && (atom = cx->runtime->atomState.emptyAtom))
{
if (length == 0 && (atom = cx->runtime->atomState.emptyAtom)) {
return STRING_TO_JSVAL(atom);
}
nsStringBuffer *buf = nsStringBuffer::FromString(readable);
if (buf)
{
if (buf) {
// yay, we can share the string's buffer!
if (sDOMStringFinalizerIndex == -1)
{
if (sDOMStringFinalizerIndex == -1) {
sDOMStringFinalizerIndex =
JS_AddExternalStringFinalizer(DOMStringFinalizer);
if (sDOMStringFinalizerIndex == -1)
@ -110,13 +107,11 @@ XPCStringConvert::ReadableToJSVal(JSContext *cx,
reinterpret_cast<jschar *>(buf->Data()),
length, sDOMStringFinalizerIndex);
if (str)
{
if (str) {
*sharedBuffer = buf;
}
}
else
{
else {
// blech, have to copy.
jschar *chars = reinterpret_cast<jschar *>
@ -127,8 +122,7 @@ XPCStringConvert::ReadableToJSVal(JSContext *cx,
if (length && !CopyUnicodeTo(readable, 0,
reinterpret_cast<PRUnichar *>(chars),
length))
{
length)) {
JS_free(cx, chars);
return JSVAL_NULL;
}

View File

@ -62,8 +62,7 @@ XPCJSContextStack::XPCJSContextStack()
XPCJSContextStack::~XPCJSContextStack()
{
if (mOwnSafeJSContext)
{
if (mOwnSafeJSContext) {
JS_SetContextThread(mOwnSafeJSContext);
JS_DestroyContext(mOwnSafeJSContext);
mOwnSafeJSContext = nsnull;
@ -98,22 +97,18 @@ XPCJSContextStack::Pop(JSContext * *_retval)
*_retval = mStack[idx].cx;
mStack.RemoveElementAt(idx);
if (idx > 0)
{
if (idx > 0) {
--idx; // Advance to new top of the stack
XPCJSContextInfo & e = mStack[idx];
NS_ASSERTION(!e.suspendDepth || e.cx, "Shouldn't have suspendDepth without a cx!");
if (e.cx)
{
if (e.suspendDepth)
{
if (e.cx) {
if (e.suspendDepth) {
JS_ResumeRequest(e.cx, e.suspendDepth);
e.suspendDepth = 0;
}
if (e.savedFrameChain)
{
if (e.savedFrameChain) {
// Pop() can be called outside any request for e.cx.
JSAutoRequest ar(e.cx);
JS_RestoreFrameChain(e.cx);
@ -128,8 +123,7 @@ static nsIPrincipal*
GetPrincipalFromCx(JSContext *cx)
{
nsIScriptContextPrincipal* scp = GetScriptContextPrincipalFromJSContext(cx);
if (scp)
{
if (scp) {
nsIScriptObjectPrincipal* globalData = scp->GetObjectPrincipal();
if (globalData)
return globalData->GetPrincipal();
@ -142,23 +136,17 @@ NS_IMETHODIMP
XPCJSContextStack::Push(JSContext * cx)
{
JS_ASSERT_IF(cx, JS_GetContextThread(cx));
if (mStack.Length() > 0)
{
if (mStack.Length() > 0) {
XPCJSContextInfo & e = mStack[mStack.Length() - 1];
if (e.cx)
{
if (e.cx == cx)
{
if (e.cx) {
if (e.cx == cx) {
nsIScriptSecurityManager* ssm = XPCWrapper::GetSecurityManager();
if (ssm)
{
if (nsIPrincipal* globalObjectPrincipal = GetPrincipalFromCx(cx))
{
if (ssm) {
if (nsIPrincipal* globalObjectPrincipal = GetPrincipalFromCx(cx)) {
nsIPrincipal* subjectPrincipal = ssm->GetCxSubjectPrincipal(cx);
bool equals = false;
globalObjectPrincipal->Equals(subjectPrincipal, &equals);
if (equals)
{
if (equals) {
goto append;
}
}
@ -222,20 +210,17 @@ static JSClass global_class = {
NS_IMETHODIMP
XPCJSContextStack::GetSafeJSContext(JSContext * *aSafeJSContext)
{
if (!mSafeJSContext)
{
if (!mSafeJSContext) {
// Start by getting the principal holder and principal for this
// context. If we can't manage that, don't bother with the rest.
nsRefPtr<nsNullPrincipal> principal = new nsNullPrincipal();
nsCOMPtr<nsIScriptObjectPrincipal> sop;
if (principal)
{
if (principal) {
nsresult rv = principal->Init();
if (NS_SUCCEEDED(rv))
sop = new PrincipalHolder(principal);
}
if (!sop)
{
if (!sop) {
*aSafeJSContext = nsnull;
return NS_ERROR_FAILURE;
}
@ -246,12 +231,10 @@ XPCJSContextStack::GetSafeJSContext(JSContext * *aSafeJSContext)
nsXPConnect* xpc = nsXPConnect::GetXPConnect();
nsCOMPtr<nsIXPConnect> xpcholder(static_cast<nsIXPConnect*>(xpc));
if (xpc && (xpcrt = xpc->GetRuntime()) && (rt = xpcrt->GetJSRuntime()))
{
if (xpc && (xpcrt = xpc->GetRuntime()) && (rt = xpcrt->GetJSRuntime())) {
JSObject *glob;
mSafeJSContext = JS_NewContext(rt, 8192);
if (mSafeJSContext)
{
if (mSafeJSContext) {
// scoped JS Request
JSAutoRequest req(mSafeJSContext);
@ -265,8 +248,7 @@ XPCJSContextStack::GetSafeJSContext(JSContext * *aSafeJSContext)
if (NS_FAILED(rv))
glob = nsnull;
if (glob)
{
if (glob) {
// Make sure the context is associated with a proper compartment
// and not the default compartment.
JS_SetGlobalObject(mSafeJSContext, glob);
@ -275,8 +257,7 @@ XPCJSContextStack::GetSafeJSContext(JSContext * *aSafeJSContext)
// InitClasses
nsIScriptObjectPrincipal* priv = nsnull;
sop.swap(priv);
if (!JS_SetPrivate(mSafeJSContext, glob, priv))
{
if (!JS_SetPrivate(mSafeJSContext, glob, priv)) {
// Drop the whole thing
NS_RELEASE(priv);
glob = nsnull;
@ -287,14 +268,12 @@ XPCJSContextStack::GetSafeJSContext(JSContext * *aSafeJSContext)
// nsIScriptObjectPrincipal ownership is either handled by the
// nsCOMPtr or dealt with, or we'll release in the finalize
// hook.
if (glob && NS_FAILED(xpc->InitClasses(mSafeJSContext, glob)))
{
if (glob && NS_FAILED(xpc->InitClasses(mSafeJSContext, glob))) {
glob = nsnull;
}
}
if (mSafeJSContext && !glob)
{
if (mSafeJSContext && !glob) {
// Destroy the context outside the scope of JSAutoRequest that
// uses the context in its destructor.
JS_DestroyContext(mSafeJSContext);
@ -332,8 +311,7 @@ XPCPerThreadData::XPCPerThreadData()
#endif
{
MOZ_COUNT_CTOR(xpcPerThreadData);
if (gLock)
{
if (gLock) {
MutexAutoLock lock(*gLock);
mNextThread = gThreads;
gThreads = this;
@ -366,18 +344,14 @@ XPCPerThreadData::~XPCPerThreadData()
Cleanup();
// Unlink 'this' from the list of threads.
if (gLock)
{
if (gLock) {
MutexAutoLock lock(*gLock);
if (gThreads == this)
gThreads = mNextThread;
else
{
else {
XPCPerThreadData* cur = gThreads;
while (cur)
{
if (cur->mNextThread == this)
{
while (cur) {
if (cur->mNextThread == this) {
cur->mNextThread = mNextThread;
break;
}
@ -388,8 +362,7 @@ XPCPerThreadData::~XPCPerThreadData()
doDestroyLock = PR_TRUE;
}
if (gLock && doDestroyLock)
{
if (gLock && doDestroyLock) {
delete gLock;
gLock = nsnull;
}
@ -433,20 +406,16 @@ XPCPerThreadData::GetDataImpl(JSContext *cx)
{
XPCPerThreadData* data;
if (!gLock)
{
if (!gLock) {
gLock = new Mutex("XPCPerThreadData.gLock");
}
if (gTLSIndex == BAD_TLS_INDEX)
{
if (gTLSIndex == BAD_TLS_INDEX) {
MutexAutoLock lock(*gLock);
// check again now that we have the lock...
if (gTLSIndex == BAD_TLS_INDEX)
{
if (gTLSIndex == BAD_TLS_INDEX) {
if (PR_FAILURE ==
PR_NewThreadPrivateIndex(&gTLSIndex, xpc_ThreadDataDtorCB))
{
PR_NewThreadPrivateIndex(&gTLSIndex, xpc_ThreadDataDtorCB)) {
NS_ERROR("PR_NewThreadPrivateIndex failed!");
gTLSIndex = BAD_TLS_INDEX;
return nsnull;
@ -455,25 +424,21 @@ XPCPerThreadData::GetDataImpl(JSContext *cx)
}
data = (XPCPerThreadData*) PR_GetThreadPrivate(gTLSIndex);
if (!data)
{
if (!data) {
data = new XPCPerThreadData();
if (!data || !data->IsValid())
{
if (!data || !data->IsValid()) {
NS_ERROR("new XPCPerThreadData() failed!");
delete data;
return nsnull;
}
if (PR_FAILURE == PR_SetThreadPrivate(gTLSIndex, data))
{
if (PR_FAILURE == PR_SetThreadPrivate(gTLSIndex, data)) {
NS_ERROR("PR_SetThreadPrivate failed!");
delete data;
return nsnull;
}
}
if (cx && !sMainJSThread && NS_IsMainThread())
{
if (cx && !sMainJSThread && NS_IsMainThread()) {
sMainJSThread = cx->thread();
sMainThreadData = data;
@ -498,19 +463,16 @@ XPCPerThreadData::CleanupAllThreads()
int count = 0;
int i;
if (gLock)
{
if (gLock) {
MutexAutoLock lock(*gLock);
for (XPCPerThreadData* cur = gThreads; cur; cur = cur->mNextThread)
count++;
stacks = (XPCJSContextStack**) new XPCJSContextStack*[count] ;
if (stacks)
{
if (stacks) {
i = 0;
for (XPCPerThreadData* cur = gThreads; cur; cur = cur->mNextThread)
{
for (XPCPerThreadData* cur = gThreads; cur; cur = cur->mNextThread) {
stacks[i++] = cur->mJSContextStack;
cur->mJSContextStack = nsnull;
cur->Cleanup();
@ -518,8 +480,7 @@ XPCPerThreadData::CleanupAllThreads()
}
}
if (stacks)
{
if (stacks) {
for (i = 0; i < count; i++)
delete stacks[i];
delete [] stacks;

View File

@ -176,21 +176,18 @@ XPCThrower::Verbosify(XPCCallContext& ccx,
{
char* sz = nsnull;
if (ccx.HasInterfaceAndMember())
{
if (ccx.HasInterfaceAndMember()) {
XPCNativeInterface* iface = ccx.GetInterface();
jsid id = ccx.GetMember()->GetName();
JSAutoByteString bytes;
const char *name = JSID_IS_VOID(id) ? "Unknown" : bytes.encode(ccx, JSID_TO_STRING(id));
if (!name)
{
if (!name) {
name = "";
}
sz = JS_smprintf("%s [%s.%s]", *psz, iface->GetNameString(), name);
}
if (sz)
{
if (sz) {
if (own)
JS_smprintf_free(*psz);
*psz = sz;
@ -210,11 +207,9 @@ XPCThrower::BuildAndThrowException(JSContext* cx, nsresult rv, const char* sz)
nsCOMPtr<nsIException> defaultException;
nsXPCException::NewException(sz, rv, nsnull, nsnull, getter_AddRefs(defaultException));
XPCPerThreadData* tls = XPCPerThreadData::GetData(cx);
if (tls)
{
if (tls) {
nsIExceptionManager * exceptionManager = tls->GetExceptionManager();
if (exceptionManager)
{
if (exceptionManager) {
// Ask the provider for the exception, if there is no provider
// we expect it to set e to null
exceptionManager->GetExceptionFromProvider(rv,
@ -222,8 +217,7 @@ XPCThrower::BuildAndThrowException(JSContext* cx, nsresult rv, const char* sz)
getter_AddRefs(finalException));
// We should get at least the defaultException back,
// but just in case
if (finalException == nsnull)
{
if (finalException == nsnull) {
finalException = defaultException;
}
}
@ -244,12 +238,10 @@ IsCallerChrome(JSContext* cx)
nsresult rv;
nsCOMPtr<nsIScriptSecurityManager> secMan;
if (XPCPerThreadData::IsMainThread(cx))
{
if (XPCPerThreadData::IsMainThread(cx)) {
secMan = XPCWrapper::GetSecurityManager();
}
else
{
else {
nsXPConnect* xpc = nsXPConnect::GetXPConnect();
if (!xpc)
return PR_FALSE;
@ -277,8 +269,7 @@ JSBool
XPCThrower::ThrowExceptionObject(JSContext* cx, nsIException* e)
{
JSBool success = JS_FALSE;
if (e)
{
if (e) {
nsCOMPtr<nsIXPCException> xpcEx;
jsval thrown;
nsXPConnect* xpc;
@ -288,15 +279,13 @@ XPCThrower::ThrowExceptionObject(JSContext* cx, nsIException* e)
// context (i.e., not chrome), rethrow the original value.
if (!IsCallerChrome(cx) &&
(xpcEx = do_QueryInterface(e)) &&
NS_SUCCEEDED(xpcEx->StealJSVal(&thrown)))
{
NS_SUCCEEDED(xpcEx->StealJSVal(&thrown))) {
if (!JS_WrapValue(cx, &thrown))
return JS_FALSE;
JS_SetPendingException(cx, thrown);
success = JS_TRUE;
}
else if ((xpc = nsXPConnect::GetXPConnect()))
{
else if ((xpc = nsXPConnect::GetXPConnect())) {
JSObject* glob = JS_GetGlobalForScopeChain(cx);
if (!glob)
return JS_FALSE;
@ -305,11 +294,9 @@ XPCThrower::ThrowExceptionObject(JSContext* cx, nsIException* e)
nsresult rv = xpc->WrapNative(cx, glob, e,
NS_GET_IID(nsIException),
getter_AddRefs(holder));
if (NS_SUCCEEDED(rv) && holder)
{
if (NS_SUCCEEDED(rv) && holder) {
JSObject* obj;
if (NS_SUCCEEDED(holder->GetJSObject(&obj)))
{
if (NS_SUCCEEDED(holder->GetJSObject(&obj))) {
JS_SetPendingException(cx, OBJECT_TO_JSVAL(obj));
success = JS_TRUE;
}

View File

@ -61,8 +61,7 @@ XPCVariant::XPCVariant(XPCCallContext& ccx, jsval aJSVal)
: mJSVal(aJSVal)
{
nsVariant::Initialize(&mData);
if (!JSVAL_IS_PRIMITIVE(mJSVal))
{
if (!JSVAL_IS_PRIMITIVE(mJSVal)) {
JSObject *obj = JS_ObjectToInnerObject(ccx, JSVAL_TO_OBJECT(mJSVal));
mJSVal = OBJECT_TO_JSVAL(obj);
@ -134,8 +133,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(XPCVariant)
tmp->mData.u.wstr.mWStringValue = nsnull;
nsVariant::Cleanup(&tmp->mData);
if (JSVAL_IS_TRACEABLE(val))
{
if (JSVAL_IS_TRACEABLE(val)) {
XPCTraceableVariant *v = static_cast<XPCTraceableVariant*>(tmp);
v->RemoveFromRootSet(nsXPConnect::GetRuntimeInstance()->GetMapLock());
}
@ -220,8 +218,7 @@ XPCArrayHomogenizer::GetTypeForArray(XPCCallContext& ccx, JSObject* array,
Type state = tUnk;
Type type;
for (jsuint i = 0; i < length; i++)
{
for (jsuint i = 0; i < length; i++) {
jsval val;
if (!JS_GetElement(ccx, array, i, &val))
return JS_FALSE;
@ -232,8 +229,7 @@ XPCArrayHomogenizer::GetTypeForArray(XPCCallContext& ccx, JSObject* array,
type = tDbl;
else if (JSVAL_IS_BOOLEAN(val))
type = tBool;
else if (JSVAL_IS_VOID(val))
{
else if (JSVAL_IS_VOID(val)) {
state = tVar;
break;
}
@ -241,8 +237,7 @@ XPCArrayHomogenizer::GetTypeForArray(XPCCallContext& ccx, JSObject* array,
type = tNull;
else if (JSVAL_IS_STRING(val))
type = tStr;
else
{
else {
NS_ASSERTION(JSVAL_IS_OBJECT(val), "invalid type of jsval!");
JSObject* jsobj = JSVAL_TO_OBJECT(val);
if (JS_IsArrayObject(ccx, jsobj))
@ -267,8 +262,7 @@ XPCArrayHomogenizer::GetTypeForArray(XPCCallContext& ccx, JSObject* array,
break;
}
switch (state)
{
switch (state) {
case tInt :
*resultType = nsXPTType((uint8)TD_INT32);
break;
@ -325,8 +319,7 @@ JSBool XPCVariant::InitializeData(XPCCallContext& ccx)
return NS_SUCCEEDED(nsVariant::SetToVoid(&mData));
if (JSVAL_IS_NULL(val))
return NS_SUCCEEDED(nsVariant::SetToEmpty(&mData));
if (JSVAL_IS_STRING(val))
{
if (JSVAL_IS_STRING(val)) {
// Make our string immutable. This will also ensure null-termination,
// which nsVariant assumes for its PRUnichar* stuff.
JSString* str = JSVAL_TO_STRING(val);
@ -370,10 +363,8 @@ JSBool XPCVariant::InitializeData(XPCCallContext& ccx)
jsuint len;
if (JS_IsArrayObject(ccx, jsobj) && JS_GetArrayLength(ccx, jsobj, &len))
{
if (!len)
{
if (JS_IsArrayObject(ccx, jsobj) && JS_GetArrayLength(ccx, jsobj, &len)) {
if (!len) {
// Zero length array
nsVariant::SetToEmptyArray(&mData);
return JS_TRUE;
@ -437,8 +428,7 @@ XPCVariant::VariantDataToJS(XPCLazyCallContext& lccx,
(JSVAL_IS_PRIMITIVE(realVal) ||
type == nsIDataType::VTYPE_ARRAY ||
type == nsIDataType::VTYPE_EMPTY_ARRAY ||
type == nsIDataType::VTYPE_ID))
{
type == nsIDataType::VTYPE_ID)) {
JSContext *cx = lccx.GetJSContext();
if (!JS_WrapValue(cx, &realVal))
return JS_FALSE;
@ -447,8 +437,7 @@ XPCVariant::VariantDataToJS(XPCLazyCallContext& lccx,
}
nsCOMPtr<XPCVariant> xpcvariant = do_QueryInterface(variant);
if (xpcvariant && xpcvariant->mReturnRawObject)
{
if (xpcvariant && xpcvariant->mReturnRawObject) {
NS_ASSERTION(type == nsIDataType::VTYPE_INTERFACE ||
type == nsIDataType::VTYPE_INTERFACE_IS,
"Weird variant");
@ -483,8 +472,7 @@ XPCVariant::VariantDataToJS(XPCLazyCallContext& lccx,
NS_ABORT_IF_FALSE(js::GetObjectCompartment(lccx.GetScopeForNewJSObjects()) == cx->compartment,
"bad scope for new JSObjects");
switch (type)
{
switch (type) {
case nsIDataType::VTYPE_INT8:
case nsIDataType::VTYPE_INT16:
case nsIDataType::VTYPE_INT32:
@ -611,8 +599,7 @@ XPCVariant::VariantDataToJS(XPCLazyCallContext& lccx,
PRUint16 elementType = du.u.array.mArrayType;
const nsID* pid = nsnull;
switch (elementType)
{
switch (elementType) {
case nsIDataType::VTYPE_INT8:
case nsIDataType::VTYPE_INT16:
case nsIDataType::VTYPE_INT32:
@ -693,15 +680,13 @@ VARIANT_DONE:
// If we are here then we need to convert the data in the xpctvar.
if (xpctvar.type.TagPart() == TD_PSTRING_SIZE_IS ||
xpctvar.type.TagPart() == TD_PWSTRING_SIZE_IS)
{
xpctvar.type.TagPart() == TD_PWSTRING_SIZE_IS) {
success = XPCConvert::NativeStringWithSize2JS(cx, pJSVal,
(const void*)&xpctvar.val,
xpctvar.type,
size, pErr);
}
else
{
else {
success = XPCConvert::NativeData2JS(lccx, pJSVal,
(const void*)&xpctvar.val,
xpctvar.type,
@ -709,8 +694,7 @@ VARIANT_DONE:
}
// We may have done something in the above code that requires cleanup.
if (xpctvar.DoesValNeedCleanup())
{
if (xpctvar.DoesValNeedCleanup()) {
if (type == nsIDataType::VTYPE_INTERFACE ||
type == nsIDataType::VTYPE_INTERFACE_IS)
((nsISupports*)xpctvar.val.p)->Release();

View File

@ -109,8 +109,7 @@ nsXPCWrappedJS::AggregatedQueryInterface(REFNSIID aIID, void** aInstancePtr)
// to be in QueryInterface before the possible delegation to 'outer', but
// we don't want to do this check twice in one call in the normal case:
// once in QueryInterface and once in DelegatedQueryInterface.
if (aIID.Equals(NS_GET_IID(nsIXPConnectWrappedJS)))
{
if (aIID.Equals(NS_GET_IID(nsIXPConnectWrappedJS))) {
NS_ADDREF(this);
*aInstancePtr = (void*) static_cast<nsIXPConnectWrappedJS*>(this);
return NS_OK;
@ -122,8 +121,7 @@ nsXPCWrappedJS::AggregatedQueryInterface(REFNSIID aIID, void** aInstancePtr)
NS_IMETHODIMP
nsXPCWrappedJS::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (nsnull == aInstancePtr)
{
if (nsnull == aInstancePtr) {
NS_PRECONDITION(0, "null pointer");
return NS_ERROR_NULL_POINTER;
}
@ -133,8 +131,7 @@ nsXPCWrappedJS::QueryInterface(REFNSIID aIID, void** aInstancePtr)
return NS_OK;
}
if (aIID.Equals(NS_GET_IID(nsCycleCollectionISupports)))
{
if (aIID.Equals(NS_GET_IID(nsCycleCollectionISupports))) {
*aInstancePtr =
NS_CYCLE_COLLECTION_CLASSNAME(nsXPCWrappedJS)::Upcast(this);
return NS_OK;
@ -145,8 +142,7 @@ nsXPCWrappedJS::QueryInterface(REFNSIID aIID, void** aInstancePtr)
// Always check for this first so that our 'outer' can get this interface
// from us without recurring into a call to the outer's QI!
if (aIID.Equals(NS_GET_IID(nsIXPConnectWrappedJS)))
{
if (aIID.Equals(NS_GET_IID(nsIXPConnectWrappedJS))) {
NS_ADDREF(this);
*aInstancePtr = (void*) static_cast<nsIXPConnectWrappedJS*>(this);
return NS_OK;
@ -187,8 +183,7 @@ nsXPCWrappedJS::AddRef(void)
nsrefcnt cnt = NS_AtomicIncrementRefcnt(mRefCnt);
NS_LOG_ADDREF(this, cnt, "nsXPCWrappedJS", sizeof(*this));
if (2 == cnt && IsValid())
{
if (2 == cnt && IsValid()) {
XPCJSRuntime* rt = mClass->GetRuntime();
rt->AddWrappedJSRoot(this);
}
@ -211,13 +206,11 @@ do_decrement:
nsrefcnt cnt = NS_AtomicDecrementRefcnt(mRefCnt);
NS_LOG_RELEASE(this, cnt, "nsXPCWrappedJS");
if (0 == cnt)
{
if (0 == cnt) {
delete this; // also unlinks us from chain
return 0;
}
if (1 == cnt)
{
if (1 == cnt) {
if (IsValid())
RemoveFromRootSet(rt->GetMapLock());
@ -288,8 +281,7 @@ nsXPCWrappedJS::GetNewOrUsed(XPCCallContext& ccx,
JSBool release_root = JS_FALSE;
map = rt->GetWrappedJSMap();
if (!map)
{
if (!map) {
NS_ASSERTION(map,"bad map");
return NS_ERROR_FAILURE;
}
@ -310,22 +302,18 @@ nsXPCWrappedJS::GetNewOrUsed(XPCCallContext& ccx,
{ // scoped lock
XPCAutoLock lock(rt->GetMapLock());
root = map->Find(rootJSObj);
if (root)
{
if (root) {
if ((nsnull != (wrapper = root->Find(aIID))) ||
(nsnull != (wrapper = root->FindInherited(aIID))))
{
(nsnull != (wrapper = root->FindInherited(aIID)))) {
NS_ADDREF(wrapper);
goto return_wrapper;
}
}
}
if (!root)
{
if (!root) {
// build the root wrapper
if (rootJSObj == aJSObj)
{
if (rootJSObj == aJSObj) {
// the root will do double duty as the interface wrapper
wrapper = root = new nsXPCWrappedJS(ccx, aJSObj, clazz, nsnull,
aOuter);
@ -340,8 +328,7 @@ nsXPCWrappedJS::GetNewOrUsed(XPCCallContext& ccx,
}
goto return_wrapper;
}
else
{
else {
// just a root wrapper
nsXPCWrappedJSClass* rootClazz = nsnull;
nsXPCWrappedJSClass::GetNewOrUsed(ccx, NS_GET_IID(nsISupports),
@ -372,8 +359,7 @@ nsXPCWrappedJS::GetNewOrUsed(XPCCallContext& ccx,
NS_ASSERTION(root,"bad root");
NS_ASSERTION(clazz,"bad clazz");
if (!wrapper)
{
if (!wrapper) {
wrapper = new nsXPCWrappedJS(ccx, aJSObj, clazz, root, aOuter);
if (!wrapper)
goto return_wrapper;
@ -436,13 +422,11 @@ nsXPCWrappedJS::~nsXPCWrappedJS()
{
NS_PRECONDITION(0 == mRefCnt, "refcounting error");
if (mRoot == this)
{
if (mRoot == this) {
// Remove this root wrapper from the map
XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance();
JSObject2WrappedJSMap* map = rt->GetWrappedJSMap();
if (map)
{
if (map) {
XPCAutoLock lock(rt->GetMapLock());
map->Remove(this);
}
@ -453,17 +437,13 @@ nsXPCWrappedJS::~nsXPCWrappedJS()
void
nsXPCWrappedJS::Unlink()
{
if (IsValid())
{
if (IsValid()) {
XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance();
if (rt)
{
if (mRoot == this)
{
if (rt) {
if (mRoot == this) {
// remove this root wrapper from the map
JSObject2WrappedJSMap* map = rt->GetWrappedJSMap();
if (map)
{
if (map) {
XPCAutoLock lock(rt->GetMapLock());
map->Remove(this);
}
@ -476,18 +456,14 @@ nsXPCWrappedJS::Unlink()
mJSObj = nsnull;
}
if (mRoot == this)
{
if (mRoot == this) {
ClearWeakReferences();
}
else if (mRoot)
{
else if (mRoot) {
// unlink this wrapper
nsXPCWrappedJS* cur = mRoot;
while (1)
{
if (cur->mNext == this)
{
while (1) {
if (cur->mNext == this) {
cur->mNext = mNext;
break;
}
@ -499,16 +475,13 @@ nsXPCWrappedJS::Unlink()
}
NS_IF_RELEASE(mClass);
if (mOuter)
{
if (mOuter) {
XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance();
if (rt->GetThreadRunningGC())
{
if (rt->GetThreadRunningGC()) {
rt->DeferredRelease(mOuter);
mOuter = nsnull;
}
else
{
else {
NS_RELEASE(mOuter);
}
}
@ -520,8 +493,7 @@ nsXPCWrappedJS::Find(REFNSIID aIID)
if (aIID.Equals(NS_GET_IID(nsISupports)))
return mRoot;
for (nsXPCWrappedJS* cur = mRoot; cur; cur = cur->mNext)
{
for (nsXPCWrappedJS* cur = mRoot; cur; cur = cur->mNext) {
if (aIID.Equals(cur->GetIID()))
return cur;
}
@ -535,8 +507,7 @@ nsXPCWrappedJS::FindInherited(REFNSIID aIID)
{
NS_ASSERTION(!aIID.Equals(NS_GET_IID(nsISupports)), "bad call sequence");
for (nsXPCWrappedJS* cur = mRoot; cur; cur = cur->mNext)
{
for (nsXPCWrappedJS* cur = mRoot; cur; cur = cur->mNext) {
bool found;
if (NS_SUCCEEDED(cur->GetClass()->GetInterfaceInfo()->
HasAncestor(&aIID, &found)) && found)
@ -672,10 +643,8 @@ nsXPCWrappedJS::DebugDump(PRInt16 depth)
if (!isRoot)
XPC_LOG_OUTDENT();
if (mNext)
{
if (isRoot)
{
if (mNext) {
if (isRoot) {
XPC_LOG_ALWAYS(("Additional wrappers for this object..."));
XPC_LOG_INDENT();
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -118,8 +118,7 @@ JSBool
XPCNativeMember::Resolve(XPCCallContext& ccx, XPCNativeInterface* iface,
JSObject *parent, jsval *vp)
{
if (IsConstant())
{
if (IsConstant()) {
const nsXPTConstant* constant;
if (NS_FAILED(iface->GetInterfaceInfo()->GetConstant(mIndex, &constant)))
return JS_FALSE;
@ -149,8 +148,7 @@ XPCNativeMember::Resolve(XPCCallContext& ccx, XPCNativeInterface* iface,
intN argc;
JSNative callback;
if (IsMethod())
{
if (IsMethod()) {
const nsXPTMethodInfo* info;
if (NS_FAILED(iface->GetInterfaceInfo()->GetMethodInfo(mIndex, &info)))
return JS_FALSE;
@ -162,8 +160,7 @@ XPCNativeMember::Resolve(XPCCallContext& ccx, XPCNativeInterface* iface,
callback = XPC_WN_CallMethod;
}
else
{
else {
argc = 0;
callback = XPC_WN_GetterSetter;
}
@ -219,14 +216,12 @@ XPCNativeInterface::GetNewOrUsed(XPCCallContext& ccx, const nsIID* iid)
{ // scoped lock
XPCAutoLock lock(rt->GetMapLock());
XPCNativeInterface* iface2 = map->Add(iface);
if (!iface2)
{
if (!iface2) {
NS_ERROR("failed to add our interface!");
DestroyInstance(iface);
iface = nsnull;
}
else if (iface2 != iface)
{
else if (iface2 != iface) {
DestroyInstance(iface);
iface = iface2;
}
@ -266,14 +261,12 @@ XPCNativeInterface::GetNewOrUsed(XPCCallContext& ccx, nsIInterfaceInfo* info)
{ // scoped lock
XPCAutoLock lock(rt->GetMapLock());
XPCNativeInterface* iface2 = map->Add(iface);
if (!iface2)
{
if (!iface2) {
NS_ERROR("failed to add our interface!");
DestroyInstance(iface);
iface = nsnull;
}
else if (iface2 != iface)
{
else if (iface2 != iface) {
DestroyInstance(iface);
iface = iface2;
}
@ -345,25 +338,21 @@ XPCNativeInterface::NewInstance(XPCCallContext& ccx,
totalCount = methodCount + constCount;
if (totalCount > MAX_LOCAL_MEMBER_COUNT)
{
if (totalCount > MAX_LOCAL_MEMBER_COUNT) {
members = new XPCNativeMember[totalCount];
if (!members)
return nsnull;
}
else
{
else {
members = local_members;
}
// NOTE: since getters and setters share a member, we might not use all
// of the member objects.
for (i = 0; i < methodCount; i++)
{
for (i = 0; i < methodCount; i++) {
const nsXPTMethodInfo* info;
if (NS_FAILED(aInfo->GetMethodInfo(i, &info)))
{
if (NS_FAILED(aInfo->GetMethodInfo(i, &info))) {
failed = JS_TRUE;
break;
}
@ -376,16 +365,14 @@ XPCNativeInterface::NewInstance(XPCCallContext& ccx,
continue;
str = JS_InternString(ccx, info->GetName());
if (!str)
{
if (!str) {
NS_ERROR("bad method name");
failed = JS_TRUE;
break;
}
name = INTERNED_STRING_TO_JSID(ccx, str);
if (info->IsSetter())
{
if (info->IsSetter()) {
NS_ASSERTION(realTotalCount,"bad setter");
// Note: ASSUMES Getter/Setter pairs are next to each other
// This is a rule of the typelib spec.
@ -395,8 +382,7 @@ XPCNativeInterface::NewInstance(XPCCallContext& ccx,
NS_ASSERTION(cur->GetIndex() == i-1,"bad setter");
cur->SetWritableAttribute();
}
else
{
else {
// XXX need better way to find dups
// NS_ASSERTION(!LookupMemberByID(name),"duplicate method name");
cur = &members[realTotalCount++];
@ -408,20 +394,16 @@ XPCNativeInterface::NewInstance(XPCCallContext& ccx,
}
}
if (!failed)
{
for (i = 0; i < constCount; i++)
{
if (!failed) {
for (i = 0; i < constCount; i++) {
const nsXPTConstant* constant;
if (NS_FAILED(aInfo->GetConstant(i, &constant)))
{
if (NS_FAILED(aInfo->GetConstant(i, &constant))) {
failed = JS_TRUE;
break;
}
str = JS_InternString(ccx, constant->GetName());
if (!str)
{
if (!str) {
NS_ERROR("bad constant name");
failed = JS_TRUE;
break;
@ -437,19 +419,16 @@ XPCNativeInterface::NewInstance(XPCCallContext& ccx,
}
}
if (!failed)
{
if (!failed) {
const char* bytes;
if (NS_FAILED(aInfo->GetNameShared(&bytes)) || !bytes ||
nsnull == (str = JS_InternString(ccx, bytes)))
{
nsnull == (str = JS_InternString(ccx, bytes))) {
failed = JS_TRUE;
}
interfaceName = INTERNED_STRING_TO_JSID(ccx, str);
}
if (!failed)
{
if (!failed) {
// Use placement new to create an object with the right amount of space
// to hold the members array
int size = sizeof(XPCNativeInterface);
@ -459,8 +438,7 @@ XPCNativeInterface::NewInstance(XPCCallContext& ccx,
if (place)
obj = new(place) XPCNativeInterface(aInfo, interfaceName);
if (obj)
{
if (obj) {
obj->mMemberCount = realTotalCount;
// copy valid members
if (realTotalCount)
@ -535,14 +513,12 @@ XPCNativeSet::GetNewOrUsed(XPCCallContext& ccx, const nsIID* iid)
{ // scoped lock
XPCAutoLock lock(rt->GetMapLock());
XPCNativeSet* set2 = map->Add(&key, set);
if (!set2)
{
if (!set2) {
NS_ERROR("failed to add our set!");
DestroyInstance(set);
set = nsnull;
}
else if (set2 != set)
{
else if (set2 != set) {
DestroyInstance(set);
set = set2;
}
@ -574,8 +550,7 @@ XPCNativeSet::GetNewOrUsed(XPCCallContext& ccx, nsIClassInfo* classInfo)
AutoMarkingNativeInterfacePtrArrayPtr interfaceArray(ccx);
PRUint32 iidCount = 0;
if (NS_FAILED(classInfo->GetInterfaces(&iidCount, &iidArray)))
{
if (NS_FAILED(classInfo->GetInterfaces(&iidCount, &iidArray))) {
// Note: I'm making it OK for this call to fail so that one can add
// nsIClassInfo to classes implemented in script without requiring this
// method to be implemented.
@ -589,8 +564,7 @@ XPCNativeSet::GetNewOrUsed(XPCCallContext& ccx, nsIClassInfo* classInfo)
// !!! from here on we only exit through the 'out' label !!!
if (iidCount)
{
if (iidCount) {
AutoMarkingNativeInterfacePtrArrayPtr
arr(ccx, new XPCNativeInterface*[iidCount], iidCount, PR_TRUE);
if (!arr)
@ -602,8 +576,7 @@ XPCNativeSet::GetNewOrUsed(XPCCallContext& ccx, nsIClassInfo* classInfo)
nsIID** currentIID = iidArray;
PRUint16 interfaceCount = 0;
for (PRUint32 i = 0; i < iidCount; i++)
{
for (PRUint32 i = 0; i < iidCount; i++) {
nsIID* iid = *(currentIID++);
if (!iid) {
NS_ERROR("Null found in classinfo interface list");
@ -613,8 +586,7 @@ XPCNativeSet::GetNewOrUsed(XPCCallContext& ccx, nsIClassInfo* classInfo)
XPCNativeInterface* iface =
XPCNativeInterface::GetNewOrUsed(ccx, iid);
if (!iface)
{
if (!iface) {
// XXX warn here
continue;
}
@ -623,11 +595,9 @@ XPCNativeSet::GetNewOrUsed(XPCCallContext& ccx, nsIClassInfo* classInfo)
interfaceCount++;
}
if (interfaceCount)
{
if (interfaceCount) {
set = NewInstance(ccx, interfaceArray, interfaceCount);
if (set)
{
if (set) {
NativeSetMap* map2 = rt->GetNativeSetMap();
if (!map2)
goto out;
@ -637,15 +607,13 @@ XPCNativeSet::GetNewOrUsed(XPCCallContext& ccx, nsIClassInfo* classInfo)
{ // scoped lock
XPCAutoLock lock(rt->GetMapLock());
XPCNativeSet* set2 = map2->Add(&key, set);
if (!set2)
{
if (!set2) {
NS_ERROR("failed to add our set!");
DestroyInstance(set);
set = nsnull;
goto out;
}
if (set2 != set)
{
if (set2 != set) {
DestroyInstance(set);
set = set2;
}
@ -726,14 +694,12 @@ XPCNativeSet::GetNewOrUsed(XPCCallContext& ccx,
{ // scoped lock
XPCAutoLock lock(rt->GetMapLock());
XPCNativeSet* set2 = map->Add(&key, set);
if (!set2)
{
if (!set2) {
NS_ERROR("failed to add our set!");
DestroyInstance(set);
set = nsnull;
}
else if (set2 != set)
{
else if (set2 != set) {
DestroyInstance(set);
set = set2;
}
@ -764,8 +730,7 @@ XPCNativeSet::NewInstance(XPCCallContext& ccx,
PRUint16 i;
XPCNativeInterface** pcur;
for (i = 0, pcur = array; i < count; i++, pcur++)
{
for (i = 0, pcur = array; i < count; i++, pcur++) {
if (*pcur == isup)
slots--;
}
@ -779,8 +744,7 @@ XPCNativeSet::NewInstance(XPCCallContext& ccx,
if (place)
obj = new(place) XPCNativeSet();
if (obj)
{
if (obj) {
// Stick the nsISupports in front and skip additional nsISupport(s)
XPCNativeInterface** inp = array;
XPCNativeInterface** outp = (XPCNativeInterface**) &obj->mInterfaces;
@ -788,8 +752,7 @@ XPCNativeSet::NewInstance(XPCCallContext& ccx,
*(outp++) = isup;
for (i = 0; i < count; i++)
{
for (i = 0; i < count; i++) {
XPCNativeInterface* cur;
if (isup == (cur = *(inp++)))
@ -826,26 +789,22 @@ XPCNativeSet::NewInstanceMutate(XPCNativeSet* otherSet,
if (place)
obj = new(place) XPCNativeSet();
if (obj)
{
if (otherSet)
{
if (obj) {
if (otherSet) {
obj->mMemberCount = otherSet->GetMemberCount() +
newInterface->GetMemberCount();
obj->mInterfaceCount = otherSet->mInterfaceCount + 1;
XPCNativeInterface** src = otherSet->mInterfaces;
XPCNativeInterface** dest = obj->mInterfaces;
for (PRUint16 i = 0; i < obj->mInterfaceCount; i++)
{
for (PRUint16 i = 0; i < obj->mInterfaceCount; i++) {
if (i == position)
*dest++ = newInterface;
else
*dest++ = *src++;
}
}
else
{
else {
obj->mMemberCount = newInterface->GetMemberCount();
obj->mInterfaceCount = 1;
obj->mInterfaces[0] = newInterface;
@ -872,8 +831,7 @@ XPCNativeSet::DebugDump(PRInt16 depth)
XPC_LOG_INDENT();
XPC_LOG_ALWAYS(("mInterfaceCount of %d", mInterfaceCount));
if (depth)
{
if (depth) {
for (PRUint16 i = 0; i < mInterfaceCount; i++)
mInterfaces[i]->DebugDump(depth);
}

View File

@ -86,8 +86,7 @@ ToStringGuts(XPCCallContext& ccx)
else
sz = JS_smprintf("[xpconnect wrapped native prototype]");
if (!sz)
{
if (!sz) {
JS_ReportOutOfMemory(ccx);
return JS_FALSE;
}
@ -110,8 +109,7 @@ XPC_WN_Shared_ToString(JSContext *cx, uintN argc, jsval *vp)
if (!obj)
return JS_FALSE;
if (IS_SLIM_WRAPPER(obj))
{
if (IS_SLIM_WRAPPER(obj)) {
XPCNativeScriptableInfo *si =
GetSlimWrapperProto(obj)->GetScriptableInfo();
#ifdef DEBUG
@ -173,11 +171,9 @@ GetDoubleWrappedJSObject(XPCCallContext& ccx, XPCWrappedNative* wrapper)
JSObject* obj = nsnull;
nsCOMPtr<nsIXPConnectWrappedJS>
underware = do_QueryInterface(wrapper->GetIdentityObject());
if (underware)
{
if (underware) {
JSObject* mainObj = nsnull;
if (NS_SUCCEEDED(underware->GetJSObject(&mainObj)) && mainObj)
{
if (NS_SUCCEEDED(underware->GetJSObject(&mainObj)) && mainObj) {
jsid id = ccx.GetRuntime()->
GetStringID(XPCJSRuntime::IDX_WRAPPED_JSOBJECT);
@ -187,8 +183,7 @@ GetDoubleWrappedJSObject(XPCCallContext& ccx, XPCWrappedNative* wrapper)
jsval val;
if (JS_GetPropertyById(ccx, mainObj, id, &val) &&
!JSVAL_IS_PRIMITIVE(val))
{
!JSVAL_IS_PRIMITIVE(val)) {
obj = JSVAL_TO_OBJECT(val);
}
}
@ -214,8 +209,7 @@ XPC_WN_DoubleWrappedGetter(JSContext *cx, uintN argc, jsval *vp)
NS_ASSERTION(JS_TypeOfValue(cx, JS_CALLEE(cx, vp)) == JSTYPE_FUNCTION, "bad function");
JSObject* realObject = GetDoubleWrappedJSObject(ccx, wrapper);
if (!realObject)
{
if (!realObject) {
// This is pretty unexpected at this point. The object originally
// responded to this get property call and now gives no object.
// XXX Should this throw something at the caller?
@ -230,14 +224,12 @@ XPC_WN_DoubleWrappedGetter(JSContext *cx, uintN argc, jsval *vp)
XPCContext* xpcc = ccx.GetXPCContext();
sm = xpcc->GetAppropriateSecurityManager(nsIXPCSecurityManager::HOOK_GET_PROPERTY);
if (sm)
{
if (sm) {
AutoMarkingNativeInterfacePtr iface(ccx);
iface = XPCNativeInterface::
GetNewOrUsed(ccx, &NS_GET_IID(nsIXPCWrappedJSObjectGetter));
if (iface)
{
if (iface) {
jsid id = ccx.GetRuntime()->
GetStringID(XPCJSRuntime::IDX_WRAPPED_JSOBJECT);
@ -248,8 +240,7 @@ XPC_WN_DoubleWrappedGetter(JSContext *cx, uintN argc, jsval *vp)
ccx.GetFlattenedJSObject(),
wrapper->GetIdentityObject(),
wrapper->GetClassInfo(), id,
wrapper->GetSecurityInfoAddr())))
{
wrapper->GetSecurityInfoAddr()))) {
// The SecurityManager should have set an exception.
return JS_FALSE;
}
@ -287,8 +278,7 @@ DefinePropertyIfFound(XPCCallContext& ccx,
JSBool found;
const char* name;
if (set)
{
if (set) {
if (iface)
found = JS_TRUE;
else
@ -297,20 +287,16 @@ DefinePropertyIfFound(XPCCallContext& ccx,
else
found = (nsnull != (member = iface->FindMember(id)));
if (!found)
{
if (reflectToStringAndToSource)
{
if (!found) {
if (reflectToStringAndToSource) {
JSNative call;
if (id == rt->GetStringID(XPCJSRuntime::IDX_TO_STRING))
{
if (id == rt->GetStringID(XPCJSRuntime::IDX_TO_STRING)) {
call = XPC_WN_Shared_ToString;
name = rt->GetStringName(XPCJSRuntime::IDX_TO_STRING);
id = rt->GetStringID(XPCJSRuntime::IDX_TO_STRING);
}
else if (id == rt->GetStringID(XPCJSRuntime::IDX_TO_SOURCE))
{
else if (id == rt->GetStringID(XPCJSRuntime::IDX_TO_SOURCE)) {
call = XPC_WN_Shared_ToSource;
name = rt->GetStringName(XPCJSRuntime::IDX_TO_SOURCE);
id = rt->GetStringID(XPCJSRuntime::IDX_TO_SOURCE);
@ -319,11 +305,9 @@ DefinePropertyIfFound(XPCCallContext& ccx,
else
call = nsnull;
if (call)
{
if (call) {
JSFunction* fun = JS_NewFunction(ccx, call, 0, 0, obj, name);
if (!fun)
{
if (!fun) {
JS_ReportOutOfMemory(ccx);
return JS_FALSE;
}
@ -342,8 +326,7 @@ DefinePropertyIfFound(XPCCallContext& ccx,
// interface. Then we'll see if the object actually *does* this
// interface and add a tearoff as necessary.
if (wrapperToReflectInterfaceNames)
{
if (wrapperToReflectInterfaceNames) {
JSAutoByteString name;
AutoMarkingNativeInterfacePtr iface2(ccx);
XPCWrappedNativeTearOff* to;
@ -365,8 +348,7 @@ DefinePropertyIfFound(XPCCallContext& ccx,
nsnull, nsnull,
propFlags & ~JSPROP_ENUMERATE);
}
else if (NS_FAILED(rv) && rv != NS_ERROR_NO_INTERFACE)
{
else if (NS_FAILED(rv) && rv != NS_ERROR_NO_INTERFACE) {
return Throw(rv, ccx);
}
}
@ -374,8 +356,7 @@ DefinePropertyIfFound(XPCCallContext& ccx,
// This *might* be a double wrapped JSObject
if (wrapperToReflectDoubleWrap &&
id == rt->GetStringID(XPCJSRuntime::IDX_WRAPPED_JSOBJECT) &&
GetDoubleWrappedJSObject(ccx, wrapperToReflectDoubleWrap))
{
GetDoubleWrappedJSObject(ccx, wrapperToReflectDoubleWrap)) {
// We build and add a getter function.
// A security check is done on a per-get basis.
@ -411,10 +392,8 @@ DefinePropertyIfFound(XPCCallContext& ccx,
return JS_TRUE;
}
if (!member)
{
if (wrapperToReflectInterfaceNames)
{
if (!member) {
if (wrapperToReflectInterfaceNames) {
XPCWrappedNativeTearOff* to =
wrapperToReflectInterfaceNames->FindTearOff(ccx, iface, JS_TRUE);
@ -436,8 +415,7 @@ DefinePropertyIfFound(XPCCallContext& ccx,
return JS_TRUE;
}
if (member->IsConstant())
{
if (member->IsConstant()) {
jsval val;
AutoResolveName arn(ccx, id);
if (resolved)
@ -469,8 +447,7 @@ DefinePropertyIfFound(XPCCallContext& ccx,
}
#endif
if (member->IsMethod())
{
if (member->IsMethod()) {
AutoResolveName arn(ccx, id);
if (resolved)
*resolved = JS_TRUE;
@ -486,14 +463,12 @@ DefinePropertyIfFound(XPCCallContext& ccx,
JSObject* funobj = JSVAL_TO_OBJECT(funval);
JSPropertyOp getter = JS_DATA_TO_FUNC_PTR(JSPropertyOp, funobj);
JSStrictPropertyOp setter;
if (member->IsWritableAttribute())
{
if (member->IsWritableAttribute()) {
propFlags |= JSPROP_SETTER;
propFlags &= ~JSPROP_READONLY;
setter = JS_DATA_TO_FUNC_PTR(JSStrictPropertyOp, funobj);
}
else
{
else {
setter = js_GetterOnlyPropertyStub;
}
@ -544,8 +519,7 @@ XPC_WN_CannotModifyStrictPropertyStub(JSContext *cx, JSObject *obj, jsid id, JSB
static JSBool
XPC_WN_Shared_Convert(JSContext *cx, JSObject *obj, JSType type, jsval *vp)
{
if (type == JSTYPE_OBJECT)
{
if (type == JSTYPE_OBJECT) {
*vp = OBJECT_TO_JSVAL(obj);
return JS_TRUE;
}
@ -555,16 +529,13 @@ XPC_WN_Shared_Convert(JSContext *cx, JSObject *obj, JSType type, jsval *vp)
XPCWrappedNative* wrapper = ccx.GetWrapper();
THROW_AND_RETURN_IF_BAD_WRAPPER(cx, wrapper);
switch (type)
{
switch (type) {
case JSTYPE_FUNCTION:
{
if (!ccx.GetTearOff())
{
if (!ccx.GetTearOff()) {
XPCNativeScriptableInfo* si = wrapper->GetScriptableInfo();
if (si && (si->GetFlags().WantCall() ||
si->GetFlags().WantConstruct()))
{
si->GetFlags().WantConstruct())) {
*vp = OBJECT_TO_JSVAL(obj);
return JS_TRUE;
}
@ -584,8 +555,7 @@ XPC_WN_Shared_Convert(JSContext *cx, JSObject *obj, JSType type, jsval *vp)
ccx.SetArgsAndResultPtr(0, nsnull, vp);
XPCNativeMember* member = ccx.GetMember();
if (member && member->IsMethod())
{
if (member && member->IsMethod()) {
if (!XPCWrappedNative::CallMethod(ccx))
return JS_FALSE;
@ -623,12 +593,10 @@ XPC_WN_Shared_Enumerate(JSContext *cx, JSObject *obj)
PRUint16 interface_count = set->GetInterfaceCount();
XPCNativeInterface** interfaceArray = set->GetInterfaceArray();
for (PRUint16 i = 0; i < interface_count; i++)
{
for (PRUint16 i = 0; i < interface_count; i++) {
XPCNativeInterface* iface = interfaceArray[i];
PRUint16 member_count = iface->GetMemberCount();
for (PRUint16 k = 0; k < member_count; k++)
{
for (PRUint16 k = 0; k < member_count; k++) {
XPCNativeMember* member = iface->GetMemberAt(k);
jsid name = member->GetName();
@ -657,8 +625,7 @@ XPC_WN_NoHelper_Finalize(JSContext *cx, JSObject *obj)
if (!p)
return;
if (IS_SLIM_WRAPPER_OBJECT(obj))
{
if (IS_SLIM_WRAPPER_OBJECT(obj)) {
SLIM_LOG(("----- %i finalized slim wrapper (%p, %p)\n",
++sFinalizedSlimWrappers, obj, p));
@ -684,15 +651,13 @@ TraceScopeJSObjects(JSTracer *trc, XPCWrappedNativeScope* scope)
JS_CALL_OBJECT_TRACER(trc, obj, "XPCWrappedNativeScope::mGlobalJSObject");
obj = scope->GetPrototypeJSObject();
if (obj)
{
if (obj) {
JS_CALL_OBJECT_TRACER(trc, obj,
"XPCWrappedNativeScope::mPrototypeJSObject");
}
obj = scope->GetPrototypeJSFunction();
if (obj)
{
if (obj) {
JS_CALL_OBJECT_TRACER(trc, obj,
"XPCWrappedNativeScope::mPrototypeJSFunction");
}
@ -737,17 +702,14 @@ MarkWrappedNative(JSTracer *trc, JSObject *obj, bool helper)
XPCWrappedNative* wrapper =
XPCWrappedNative::GetWrappedNativeOfJSObject(nsnull, obj, nsnull, &obj2);
if (wrapper)
{
if (wrapper->IsValid())
{
if (wrapper) {
if (wrapper->IsValid()) {
if (helper)
wrapper->GetScriptableCallback()->Trace(wrapper, trc, obj);
TraceForValidWrapper(trc, wrapper);
}
}
else if (obj2)
{
else if (obj2) {
GetSlimWrapperProto(obj2)->TraceJS(trc);
}
}
@ -800,8 +762,7 @@ XPC_WN_Equality(JSContext *cx, JSObject *obj, const jsval *valp, JSBool *bp)
JSObject *obj2;
XPCWrappedNative *wrapper =
XPCWrappedNative::GetWrappedNativeOfJSObject(cx, obj, nsnull, &obj2);
if (obj2)
{
if (obj2) {
*bp = !JSVAL_IS_PRIMITIVE(v) && (JSVAL_TO_OBJECT(v) == obj2);
return JS_TRUE;
@ -810,16 +771,14 @@ XPC_WN_Equality(JSContext *cx, JSObject *obj, const jsval *valp, JSBool *bp)
THROW_AND_RETURN_IF_BAD_WRAPPER(cx, wrapper);
XPCNativeScriptableInfo* si = wrapper->GetScriptableInfo();
if (si && si->GetFlags().WantEquality())
{
if (si && si->GetFlags().WantEquality()) {
bool res;
nsresult rv = si->GetCallback()->Equality(wrapper, cx, obj, v, &res);
if (NS_FAILED(rv))
return Throw(rv, cx);
*bp = res;
}
else if (!JSVAL_IS_PRIMITIVE(v))
{
else if (!JSVAL_IS_PRIMITIVE(v)) {
JSObject *other = JSVAL_TO_OBJECT(v);
*bp = (obj == other ||
@ -835,29 +794,25 @@ XPC_WN_OuterObject(JSContext *cx, JSObject *obj)
{
XPCWrappedNative *wrapper =
static_cast<XPCWrappedNative *>(js::GetObjectPrivate(obj));
if (!wrapper)
{
if (!wrapper) {
Throw(NS_ERROR_XPC_BAD_OP_ON_WN_PROTO, cx);
return nsnull;
}
if (!wrapper->IsValid())
{
if (!wrapper->IsValid()) {
Throw(NS_ERROR_XPC_HAS_BEEN_SHUTDOWN, cx);
return nsnull;
}
XPCNativeScriptableInfo* si = wrapper->GetScriptableInfo();
if (si && si->GetFlags().WantOuterObject())
{
if (si && si->GetFlags().WantOuterObject()) {
JSObject *newThis;
nsresult rv =
si->GetCallback()->OuterObject(wrapper, cx, obj, &newThis);
if (NS_FAILED(rv))
{
if (NS_FAILED(rv)) {
Throw(rv, cx);
return nsnull;
@ -976,8 +931,7 @@ XPC_WN_MaybeResolvingStrictPropertyStub(JSContext *cx, JSObject *obj, jsid id, J
#define PRE_HELPER_STUB \
XPCWrappedNative* wrapper; \
nsIXPCScriptable* si; \
if (IS_SLIM_WRAPPER(obj)) \
{ \
if (IS_SLIM_WRAPPER(obj)) { \
wrapper = nsnull; \
si = GetSlimWrapperProto(obj)->GetScriptableInfo()->GetCallback(); \
} \
@ -1099,8 +1053,7 @@ static void
XPC_WN_Helper_Finalize(JSContext *cx, JSObject *obj)
{
nsISupports* p = static_cast<nsISupports*>(xpc_GetJSPrivate(obj));
if (IS_SLIM_WRAPPER(obj))
{
if (IS_SLIM_WRAPPER(obj)) {
SLIM_LOG(("----- %i finalized slim wrapper (%p, %p)\n",
++sFinalizedSlimWrappers, obj, p));
@ -1131,8 +1084,7 @@ XPC_WN_Helper_NewResolve(JSContext *cx, JSObject *obj, jsid id, uintN flags,
nsresult rv = NS_OK;
bool retval = JS_TRUE;
JSObject* obj2FromScriptable = nsnull;
if (IS_SLIM_WRAPPER(obj))
{
if (IS_SLIM_WRAPPER(obj)) {
XPCNativeScriptableInfo *si =
GetSlimWrapperProto(obj)->GetScriptableInfo();
if (!si->GetFlags().WantNewResolve())
@ -1160,8 +1112,7 @@ XPC_WN_Helper_NewResolve(JSContext *cx, JSObject *obj, jsid id, uintN flags,
jsid old = ccx.SetResolveName(id);
XPCNativeScriptableInfo* si = wrapper->GetScriptableInfo();
if (si && si->GetFlags().WantNewResolve())
{
if (si && si->GetFlags().WantNewResolve()) {
XPCWrappedNative* oldResolvingWrapper;
JSBool allowPropMods = si->GetFlags().AllowPropModsDuringResolve();
@ -1178,17 +1129,14 @@ XPC_WN_Helper_NewResolve(JSContext *cx, JSObject *obj, jsid id, uintN flags,
old = ccx.SetResolveName(old);
NS_ASSERTION(old == id, "bad nest");
if (NS_FAILED(rv))
{
if (NS_FAILED(rv)) {
return Throw(rv, cx);
}
if (obj2FromScriptable)
{
if (obj2FromScriptable) {
*objp = obj2FromScriptable;
}
else if (wrapper->HasMutatedSet())
{
else if (wrapper->HasMutatedSet()) {
// We are here if scriptable did not resolve this property and
// it *might* be in the instance set but not the proto set.
@ -1200,8 +1148,7 @@ XPC_WN_Helper_NewResolve(JSContext *cx, JSObject *obj, jsid id, uintN flags,
JSBool IsLocal;
if (set->FindMember(id, &member, &iface, protoSet, &IsLocal) &&
IsLocal)
{
IsLocal) {
XPCWrappedNative* oldResolvingWrapper;
XPCNativeScriptableFlags siFlags(0);
@ -1274,8 +1221,7 @@ XPC_WN_JSOp_Enumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op,
jsval *statep, jsid *idp)
{
js::Class *clazz = js::GetObjectClass(obj);
if (!IS_WRAPPER_CLASS(clazz) || clazz == &XPC_WN_NoHelper_JSClass)
{
if (!IS_WRAPPER_CLASS(clazz) || clazz == &XPC_WN_NoHelper_JSClass) {
// obj must be a prototype object or a wrapper w/o a
// helper. Short circuit this call to the default
// implementation.
@ -1296,14 +1242,12 @@ XPC_WN_JSOp_Enumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op,
bool retval = JS_TRUE;
nsresult rv;
if (si->GetFlags().WantNewEnumerate())
{
if (si->GetFlags().WantNewEnumerate()) {
if (((enum_op == JSENUMERATE_INIT &&
!si->GetFlags().DontEnumStaticProps()) ||
enum_op == JSENUMERATE_INIT_ALL) &&
wrapper->HasMutatedSet() &&
!XPC_WN_Shared_Enumerate(cx, obj))
{
!XPC_WN_Shared_Enumerate(cx, obj)) {
*statep = JSVAL_NULL;
return JS_FALSE;
}
@ -1315,8 +1259,7 @@ XPC_WN_JSOp_Enumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op,
NewEnumerate(wrapper, cx, obj, enum_op, statep, idp, &retval);
if ((enum_op == JSENUMERATE_INIT || enum_op == JSENUMERATE_INIT_ALL) &&
(NS_FAILED(rv) || !retval))
{
(NS_FAILED(rv) || !retval)) {
*statep = JSVAL_NULL;
}
@ -1325,15 +1268,12 @@ XPC_WN_JSOp_Enumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op,
return retval;
}
if (si->GetFlags().WantEnumerate())
{
if (enum_op == JSENUMERATE_INIT || enum_op == JSENUMERATE_INIT_ALL)
{
if (si->GetFlags().WantEnumerate()) {
if (enum_op == JSENUMERATE_INIT || enum_op == JSENUMERATE_INIT_ALL) {
if ((enum_op == JSENUMERATE_INIT_ALL ||
!si->GetFlags().DontEnumStaticProps()) &&
wrapper->HasMutatedSet() &&
!XPC_WN_Shared_Enumerate(cx, obj))
{
!XPC_WN_Shared_Enumerate(cx, obj)) {
*statep = JSVAL_NULL;
return JS_FALSE;
}
@ -1438,8 +1378,7 @@ XPCNativeScriptableInfo::Construct(XPCCallContext& ccx,
return nsnull;
char* name = nsnull;
if (NS_FAILED(sci->GetCallback()->GetClassName(&name)) || !name)
{
if (NS_FAILED(sci->GetCallback()->GetClassName(&name)) || !name) {
delete newObj;
return nsnull;
}
@ -1454,8 +1393,7 @@ XPCNativeScriptableInfo::Construct(XPCCallContext& ccx,
sci->GetInterfacesBitmap(), newObj);
}
if (!success)
{
if (!success) {
delete newObj;
return nsnull;
}
@ -1548,28 +1486,24 @@ XPCNativeScriptableShared::PopulateJSClass(JSBool isGlobal)
ops->clear = XPC_WN_JSOp_Clear;
ops->thisObject = XPC_WN_JSOp_ThisObject;
if (mFlags.WantCall() || mFlags.WantConstruct())
{
if (mFlags.WantCall() || mFlags.WantConstruct()) {
ops->typeOf = XPC_WN_JSOp_TypeOf_Function;
if (mFlags.WantCall())
mJSClass.base.call = XPC_WN_Helper_Call;
if (mFlags.WantConstruct())
mJSClass.base.construct = XPC_WN_Helper_Construct;
}
else
{
else {
ops->typeOf = XPC_WN_JSOp_TypeOf_Object;
}
if (mFlags.UseStubEqualityHook())
{
if (mFlags.UseStubEqualityHook()) {
NS_ASSERTION(!mFlags.WantEquality(),
"If you want an Equality callback, you can't use a stub "
"equality hook");
mJSClass.base.ext.equality = nsnull;
}
else
{
else {
mJSClass.base.ext.equality = XPC_WN_Equality;
}
@ -1642,8 +1576,7 @@ XPC_WN_GetterSetter(JSContext *cx, uintN argc, jsval *vp)
{
const char* funname = nsnull;
JSAutoByteString bytes;
if (JS_TypeOfValue(cx, JS_CALLEE(cx, vp)) == JSTYPE_FUNCTION)
{
if (JS_TypeOfValue(cx, JS_CALLEE(cx, vp)) == JSTYPE_FUNCTION) {
JSString *funid = JS_GetFunctionId(funobj->getFunctionPrivate());
funname = !funid ? "" : bytes.encode(cx, funid) ? bytes.ptr() : "<error>";
}
@ -1664,8 +1597,7 @@ XPC_WN_GetterSetter(JSContext *cx, uintN argc, jsval *vp)
return Throw(NS_ERROR_XPC_CANT_GET_METHOD_INFO, cx);
ccx.SetArgsAndResultPtr(argc, JS_ARGV(cx, vp), vp);
if (argc && member->IsWritableAttribute())
{
if (argc && member->IsWritableAttribute()) {
ccx.SetCallInfo(iface, member, JS_TRUE);
JSBool retval = XPCWrappedNative::SetAttribute(ccx);
if (retval)
@ -1708,13 +1640,11 @@ XPC_WN_Shared_Proto_Enumerate(JSContext *cx, JSObject *obj)
PRUint16 interface_count = set->GetInterfaceCount();
XPCNativeInterface** interfaceArray = set->GetInterfaceArray();
for (PRUint16 i = 0; i < interface_count; i++)
{
for (PRUint16 i = 0; i < interface_count; i++) {
XPCNativeInterface* iface = interfaceArray[i];
PRUint16 member_count = iface->GetMemberCount();
for (PRUint16 k = 0; k < member_count; k++)
{
for (PRUint16 k = 0; k < member_count; k++) {
if (!xpc_ForcePropertyResolve(cx, obj, iface->GetMemberAt(k)->GetName()))
return JS_FALSE;
}
@ -1960,8 +1890,7 @@ XPC_WN_TearOff_Enumerate(JSContext *cx, JSObject *obj)
return Throw(NS_ERROR_XPC_BAD_OP_ON_WN_PROTO, cx);
PRUint16 member_count = iface->GetMemberCount();
for (PRUint16 k = 0; k < member_count; k++)
{
for (PRUint16 k = 0; k < member_count; k++) {
if (!xpc_ForcePropertyResolve(cx, obj, iface->GetMemberAt(k)->GetName()))
return JS_FALSE;
}

View File

@ -95,8 +95,7 @@ XPCWrappedNativeProto::Init(XPCCallContext& ccx,
nsIXPCScriptable *callback = scriptableCreateInfo ?
scriptableCreateInfo->GetCallback() :
nsnull;
if (callback)
{
if (callback) {
mScriptableInfo =
XPCNativeScriptableInfo::Construct(ccx, isGlobal, scriptableCreateInfo);
if (!mScriptableInfo)
@ -106,25 +105,21 @@ XPCWrappedNativeProto::Init(XPCCallContext& ccx,
js::Class* jsclazz;
if (mScriptableInfo)
{
if (mScriptableInfo) {
const XPCNativeScriptableFlags& flags(mScriptableInfo->GetFlags());
if (flags.AllowPropModsToPrototype())
{
if (flags.AllowPropModsToPrototype()) {
jsclazz = flags.WantCall() ?
&XPC_WN_ModsAllowed_WithCall_Proto_JSClass :
&XPC_WN_ModsAllowed_NoCall_Proto_JSClass;
}
else
{
else {
jsclazz = flags.WantCall() ?
&XPC_WN_NoMods_WithCall_Proto_JSClass :
&XPC_WN_NoMods_NoCall_Proto_JSClass;
}
}
else
{
else {
jsclazz = &XPC_WN_NoMods_NoCall_Proto_JSClass;
}
@ -137,11 +132,9 @@ XPCWrappedNativeProto::Init(XPCCallContext& ccx,
JSBool ok = mJSProtoObject && JS_SetPrivate(ccx, mJSProtoObject, this);
if (ok && callback)
{
if (ok && callback) {
nsresult rv = callback->PostCreatePrototype(ccx, mJSProtoObject);
if (NS_FAILED(rv))
{
if (NS_FAILED(rv)) {
JS_SetPrivate(ccx, mJSProtoObject, nsnull);
mJSProtoObject = nsnull;
XPCThrower::Throw(rv, ccx);
@ -161,8 +154,7 @@ XPCWrappedNativeProto::JSProtoObjectFinalized(JSContext *cx, JSObject *obj)
// Map locking is not necessary since we are running gc.
if (IsShared())
{
if (IsShared()) {
// Only remove this proto from the map if it is the one in the map.
ClassInfo2WrappedNativeProtoMap* map =
GetScope()->GetWrappedNativeProtoMap(ClassIsMainThreadOnly());
@ -184,16 +176,14 @@ XPCWrappedNativeProto::SystemIsBeingShutDown(JSContext* cx)
#ifdef XPC_TRACK_PROTO_STATS
static bool DEBUG_DumpedStats = false;
if (!DEBUG_DumpedStats)
{
if (!DEBUG_DumpedStats) {
printf("%d XPCWrappedNativeProto(s) alive at shutdown\n",
gDEBUG_LiveProtoCount);
DEBUG_DumpedStats = PR_TRUE;
}
#endif
if (mJSProtoObject)
{
if (mJSProtoObject) {
// short circuit future finalization
JS_SetPrivate(cx, mJSProtoObject, nsnull);
mJSProtoObject = nsnull;
@ -222,26 +212,22 @@ XPCWrappedNativeProto::GetNewOrUsed(XPCCallContext& ccx,
if (NS_FAILED(ClassInfo->GetFlags(&ciFlags)))
ciFlags = 0;
if (ciFlags & XPC_PROTO_DONT_SHARE)
{
if (ciFlags & XPC_PROTO_DONT_SHARE) {
NS_ERROR("reserved flag set!");
ciFlags &= ~XPC_PROTO_DONT_SHARE;
}
if (ForceNoSharing || (ciFlags & nsIClassInfo::PLUGIN_OBJECT) ||
(ScriptableCreateInfo &&
ScriptableCreateInfo->GetFlags().DontSharePrototype()))
{
ScriptableCreateInfo->GetFlags().DontSharePrototype())) {
ciFlags |= XPC_PROTO_DONT_SHARE;
shared = JS_FALSE;
}
else
{
else {
shared = JS_TRUE;
}
if (shared)
{
if (shared) {
JSBool mainThreadOnly = !!(ciFlags & nsIClassInfo::MAIN_THREAD_ONLY);
map = Scope->GetWrappedNativeProtoMap(mainThreadOnly);
lock = mainThreadOnly ? nsnull : Scope->GetRuntime()->GetMapLock();
@ -260,8 +246,7 @@ XPCWrappedNativeProto::GetNewOrUsed(XPCCallContext& ccx,
proto = new XPCWrappedNativeProto(Scope, ClassInfo, ciFlags, set, offsets);
if (!proto || !proto->Init(ccx, isGlobal, ScriptableCreateInfo))
{
if (!proto || !proto->Init(ccx, isGlobal, ScriptableCreateInfo)) {
delete proto.get();
return nsnull;
}
@ -288,8 +273,7 @@ XPCWrappedNativeProto::DebugDump(PRInt16 depth)
XPC_LOG_ALWAYS(("mSet @ %x", mSet));
XPC_LOG_ALWAYS(("mSecurityInfo of %x", mSecurityInfo));
XPC_LOG_ALWAYS(("mScriptableInfo @ %x", mScriptableInfo));
if (depth && mScriptableInfo)
{
if (depth && mScriptableInfo) {
XPC_LOG_INDENT();
XPC_LOG_ALWAYS(("mScriptable @ %x", mScriptableInfo->GetCallback()));
XPC_LOG_ALWAYS(("mFlags of %x", (PRUint32)mScriptableInfo->GetFlags()));

View File

@ -82,8 +82,7 @@ static void DEBUG_TrackScopeTraversal()
static void DEBUG_TrackScopeShutdown()
{
#ifdef XPC_TRACK_SCOPE_STATS
if (!DEBUG_DumpedStats)
{
if (!DEBUG_DumpedStats) {
DEBUG_DumpedStats = PR_TRUE;
printf("%d XPCWrappedNativeScope(s) were constructed.\n",
DEBUG_TotalScopeCount);
@ -119,8 +118,7 @@ XPCWrappedNativeScope::GetNewOrUsed(XPCCallContext& ccx, JSObject* aGlobal)
XPCWrappedNativeScope* scope = FindInJSObjectScope(ccx, aGlobal, JS_TRUE);
if (!scope)
scope = new XPCWrappedNativeScope(ccx, aGlobal);
else
{
else {
// We need to call SetGlobal in order to refresh our cached
// mPrototypeJSObject and mPrototypeJSFunction and to clear
// mPrototypeNoHelper (so we get a new one if requested in the
@ -179,8 +177,7 @@ XPCWrappedNativeScope::XPCWrappedNativeScope(XPCCallContext& ccx,
JSBool
XPCWrappedNativeScope::IsDyingScope(XPCWrappedNativeScope *scope)
{
for (XPCWrappedNativeScope *cur = gDyingScopes; cur; cur = cur->mNext)
{
for (XPCWrappedNativeScope *cur = gDyingScopes; cur; cur = cur->mNext) {
if (scope == cur)
return JS_TRUE;
}
@ -244,20 +241,17 @@ XPCWrappedNativeScope::SetGlobal(XPCCallContext& ccx, JSObject* aGlobal)
const JSClass* jsClass = js::GetObjectJSClass(aGlobal);
if (!(~jsClass->flags & (JSCLASS_HAS_PRIVATE |
JSCLASS_PRIVATE_IS_NSISUPPORTS)))
{
JSCLASS_PRIVATE_IS_NSISUPPORTS))) {
// Our global has an nsISupports native pointer. Let's
// see whether it's what we want.
nsISupports* priv = (nsISupports*)xpc_GetJSPrivate(aGlobal);
nsCOMPtr<nsIXPConnectWrappedNative> native =
do_QueryInterface(priv);
nsCOMPtr<nsIScriptObjectPrincipal> sop;
if (native)
{
if (native) {
sop = do_QueryWrappedNative(native);
}
if (!sop)
{
if (!sop) {
sop = do_QueryInterface(priv);
}
mScriptObjectPrincipal = sop;
@ -275,24 +269,20 @@ XPCWrappedNativeScope::SetGlobal(XPCCallContext& ccx, JSObject* aGlobal)
if (JS_GetPropertyById(ccx, aGlobal, idObj, &val) &&
!JSVAL_IS_PRIMITIVE(val) &&
JS_GetPropertyById(ccx, JSVAL_TO_OBJECT(val), idProto, &val) &&
!JSVAL_IS_PRIMITIVE(val))
{
!JSVAL_IS_PRIMITIVE(val)) {
mPrototypeJSObject = JSVAL_TO_OBJECT(val);
}
else
{
else {
NS_ERROR("Can't get globalObject.Object.prototype");
}
if (JS_GetPropertyById(ccx, aGlobal, idFun, &val) &&
!JSVAL_IS_PRIMITIVE(val) &&
JS_GetPropertyById(ccx, JSVAL_TO_OBJECT(val), idProto, &val) &&
!JSVAL_IS_PRIMITIVE(val))
{
!JSVAL_IS_PRIMITIVE(val)) {
mPrototypeJSFunction = JSVAL_TO_OBJECT(val);
}
else
{
else {
NS_ERROR("Can't get globalObject.Function.prototype");
}
}
@ -309,20 +299,17 @@ XPCWrappedNativeScope::~XPCWrappedNativeScope()
// We can do additional cleanup assertions here...
if (mWrappedNativeMap)
{
if (mWrappedNativeMap) {
NS_ASSERTION(0 == mWrappedNativeMap->Count(), "scope has non-empty map");
delete mWrappedNativeMap;
}
if (mWrappedNativeProtoMap)
{
if (mWrappedNativeProtoMap) {
NS_ASSERTION(0 == mWrappedNativeProtoMap->Count(), "scope has non-empty map");
delete mWrappedNativeProtoMap;
}
if (mMainThreadWrappedNativeProtoMap)
{
if (mMainThreadWrappedNativeProtoMap) {
NS_ASSERTION(0 == mMainThreadWrappedNativeProtoMap->Count(), "scope has non-empty map");
delete mMainThreadWrappedNativeProtoMap;
}
@ -341,8 +328,7 @@ XPCWrappedNativeScope::GetPrototypeNoHelper(XPCCallContext& ccx)
// We could create this prototype in SetGlobal(), but all scopes
// don't need one, so we save ourselves a bit of space if we
// create these when they're needed.
if (!mPrototypeNoHelper)
{
if (!mPrototypeNoHelper) {
mPrototypeNoHelper =
xpc_NewSystemInheritingJSObject(ccx,
js::Jsvalify(&XPC_WN_NoHelper_Proto_JSClass),
@ -361,8 +347,7 @@ WrappedNativeJSGCThingTracer(JSDHashTable *table, JSDHashEntryHdr *hdr,
uint32 number, void *arg)
{
XPCWrappedNative* wrapper = ((Native2WrappedNativeMap::Entry*)hdr)->value;
if (wrapper->HasExternalReference() && !wrapper->IsWrapperExpired())
{
if (wrapper->HasExternalReference() && !wrapper->IsWrapperExpired()) {
JSTracer* trc = (JSTracer *)arg;
JS_CALL_OBJECT_TRACER(trc, wrapper->GetFlatJSObjectPreserveColor(),
"XPCWrappedNative::mFlatJSObject");
@ -380,8 +365,7 @@ XPCWrappedNativeScope::TraceJS(JSTracer* trc, XPCJSRuntime* rt)
XPCAutoLock lock(rt->GetMapLock());
// Do JS_CallTracer for all wrapped natives with external references.
for (XPCWrappedNativeScope* cur = gScopes; cur; cur = cur->mNext)
{
for (XPCWrappedNativeScope* cur = gScopes; cur; cur = cur->mNext) {
cur->mWrappedNativeMap->Enumerate(WrappedNativeJSGCThingTracer, trc);
}
}
@ -403,8 +387,7 @@ WrappedNativeSuspecter(JSDHashTable *table, JSDHashEntryHdr *hdr,
{
XPCWrappedNative* wrapper = ((Native2WrappedNativeMap::Entry*)hdr)->value;
if (wrapper->HasExternalReference())
{
if (wrapper->HasExternalReference()) {
SuspectClosure* closure = static_cast<SuspectClosure*>(arg);
XPCJSRuntime::SuspectWrappedNative(closure->cx, wrapper, closure->cb);
}
@ -420,8 +403,7 @@ XPCWrappedNativeScope::SuspectAllWrappers(XPCJSRuntime* rt, JSContext* cx,
XPCAutoLock lock(rt->GetMapLock());
SuspectClosure closure(cx, cb);
for (XPCWrappedNativeScope* cur = gScopes; cur; cur = cur->mNext)
{
for (XPCWrappedNativeScope* cur = gScopes; cur; cur = cur->mNext) {
cur->mWrappedNativeMap->Enumerate(WrappedNativeSuspecter, &closure);
}
}
@ -443,15 +425,13 @@ XPCWrappedNativeScope::FinishedMarkPhaseOfGC(JSContext* cx, XPCJSRuntime* rt)
XPCWrappedNativeScope* prev = nsnull;
XPCWrappedNativeScope* cur = gScopes;
while (cur)
{
while (cur) {
XPCWrappedNativeScope* next = cur->mNext;
js::AutoSwitchCompartment sc(cx, cur->mGlobalJSObject);
if (cur->mGlobalJSObject &&
JS_IsAboutToBeFinalized(cx, cur->mGlobalJSObject))
{
JS_IsAboutToBeFinalized(cx, cur->mGlobalJSObject)) {
cur->mGlobalJSObject = nsnull;
cur->mScriptObjectPrincipal = nsnull;
if (cur->GetCachedDOMPrototypes().IsInitialized())
@ -465,21 +445,17 @@ XPCWrappedNativeScope::FinishedMarkPhaseOfGC(JSContext* cx, XPCJSRuntime* rt)
gDyingScopes = cur;
cur = nsnull;
}
else
{
else {
if (cur->mPrototypeJSObject &&
JS_IsAboutToBeFinalized(cx, cur->mPrototypeJSObject))
{
JS_IsAboutToBeFinalized(cx, cur->mPrototypeJSObject)) {
cur->mPrototypeJSObject = nsnull;
}
if (cur->mPrototypeJSFunction &&
JS_IsAboutToBeFinalized(cx, cur->mPrototypeJSFunction))
{
JS_IsAboutToBeFinalized(cx, cur->mPrototypeJSFunction)) {
cur->mPrototypeJSFunction = nsnull;
}
if (cur->mPrototypeNoHelper &&
JS_IsAboutToBeFinalized(cx, cur->mPrototypeNoHelper))
{
JS_IsAboutToBeFinalized(cx, cur->mPrototypeNoHelper)) {
cur->mPrototypeNoHelper = nsnull;
}
}
@ -524,8 +500,7 @@ WrappedNativeProtoMarker(JSDHashTable *table, JSDHashEntryHdr *hdr,
void
XPCWrappedNativeScope::MarkAllWrappedNativesAndProtos()
{
for (XPCWrappedNativeScope* cur = gScopes; cur; cur = cur->mNext)
{
for (XPCWrappedNativeScope* cur = gScopes; cur; cur = cur->mNext) {
cur->mWrappedNativeMap->Enumerate(WrappedNativeMarker, nsnull);
cur->mWrappedNativeProtoMap->Enumerate(WrappedNativeProtoMarker, nsnull);
cur->mMainThreadWrappedNativeProtoMap->Enumerate(WrappedNativeProtoMarker, nsnull);
@ -555,8 +530,7 @@ ASSERT_WrappedNativeProtoSetNotMarked(JSDHashTable *table, JSDHashEntryHdr *hdr,
void
XPCWrappedNativeScope::ASSERT_NoInterfaceSetsAreMarked()
{
for (XPCWrappedNativeScope* cur = gScopes; cur; cur = cur->mNext)
{
for (XPCWrappedNativeScope* cur = gScopes; cur; cur = cur->mNext) {
cur->mWrappedNativeMap->Enumerate(ASSERT_WrappedNativeSetNotMarked, nsnull);
cur->mWrappedNativeProtoMap->Enumerate(ASSERT_WrappedNativeProtoSetNotMarked, nsnull);
cur->mMainThreadWrappedNativeProtoMap->Enumerate(ASSERT_WrappedNativeProtoSetNotMarked, nsnull);
@ -588,8 +562,7 @@ XPCWrappedNativeScope::KillDyingScopes()
{
// always called inside the lock!
XPCWrappedNativeScope* cur = gDyingScopes;
while (cur)
{
while (cur) {
XPCWrappedNativeScope* next = cur->mNext;
delete cur;
cur = next;
@ -615,8 +588,7 @@ WrappedNativeShutdownEnumerator(JSDHashTable *table, JSDHashEntryHdr *hdr,
ShutdownData* data = (ShutdownData*) arg;
XPCWrappedNative* wrapper = ((Native2WrappedNativeMap::Entry*)hdr)->value;
if (wrapper->IsValid())
{
if (wrapper->IsValid()) {
if (wrapper->HasProto() && !wrapper->HasSharedProto())
data->nonSharedProtoCount++;
wrapper->SystemIsBeingShutDown(data->cx);
@ -652,8 +624,7 @@ XPCWrappedNativeScope::SystemIsBeingShutDown(JSContext* cx)
// First move all the scopes to the dying list.
cur = gScopes;
while (cur)
{
while (cur) {
XPCWrappedNativeScope* next = cur->mNext;
cur->mNext = gDyingScopes;
gDyingScopes = cur;
@ -664,8 +635,7 @@ XPCWrappedNativeScope::SystemIsBeingShutDown(JSContext* cx)
// Walk the unified dying list and call shutdown on all wrappers and protos
for (cur = gDyingScopes; cur; cur = cur->mNext)
{
for (cur = gDyingScopes; cur; cur = cur->mNext) {
// Give the Components object a chance to try to clean up.
if (cur->mComponents)
cur->mComponents->SystemIsBeingShutDown();
@ -764,8 +734,7 @@ void DEBUG_CheckForComponentsInScope(JSContext* cx, JSObject* obj,
js_DumpObject(startingObj);
JSObject *p = startingObj;
while (js::IsWrapper(p))
{
while (js::IsWrapper(p)) {
p = js::GetProxyPrivate(p).toObjectOrNull();
if (!p)
break;
@ -807,15 +776,13 @@ XPCWrappedNativeScope::FindInJSObjectScope(JSContext* cx, JSObject* obj,
obj = JS_GetGlobalForObject(cx, obj);
if (js::GetObjectClass(obj)->flags & JSCLASS_XPCONNECT_GLOBAL)
{
if (js::GetObjectClass(obj)->flags & JSCLASS_XPCONNECT_GLOBAL) {
scope = XPCWrappedNativeScope::GetNativeScope(cx, obj);
if (scope)
return scope;
}
if (!runtime)
{
if (!runtime) {
runtime = nsXPConnect::GetRuntimeInstance();
NS_ASSERTION(runtime, "This should never be null!");
}
@ -828,10 +795,8 @@ XPCWrappedNativeScope::FindInJSObjectScope(JSContext* cx, JSObject* obj,
DEBUG_TrackScopeTraversal();
for (XPCWrappedNativeScope* cur = gScopes; cur; cur = cur->mNext)
{
if (obj == cur->GetGlobalJSObject())
{
for (XPCWrappedNativeScope* cur = gScopes; cur; cur = cur->mNext) {
if (obj == cur->GetGlobalJSObject()) {
found = cur;
break;
}
@ -881,8 +846,7 @@ XPCWrappedNativeScope::ClearAllWrappedNativeSecurityPolicies(XPCCallContext& ccx
// Hold the lock throughout.
XPCAutoLock lock(ccx.GetRuntime()->GetMapLock());
for (XPCWrappedNativeScope* cur = gScopes; cur; cur = cur->mNext)
{
for (XPCWrappedNativeScope* cur = gScopes; cur; cur = cur->mNext) {
cur->mWrappedNativeProtoMap->Enumerate(WNProtoSecPolicyClearer, nsnull);
cur->mMainThreadWrappedNativeProtoMap->Enumerate(WNProtoSecPolicyClearer, nsnull);
cur->mWrappedNativeMap->Enumerate(WNSecPolicyClearer, nsnull);
@ -995,8 +959,7 @@ XPCWrappedNativeScope::DebugDump(PRInt16 depth)
mWrappedNativeMap, \
mWrappedNativeMap ? mWrappedNativeMap->Count() : 0));
// iterate contexts...
if (depth && mWrappedNativeMap && mWrappedNativeMap->Count())
{
if (depth && mWrappedNativeMap && mWrappedNativeMap->Count()) {
XPC_LOG_INDENT();
mWrappedNativeMap->Enumerate(WrappedNativeMapDumpEnumerator, &depth);
XPC_LOG_OUTDENT();
@ -1006,8 +969,7 @@ XPCWrappedNativeScope::DebugDump(PRInt16 depth)
mWrappedNativeProtoMap, \
mWrappedNativeProtoMap ? mWrappedNativeProtoMap->Count() : 0));
// iterate contexts...
if (depth && mWrappedNativeProtoMap && mWrappedNativeProtoMap->Count())
{
if (depth && mWrappedNativeProtoMap && mWrappedNativeProtoMap->Count()) {
XPC_LOG_INDENT();
mWrappedNativeProtoMap->Enumerate(WrappedNativeProtoMapDumpEnumerator, &depth);
XPC_LOG_OUTDENT();
@ -1017,8 +979,7 @@ XPCWrappedNativeScope::DebugDump(PRInt16 depth)
mMainThreadWrappedNativeProtoMap, \
mMainThreadWrappedNativeProtoMap ? mMainThreadWrappedNativeProtoMap->Count() : 0));
// iterate contexts...
if (depth && mMainThreadWrappedNativeProtoMap && mMainThreadWrappedNativeProtoMap->Count())
{
if (depth && mMainThreadWrappedNativeProtoMap && mMainThreadWrappedNativeProtoMap->Count()) {
XPC_LOG_INDENT();
mMainThreadWrappedNativeProtoMap->Enumerate(WrappedNativeProtoMapDumpEnumerator, &depth);
XPC_LOG_OUTDENT();

View File

@ -119,16 +119,14 @@ xpc_qsUnwrapThis<nsGenericElement>(JSContext *cx,
JSBool ok = xpc_qsUnwrapThis<nsIContent>(cx, obj, callee, &content,
pThisRef, &val, lccx,
failureFatal);
if (ok)
{
if (ok) {
if (failureFatal || content)
ok = castToElement(content, val, ppThis, pThisVal);
if (failureFatal && !ok)
xpc_qsThrow(cx, NS_ERROR_XPC_BAD_OP_ON_WN_PROTO);
}
if (!failureFatal && (!ok || !content))
{
if (!failureFatal && (!ok || !content)) {
ok = JS_TRUE;
*ppThis = nsnull;
}

View File

@ -164,8 +164,7 @@ nsXPConnect::~nsXPConnect()
nsXPConnect*
nsXPConnect::GetXPConnect()
{
if (!gSelf)
{
if (!gSelf) {
if (gOnceAliveNowDead)
return nsnull;
gSelf = new nsXPConnect();
@ -204,8 +203,7 @@ void
nsXPConnect::ReleaseXPConnectSingleton()
{
nsXPConnect* xpc = gSelf;
if (xpc)
{
if (xpc) {
NS_SetGlobalThreadObserver(nsnull);
#ifdef DEBUG
@ -214,17 +212,14 @@ nsXPConnect::ReleaseXPConnectSingleton()
{
// autoscope
XPCCallContext ccx(NATIVE_CALLER);
if (ccx.IsValid())
{
if (ccx.IsValid()) {
const char* dumpName = getenv("XPC_SHUTDOWN_HEAP_DUMP");
if (dumpName)
{
if (dumpName) {
FILE* dumpFile = (*dumpName == '\0' ||
strcmp(dumpName, "stdout") == 0)
? stdout
: fopen(dumpName, "w");
if (dumpFile)
{
if (dumpFile) {
JS_DumpHeap(ccx, dumpFile, nsnull, JSTRACE_OBJECT, nsnull,
static_cast<size_t>(-1), nsnull);
if (dumpFile != stdout)
@ -315,14 +310,12 @@ static nsresult FindInfo(InfoTester tester, const void* data,
if (NS_SUCCEEDED(iism->HasAdditionalManagers(&yes)) && yes &&
NS_SUCCEEDED(iism->EnumerateAdditionalManagers(getter_AddRefs(list))) &&
list)
{
list) {
bool more;
nsCOMPtr<nsIInterfaceInfoManager> current;
while (NS_SUCCEEDED(list->HasMoreElements(&more)) && more &&
NS_SUCCEEDED(list->GetNext(getter_AddRefs(current))) && current)
{
NS_SUCCEEDED(list->GetNext(getter_AddRefs(current))) && current) {
if (tester(current, data, info))
return NS_OK;
}
@ -449,20 +442,17 @@ struct NoteJSRootTracer : public JSTracer
static void
NoteJSRoot(JSTracer *trc, void *thing, JSGCTraceKind kind)
{
if (AddToCCKind(kind))
{
if (AddToCCKind(kind)) {
NoteJSRootTracer *tracer = static_cast<NoteJSRootTracer*>(trc);
PLDHashEntryHdr *entry = PL_DHashTableOperate(tracer->mObjects, thing,
PL_DHASH_ADD);
if (entry && !reinterpret_cast<PLDHashEntryStub*>(entry)->key)
{
if (entry && !reinterpret_cast<PLDHashEntryStub*>(entry)->key) {
reinterpret_cast<PLDHashEntryStub*>(entry)->key = thing;
tracer->mCb.NoteRoot(nsIProgrammingLanguage::JAVASCRIPT, thing,
nsXPConnect::GetXPConnect());
}
}
else if (kind != JSTRACE_STRING)
{
else if (kind != JSTRACE_STRING) {
JS_TraceChildren(trc, thing, kind);
}
}
@ -492,8 +482,7 @@ nsXPConnect::BeginCycleCollection(nsCycleCollectionTraversalCallback &cb,
}
static bool gcHasRun = false;
if (!gcHasRun)
{
if (!gcHasRun) {
JSRuntime* rt = JS_GetRuntime(mCycleCollectionContext->GetJSContext());
if (!rt)
NS_RUNTIMEABORT("Failed to get JS runtime!");
@ -506,8 +495,7 @@ nsXPConnect::BeginCycleCollection(nsCycleCollectionTraversalCallback &cb,
#ifdef DEBUG_CC
NS_ASSERTION(!mJSRoots.ops, "Didn't call FinishCycleCollection?");
if (explainLiveExpectedGarbage)
{
if (explainLiveExpectedGarbage) {
// Being called from nsCycleCollector::ExplainLiveExpectedGarbage.
// Record all objects held by the JS runtime. This avoids doing a
@ -549,8 +537,7 @@ nsresult
nsXPConnect::FinishCycleCollection()
{
#ifdef DEBUG_CC
if (mJSRoots.ops)
{
if (mJSRoots.ops) {
PL_DHashTableFinish(&mJSRoots);
mJSRoots.ops = nsnull;
}
@ -656,8 +643,7 @@ xpc_UnmarkGrayObjectRecursive(JSObject *obj)
// Tracing requires a JSContext...
JSContext *cx;
nsXPConnect* xpc = nsXPConnect::GetXPConnect();
if (!xpc || NS_FAILED(xpc->GetSafeJSContext(&cx)) || !cx)
{
if (!xpc || NS_FAILED(xpc->GetSafeJSContext(&cx)) || !cx) {
NS_ERROR("Failed to get safe JSContext!");
return;
}
@ -679,8 +665,7 @@ struct TraversalTracer : public JSTracer
static void
NoteJSChild(JSTracer *trc, void *thing, JSGCTraceKind kind)
{
if (AddToCCKind(kind))
{
if (AddToCCKind(kind)) {
TraversalTracer *tracer = static_cast<TraversalTracer*>(trc);
// There's no point in further traversing a non-gray object here unless
@ -708,8 +693,7 @@ NoteJSChild(JSTracer *trc, void *thing, JSGCTraceKind kind)
#endif
tracer->cb.NoteScriptChild(nsIProgrammingLanguage::JAVASCRIPT, thing);
}
else if (kind != JSTRACE_STRING)
{
else if (kind != JSTRACE_STRING) {
JS_TraceChildren(trc, thing, kind);
}
}
@ -745,19 +729,16 @@ nsXPConnect::Traverse(void *p, nsCycleCollectionTraversalCallback &cb)
// we did add the wrapper to the cycle collector.
JSBool dontTraverse = PR_FALSE;
JSBool markJSObject = PR_FALSE;
if (traceKind == JSTRACE_OBJECT)
{
if (traceKind == JSTRACE_OBJECT) {
obj = static_cast<JSObject*>(p);
clazz = obj->getClass();
if (clazz == &XPC_WN_Tearoff_JSClass)
{
if (clazz == &XPC_WN_Tearoff_JSClass) {
XPCWrappedNative *wrapper =
(XPCWrappedNative*)xpc_GetJSPrivate(obj->getParent());
dontTraverse = WrapperIsNotMainThreadOnly(wrapper);
}
else if (IS_WRAPPER_CLASS(clazz) && IS_WN_WRAPPER_OBJECT(obj))
{
else if (IS_WRAPPER_CLASS(clazz) && IS_WN_WRAPPER_OBJECT(obj)) {
XPCWrappedNative *wrapper = (XPCWrappedNative*)xpc_GetJSPrivate(obj);
dontTraverse = WrapperIsNotMainThreadOnly(wrapper);
markJSObject = dontTraverse && wrapper->HasExternalReference();
@ -777,8 +758,7 @@ nsXPConnect::Traverse(void *p, nsCycleCollectionTraversalCallback &cb)
// do an extra GC, so we use mJSRoots, built from JS_TraceRuntime,
// which produces a different result because we didn't call
// JS_TraceChildren to trace everything that was reachable.
if (mJSRoots.ops)
{
if (mJSRoots.ops) {
// ExplainLiveExpectedGarbage codepath
PLDHashEntryHdr* entry =
PL_DHashTableOperate(&mJSRoots, p, PL_DHASH_LOOKUP);
@ -793,57 +773,46 @@ nsXPConnect::Traverse(void *p, nsCycleCollectionTraversalCallback &cb)
if (cb.WantDebugInfo()) {
char name[72];
if (traceKind == JSTRACE_OBJECT)
{
if (traceKind == JSTRACE_OBJECT) {
XPCNativeScriptableInfo* si = nsnull;
if (IS_PROTO_CLASS(clazz))
{
if (IS_PROTO_CLASS(clazz)) {
XPCWrappedNativeProto* p =
(XPCWrappedNativeProto*) xpc_GetJSPrivate(obj);
si = p->GetScriptableInfo();
}
if (si)
{
if (si) {
JS_snprintf(name, sizeof(name), "JS Object (%s - %s)",
clazz->name, si->GetJSClass()->name);
}
else if (clazz == &js::ScriptClass)
{
else if (clazz == &js::ScriptClass) {
JSScript* script = (JSScript*) xpc_GetJSPrivate(obj);
if (script->filename)
{
if (script->filename) {
JS_snprintf(name, sizeof(name),
"JS Object (Script - %s)",
script->filename);
}
else
{
else {
JS_snprintf(name, sizeof(name), "JS Object (Script)");
}
}
else if (clazz == &js::FunctionClass)
{
else if (clazz == &js::FunctionClass) {
JSFunction* fun = (JSFunction*) xpc_GetJSPrivate(obj);
JSString* str = JS_GetFunctionId(fun);
if (str)
{
if (str) {
NS_ConvertUTF16toUTF8 fname(JS_GetInternedStringChars(str));
JS_snprintf(name, sizeof(name),
"JS Object (Function - %s)", fname.get());
}
else
{
else {
JS_snprintf(name, sizeof(name), "JS Object (Function)");
}
}
else
{
else {
JS_snprintf(name, sizeof(name), "JS Object (%s)",
clazz->name);
}
}
else
{
else {
static const char trace_types[][11] = {
"Object",
"String",
@ -890,8 +859,7 @@ nsXPConnect::Traverse(void *p, nsCycleCollectionTraversalCallback &cb)
if (traceKind != JSTRACE_OBJECT || dontTraverse)
return NS_OK;
if (clazz == &XPC_WN_Tearoff_JSClass)
{
if (clazz == &XPC_WN_Tearoff_JSClass) {
// A tearoff holds a strong reference to its native object
// (see XPCWrappedNative::FlatJSObjectFinalized). Its XPCWrappedNative
// will be held alive through the parent of the JSObject of the tearoff.
@ -903,13 +871,11 @@ nsXPConnect::Traverse(void *p, nsCycleCollectionTraversalCallback &cb)
// XXX This test does seem fragile, we should probably whitelist classes
// that do hold a strong reference, but that might not be possible.
else if (clazz->flags & JSCLASS_HAS_PRIVATE &&
clazz->flags & JSCLASS_PRIVATE_IS_NSISUPPORTS)
{
clazz->flags & JSCLASS_PRIVATE_IS_NSISUPPORTS) {
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "xpc_GetJSPrivate(obj)");
cb.NoteXPCOMChild(static_cast<nsISupports*>(xpc_GetJSPrivate(obj)));
}
else if (mozilla::dom::binding::instanceIsProxy(obj))
{
else if (mozilla::dom::binding::instanceIsProxy(obj)) {
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "js::GetProxyPrivate(obj)");
nsISupports *identity =
static_cast<nsISupports*>(js::GetProxyPrivate(obj).toPrivate());
@ -926,8 +892,7 @@ nsXPConnect::GetOutstandingRequests(JSContext* cx)
XPCCallContext* context = mCycleCollectionContext;
// Ignore the contribution from the XPCCallContext we created for cycle
// collection.
if (context && cx == context->GetJSContext())
{
if (context && cx == context->GetJSContext()) {
JS_ASSERT(n);
--n;
}
@ -1028,8 +993,7 @@ nsXPConnect::InitClasses(JSContext * aJSContext, JSObject * aGlobalJSObj)
if (!nsXPCComponents::AttachNewComponentsObject(ccx, scope, aGlobalJSObj))
return UnexpectedFailure(NS_ERROR_FAILURE);
if (XPCPerThreadData::IsMainThread(ccx))
{
if (XPCPerThreadData::IsMainThread(ccx)) {
if (!XPCNativeWrapper::AttachNewConstructorObject(ccx, aGlobalJSObj))
return UnexpectedFailure(NS_ERROR_FAILURE);
}
@ -1097,8 +1061,7 @@ void
TraceXPCGlobal(JSTracer *trc, JSObject *obj)
{
#ifdef DEBUG
if (trc->callback == VerifyTraceXPCGlobalCalled)
{
if (trc->callback == VerifyTraceXPCGlobalCalled) {
// We don't do anything here, we only want to verify that TraceXPCGlobal
// was called.
reinterpret_cast<VerifyTraceXPCGlobalCalledTracer*>(trc)->ok = JS_TRUE;
@ -1123,22 +1086,19 @@ xpc_CreateGlobalObject(JSContext *cx, JSClass *clasp,
XPCCompartmentMap& map = nsXPConnect::GetRuntimeInstance()->GetCompartmentMap();
xpc::PtrAndPrincipalHashKey key(ptr, principal);
if (!map.Get(&key, compartment))
{
if (!map.Get(&key, compartment)) {
xpc::PtrAndPrincipalHashKey *priv_key =
new xpc::PtrAndPrincipalHashKey(ptr, principal);
xpc::CompartmentPrivate *priv =
new xpc::CompartmentPrivate(priv_key, wantXrays, NS_IsMainThread());
if (!CreateNewCompartment(cx, clasp, principal, priv,
global, compartment))
{
global, compartment)) {
return UnexpectedFailure(NS_ERROR_FAILURE);
}
map.Put(&key, *compartment);
}
else
{
else {
js::AutoSwitchCompartment sc(cx, *compartment);
JSObject *tempGlobal = JS_NewGlobalObject(cx, clasp);
@ -1148,8 +1108,7 @@ xpc_CreateGlobalObject(JSContext *cx, JSClass *clasp,
}
#ifdef DEBUG
if (clasp->flags & JSCLASS_XPCONNECT_GLOBAL)
{
if (clasp->flags & JSCLASS_XPCONNECT_GLOBAL) {
VerifyTraceXPCGlobalCalledTracer trc;
JS_TRACER_INIT(&trc.base, cx, VerifyTraceXPCGlobalCalled);
trc.ok = JS_FALSE;
@ -1168,8 +1127,7 @@ xpc_CreateMTGlobalObject(JSContext *cx, JSClass *clasp,
{
// NB: We can be either on or off the main thread here.
XPCMTCompartmentMap& map = nsXPConnect::GetRuntimeInstance()->GetMTCompartmentMap();
if (!map.Get(ptr, compartment))
{
if (!map.Get(ptr, compartment)) {
// We allow the pointer to be a principal, in which case it becomes
// the principal for the newly created compartment. The caller is
// responsible for ensuring that doing this doesn't violate
@ -1178,15 +1136,13 @@ xpc_CreateMTGlobalObject(JSContext *cx, JSClass *clasp,
xpc::CompartmentPrivate *priv =
new xpc::CompartmentPrivate(ptr, false, NS_IsMainThread());
if (!CreateNewCompartment(cx, clasp, principal, priv, global,
compartment))
{
compartment)) {
return UnexpectedFailure(NS_ERROR_UNEXPECTED);
}
map.Put(ptr, *compartment);
}
else
{
else {
js::AutoSwitchCompartment sc(cx, *compartment);
JSObject *tempGlobal = JS_NewGlobalObject(cx, clasp);
@ -1300,8 +1256,7 @@ nsXPConnect::InitClassesWithNewWrappedGlobal(JSContext * aJSContext,
JSObject* protoJSObject = wrapper->HasProto() ?
wrapper->GetProto()->GetJSProtoObject() :
globalJSObj;
if (protoJSObject)
{
if (protoJSObject) {
if (protoJSObject != globalJSObj)
JS_SetParent(aJSContext, protoJSObject, globalJSObj);
if (!JS_SplicePrototype(aJSContext, protoJSObject, scope->GetPrototypeJSObject()))
@ -1313,8 +1268,7 @@ nsXPConnect::InitClassesWithNewWrappedGlobal(JSContext * aJSContext,
if (!nsXPCComponents::AttachNewComponentsObject(ccx, scope, globalJSObj))
return UnexpectedFailure(NS_ERROR_FAILURE);
if (XPCPerThreadData::IsMainThread(ccx))
{
if (XPCPerThreadData::IsMainThread(ccx)) {
if (!XPCNativeWrapper::AttachNewConstructorObject(ccx, globalJSObj))
return UnexpectedFailure(NS_ERROR_FAILURE);
}
@ -1507,8 +1461,7 @@ nsXPConnect::GetWrappedNativeOfJSObject(JSContext * aJSContext,
SLIM_LOG_WILL_MORPH(aJSContext, aJSObj);
nsIXPConnectWrappedNative* wrapper =
XPCWrappedNative::GetAndMorphWrappedNativeOfJSObject(aJSContext, aJSObj);
if (wrapper)
{
if (wrapper) {
NS_ADDREF(wrapper);
*_retval = wrapper;
return NS_OK;
@ -1528,8 +1481,7 @@ nsXPConnect::GetNativeOfWrapper(JSContext * aJSContext,
NS_ASSERTION(aJSObj, "bad param");
XPCCallContext ccx(NATIVE_CALLER, aJSContext);
if (!ccx.IsValid())
{
if (!ccx.IsValid()) {
UnexpectedFailure(NS_ERROR_FAILURE);
return nsnull;
}
@ -1574,18 +1526,15 @@ nsXPConnect::GetJSObjectOfWrapper(JSContext * aJSContext,
nsIXPConnectWrappedNative* wrapper =
XPCWrappedNative::GetWrappedNativeOfJSObject(aJSContext, aJSObj, nsnull,
&obj2);
if (wrapper)
{
if (wrapper) {
wrapper->GetJSObject(_retval);
return NS_OK;
}
if (obj2)
{
if (obj2) {
*_retval = obj2;
return NS_OK;
}
if (mozilla::dom::binding::instanceIsProxy(aJSObj))
{
if (mozilla::dom::binding::instanceIsProxy(aJSObj)) {
*_retval = aJSObj;
return NS_OK;
}
@ -1682,8 +1631,7 @@ MoveWrapper(XPCCallContext& ccx, XPCWrappedNative *wrapper,
// First, check to see if this wrapper really needs to be
// reparented.
if (wrapper->GetScope() == newScope)
{
if (wrapper->GetScope() == newScope) {
// The wrapper already got moved, nothing to do here.
return NS_OK;
}
@ -1718,8 +1666,7 @@ MoveWrapper(XPCCallContext& ccx, XPCWrappedNative *wrapper,
if (NS_FAILED(rv))
return rv;
if (newParent == oldScope->GetGlobalJSObject())
{
if (newParent == oldScope->GetGlobalJSObject()) {
// The old scope still works for this wrapper. We have to
// assume that the wrapper will continue to return the old
// scope from PreCreate, so don't move it.
@ -1732,8 +1679,7 @@ MoveWrapper(XPCCallContext& ccx, XPCWrappedNative *wrapper,
XPCWrappedNativeScope *betterScope =
XPCWrappedNativeScope::FindInJSObjectScope(ccx, newParent);
if (betterScope == oldScope)
{
if (betterScope == oldScope) {
// The wrapper asked for a different object, but that object
// was in the same scope. This means that the new parent
// simply hasn't been reparented yet, so reparent it first,
@ -1802,8 +1748,7 @@ nsXPConnect::MoveWrappers(JSContext *aJSContext,
}
// Now that we have the wrappers, reparent them to the new scope.
for (PRUint32 i = 0, stop = wrappersToMove.Length(); i < stop; ++i)
{
for (PRUint32 i = 0, stop = wrappersToMove.Length(); i < stop; ++i) {
nsresult rv = MoveWrapper(ccx, wrappersToMove[i], newScope, oldScope);
NS_ENSURE_SUCCESS(rv, rv);
}
@ -1919,12 +1864,10 @@ nsXPConnect::GetCurrentJSStack(nsIStackFrame * *aCurrentJSStack)
JSContext* cx;
// is there a current context available?
if (NS_SUCCEEDED(Peek(&cx)) && cx)
{
if (NS_SUCCEEDED(Peek(&cx)) && cx) {
nsCOMPtr<nsIStackFrame> stack;
XPCJSStack::CreateStack(cx, getter_AddRefs(stack));
if (stack)
{
if (stack) {
// peel off native frames...
PRUint32 language;
nsCOMPtr<nsIStackFrame> caller;
@ -1932,8 +1875,7 @@ nsXPConnect::GetCurrentJSStack(nsIStackFrame * *aCurrentJSStack)
NS_SUCCEEDED(stack->GetLanguage(&language)) &&
language != nsIProgrammingLanguage::JAVASCRIPT &&
NS_SUCCEEDED(stack->GetCaller(getter_AddRefs(caller))) &&
caller)
{
caller) {
stack = caller;
}
NS_IF_ADDREF(*aCurrentJSStack = stack);
@ -1949,8 +1891,7 @@ nsXPConnect::GetCurrentNativeCallContext(nsAXPCNativeCallContext * *aCurrentNati
NS_ASSERTION(aCurrentNativeCallContext, "bad param");
XPCPerThreadData* data = XPCPerThreadData::GetData(nsnull);
if (data)
{
if (data) {
*aCurrentNativeCallContext = data->GetCallContext();
return NS_OK;
}
@ -1966,8 +1907,7 @@ nsXPConnect::GetPendingException(nsIException * *aPendingException)
NS_ASSERTION(aPendingException, "bad param");
XPCPerThreadData* data = XPCPerThreadData::GetData(nsnull);
if (!data)
{
if (!data) {
*aPendingException = nsnull;
return UnexpectedFailure(NS_ERROR_FAILURE);
}
@ -2005,8 +1945,7 @@ nsXPConnect::SetFunctionThisTranslator(const nsIID & aIID,
{
XPCAutoLock lock(rt->GetMapLock()); // scoped lock
if (_retval)
{
if (_retval) {
old = map->Find(aIID);
NS_IF_ADDREF(old);
*_retval = old;
@ -2077,8 +2016,7 @@ nsXPConnect::RestoreWrappedNativePrototype(JSContext * aJSContext,
if (!proto)
return UnexpectedFailure(NS_ERROR_FAILURE);
if (scope != proto->GetScope())
{
if (scope != proto->GetScope()) {
NS_ERROR("Attempt to reset prototype to a prototype from a"
"different scope!");
@ -2104,8 +2042,7 @@ nsXPConnect::RestoreWrappedNativePrototype(JSContext * aJSContext,
// map of detached wrapped native protos so that the old proto
// gets properly cleaned up, especially during shutdown.
XPCWrappedNativeProto *oldProto = map->Find(aClassInfo);
if (oldProto)
{
if (oldProto) {
detachedMap->Add(oldProto);
// ClassInfo2WrappedNativeProtoMap doesn't ever replace
@ -2229,22 +2166,18 @@ nsXPConnect::ReleaseJSContext(JSContext * aJSContext, bool noGC)
{
NS_ASSERTION(aJSContext, "bad param");
XPCPerThreadData* tls = XPCPerThreadData::GetData(aJSContext);
if (tls)
{
if (tls) {
XPCCallContext* ccx = nsnull;
for (XPCCallContext* cur = tls->GetCallContext();
cur;
cur = cur->GetPrevCallContext())
{
if (cur->GetJSContext() == aJSContext)
{
cur = cur->GetPrevCallContext()) {
if (cur->GetJSContext() == aJSContext) {
ccx = cur;
// Keep looping to find the deepest matching call context.
}
}
if (ccx)
{
if (ccx) {
#ifdef DEBUG_xpc_hacker
printf("!xpc - deferring destruction of JSContext @ %p\n",
(void *)aJSContext);
@ -2280,8 +2213,7 @@ nsXPConnect::DebugDump(PRInt16 depth)
XPC_LOG_ALWAYS(("mDefaultSecurityManager @ %x", mDefaultSecurityManager));
XPC_LOG_ALWAYS(("mDefaultSecurityManagerFlags of %x", mDefaultSecurityManagerFlags));
XPC_LOG_ALWAYS(("mInterfaceInfoManager @ %x", mInterfaceInfoManager.get()));
if (mRuntime)
{
if (mRuntime) {
if (depth)
mRuntime->DebugDump(depth);
else
@ -2302,8 +2234,7 @@ nsXPConnect::DebugDumpObject(nsISupports *p, PRInt16 depth)
#ifdef DEBUG
if (!depth)
return NS_OK;
if (!p)
{
if (!p) {
XPC_LOG_ALWAYS(("*** Cound not dump object with NULL address"));
return NS_OK;
}
@ -2314,29 +2245,25 @@ nsXPConnect::DebugDumpObject(nsISupports *p, PRInt16 depth)
nsIXPConnectWrappedJS* wjs;
if (NS_SUCCEEDED(p->QueryInterface(NS_GET_IID(nsIXPConnect),
(void**)&xpc)))
{
(void**)&xpc))) {
XPC_LOG_ALWAYS(("Dumping a nsIXPConnect..."));
xpc->DebugDump(depth);
NS_RELEASE(xpc);
}
else if (NS_SUCCEEDED(p->QueryInterface(NS_GET_IID(nsIXPCWrappedJSClass),
(void**)&wjsc)))
{
(void**)&wjsc))) {
XPC_LOG_ALWAYS(("Dumping a nsIXPCWrappedJSClass..."));
wjsc->DebugDump(depth);
NS_RELEASE(wjsc);
}
else if (NS_SUCCEEDED(p->QueryInterface(NS_GET_IID(nsIXPConnectWrappedNative),
(void**)&wn)))
{
(void**)&wn))) {
XPC_LOG_ALWAYS(("Dumping a nsIXPConnectWrappedNative..."));
wn->DebugDump(depth);
NS_RELEASE(wn);
}
else if (NS_SUCCEEDED(p->QueryInterface(NS_GET_IID(nsIXPConnectWrappedJS),
(void**)&wjs)))
{
(void**)&wjs))) {
XPC_LOG_ALWAYS(("Dumping a nsIXPConnectWrappedJS..."));
wjs->DebugDump(depth);
NS_RELEASE(wjs);
@ -2412,8 +2339,7 @@ nsXPConnect::VariantToJS(JSContext* ctx, JSObject* scope, nsIVariant* value, jsv
ccx.SetScopeForNewJSObjects(scope);
nsresult rv = NS_OK;
if (!XPCVariant::VariantDataToJS(lccx, value, &rv, _retval))
{
if (!XPCVariant::VariantDataToJS(lccx, value, &rv, _retval)) {
if (NS_FAILED(rv))
return rv;
@ -2561,8 +2487,7 @@ nsXPConnect::GetCount(PRInt32 *aCount)
XPCPerThreadData* data = XPCPerThreadData::GetData(nsnull);
if (!data)
{
if (!data) {
*aCount = 0;
return NS_ERROR_FAILURE;
}
@ -2579,8 +2504,7 @@ nsXPConnect::Peek(JSContext * *_retval)
XPCPerThreadData* data = XPCPerThreadData::GetData(nsnull);
if (!data)
{
if (!data) {
*_retval = nsnull;
return NS_ERROR_FAILURE;
}
@ -2666,8 +2590,7 @@ nsXPConnect::Pop(JSContext * *_retval)
{
XPCPerThreadData* data = XPCPerThreadData::GetData(nsnull);
if (!data)
{
if (!data) {
if (_retval)
*_retval = nsnull;
return NS_ERROR_FAILURE;
@ -2715,8 +2638,7 @@ nsXPConnect::GetSafeJSContext(JSContext * *aSafeJSContext)
XPCPerThreadData* data = XPCPerThreadData::GetData(nsnull);
if (!data)
{
if (!data) {
*aSafeJSContext = nsnull;
return NS_ERROR_FAILURE;
}
@ -2730,8 +2652,7 @@ nsXPConnect::GetPrincipal(JSObject* obj, bool allowShortCircuit) const
NS_ASSERTION(IS_WRAPPER_CLASS(obj->getClass()),
"What kind of wrapper is this?");
if (IS_WN_WRAPPER_OBJECT(obj))
{
if (IS_WN_WRAPPER_OBJECT(obj)) {
XPCWrappedNative *xpcWrapper =
(XPCWrappedNative *)xpc_GetJSPrivate(obj);
if (xpcWrapper) {
@ -2753,8 +2674,7 @@ nsXPConnect::GetPrincipal(JSObject* obj, bool allowShortCircuit) const
}
}
}
else
{
else {
if (allowShortCircuit) {
nsIPrincipal *result =
GetSlimWrapperProto(obj)->GetScope()->GetPrincipal();
@ -2814,8 +2734,7 @@ nsXPConnect::Base64Encode(const nsACString &aBinaryData, nsACString &aString)
// Add one byte for null termination.
if (aString.SetCapacity(stringLen + 1) &&
(buffer = aString.BeginWriting()) &&
PL_Base64Encode(aBinaryData.BeginReading(), aBinaryData.Length(), buffer))
{
PL_Base64Encode(aBinaryData.BeginReading(), aBinaryData.Length(), buffer)) {
// PL_Base64Encode doesn't null terminate the buffer for us when we pass
// the buffer in. Do that manually.
buffer[stringLen] = '\0';
@ -2858,8 +2777,7 @@ nsXPConnect::Base64Encode(JSContext *cx, jsval val, jsval *out)
return JS_FALSE;
nsCAutoString result;
if (NS_FAILED(nsXPConnect::Base64Encode(encodedString, result)))
{
if (NS_FAILED(nsXPConnect::Base64Encode(encodedString, result))) {
JS_ReportError(cx, "Failed to encode base64 data!");
return JS_FALSE;
}
@ -2887,13 +2805,11 @@ nsXPConnect::Base64Decode(const nsACString &aString, nsACString &aBinaryData)
// Add one byte for null termination.
if (aBinaryData.SetCapacity(binaryDataLen + 1) &&
(buffer = aBinaryData.BeginWriting()) &&
PL_Base64Decode(aString.BeginReading(), aString.Length(), buffer))
{
PL_Base64Decode(aString.BeginReading(), aString.Length(), buffer)) {
// PL_Base64Decode doesn't null terminate the buffer for us when we pass
// the buffer in. Do that manually, taking into account the number of '='
// characters we were passed.
if (!aString.IsEmpty() && aString[aString.Length() - 1] == '=')
{
if (!aString.IsEmpty() && aString[aString.Length() - 1] == '=') {
if (aString.Length() > 1 && aString[aString.Length() - 2] == '=')
binaryDataLen -= 2;
else
@ -2939,8 +2855,7 @@ nsXPConnect::Base64Decode(JSContext *cx, jsval val, jsval *out)
return JS_FALSE;
nsCAutoString result;
if (NS_FAILED(nsXPConnect::Base64Decode(encodedString, result)))
{
if (NS_FAILED(nsXPConnect::Base64Decode(encodedString, result))) {
JS_ReportError(cx, "Failed to decode base64 string!");
return JS_FALSE;
}

View File

@ -373,8 +373,7 @@ public:
~XPCAutoLock()
{
if (mLock)
{
if (mLock) {
mLock->Exit();
}
}
@ -407,8 +406,7 @@ public:
: mLock(lock)
{
MOZILLA_GUARD_OBJECT_NOTIFIER_INIT;
if (mLock)
{
if (mLock) {
mLock->Exit();
}
}
@ -923,13 +921,11 @@ public:
NS_ASSERTION(CallerTypeIsKnown(),"missing caller type set somewhere");
if (!CallerTypeIsJavaScript())
return nsnull;
if (mSecurityManager)
{
if (mSecurityManager) {
if (flags & mSecurityManagerFlags)
return mSecurityManager;
}
else
{
else {
nsIXPCSecurityManager* mgr;
nsXPConnect* xpc = mRuntime->GetXPConnect();
mgr = xpc->GetDefaultSecurityManager();
@ -1312,16 +1308,14 @@ public:
}
XPCCallContext &GetXPCCallContext()
{
if (!mCcx)
{
if (!mCcx) {
mCcxToDestroy = mCcx =
new (mData) XPCCallContext(mCallerLanguage, mCx,
mCallBeginRequest == CALL_BEGINREQUEST,
mObj,
mFlattenedJSObject, mWrapper,
mTearOff);
if (!mCcx->IsValid())
{
if (!mCcx->IsValid()) {
NS_ERROR("This is not supposed to fail!");
}
}
@ -2254,8 +2248,7 @@ public:
static NS_DEFINE_IID(kThisPtrOffsetsSID, NS_THISPTROFFSETS_SID);
#ifdef DEBUG
if (InitedOffsets() && mOffsets)
{
if (InitedOffsets() && mOffsets) {
QITableEntry* offsets;
identity->QueryInterface(kThisPtrOffsetsSID, (void**)&offsets);
NS_ASSERTION(offsets == mOffsets,
@ -2264,14 +2257,11 @@ public:
}
#endif
if (!InitedOffsets())
{
if (mClassInfoFlags & nsIClassInfo::CONTENT_NODE)
{
if (!InitedOffsets()) {
if (mClassInfoFlags & nsIClassInfo::CONTENT_NODE) {
identity->QueryInterface(kThisPtrOffsetsSID, (void**)&mOffsets);
}
else
{
else {
mOffsets = nsnull;
}
}
@ -2309,8 +2299,7 @@ public:
void TraceJS(JSTracer* trc)
{
if (mJSProtoObject)
{
if (mJSProtoObject) {
JS_CALL_OBJECT_TRACER(trc, mJSProtoObject,
"XPCWrappedNativeProto::mJSProtoObject");
}
@ -2707,8 +2696,7 @@ public:
// This is the only time we should be tracing our mFlatJSObject,
// normally somebody else is doing that. Be careful not to trace the
// bogus INVALID_OBJECT value we can have during init, though.
if (mFlatJSObject && mFlatJSObject != INVALID_OBJECT)
{
if (mFlatJSObject && mFlatJSObject != INVALID_OBJECT) {
JS_CALL_OBJECT_TRACER(trc, mFlatJSObject,
"XPCWrappedNative::mFlatJSObject");
}
@ -2746,8 +2734,7 @@ public:
JSObject* GetWrapper()
{
JSObject* wrapper = GetWrapperPreserveColor();
if (wrapper)
{
if (wrapper) {
xpc_UnmarkGrayObject(wrapper);
// Call this to unmark mFlatJSObject.
GetFlatJSObject();
@ -2772,8 +2759,7 @@ public:
XPCWrappedNativeProto* proto = GetProto();
QITableEntry* offsets = proto->GetOffsets();
if (!offsets)
{
if (!offsets) {
static NS_DEFINE_IID(kThisPtrOffsetsSID, NS_THISPTROFFSETS_SID);
mIdentity->QueryInterface(kThisPtrOffsetsSID, (void**)&offsets);
}
@ -3136,8 +3122,7 @@ public:
mCache(aCache),
mIsNode(PR_FALSE)
{
if (!mCache)
{
if (!mCache) {
if (aObject)
CallQueryInterface(aObject, &mCache);
else
@ -3179,8 +3164,7 @@ public:
}
nsXPCClassInfo *GetXPCClassInfo()
{
if (!mXPCClassInfo)
{
if (!mXPCClassInfo) {
if (mIsNode)
mXPCClassInfo = static_cast<nsINode*>(GetCanonical())->GetClassInfo();
else
@ -3656,15 +3640,13 @@ public:
// Get the instance of this object for the current thread
static inline XPCPerThreadData* GetData(JSContext *cx)
{
if (cx)
{
if (cx) {
NS_ASSERTION(cx->thread(), "Uh, JS context w/o a thread?");
if (cx->thread() == sMainJSThread)
return sMainThreadData;
}
else if (sMainThreadData && sMainThreadData->mThread == PR_GetCurrentThread())
{
else if (sMainThreadData && sMainThreadData->mThread == PR_GetCurrentThread()) {
return sMainThreadData;
}
@ -4179,11 +4161,9 @@ public: \
\
virtual void TraceJS(JSTracer* trc) \
{ \
for (PRUint32 i = 0; i < mCount; ++i) \
{ \
for (PRUint32 i = 0; i < mCount; ++i) { \
type_* cur = mPtr[i]; \
if (cur) \
{ \
if (cur) { \
cur->TraceJS(trc); \
cur->AutoTrace(trc); \
} \
@ -4193,8 +4173,7 @@ public: \
\
virtual void MarkAfterJSFinalize() \
{ \
for (PRUint32 i = 0; i < mCount; ++i) \
{ \
for (PRUint32 i = 0; i < mCount; ++i) { \
type_* cur = mPtr[i]; \
if (cur) \
cur->Mark(); \

View File

@ -1103,8 +1103,7 @@ XrayProxy::getPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id,
AutoLeaveHelper<CrossCompartmentWrapper> helper(*this, cx, wrapper);
JSObject *obj = &js::GetProxyPrivate(wrapper).toObject();
if (XrayUtils::IsTransparent(cx, wrapper)) {
{
if (XrayUtils::IsTransparent(cx, wrapper)) { {
JSAutoEnterCompartment ac;
if (!ac.enter(cx, obj))
return false;
@ -1174,8 +1173,7 @@ XrayProxy::getOwnPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id,
AutoLeaveHelper<CrossCompartmentWrapper> helper(*this, cx, wrapper);
JSObject *obj = &js::GetProxyPrivate(wrapper).toObject();
if (XrayUtils::IsTransparent(cx, wrapper)) {
{
if (XrayUtils::IsTransparent(cx, wrapper)) { {
JSAutoEnterCompartment ac;
if (!ac.enter(cx, obj))
return false;