本文整理汇总了C++中js::CompartmentOptions::setZone方法的典型用法代码示例。如果您正苦于以下问题:C++ CompartmentOptions::setZone方法的具体用法?C++ CompartmentOptions::setZone怎么用?C++ CompartmentOptions::setZone使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类js::CompartmentOptions
的用法示例。
在下文中一共展示了CompartmentOptions::setZone方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: req
JSContext*
XPCJSContextStack::InitSafeJSContext()
{
MOZ_ASSERT(!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();
nsresult rv = principal->Init();
if (NS_FAILED(rv))
MOZ_CRASH();
nsXPConnect* xpc = nsXPConnect::XPConnect();
JSRuntime *rt = xpc->GetRuntime()->Runtime();
if (!rt)
MOZ_CRASH();
mSafeJSContext = JS_NewContext(rt, 8192);
if (!mSafeJSContext)
MOZ_CRASH();
JSAutoRequest req(mSafeJSContext);
ContextOptionsRef(mSafeJSContext).setNoDefaultCompartmentObject(true);
JS_SetErrorReporter(mSafeJSContext, xpc::SystemErrorReporter);
// Note - We intentionally avoid firing OnNewGlobalObject while
// simultaneously skipping the call to setInvisibleToDebugger(true) here.
// This lets us piggy-back on the assertions in the JS engine (which make
// sure that, for non-invisible globals, we always fire onNewGlobalObject
// before creating scripts), to assert that we never create scripts with
// the SafeJSContextGlobal. This is all happening way before anyone could be
// listening for debugger notifications anyway.
JS::CompartmentOptions options;
options.setZone(JS::SystemZone)
.setTrace(TraceXPCGlobal);
mSafeJSContextGlobal = CreateGlobalObject(mSafeJSContext,
&SafeJSContextGlobalClass,
principal, options);
if (!mSafeJSContextGlobal)
MOZ_CRASH();
nsRefPtr<SandboxPrivate> sp = new SandboxPrivate(principal, mSafeJSContextGlobal);
JS_SetPrivate(mSafeJSContextGlobal, sp.forget().take());
return mSafeJSContext;
}
示例2: ac
GlobalObject *
JSRuntime::createSelfHostingGlobal(JSContext *cx)
{
MOZ_ASSERT(!cx->isExceptionPending());
MOZ_ASSERT(!cx->runtime()->isAtomsCompartment(cx->compartment()));
JS::CompartmentOptions options;
options.setDiscardSource(true);
options.setZone(JS::FreshZone);
JSCompartment *compartment = NewCompartment(cx, nullptr, nullptr, options);
if (!compartment)
return nullptr;
static const Class shgClass = {
"self-hosting-global", JSCLASS_GLOBAL_FLAGS,
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr,
JS_GlobalObjectTraceHook
};
AutoCompartment ac(cx, compartment);
Rooted<GlobalObject*> shg(cx, GlobalObject::createInternal(cx, &shgClass));
if (!shg)
return nullptr;
cx->runtime()->selfHostingGlobal_ = shg;
compartment->isSelfHosting = true;
compartment->isSystem = true;
if (!GlobalObject::initSelfHostingBuiltins(cx, shg, intrinsic_functions))
return nullptr;
JS_FireOnNewGlobalObject(cx, shg);
return shg;
}
示例3: Init
nsresult Init()
{
mRuntime = JS_NewRuntime(sRuntimeHeapSize, JS_NO_HELPER_THREADS);
NS_ENSURE_TRUE(mRuntime, NS_ERROR_OUT_OF_MEMORY);
/*
* Not setting this will cause JS_CHECK_RECURSION to report false
* positives
*/
JS_SetNativeStackQuota(mRuntime, 128 * sizeof(size_t) * 1024);
mContext = JS_NewContext(mRuntime, 0);
NS_ENSURE_TRUE(mContext, NS_ERROR_OUT_OF_MEMORY);
JSAutoRequest ar(mContext);
JS::CompartmentOptions options;
options.setZone(JS::SystemZone)
.setVersion(JSVERSION_LATEST);
mGlobal = JS_NewGlobalObject(mContext, &sGlobalClass, nullptr,
JS::DontFireOnNewGlobalHook, options);
NS_ENSURE_TRUE(mGlobal, NS_ERROR_OUT_OF_MEMORY);
JS::Rooted<JSObject*> global(mContext, mGlobal);
JSAutoCompartment ac(mContext, global);
js::SetDefaultObjectForContext(mContext, global);
JS_InitStandardClasses(mContext, global);
JS_SetErrorReporter(mContext, PACErrorReporter);
if (!JS_DefineFunctions(mContext, global, PACGlobalFunctions))
return NS_ERROR_FAILURE;
JS_FireOnNewGlobalObject(mContext, global);
return NS_OK;
}
示例4: usage
//.........这里部分代码省略.........
fprintf(gErrFile, "+++ Failed to obtain SystemPrincipal from ScriptSecurityManager service.\n");
} else {
// fetch the JS principals and stick in a global
gJSPrincipals = nsJSPrincipals::get(systemprincipal);
JS_HoldPrincipals(gJSPrincipals);
}
} else {
fprintf(gErrFile, "+++ Failed to get ScriptSecurityManager service, running without principals");
}
}
const JSSecurityCallbacks* scb = JS_GetSecurityCallbacks(rt);
MOZ_ASSERT(scb, "We are assuming that nsScriptSecurityManager::Init() has been run");
shellSecurityCallbacks = *scb;
JS_SetSecurityCallbacks(rt, &shellSecurityCallbacks);
#ifdef TEST_TranslateThis
nsCOMPtr<nsIXPCFunctionThisTranslator>
translator(new nsXPCFunctionThisTranslator);
xpc->SetFunctionThisTranslator(NS_GET_IID(nsITestXPCFunctionCallback), translator);
#endif
nsRefPtr<BackstagePass> backstagePass;
rv = NS_NewBackstagePass(getter_AddRefs(backstagePass));
if (NS_FAILED(rv)) {
fprintf(gErrFile, "+++ Failed to create BackstagePass: %8x\n",
static_cast<uint32_t>(rv));
return 1;
}
// Make the default XPCShell global use a fresh zone (rather than the
// System Zone) to improve cross-zone test coverage.
JS::CompartmentOptions options;
options.setZone(JS::FreshZone)
.setVersion(JSVERSION_LATEST);
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
rv = xpc->InitClassesWithNewWrappedGlobal(cx,
static_cast<nsIGlobalObject*>(backstagePass),
systemprincipal,
0,
options,
getter_AddRefs(holder));
if (NS_FAILED(rv))
return 1;
{
JS::Rooted<JSObject*> glob(cx, holder->GetJSObject());
if (!glob) {
return 1;
}
// Even if we're building in a configuration where source is
// discarded, there's no reason to do that on XPCShell, and doing so
// might break various automation scripts.
JS::CompartmentOptionsRef(glob).setDiscardSource(false);
backstagePass->SetGlobalObject(glob);
JSAutoCompartment ac(cx, glob);
if (!JS_InitReflect(cx, glob)) {
return 1;
}
if (!JS_DefineFunctions(cx, glob, glob_functions) ||
!JS_DefineProfilingFunctions(cx, glob)) {
示例5: ar
bool
XPCShellEnvironment::Init()
{
nsresult rv;
#ifdef HAVE_SETBUF
// unbuffer stdout so that output is in the correct order; note that stderr
// is unbuffered by default
setbuf(stdout, 0);
#endif
nsCOMPtr<nsIJSRuntimeService> rtsvc =
do_GetService("@mozilla.org/js/xpc/RuntimeService;1");
if (!rtsvc) {
NS_ERROR("failed to get nsJSRuntimeService!");
return false;
}
JSRuntime *rt;
if (NS_FAILED(rtsvc->GetRuntime(&rt)) || !rt) {
NS_ERROR("failed to get JSRuntime from nsJSRuntimeService!");
return false;
}
if (!mGlobalHolder.Hold(rt)) {
NS_ERROR("Can't protect global object!");
return false;
}
gOldContextCallback = JS_SetContextCallback(rt, ContextCallback);
JSContext *cx = JS_NewContext(rt, 8192);
if (!cx) {
NS_ERROR("JS_NewContext failed!");
JS_SetContextCallback(rt, gOldContextCallback);
gOldContextCallback = NULL;
return false;
}
mCx = cx;
JS_SetContextPrivate(cx, this);
nsCOMPtr<nsIXPConnect> xpc =
do_GetService(nsIXPConnect::GetCID());
if (!xpc) {
NS_ERROR("failed to get nsXPConnect service!");
return false;
}
nsCOMPtr<nsIPrincipal> principal;
nsCOMPtr<nsIScriptSecurityManager> securityManager =
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv) && securityManager) {
rv = securityManager->GetSystemPrincipal(getter_AddRefs(principal));
if (NS_FAILED(rv)) {
fprintf(stderr, "+++ Failed to obtain SystemPrincipal from ScriptSecurityManager service.\n");
} else {
// fetch the JS principals and stick in a global
mJSPrincipals = nsJSPrincipals::get(principal);
JS_HoldPrincipals(mJSPrincipals);
}
} else {
fprintf(stderr, "+++ Failed to get ScriptSecurityManager service, running without principals");
}
nsCxPusher pusher;
pusher.Push(mCx);
nsRefPtr<BackstagePass> backstagePass;
rv = NS_NewBackstagePass(getter_AddRefs(backstagePass));
if (NS_FAILED(rv)) {
NS_ERROR("Failed to create backstage pass!");
return false;
}
JS::CompartmentOptions options;
options.setZone(JS::SystemZone)
.setVersion(JSVERSION_LATEST);
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
rv = xpc->InitClassesWithNewWrappedGlobal(cx,
static_cast<nsIGlobalObject *>(backstagePass),
principal, 0,
options,
getter_AddRefs(holder));
if (NS_FAILED(rv)) {
NS_ERROR("InitClassesWithNewWrappedGlobal failed!");
return false;
}
JS::Rooted<JSObject*> globalObj(cx, holder->GetJSObject());
if (!globalObj) {
NS_ERROR("Failed to get global JSObject!");
return false;
}
backstagePass->SetGlobalObject(globalObj);
{
//.........这里部分代码省略.........