зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1036777 - Remove the useAllocator argument to XPCConvert::JSData2Native; r=bholley
It turns out the useAllocator argument is only used for the dipper types (nsXPTType::{T_ASTRING, T_DOMSTRING, T_UTF8STRING, T_CSTRING}), while we only pass true in cases where we don't have a dipper type: * XPCConvert::JSArray2Native errors on those types; * GetNamedPropertyAsVariantRaw() passes an interface type; * nsXPCWrappedJSClass::CallMethod passes !param.IsDipper() for the first calls and only reaches the last call for dependent types, which do not include any of the dipper types; * CallMethodHelper::ConvertIndependentParam handles dipper types earlier * and CallMethodHelper::ConvertDependentParam handles dependent types.
This commit is contained in:
Родитель
de1ac1f4bd
Коммит
89cf0e3900
|
@ -388,7 +388,7 @@ bool ConvertToPrimitive(JSContext *cx, HandleValue v, T *retval)
|
|||
bool
|
||||
XPCConvert::JSData2Native(void* d, HandleValue s,
|
||||
const nsXPTType& type,
|
||||
bool useAllocator, const nsID* iid,
|
||||
const nsID* iid,
|
||||
nsresult* pErr)
|
||||
{
|
||||
NS_PRECONDITION(d, "bad param");
|
||||
|
@ -489,10 +489,7 @@ XPCConvert::JSData2Native(void* d, HandleValue s,
|
|||
case nsXPTType::T_ASTRING:
|
||||
{
|
||||
if (s.isUndefined()) {
|
||||
if (useAllocator)
|
||||
*((const nsAString**)d) = &NullString();
|
||||
else
|
||||
(**((nsAString**)d)).SetIsVoid(true);
|
||||
(**((nsAString**)d)).SetIsVoid(true);
|
||||
return true;
|
||||
}
|
||||
// Fall through to T_DOMSTRING case.
|
||||
|
@ -500,10 +497,7 @@ XPCConvert::JSData2Native(void* d, HandleValue s,
|
|||
case nsXPTType::T_DOMSTRING:
|
||||
{
|
||||
if (s.isNull()) {
|
||||
if (useAllocator)
|
||||
*((const nsAString**)d) = &NullString();
|
||||
else
|
||||
(**((nsAString**)d)).SetIsVoid(true);
|
||||
(**((nsAString**)d)).SetIsVoid(true);
|
||||
return true;
|
||||
}
|
||||
size_t length = 0;
|
||||
|
@ -515,21 +509,12 @@ XPCConvert::JSData2Native(void* d, HandleValue s,
|
|||
|
||||
length = JS_GetStringLength(str);
|
||||
if (!length) {
|
||||
if (useAllocator)
|
||||
*((const nsAString**)d) = &EmptyString();
|
||||
else
|
||||
(**((nsAString**)d)).Truncate();
|
||||
(**((nsAString**)d)).Truncate();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
nsString* ws;
|
||||
if (useAllocator) {
|
||||
ws = nsXPConnect::GetRuntimeInstance()->NewShortLivedString();
|
||||
*((const nsString**)d) = ws;
|
||||
} else {
|
||||
ws = *((nsString**)d);
|
||||
}
|
||||
nsString* ws = *((nsString**)d);
|
||||
|
||||
if (!str) {
|
||||
ws->AssignLiteral(MOZ_UTF16("undefined"));
|
||||
|
@ -619,12 +604,8 @@ XPCConvert::JSData2Native(void* d, HandleValue s,
|
|||
case nsXPTType::T_UTF8STRING:
|
||||
{
|
||||
if (s.isNull() || s.isUndefined()) {
|
||||
if (useAllocator) {
|
||||
*((const nsACString**)d) = &NullCString();
|
||||
} else {
|
||||
nsCString* rs = *((nsCString**)d);
|
||||
rs->SetIsVoid(true);
|
||||
}
|
||||
nsCString* rs = *((nsCString**)d);
|
||||
rs->SetIsVoid(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -635,54 +616,31 @@ XPCConvert::JSData2Native(void* d, HandleValue s,
|
|||
|
||||
size_t length = JS_GetStringLength(str);
|
||||
if (!length) {
|
||||
if (useAllocator) {
|
||||
*((const nsACString**)d) = &EmptyCString();
|
||||
} else {
|
||||
nsCString* rs = *((nsCString**)d);
|
||||
rs->Truncate();
|
||||
}
|
||||
nsCString* rs = *((nsCString**)d);
|
||||
rs->Truncate();
|
||||
return true;
|
||||
}
|
||||
|
||||
nsCString *rs;
|
||||
if (useAllocator) {
|
||||
// Use nsCString to enable sharing
|
||||
rs = new nsCString();
|
||||
if (!rs)
|
||||
return false;
|
||||
|
||||
*((const nsCString**)d) = rs;
|
||||
} else {
|
||||
rs = *((nsCString**)d);
|
||||
}
|
||||
|
||||
JSFlatString *flat = JS_FlattenString(cx, str);
|
||||
if (!flat)
|
||||
return false;
|
||||
|
||||
size_t utf8Length = JS::GetDeflatedUTF8StringLength(flat);
|
||||
nsCString *rs = *((nsCString**)d);
|
||||
rs->SetLength(utf8Length);
|
||||
|
||||
JS::DeflateStringToUTF8Buffer(flat, mozilla::RangedPtr<char>(rs->BeginWriting(), utf8Length));
|
||||
MOZ_ASSERT(rs->get()[utf8Length] == '\0');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
case nsXPTType::T_CSTRING:
|
||||
{
|
||||
if (s.isNull() || s.isUndefined()) {
|
||||
if (useAllocator) {
|
||||
nsACString *rs = new nsCString();
|
||||
if (!rs)
|
||||
return false;
|
||||
|
||||
rs->SetIsVoid(true);
|
||||
*((nsACString**)d) = rs;
|
||||
} else {
|
||||
nsACString* rs = *((nsACString**)d);
|
||||
rs->Truncate();
|
||||
rs->SetIsVoid(true);
|
||||
}
|
||||
nsACString* rs = *((nsACString**)d);
|
||||
rs->Truncate();
|
||||
rs->SetIsVoid(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -698,25 +656,12 @@ XPCConvert::JSData2Native(void* d, HandleValue s,
|
|||
}
|
||||
|
||||
if (!length) {
|
||||
if (useAllocator) {
|
||||
*((const nsACString**)d) = &EmptyCString();
|
||||
} else {
|
||||
nsCString* rs = *((nsCString**)d);
|
||||
rs->Truncate();
|
||||
}
|
||||
nsCString* rs = *((nsCString**)d);
|
||||
rs->Truncate();
|
||||
return true;
|
||||
}
|
||||
|
||||
nsACString *rs;
|
||||
if (useAllocator) {
|
||||
rs = new nsCString();
|
||||
if (!rs)
|
||||
return false;
|
||||
*((const nsACString**)d) = rs;
|
||||
} else {
|
||||
rs = *((nsACString**)d);
|
||||
}
|
||||
|
||||
nsACString *rs = *((nsACString**)d);
|
||||
rs->SetLength(uint32_t(length));
|
||||
if (rs->Length() != uint32_t(length)) {
|
||||
return false;
|
||||
|
@ -1618,7 +1563,7 @@ XPCConvert::JSArray2Native(void** d, HandleValue s,
|
|||
for (initedCount = 0; initedCount < count; initedCount++) { \
|
||||
if (!JS_GetElement(cx, jsarray, initedCount, ¤t) || \
|
||||
!JSData2Native(((_t*)array)+initedCount, current, type, \
|
||||
true, iid, pErr)) \
|
||||
iid, pErr)) \
|
||||
goto failure; \
|
||||
} \
|
||||
PR_END_MACRO
|
||||
|
|
|
@ -286,10 +286,7 @@ GetNamedPropertyAsVariantRaw(XPCCallContext& ccx,
|
|||
RootedValue val(ccx);
|
||||
|
||||
return JS_GetPropertyById(ccx, aJSObj, aName, &val) &&
|
||||
// Note that this always takes the T_INTERFACE path through
|
||||
// JSData2Native, so the value passed for useAllocator
|
||||
// doesn't really matter. We pass true for consistency.
|
||||
XPCConvert::JSData2Native(aResult, val, type, true,
|
||||
XPCConvert::JSData2Native(aResult, val, type,
|
||||
&NS_GET_IID(nsIVariant), pErr);
|
||||
}
|
||||
|
||||
|
@ -1352,13 +1349,13 @@ pre_call_clean_up:
|
|||
(defined(__powerpc__) && !defined (__powerpc64__)))
|
||||
if (type_tag == nsXPTType::T_JSVAL) {
|
||||
if (!XPCConvert::JSData2Native(*(void**)(&pv->val), val, type,
|
||||
!param.IsDipper(), ¶m_iid, nullptr))
|
||||
¶m_iid, nullptr))
|
||||
break;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
if (!XPCConvert::JSData2Native(&pv->val, val, type,
|
||||
!param.IsDipper(), ¶m_iid, nullptr))
|
||||
¶m_iid, nullptr))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1431,7 +1428,7 @@ pre_call_clean_up:
|
|||
break;
|
||||
} else {
|
||||
if (!XPCConvert::JSData2Native(&pv->val, val, type,
|
||||
true, ¶m_iid,
|
||||
¶m_iid,
|
||||
nullptr))
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -2165,7 +2165,7 @@ CallMethodHelper::ConvertIndependentParam(uint8_t i)
|
|||
}
|
||||
|
||||
nsresult err;
|
||||
if (!XPCConvert::JSData2Native(&dp->val, src, type, !paramInfo.IsStringClass(), ¶m_iid, &err)) {
|
||||
if (!XPCConvert::JSData2Native(&dp->val, src, type, ¶m_iid, &err)) {
|
||||
ThrowBadParam(err, i, mCallContext);
|
||||
return false;
|
||||
}
|
||||
|
@ -2285,7 +2285,7 @@ CallMethodHelper::ConvertDependentParam(uint8_t i)
|
|||
}
|
||||
}
|
||||
} else {
|
||||
if (!XPCConvert::JSData2Native(&dp->val, src, type, true,
|
||||
if (!XPCConvert::JSData2Native(&dp->val, src, type,
|
||||
¶m_iid, &err)) {
|
||||
ThrowBadParam(err, i, mCallContext);
|
||||
return false;
|
||||
|
|
|
@ -2507,7 +2507,7 @@ public:
|
|||
|
||||
static bool JSData2Native(void* d, JS::HandleValue s,
|
||||
const nsXPTType& type,
|
||||
bool useAllocator, const nsID* iid,
|
||||
const nsID* iid,
|
||||
nsresult* pErr);
|
||||
|
||||
/**
|
||||
|
|
Загрузка…
Ссылка в новой задаче