Bug 1447914 - Change FunctionCall::getAtomName() to appendName(). r=froydnj

getAtomName() is only used in one place -- FunctionCall::toString() -- where
the returned atom is appended to a string. This patch changes it to
appendName(), which does the appending itself. This avoids a bunch of manual
atom refcounting and the possibility of failure.

MozReview-Commit-ID: I75rO1Bv6Y8

--HG--
extra : rebase_source : ef78377db12b2e89c582e32836d3abd460bde7d0
This commit is contained in:
Nicholas Nethercote 2018-03-23 08:05:29 +11:00
parent feca6aae6f
commit e7236b0cc6
12 changed files with 42 additions and 67 deletions

View File

@ -734,10 +734,9 @@ txCoreFunctionCall::getTypeFromAtom(nsAtom* aName, eType& aType)
}
#ifdef TX_TO_STRING
nsresult
txCoreFunctionCall::getNameAtom(nsAtom** aAtom)
void
txCoreFunctionCall::appendName(nsAString& aDest)
{
NS_ADDREF(*aAtom = *descriptTable[mType].mName);
return NS_OK;
aDest.Append((*descriptTable[mType].mName)->GetUTF16String());
}
#endif

View File

@ -140,11 +140,11 @@ public:
#ifdef TX_TO_STRING
#define TX_DECL_TOSTRING \
void toString(nsAString& aDest) override;
#define TX_DECL_GETNAMEATOM \
nsresult getNameAtom(nsAtom** aAtom) override;
#define TX_DECL_APPENDNAME \
void appendName(nsAString& aDest) override;
#else
#define TX_DECL_TOSTRING
#define TX_DECL_GETNAMEATOM
#define TX_DECL_APPENDNAME
#endif
#define TX_DECL_EXPR_BASE \
@ -163,7 +163,7 @@ public:
ExprType getType() override;
#define TX_DECL_FUNCTION \
TX_DECL_GETNAMEATOM \
TX_DECL_APPENDNAME \
TX_DECL_EXPR_BASE
#define TX_IMPL_EXPR_STUBS_BASE(_class, _ReturnType) \
@ -313,9 +313,9 @@ protected:
#ifdef TX_TO_STRING
/*
* Returns the name of the function as an atom.
* Appends the name of the function to `aStr`.
*/
virtual nsresult getNameAtom(nsAtom** aAtom) = 0;
virtual void appendName(nsAString& aStr) = 0;
#endif
};

View File

@ -112,16 +112,8 @@ FunctionCall::argsSensitiveTo(ContextSensitivity aContext)
void
FunctionCall::toString(nsAString& aDest)
{
RefPtr<nsAtom> functionNameAtom;
if (NS_FAILED(getNameAtom(getter_AddRefs(functionNameAtom)))) {
NS_ERROR("Can't get function name.");
return;
}
aDest.Append(nsDependentAtomString(functionNameAtom) +
NS_LITERAL_STRING("("));
appendName(aDest);
aDest.AppendLiteral("(");
for (uint32_t i = 0; i < mParams.Length(); ++i) {
if (i != 0) {
aDest.Append(char16_t(','));

View File

@ -610,11 +610,9 @@ txXPCOMExtensionFunctionCall::isSensitiveTo(ContextSensitivity aContext)
}
#ifdef TX_TO_STRING
nsresult
txXPCOMExtensionFunctionCall::getNameAtom(nsAtom** aAtom)
void
txXPCOMExtensionFunctionCall::appendName(nsAString& aDest)
{
NS_ADDREF(*aAtom = mName);
return NS_OK;
aDest.Append(mName->GetUTF16String());
}
#endif

View File

@ -55,11 +55,9 @@ CurrentFunctionCall::isSensitiveTo(ContextSensitivity aContext)
}
#ifdef TX_TO_STRING
nsresult
CurrentFunctionCall::getNameAtom(nsAtom** aAtom)
void
CurrentFunctionCall::appendName(nsAString& aDest)
{
*aAtom = nsGkAtoms::current;
NS_ADDREF(*aAtom);
return NS_OK;
aDest.Append(nsGkAtoms::current->GetUTF16String());
}
#endif

View File

@ -157,11 +157,9 @@ DocumentFunctionCall::isSensitiveTo(ContextSensitivity aContext)
}
#ifdef TX_TO_STRING
nsresult
DocumentFunctionCall::getNameAtom(nsAtom** aAtom)
void
DocumentFunctionCall::appendName(nsAString& aDest)
{
*aAtom = nsGkAtoms::document;
NS_ADDREF(*aAtom);
return NS_OK;
aDest.Append(nsGkAtoms::document->GetUTF16String());
}
#endif

