Bug 868675 - Introduce a Cu API for waiving/unwaiving. r=gabor,sr=mrbkap

This should be the API we promote going forward.
This commit is contained in:
Bobby Holley 2013-05-07 10:09:02 -07:00
parent 93cdc4ce53
commit 771069e4dc
2 changed files with 36 additions and 1 deletions

View File

@ -119,7 +119,7 @@ interface ScheduledGCCallback : nsISupports
/**
* interface of Components.utils
*/
[scriptable, uuid(379dd078-8d4d-42c6-9617-4e7beea16aa2)]
[scriptable, uuid(623d354d-6eab-4cf6-8c08-2cde5869d439)]
interface nsIXPCComponents_Utils : nsISupports
{
@ -405,6 +405,18 @@ interface nsIXPCComponents_Utils : nsISupports
*/
bool isXrayWrapper(in jsval obj);
/**
* Waive Xray on a given value. Identity op for primitives.
*/
[implicit_jscontext]
jsval waiveXrays(in jsval aVal);
/**
* Strip off Xray waivers on a given value. Identity op for primitives.
*/
[implicit_jscontext]
jsval unwaiveXrays(in jsval aVal);
/**
* Gets the name of the JSClass of the object.
*

View File

@ -4574,6 +4574,29 @@ nsXPCComponents_Utils::IsXrayWrapper(const JS::Value &obj, bool* aRetval)
return NS_OK;
}
NS_IMETHODIMP
nsXPCComponents_Utils::WaiveXrays(const JS::Value &aVal, JSContext *aCx, jsval *aRetval)
{
*aRetval = aVal;
if (!xpc::WrapperFactory::WaiveXrayAndWrap(aCx, aRetval))
return NS_ERROR_FAILURE;
return NS_OK;
}
NS_IMETHODIMP
nsXPCComponents_Utils::UnwaiveXrays(const JS::Value &aVal, JSContext *aCx, jsval *aRetval)
{
if (!aVal.isObject()) {
*aRetval = aVal;
return NS_OK;
}
*aRetval = ObjectValue(*js::UncheckedUnwrap(&aVal.toObject()));
if (!JS_WrapValue(aCx, aRetval))
return NS_ERROR_FAILURE;
return NS_OK;
}
NS_IMETHODIMP
nsXPCComponents_Utils::GetClassName(const JS::Value &aObj, bool aUnwrap, JSContext *aCx, char **aRv)
{