Bug 696242 - Convert NS_RegisterStaticAtoms and nsCSSScanner::ReportUnexpectedParams to take an array-reference rather than a pointer and length, making it impossible to pass a pointer/length that are inconsistent. r=jwalden

--HG--
extra : rebase_source : 882b5b4d500b1fa242c0a3cfa3084e4171cbaa9d
This commit is contained in:
Jacob Holzinger 2012-03-08 18:22:57 -08:00
parent 08d94514e3
commit 86f648606c
27 changed files with 55 additions and 34 deletions

View File

@ -848,11 +848,22 @@ public:
* Fill (with the parameters given) the localized string named |aKey| in * Fill (with the parameters given) the localized string named |aKey| in
* properties file |aFile|. * properties file |aFile|.
*/ */
private:
static nsresult FormatLocalizedString(PropertiesFile aFile, static nsresult FormatLocalizedString(PropertiesFile aFile,
const char* aKey, const char* aKey,
const PRUnichar **aParams, const PRUnichar** aParams,
PRUint32 aParamsLength, PRUint32 aParamsLength,
nsXPIDLString& aResult); nsXPIDLString& aResult);
public:
template<PRUint32 N>
static nsresult FormatLocalizedString(PropertiesFile aFile,
const char* aKey,
const PRUnichar* (&aParams)[N],
nsXPIDLString& aResult)
{
return FormatLocalizedString(aFile, aKey, aParams, N, aResult);
}
/** /**
* Returns true if aDocument is a chrome document * Returns true if aDocument is a chrome document

View File

@ -65,6 +65,6 @@ static const nsStaticAtom GkAtoms_info[] = {
void nsGkAtoms::AddRefAtoms() void nsGkAtoms::AddRefAtoms()
{ {
NS_RegisterStaticAtoms(GkAtoms_info, ArrayLength(GkAtoms_info)); NS_RegisterStaticAtoms(GkAtoms_info);
} }

View File

@ -269,7 +269,6 @@ HandleMailtoSubject(nsCString& aPath) {
nsContentUtils::eFORMS_PROPERTIES, nsContentUtils::eFORMS_PROPERTIES,
"DefaultFormSubject", "DefaultFormSubject",
formatStrings, formatStrings,
ArrayLength(formatStrings),
subjectStr); subjectStr);
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return; return;

View File

@ -3830,7 +3830,7 @@ nsHTMLInputElement::GetValidationMessage(nsAString& aValidationMessage,
const PRUnichar* params[] = { strMaxLength.get(), strTextLength.get() }; const PRUnichar* params[] = { strMaxLength.get(), strTextLength.get() };
rv = nsContentUtils::FormatLocalizedString(nsContentUtils::eDOM_PROPERTIES, rv = nsContentUtils::FormatLocalizedString(nsContentUtils::eDOM_PROPERTIES,
"FormValidationTextTooLong", "FormValidationTextTooLong",
params, 2, message); params, message);
aValidationMessage = message; aValidationMessage = message;
break; break;
} }
@ -3889,7 +3889,7 @@ nsHTMLInputElement::GetValidationMessage(nsAString& aValidationMessage,
const PRUnichar* params[] = { title.get() }; const PRUnichar* params[] = { title.get() };
rv = nsContentUtils::FormatLocalizedString(nsContentUtils::eDOM_PROPERTIES, rv = nsContentUtils::FormatLocalizedString(nsContentUtils::eDOM_PROPERTIES,
"FormValidationPatternMismatchWithTitle", "FormValidationPatternMismatchWithTitle",
params, 1, message); params, message);
} }
aValidationMessage = message; aValidationMessage = message;
break; break;

View File

@ -1423,7 +1423,7 @@ nsHTMLTextAreaElement::GetValidationMessage(nsAString& aValidationMessage,
const PRUnichar* params[] = { strMaxLength.get(), strTextLength.get() }; const PRUnichar* params[] = { strMaxLength.get(), strTextLength.get() };
rv = nsContentUtils::FormatLocalizedString(nsContentUtils::eDOM_PROPERTIES, rv = nsContentUtils::FormatLocalizedString(nsContentUtils::eDOM_PROPERTIES,
"FormValidationTextTooLong", "FormValidationTextTooLong",
params, 2, message); params, message);
aValidationMessage = message; aValidationMessage = message;
} }
break; break;

View File

@ -4702,7 +4702,7 @@ nsGlobalWindow::MakeScriptDialogTitle(nsAString &aOutTitle)
nsXPIDLString tempString; nsXPIDLString tempString;
nsContentUtils::FormatLocalizedString(nsContentUtils::eCOMMON_DIALOG_PROPERTIES, nsContentUtils::FormatLocalizedString(nsContentUtils::eCOMMON_DIALOG_PROPERTIES,
"ScriptDlgHeading", "ScriptDlgHeading",
formatStrings, ArrayLength(formatStrings), formatStrings,
tempString); tempString);
aOutTitle = tempString; aOutTitle = tempString;
} }

View File

@ -815,7 +815,7 @@ nsJSContext::DOMOperationCallback(JSContext *cx)
const PRUnichar *formatParams[] = { filenameUTF16.get() }; const PRUnichar *formatParams[] = { filenameUTF16.get() };
rv = nsContentUtils::FormatLocalizedString(nsContentUtils::eDOM_PROPERTIES, rv = nsContentUtils::FormatLocalizedString(nsContentUtils::eDOM_PROPERTIES,
"KillScriptLocation", "KillScriptLocation",
formatParams, 1, formatParams,
scriptLocation); scriptLocation);
if (NS_SUCCEEDED(rv) && scriptLocation) { if (NS_SUCCEEDED(rv) && scriptLocation) {

View File

@ -85,5 +85,5 @@ nsEditProperty::RegisterAtoms()
#undef EDITOR_ATOM #undef EDITOR_ATOM
}; };
NS_RegisterStaticAtoms(property_atoms, ArrayLength(property_atoms)); NS_RegisterStaticAtoms(property_atoms);
} }

View File

@ -134,7 +134,7 @@ nsTextServicesDocument::RegisterAtoms()
#undef TS_ATOM #undef TS_ATOM
}; };
NS_RegisterStaticAtoms(ts_atoms, ArrayLength(ts_atoms)); NS_RegisterStaticAtoms(ts_atoms);
} }
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsTextServicesDocument) NS_IMPL_CYCLE_COLLECTING_ADDREF(nsTextServicesDocument)

View File

@ -58,5 +58,5 @@ static const nsStaticAtom atoms[] = {
void gfxAtoms::RegisterAtoms() void gfxAtoms::RegisterAtoms()
{ {
NS_RegisterStaticAtoms(atoms, ArrayLength(atoms)); NS_RegisterStaticAtoms(atoms);
} }

View File

@ -142,7 +142,7 @@ inDOMView::~inDOMView()
/* static */ void /* static */ void
inDOMView::InitAtoms() inDOMView::InitAtoms()
{ {
NS_RegisterStaticAtoms(Atoms_info, ArrayLength(Atoms_info)); NS_RegisterStaticAtoms(Atoms_info);
} }
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////

