Bug 939294 - Handlify XPConnect. r=gabor

This commit is contained in:
Tom Schuster 2014-01-09 18:39:36 +01:00
parent 9ca1e74a06
commit f2eab1cc4d
13 changed files with 146 additions and 186 deletions

View File

@ -177,7 +177,7 @@ File(JSContext *cx, unsigned argc, Value *vp)
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
rv = xpc->WrapNativeToJSVal(cx, glob, native, nullptr,
&NS_GET_IID(nsISupports),
true, args.rval().address());
true, args.rval());
if (NS_FAILED(rv)) {
XPCThrower::Throw(rv, cx);
return false;
@ -212,7 +212,7 @@ Blob(JSContext *cx, unsigned argc, Value *vp)
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
rv = xpc->WrapNativeToJSVal(cx, glob, native, nullptr,
&NS_GET_IID(nsISupports),
true, args.rval().address());
true, args.rval());
if (NS_FAILED(rv)) {
XPCThrower::Throw(rv, cx);
return false;
@ -1084,10 +1084,10 @@ mozJSComponentLoader::UnloadModules()
NS_IMETHODIMP
mozJSComponentLoader::Import(const nsACString& registryLocation,
const Value& targetValArg,
JSContext* cx,
HandleValue targetValArg,
JSContext *cx,
uint8_t optionalArgc,
Value* retval)
MutableHandleValue retval)
{
MOZ_ASSERT(nsContentUtils::IsCallerChrome());
@ -1133,7 +1133,7 @@ mozJSComponentLoader::Import(const nsACString& registryLocation,
return NS_ERROR_FAILURE;
}
*retval = ObjectValue(*global);
retval.setObject(*global);
}
return rv;
}

View File

