mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 05:11:16 +00:00
Bug 1283855
part 20 - Make more principals code take JSContext instead of JSRuntime. r=luke
--HG-- extra : rebase_source : ad5f2f5b5bef9d20e4e248898a3c754adb306683
This commit is contained in:
parent
078a91ca56
commit
e4ae5f26da
@ -1386,11 +1386,12 @@ nsresult nsScriptSecurityManager::Init()
|
||||
JSPrincipalsSubsume,
|
||||
};
|
||||
|
||||
MOZ_ASSERT(!JS_GetSecurityCallbacks(JS_GetContext(sRuntime)));
|
||||
JS_SetSecurityCallbacks(JS_GetContext(sRuntime), &securityCallbacks);
|
||||
JS_InitDestroyPrincipalsCallback(sRuntime, nsJSPrincipals::Destroy);
|
||||
JSContext* cx = JS_GetContext(sRuntime);
|
||||
MOZ_ASSERT(!JS_GetSecurityCallbacks(cx));
|
||||
JS_SetSecurityCallbacks(cx, &securityCallbacks);
|
||||
JS_InitDestroyPrincipalsCallback(cx, nsJSPrincipals::Destroy);
|
||||
|
||||
JS_SetTrustedPrincipals(sRuntime, system);
|
||||
JS_SetTrustedPrincipals(cx, system);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@ -1415,7 +1416,7 @@ nsScriptSecurityManager::Shutdown()
|
||||
{
|
||||
if (sRuntime) {
|
||||
JS_SetSecurityCallbacks(JS_GetContext(sRuntime), nullptr);
|
||||
JS_SetTrustedPrincipals(sRuntime, nullptr);
|
||||
JS_SetTrustedPrincipals(JS_GetContext(sRuntime), nullptr);
|
||||
sRuntime = nullptr;
|
||||
}
|
||||
|
||||
|
@ -892,7 +892,7 @@ public:
|
||||
JSContext* cx = JS_GetContext(rt);
|
||||
|
||||
js::SetPreserveWrapperCallback(cx, PreserveWrapper);
|
||||
JS_InitDestroyPrincipalsCallback(rt, DestroyWorkerPrincipals);
|
||||
JS_InitDestroyPrincipalsCallback(cx, DestroyWorkerPrincipals);
|
||||
JS_SetWrapObjectCallbacks(cx, &WrapObjectCallbacks);
|
||||
if (mWorkerPrivate->IsDedicatedWorker()) {
|
||||
JS_SetFutexCanWait(cx);
|
||||
|
@ -87,14 +87,14 @@ JS_GetSecurityCallbacks(JSContext* cx);
|
||||
* untrusted script has exhausted the stack. This function sets the
|
||||
* runtime-wide trusted principal.
|
||||
*
|
||||
* This principals is not held (via JS_HoldPrincipals/JS_DropPrincipals) since
|
||||
* there is no available JSContext. Instead, the caller must ensure that the
|
||||
* given principals stays valid for as long as 'rt' may point to it. If the
|
||||
* principals would be destroyed before 'rt', JS_SetTrustedPrincipals must be
|
||||
* called again, passing nullptr for 'prin'.
|
||||
* This principals is not held (via JS_HoldPrincipals/JS_DropPrincipals).
|
||||
* Instead, the caller must ensure that the given principals stays valid for as
|
||||
* long as 'cx' may point to it. If the principals would be destroyed before
|
||||
* 'cx', JS_SetTrustedPrincipals must be called again, passing nullptr for
|
||||
* 'prin'.
|
||||
*/
|
||||
extern JS_PUBLIC_API(void)
|
||||
JS_SetTrustedPrincipals(JSRuntime* rt, JSPrincipals* prin);
|
||||
JS_SetTrustedPrincipals(JSContext* cx, JSPrincipals* prin);
|
||||
|
||||
typedef void
|
||||
(* JSDestroyPrincipalsOp)(JSPrincipals* principals);
|
||||
@ -105,7 +105,7 @@ typedef void
|
||||
* only once per JS runtime.
|
||||
*/
|
||||
extern JS_PUBLIC_API(void)
|
||||
JS_InitDestroyPrincipalsCallback(JSRuntime* rt, JSDestroyPrincipalsOp destroyPrincipals);
|
||||
JS_InitDestroyPrincipalsCallback(JSContext* cx, JSDestroyPrincipalsOp destroyPrincipals);
|
||||
|
||||
/*
|
||||
* Read a JSPrincipals instance from the given |reader| and initialize the out
|
||||
@ -126,7 +126,7 @@ using JSReadPrincipalsOp = bool (*)(JSContext* cx, JSStructuredCloneReader* read
|
||||
* buffer. The initialization can be done only once per JS runtime.
|
||||
*/
|
||||
extern JS_PUBLIC_API(void)
|
||||
JS_InitReadPrincipalsCallback(JSRuntime* rt, JSReadPrincipalsOp read);
|
||||
JS_InitReadPrincipalsCallback(JSContext* cx, JSReadPrincipalsOp read);
|
||||
|
||||
|
||||
#endif /* js_Principals_h */
|
||||
|
@ -48,7 +48,7 @@ CallTrusted(JSContext* cx, unsigned argc, JS::Value* vp)
|
||||
|
||||
BEGIN_TEST(testChromeBuffer)
|
||||
{
|
||||
JS_SetTrustedPrincipals(rt, &system_principals);
|
||||
JS_SetTrustedPrincipals(cx, &system_principals);
|
||||
|
||||
JS::CompartmentOptions options;
|
||||
trusted_glob.init(cx, JS_NewGlobalObject(cx, &global_class, &system_principals,
|
||||
|
@ -92,7 +92,7 @@ DestroyPrincipals(JSPrincipals* principals)
|
||||
|
||||
BEGIN_TEST(test_cloneScriptWithPrincipals)
|
||||
{
|
||||
JS_InitDestroyPrincipalsCallback(rt, DestroyPrincipals);
|
||||
JS_InitDestroyPrincipalsCallback(cx, DestroyPrincipals);
|
||||
|
||||
JSPrincipals* principalsA = new Principals();
|
||||
AutoDropPrincipals dropA(rt, principalsA);
|
||||
|
@ -131,8 +131,8 @@ JSSecurityCallbacks StructuredCloneTestPrincipals::securityCallbacks = {
|
||||
BEGIN_TEST(testStructuredClone_SavedFrame)
|
||||
{
|
||||
JS_SetSecurityCallbacks(cx, &StructuredCloneTestPrincipals::securityCallbacks);
|
||||
JS_InitDestroyPrincipalsCallback(rt, StructuredCloneTestPrincipals::destroy);
|
||||
JS_InitReadPrincipalsCallback(rt, StructuredCloneTestPrincipals::read);
|
||||
JS_InitDestroyPrincipalsCallback(cx, StructuredCloneTestPrincipals::destroy);
|
||||
JS_InitReadPrincipalsCallback(cx, StructuredCloneTestPrincipals::read);
|
||||
|
||||
auto testPrincipals = new StructuredCloneTestPrincipals(42, 0);
|
||||
CHECK(testPrincipals);
|
||||
|
@ -3289,25 +3289,25 @@ JS_GetSecurityCallbacks(JSContext* cx)
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(void)
|
||||
JS_SetTrustedPrincipals(JSRuntime* rt, JSPrincipals* prin)
|
||||
JS_SetTrustedPrincipals(JSContext* cx, JSPrincipals* prin)
|
||||
{
|
||||
rt->setTrustedPrincipals(prin);
|
||||
cx->setTrustedPrincipals(prin);
|
||||
}
|
||||
|
||||
extern JS_PUBLIC_API(void)
|
||||
JS_InitDestroyPrincipalsCallback(JSRuntime* rt, JSDestroyPrincipalsOp destroyPrincipals)
|
||||
JS_InitDestroyPrincipalsCallback(JSContext* cx, JSDestroyPrincipalsOp destroyPrincipals)
|
||||
{
|
||||
MOZ_ASSERT(destroyPrincipals);
|
||||
MOZ_ASSERT(!rt->destroyPrincipals);
|
||||
rt->destroyPrincipals = destroyPrincipals;
|
||||
MOZ_ASSERT(!cx->destroyPrincipals);
|
||||
cx->destroyPrincipals = destroyPrincipals;
|
||||
}
|
||||
|
||||
extern JS_PUBLIC_API(void)
|
||||
JS_InitReadPrincipalsCallback(JSRuntime* rt, JSReadPrincipalsOp read)
|
||||
JS_InitReadPrincipalsCallback(JSContext* cx, JSReadPrincipalsOp read)
|
||||
{
|
||||
MOZ_ASSERT(read);
|
||||
MOZ_ASSERT(!rt->readPrincipals);
|
||||
rt->readPrincipals = read;
|
||||
MOZ_ASSERT(!cx->readPrincipals);
|
||||
cx->readPrincipals = read;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSFunction*)
|
||||
|
@ -2949,7 +2949,7 @@ WorkerMain(void* arg)
|
||||
JS_SetRuntimePrivate(rt, sr.get());
|
||||
JS_SetFutexCanWait(cx);
|
||||
JS::SetWarningReporter(cx, WarningReporter);
|
||||
JS_InitDestroyPrincipalsCallback(rt, ShellPrincipals::destroy);
|
||||
JS_InitDestroyPrincipalsCallback(cx, ShellPrincipals::destroy);
|
||||
SetWorkerRuntimeOptions(rt);
|
||||
|
||||
if (!JS::InitSelfHostedCode(cx)) {
|
||||
@ -7396,9 +7396,9 @@ main(int argc, char** argv, char** envp)
|
||||
if (availMem > 0)
|
||||
JS_SetGCParametersBasedOnAvailableMemory(cx, availMem);
|
||||
|
||||
JS_SetTrustedPrincipals(rt, &ShellPrincipals::fullyTrusted);
|
||||
JS_SetTrustedPrincipals(cx, &ShellPrincipals::fullyTrusted);
|
||||
JS_SetSecurityCallbacks(cx, &ShellPrincipals::securityCallbacks);
|
||||
JS_InitDestroyPrincipalsCallback(rt, ShellPrincipals::destroy);
|
||||
JS_InitDestroyPrincipalsCallback(cx, ShellPrincipals::destroy);
|
||||
|
||||
JS_SetInterruptCallback(rt, ShellInterruptCallback);
|
||||
JS::SetBuildIdOp(cx, ShellBuildId);
|
||||
|
Loading…
Reference in New Issue
Block a user