Bug 1652274 - Fix idl to avoid lots of "PreferDisplayName: undefined - not a boolean" errors. r=leftmostcat

Change the IDL to use a default value in case the property was not set. This way we avoid the pointless error spew.
There were many "errors" in tests such as comm/mail/test/browser/message-header/browser_messageHeader.js

Differential Revision: https://phabricator.services.mozilla.com/D175080

--HG--
extra : rebase_source : c376ce147f4ef76ad22d0d7b6e85a5d4bf6dc0d2
extra : amend_source : 0cd60bb13aacea2df1ce6d8a875673a72a9b5eaa
This commit is contained in:
Magnus Melin 2023-04-11 20:17:02 +10:00
Родитель bed5e7f933
Коммит c670a5fc4b
5 изменённых файлов: 17 добавлений и 13 удалений

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

@ -370,7 +370,7 @@ AddrBookCard.prototype = {
Cr.NS_ERROR_NOT_AVAILABLE
);
},
getPropertyAsBool(name) {
getPropertyAsBool(name, defaultValue) {
let value = this.getProperty(name);
switch (value) {
case false:
@ -381,6 +381,8 @@ AddrBookCard.prototype = {
case 1:
case "1":
return true;
case undefined:
return defaultValue;
}
throw Components.Exception(
`${name}: ${value} - not a boolean`,

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

@ -155,7 +155,14 @@ interface nsIAbCard : nsISupports {
AString getPropertyAsAString(in string name);
AUTF8String getPropertyAsAUTF8String(in string name);
unsigned long getPropertyAsUint32(in string name);
boolean getPropertyAsBool(in string name);
/**
* Returns a property for the given name.
*
* @param name The case-sensitive name of the property to get.
* @param defaultValue The value to return if the property does not exist.
*/
boolean getPropertyAsBool(in string name, in boolean defaultValue);
/** @} */

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

@ -220,13 +220,16 @@ NS_IMETHODIMP nsAbCardProperty::GetPropertyAsUint32(const char* name,
}
NS_IMETHODIMP nsAbCardProperty::GetPropertyAsBool(const char* name,
bool defaultValue,
bool* value) {
NS_ENSURE_ARG_POINTER(name);
*value = defaultValue;
nsCOMPtr<nsIVariant> variant;
return m_properties.Get(nsDependentCString(name), getter_AddRefs(variant))
? variant->GetAsBool(value)
: NS_ERROR_NOT_AVAILABLE;
: NS_OK;
}
NS_IMETHODIMP nsAbCardProperty::SetProperty(const nsACString& name,

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

@ -26,15 +26,7 @@ add_task(async function() {
return null;
}
let preferDisplayName = true;
try {
preferDisplayName = card.getPropertyAsBool("PreferDisplayName");
} catch {
// An error will be logged here:
// "NS_ERROR_NOT_AVAILABLE: PreferDisplayName: undefined - not a boolean"
// This is expected and not a bug.
}
let preferDisplayName = card.getPropertyAsBool("PreferDisplayName", true);
return preferDisplayName ? card.displayName : card.primaryEmail;
}

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

@ -274,7 +274,7 @@ static nsresult GetDisplayNameInAddressBook(const nsACString& emailAddress,
if (cardForAddress) {
bool preferDisplayName = true;
rv = cardForAddress->GetPropertyAsBool("PreferDisplayName",
rv = cardForAddress->GetPropertyAsBool("PreferDisplayName", true,
&preferDisplayName);
if (NS_FAILED(rv) || preferDisplayName)