@ -184,10 +184,10 @@ mozJSSubScriptLoader::ReadScript(nsIURI *uri, JSContext *cx, JSObject *targetObj
NS_IMETHODIMP
mozJSSubScriptLoader::LoadSubScript(const nsAString& url,
const Value& targetArg,
HandleValue target,
const nsAString& charset,
JSContext* cx,
Value* retval)
JSContext *cx,
MutableHandleValue retval)
{
/*
* Loads a local url and evals it into the current cx
@ -202,14 +202,16 @@ mozJSSubScriptLoader::LoadSubScript(const nsAString& url,
*/
LoadSubScriptOptions options(cx);
options.charset = charset;
options.target = targetArg.isObject() ? &targetArg.toObject() : nullptr;
options.target = target.isObject() ? &target.toObject() : nullptr;
return DoLoadSubScriptWithOptions(url, options, cx, retval);
}
NS_IMETHODIMP
mozJSSubScriptLoader::LoadSubScriptWithOptions(const nsAString& url, const Value& optionsVal,
JSContext* cx, Value* retval)
mozJSSubScriptLoader::LoadSubScriptWithOptions(const nsAString& url,
HandleValue optionsVal,
JSContext *cx,
MutableHandleValue retval)
{
if (!optionsVal.isObject())
return NS_ERROR_INVALID_ARG;
@ -222,7 +224,8 @@ mozJSSubScriptLoader::LoadSubScriptWithOptions(const nsAString& url, const Value
nsresult
mozJSSubScriptLoader::DoLoadSubScriptWithOptions(const nsAString& url,
LoadSubScriptOptions& options,
JSContext* cx, Value* retval)
JSContext *cx,
MutableHandleValue retval)
{
nsresult rv = NS_OK;
@ -346,19 +349,18 @@ mozJSSubScriptLoader::DoLoadSubScriptWithOptions(const nsAString& url,
loader->NoteSubScript(script, targetObj);
RootedValue rval(cx);
bool ok = false;
if (function) {
ok = JS_CallFunction(cx, targetObj, function, 0, nullptr, rval.address());
ok = JS_CallFunction(cx, targetObj, function, 0, nullptr, retval.address());
} else {
ok = JS_ExecuteScriptVersion(cx, targetObj, script, rval.address(), version);
ok = JS_ExecuteScriptVersion(cx, targetObj, script, retval.address(), version);
}
if (ok) {
JSAutoCompartment rac(cx, result_obj);
if (!JS_WrapValue(cx, &rval))
if (!JS_WrapValue(cx, retval))
return NS_ERROR_UNEXPECTED;
*retval = rval;
}
if (cache && ok && writeScript) {

View File

@ -40,7 +40,8 @@ private:
nsresult DoLoadSubScriptWithOptions(const nsAString& url,
LoadSubScriptOptions& options,
JSContext* cx, JS::Value* retval);
JSContext* cx,
JS::MutableHandle<JS::Value> retval);
nsCOMPtr<nsIPrincipal> mSystemPrincipal;
};

View File

@ -170,7 +170,7 @@ NS_IMETHODIMP XPC_MAP_CLASSNAME::Construct(nsIXPConnectWrappedNative *wrapper, J
#endif
#ifndef XPC_MAP_WANT_HASINSTANCE
NS_IMETHODIMP XPC_MAP_CLASSNAME::HasInstance(nsIXPConnectWrappedNative *wrapper, JSContext * cx, JSObject * obj, const JS::Value &val, bool *bp, bool *_retval)
NS_IMETHODIMP XPC_MAP_CLASSNAME::HasInstance(nsIXPConnectWrappedNative *wrapper, JSContext * cx, JSObject * obj, JS::HandleValue val, bool *bp, bool *_retval)
{NS_ERROR("never called"); return NS_ERROR_NOT_IMPLEMENTED;}
#endif

View File

@ -1596,11 +1596,10 @@ nsXPCComponents_ID::CallOrConstruct(nsIXPConnectWrappedNative *wrapper,
NS_IMETHODIMP
nsXPCComponents_ID::HasInstance(nsIXPConnectWrappedNative *wrapper,
JSContext *cx, JSObject *obj,
const jsval &val, bool *bp, bool *_retval)
HandleValue val, bool *bp, bool *_retval)
{
RootedValue v(cx, val);
if (bp)
*bp = JSValIsInterfaceOfType(cx, v, NS_GET_IID(nsIJSID));
*bp = JSValIsInterfaceOfType(cx, val, NS_GET_IID(nsIJSID));
return NS_OK;
}
@ -1962,7 +1961,7 @@ nsXPCComponents_Exception::CallOrConstruct(nsIXPConnectWrappedNative *wrapper,
NS_IMETHODIMP
nsXPCComponents_Exception::HasInstance(nsIXPConnectWrappedNative *wrapper,
JSContext * cx, JSObject * obj,
const jsval &val, bool *bp,
HandleValue val, bool *bp,
bool *_retval)
{
using namespace mozilla::dom;
@ -2565,13 +2564,12 @@ nsXPCComponents_Constructor::CallOrConstruct(nsIXPConnectWrappedNative *wrapper,
/* bool hasInstance (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in jsval val, out bool bp); */
NS_IMETHODIMP
nsXPCComponents_Constructor::HasInstance(nsIXPConnectWrappedNative *wrapper,
JSContext * cx, JSObject * obj,
const jsval &val, bool *bp,
JSContext *cx, JSObject *obj,
HandleValue val, bool *bp,
bool *_retval)
{
RootedValue v(cx, val);
if (bp)
*bp = JSValIsInterfaceOfType(cx, v, NS_GET_IID(nsIXPCConstructor));
*bp = JSValIsInterfaceOfType(cx, val, NS_GET_IID(nsIXPCConstructor));
return NS_OK;
}
@ -2624,10 +2622,8 @@ nsXPCComponents_Utils::GetSandbox(nsIXPCComponents_utils_Sandbox **aSandbox)
/* void reportError (); */
NS_IMETHODIMP
nsXPCComponents_Utils::ReportError(const Value &errorArg, JSContext *cx)
nsXPCComponents_Utils::ReportError(HandleValue error, JSContext *cx)
{
RootedValue error(cx, errorArg);
// This function shall never fail! Silently eat any failure conditions.
nsCOMPtr<nsIConsoleService> console(do_GetService(NS_CONSOLESERVICE_CONTRACTID));
@ -2697,16 +2693,14 @@ nsXPCComponents_Utils::ReportError(const Value &errorArg, JSContext *cx)
/* void evalInSandbox(in AString source, in nativeobj sandbox); */
NS_IMETHODIMP
nsXPCComponents_Utils::EvalInSandbox(const nsAString& source,
const Value& sandboxValArg,
const Value& versionArg,
const Value& filenameVal,
HandleValue sandboxVal,
HandleValue version,
HandleValue filenameVal,
int32_t lineNumber,
JSContext *cx,
uint8_t optionalArgc,
Value *retval)
MutableHandleValue retval)
{
RootedValue sandboxVal(cx, sandboxValArg);
RootedValue version(cx, versionArg);
RootedObject sandbox(cx);
if (!JS_ValueToObject(cx, sandboxVal, &sandbox) || !sandbox)
return NS_ERROR_INVALID_ARG;
@ -2738,8 +2732,7 @@ nsXPCComponents_Utils::EvalInSandbox(const nsAString& source,
nsXPIDLCString filename;
int32_t lineNo = (optionalArgc >= 3) ? lineNumber : 1;
if (optionalArgc >= 2) {
RootedValue value(cx, filenameVal);
JSString *filenameStr = ToString(cx, value);
JSString *filenameStr = ToString(cx, filenameVal);
if (!filenameStr)
return NS_ERROR_INVALID_ARG;
@ -2761,17 +2754,13 @@ nsXPCComponents_Utils::EvalInSandbox(const nsAString& source,
}
}
RootedValue rval(cx);
nsresult rv = xpc::EvalInSandbox(cx, sandbox, source, filename.get(), lineNo,
jsVersion, false, &rval);
NS_ENSURE_SUCCESS(rv, rv);
*retval = rval;
return NS_OK;
return xpc::EvalInSandbox(cx, sandbox, source, filename.get(), lineNo,
jsVersion, false, retval);
}
NS_IMETHODIMP
nsXPCComponents_Utils::GetSandboxMetadata(const Value &sandboxVal,
JSContext *cx, Value *rval)
nsXPCComponents_Utils::GetSandboxMetadata(HandleValue sandboxVal,
JSContext *cx, MutableHandleValue rval)
{
if (!sandboxVal.isObject())
return NS_ERROR_INVALID_ARG;
@ -2781,17 +2770,12 @@ nsXPCComponents_Utils::GetSandboxMetadata(const Value &sandboxVal,
if (!sandbox || !xpc::IsSandbox(sandbox))
return NS_ERROR_INVALID_ARG;
RootedValue metadata(cx);
nsresult rv = xpc::GetSandboxMetadata(cx, sandbox, &metadata);
NS_ENSURE_SUCCESS(rv, rv);
*rval = metadata;
return NS_OK;
return xpc::GetSandboxMetadata(cx, sandbox, rval);
}
NS_IMETHODIMP
nsXPCComponents_Utils::SetSandboxMetadata(const Value &sandboxVal,
const Value &metadataVal,
nsXPCComponents_Utils::SetSandboxMetadata(HandleValue sandboxVal,
HandleValue metadataVal,
JSContext *cx)
{
if (!sandboxVal.isObject())
@ -2802,8 +2786,7 @@ nsXPCComponents_Utils::SetSandboxMetadata(const Value &sandboxVal,
if (!sandbox || !xpc::IsSandbox(sandbox))
return NS_ERROR_INVALID_ARG;
RootedValue metadata(cx, metadataVal);
nsresult rv = xpc::SetSandboxMetadata(cx, sandbox, metadata);
nsresult rv = xpc::SetSandboxMetadata(cx, sandbox, metadataVal);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
@ -2814,10 +2797,10 @@ nsXPCComponents_Utils::SetSandboxMetadata(const Value &sandboxVal,
*/
NS_IMETHODIMP
nsXPCComponents_Utils::Import(const nsACString& registryLocation,
const Value& targetObj,
HandleValue targetObj,
JSContext* cx,
uint8_t optionalArgc,
Value* retval)
MutableHandleValue retval)
{
nsCOMPtr<xpcIJSModuleLoader> moduleloader =
do_GetService(MOZJSCOMPONENTLOADER_CONTRACTID);
@ -2842,7 +2825,7 @@ nsXPCComponents_Utils::Unload(const nsACString & registryLocation)
* JSObject importGlobalProperties (in jsval aPropertyList);
*/
NS_IMETHODIMP
nsXPCComponents_Utils::ImportGlobalProperties(const JS::Value& aPropertyList,
nsXPCComponents_Utils::ImportGlobalProperties(HandleValue aPropertyList,
JSContext* cx)
{
RootedObject global(cx, CurrentGlobalOrNull(cx));
@ -2862,7 +2845,7 @@ nsXPCComponents_Utils::ImportGlobalProperties(const JS::Value& aPropertyList,
/* xpcIJSWeakReference getWeakReference (); */
NS_IMETHODIMP
nsXPCComponents_Utils::GetWeakReference(const Value &object, JSContext *cx,
nsXPCComponents_Utils::GetWeakReference(HandleValue object, JSContext *cx,
xpcIJSWeakReference **_retval)
{
nsRefPtr<xpcJSWeakReference> ref = new xpcJSWeakReference();
@ -2951,41 +2934,41 @@ nsXPCComponents_Utils::SchedulePreciseShrinkingGC(ScheduledGCCallback* aCallback
/* [implicit_jscontext] jsval nondeterministicGetWeakMapKeys(in jsval aMap); */
NS_IMETHODIMP
nsXPCComponents_Utils::NondeterministicGetWeakMapKeys(const Value &aMap,
nsXPCComponents_Utils::NondeterministicGetWeakMapKeys(HandleValue aMap,
JSContext *aCx,
Value *aKeys)
MutableHandleValue aKeys)
{
if (!aMap.isObject()) {
aKeys->setUndefined();
aKeys.setUndefined();
return NS_OK;
}
RootedObject objRet(aCx);
if (!JS_NondeterministicGetWeakMapKeys(aCx, &aMap.toObject(), objRet.address()))
return NS_ERROR_OUT_OF_MEMORY;
*aKeys = objRet ? ObjectValue(*objRet) : UndefinedValue();
aKeys.set(objRet ? ObjectValue(*objRet) : UndefinedValue());
return NS_OK;
}
/* void getDebugObject(); */
NS_IMETHODIMP
nsXPCComponents_Utils::GetJSTestingFunctions(JSContext *cx,
Value *retval)
MutableHandleValue retval)
{
JSObject *obj = js::GetTestingFunctions(cx);
if (!obj)
return NS_ERROR_XPC_JAVASCRIPT_ERROR;
*retval = OBJECT_TO_JSVAL(obj);
retval.setObject(*obj);
return NS_OK;
}
/* void getGlobalForObject(); */
NS_IMETHODIMP
nsXPCComponents_Utils::GetGlobalForObject(const Value& object,
nsXPCComponents_Utils::GetGlobalForObject(HandleValue object,
JSContext *cx,
Value *retval)
MutableHandleValue retval)
{
// First argument must be an object.
if (JSVAL_IS_PRIMITIVE(object))
if (object.isPrimitive())
return NS_ERROR_XPC_BAD_CONVERT_JS;
// Wrappers are parented to their the global in their home compartment. But
@ -2993,7 +2976,7 @@ nsXPCComponents_Utils::GetGlobalForObject(const Value& object,
// a wrapper for the foreign global. So we need to unwrap before getting the
// parent, enter the compartment for the duration of the call, and wrap the
// result.
Rooted<JSObject*> obj(cx, JSVAL_TO_OBJECT(object));
Rooted<JSObject*> obj(cx, &object.toObject());
obj = js::UncheckedUnwrap(obj);
{
JSAutoCompartment ac(cx, obj);
@ -3003,12 +2986,11 @@ nsXPCComponents_Utils::GetGlobalForObject(const Value& object,
if (!JS_WrapObject(cx, &obj))
return NS_ERROR_FAILURE;
*retval = OBJECT_TO_JSVAL(obj);
// Outerize if necessary.
if (JSObjectOp outerize = js::GetObjectClass(obj)->ext.outerObject)
*retval = OBJECT_TO_JSVAL(outerize(cx, obj));
obj = outerize(cx, obj);
retval.setObject(*obj);
return NS_OK;
}
@ -3059,7 +3041,7 @@ xpc::CreateObjectIn(JSContext *cx, HandleValue vobj, CreateObjectInOptions &opti
/* boolean isProxy(in value vobj); */
NS_IMETHODIMP
nsXPCComponents_Utils::IsProxy(const Value &vobj, JSContext *cx, bool *rval)
nsXPCComponents_Utils::IsProxy(HandleValue vobj, JSContext *cx, bool *rval)
{
if (!vobj.isObject()) {
*rval = false;
@ -3076,40 +3058,33 @@ nsXPCComponents_Utils::IsProxy(const Value &vobj, JSContext *cx, bool *rval)
/* jsval evalInWindow(in string source, in jsval window); */
NS_IMETHODIMP
nsXPCComponents_Utils::EvalInWindow(const nsAString &source, const Value &window,
JSContext *cx, Value *rval)
nsXPCComponents_Utils::EvalInWindow(const nsAString &source, HandleValue window,
JSContext *cx, MutableHandleValue rval)
{
if (!window.isObject())
return NS_ERROR_INVALID_ARG;
RootedObject rwindow(cx, &window.toObject());
RootedValue res(cx);
if (!xpc::EvalInWindow(cx, source, rwindow, &res))
if (!xpc::EvalInWindow(cx, source, rwindow, rval))
return NS_ERROR_FAILURE;
*rval = res;
return NS_OK;
}
/* jsval exportFunction(in jsval vfunction, in jsval vscope, in jsval vname); */
NS_IMETHODIMP
nsXPCComponents_Utils::ExportFunction(const Value &vfunction, const Value &vscope,
const Value &voptions, JSContext *cx, Value *rval)
nsXPCComponents_Utils::ExportFunction(HandleValue vfunction, HandleValue vscope,
HandleValue voptions, JSContext *cx,
MutableHandleValue rval)
{
RootedValue rfunction(cx, vfunction);
RootedValue rscope(cx, vscope);
RootedValue roptions(cx, voptions);
RootedValue res(cx);
if (!xpc::ExportFunction(cx, rfunction, rscope, roptions, &res))
if (!xpc::ExportFunction(cx, vfunction, vscope, voptions, rval))
return NS_ERROR_FAILURE;
*rval = res;
return NS_OK;
}
/* jsval createObjectIn(in jsval vobj, [optional] in jsval voptions); */
NS_IMETHODIMP
nsXPCComponents_Utils::CreateObjectIn(const Value &vobj, const Value &voptions,
JSContext *cx, Value *rval)
nsXPCComponents_Utils::CreateObjectIn(HandleValue vobj, HandleValue voptions,
JSContext *cx, MutableHandleValue rval)
{
RootedObject optionsObject(cx, voptions.isObject() ? &voptions.toObject()
: nullptr);
@ -3120,18 +3095,15 @@ nsXPCComponents_Utils::CreateObjectIn(const Value &vobj, const Value &voptions,
return NS_ERROR_FAILURE;
}
RootedValue rvobj(cx, vobj);
RootedValue res(cx);
if (!xpc::CreateObjectIn(cx, rvobj, options, &res))
if (!xpc::CreateObjectIn(cx, vobj, options, rval))
return NS_ERROR_FAILURE;
*rval = res;
return NS_OK;
}
/* jsval createObjectIn(in jsval vobj); */
NS_IMETHODIMP
nsXPCComponents_Utils::CreateArrayIn(const Value &vobj, JSContext *cx, Value *rval)
nsXPCComponents_Utils::CreateArrayIn(HandleValue vobj, JSContext *cx,
MutableHandleValue rval)
{
if (!cx)
return NS_ERROR_FAILURE;
@ -3152,13 +3124,14 @@ nsXPCComponents_Utils::CreateArrayIn(const Value &vobj, JSContext *cx, Value *rv
if (!JS_WrapObject(cx, &obj))
return NS_ERROR_FAILURE;
*rval = ObjectValue(*obj);
rval.setObject(*obj);
return NS_OK;
}
/* jsval createDateIn(in jsval vobj, in long long msec); */
NS_IMETHODIMP
nsXPCComponents_Utils::CreateDateIn(const Value &vobj, int64_t msec, JSContext *cx, Value *rval)
nsXPCComponents_Utils::CreateDateIn(HandleValue vobj, int64_t msec, JSContext *cx,
MutableHandleValue rval)
{
if (!cx)
return NS_ERROR_FAILURE;
@ -3179,13 +3152,13 @@ nsXPCComponents_Utils::CreateDateIn(const Value &vobj, int64_t msec, JSContext *
if (!JS_WrapObject(cx, &obj))
return NS_ERROR_FAILURE;
*rval = ObjectValue(*obj);
rval.setObject(*obj);
return NS_OK;
}
/* void makeObjectPropsNormal(jsval vobj); */
NS_IMETHODIMP
nsXPCComponents_Utils::MakeObjectPropsNormal(const Value &vobj, JSContext *cx)
nsXPCComponents_Utils::MakeObjectPropsNormal(HandleValue vobj, JSContext *cx)
{
if (!cx)
return NS_ERROR_FAILURE;
@ -3225,22 +3198,22 @@ nsXPCComponents_Utils::MakeObjectPropsNormal(const Value &vobj, JSContext *cx)
}
NS_IMETHODIMP
nsXPCComponents_Utils::IsDeadWrapper(const jsval &obj, bool *out)
nsXPCComponents_Utils::IsDeadWrapper(HandleValue obj, bool *out)
{
*out = false;
if (JSVAL_IS_PRIMITIVE(obj))
if (obj.isPrimitive())
return NS_ERROR_INVALID_ARG;
// Make sure to unwrap first. Once a proxy is nuked, it ceases to be a
// wrapper, meaning that, if passed to another compartment, we'll generate
// a CCW for it. Make sure that IsDeadWrapper sees through the confusion.
*out = JS_IsDeadWrapper(js::CheckedUnwrap(JSVAL_TO_OBJECT(obj)));
*out = JS_IsDeadWrapper(js::CheckedUnwrap(&obj.toObject()));
return NS_OK;
}
/* void recomputerWrappers(jsval vobj); */
NS_IMETHODIMP
nsXPCComponents_Utils::RecomputeWrappers(const jsval &vobj, JSContext *cx)
nsXPCComponents_Utils::RecomputeWrappers(HandleValue vobj, JSContext *cx)
{
// Determine the compartment of the given object, if any.
JSCompartment *c = vobj.isObject()
@ -3260,7 +3233,7 @@ nsXPCComponents_Utils::RecomputeWrappers(const jsval &vobj, JSContext *cx)
/* jsval setWantXrays(jsval vscope); */
NS_IMETHODIMP
nsXPCComponents_Utils::SetWantXrays(const jsval &vscope, JSContext *cx)
nsXPCComponents_Utils::SetWantXrays(HandleValue vscope, JSContext *cx)
{
if (!vscope.isObject())
return NS_ERROR_INVALID_ARG;
@ -3275,8 +3248,8 @@ nsXPCComponents_Utils::SetWantXrays(const jsval &vscope, JSContext *cx)
/* jsval getComponentsForScope(jsval vscope); */
NS_IMETHODIMP
nsXPCComponents_Utils::GetComponentsForScope(const jsval &vscope, JSContext *cx,
jsval *rval)
nsXPCComponents_Utils::GetComponentsForScope(HandleValue vscope, JSContext *cx,
MutableHandleValue rval)
{
if (!vscope.isObject())
return NS_ERROR_INVALID_ARG;
@ -3287,17 +3260,17 @@ nsXPCComponents_Utils::GetComponentsForScope(const jsval &vscope, JSContext *cx,
return NS_ERROR_FAILURE;
if (!JS_WrapObject(cx, &components))
return NS_ERROR_FAILURE;
*rval = ObjectValue(*components);
rval.setObject(*components);
return NS_OK;
}
NS_IMETHODIMP
nsXPCComponents_Utils::Dispatch(const jsval &runnableArg, const jsval &scope,
nsXPCComponents_Utils::Dispatch(HandleValue runnableArg, HandleValue scope,
JSContext *cx)
{
// Enter the given compartment, if any, and rewrap runnable.
Maybe<JSAutoCompartment> ac;
RootedValue runnable(cx, runnableArg);
Maybe<JSAutoCompartment> ac;
if (scope.isObject()) {
JSObject *scopeObj = js::UncheckedUnwrap(&scope.toObject());
if (!scopeObj)
@ -3388,7 +3361,7 @@ nsXPCComponents_Utils::SetGCZeal(int32_t aValue, JSContext* cx)
}
NS_IMETHODIMP
nsXPCComponents_Utils::NukeSandbox(const Value &obj, JSContext *cx)
nsXPCComponents_Utils::NukeSandbox(HandleValue obj, JSContext *cx)
{
NS_ENSURE_TRUE(obj.isObject(), NS_ERROR_INVALID_ARG);
JSObject *wrapper = &obj.toObject();
@ -3402,7 +3375,7 @@ nsXPCComponents_Utils::NukeSandbox(const Value &obj, JSContext *cx)
}
NS_IMETHODIMP
nsXPCComponents_Utils::BlockScriptForGlobal(const JS::Value &globalArg,
nsXPCComponents_Utils::BlockScriptForGlobal(HandleValue globalArg,
JSContext *cx)
{
NS_ENSURE_TRUE(globalArg.isObject(), NS_ERROR_INVALID_ARG);
@ -3418,7 +3391,7 @@ nsXPCComponents_Utils::BlockScriptForGlobal(const JS::Value &globalArg,
}
NS_IMETHODIMP
nsXPCComponents_Utils::UnblockScriptForGlobal(const JS::Value &globalArg,
nsXPCComponents_Utils::UnblockScriptForGlobal(HandleValue globalArg,
JSContext *cx)
{
NS_ENSURE_TRUE(globalArg.isObject(), NS_ERROR_INVALID_ARG);
@ -3434,7 +3407,7 @@ nsXPCComponents_Utils::UnblockScriptForGlobal(const JS::Value &globalArg,
}
NS_IMETHODIMP
nsXPCComponents_Utils::IsXrayWrapper(const Value &obj, bool* aRetval)
nsXPCComponents_Utils::IsXrayWrapper(HandleValue obj, bool* aRetval)
{
*aRetval =
obj.isObject() && xpc::WrapperFactory::IsXrayWrapper(&obj.toObject());
@ -3442,32 +3415,32 @@ nsXPCComponents_Utils::IsXrayWrapper(const Value &obj, bool* aRetval)
}
NS_IMETHODIMP
nsXPCComponents_Utils::WaiveXrays(const Value &aVal, JSContext *aCx, jsval *aRetval)
nsXPCComponents_Utils::WaiveXrays(HandleValue aVal, JSContext *aCx, MutableHandleValue aRetval)
{
RootedValue value(aCx, aVal);
if (!xpc::WrapperFactory::WaiveXrayAndWrap(aCx, &value))
return NS_ERROR_FAILURE;
*aRetval = value;
aRetval.set(value);
return NS_OK;
}
NS_IMETHODIMP
nsXPCComponents_Utils::UnwaiveXrays(const Value &aVal, JSContext *aCx, jsval *aRetval)
nsXPCComponents_Utils::UnwaiveXrays(HandleValue aVal, JSContext *aCx, MutableHandleValue aRetval)
{
if (!aVal.isObject()) {
*aRetval = aVal;
aRetval.set(aVal);
return NS_OK;
}
RootedObject obj(aCx, js::UncheckedUnwrap(&aVal.toObject()));
if (!JS_WrapObject(aCx, &obj))
return NS_ERROR_FAILURE;
*aRetval = ObjectValue(*obj);
aRetval.setObject(*obj);
return NS_OK;
}
NS_IMETHODIMP
nsXPCComponents_Utils::GetClassName(const Value &aObj, bool aUnwrap, JSContext *aCx, char **aRv)
nsXPCComponents_Utils::GetClassName(HandleValue aObj, bool aUnwrap, JSContext *aCx, char **aRv)
{
if (!aObj.isObject())
return NS_ERROR_INVALID_ARG;
@ -3488,8 +3461,8 @@ nsXPCComponents_Utils::GetDOMClassInfo(const nsAString& aClassName,
}
NS_IMETHODIMP
nsXPCComponents_Utils::GetIncumbentGlobal(const Value &aCallback,
JSContext *aCx, Value *aOut)
nsXPCComponents_Utils::GetIncumbentGlobal(HandleValue aCallback,
JSContext *aCx, MutableHandleValue aOut)
{
nsCOMPtr<nsIGlobalObject> global = mozilla::dom::GetIncumbentGlobal();
RootedValue globalVal(aCx);
@ -3510,7 +3483,7 @@ nsXPCComponents_Utils::GetIncumbentGlobal(const Value &aCallback,
return NS_ERROR_FAILURE;
}
*aOut = globalVal;
aOut.set(globalVal);
return NS_OK;
}
@ -3535,7 +3508,7 @@ class WrappedJSHolder : public nsISupports
NS_IMPL_ISUPPORTS0(WrappedJSHolder);
NS_IMETHODIMP
nsXPCComponents_Utils::GenerateXPCWrappedJS(const Value &aObj, const Value &aScope,
nsXPCComponents_Utils::GenerateXPCWrappedJS(HandleValue aObj, HandleValue aScope,
JSContext *aCx, nsISupports **aOut)
{
if (!aObj.isObject())
@ -3886,7 +3859,7 @@ nsXPCComponents::AttachComponentsObject(JSContext* aCx,
}
/* void reportError (); */
NS_IMETHODIMP nsXPCComponents::ReportError(const Value &error, JSContext *cx)
NS_IMETHODIMP nsXPCComponents::ReportError(HandleValue error, JSContext *cx)
{
NS_WARNING("Components.reportError deprecated, use Components.utils.reportError");

View File

@ -546,15 +546,15 @@ xpc::HasInstance(JSContext *cx, HandleObject objArg, const nsID *iid, bool *bp)
NS_IMETHODIMP
nsJSIID::HasInstance(nsIXPConnectWrappedNative *wrapper,
JSContext * cx, JSObject * /* unused */,
const jsval &val, bool *bp, bool *_retval)
HandleValue val, bool *bp, bool *_retval)
{
*bp = false;
if (JSVAL_IS_PRIMITIVE(val))
if (val.isPrimitive())
return NS_OK;
// we have a JSObject
RootedObject obj(cx, JSVAL_TO_OBJECT(val));
RootedObject obj(cx, &val.toObject());
const nsIID* iid;
mInfo->GetIIDShared(&iid);
@ -721,8 +721,8 @@ GetWrapperObject(MutableHandleObject obj)
/* nsISupports createInstance (); */
NS_IMETHODIMP
nsJSCID::CreateInstance(const JS::Value& iidval, JSContext* cx,
uint8_t optionalArgc, JS::Value* retval)
nsJSCID::CreateInstance(HandleValue iidval, JSContext* cx,
uint8_t optionalArgc, MutableHandleValue retval)
{
if (!mDetails.IsValid())
return NS_ERROR_XPC_BAD_CID;
@ -757,15 +757,15 @@ nsJSCID::CreateInstance(const JS::Value& iidval, JSContext* cx,
return NS_ERROR_XPC_CI_RETURNED_FAILURE;
rv = nsXPConnect::XPConnect()->WrapNativeToJSVal(cx, obj, inst, nullptr, iid, true, retval);
if (NS_FAILED(rv) || JSVAL_IS_PRIMITIVE(*retval))
if (NS_FAILED(rv) || retval.isPrimitive())
return NS_ERROR_XPC_CANT_CREATE_WN;
return NS_OK;
}
/* nsISupports getService (); */
NS_IMETHODIMP
nsJSCID::GetService(const JS::Value& iidval, JSContext* cx,
uint8_t optionalArgc, JS::Value* retval)
nsJSCID::GetService(HandleValue iidval, JSContext* cx,
uint8_t optionalArgc, MutableHandleValue retval)
{
if (!mDetails.IsValid())
return NS_ERROR_XPC_BAD_CID;
@ -808,7 +808,7 @@ nsJSCID::GetService(const JS::Value& iidval, JSContext* cx,
!(instJSObj = holder->GetJSObject()))
return NS_ERROR_XPC_CANT_CREATE_WN;
*retval = OBJECT_TO_JSVAL(instJSObj);
retval.setObject(*instJSObj);
return NS_OK;
}
@ -836,7 +836,7 @@ nsJSCID::Construct(nsIXPConnectWrappedNative *wrapper,
NS_IMETHODIMP
nsJSCID::HasInstance(nsIXPConnectWrappedNative *wrapper,
JSContext * cx, JSObject * /* unused */,
const jsval &val, bool *bp, bool *_retval)
HandleValue val, bool *bp, bool *_retval)
{
*bp = false;
nsresult rv = NS_OK;

View File

@ -53,9 +53,9 @@ nsresult xpcJSWeakReference::Init(JSContext* cx, const JS::Value& object)
}
NS_IMETHODIMP
xpcJSWeakReference::Get(JSContext* aCx, JS::Value* aRetval)
xpcJSWeakReference::Get(JSContext* aCx, MutableHandleValue aRetval)
{
*aRetval = JSVAL_NULL;
aRetval.setNull();
if (!mReferent) {
return NS_OK;
@ -71,12 +71,9 @@ xpcJSWeakReference::Get(JSContext* aCx, JS::Value* aRetval)
// We have a generic XPCOM object that supports weak references here.
// Wrap it and pass it out.
RootedObject global(aCx, CurrentGlobalOrNull(aCx));
RootedValue rval(aCx);
nsresult rv = nsContentUtils::WrapNative(aCx, global,
supports, &NS_GET_IID(nsISupports),
&rval);
*aRetval = rval;
return rv;
return nsContentUtils::WrapNative(aCx, global,
supports, &NS_GET_IID(nsISupports),
aRetval);
}
JS::RootedObject obj(aCx, wrappedObj->GetJSObject());
@ -93,6 +90,6 @@ xpcJSWeakReference::Get(JSContext* aCx, JS::Value* aRetval)
return NS_ERROR_FAILURE;
}
*aRetval = OBJECT_TO_JSVAL(obj);
aRetval.setObject(*obj);
return NS_OK;
}

View File

@ -586,7 +586,7 @@ Blob(JSContext *cx, unsigned argc, jsval *vp)
JSObject* global = JS::CurrentGlobalOrNull(cx);
rv = xpc->WrapNativeToJSVal(cx, global, native, nullptr,
&NS_GET_IID(nsISupports), true,
args.rval().address());
args.rval());
if (NS_FAILED(rv)) {
JS_ReportError(cx, "Could not wrap native object!");
return false;
@ -625,7 +625,7 @@ File(JSContext *cx, unsigned argc, jsval *vp)
JSObject* global = JS::CurrentGlobalOrNull(cx);
rv = xpc->WrapNativeToJSVal(cx, global, native, nullptr,
&NS_GET_IID(nsISupports), true,
args.rval().address());
args.rval());
if (NS_FAILED(rv)) {
JS_ReportError(cx, "Could not wrap native object!");
return false;

View File

@ -365,10 +365,9 @@ bool XPCVariant::InitializeData(JSContext* cx)
}
NS_IMETHODIMP
XPCVariant::GetAsJSVal(jsval* result)
XPCVariant::GetAsJSVal(MutableHandleValue result)
{
NS_PRECONDITION(result, "null result arg.");
*result = GetJSVal();
result.set(GetJSVal());
return NS_OK;
}
@ -384,7 +383,7 @@ XPCVariant::VariantDataToJS(nsIVariant* variant,
AutoJSContext cx;
RootedValue realVal(cx);
nsresult rv = variant->GetAsJSVal(realVal.address());
nsresult rv = variant->GetAsJSVal(&realVal);
if (NS_SUCCEEDED(rv) &&
(JSVAL_IS_PRIMITIVE(realVal) ||

View File

@ -579,19 +579,15 @@ nsXPConnect::WrapNativeToJSVal(JSContext * aJSContext,
nsWrapperCache *aCache,
const nsIID * aIID,
bool aAllowWrapping,
jsval *aVal)
MutableHandleValue aVal)
{
MOZ_ASSERT(aJSContext, "bad param");
MOZ_ASSERT(aScopeArg, "bad param");
MOZ_ASSERT(aCOMObj, "bad param");
RootedObject aScope(aJSContext, aScopeArg);
RootedValue rval(aJSContext);
nsresult rv = NativeInterface2JSObject(aScope, aCOMObj, aCache, aIID,
aAllowWrapping, &rval, nullptr);
*aVal = rval;
return rv;
return NativeInterface2JSObject(aScope, aCOMObj, aCache, aIID,
aAllowWrapping, aVal, nullptr);
}
/* void wrapJS (in JSContextPtr aJSContext, in JSObjectPtr aJSObj, in nsIIDRef aIID, [iid_is (aIID), retval] out nsQIResult result); */
@ -619,13 +615,12 @@ nsXPConnect::WrapJS(JSContext * aJSContext,
NS_IMETHODIMP
nsXPConnect::JSValToVariant(JSContext *cx,
jsval *aJSVal,
HandleValue aJSVal,
nsIVariant ** aResult)
{
NS_PRECONDITION(aJSVal, "bad param");
NS_PRECONDITION(aResult, "bad param");
*aResult = XPCVariant::newVariant(cx, *aJSVal);
*aResult = XPCVariant::newVariant(cx, aJSVal);
NS_ENSURE_TRUE(*aResult, NS_ERROR_OUT_OF_MEMORY);
return NS_OK;
@ -897,19 +892,15 @@ nsXPConnect::CreateSandbox(JSContext *cx, nsIPrincipal *principal,
NS_IMETHODIMP
nsXPConnect::EvalInSandboxObject(const nsAString& source, const char *filename,
JSContext *cx, JSObject *sandboxArg,
bool returnStringOnly, JS::Value *rvalArg)
bool returnStringOnly, MutableHandleValue rval)
{
if (!sandboxArg)
return NS_ERROR_INVALID_ARG;
RootedObject sandbox(cx, sandboxArg);
RootedValue rval(cx);
nsresult rv = EvalInSandbox(cx, sandbox, source, filename ? filename :
"x-bogus://XPConnect/Sandbox", 1, JSVERSION_DEFAULT,
returnStringOnly, &rval);
NS_ENSURE_SUCCESS(rv, rv);
*rvalArg = rval;
return NS_OK;
return EvalInSandbox(cx, sandbox, source, filename ? filename :
"x-bogus://XPConnect/Sandbox", 1, JSVERSION_DEFAULT,
returnStringOnly, rval);
}
/* nsIXPConnectJSObjectHolder getWrappedNativePrototype (in JSContextPtr aJSContext, in JSObjectPtr aScope, in nsIClassInfo aClassInfo); */
@ -1055,32 +1046,28 @@ nsXPConnect::DebugDumpEvalInJSStackFrame(uint32_t aFrameNumber, const char *aSou
/* jsval variantToJS (in JSContextPtr ctx, in JSObjectPtr scope, in nsIVariant value); */
NS_IMETHODIMP
nsXPConnect::VariantToJS(JSContext* ctx, JSObject* scopeArg, nsIVariant* value,
jsval* _retval)
MutableHandleValue _retval)
{
NS_PRECONDITION(ctx, "bad param");
NS_PRECONDITION(scopeArg, "bad param");
NS_PRECONDITION(value, "bad param");
NS_PRECONDITION(_retval, "bad param");
RootedObject scope(ctx, scopeArg);
MOZ_ASSERT(js::IsObjectInContextCompartment(scope, ctx));
nsresult rv = NS_OK;
RootedValue rval(ctx);
if (!XPCVariant::VariantDataToJS(value, &rv, &rval)) {
if (!XPCVariant::VariantDataToJS(value, &rv, _retval)) {
if (NS_FAILED(rv))
return rv;
return NS_ERROR_FAILURE;
}
*_retval = rval;
return NS_OK;
}
/* nsIVariant JSToVariant (in JSContextPtr ctx, in jsval value); */
NS_IMETHODIMP
nsXPConnect::JSToVariant(JSContext* ctx, const jsval &value, nsIVariant** _retval)
nsXPConnect::JSToVariant(JSContext* ctx, HandleValue value, nsIVariant** _retval)
{
NS_PRECONDITION(ctx, "bad param");
NS_PRECONDITION(_retval, "bad param");
@ -1418,7 +1405,7 @@ nsXPConnect::SetDebugModeWhenPossible(bool mode, bool allowSyncDisable)
}
NS_IMETHODIMP
nsXPConnect::GetTelemetryValue(JSContext *cx, jsval *rval)
nsXPConnect::GetTelemetryValue(JSContext *cx, MutableHandleValue rval)
{
RootedObject obj(cx, JS_NewObject(cx, nullptr, nullptr, nullptr));
if (!obj)
@ -1436,7 +1423,7 @@ nsXPConnect::GetTelemetryValue(JSContext *cx, jsval *rval)
if (!JS_DefineProperty(cx, obj, "customIter", v, nullptr, nullptr, attrs))
return NS_ERROR_OUT_OF_MEMORY;
*rval = OBJECT_TO_JSVAL(obj);
rval.setObject(*obj);
return NS_OK;
}

View File

@ -613,8 +613,8 @@ def outParamForm(name, type):
return '&' + name
elif type.kind == 'native':
if getBuiltinOrNativeTypeName(type) == '[jsval]':
return name + '.address()'
elif type.modifier == 'ref':
return '&' + name
if type.modifier == 'ref':
return name
else:
return '&' + name

View File

@ -197,11 +197,13 @@ NS_IMETHODIMP nsXPCTestParams::TestACString(const nsACString & a, nsACString & b
STRING_METHOD_IMPL;
}
/* jsval testJsval (in jsval a, inout jsval b); */
NS_IMETHODIMP nsXPCTestParams::TestJsval(const jsval & a, jsval & b, jsval *_retval)
/* jsval testJsval (in jsval a, in jsval b); */
NS_IMETHODIMP nsXPCTestParams::TestJsval(JS::Handle<JS::Value> a,
JS::MutableHandle<JS::Value> b,
JS::MutableHandle<JS::Value> _retval)
{
*_retval = b;
b = a;
_retval.set(b);
b.set(a);
return NS_OK;
}

View File

@ -282,8 +282,7 @@ WrapperFactory::PrepareForWrapping(JSContext *cx, HandleObject scope,
RootedValue v(cx);
nsresult rv =
nsXPConnect::XPConnect()->WrapNativeToJSVal(cx, wrapScope, wn->Native(), nullptr,
&NS_GET_IID(nsISupports), false,
v.address());
&NS_GET_IID(nsISupports), false, &v);
NS_ENSURE_SUCCESS(rv, nullptr);
obj = JSVAL_TO_OBJECT(v);