Bug 785096 - part2: Removing XPCCallContext dependency from XPCVariant; r=bholley

This commit is contained in:
Gabor Krizsanits 2012-09-20 15:03:28 +02:00
Родитель ca6baf3206
Коммит dc6a0acf70
10 изменённых файлов: 126 добавлений и 99 удалений

Просмотреть файл

@ -365,15 +365,13 @@ bool ConvertToPrimitive(JSContext *cx, const JS::Value& v, T *retval)
// static // static
JSBool JSBool
XPCConvert::JSData2Native(XPCCallContext& ccx, void* d, jsval s, XPCConvert::JSData2Native(JSContext* cx, void* d, jsval s,
const nsXPTType& type, const nsXPTType& type,
JSBool useAllocator, const nsID* iid, JSBool useAllocator, const nsID* iid,
nsresult* pErr) nsresult* pErr)
{ {
NS_PRECONDITION(d, "bad param"); NS_PRECONDITION(d, "bad param");
JSContext* cx = ccx.GetJSContext();
JSBool isDOMString = true; JSBool isDOMString = true;
if (pErr) if (pErr)
@ -515,7 +513,7 @@ XPCConvert::JSData2Native(XPCCallContext& ccx, void* d, jsval s,
return false; return false;
XPCReadableJSStringWrapper *wrapper = XPCReadableJSStringWrapper *wrapper =
ccx.NewStringWrapper(strChars, strLength); nsXPConnect::GetRuntimeInstance()->NewStringWrapper(strChars, strLength);
if (!wrapper) if (!wrapper)
return false; return false;
@ -715,7 +713,7 @@ XPCConvert::JSData2Native(XPCCallContext& ccx, void* d, jsval s,
NS_ASSERTION(iid,"can't do interface conversions without iid"); NS_ASSERTION(iid,"can't do interface conversions without iid");
if (iid->Equals(NS_GET_IID(nsIVariant))) { if (iid->Equals(NS_GET_IID(nsIVariant))) {
XPCVariant* variant = XPCVariant::newVariant(ccx, s); XPCVariant* variant = XPCVariant::newVariant(cx, s);
if (!variant) if (!variant)
return false; return false;
*((nsISupports**)d) = static_cast<nsIVariant*>(variant); *((nsISupports**)d) = static_cast<nsIVariant*>(variant);
@ -752,7 +750,7 @@ XPCConvert::JSData2Native(XPCCallContext& ccx, void* d, jsval s,
return false; return false;
} }
return JSObject2NativeInterface(ccx, (void**)d, &s.toObject(), iid, return JSObject2NativeInterface(cx, (void**)d, &s.toObject(), iid,
nullptr, pErr); nullptr, pErr);
} }
default: default:
@ -1010,7 +1008,7 @@ XPCConvert::NativeInterface2JSObject(XPCLazyCallContext& lccx,
// static // static
JSBool JSBool
XPCConvert::JSObject2NativeInterface(XPCCallContext& ccx, XPCConvert::JSObject2NativeInterface(JSContext* cx,
void** dest, JSObject* src, void** dest, JSObject* src,
const nsID* iid, const nsID* iid,
nsISupports* aOuter, nsISupports* aOuter,
@ -1020,7 +1018,6 @@ XPCConvert::JSObject2NativeInterface(XPCCallContext& ccx,
NS_ASSERTION(src, "bad param"); NS_ASSERTION(src, "bad param");
NS_ASSERTION(iid, "bad param"); NS_ASSERTION(iid, "bad param");
JSContext* cx = ccx.GetJSContext();
JSAutoCompartment ac(cx, src); JSAutoCompartment ac(cx, src);
*dest = nullptr; *dest = nullptr;
@ -1078,7 +1075,7 @@ XPCConvert::JSObject2NativeInterface(XPCCallContext& ccx,
// else... // else...
nsXPCWrappedJS* wrapper; nsXPCWrappedJS* wrapper;
nsresult rv = nsXPCWrappedJS::GetNewOrUsed(ccx, src, *iid, aOuter, &wrapper); nsresult rv = nsXPCWrappedJS::GetNewOrUsed(cx, src, *iid, aOuter, &wrapper);
if (pErr) if (pErr)
*pErr = rv; *pErr = rv;
if (NS_SUCCEEDED(rv) && wrapper) { if (NS_SUCCEEDED(rv) && wrapper) {
@ -1534,7 +1531,7 @@ CheckTargetAndPopulate(JSContext *cx,
// static // static
JSBool JSBool
XPCConvert::JSTypedArray2Native(XPCCallContext& ccx, XPCConvert::JSTypedArray2Native(JSContext* cx,
void** d, void** d,
JSObject* jsArray, JSObject* jsArray,
uint32_t count, uint32_t count,
@ -1543,7 +1540,6 @@ XPCConvert::JSTypedArray2Native(XPCCallContext& ccx,
{ {
NS_ABORT_IF_FALSE(jsArray, "bad param"); NS_ABORT_IF_FALSE(jsArray, "bad param");
NS_ABORT_IF_FALSE(d, "bad param"); NS_ABORT_IF_FALSE(d, "bad param");
JSContext* cx = ccx.GetJSContext();
NS_ABORT_IF_FALSE(JS_IsTypedArrayObject(jsArray, cx), "not a typed array"); NS_ABORT_IF_FALSE(JS_IsTypedArrayObject(jsArray, cx), "not a typed array");
// Check the actual length of the input array against the // Check the actual length of the input array against the
@ -1641,14 +1637,12 @@ XPCConvert::JSTypedArray2Native(XPCCallContext& ccx,
// static // static
JSBool JSBool
XPCConvert::JSArray2Native(XPCCallContext& ccx, void** d, JS::Value s, XPCConvert::JSArray2Native(JSContext* cx, void** d, JS::Value s,
uint32_t count, const nsXPTType& type, uint32_t count, const nsXPTType& type,
const nsID* iid, nsresult* pErr) const nsID* iid, nsresult* pErr)
{ {
NS_ABORT_IF_FALSE(d, "bad param"); NS_ABORT_IF_FALSE(d, "bad param");
JSContext* cx = ccx.GetJSContext();
// XXX add support for getting chars from strings // XXX add support for getting chars from strings
// XXX add support to indicate *which* array element was not convertable // XXX add support to indicate *which* array element was not convertable
@ -1674,7 +1668,7 @@ XPCConvert::JSArray2Native(XPCCallContext& ccx, void** d, JS::Value s,
// If this is a typed array, then try a fast conversion with memcpy. // If this is a typed array, then try a fast conversion with memcpy.
if (JS_IsTypedArrayObject(jsarray, cx)) { if (JS_IsTypedArrayObject(jsarray, cx)) {
return JSTypedArray2Native(ccx, d, jsarray, count, type, pErr); return JSTypedArray2Native(cx, d, jsarray, count, type, pErr);
} }
if (!JS_IsArrayObject(cx, jsarray)) { if (!JS_IsArrayObject(cx, jsarray)) {
@ -1705,7 +1699,7 @@ XPCConvert::JSArray2Native(XPCCallContext& ccx, void** d, JS::Value s,
} \ } \
for (initedCount = 0; initedCount < count; initedCount++) { \ for (initedCount = 0; initedCount < count; initedCount++) { \
if (!JS_GetElement(cx, jsarray, initedCount, &current) || \ if (!JS_GetElement(cx, jsarray, initedCount, &current) || \
!JSData2Native(ccx, ((_t*)array)+initedCount, current, type, \ !JSData2Native(cx, ((_t*)array)+initedCount, current, type, \
true, iid, pErr)) \ true, iid, pErr)) \
goto failure; \ goto failure; \
} \ } \

Просмотреть файл

@ -25,12 +25,12 @@ NS_IMPL_CI_INTERFACE_GETTER2(XPCVariant, XPCVariant, nsIVariant)
NS_IMPL_CYCLE_COLLECTING_ADDREF(XPCVariant) NS_IMPL_CYCLE_COLLECTING_ADDREF(XPCVariant)
NS_IMPL_CYCLE_COLLECTING_RELEASE(XPCVariant) NS_IMPL_CYCLE_COLLECTING_RELEASE(XPCVariant)
XPCVariant::XPCVariant(XPCCallContext& ccx, jsval aJSVal) XPCVariant::XPCVariant(JSContext* cx, jsval aJSVal)
: mJSVal(aJSVal), mCCGeneration(0) : mJSVal(aJSVal), mCCGeneration(0)
{ {
nsVariant::Initialize(&mData); nsVariant::Initialize(&mData);
if (!JSVAL_IS_PRIMITIVE(mJSVal)) { if (!JSVAL_IS_PRIMITIVE(mJSVal)) {
JSObject *obj = JS_ObjectToInnerObject(ccx, JSVAL_TO_OBJECT(mJSVal)); JSObject *obj = JS_ObjectToInnerObject(cx, JSVAL_TO_OBJECT(mJSVal));
mJSVal = OBJECT_TO_JSVAL(obj); mJSVal = OBJECT_TO_JSVAL(obj);
@ -40,7 +40,7 @@ XPCVariant::XPCVariant(XPCCallContext& ccx, jsval aJSVal)
JSObject* proto; JSObject* proto;
XPCWrappedNative* wn = XPCWrappedNative* wn =
XPCWrappedNative::GetWrappedNativeOfJSObject(ccx, XPCWrappedNative::GetWrappedNativeOfJSObject(cx,
JSVAL_TO_OBJECT(mJSVal), JSVAL_TO_OBJECT(mJSVal),
nullptr, nullptr,
&proto); &proto);
@ -107,20 +107,20 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(XPCVariant)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END NS_IMPL_CYCLE_COLLECTION_UNLINK_END
// static // static
XPCVariant* XPCVariant::newVariant(XPCCallContext& ccx, jsval aJSVal) XPCVariant* XPCVariant::newVariant(JSContext* cx, jsval aJSVal)
{ {
XPCVariant* variant; XPCVariant* variant;
if (!JSVAL_IS_TRACEABLE(aJSVal)) if (!JSVAL_IS_TRACEABLE(aJSVal))
variant = new XPCVariant(ccx, aJSVal); variant = new XPCVariant(cx, aJSVal);
else else
variant = new XPCTraceableVariant(ccx, aJSVal); variant = new XPCTraceableVariant(cx, aJSVal);
if (!variant) if (!variant)
return nullptr; return nullptr;
NS_ADDREF(variant); NS_ADDREF(variant);
if (!variant->InitializeData(ccx)) if (!variant->InitializeData(cx))
NS_RELEASE(variant); // Also sets variant to nullptr. NS_RELEASE(variant); // Also sets variant to nullptr.
return variant; return variant;
@ -152,7 +152,7 @@ private:
static const Type StateTable[tTypeCount][tTypeCount-1]; static const Type StateTable[tTypeCount][tTypeCount-1];
public: public:
static JSBool GetTypeForArray(XPCCallContext& ccx, JSObject* array, static JSBool GetTypeForArray(JSContext* cx, JSObject* array,
uint32_t length, uint32_t length,
nsXPTType* resultType, nsID* resultID); nsXPTType* resultType, nsID* resultID);
}; };
@ -177,7 +177,7 @@ XPCArrayHomogenizer::StateTable[tTypeCount][tTypeCount-1] = {
// static // static
JSBool JSBool
XPCArrayHomogenizer::GetTypeForArray(XPCCallContext& ccx, JSObject* array, XPCArrayHomogenizer::GetTypeForArray(JSContext* cx, JSObject* array,
uint32_t length, uint32_t length,
nsXPTType* resultType, nsID* resultID) nsXPTType* resultType, nsID* resultID)
{ {
@ -186,7 +186,7 @@ XPCArrayHomogenizer::GetTypeForArray(XPCCallContext& ccx, JSObject* array,
for (uint32_t i = 0; i < length; i++) { for (uint32_t i = 0; i < length; i++) {
JS::Value val; JS::Value val;
if (!JS_GetElement(ccx, array, i, &val)) if (!JS_GetElement(cx, array, i, &val))
return false; return false;
if (val.isInt32()) { if (val.isInt32()) {
@ -205,9 +205,9 @@ XPCArrayHomogenizer::GetTypeForArray(XPCCallContext& ccx, JSObject* array,
} else { } else {
NS_ASSERTION(val.isObject(), "invalid type of jsval!"); NS_ASSERTION(val.isObject(), "invalid type of jsval!");
JSObject* jsobj = &val.toObject(); JSObject* jsobj = &val.toObject();
if (JS_IsArrayObject(ccx, jsobj)) if (JS_IsArrayObject(cx, jsobj))
type = tArr; type = tArr;
else if (xpc_JSObjectIsID(ccx, jsobj)) else if (xpc_JSObjectIsID(cx, jsobj))
type = tID; type = tID;
else else
type = tISup; type = tISup;
@ -266,9 +266,9 @@ XPCArrayHomogenizer::GetTypeForArray(XPCCallContext& ccx, JSObject* array,
return true; return true;
} }
JSBool XPCVariant::InitializeData(XPCCallContext& ccx) JSBool XPCVariant::InitializeData(JSContext* cx)
{ {
JS_CHECK_RECURSION(ccx.GetJSContext(), return false); JS_CHECK_RECURSION(cx, return false);
JS::Value val = GetJSVal(); JS::Value val = GetJSVal();
@ -296,7 +296,7 @@ JSBool XPCVariant::InitializeData(XPCCallContext& ccx)
// Despite the fact that the variant holds the length, there are // Despite the fact that the variant holds the length, there are
// implicit assumptions that mWStringValue[mWStringLength] == 0 // implicit assumptions that mWStringValue[mWStringLength] == 0
size_t length; size_t length;
const jschar *chars = JS_GetStringCharsZAndLength(ccx, str, &length); const jschar *chars = JS_GetStringCharsZAndLength(cx, str, &length);
if (!chars) if (!chars)
return false; return false;
@ -316,7 +316,7 @@ JSBool XPCVariant::InitializeData(XPCCallContext& ccx)
// Let's see if it is a xpcJSID. // Let's see if it is a xpcJSID.
const nsID* id = xpc_JSObjectToID(ccx, jsobj); const nsID* id = xpc_JSObjectToID(cx, jsobj);
if (id) if (id)
return NS_SUCCEEDED(nsVariant::SetFromID(&mData, *id)); return NS_SUCCEEDED(nsVariant::SetFromID(&mData, *id));
@ -324,7 +324,7 @@ JSBool XPCVariant::InitializeData(XPCCallContext& ccx)
uint32_t len; uint32_t len;
if (JS_IsArrayObject(ccx, jsobj) && JS_GetArrayLength(ccx, jsobj, &len)) { if (JS_IsArrayObject(cx, jsobj) && JS_GetArrayLength(cx, jsobj, &len)) {
if (!len) { if (!len) {
// Zero length array // Zero length array
nsVariant::SetToEmptyArray(&mData); nsVariant::SetToEmptyArray(&mData);
@ -334,10 +334,10 @@ JSBool XPCVariant::InitializeData(XPCCallContext& ccx)
nsXPTType type; nsXPTType type;
nsID id; nsID id;
if (!XPCArrayHomogenizer::GetTypeForArray(ccx, jsobj, len, &type, &id)) if (!XPCArrayHomogenizer::GetTypeForArray(cx, jsobj, len, &type, &id))
return false; return false;
if (!XPCConvert::JSArray2Native(ccx, &mData.u.array.mArrayValue, if (!XPCConvert::JSArray2Native(cx, &mData.u.array.mArrayValue,
val, len, type, &id, nullptr)) val, len, type, &id, nullptr))
return false; return false;
@ -357,7 +357,7 @@ JSBool XPCVariant::InitializeData(XPCCallContext& ccx)
const nsIID& iid = NS_GET_IID(nsISupports); const nsIID& iid = NS_GET_IID(nsISupports);
return nullptr != (xpc = nsXPConnect::GetXPConnect()) && return nullptr != (xpc = nsXPConnect::GetXPConnect()) &&
NS_SUCCEEDED(xpc->WrapJS(ccx, jsobj, NS_SUCCEEDED(xpc->WrapJS(cx, jsobj,
iid, getter_AddRefs(wrapper))) && iid, getter_AddRefs(wrapper))) &&
NS_SUCCEEDED(nsVariant::SetFromInterface(&mData, iid, wrapper)); NS_SUCCEEDED(nsVariant::SetFromInterface(&mData, iid, wrapper));
} }

Просмотреть файл

@ -273,7 +273,7 @@ CheckMainThreadOnly(nsXPCWrappedJS *aWrapper)
// static // static
nsresult nsresult
nsXPCWrappedJS::GetNewOrUsed(XPCCallContext& ccx, nsXPCWrappedJS::GetNewOrUsed(JSContext* cx,
JSObject* aJSObj, JSObject* aJSObj,
REFNSIID aIID, REFNSIID aIID,
nsISupports* aOuter, nsISupports* aOuter,
@ -284,7 +284,7 @@ nsXPCWrappedJS::GetNewOrUsed(XPCCallContext& ccx,
nsXPCWrappedJS* root = nullptr; nsXPCWrappedJS* root = nullptr;
nsXPCWrappedJS* wrapper = nullptr; nsXPCWrappedJS* wrapper = nullptr;
nsXPCWrappedJSClass* clazz = nullptr; nsXPCWrappedJSClass* clazz = nullptr;
XPCJSRuntime* rt = ccx.GetRuntime(); XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance();
JSBool release_root = false; JSBool release_root = false;
map = rt->GetWrappedJSMap(); map = rt->GetWrappedJSMap();
@ -293,13 +293,13 @@ nsXPCWrappedJS::GetNewOrUsed(XPCCallContext& ccx,
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
nsXPCWrappedJSClass::GetNewOrUsed(ccx, aIID, &clazz); nsXPCWrappedJSClass::GetNewOrUsed(cx, aIID, &clazz);
if (!clazz) if (!clazz)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
// from here on we need to return through 'return_wrapper' // from here on we need to return through 'return_wrapper'
// always find the root JSObject // always find the root JSObject
rootJSObj = clazz->GetRootJSObject(ccx, aJSObj); rootJSObj = clazz->GetRootJSObject(cx, aJSObj);
if (!rootJSObj) if (!rootJSObj)
goto return_wrapper; goto return_wrapper;
@ -322,7 +322,7 @@ nsXPCWrappedJS::GetNewOrUsed(XPCCallContext& ccx,
// build the root wrapper // build the root wrapper
if (rootJSObj == aJSObj) { if (rootJSObj == aJSObj) {
// the root will do double duty as the interface wrapper // the root will do double duty as the interface wrapper
wrapper = root = new nsXPCWrappedJS(ccx, aJSObj, clazz, nullptr, wrapper = root = new nsXPCWrappedJS(cx, aJSObj, clazz, nullptr,
aOuter); aOuter);
if (!root) if (!root)
goto return_wrapper; goto return_wrapper;
@ -347,12 +347,12 @@ nsXPCWrappedJS::GetNewOrUsed(XPCCallContext& ccx,
} else { } else {
// just a root wrapper // just a root wrapper
nsXPCWrappedJSClass* rootClazz = nullptr; nsXPCWrappedJSClass* rootClazz = nullptr;
nsXPCWrappedJSClass::GetNewOrUsed(ccx, NS_GET_IID(nsISupports), nsXPCWrappedJSClass::GetNewOrUsed(cx, NS_GET_IID(nsISupports),
&rootClazz); &rootClazz);
if (!rootClazz) if (!rootClazz)
goto return_wrapper; goto return_wrapper;
root = new nsXPCWrappedJS(ccx, rootJSObj, rootClazz, nullptr, aOuter); root = new nsXPCWrappedJS(cx, rootJSObj, rootClazz, nullptr, aOuter);
NS_RELEASE(rootClazz); NS_RELEASE(rootClazz);
if (!root) if (!root)
@ -383,7 +383,7 @@ nsXPCWrappedJS::GetNewOrUsed(XPCCallContext& ccx,
NS_ASSERTION(clazz,"bad clazz"); NS_ASSERTION(clazz,"bad clazz");
if (!wrapper) { if (!wrapper) {
wrapper = new nsXPCWrappedJS(ccx, aJSObj, clazz, root, aOuter); wrapper = new nsXPCWrappedJS(cx, aJSObj, clazz, root, aOuter);
if (!wrapper) if (!wrapper)
goto return_wrapper; goto return_wrapper;
#if DEBUG_xpc_leaks #if DEBUG_xpc_leaks
@ -409,7 +409,7 @@ return_wrapper:
return NS_OK; return NS_OK;
} }
nsXPCWrappedJS::nsXPCWrappedJS(XPCCallContext& ccx, nsXPCWrappedJS::nsXPCWrappedJS(JSContext* cx,
JSObject* aJSObj, JSObject* aJSObj,
nsXPCWrappedJSClass* aClass, nsXPCWrappedJSClass* aClass,
nsXPCWrappedJS* root, nsXPCWrappedJS* root,

Просмотреть файл

@ -107,11 +107,11 @@ JSBool xpc_IsReportableErrorCode(nsresult code)
// static // static
nsresult nsresult
nsXPCWrappedJSClass::GetNewOrUsed(XPCCallContext& ccx, REFNSIID aIID, nsXPCWrappedJSClass::GetNewOrUsed(JSContext* cx, REFNSIID aIID,
nsXPCWrappedJSClass** resultClazz) nsXPCWrappedJSClass** resultClazz)
{ {
nsXPCWrappedJSClass* clazz = nullptr; nsXPCWrappedJSClass* clazz = nullptr;
XPCJSRuntime* rt = ccx.GetRuntime(); XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance();
{ // scoped lock { // scoped lock
XPCAutoLock lock(rt->GetMapLock()); XPCAutoLock lock(rt->GetMapLock());
@ -122,13 +122,13 @@ nsXPCWrappedJSClass::GetNewOrUsed(XPCCallContext& ccx, REFNSIID aIID,
if (!clazz) { if (!clazz) {
nsCOMPtr<nsIInterfaceInfo> info; nsCOMPtr<nsIInterfaceInfo> info;
ccx.GetXPConnect()->GetInfoForIID(&aIID, getter_AddRefs(info)); nsXPConnect::GetXPConnect()->GetInfoForIID(&aIID, getter_AddRefs(info));
if (info) { if (info) {
bool canScript, isBuiltin; bool canScript, isBuiltin;
if (NS_SUCCEEDED(info->IsScriptable(&canScript)) && canScript && if (NS_SUCCEEDED(info->IsScriptable(&canScript)) && canScript &&
NS_SUCCEEDED(info->IsBuiltinClass(&isBuiltin)) && !isBuiltin && NS_SUCCEEDED(info->IsBuiltinClass(&isBuiltin)) && !isBuiltin &&
nsXPConnect::IsISupportsDescendant(info)) { nsXPConnect::IsISupportsDescendant(info)) {
clazz = new nsXPCWrappedJSClass(ccx, aIID, info); clazz = new nsXPCWrappedJSClass(cx, aIID, info);
if (clazz && !clazz->mDescriptors) if (clazz && !clazz->mDescriptors)
NS_RELEASE(clazz); // sets clazz to nullptr NS_RELEASE(clazz); // sets clazz to nullptr
} }
@ -138,9 +138,9 @@ nsXPCWrappedJSClass::GetNewOrUsed(XPCCallContext& ccx, REFNSIID aIID,
return NS_OK; return NS_OK;
} }
nsXPCWrappedJSClass::nsXPCWrappedJSClass(XPCCallContext& ccx, REFNSIID aIID, nsXPCWrappedJSClass::nsXPCWrappedJSClass(JSContext* cx, REFNSIID aIID,
nsIInterfaceInfo* aInfo) nsIInterfaceInfo* aInfo)
: mRuntime(ccx.GetRuntime()), : mRuntime(nsXPConnect::GetRuntimeInstance()),
mInfo(aInfo), mInfo(aInfo),
mName(nullptr), mName(nullptr),
mIID(aIID), mIID(aIID),
@ -196,11 +196,10 @@ nsXPCWrappedJSClass::~nsXPCWrappedJSClass()
} }
JSObject* JSObject*
nsXPCWrappedJSClass::CallQueryInterfaceOnJSObject(XPCCallContext& ccx, nsXPCWrappedJSClass::CallQueryInterfaceOnJSObject(JSContext* cx,
JSObject* jsobj, JSObject* jsobj,
REFNSIID aIID) REFNSIID aIID)
{ {
JSContext* cx = ccx.GetJSContext();
JSObject* id; JSObject* id;
jsval retval; jsval retval;
JSObject* retObj; JSObject* retObj;
@ -230,7 +229,7 @@ nsXPCWrappedJSClass::CallQueryInterfaceOnJSObject(XPCCallContext& ccx,
return nullptr; return nullptr;
// protect fun so that we're sure it's alive when we call it // protect fun so that we're sure it's alive when we call it
AUTO_MARK_JSVAL(ccx, fun); AUTO_MARK_JSVAL(cx, fun);
// Ensure that we are asking for a scriptable interface. // Ensure that we are asking for a scriptable interface.
// NB: It's important for security that this check is here rather // NB: It's important for security that this check is here rather
@ -240,7 +239,7 @@ nsXPCWrappedJSClass::CallQueryInterfaceOnJSObject(XPCCallContext& ccx,
// We so often ask for nsISupports that we can short-circuit the test... // We so often ask for nsISupports that we can short-circuit the test...
if (!aIID.Equals(NS_GET_IID(nsISupports))) { if (!aIID.Equals(NS_GET_IID(nsISupports))) {
nsCOMPtr<nsIInterfaceInfo> info; nsCOMPtr<nsIInterfaceInfo> info;
ccx.GetXPConnect()->GetInfoForIID(&aIID, getter_AddRefs(info)); nsXPConnect::GetXPConnect()->GetInfoForIID(&aIID, getter_AddRefs(info));
if (!info) if (!info)
return nullptr; return nullptr;
bool canScript, isBuiltin; bool canScript, isBuiltin;
@ -268,7 +267,7 @@ nsXPCWrappedJSClass::CallQueryInterfaceOnJSObject(XPCCallContext& ccx,
"JS failed without setting an exception!"); "JS failed without setting an exception!");
jsval jsexception = JSVAL_NULL; jsval jsexception = JSVAL_NULL;
AUTO_MARK_JSVAL(ccx, &jsexception); AUTO_MARK_JSVAL(cx, &jsexception);
if (JS_GetPendingException(cx, &jsexception)) { if (JS_GetPendingException(cx, &jsexception)) {
nsresult rv; nsresult rv;
@ -278,7 +277,7 @@ nsXPCWrappedJSClass::CallQueryInterfaceOnJSObject(XPCCallContext& ccx,
nsCOMPtr<nsIXPConnectWrappedNative> wrapper; nsCOMPtr<nsIXPConnectWrappedNative> wrapper;
nsXPConnect::GetXPConnect()-> nsXPConnect::GetXPConnect()->
GetWrappedNativeOfJSObject(ccx, GetWrappedNativeOfJSObject(cx,
&jsexception.toObject(), &jsexception.toObject(),
getter_AddRefs(wrapper)); getter_AddRefs(wrapper));
@ -746,13 +745,13 @@ nsXPCWrappedJSClass::DelegatedQueryInterface(nsXPCWrappedJS* self,
} }
JSObject* JSObject*
nsXPCWrappedJSClass::GetRootJSObject(XPCCallContext& ccx, JSObject* aJSObj) nsXPCWrappedJSClass::GetRootJSObject(JSContext* cx, JSObject* aJSObj)
{ {
JSObject* result = CallQueryInterfaceOnJSObject(ccx, aJSObj, JSObject* result = CallQueryInterfaceOnJSObject(cx, aJSObj,
NS_GET_IID(nsISupports)); NS_GET_IID(nsISupports));
if (!result) if (!result)
return aJSObj; return aJSObj;
JSObject* inner = XPCWrapper::Unwrap(ccx, result); JSObject* inner = XPCWrapper::Unwrap(cx, result);
if (inner) if (inner)
return inner; return inner;
return result; return result;

Просмотреть файл

@ -3024,7 +3024,7 @@ CallMethodHelper::CleanupParam(nsXPTCMiniVariant& param, nsXPTType& type)
break; break;
case nsXPTType::T_ASTRING: case nsXPTType::T_ASTRING:
case nsXPTType::T_DOMSTRING: case nsXPTType::T_DOMSTRING:
mCallContext.DeleteString((nsAString*)param.val.p); nsXPConnect::GetRuntimeInstance()->DeleteString((nsAString*)param.val.p);
break; break;
case nsXPTType::T_UTF8STRING: case nsXPTType::T_UTF8STRING:
case nsXPTType::T_CSTRING: case nsXPTType::T_CSTRING:

Просмотреть файл

@ -208,12 +208,11 @@ def writeArgumentUnboxing(f, i, name, type, haveCcx, optional, rvdeclared,
elif isInterfaceType(type): elif isInterfaceType(type):
if type.name == 'nsIVariant': if type.name == 'nsIVariant':
# Totally custom. # Totally custom.
assert haveCcx
template = ( template = (
" nsCOMPtr<nsIVariant> ${name}(already_AddRefed<nsIVariant>(" " nsCOMPtr<nsIVariant> ${name}(already_AddRefed<nsIVariant>("
"XPCVariant::newVariant(ccx, ${argVal})));\n" "XPCVariant::newVariant(cx, ${argVal})));\n"
" if (!${name}) {\n" " if (!${name}) {\n"
" xpc_qsThrowBadArgWithCcx(ccx, NS_ERROR_XPC_BAD_CONVERT_JS, %d);\n" " xpc_qsThrowBadArg(cx, NS_ERROR_INVALID_ARG, vp, %d);\n"
" return JS_FALSE;\n" " return JS_FALSE;\n"
" }\n") % i " }\n") % i
f.write(string.Template(template).substitute(params)) f.write(string.Template(template).substitute(params))
@ -392,9 +391,6 @@ def writeResultConv(f, type, interfaceResultTemplate, jsvalPtr, jsvalRef):
f.write(" return xpc_qsThrow(cx, NS_ERROR_UNEXPECTED); // FIXME\n") f.write(" return xpc_qsThrow(cx, NS_ERROR_UNEXPECTED); // FIXME\n")
def anyParamRequiresCcx(member): def anyParamRequiresCcx(member):
for p in member.params:
if isVariantType(p.realtype):
return True
return False return False
def memberNeedsCcx(member): def memberNeedsCcx(member):

Просмотреть файл

@ -537,12 +537,11 @@ def writeArgumentUnboxing(f, i, name, type, haveCcx, optional, rvdeclared,
elif isInterfaceType(type): elif isInterfaceType(type):
if type.name == 'nsIVariant': if type.name == 'nsIVariant':
# Totally custom. # Totally custom.
assert haveCcx
template = ( template = (
" nsCOMPtr<nsIVariant> ${name}(already_AddRefed<nsIVariant>(" " nsCOMPtr<nsIVariant> ${name}(already_AddRefed<nsIVariant>("
"XPCVariant::newVariant(ccx, ${argVal})));\n" "XPCVariant::newVariant(cx, ${argVal})));\n"
" if (!${name}) {\n" " if (!${name}) {\n"
" xpc_qsThrowBadArgWithCcx(ccx, NS_ERROR_XPC_BAD_CONVERT_JS, %d);\n" " xpc_qsThrowBadArg(cx, NS_ERROR_INVALID_ARG, vp, %d);\n"
" return JS_FALSE;\n" " return JS_FALSE;\n"
" }") % i " }") % i
f.write(substitute(template, params)) f.write(substitute(template, params))
@ -725,9 +724,6 @@ def writeResultConv(f, type, jsvalPtr, jsvalRef):
f.write(" return xpc_qsThrow(cx, NS_ERROR_UNEXPECTED); // FIXME\n") f.write(" return xpc_qsThrow(cx, NS_ERROR_UNEXPECTED); // FIXME\n")
def anyParamRequiresCcx(member): def anyParamRequiresCcx(member):
for p in member.params:
if isVariantType(p.realtype):
return True
return False return False
def memberNeedsCcx(member): def memberNeedsCcx(member):

Просмотреть файл

@ -958,7 +958,7 @@ private:
{ {
StringWrapperEntry() : mInUse(false) { } StringWrapperEntry() : mInUse(false) { }
js::AlignedStorage2<XPCReadableJSStringWrapper> mString; mozilla::AlignedStorage2<XPCReadableJSStringWrapper> mString;
bool mInUse; bool mInUse;
}; };
@ -3037,7 +3037,7 @@ class nsXPCWrappedJSClass : public nsIXPCWrappedJSClass
public: public:
static nsresult static nsresult
GetNewOrUsed(XPCCallContext& ccx, GetNewOrUsed(JSContext* cx,
REFNSIID aIID, REFNSIID aIID,
nsXPCWrappedJSClass** clazz); nsXPCWrappedJSClass** clazz);
@ -3051,13 +3051,13 @@ public:
NS_IMETHOD DelegatedQueryInterface(nsXPCWrappedJS* self, REFNSIID aIID, NS_IMETHOD DelegatedQueryInterface(nsXPCWrappedJS* self, REFNSIID aIID,
void** aInstancePtr); void** aInstancePtr);
JSObject* GetRootJSObject(XPCCallContext& ccx, JSObject* aJSObj); JSObject* GetRootJSObject(JSContext* cx, JSObject* aJSObj);
NS_IMETHOD CallMethod(nsXPCWrappedJS* wrapper, uint16_t methodIndex, NS_IMETHOD CallMethod(nsXPCWrappedJS* wrapper, uint16_t methodIndex,
const XPTMethodDescriptor* info, const XPTMethodDescriptor* info,
nsXPTCMiniVariant* params); nsXPTCMiniVariant* params);
JSObject* CallQueryInterfaceOnJSObject(XPCCallContext& ccx, JSObject* CallQueryInterfaceOnJSObject(JSContext* cx,
JSObject* jsobj, REFNSIID aIID); JSObject* jsobj, REFNSIID aIID);
static nsresult BuildPropertyEnumerator(XPCCallContext& ccx, static nsresult BuildPropertyEnumerator(XPCCallContext& ccx,
@ -3077,7 +3077,7 @@ public:
bool aForceReport); bool aForceReport);
private: private:
nsXPCWrappedJSClass(); // not implemented nsXPCWrappedJSClass(); // not implemented
nsXPCWrappedJSClass(XPCCallContext& ccx, REFNSIID aIID, nsXPCWrappedJSClass(JSContext* cx, REFNSIID aIID,
nsIInterfaceInfo* aInfo); nsIInterfaceInfo* aInfo);
JSObject* NewOutObject(JSContext* cx, JSObject* scope); JSObject* NewOutObject(JSContext* cx, JSObject* scope);
@ -3151,7 +3151,7 @@ public:
*/ */
static nsresult static nsresult
GetNewOrUsed(XPCCallContext& ccx, GetNewOrUsed(JSContext* cx,
JSObject* aJSObj, JSObject* aJSObj,
REFNSIID aIID, REFNSIID aIID,
nsISupports* aOuter, nsISupports* aOuter,
@ -3209,7 +3209,7 @@ public:
virtual ~nsXPCWrappedJS(); virtual ~nsXPCWrappedJS();
protected: protected:
nsXPCWrappedJS(); // not implemented nsXPCWrappedJS(); // not implemented
nsXPCWrappedJS(XPCCallContext& ccx, nsXPCWrappedJS(JSContext* cx,
JSObject* aJSObj, JSObject* aJSObj,
nsXPCWrappedJSClass* aClass, nsXPCWrappedJSClass* aClass,
nsXPCWrappedJS* root, nsXPCWrappedJS* root,
@ -3295,6 +3295,7 @@ public:
* chain * chain
* @param pErr [out] relevant error code, if any. * @param pErr [out] relevant error code, if any.
*/ */
static JSBool NativeData2JS(XPCCallContext& ccx, jsval* d, const void* s, static JSBool NativeData2JS(XPCCallContext& ccx, jsval* d, const void* s,
const nsXPTType& type, const nsID* iid, const nsXPTType& type, const nsID* iid,
nsresult* pErr) nsresult* pErr)
@ -3302,11 +3303,12 @@ public:
XPCLazyCallContext lccx(ccx); XPCLazyCallContext lccx(ccx);
return NativeData2JS(lccx, d, s, type, iid, pErr); return NativeData2JS(lccx, d, s, type, iid, pErr);
} }
static JSBool NativeData2JS(XPCLazyCallContext& lccx, jsval* d, static JSBool NativeData2JS(XPCLazyCallContext& lccx, jsval* d,
const void* s, const nsXPTType& type, const void* s, const nsXPTType& type,
const nsID* iid, nsresult* pErr); const nsID* iid, nsresult* pErr);
static JSBool JSData2Native(XPCCallContext& ccx, void* d, jsval s, static JSBool JSData2Native(JSContext* cx, void* d, jsval s,
const nsXPTType& type, const nsXPTType& type,
JSBool useAllocator, const nsID* iid, JSBool useAllocator, const nsID* iid,
nsresult* pErr); nsresult* pErr);
@ -3353,7 +3355,7 @@ public:
void** dest, JSObject* src, void** dest, JSObject* src,
const nsID* iid, const nsID* iid,
nsresult* pErr); nsresult* pErr);
static JSBool JSObject2NativeInterface(XPCCallContext& ccx, static JSBool JSObject2NativeInterface(JSContext* cx,
void** dest, JSObject* src, void** dest, JSObject* src,
const nsID* iid, const nsID* iid,
nsISupports* aOuter, nsISupports* aOuter,
@ -3377,11 +3379,11 @@ public:
const nsXPTType& type, const nsID* iid, const nsXPTType& type, const nsID* iid,
uint32_t count, nsresult* pErr); uint32_t count, nsresult* pErr);
static JSBool JSArray2Native(XPCCallContext& ccx, void** d, jsval s, static JSBool JSArray2Native(JSContext* cx, void** d, jsval s,
uint32_t count, const nsXPTType& type, uint32_t count, const nsXPTType& type,
const nsID* iid, nsresult* pErr); const nsID* iid, nsresult* pErr);
static JSBool JSTypedArray2Native(XPCCallContext& ccx, static JSBool JSTypedArray2Native(JSContext* cx,
void** d, void** d,
JSObject* jsarray, JSObject* jsarray,
uint32_t count, uint32_t count,
@ -3938,7 +3940,7 @@ private:
class AutoMarkingPtr class AutoMarkingPtr
{ {
public: public:
AutoMarkingPtr(XPCCallContext& ccx) { AutoMarkingPtr(JSContext* cx) {
mRoot = XPCJSRuntime::Get()->GetAutoRootsAdr(); mRoot = XPCJSRuntime::Get()->GetAutoRootsAdr();
mNext = *mRoot; mNext = *mRoot;
*mRoot = this; *mRoot = this;
@ -3974,8 +3976,8 @@ template<class T>
class TypedAutoMarkingPtr : public AutoMarkingPtr class TypedAutoMarkingPtr : public AutoMarkingPtr
{ {
public: public:
TypedAutoMarkingPtr(XPCCallContext& ccx) : AutoMarkingPtr(ccx), mPtr(nullptr) {} TypedAutoMarkingPtr(JSContext* cx) : AutoMarkingPtr(cx), mPtr(nullptr) {}
TypedAutoMarkingPtr(XPCCallContext& ccx, T* ptr) : AutoMarkingPtr(ccx), mPtr(ptr) {} TypedAutoMarkingPtr(JSContext* cx, T* ptr) : AutoMarkingPtr(cx), mPtr(ptr) {}
T* get() const { return mPtr; } T* get() const { return mPtr; }
operator T *() const { return mPtr; } operator T *() const { return mPtr; }
@ -4014,10 +4016,10 @@ template<class T>
class ArrayAutoMarkingPtr : public AutoMarkingPtr class ArrayAutoMarkingPtr : public AutoMarkingPtr
{ {
public: public:
ArrayAutoMarkingPtr(XPCCallContext& ccx) ArrayAutoMarkingPtr(JSContext* cx)
: AutoMarkingPtr(ccx), mPtr(nullptr), mCount(0) {} : AutoMarkingPtr(cx), mPtr(nullptr), mCount(0) {}
ArrayAutoMarkingPtr(XPCCallContext& ccx, T** ptr, uint32_t count, bool clear) ArrayAutoMarkingPtr(JSContext* cx, T** ptr, uint32_t count, bool clear)
: AutoMarkingPtr(ccx), mPtr(ptr), mCount(count) : AutoMarkingPtr(cx), mPtr(ptr), mCount(count)
{ {
if (!mPtr) mCount = 0; if (!mPtr) mCount = 0;
else if (clear) memset(mPtr, 0, mCount*sizeof(T*)); else if (clear) memset(mPtr, 0, mCount*sizeof(T*));
@ -4063,10 +4065,10 @@ typedef ArrayAutoMarkingPtr<XPCNativeInterface> AutoMarkingNativeInterfacePtrArr
#define AUTO_MARK_JSVAL_HELPER2(tok, line) tok##line #define AUTO_MARK_JSVAL_HELPER2(tok, line) tok##line
#define AUTO_MARK_JSVAL_HELPER(tok, line) AUTO_MARK_JSVAL_HELPER2(tok, line) #define AUTO_MARK_JSVAL_HELPER(tok, line) AUTO_MARK_JSVAL_HELPER2(tok, line)
#define AUTO_MARK_JSVAL(ccx, val) \ #define AUTO_MARK_JSVAL(cx, val) \
XPCMarkableJSVal AUTO_MARK_JSVAL_HELPER(_val_,__LINE__)(val); \ XPCMarkableJSVal AUTO_MARK_JSVAL_HELPER(_val_,__LINE__)(val); \
AutoMarkingJSVal AUTO_MARK_JSVAL_HELPER(_automarker_,__LINE__) \ AutoMarkingJSVal AUTO_MARK_JSVAL_HELPER(_automarker_,__LINE__) \
(ccx, &AUTO_MARK_JSVAL_HELPER(_val_,__LINE__)) (cx, &AUTO_MARK_JSVAL_HELPER(_val_,__LINE__))
/***************************************************************************/ /***************************************************************************/
// Allocates a string that grants all access ("AllAccess") // Allocates a string that grants all access ("AllAccess")
@ -4105,7 +4107,7 @@ public:
// if a given nsIVariant is in fact an XPCVariant. // if a given nsIVariant is in fact an XPCVariant.
NS_DECLARE_STATIC_IID_ACCESSOR(XPCVARIANT_IID) NS_DECLARE_STATIC_IID_ACCESSOR(XPCVARIANT_IID)
static XPCVariant* newVariant(XPCCallContext& ccx, jsval aJSVal); static XPCVariant* newVariant(JSContext* cx, jsval aJSVal);
/** /**
* This getter clears the gray bit before handing out the jsval if the jsval * This getter clears the gray bit before handing out the jsval if the jsval
@ -4128,7 +4130,7 @@ public:
*/ */
jsval GetJSValPreserveColor() const {return mJSVal;} jsval GetJSValPreserveColor() const {return mJSVal;}
XPCVariant(XPCCallContext& ccx, jsval aJSVal); XPCVariant(JSContext* cx, jsval aJSVal);
/** /**
* Convert a variant into a jsval. * Convert a variant into a jsval.
@ -4162,7 +4164,7 @@ public:
protected: protected:
virtual ~XPCVariant() { } virtual ~XPCVariant() { }
JSBool InitializeData(XPCCallContext& ccx); JSBool InitializeData(JSContext* cx);
protected: protected:
nsDiscriminatedUnion mData; nsDiscriminatedUnion mData;
@ -4177,10 +4179,10 @@ class XPCTraceableVariant: public XPCVariant,
public XPCRootSetElem public XPCRootSetElem
{ {
public: public:
XPCTraceableVariant(XPCCallContext& ccx, jsval aJSVal) XPCTraceableVariant(JSContext* cx, jsval aJSVal)
: XPCVariant(ccx, aJSVal) : XPCVariant(cx, aJSVal)
{ {
ccx.GetRuntime()->AddVariantRoot(this); nsXPConnect::GetRuntimeInstance()->AddVariantRoot(this);
} }
virtual ~XPCTraceableVariant(); virtual ~XPCTraceableVariant();

Просмотреть файл

@ -77,6 +77,7 @@ MOCHITEST_FILES = bug500931_helper.html \
file_mozMatchesSelector.html \ file_mozMatchesSelector.html \
file_bug720619.html \ file_bug720619.html \
test_bug720619.html \ test_bug720619.html \
test_bug785096.html \
$(NULL) $(NULL)
MOCHITEST_CHROME_FILES = \ MOCHITEST_CHROME_FILES = \

Просмотреть файл

@ -0,0 +1,39 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=390488
-->
<head>
<title>Test for Bug 785096</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body onload="test()">
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=785096">Mozilla Bug 785096</a>
<script class="testbody" type="text/javascript">
/** Test for Bug 785096 **/
SimpleTest.waitForExplicitFinish();
function test()
{
var sel = document.createElementNS('http://www.w3.org/1999/xhtml', 'select');
var option=document.createElement("option");
option.text="Fubar";
sel.options.add(option);
try {
Components.lookupMethod(sel.options, "add")(option);
ok(true, "function call should not throw")
} catch(e) {
do_throw("this call should just work without any exceptions");
}
SimpleTest.finish();
}
</script>
</pre>
</body>
</html>