View File

@ -68,8 +68,7 @@ static const nsStaticAtom CSSAnonBoxes_info[] = {
void nsCSSAnonBoxes::AddRefAtoms() void nsCSSAnonBoxes::AddRefAtoms()
{ {
NS_RegisterStaticAtoms(CSSAnonBoxes_info, NS_RegisterStaticAtoms(CSSAnonBoxes_info);
ArrayLength(CSSAnonBoxes_info));
} }
bool nsCSSAnonBoxes::IsAnonBox(nsIAtom *aAtom) bool nsCSSAnonBoxes::IsAnonBox(nsIAtom *aAtom)

View File

@ -735,7 +735,7 @@ static void AppendRuleToSheet(css::Rule* aRule, void* aParser)
mScanner.ReportUnexpected(#msg_) mScanner.ReportUnexpected(#msg_)
#define REPORT_UNEXPECTED_P(msg_, params_) \ #define REPORT_UNEXPECTED_P(msg_, params_) \
mScanner.ReportUnexpectedParams(#msg_, params_, ArrayLength(params_)) mScanner.ReportUnexpectedParams(#msg_, params_)
#define REPORT_UNEXPECTED_EOF(lf_) \ #define REPORT_UNEXPECTED_EOF(lf_) \
mScanner.ReportUnexpectedEOF(#lf_) mScanner.ReportUnexpectedEOF(#lf_)

View File

@ -66,8 +66,7 @@ static const nsStaticAtom CSSPseudoClasses_info[] = {
void nsCSSPseudoClasses::AddRefAtoms() void nsCSSPseudoClasses::AddRefAtoms()
{ {
NS_RegisterStaticAtoms(CSSPseudoClasses_info, NS_RegisterStaticAtoms(CSSPseudoClasses_info);
ArrayLength(CSSPseudoClasses_info));
} }
bool bool

View File

@ -80,8 +80,7 @@ static const PRUint32 CSSPseudoElements_flags[] = {
void nsCSSPseudoElements::AddRefAtoms() void nsCSSPseudoElements::AddRefAtoms()
{ {
NS_RegisterStaticAtoms(CSSPseudoElements_info, NS_RegisterStaticAtoms(CSSPseudoElements_info);
ArrayLength(CSSPseudoElements_info));
} }
bool nsCSSPseudoElements::IsPseudoElement(nsIAtom *aAtom) bool nsCSSPseudoElements::IsPseudoElement(nsIAtom *aAtom)

View File

@ -547,7 +547,7 @@ nsCSSScanner::ReportUnexpectedToken(nsCSSToken& tok,
tokenString.get() tokenString.get()
}; };
ReportUnexpectedParams(aMessage, params, ArrayLength(params)); ReportUnexpectedParams(aMessage, params);
} }
// aParams's first entry must be null, and we'll fill in the token // aParams's first entry must be null, and we'll fill in the token

View File

@ -160,9 +160,19 @@ class nsCSSScanner {
// aMessage must take no parameters // aMessage must take no parameters
void ReportUnexpected(const char* aMessage); void ReportUnexpected(const char* aMessage);
private:
void ReportUnexpectedParams(const char* aMessage, void ReportUnexpectedParams(const char* aMessage,
const PRUnichar **aParams, const PRUnichar** aParams,
PRUint32 aParamsLength); PRUint32 aParamsLength);
public:
template<PRUint32 N>
void ReportUnexpectedParams(const char* aMessage,
const PRUnichar* (&aParams)[N])
{
return ReportUnexpectedParams(aMessage, aParams, N);
}
// aLookingFor is a plain string, not a format string // aLookingFor is a plain string, not a format string
void ReportUnexpectedEOF(const char* aLookingFor); void ReportUnexpectedEOF(const char* aLookingFor);
// aLookingFor is a single character // aLookingFor is a single character

View File

@ -66,5 +66,5 @@ static const nsStaticAtom Html5Atoms_info[] = {
void nsHtml5Atoms::AddRefAtoms() void nsHtml5Atoms::AddRefAtoms()
{ {
NS_RegisterStaticAtoms(Html5Atoms_info, ArrayLength(Html5Atoms_info)); NS_RegisterStaticAtoms(Html5Atoms_info);
} }

View File

@ -795,12 +795,12 @@ nsHtml5TreeOperation::Perform(nsHtml5TreeOpExecutor* aBuilder,
const PRUnichar* params[] = { atom->GetUTF16String(), const PRUnichar* params[] = { atom->GetUTF16String(),
otherAtom->GetUTF16String() }; otherAtom->GetUTF16String() };
rv = nsContentUtils::FormatLocalizedString( rv = nsContentUtils::FormatLocalizedString(
nsContentUtils::eHTMLPARSER_PROPERTIES, msgId, params, 2, message); nsContentUtils::eHTMLPARSER_PROPERTIES, msgId, params, message);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
} else if (atom) { } else if (atom) {
const PRUnichar* params[] = { atom->GetUTF16String() }; const PRUnichar* params[] = { atom->GetUTF16String() };
rv = nsContentUtils::FormatLocalizedString( rv = nsContentUtils::FormatLocalizedString(
nsContentUtils::eHTMLPARSER_PROPERTIES, msgId, params, 1, message); nsContentUtils::eHTMLPARSER_PROPERTIES, msgId, params, message);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
} else { } else {
rv = nsContentUtils::GetLocalizedString( rv = nsContentUtils::GetLocalizedString(

View File

@ -374,7 +374,7 @@ nsHTMLTags::AddRefTable(void)
if (gTableRefCount++ == 0) { if (gTableRefCount++ == 0) {
// Fill in our static atom pointers // Fill in our static atom pointers
NS_RegisterStaticAtoms(sTagAtoms_info, ArrayLength(sTagAtoms_info)); NS_RegisterStaticAtoms(sTagAtoms_info);
NS_ASSERTION(!gTagTable && !gTagAtomTable, "pre existing hash!"); NS_ASSERTION(!gTagTable && !gTagAtomTable, "pre existing hash!");

View File

@ -337,7 +337,7 @@ RDFContentSinkImpl::RDFContentSinkImpl()
rv = CallGetService(kRDFContainerUtilsCID, &gRDFContainerUtils); rv = CallGetService(kRDFContainerUtilsCID, &gRDFContainerUtils);
NS_RegisterStaticAtoms(rdf_atoms, ArrayLength(rdf_atoms)); NS_RegisterStaticAtoms(rdf_atoms);
} }
mNodeIDMap.Init(); mNodeIDMap.Init();

View File

@ -547,7 +547,7 @@ class CheckStaticAtomSizes
}; };
nsresult nsresult
NS_RegisterStaticAtoms(const nsStaticAtom* aAtoms, PRUint32 aAtomCount) RegisterStaticAtoms(const nsStaticAtom* aAtoms, PRUint32 aAtomCount)
{ {
// this does three things: // this does three things:
// 1) wraps each static atom in a wrapper, if necessary // 1) wraps each static atom in a wrapper, if necessary

View File

@ -76,8 +76,13 @@ struct nsFakeStringBuffer {
nsStaticAtomStringType mStringData[size]; nsStaticAtomStringType mStringData[size];
}; };
// Register static atoms with the atom table // Register an array of static atoms with the atom table
template<PRUint32 N>
nsresult nsresult
NS_RegisterStaticAtoms(const nsStaticAtom*, PRUint32 aAtomCount); NS_RegisterStaticAtoms(const nsStaticAtom (&atoms)[N])
{
extern nsresult RegisterStaticAtoms(const nsStaticAtom*, PRUint32 aAtomCount);
return RegisterStaticAtoms(atoms, N);
}
#endif #endif

View File

@ -307,7 +307,7 @@ nsDirectoryService::RealInit()
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return rv; return rv;
NS_RegisterStaticAtoms(directory_atoms, ArrayLength(directory_atoms)); NS_RegisterStaticAtoms(directory_atoms);
// Let the list hold the only reference to the provider. // Let the list hold the only reference to the provider.
nsAppFileLocationProvider *defaultProvider = new nsAppFileLocationProvider; nsAppFileLocationProvider *defaultProvider = new nsAppFileLocationProvider;

View File

@ -59,6 +59,5 @@ static const nsStaticAtom MoreTestingAtoms_info[] = {
void MoreTestingAtoms::AddRefAtoms() void MoreTestingAtoms::AddRefAtoms()
{ {
NS_RegisterStaticAtoms(MoreTestingAtoms_info, NS_RegisterStaticAtoms(MoreTestingAtoms_info);
mozilla::ArrayLength(MoreTestingAtoms_info));
} }

View File

@ -212,7 +212,7 @@ test_atomtable()
if (!thirdNonPerm || NS_GetNumberOfAtoms() != count + 1) if (!thirdNonPerm || NS_GetNumberOfAtoms() != count + 1)
return false; return false;
NS_RegisterStaticAtoms(sAtoms_info, ArrayLength(sAtoms_info)); NS_RegisterStaticAtoms(sAtoms_info);
return sAtom1 && return sAtom1 &&
sAtom1->Equals(NS_LITERAL_STRING(FIRST_ATOM_STR)) && sAtom1->Equals(NS_LITERAL_STRING(FIRST_ATOM_STR)) &&

View File

@ -58,5 +58,5 @@ static const nsStaticAtom TestingAtoms_info[] = {
void TestingAtoms::AddRefAtoms() void TestingAtoms::AddRefAtoms()
{ {
NS_RegisterStaticAtoms(TestingAtoms_info, mozilla::ArrayLength(TestingAtoms_info)); NS_RegisterStaticAtoms(TestingAtoms_info);
} }