Bug 766378 - adds a createArrayIn() call to create JS arrays in a given scope [r=mrbkap]

This commit is contained in:
Fabrice Desré 2012-06-19 16:54:46 -07:00
parent 7ff49f22ce
commit 7a73ff8ad0
2 changed files with 37 additions and 0 deletions

View File

@ -285,6 +285,14 @@ interface nsIXPCComponents_Utils : nsISupports
[implicit_jscontext]
jsval createObjectIn(in jsval vobj);
/*
* To be called from JS only.
*
* Returns an array created in |vobj|'s compartment.
*/
[implicit_jscontext]
jsval createArrayIn(in jsval vobj);
/*
* To be called from JS only.
*

View File

@ -4129,6 +4129,35 @@ nsXPCComponents_Utils::CreateObjectIn(const jsval &vobj, JSContext *cx, jsval *r
return NS_OK;
}
/* jsval createObjectIn(in jsval vobj); */
NS_IMETHODIMP
nsXPCComponents_Utils::CreateArrayIn(const jsval &vobj, JSContext *cx, jsval *rval)
{
if (!cx)
return NS_ERROR_FAILURE;
// first argument must be an object
if (JSVAL_IS_PRIMITIVE(vobj))
return NS_ERROR_XPC_BAD_CONVERT_JS;
JSObject *scope = js::UnwrapObject(JSVAL_TO_OBJECT(vobj));
JSObject *obj;
{
JSAutoEnterCompartment ac;
if (!ac.enter(cx, scope))
return NS_ERROR_FAILURE;
obj = JS_NewArrayObject(cx, 0, NULL);
if (!obj)
return NS_ERROR_FAILURE;
}
if (!JS_WrapObject(cx, &obj))
return NS_ERROR_FAILURE;
*rval = OBJECT_TO_JSVAL(obj);
return NS_OK;
}
JSBool
FunctionWrapper(JSContext *cx, unsigned argc, jsval *vp)
{