本文整理汇总了C++中XPCPerThreadData类的典型用法代码示例。如果您正苦于以下问题:C++ XPCPerThreadData类的具体用法?C++ XPCPerThreadData怎么用?C++ XPCPerThreadData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了XPCPerThreadData类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PR_NewLock
// static
XPCPerThreadData*
XPCPerThreadData::GetDataImpl(JSContext *cx)
{
XPCPerThreadData* data;
if(!gLock)
{
gLock = PR_NewLock();
if(!gLock)
return nsnull;
}
if(gTLSIndex == BAD_TLS_INDEX)
{
nsAutoLock lock(gLock);
// check again now that we have the lock...
if(gTLSIndex == BAD_TLS_INDEX)
{
if(PR_FAILURE ==
PR_NewThreadPrivateIndex(&gTLSIndex, xpc_ThreadDataDtorCB))
{
NS_ERROR("PR_NewThreadPrivateIndex failed!");
gTLSIndex = BAD_TLS_INDEX;
return nsnull;
}
}
}
data = (XPCPerThreadData*) PR_GetThreadPrivate(gTLSIndex);
if(!data)
{
data = new XPCPerThreadData();
if(!data || !data->IsValid())
{
NS_ERROR("new XPCPerThreadData() failed!");
if(data)
delete data;
return nsnull;
}
if(PR_FAILURE == PR_SetThreadPrivate(gTLSIndex, data))
{
NS_ERROR("PR_SetThreadPrivate failed!");
delete data;
return nsnull;
}
}
if(cx && !sMainJSThread && NS_IsMainThread())
{
sMainJSThread = cx->thread;
sMainThreadData = data;
sMainThreadData->mThread = PR_GetCurrentThread();
}
return data;
}
示例2:
// static
void
XPCLazyCallContext::AssertContextIsTopOfStack(JSContext* cx)
{
XPCPerThreadData* tls = XPCPerThreadData::GetData(cx);
XPCJSContextStack* stack = tls->GetJSContextStack();
JSContext* topJSContext;
nsresult rv = stack->Peek(&topJSContext);
NS_ASSERTION(NS_SUCCEEDED(rv), "XPCJSContextStack::Peek failed");
NS_ASSERTION(cx == topJSContext, "wrong context on XPCJSContextStack!");
}
示例3: lock
XPCContext*
XPCJSRuntime::SyncXPCContextList(JSContext* cx /* = nsnull */)
{
// hold the map lock through this whole thing
XPCAutoLock lock(GetMapLock());
XPCContext* found = nsnull;
// add XPCContexts that represent any JSContexts we have not seen before
JSContext *cur, *iter = nsnull;
while(nsnull != (cur = JS_ContextIterator(mJSRuntime, &iter)))
{
XPCContext* xpcc = mContextMap->Find(cur);
if(!xpcc)
{
xpcc = XPCContext::newXPCContext(this, cur);
if(xpcc)
mContextMap->Add(xpcc);
}
if(xpcc)
{
xpcc->Mark();
}
// if it is our first context then we need to generate our string ids
if(!mStrIDs[0])
{
JSAutoRequest ar(cur);
GenerateStringIDs(cur);
}
if(cx && cx == cur)
found = xpcc;
}
// get rid of any XPCContexts that represent dead JSContexts
mContextMap->Enumerate(SweepContextsCB, 0);
XPCPerThreadData* tls = XPCPerThreadData::GetData(cx);
if(tls)
{
if(found)
tls->SetRecentContext(cx, found);
else
tls->ClearRecentContext();
}
return found;
}
示例4: NS_ASSERTION
NS_IMETHODIMP
nsXPCJSContextStackIterator::Reset(nsIJSContextStack *aStack)
{
NS_ASSERTION(aStack == nsXPConnect::GetXPConnect(),
"aStack must be implemented by XPConnect singleton");
XPCPerThreadData* data = XPCPerThreadData::GetData(nsnull);
if(!data)
return NS_ERROR_FAILURE;
mStack = data->GetJSContextStack()->GetStack();
if(mStack->IsEmpty())
mStack = nsnull;
else
mPosition = mStack->Length() - 1;
return NS_OK;
}
示例5: xpc_qsAssertContextOK
void
xpc_qsAssertContextOK(JSContext *cx)
{
XPCPerThreadData *thread = XPCPerThreadData::GetData(cx);
XPCJSContextStack* stack = thread->GetJSContextStack();
JSContext* topJSContext = nsnull;
nsresult rv = stack->Peek(&topJSContext);
NS_ASSERTION(NS_SUCCEEDED(rv), "XPCJSContextStack::Peek failed");
// This is what we're actually trying to assert here.
NS_ASSERTION(cx == topJSContext, "wrong context on XPCJSContextStack!");
NS_ASSERTION(XPCPerThreadData::IsMainThread(cx),
"XPConnect quick stub called on non-main thread");
}
示例6: lock
// static
void
XPCPerThreadData::CleanupAllThreads()
{
// I've questioned the sense of cleaning up other threads' data from the
// start. But I got talked into it. Now I see that we *can't* do all the
// cleaup while holding this lock. So, we are going to go to the trouble
// to copy out the data that needs to be cleaned up *outside* of
// the lock. Yuk!
XPCJSContextStack** stacks = nsnull;
int count = 0;
int i;
if(gLock)
{
nsAutoLock lock(gLock);
for(XPCPerThreadData* cur = gThreads; cur; cur = cur->mNextThread)
count++;
stacks = (XPCJSContextStack**) new XPCJSContextStack*[count] ;
if(stacks)
{
i = 0;
for(XPCPerThreadData* cur = gThreads; cur; cur = cur->mNextThread)
{
stacks[i++] = cur->mJSContextStack;
cur->mJSContextStack = nsnull;
cur->Cleanup();
}
}
}
if(stacks)
{
for(i = 0; i < count; i++)
delete stacks[i];
delete [] stacks;
}
if(gTLSIndex != BAD_TLS_INDEX)
PR_SetThreadPrivate(gTLSIndex, nsnull);
}
示例7: lock
// static
void XPCJSRuntime::TraceJS(JSTracer* trc, void* data)
{
XPCJSRuntime* self = (XPCJSRuntime*)data;
// Skip this part if XPConnect is shutting down. We get into
// bad locking problems with the thread iteration otherwise.
if(!self->GetXPConnect()->IsShuttingDown())
{
PRLock* threadLock = XPCPerThreadData::GetLock();
if(threadLock)
{ // scoped lock
nsAutoLock lock(threadLock);
XPCPerThreadData* iterp = nsnull;
XPCPerThreadData* thread;
while(nsnull != (thread =
XPCPerThreadData::IterateThreads(&iterp)))
{
// Trace those AutoMarkingPtr lists!
thread->TraceJS(trc);
}
}
}
// XPCJSObjectHolders don't participate in cycle collection, so always trace
// them here.
for(XPCRootSetElem *e = self->mObjectHolderRoots; e ; e = e->GetNextRoot())
static_cast<XPCJSObjectHolder*>(e)->TraceJS(trc);
// Mark these roots as gray so the CC can walk them later.
js::GCMarker *gcmarker = NULL;
if (IS_GC_MARKING_TRACER(trc)) {
gcmarker = static_cast<js::GCMarker *>(trc);
JS_ASSERT(gcmarker->getMarkColor() == XPC_GC_COLOR_BLACK);
gcmarker->setMarkColor(XPC_GC_COLOR_GRAY);
}
self->TraceXPConnectRoots(trc);
if (gcmarker)
gcmarker->setMarkColor(XPC_GC_COLOR_BLACK);
}
示例8: ContextCallback
ContextCallback(JSContext *cx, uintN operation)
{
XPCJSRuntime* self = nsXPConnect::GetRuntime();
if (self)
{
if (operation == JSCONTEXT_NEW)
{
// Set the limits on the native and script stack space.
XPCPerThreadData* tls = XPCPerThreadData::GetData(cx);
if(tls)
{
JS_SetThreadStackLimit(cx, tls->GetStackLimit());
}
JS_SetScriptStackQuota(cx, 100*1024*1024);
}
}
return gOldJSContextCallback
? gOldJSContextCallback(cx, operation)
: JS_TRUE;
}
示例9: getter_AddRefs
// static
void
XPCThrower::BuildAndThrowException(JSContext* cx, nsresult rv, const char* sz)
{
JSBool success = JS_FALSE;
/* no need to set an expection if the security manager already has */
if(rv == NS_ERROR_XPC_SECURITY_MANAGER_VETO && JS_IsExceptionPending(cx))
return;
nsCOMPtr<nsIException> finalException;
nsCOMPtr<nsIException> defaultException;
nsXPCException::NewException(sz, rv, nsnull, nsnull, getter_AddRefs(defaultException));
XPCPerThreadData* tls = XPCPerThreadData::GetData(cx);
if(tls)
{
nsIExceptionManager * exceptionManager = tls->GetExceptionManager();
if(exceptionManager)
{
// Ask the provider for the exception, if there is no provider
// we expect it to set e to null
exceptionManager->GetExceptionFromProvider(
rv,
defaultException,
getter_AddRefs(finalException));
// We should get at least the defaultException back,
// but just in case
if(finalException == nsnull)
{
finalException = defaultException;
}
}
}
// XXX Should we put the following test and call to JS_ReportOutOfMemory
// inside this test?
if(finalException)
success = ThrowExceptionObject(cx, finalException);
// If we weren't able to build or throw an exception we're
// most likely out of memory
if(!success)
JS_ReportOutOfMemory(cx);
}
示例10: switch
//.........这里部分代码省略.........
wrapper = static_cast<nsXPCWrappedJS*>
(dyingWrappedJSArray->ElementAt(count-1));
dyingWrappedJSArray->RemoveElementAt(count-1);
NS_RELEASE(wrapper);
}
#ifdef XPC_REPORT_NATIVE_INTERFACE_AND_SET_FLUSHING
printf("--------------------------------------------------------------\n");
int setsBefore = (int) self->mNativeSetMap->Count();
int ifacesBefore = (int) self->mIID2NativeInterfaceMap->Count();
#endif
// We use this occasion to mark and sweep NativeInterfaces,
// NativeSets, and the WrappedNativeJSClasses...
// Do the marking...
XPCWrappedNativeScope::MarkAllWrappedNativesAndProtos();
self->mDetachedWrappedNativeProtoMap->
Enumerate(DetachedWrappedNativeProtoMarker, nsnull);
// Mark the sets used in the call contexts. There is a small
// chance that a wrapper's set will change *while* a call is
// happening which uses that wrapper's old interfface set. So,
// we need to do this marking to avoid collecting those sets
// that might no longer be otherwise reachable from the wrappers
// or the wrapperprotos.
// Skip this part if XPConnect is shutting down. We get into
// bad locking problems with the thread iteration otherwise.
if(!self->GetXPConnect()->IsShuttingDown())
{
PRLock* threadLock = XPCPerThreadData::GetLock();
if(threadLock)
{ // scoped lock
nsAutoLock lock(threadLock);
XPCPerThreadData* iterp = nsnull;
XPCPerThreadData* thread;
while(nsnull != (thread =
XPCPerThreadData::IterateThreads(&iterp)))
{
// Mark those AutoMarkingPtr lists!
thread->MarkAutoRootsAfterJSFinalize();
XPCCallContext* ccxp = thread->GetCallContext();
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())
{
XPCNativeSet* set = ccxp->GetSet();
if(set)
set->Mark();
}
if(ccxp->CanGetInterface())
{
XPCNativeInterface* iface = ccxp->GetInterface();
if(iface)
iface->Mark();
}
示例11: NS_ASSERTION
JSBool XPCDispObject::Invoke(XPCCallContext & ccx, CallMode mode)
{
nsresult rv = ccx.CanCallNow();
if(NS_FAILED(rv))
{
// If the security manager is complaining then this is not really an
// internal error in xpconnect. So, no reason to botch the assertion.
NS_ASSERTION(rv == NS_ERROR_XPC_SECURITY_MANAGER_VETO,
"hmm? CanCallNow failed in XPCDispObject::Invoke. "
"We are finding out about this late!");
XPCThrower::Throw(rv, ccx);
return JS_FALSE;
}
// TODO: Remove type cast and change GetIDispatchMember to use the correct type
XPCDispInterface::Member* member = reinterpret_cast<XPCDispInterface::Member*>(ccx.GetIDispatchMember());
XPCJSRuntime* rt = ccx.GetRuntime();
XPCContext* xpcc = ccx.GetXPCContext();
XPCPerThreadData* tls = ccx.GetThreadData();
jsval* argv = ccx.GetArgv();
uintN argc = ccx.GetArgc();
tls->SetException(nsnull);
xpcc->SetLastResult(NS_ERROR_UNEXPECTED);
// set up the method index and do the security check if needed
PRUint32 secFlag;
PRUint32 secAction;
switch(mode)
{
case CALL_METHOD:
secFlag = nsIXPCSecurityManager::HOOK_CALL_METHOD;
secAction = nsIXPCSecurityManager::ACCESS_CALL_METHOD;
break;
case CALL_GETTER:
secFlag = nsIXPCSecurityManager::HOOK_GET_PROPERTY;
secAction = nsIXPCSecurityManager::ACCESS_GET_PROPERTY;
break;
case CALL_SETTER:
secFlag = nsIXPCSecurityManager::HOOK_SET_PROPERTY;
secAction = nsIXPCSecurityManager::ACCESS_SET_PROPERTY;
break;
default:
NS_ASSERTION(0,"bad value");
return JS_FALSE;
}
jsval name = member->GetName();
nsIXPCSecurityManager* sm = xpcc->GetAppropriateSecurityManager(secFlag);
XPCWrappedNative* wrapper = ccx.GetWrapper();
if(sm && NS_FAILED(sm->CanAccess(secAction, &ccx, ccx,
ccx.GetFlattenedJSObject(),
wrapper->GetIdentityObject(),
wrapper->GetClassInfo(), name,
wrapper->GetSecurityInfoAddr())))
{
// the security manager vetoed. It should have set an exception.
return JS_FALSE;
}
IDispatch * pObj = reinterpret_cast<IDispatch*>
(ccx.GetTearOff()->GetNative());
PRUint32 args = member->GetParamCount();
uintN err;
// Make sure setter has one argument
if(mode == CALL_SETTER)
args = 1;
// Allow for optional parameters. We'll let COM handle the error if there
// are not enough parameters
if(argc < args)
args = argc;
XPCDispParams * params = new XPCDispParams(args);
jsval val;
// If this is a setter, we just need to convert the first parameter
if(mode == CALL_SETTER)
{
params->SetNamedPropID();
if(!XPCDispConvert::JSToCOM(ccx, argv[0], params->GetParamRef(0), err))
{
delete params;
return ThrowBadParam(err, 0, ccx);
}
}
else if(mode != CALL_GETTER) // This is a function
{
// Convert the arguments to the function
for(PRUint32 index = 0; index < args; ++index)
{
const XPCDispInterface::Member::ParamInfo & paramInfo = member->GetParamInfo(index);
if(paramInfo.IsIn())
{
val = argv[index];
if(paramInfo.IsOut())
{
if(JSVAL_IS_PRIMITIVE(val) ||
!OBJ_GET_PROPERTY(ccx, JSVAL_TO_OBJECT(val),
rt->GetStringID(XPCJSRuntime::IDX_VALUE),
//.........这里部分代码省略.........