Bug 925916 - Handlify various things in XPConnect, r=bholley

--HG--
extra : rebase_source : d6b2697f043d56e6c96e5addc7e6192d067a068c
This commit is contained in:
Steve Fink 2013-10-11 22:02:39 -07:00
parent 06dbe4a13d
commit 98a2217207
19 changed files with 232 additions and 193 deletions

View File

@ -31,8 +31,8 @@ nsTArrayToJSArray(JSContext* aCx, const nsTArray<T>& aSourceArray,
nsresult rv = aSourceArray[index]->QueryInterface(NS_GET_IID(nsISupports), getter_AddRefs(obj));
NS_ENSURE_SUCCESS(rv, rv);
JS::Rooted<JS::Value> wrappedVal(aCx);
rv = nsContentUtils::WrapNative(aCx, global, obj, wrappedVal.address(),
JS::RootedValue wrappedVal(aCx);
rv = nsContentUtils::WrapNative(aCx, global, obj, &wrappedVal,
nullptr, true);
NS_ENSURE_SUCCESS(rv, rv);

View File

@ -186,6 +186,8 @@ SandboxImport(JSContext *cx, unsigned argc, Value *vp)
static bool
CreateXMLHttpRequest(JSContext *cx, unsigned argc, jsval *vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
nsIScriptSecurityManager *ssm = XPCWrapper::GetSecurityManager();
if (!ssm)
return false;
@ -206,7 +208,7 @@ CreateXMLHttpRequest(JSContext *cx, unsigned argc, jsval *vp)
if (NS_FAILED(rv))
return false;
rv = nsContentUtils::WrapNative(cx, global, xhr, vp);
rv = nsContentUtils::WrapNative(cx, global, xhr, args.rval());
if (NS_FAILED(rv))
return false;

View File

@ -95,34 +95,33 @@ XPCConvert::GetISupportsFromJSObject(JSObject* obj, nsISupports** iface)
// static
bool
XPCConvert::NativeData2JS(jsval* d, const void* s,
XPCConvert::NativeData2JS(MutableHandleValue d, const void* s,
const nsXPTType& type, const nsID* iid, nsresult* pErr)
{
NS_PRECONDITION(s, "bad param");
NS_PRECONDITION(d, "bad param");
AutoJSContext cx;
if (pErr)
*pErr = NS_ERROR_XPC_BAD_CONVERT_NATIVE;
switch (type.TagPart()) {
case nsXPTType::T_I8 : *d = INT_TO_JSVAL(int32_t(*((int8_t*)s))); break;
case nsXPTType::T_I16 : *d = INT_TO_JSVAL(int32_t(*((int16_t*)s))); break;
case nsXPTType::T_I32 : *d = INT_TO_JSVAL(*((int32_t*)s)); break;
case nsXPTType::T_I64 : *d = DOUBLE_TO_JSVAL(double(*((int64_t*)s))); break;
case nsXPTType::T_U8 : *d = INT_TO_JSVAL(int32_t(*((uint8_t*)s))); break;
case nsXPTType::T_U16 : *d = INT_TO_JSVAL(int32_t(*((uint16_t*)s))); break;
case nsXPTType::T_U32 : *d = UINT_TO_JSVAL(*((uint32_t*)s)); break;
case nsXPTType::T_U64 : *d = DOUBLE_TO_JSVAL(double(*((uint64_t*)s))); break;
case nsXPTType::T_FLOAT : *d = DOUBLE_TO_JSVAL(*((float*)s)); break;
case nsXPTType::T_DOUBLE: *d = DOUBLE_TO_JSVAL(*((double*)s)); break;
case nsXPTType::T_I8 : d.setInt32(*((int8_t*)s)); break;
case nsXPTType::T_I16 : d.setInt32(*((int16_t*)s)); break;
case nsXPTType::T_I32 : d.setInt32(*((int32_t*)s)); break;
case nsXPTType::T_I64 : d.setNumber(double(*((int64_t*)s))); break;
case nsXPTType::T_U8 : d.setInt32(*((uint8_t*)s)); break;
case nsXPTType::T_U16 : d.setInt32(*((uint16_t*)s)); break;
case nsXPTType::T_U32 : d.setNumber(*((uint32_t*)s)); break;
case nsXPTType::T_U64 : d.setNumber(double(*((uint64_t*)s))); break;
case nsXPTType::T_FLOAT : d.setNumber(*((float*)s)); break;
case nsXPTType::T_DOUBLE: d.setNumber(*((double*)s)); break;
case nsXPTType::T_BOOL :
{
bool b = *((bool*)s);
NS_WARN_IF_FALSE(b == 1 || b == 0,
"Passing a malformed bool through XPConnect");
*d = BOOLEAN_TO_JSVAL(!!b);
d.setBoolean(b);
break;
}
case nsXPTType::T_CHAR :
@ -138,7 +137,7 @@ XPCConvert::NativeData2JS(jsval* d, const void* s,
JSString* str;
if (!(str = JS_NewStringCopyN(cx, p, 1)))
return false;
*d = STRING_TO_JSVAL(str);
d.setString(str);
break;
}
case nsXPTType::T_WCHAR :
@ -149,14 +148,14 @@ XPCConvert::NativeData2JS(jsval* d, const void* s,
JSString* str;
if (!(str = JS_NewUCStringCopyN(cx, p, 1)))
return false;
*d = STRING_TO_JSVAL(str);
d.setString(str);
break;
}
case nsXPTType::T_JSVAL :
{
*d = *((jsval*)s);
if (!JS_WrapValue(cx, d))
d.set(*((Value*)s));
if (!JS_WrapValue(cx, d.address()))
return false;
break;
}
@ -164,7 +163,7 @@ XPCConvert::NativeData2JS(jsval* d, const void* s,
default:
// set the default result
*d = JSVAL_NULL;
d.setNull();
switch (type.TagPart()) {
case nsXPTType::T_VOID:
@ -180,7 +179,7 @@ XPCConvert::NativeData2JS(jsval* d, const void* s,
JSObject* obj;
if (!(obj = xpc_NewIDObject(cx, scope, *iid2)))
return false;
*d = OBJECT_TO_JSVAL(obj);
d.setObject(*obj);
break;
}
@ -201,7 +200,7 @@ XPCConvert::NativeData2JS(jsval* d, const void* s,
if (buf)
buf->AddRef();
*d = str;
d.set(str);
}
// *d is defaulted to JSVAL_NULL so no need to set it
@ -228,7 +227,7 @@ XPCConvert::NativeData2JS(jsval* d, const void* s,
JSString* str;
if (!(str = JS_NewStringCopyZ(cx, p)))
return false;
*d = STRING_TO_JSVAL(str);
d.setString(str);
break;
}
@ -240,7 +239,7 @@ XPCConvert::NativeData2JS(jsval* d, const void* s,
JSString* str;
if (!(str = JS_NewUCStringCopyZ(cx, p)))
return false;
*d = STRING_TO_JSVAL(str);
d.setString(str);
break;
}
case nsXPTType::T_UTF8STRING:
@ -251,7 +250,7 @@ XPCConvert::NativeData2JS(jsval* d, const void* s,
break;
if (utf8String->IsEmpty()) {
*d = JS_GetEmptyStringValue(cx);
d.set(JS_GetEmptyStringValue(cx));
break;
}
@ -285,7 +284,7 @@ XPCConvert::NativeData2JS(jsval* d, const void* s,
return false;
}
*d = STRING_TO_JSVAL(str);
d.setString(str);
break;
}
case nsXPTType::T_CSTRING:
@ -296,7 +295,7 @@ XPCConvert::NativeData2JS(jsval* d, const void* s,
break;
if (cString->IsEmpty()) {
*d = JS_GetEmptyStringValue(cx);
d.set(JS_GetEmptyStringValue(cx));
break;
}
@ -308,7 +307,7 @@ XPCConvert::NativeData2JS(jsval* d, const void* s,
if (!str)
return false;
*d = STRING_TO_JSVAL(str);
d.setString(str);
break;
}
@ -332,7 +331,7 @@ XPCConvert::NativeData2JS(jsval* d, const void* s,
return false;
#ifdef DEBUG
JSObject* jsobj = JSVAL_TO_OBJECT(*d);
JSObject* jsobj = d.toObjectOrNull();
if (jsobj && !js::GetObjectParent(jsobj))
MOZ_ASSERT(js::GetObjectClass(jsobj)->flags & JSCLASS_IS_GLOBAL,
"Why did we recreate this wrapper?");
@ -771,7 +770,7 @@ XPCConvert::JSData2Native(void* d, HandleValue s,
}
static inline bool
CreateHolderIfNeeded(HandleObject obj, jsval* d,
CreateHolderIfNeeded(HandleObject obj, MutableHandleValue d,
nsIXPConnectJSObjectHolder** dest)
{
if (dest) {
@ -782,7 +781,7 @@ CreateHolderIfNeeded(HandleObject obj, jsval* d,
NS_ADDREF(*dest = objHolder);
}
*d = OBJECT_TO_JSVAL(obj);
d.setObjectOrNull(obj);
return true;
}
@ -790,7 +789,7 @@ CreateHolderIfNeeded(HandleObject obj, jsval* d,
/***************************************************************************/
// static
bool
XPCConvert::NativeInterface2JSObject(jsval* d,
XPCConvert::NativeInterface2JSObject(MutableHandleValue d,
nsIXPConnectJSObjectHolder** dest,
xpcObjectHelper& aHelper,
const nsID* iid,
@ -802,7 +801,7 @@ XPCConvert::NativeInterface2JSObject(jsval* d,
if (!iid)
iid = &NS_GET_IID(nsISupports);
*d = JSVAL_NULL;
d.setNull();
if (dest)
*dest = nullptr;
if (!aHelper.Object())
@ -835,7 +834,7 @@ XPCConvert::NativeInterface2JSObject(jsval* d,
flat = cache->GetWrapper();
if (cache->IsDOMBinding()) {
if (!flat) {
JS::Rooted<JSObject*> global(cx, xpcscope->GetGlobalJSObject());
RootedObject global(cx, xpcscope->GetGlobalJSObject());
flat = cache->WrapObject(cx, global);
if (!flat)
return false;
@ -858,7 +857,7 @@ XPCConvert::NativeInterface2JSObject(jsval* d,
if (cpow) {
if (!JS_WrapObject(cx, &cpow))
return false;
*d = JS::ObjectValue(*cpow);
d.setObject(*cpow);
return true;
}
@ -920,7 +919,7 @@ XPCConvert::NativeInterface2JSObject(jsval* d,
flat = wrapper->GetFlatJSObject();
jsval v = OBJECT_TO_JSVAL(flat);
if (!allowNativeWrapper) {
*d = v;
d.set(v);
if (dest)
*dest = strongWrapper.forget().get();
if (pErr)
@ -934,7 +933,7 @@ XPCConvert::NativeInterface2JSObject(jsval* d,
if (!JS_WrapObject(cx, &flat))
return false;
*d = OBJECT_TO_JSVAL(flat);
d.setObjectOrNull(flat);
if (dest) {
// The strongWrapper still holds the original flat object.
@ -1343,12 +1342,11 @@ XPCConvert::JSErrorToXPCException(const char* message,
// static
bool
XPCConvert::NativeArray2JS(jsval* d, const void** s,
XPCConvert::NativeArray2JS(MutableHandleValue d, const void** s,
const nsXPTType& type, const nsID* iid,
uint32_t count, nsresult* pErr)
{
NS_PRECONDITION(s, "bad param");
NS_PRECONDITION(d, "bad param");
AutoJSContext cx;
@ -1369,7 +1367,7 @@ XPCConvert::NativeArray2JS(jsval* d, const void** s,
#define POPULATE(_t) \
PR_BEGIN_MACRO \
for (i = 0; i < count; i++) { \
if (!NativeData2JS(current.address(), ((_t*)*s)+i, type, iid, pErr) || \
if (!NativeData2JS(&current, ((_t*)*s)+i, type, iid, pErr) || \
!JS_SetElement(cx, array, i, &current)) \
goto failure; \
} \
@ -1406,7 +1404,7 @@ XPCConvert::NativeArray2JS(jsval* d, const void** s,
if (pErr)
*pErr = NS_OK;
*d = OBJECT_TO_JSVAL(array);
d.setObject(*array);
return true;
failure:
@ -1713,13 +1711,12 @@ failure:
// static
bool
XPCConvert::NativeStringWithSize2JS(jsval* d, const void* s,
XPCConvert::NativeStringWithSize2JS(MutableHandleValue d, const void* s,
const nsXPTType& type,
uint32_t count,
nsresult* pErr)
{
NS_PRECONDITION(s, "bad param");
NS_PRECONDITION(d, "bad param");
AutoJSContext cx;
if (pErr)
@ -1734,7 +1731,7 @@ XPCConvert::NativeStringWithSize2JS(jsval* d, const void* s,
JSString* str;
if (!(str = JS_NewStringCopyN(cx, p, count)))
return false;
*d = STRING_TO_JSVAL(str);
d.setString(str);
break;
}
case nsXPTType::T_PWSTRING_SIZE_IS:
@ -1745,7 +1742,7 @@ XPCConvert::NativeStringWithSize2JS(jsval* d, const void* s,
JSString* str;
if (!(str = JS_NewUCStringCopyN(cx, p, count)))
return false;
*d = STRING_TO_JSVAL(str);
d.setString(str);
break;
}
default:

View File

@ -8,6 +8,8 @@
#include "nsContentUtils.h"
using namespace JS;
xpcJSWeakReference::xpcJSWeakReference()
{
}
@ -69,10 +71,13 @@ xpcJSWeakReference::Get(JSContext* aCx, JS::Value* aRetval)
if (!wrappedObj) {
// We have a generic XPCOM object that supports weak references here.
// Wrap it and pass it out.
JS::Rooted<JSObject*> global(aCx, JS::CurrentGlobalOrNull(aCx));
return nsContentUtils::WrapNative(aCx, global,
supports, &NS_GET_IID(nsISupports),
aRetval);
RootedObject global(aCx, CurrentGlobalOrNull(aCx));
RootedValue rval(aCx);
nsresult rv = nsContentUtils::WrapNative(aCx, global,
supports, &NS_GET_IID(nsISupports),
&rval);
*aRetval = rval;
return rv;
}
JS::RootedObject obj(aCx, wrappedObj->GetJSObject());

View File

@ -413,13 +413,16 @@ xpc_qsGetterOnlyNativeStub(JSContext *cx, unsigned argc, jsval *vp)
JSMSG_GETTER_ONLY);
}
xpc_qsDOMString::xpc_qsDOMString(JSContext *cx, jsval v, jsval *pval,
xpc_qsDOMString::xpc_qsDOMString(JSContext *cx, HandleValue v,
MutableHandleValue pval, bool notpassed,
StringificationBehavior nullBehavior,
StringificationBehavior undefinedBehavior)
{
typedef implementation_type::char_traits traits;
// From the T_DOMSTRING case in XPCConvert::JSData2Native.
JSString *s = InitOrStringify<traits>(cx, v, pval, nullBehavior,
JSString *s = InitOrStringify<traits>(cx, v,
pval, notpassed,
nullBehavior,
undefinedBehavior);
if (!s)
return;
@ -435,13 +438,16 @@ xpc_qsDOMString::xpc_qsDOMString(JSContext *cx, jsval v, jsval *pval,
mValid = true;
}
xpc_qsACString::xpc_qsACString(JSContext *cx, jsval v, jsval *pval,
xpc_qsACString::xpc_qsACString(JSContext *cx, HandleValue v,
MutableHandleValue pval, bool notpassed,
StringificationBehavior nullBehavior,
StringificationBehavior undefinedBehavior)
{
typedef implementation_type::char_traits traits;
// From the T_CSTRING case in XPCConvert::JSData2Native.
JSString *s = InitOrStringify<traits>(cx, v, pval, nullBehavior,
JSString *s = InitOrStringify<traits>(cx, v,
pval, notpassed,
nullBehavior,
undefinedBehavior);
if (!s)
return;
@ -462,11 +468,11 @@ xpc_qsACString::xpc_qsACString(JSContext *cx, jsval v, jsval *pval,
mValid = true;
}
xpc_qsAUTF8String::xpc_qsAUTF8String(JSContext *cx, jsval v, jsval *pval)
xpc_qsAUTF8String::xpc_qsAUTF8String(JSContext *cx, HandleValue v, MutableHandleValue pval, bool notpassed)
{
typedef nsCharTraits<PRUnichar> traits;
// From the T_UTF8STRING case in XPCConvert::JSData2Native.
JSString *s = InitOrStringify<traits>(cx, v, pval, eNull, eNull);
JSString *s = InitOrStringify<traits>(cx, v, pval, notpassed, eNull, eNull);
if (!s)
return;
@ -574,12 +580,12 @@ castNative(JSContext *cx,
const nsIID &iid,
void **ppThis,
nsISupports **pThisRef,
jsval *vp)
MutableHandleValue vp)
{
RootedObject cur(cx, curArg);
if (wrapper) {
nsresult rv = getNativeFromWrapper(cx,wrapper, iid, ppThis, pThisRef,
vp);
vp.address());
if (rv != NS_ERROR_NO_INTERFACE)
return rv;
@ -590,7 +596,7 @@ castNative(JSContext *cx,
return NS_ERROR_ILLEGAL_VALUE;
}
if (NS_SUCCEEDED(getNative(native, cur, iid, ppThis, pThisRef, vp))) {
if (NS_SUCCEEDED(getNative(native, cur, iid, ppThis, pThisRef, vp.address()))) {
return NS_OK;
}
}
@ -606,7 +612,7 @@ castNativeFromWrapper(JSContext *cx,
uint32_t protoID,
int32_t protoDepth,
nsISupports **pRef,
jsval *pVal,
MutableHandleValue pVal,
nsresult *rv)
{
XPCWrappedNative *wrapper;
@ -644,7 +650,7 @@ castNativeFromWrapper(JSContext *cx,
if (native) {
*pRef = nullptr;
*pVal = OBJECT_TO_JSVAL(cur);
pVal.setObjectOrNull(cur);
*rv = NS_OK;
} else {
*rv = NS_ERROR_XPC_BAD_CONVERT_JS;
@ -673,11 +679,11 @@ xpc_qsUnwrapThisFromCcxImpl(XPCCallContext &ccx,
nsresult
xpc_qsUnwrapArgImpl(JSContext *cx,
jsval v,
HandleValue v,
const nsIID &iid,
void **ppArg,
nsISupports **ppArgRef,
jsval *vp)
MutableHandleValue vp)
{
nsresult rv;
RootedObject src(cx, xpc_qsUnwrapObj(v, ppArgRef, &rv));
@ -736,7 +742,7 @@ xpc_qsUnwrapArgImpl(JSContext *cx,
rv = wrappedJS->QueryInterface(iid, ppArg);
if (NS_SUCCEEDED(rv)) {
*ppArgRef = static_cast<nsISupports*>(*ppArg);
*vp = OBJECT_TO_JSVAL(wrappedJS->GetJSObject());
vp.setObjectOrNull(wrappedJS->GetJSObject());
}
return rv;
}
@ -785,13 +791,13 @@ xpc_qsJsvalToWcharStr(JSContext *cx, jsval v, jsval *pval, const PRUnichar **pst
namespace xpc {
bool
NonVoidStringToJsval(JSContext *cx, nsAString &str, JS::Value *rval)
NonVoidStringToJsval(JSContext *cx, nsAString &str, MutableHandleValue rval)
{
nsStringBuffer* sharedBuffer;
jsval jsstr = XPCStringConvert::ReadableToJSVal(cx, str, &sharedBuffer);
if (JSVAL_IS_NULL(jsstr))
return false;
*rval = jsstr;
rval.set(jsstr);
if (sharedBuffer) {
// The string was shared but ReadableToJSVal didn't addref it.
// Move the ownership from str to jsstr.
@ -827,7 +833,7 @@ xpc_qsStringToJsstring(JSContext *cx, nsString &str, JSString **rval)
bool
xpc_qsXPCOMObjectToJsval(JSContext *cx, qsObjectHelper &aHelper,
const nsIID *iid, XPCNativeInterface **iface,
jsval *rval)
MutableHandleValue rval)
{
NS_PRECONDITION(iface, "Who did that and why?");
@ -847,7 +853,7 @@ xpc_qsXPCOMObjectToJsval(JSContext *cx, qsObjectHelper &aHelper,
}
#ifdef DEBUG
JSObject* jsobj = JSVAL_TO_OBJECT(*rval);
JSObject* jsobj = rval.toObjectOrNull();
if (jsobj && !js::GetObjectParent(jsobj))
MOZ_ASSERT(js::GetObjectClass(jsobj)->flags & JSCLASS_IS_GLOBAL,
"Why did we recreate this wrapper?");
@ -859,7 +865,7 @@ xpc_qsXPCOMObjectToJsval(JSContext *cx, qsObjectHelper &aHelper,
bool
xpc_qsVariantToJsval(JSContext *aCx,
nsIVariant *p,
jsval *rval)
MutableHandleValue rval)
{
// From the T_INTERFACE case in XPCConvert::NativeData2JS.
// Error handling is in XPCWrappedNative::CallMethod.
@ -870,7 +876,7 @@ xpc_qsVariantToJsval(JSContext *aCx,
xpc_qsThrow(aCx, rv);
return ok;
}
*rval = JSVAL_NULL;
rval.setNull();
return true;
}

View File

@ -142,16 +142,16 @@ xpc_qsGetterOnlyNativeStub(JSContext *cx, unsigned argc, jsval *vp);
/* Functions for converting values between COM and JS. */
inline bool
xpc_qsInt64ToJsval(JSContext *cx, int64_t i, jsval *rv)
xpc_qsInt64ToJsval(JSContext *cx, int64_t i, JS::MutableHandleValue rv)
{
*rv = JS_NumberValue(static_cast<double>(i));
rv.setNumber(static_cast<double>(i));
return true;
}
inline bool
xpc_qsUint64ToJsval(JSContext *cx, uint64_t u, jsval *rv)
xpc_qsUint64ToJsval(JSContext *cx, uint64_t u, JS::MutableHandleValue rv)
{
*rv = JS_NumberValue(static_cast<double>(u));
rv.setNumber(static_cast<double>(u));
return true;
}
@ -235,7 +235,9 @@ protected:
* when |v| is JSVAL_IS_NULL and JSVAL_IS_VOID respectively.
*/
template<class traits>
JSString* InitOrStringify(JSContext* cx, jsval v, jsval* pval,
JSString* InitOrStringify(JSContext* cx, jsval v,
JS::MutableHandleValue pval,
bool notpassed,
StringificationBehavior nullBehavior,
StringificationBehavior undefinedBehavior) {
JSString *s;
@ -252,8 +254,8 @@ protected:
// If pval is null, that means the argument was optional and
// not passed; turn those into void strings if they're
// supposed to be stringified.
if (behavior != eStringify || !pval) {
// Here behavior == eStringify implies !pval, so both eNull and
if (behavior != eStringify || notpassed) {
// Here behavior == eStringify implies notpassed, so both eNull and
// eStringify should end up with void strings.
(new(mBuf) implementation_type(traits::sEmptyBuffer, uint32_t(0)))->
SetIsVoid(behavior != eEmpty);
@ -266,7 +268,7 @@ protected:
mValid = false;
return nullptr;
}
*pval = STRING_TO_JSVAL(s); // Root the new string.
pval.setString(s); // Root the new string.
}
return s;
@ -290,7 +292,8 @@ protected:
class xpc_qsDOMString : public xpc_qsBasicString<nsAString, nsDependentString>
{
public:
xpc_qsDOMString(JSContext *cx, jsval v, jsval *pval,
xpc_qsDOMString(JSContext *cx, JS::HandleValue v,
JS::MutableHandleValue pval, bool notpassed,
StringificationBehavior nullBehavior,
StringificationBehavior undefinedBehavior);
};
@ -302,8 +305,9 @@ public:
class xpc_qsAString : public xpc_qsDOMString
{
public:
xpc_qsAString(JSContext *cx, jsval v, jsval *pval)
: xpc_qsDOMString(cx, v, pval, eNull, eNull)
xpc_qsAString(JSContext *cx, JS::HandleValue v,
JS::MutableHandleValue pval, bool notpassed)
: xpc_qsDOMString(cx, v, pval, notpassed, eNull, eNull)
{}
};
@ -314,9 +318,10 @@ public:
class xpc_qsACString : public xpc_qsBasicString<nsACString, nsCString>
{
public:
xpc_qsACString(JSContext *cx, jsval v, jsval *pval,
StringificationBehavior nullBehavior = eNull,
StringificationBehavior undefinedBehavior = eNull);
xpc_qsACString(JSContext *cx, JS::HandleValue v,
JS::MutableHandleValue pval, bool notpassed,
StringificationBehavior nullBehavior,
StringificationBehavior undefinedBehavior);
};
/**
@ -326,7 +331,8 @@ class xpc_qsAUTF8String :
public xpc_qsBasicString<nsACString, NS_ConvertUTF16toUTF8>
{
public:
xpc_qsAUTF8String(JSContext* cx, jsval v, jsval *pval);
xpc_qsAUTF8String(JSContext* cx, JS::HandleValue v,
JS::MutableHandleValue pval, bool notpassed);
};
struct xpc_qsSelfRef
@ -353,7 +359,7 @@ bool
xpc_qsJsvalToCharStr(JSContext *cx, jsval v, JSAutoByteString *bytes);
bool
xpc_qsJsvalToWcharStr(JSContext *cx, jsval v, jsval *pval, const PRUnichar **pstr);
xpc_qsJsvalToWcharStr(JSContext *cx, jsval v, JS::MutableHandleValue pval, const PRUnichar **pstr);
/** Convert an nsString to JSString, returning true on success. This will sometimes modify |str| to be empty. */
@ -375,7 +381,7 @@ castNative(JSContext *cx,
const nsIID &iid,
void **ppThis,
nsISupports **ppThisRef,
jsval *vp);
JS::MutableHandleValue vp);
/**
* Search @a obj and its prototype chain for an XPCOM object that implements
@ -399,7 +405,7 @@ xpc_qsUnwrapThis(JSContext *cx,
JS::HandleObject obj,
T **ppThis,
nsISupports **pThisRef,
jsval *pThisVal,
JS::MutableHandleValue pThisVal,
bool failureFatal = true)
{
XPCWrappedNative *wrapper;
@ -425,7 +431,7 @@ castNativeFromWrapper(JSContext *cx,
uint32_t protoID,
int32_t protoDepth,
nsISupports **pRef,
jsval *pVal,
JS::MutableHandleValue pVal,
nsresult *rv);
bool
@ -433,7 +439,7 @@ xpc_qsUnwrapThisFromCcxImpl(XPCCallContext &ccx,
const nsIID &iid,
void **ppThis,
nsISupports **pThisRef,
jsval *vp);
JS::MutableHandleValue vp);
/**
* Alternate implementation of xpc_qsUnwrapThis using information already
@ -444,7 +450,7 @@ inline bool
xpc_qsUnwrapThisFromCcx(XPCCallContext &ccx,
T **ppThis,
nsISupports **pThisRef,
jsval *pThisVal)
JS::MutableHandleValue pThisVal)
{
return xpc_qsUnwrapThisFromCcxImpl(ccx,
NS_GET_TEMPLATE_IID(T),
@ -472,14 +478,14 @@ xpc_qsUnwrapObj(jsval v, nsISupports **ppArgRef, nsresult *rv)
}
nsresult
xpc_qsUnwrapArgImpl(JSContext *cx, jsval v, const nsIID &iid, void **ppArg,
nsISupports **ppArgRef, jsval *vp);
xpc_qsUnwrapArgImpl(JSContext *cx, JS::HandleValue v, const nsIID &iid, void **ppArg,
nsISupports **ppArgRef, JS::MutableHandleValue vp);
/** Convert a jsval to an XPCOM pointer. */
template <class Interface, class StrongRefType>
inline nsresult
xpc_qsUnwrapArg(JSContext *cx, jsval v, Interface **ppArg,
StrongRefType **ppArgRef, jsval *vp)
xpc_qsUnwrapArg(JSContext *cx, JS::HandleValue v, Interface **ppArg,
StrongRefType **ppArgRef, JS::MutableHandleValue vp)
{
nsISupports* argRef = *ppArgRef;
nsresult rv = xpc_qsUnwrapArgImpl(cx, v, NS_GET_TEMPLATE_IID(Interface),
@ -496,7 +502,7 @@ castNativeArgFromWrapper(JSContext *cx,
uint32_t protoID,
int32_t protoDepth,
nsISupports **pArgRef,
jsval *vp,
JS::MutableHandleValue vp,
nsresult *rv)
{
JSObject *src = xpc_qsUnwrapObj(v, pArgRef, rv);
@ -533,7 +539,7 @@ xpc_qsXPCOMObjectToJsval(JSContext *aCx,
qsObjectHelper &aHelper,
const nsIID *iid,
XPCNativeInterface **iface,
jsval *rval);
JS::MutableHandleValue rval);
/**
* Convert a variant to jsval. Return true on success.
@ -541,7 +547,7 @@ xpc_qsXPCOMObjectToJsval(JSContext *aCx,
bool
xpc_qsVariantToJsval(JSContext *cx,
nsIVariant *p,
jsval *rval);
JS::MutableHandleValue rval);
#ifdef DEBUG
void

View File

@ -71,7 +71,7 @@ XPCStringConvert::ReadableToJSVal(JSContext *cx,
if (buf) {
JS::RootedValue val(cx);
bool shared;
bool ok = StringBufferToJSVal(cx, buf, length, val.address(), &shared);
bool ok = StringBufferToJSVal(cx, buf, length, &val, &shared);
if (!ok) {
return JS::NullValue();
}

View File

@ -375,7 +375,7 @@ XPCVariant::GetAsJSVal(jsval* result)
// static
bool
XPCVariant::VariantDataToJS(nsIVariant* variant,
nsresult* pErr, jsval* pJSVal)
nsresult* pErr, MutableHandleValue pJSVal)
{
// Get the type early because we might need to spoof it below.
uint16_t type;
@ -393,7 +393,7 @@ XPCVariant::VariantDataToJS(nsIVariant* variant,
type == nsIDataType::VTYPE_ID)) {
if (!JS_WrapValue(cx, realVal.address()))
return false;
*pJSVal = realVal;
pJSVal.set(realVal);
return true;
}
@ -405,7 +405,7 @@ XPCVariant::VariantDataToJS(nsIVariant* variant,
if (!JS_WrapValue(cx, realVal.address()))
return false;
*pJSVal = realVal;
pJSVal.set(realVal);
return true;
}
@ -436,7 +436,7 @@ XPCVariant::VariantDataToJS(nsIVariant* variant,
double d;
if (NS_FAILED(variant->GetAsDouble(&d)))
return false;
*pJSVal = JS_NumberValue(d);
pJSVal.setNumber(d);
return true;
}
case nsIDataType::VTYPE_BOOL:
@ -444,7 +444,7 @@ XPCVariant::VariantDataToJS(nsIVariant* variant,
bool b;
if (NS_FAILED(variant->GetAsBool(&b)))
return false;
*pJSVal = BOOLEAN_TO_JSVAL(b);
pJSVal.setBoolean(b);
return true;
}
case nsIDataType::VTYPE_CHAR:
@ -647,14 +647,14 @@ VARIANT_DONE:
JSObject* array = JS_NewArrayObject(cx, 0, nullptr);
if (!array)
return false;
*pJSVal = OBJECT_TO_JSVAL(array);
pJSVal.setObject(*array);
return true;
}
case nsIDataType::VTYPE_VOID:
*pJSVal = JSVAL_VOID;
pJSVal.setUndefined();
return true;
case nsIDataType::VTYPE_EMPTY:
*pJSVal = JSVAL_NULL;
pJSVal.setNull();
return true;
default:
NS_ERROR("bad type in variant!");

View File

@ -1230,7 +1230,7 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16_t methodIndex,
xpcObjectHelper helper(newThis);
bool ok =
XPCConvert::NativeInterface2JSObject(
v.address(), nullptr, helper, nullptr,
&v, nullptr, helper, nullptr,
nullptr, false, nullptr);
if (!ok) {
goto pre_call_clean_up;
@ -1317,19 +1317,19 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16_t methodIndex,
}
if (isArray) {
if (!XPCConvert::NativeArray2JS(val.address(),
if (!XPCConvert::NativeArray2JS(&val,
(const void**)&pv->val,
datum_type, &param_iid,
array_count, nullptr))
goto pre_call_clean_up;
} else if (isSizedString) {
if (!XPCConvert::NativeStringWithSize2JS(val.address(),
if (!XPCConvert::NativeStringWithSize2JS(&val,
(const void*)&pv->val,
datum_type,
array_count, nullptr))
goto pre_call_clean_up;
} else {
if (!XPCConvert::NativeData2JS(val.address(), &pv->val, type,
if (!XPCConvert::NativeData2JS(&val, &pv->val, type,
&param_iid, nullptr))
goto pre_call_clean_up;
}

View File

@ -2318,7 +2318,7 @@ CallMethodHelper::GatherAndConvertResults()
nsresult err;
if (isArray) {
if (!XPCConvert::NativeArray2JS(v.address(), (const void**)&dp->val,
if (!XPCConvert::NativeArray2JS(&v, (const void**)&dp->val,
datum_type, &param_iid,
array_count, &err)) {
// XXX need exception scheme for arrays to indicate bad element
@ -2326,7 +2326,7 @@ CallMethodHelper::GatherAndConvertResults()
return false;
}
} else if (isSizedString) {
if (!XPCConvert::NativeStringWithSize2JS(v.address(),
if (!XPCConvert::NativeStringWithSize2JS(&v,
(const void*)&dp->val,
datum_type,
array_count, &err)) {
@ -2334,7 +2334,7 @@ CallMethodHelper::GatherAndConvertResults()
return false;
}
} else {
if (!XPCConvert::NativeData2JS(v.address(), &dp->val, datum_type,
if (!XPCConvert::NativeData2JS(&v, &dp->val, datum_type,
&param_iid, &err)) {
ThrowBadParam(err, i, mCallContext);
return false;
@ -2397,7 +2397,7 @@ CallMethodHelper::QueryInterfaceFastPath() const
RootedValue v(mCallContext, NullValue());
nsresult err;
bool success =
XPCConvert::NativeData2JS(v.address(), &qiresult,
XPCConvert::NativeData2JS(&v, &qiresult,
nsXPTType::T_INTERFACE_IS,
iid, &err);
NS_IF_RELEASE(qiresult);

View File

@ -65,8 +65,7 @@ XPCNativeMember::Resolve(XPCCallContext& ccx, XPCNativeInterface* iface,
RootedValue resultVal(ccx);
if (!XPCConvert::NativeData2JS(resultVal.address(), &v.val, v.type,
nullptr, nullptr))
if (!XPCConvert::NativeData2JS(&resultVal, &v.val, v.type, nullptr, nullptr))
return false;
*vp = resultVal;

View File

@ -309,9 +309,9 @@ def write_getter(a, iface, fd):
fd.write(" aDict.%s = (float) d;\n" % a.name)
elif realtype.count("nsAString"):
if a.nullable:
fd.write(" xpc_qsDOMString d(aCx, v, v.address(), xpc_qsDOMString::eNull, xpc_qsDOMString::eNull);\n")
fd.write(" xpc_qsDOMString d(aCx, v, &v, false, xpc_qsDOMString::eNull, xpc_qsDOMString::eNull);\n")
else:
fd.write(" xpc_qsDOMString d(aCx, v, v.address(), xpc_qsDOMString::eStringify, xpc_qsDOMString::eStringify);\n")
fd.write(" xpc_qsDOMString d(aCx, v, &v, false, xpc_qsDOMString::eStringify, xpc_qsDOMString::eStringify);\n")
fd.write(" NS_ENSURE_STATE(d.IsValid());\n")
fd.write(" aDict.%s = d;\n" % a.name)
elif realtype.count("nsIVariant"):
@ -321,7 +321,7 @@ def write_getter(a, iface, fd):
elif realtype.endswith('*'):
fd.write(" %s d;\n" % realtype)
fd.write(" xpc_qsSelfRef ref;\n")
fd.write(" nsresult rv = xpc_qsUnwrapArg<%s>(aCx, v, &d, &ref.ptr, v.address());\n" % realtype.strip('* '))
fd.write(" nsresult rv = xpc_qsUnwrapArg<%s>(aCx, v, &d, &ref.ptr, &v);\n" % realtype.strip('* '))
fd.write(" NS_ENSURE_SUCCESS(rv, rv);\n")
fd.write(" aDict.%s = d;\n" % a.name)
elif not realtype.count("JS::Value"):

View File

@ -315,7 +315,7 @@ def writeAttributeGetter(fd, classname, a):
fd.write("{\n")
fd.write(" JS::Rooted<JS::Value> retVal(aCx, JS::NullValue());\n");
fd.write(" nsresult rv = NS_ERROR_UNEXPECTED;\n")
fd.write(" if (m%s && !XPCVariant::VariantDataToJS(m%s, &rv, retVal.address())) {\n" % (firstCap(a.name), firstCap(a.name)))
fd.write(" if (m%s && !XPCVariant::VariantDataToJS(m%s, &rv, &retVal)) {\n" % (firstCap(a.name), firstCap(a.name)))
fd.write(" aRv.Throw(NS_ERROR_FAILURE);\n")
fd.write(" }\n")
fd.write(" return retVal;\n");

View File

@ -67,7 +67,7 @@ xpc_qsUnwrapThis<_interface>(JSContext *cx, \
JS::HandleObject obj, \
_interface **ppThis, \
nsISupports **pThisRef, \
jsval *pThisVal, \
JS::MutableHandleValue pThisVal, \
bool failureFatal) \
{ \
nsresult rv; \
@ -86,10 +86,10 @@ xpc_qsUnwrapThis<_interface>(JSContext *cx, \
template <> \
MOZ_ALWAYS_INLINE nsresult \
xpc_qsUnwrapArg<_interface>(JSContext *cx, \
jsval v, \
JS::HandleValue v, \
_interface **ppArg, \
nsISupports **ppArgRef, \
jsval *vp) \
JS::MutableHandleValue vp) \
{ \
nsresult rv; \
nsISupports *native = \
@ -105,10 +105,10 @@ xpc_qsUnwrapArg<_interface>(JSContext *cx, \
template <> \
inline nsresult \
xpc_qsUnwrapArg<_interface>(JSContext *cx, \
jsval v, \
JS::HandleValue v, \
_interface **ppArg, \
_interface **ppArgRef, \
jsval *vp) \
JS::MutableHandleValue vp) \
{ \
nsISupports* argRef = static_cast<_base*>(*ppArgRef); \
nsresult rv = xpc_qsUnwrapArg<_interface>(cx, v, ppArg, &argRef, vp); \
@ -122,10 +122,10 @@ namespace dom { \
template <> \
MOZ_ALWAYS_INLINE nsresult \
UnwrapArg<_interface>(JSContext *cx, \
jsval v, \
JS::HandleValue v, \
_interface **ppArg, \
nsISupports **ppArgRef, \
jsval *vp) \
JS::MutableHandleValue vp) \
{ \
return xpc_qsUnwrapArg<_interface>(cx, v, ppArg, ppArgRef, vp); \
} \
@ -133,10 +133,10 @@ UnwrapArg<_interface>(JSContext *cx, \
template <> \
inline nsresult \
UnwrapArg<_interface>(JSContext *cx, \
jsval v, \
JS::HandleValue v, \
_interface **ppArg, \
_interface **ppArgRef, \
jsval *vp) \
JS::MutableHandleValue vp) \
{ \
return xpc_qsUnwrapArg<_interface>(cx, v, ppArg, ppArgRef, vp); \
} \
@ -156,20 +156,20 @@ DOMCI_CASTABLE_INTERFACES(unused)
inline nsresult
xpc_qsUnwrapArg_HTMLElement(JSContext *cx,
jsval v,
JS::HandleValue v,
nsIAtom *aTag,
nsIContent **ppArg,
nsISupports **ppArgRef,
jsval *vp)
JS::MutableHandleValue vp)
{
nsGenericHTMLElement *elem;
jsval val;
JS::RootedValue val(cx);
nsresult rv =
xpc_qsUnwrapArg<nsGenericHTMLElement>(cx, v, &elem, ppArgRef, &val);
if (NS_SUCCEEDED(rv)) {
if (elem->IsHTML(aTag)) {
*ppArg = elem;
*vp = val;
vp.set(val);
} else {
rv = NS_ERROR_XPC_BAD_CONVERT_JS;
}
@ -181,10 +181,10 @@ xpc_qsUnwrapArg_HTMLElement(JSContext *cx,
template <> \
inline nsresult \
xpc_qsUnwrapArg<_clazz>(JSContext *cx, \
jsval v, \
JS::HandleValue v, \
_clazz **ppArg, \
nsISupports **ppArgRef, \
jsval *vp) \
JS::MutableHandleValue vp) \
{ \
nsIContent *elem; \
nsresult rv = xpc_qsUnwrapArg_HTMLElement(cx, v, nsGkAtoms::_tag, &elem, \
@ -196,8 +196,8 @@ xpc_qsUnwrapArg<_clazz>(JSContext *cx, \
\
template <> \
inline nsresult \
xpc_qsUnwrapArg<_clazz>(JSContext *cx, jsval v, _clazz **ppArg, \
_clazz **ppArgRef, jsval *vp) \
xpc_qsUnwrapArg<_clazz>(JSContext *cx, JS::HandleValue v, _clazz **ppArg, \
_clazz **ppArgRef, JS::MutableHandleValue vp) \
{ \
nsISupports* argRef = static_cast<nsIContent*>(*ppArgRef); \
nsresult rv = xpc_qsUnwrapArg<_clazz>(cx, v, ppArg, &argRef, vp); \
@ -211,18 +211,18 @@ namespace dom { \
template <> \
inline nsresult \
UnwrapArg<_clazz>(JSContext *cx, \
jsval v, \
JS::HandleValue v, \
_clazz **ppArg, \
nsISupports **ppArgRef, \
jsval *vp) \
JS::MutableHandleValue vp) \
{ \
return xpc_qsUnwrapArg<_clazz>(cx, v, ppArg, ppArgRef, vp); \
} \
\
template <> \
inline nsresult \
UnwrapArg<_clazz>(JSContext *cx, jsval v, _clazz **ppArg, \
_clazz **ppArgRef, jsval *vp) \
UnwrapArg<_clazz>(JSContext *cx, JS::HandleValue v, _clazz **ppArg, \
_clazz **ppArgRef, JS::MutableHandleValue vp) \
{ \
return xpc_qsUnwrapArg<_clazz>(cx, v, ppArg, ppArgRef, vp); \
} \

View File

@ -552,7 +552,7 @@ NativeInterface2JSObject(HandleObject aScope,
nsWrapperCache *aCache,
const nsIID * aIID,
bool aAllowWrapping,
jsval *aVal,
MutableHandleValue aVal,
nsIXPConnectJSObjectHolder **aHolder)
{
AutoJSContext cx;
@ -564,7 +564,7 @@ NativeInterface2JSObject(HandleObject aScope,
nullptr, aAllowWrapping, &rv))
return rv;
MOZ_ASSERT(aAllowWrapping || !xpc::WrapperFactory::IsXrayWrapper(JSVAL_TO_OBJECT(*aVal)),
MOZ_ASSERT(aAllowWrapping || !xpc::WrapperFactory::IsXrayWrapper(&aVal.toObject()),
"Shouldn't be returning a xray wrapper here");
return NS_OK;
@ -586,7 +586,7 @@ nsXPConnect::WrapNative(JSContext * aJSContext,
RootedObject aScope(aJSContext, aScopeArg);
RootedValue v(aJSContext);
return NativeInterface2JSObject(aScope, aCOMObj, nullptr, &aIID,
false, v.address(), aHolder);
false, &v, aHolder);
}
/* void wrapNativeToJSVal (in JSContextPtr aJSContext, in JSObjectPtr aScope, in nsISupports aCOMObj, in nsIIDPtr aIID, out jsval aVal, out nsIXPConnectJSObjectHolder aHolder); */
@ -609,8 +609,11 @@ nsXPConnect::WrapNativeToJSVal(JSContext * aJSContext,
RootedObject aScope(aJSContext, aScopeArg);
return NativeInterface2JSObject(aScope, aCOMObj, aCache, aIID,
aAllowWrapping, aVal, aHolder);
RootedValue rval(aJSContext);
nsresult rv = NativeInterface2JSObject(aScope, aCOMObj, aCache, aIID,
aAllowWrapping, &rval, aHolder);
*aVal = rval;
return rv;
}
/* void wrapJS (in JSContextPtr aJSContext, in JSObjectPtr aJSObj, in nsIIDRef aIID, [iid_is (aIID), retval] out nsQIResult result); */
@ -1099,13 +1102,15 @@ nsXPConnect::VariantToJS(JSContext* ctx, JSObject* scopeArg, nsIVariant* value,
MOZ_ASSERT(js::IsObjectInContextCompartment(scope, ctx));
nsresult rv = NS_OK;
if (!XPCVariant::VariantDataToJS(value, &rv, _retval)) {
RootedValue rval(ctx);
if (!XPCVariant::VariantDataToJS(value, &rv, &rval)) {
if (NS_FAILED(rv))
return rv;
return NS_ERROR_FAILURE;
}
*_retval = rval;
return NS_OK;
}
@ -1368,7 +1373,8 @@ Base64Encode(JSContext *cx, JS::Value val, JS::Value *out)
MOZ_ASSERT(out);
JS::RootedValue root(cx, val);
xpc_qsACString encodedString(cx, root, root.address(), xpc_qsACString::eNull,
xpc_qsACString encodedString(cx, root, &root, false,
xpc_qsACString::eNull,
xpc_qsACString::eStringify);
if (!encodedString.IsValid())
return false;
@ -1394,7 +1400,8 @@ Base64Decode(JSContext *cx, JS::Value val, JS::Value *out)
MOZ_ASSERT(out);
JS::RootedValue root(cx, val);
xpc_qsACString encodedString(cx, root, root.address(), xpc_qsACString::eNull,
xpc_qsACString encodedString(cx, root, &root, false,
xpc_qsACString::eNull,
xpc_qsACString::eNull);
if (!encodedString.IsValid())
return false;

View File

@ -437,12 +437,13 @@ argumentUnboxingTemplates = {
" JS_ValueToBoolean(cx, ${argVal}, &${name});\n",
'[astring]':
" xpc_qsAString ${name}(cx, ${argVal}, ${argPtr});\n"
" xpc_qsAString ${name}(cx, ${argVal}, ${argPtr}, ${notPassed});\n"
" if (!${name}.IsValid())\n"
" return false;\n",
'[domstring]':
" xpc_qsDOMString ${name}(cx, ${argVal}, ${argPtr},\n"
" xpc_qsDOMString ${name}(cx, ${argVal},\n"
" ${argPtr}, ${notPassed},\n"
" xpc_qsDOMString::e${nullBehavior},\n"
" xpc_qsDOMString::e${undefinedBehavior});\n"
" if (!${name}.IsValid())\n"
@ -460,12 +461,12 @@ argumentUnboxingTemplates = {
" return false;\n",
'[cstring]':
" xpc_qsACString ${name}(cx, ${argVal}, ${argPtr});\n"
" xpc_qsACString ${name}(cx, ${argVal}, ${argPtr}, ${notPassed});\n"
" if (!${name}.IsValid())\n"
" return false;\n",
'[utf8string]':
" xpc_qsAUTF8String ${name}(cx, ${argVal}, ${argPtr});\n"
" xpc_qsAUTF8String ${name}(cx, ${argVal}, ${argPtr}, ${notPassed});\n"
" if (!${name}.IsValid())\n"
" return false;\n",
@ -484,7 +485,7 @@ def writeArgumentUnboxing(f, i, name, type, optional, rvdeclared,
propIndex=None):
# f - file to write to
# i - int or None - Indicates the source jsval. If i is an int, the source
# jsval is argv[i]; otherwise it is argv[0]. But if Python i >= C++ argc,
# jsval is args[i]; otherwise it is args[0]. But if Python i >= C++ argc,
# which can only happen if optional is True, the argument is missing;
# use JSVAL_NULL as the source jsval instead.
# name - str - name of the native C++ variable to create.
@ -496,29 +497,42 @@ def writeArgumentUnboxing(f, i, name, type, optional, rvdeclared,
isSetter = (i is None)
notPassed = "false"
if isSetter:
argPtr = "argv[0].address()"
argVal = "argv[0]"
argPtr = "args[0]"
argVal = "args[0]"
elif optional:
if typeName == "[jsval]":
val = "JS::UndefinedHandleValue"
else:
val = "JS::NullHandleValue"
argVal = "(%d < argc ? argv[%d] : %s)" % (i, i, val)
argVal = "(%d < argc ? args[%d] : %s)" % (i, i, val)
if typeName == "[jsval]":
# This should use the rooted argument,
# however we probably won't ever need to support that.
argPtr = None
notPassed = None
else:
argPtr = "(%d < argc ? argv[%d].address() : NULL)" % (i, i)
# Need a MutableHandleValue to pass into eg the xpc_qsAString
# constructor, but the corresponding argument may not have been
# passed in at all. In that case, point the MutableHandleValue at a
# dummy variable, and pass in a boolean saying that the argument
# wasn't passed (previously, this used a NULL ptr sentinel value.)
f.write(" JS::RootedValue {name}_dummy(cx);\n".format(name=name))
f.write(" JS::MutableHandleValue {name}_mhv({i} < argc ? args[{i}] : &{name}_dummy);\n".format(name=name, i=i))
f.write(" (void) {name}_mhv;\n".format(name=name, i=i))
argPtr = "{name}_mhv".format(name=name)
notPassed = "argc < {i}".format(i=i)
else:
argVal = "argv[%d]" % i
argPtr = argVal + ".address()"
argVal = "args[%d]" % i
argPtr = "args[%d]" % i
params = {
'name': name,
'argVal': argVal,
'argPtr': argPtr,
'notPassed': notPassed,
'nullBehavior': nullBehavior or 'DefaultNullBehavior',
'undefinedBehavior': undefinedBehavior or 'DefaultUndefinedBehavior'
}
@ -565,9 +579,9 @@ def writeArgumentUnboxing(f, i, name, type, optional, rvdeclared,
warn("Unable to unbox argument of type %s (native type %s)" % (type.name, typeName))
if i is None:
src = 'argv[0]'
src = 'args[0]'
else:
src = 'argv[%d]' % i
src = 'args[%d]' % i
f.write(" !; // TODO - Unbox argument %s = %s\n" % (name, src))
return rvdeclared
@ -664,8 +678,8 @@ resultConvTemplates = {
" return xpc::StringToJsval(cx, result, ${jsvalPtr});\n",
'[jsval]':
" ${jsvalRef} = result;\n"
" return JS_WrapValue(cx, ${jsvalPtr});\n"
" ${jsvalPtr}.set(result);\n"
" return JS_WrapValue(cx, ${jsvalPtr}.address());\n"
}
def isVariantType(t):
@ -694,7 +708,7 @@ def writeResultConv(f, type, jsvalPtr, jsvalRef):
return
else:
f.write(" if (!result) {\n"
" *%s = JSVAL_NULL;\n"
" %s.setNull();\n"
" return true;\n"
" }\n"
" nsWrapperCache* cache = xpc_qsGetWrapperCache(result);\n"
@ -832,6 +846,10 @@ def writeQuickStub(f, customMethodCalls, stringtable, member, stubName,
f.write("{\n")
f.write(" XPC_QS_ASSERT_CONTEXT_OK(cx);\n")
# Compute "args".
f.write(" JS::CallArgs args = JS::CallArgsFromVp(argc, vp);\n")
f.write(" (void) args;\n")
# Compute "this".
f.write(" JS::RootedObject obj(cx, JS_THIS_OBJECT(cx, vp));\n"
" if (!obj)\n"
@ -843,7 +861,7 @@ def writeQuickStub(f, customMethodCalls, stringtable, member, stubName,
else:
f.write(" %s *self;\n" % customMethodCall['thisType'])
f.write(" xpc_qsSelfRef selfref;\n")
pthisval = '&vp[1]' # as above, ok to overwrite vp[1]
pthisval = 'JS::MutableHandleValue::fromMarkedLocation(&vp[1])' # as above, ok to overwrite vp[1]
if unwrapThisFailureFatal:
unwrapFatalArg = "true"
@ -857,7 +875,7 @@ def writeQuickStub(f, customMethodCalls, stringtable, member, stubName,
if not unwrapThisFailureFatal:
f.write(" if (!self) {\n")
if (isGetter):
f.write(" *vp = JSVAL_NULL;\n")
f.write(" args.rval().setNull();\n")
f.write(" return true;\n")
f.write(" }\n");
@ -878,8 +896,6 @@ def writeQuickStub(f, customMethodCalls, stringtable, member, stubName,
# Convert in-parameters.
rvdeclared = False
if isMethod:
if len(member.params) > 0:
f.write(" JS::CallArgs argv = JS::CallArgsFromVp(argc, vp);\n")
for i, param in enumerate(member.params):
argName = 'arg%d' % i
argTypeKey = argName + 'Type'
@ -897,7 +913,6 @@ def writeQuickStub(f, customMethodCalls, stringtable, member, stubName,
nullBehavior=param.null,
undefinedBehavior=param.undefined)
elif isSetter:
f.write(" JS::CallArgs argv = JS::CallArgsFromVp(argc, vp);\n")
rvdeclared = writeArgumentUnboxing(f, None, 'arg0', member.realtype,
optional=False,
rvdeclared=rvdeclared,
@ -982,7 +997,7 @@ def writeQuickStub(f, customMethodCalls, stringtable, member, stubName,
# Convert the return value.
if isMethod or isGetter:
writeResultConv(f, member.realtype, 'vp', '*vp')
writeResultConv(f, member.realtype, 'args.rval()', '*vp')
else:
f.write(" return true;\n")

View File

@ -2817,7 +2817,7 @@ public:
* @param pErr [out] relevant error code, if any.
*/
static bool NativeData2JS(jsval* d,
static bool NativeData2JS(JS::MutableHandleValue d,
const void* s, const nsXPTType& type,
const nsID* iid, nsresult* pErr);
@ -2841,7 +2841,7 @@ public:
* @param src_is_identity optional performance hint. Set to true only
* if src is the identity pointer.
*/
static bool NativeInterface2JSObject(jsval* d,
static bool NativeInterface2JSObject(JS::MutableHandleValue d,
nsIXPConnectJSObjectHolder** dest,
xpcObjectHelper& aHelper,
const nsID* iid,
@ -2869,7 +2869,7 @@ public:
* @param scope the default scope to put on the new JSObjects' parent chain
* @param pErr [out] relevant error code, if any.
*/
static bool NativeArray2JS(jsval* d, const void** s,
static bool NativeArray2JS(JS::MutableHandleValue d, const void** s,
const nsXPTType& type, const nsID* iid,
uint32_t count, nsresult* pErr);
@ -2883,7 +2883,7 @@ public:
const nsXPTType& type,
nsresult* pErr);
static bool NativeStringWithSize2JS(jsval* d, const void* s,
static bool NativeStringWithSize2JS(JS::MutableHandleValue d, const void* s,
const nsXPTType& type,
uint32_t count,
nsresult* pErr);
@ -3502,7 +3502,7 @@ public:
* @param pJSVal [out] the resulting jsval.
*/
static bool VariantDataToJS(nsIVariant* variant,
nsresult* pErr, jsval* pJSVal);
nsresult* pErr, JS::MutableHandleValue pJSVal);
bool IsPurple()
{

View File

@ -102,7 +102,7 @@ extern bool
xpc_OkToHandOutWrapper(nsWrapperCache *cache);
inline JSObject*
xpc_FastGetCachedWrapper(nsWrapperCache *cache, JSObject *scope, jsval *vp)
xpc_FastGetCachedWrapper(nsWrapperCache *cache, JSObject *scope, JS::MutableHandleValue vp)
{
if (cache) {
JSObject* wrapper = cache->GetWrapper();
@ -110,7 +110,7 @@ xpc_FastGetCachedWrapper(nsWrapperCache *cache, JSObject *scope, jsval *vp)
js::GetObjectCompartment(wrapper) == js::GetObjectCompartment(scope) &&
(cache->IsDOMBinding() ? !cache->HasSystemOnlyWrapper() :
xpc_OkToHandOutWrapper(cache))) {
*vp = OBJECT_TO_JSVAL(wrapper);
vp.setObject(*wrapper);
return wrapper;
}
}
@ -174,12 +174,12 @@ public:
// Convert the given stringbuffer/length pair to a jsval
static MOZ_ALWAYS_INLINE bool
StringBufferToJSVal(JSContext* cx, nsStringBuffer* buf, uint32_t length,
JS::Value* rval, bool* sharedBuffer)
JS::MutableHandleValue rval, bool* sharedBuffer)
{
if (buf == sCachedBuffer &&
JS::GetGCThingZone(sCachedString) == js::GetContextZone(cx))
{
*rval = JS::StringValue(sCachedString);
rval.set(JS::StringValue(sCachedString));
*sharedBuffer = false;
return true;
}
@ -190,7 +190,7 @@ public:
if (!str) {
return false;
}
*rval = JS::StringValue(str);
rval.setString(str);
sCachedString = str;
sCachedBuffer = buf;
*sharedBuffer = true;
@ -220,26 +220,26 @@ NS_EXPORT_(bool) Base64Decode(JSContext *cx, JS::Value val, JS::Value *out);
* Note, the ownership of the string buffer may be moved from str to rval.
* If that happens, str will point to an empty string after this call.
*/
bool NonVoidStringToJsval(JSContext *cx, nsAString &str, JS::Value *rval);
inline bool StringToJsval(JSContext *cx, nsAString &str, JS::Value *rval)
bool NonVoidStringToJsval(JSContext *cx, nsAString &str, JS::MutableHandleValue rval);
inline bool StringToJsval(JSContext *cx, nsAString &str, JS::MutableHandleValue rval)
{
// From the T_DOMSTRING case in XPCConvert::NativeData2JS.
if (str.IsVoid()) {
*rval = JSVAL_NULL;
rval.setNull();
return true;
}
return NonVoidStringToJsval(cx, str, rval);
}
inline bool
NonVoidStringToJsval(JSContext* cx, const nsAString& str, JS::Value *rval)
NonVoidStringToJsval(JSContext* cx, const nsAString& str, JS::MutableHandleValue rval)
{
nsString mutableCopy(str);
return NonVoidStringToJsval(cx, mutableCopy, rval);
}
inline bool
StringToJsval(JSContext* cx, const nsAString& str, JS::Value *rval)
StringToJsval(JSContext* cx, const nsAString& str, JS::MutableHandleValue rval)
{
nsString mutableCopy(str);
return StringToJsval(cx, mutableCopy, rval);
@ -250,7 +250,7 @@ StringToJsval(JSContext* cx, const nsAString& str, JS::Value *rval)
*/
MOZ_ALWAYS_INLINE
bool NonVoidStringToJsval(JSContext* cx, mozilla::dom::DOMString& str,
JS::Value *rval)
JS::MutableHandleValue rval)
{
if (!str.HasStringBuffer()) {
// It's an actual XPCOM string
@ -259,7 +259,7 @@ bool NonVoidStringToJsval(JSContext* cx, mozilla::dom::DOMString& str,
uint32_t length = str.StringBufferLength();
if (length == 0) {
*rval = JS_GetEmptyStringValue(cx);
rval.set(JS_GetEmptyStringValue(cx));
return true;
}
@ -278,10 +278,10 @@ bool NonVoidStringToJsval(JSContext* cx, mozilla::dom::DOMString& str,
MOZ_ALWAYS_INLINE
bool StringToJsval(JSContext* cx, mozilla::dom::DOMString& str,
JS::Value *rval)
JS::MutableHandleValue rval)
{
if (str.IsNull()) {
*rval = JS::NullValue();
rval.setNull();
return true;
}
return NonVoidStringToJsval(cx, str, rval);

View File

@ -1408,8 +1408,10 @@ XrayWrapper<Base, Traits>::getPropertyDescriptor(JSContext *cx, HandleObject wra
// we're set up (above) to cache (on the holder) anything that comes out of
// resolveNativeProperty, which we don't want for something dynamic like
// named access. So we just handle it separately here.
nsGlobalWindow *win;
if (!desc.object() && Traits::Type == XrayForWrappedNative && JSID_IS_STRING(id) &&
nsGlobalWindow *win = nullptr;
if (!desc.object() &&
(Traits::Type == XrayForWrappedNative) &&
JSID_IS_STRING(id) &&
(win = static_cast<nsGlobalWindow*>(As<nsPIDOMWindow>(wrapper))))
{
nsDependentJSString name(id);