mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
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:
parent
38f630a4ee
commit
576e908707
@ -376,7 +376,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");
|
||||
@ -474,10 +474,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.
|
||||
@ -485,10 +482,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;
|
||||
@ -499,27 +493,17 @@ XPCConvert::JSData2Native(void* d, HandleValue s,
|
||||
if (!str)
|
||||
return false;
|
||||
|
||||
chars = useAllocator ? JS_GetStringCharsZAndLength(cx, str, &length)
|
||||
: JS_GetStringCharsAndLength(cx, str, &length);
|
||||
chars = JS_GetStringCharsAndLength(cx, str, &length);
|
||||
if (!chars)
|
||||
return false;
|
||||
|
||||
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"));
|
||||
@ -531,10 +515,6 @@ XPCConvert::JSData2Native(void* d, HandleValue s,
|
||||
// The characters represent a literal char16_t string constant
|
||||
// compiled into libxul, such as the string "undefined" above.
|
||||
ws->AssignLiteral(chars, length);
|
||||
} else if (useAllocator && STRING_TO_JSVAL(str) == s) {
|
||||
// The JS string will exist over the function call.
|
||||
// We don't need to copy the characters in this case.
|
||||
ws->Rebind(chars, length);
|
||||
} else {
|
||||
ws->Assign(chars, length);
|
||||
}
|
||||
@ -615,12 +595,8 @@ XPCConvert::JSData2Native(void* d, HandleValue s,
|
||||
JSString* str;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -632,26 +608,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;
|
||||
}
|
||||
|
||||
nsCString *rs;
|
||||
if (useAllocator) {
|
||||
// Use nsCString to enable sharing
|
||||
rs = new nsCString();
|
||||
if (!rs)
|
||||
return false;
|
||||
|
||||
*((const nsCString**)d) = rs;
|
||||
} else {
|
||||
rs = *((nsCString**)d);
|
||||
}
|
||||
nsCString *rs = *((nsCString**)d);
|
||||
CopyUTF16toUTF8(Substring(chars, length), *rs);
|
||||
return true;
|
||||
}
|
||||
@ -659,18 +621,9 @@ XPCConvert::JSData2Native(void* d, HandleValue s,
|
||||
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;
|
||||
}
|
||||
|
||||
@ -686,25 +639,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;
|
||||
@ -1608,7 +1548,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
|
||||
|
@ -283,10 +283,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);
|
||||
}
|
||||
|
||||
@ -1350,13 +1347,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;
|
||||
}
|
||||
}
|
||||
@ -1429,7 +1426,7 @@ pre_call_clean_up:
|
||||
break;
|
||||
} else {
|
||||
if (!XPCConvert::JSData2Native(&pv->val, val, type,
|
||||
true, ¶m_iid,
|
||||
¶m_iid,
|
||||
nullptr))
|
||||
break;
|
||||
}
|
||||
|
@ -2156,7 +2156,7 @@ CallMethodHelper::ConvertIndependentParam(uint8_t i)
|
||||
}
|
||||
|
||||
nsresult err;
|
||||
if (!XPCConvert::JSData2Native(&dp->val, src, type, true, ¶m_iid, &err)) {
|
||||
if (!XPCConvert::JSData2Native(&dp->val, src, type, ¶m_iid, &err)) {
|
||||
ThrowBadParam(err, i, mCallContext);
|
||||
return false;
|
||||
}
|
||||
@ -2276,7 +2276,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;
|
||||
|
@ -2501,7 +2501,7 @@ public:
|
||||
|
||||
static bool JSData2Native(void* d, JS::HandleValue s,
|
||||
const nsXPTType& type,
|
||||
bool useAllocator, const nsID* iid,
|
||||
const nsID* iid,
|
||||
nsresult* pErr);
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user