diff --git a/js/jetpack/JetpackChild.cpp b/js/jetpack/JetpackChild.cpp index 6eb0340f643..263cd4cd74a 100644 --- a/js/jetpack/JetpackChild.cpp +++ b/js/jetpack/JetpackChild.cpp @@ -137,9 +137,15 @@ JetpackChild::Init(base::ProcessHandle aParentProcessHandle, JS_SetContextPrivate(mCx, this); JSObject* implGlobal = JS_NewCompartmentAndGlobalObject(mCx, const_cast(&sGlobalClass), NULL); + if (!implGlobal) + return false; + + JSAutoEnterCompartment ac; + if (!ac.enter(mCx, implGlobal)) + return false; + jsval ctypes; - if (!implGlobal || - !JS_InitStandardClasses(mCx, implGlobal) || + if (!JS_InitStandardClasses(mCx, implGlobal) || #ifdef BUILD_CTYPES !JS_InitCTypesClass(mCx, implGlobal) || !JS_GetProperty(mCx, implGlobal, "ctypes", &ctypes) || @@ -173,6 +179,12 @@ JetpackChild::RecvSendMessage(const nsString& messageName, const nsTArray& data) { JSAutoRequest request(mCx); + + JSObject *global = JS_GetGlobalObject(mCx); + JSAutoEnterCompartment ac; + if (!ac.enter(mCx, global)) + return false; + return JetpackActorCommon::RecvMessage(mCx, messageName, data, NULL); } @@ -181,9 +193,14 @@ JetpackChild::RecvEvalScript(const nsString& code) { JSAutoRequest request(mCx); - js::AutoValueRooter ignored(mCx); - (void) JS_EvaluateUCScript(mCx, JS_GetGlobalObject(mCx), code.get(), - code.Length(), "", 1, ignored.jsval_addr()); + JSObject *global = JS_GetGlobalObject(mCx); + JSAutoEnterCompartment ac; + if (!ac.enter(mCx, global)) + return false; + + jsval ignored; + (void) JS_EvaluateUCScript(mCx, global, code.get(), + code.Length(), "", 1, &ignored); return true; } diff --git a/js/jetpack/JetpackParent.cpp b/js/jetpack/JetpackParent.cpp index 65032e4c145..8c1f4c983e9 100644 --- a/js/jetpack/JetpackParent.cpp +++ b/js/jetpack/JetpackParent.cpp @@ -92,6 +92,10 @@ JetpackParent::SendMessage(const nsAString& aMessageName) JSAutoRequest request(cx); + JSAutoEnterCompartment ac; + if (!ac.enter(cx, JS_GetGlobalObject(cx))) + return false; + for (PRUint32 i = 1; i < argc; ++i) if (!jsval_to_Variant(cx, argv[i], data.AppendElement())) return NS_ERROR_INVALID_ARG; @@ -162,6 +166,11 @@ JetpackParent::RecvSendMessage(const nsString& messageName, { AutoCXPusher cxp(mContext); JSAutoRequest request(mContext); + + JSAutoEnterCompartment ac; + if (!ac.enter(mContext, JS_GetGlobalObject(mContext))) + return false; + return JetpackActorCommon::RecvMessage(mContext, messageName, data, NULL); } @@ -172,6 +181,11 @@ JetpackParent::AnswerCallMessage(const nsString& messageName, { AutoCXPusher cxp(mContext); JSAutoRequest request(mContext); + + JSAutoEnterCompartment ac; + if (!ac.enter(mContext, JS_GetGlobalObject(mContext))) + return false; + return JetpackActorCommon::RecvMessage(mContext, messageName, data, results); } @@ -188,6 +202,10 @@ JetpackParent::CreateHandle(nsIVariant** aResult) JSAutoRequest request(mContext); + JSAutoEnterCompartment ac; + if (!ac.enter(mContext, JS_GetGlobalObject(mContext))) + return false; + JSObject* hobj = handle->ToJSObject(mContext); if (!hobj) return NS_ERROR_FAILURE;