View File

@ -689,11 +689,10 @@ txEXSLTFunctionCall::isSensitiveTo(ContextSensitivity aContext)
}
#ifdef TX_TO_STRING
nsresult
txEXSLTFunctionCall::getNameAtom(nsAtom **aAtom)
void
txEXSLTFunctionCall::appendName(nsAString& aDest)
{
NS_ADDREF(*aAtom = *descriptTable[mType].mName);
return NS_OK;
aDest.Append((*descriptTable[mType].mName)->GetUTF16String());
}
#endif

View File

@ -388,12 +388,10 @@ txFormatNumberFunctionCall::isSensitiveTo(ContextSensitivity aContext)
}
#ifdef TX_TO_STRING
nsresult
txFormatNumberFunctionCall::getNameAtom(nsAtom** aAtom)
void
txFormatNumberFunctionCall::appendName(nsAString& aDest)
{
*aAtom = nsGkAtoms::formatNumber;
NS_ADDREF(*aAtom);
return NS_OK;
aDest.Append(nsGkAtoms::formatNumber->GetUTF16String());
}
#endif

View File

@ -104,11 +104,9 @@ GenerateIdFunctionCall::isSensitiveTo(ContextSensitivity aContext)
}
#ifdef TX_TO_STRING
nsresult
GenerateIdFunctionCall::getNameAtom(nsAtom** aAtom)
void
GenerateIdFunctionCall::appendName(nsAString& aDest)
{
*aAtom = nsGkAtoms::generateId;
NS_ADDREF(*aAtom);
return NS_OK;
aDest.Append(nsGkAtoms::generateId->GetUTF16String());
}
#endif

View File

@ -110,12 +110,10 @@ txKeyFunctionCall::isSensitiveTo(ContextSensitivity aContext)
}
#ifdef TX_TO_STRING
nsresult
txKeyFunctionCall::getNameAtom(nsAtom** aAtom)
void
txKeyFunctionCall::appendName(nsAString& aDest)
{
*aAtom = nsGkAtoms::key;
NS_ADDREF(*aAtom);
return NS_OK;
aDest.Append(nsGkAtoms::key->GetUTF16String());
}
#endif

View File

@ -891,12 +891,10 @@ txErrorFunctionCall::isSensitiveTo(ContextSensitivity aContext)
}
#ifdef TX_TO_STRING
nsresult
txErrorFunctionCall::getNameAtom(nsAtom** aAtom)
void
txErrorFunctionCall::appendName(nsAString& aDest)
{
NS_IF_ADDREF(*aAtom = mName);
return NS_OK;
aDest.Append(mName->GetUTF16String());
}
#endif

View File

@ -125,14 +125,13 @@ txXSLTEnvironmentFunctionCall::isSensitiveTo(ContextSensitivity aContext)
}
#ifdef TX_TO_STRING
nsresult
txXSLTEnvironmentFunctionCall::getNameAtom(nsAtom** aAtom)
void
txXSLTEnvironmentFunctionCall::appendName(nsAString& aDest)
{
*aAtom = mType == SYSTEM_PROPERTY ? nsGkAtoms::systemProperty :
mType == ELEMENT_AVAILABLE ? nsGkAtoms::elementAvailable :
nsGkAtoms::functionAvailable;
NS_ADDREF(*aAtom);
return NS_OK;
nsStaticAtom* atom =
mType == SYSTEM_PROPERTY ? nsGkAtoms::systemProperty :
mType == ELEMENT_AVAILABLE ? nsGkAtoms::elementAvailable :
nsGkAtoms::functionAvailable;
aDest.Append(atom->GetUTF16String());
}
#endif