Bug 590319 - TM: Global Object created in JetpackChild needs its own compartment r=mrbkap

This commit is contained in:
Gregor Wagner 2010-08-26 14:26:57 -07:00
parent 4715311df8
commit 10b59b0ba7

View File

@ -111,7 +111,7 @@ JetpackChild::Init(base::ProcessHandle aParentProcessHandle,
JSAutoRequest request(mCx); JSAutoRequest request(mCx);
JS_SetContextPrivate(mCx, this); JS_SetContextPrivate(mCx, this);
JSObject* implGlobal = JSObject* implGlobal =
JS_NewGlobalObject(mCx, const_cast<JSClass*>(&sGlobalClass)); JS_NewCompartmentAndGlobalObject(mCx, const_cast<JSClass*>(&sGlobalClass), NULL);
if (!implGlobal || if (!implGlobal ||
!JS_InitStandardClasses(mCx, implGlobal) || !JS_InitStandardClasses(mCx, implGlobal) ||
!JS_DefineFunctions(mCx, implGlobal, !JS_DefineFunctions(mCx, implGlobal,
@ -396,10 +396,14 @@ JetpackChild::CreateSandbox(JSContext* cx, uintN argc, jsval* vp)
return JS_FALSE; return JS_FALSE;
} }
JSObject* obj = JS_NewGlobalObject(cx, const_cast<JSClass*>(&sGlobalClass)); JSObject* obj = JS_NewCompartmentAndGlobalObject(cx, const_cast<JSClass*>(&sGlobalClass), NULL);
if (!obj) if (!obj)
return JS_FALSE; return JS_FALSE;
JSAutoCrossCompartmentCall ac;
if (!ac.enter(cx, obj))
return JS_FALSE;
JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
return JS_InitStandardClasses(cx, obj); return JS_InitStandardClasses(cx, obj);
} }
@ -427,6 +431,10 @@ JetpackChild::EvalInSandbox(JSContext* cx, uintN argc, jsval* vp)
if (!str) if (!str)
return JS_FALSE; return JS_FALSE;
JSAutoCrossCompartmentCall ac;
if (!ac.enter(cx, obj))
return JS_FALSE;
js::AutoValueRooter ignored(cx); js::AutoValueRooter ignored(cx);
return JS_EvaluateUCScript(cx, obj, JS_GetStringChars(str), JS_GetStringLength(str), "", 1, return JS_EvaluateUCScript(cx, obj, JS_GetStringChars(str), JS_GetStringLength(str), "", 1,
ignored.jsval_addr()); ignored.jsval_addr());