[JAEGER] Merge from tracemonkey.

This commit is contained in:
David Mandelin 2010-08-27 11:25:56 -07:00
commit 7b2310c5cf
4 changed files with 19 additions and 3 deletions

View File

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

View File

@ -285,6 +285,7 @@ protected:
if (!global)
return NULL;
JSAutoEnterCompartment enter(cx, global);
/* Populate the global object with the standard globals,
like Object and Array. */
if (!JS_InitStandardClasses(cx, global))

View File

@ -1219,6 +1219,10 @@ mozJSComponentLoader::GlobalForLocation(nsILocalFile *aComponentFile,
rv = holder->GetJSObject(&global);
NS_ENSURE_SUCCESS(rv, rv);
JSAutoCrossCompartmentCall ac;
if (!ac.enter(cx, global))
return NS_ERROR_FAILURE;
if (!JS_DefineFunctions(cx, global, gGlobalFun)) {
return NS_ERROR_FAILURE;
}

View File

@ -810,9 +810,12 @@ int main()
{
JSAutoRequest ar(jscontext);
glob = JS_NewGlobalObject(jscontext, &global_class);
glob = JS_NewCompartmentAndGlobalObject(jscontext, &global_class, NULL);
if (!glob)
DIE("FAILED to create global object");
JSAutoEnterCompartment autoCompartment(jscontext, glob);
if (!JS_InitStandardClasses(jscontext, glob))
DIE("FAILED to init standard classes");
if (!JS_DefineFunctions(jscontext, glob, glob_functions))