Bug 1320179 - Part 1: Move nsresult value calculation into a python script, r=froydnj

This patch makes the error codes in nsError.h be generated by a python script.
This gives us the opportunity to add rust code generation in parallel with the
C++ code generation, which will happen in part 2.

This patch also reworks the name calculation in ErrorNames.cpp to use generated
code by the python script.

MozReview-Commit-ID: 5wxbdZwxe7q
This commit is contained in:
Michael Layzell
2017-03-30 14:13:01 -04:00
parent 7a0e0960f1
commit dde6ff63cd
5 changed files with 1268 additions and 1208 deletions

View File

@@ -9,35 +9,17 @@
#include "nsString.h"
#include "prerror.h"
namespace {
struct ErrorEntry
{
nsresult value;
const char * name;
};
#undef ERROR
#define ERROR(key, val) {key, #key}
const ErrorEntry errors[] = {
#include "ErrorList.h"
};
#undef ERROR
} // unnamed namespace
// Get the GetErrorNameInternal method
#include "ErrorNamesInternal.h"
namespace mozilla {
void
GetErrorName(nsresult rv, nsACString& name)
{
for (size_t i = 0; i < ArrayLength(errors); ++i) {
if (errors[i].value == rv) {
name.AssignASCII(errors[i].name);
return;
}
if (const char* errorName = GetErrorNameInternal(rv)) {
name.AssignASCII(errorName);
return;
}
bool isSecurityError = NS_ERROR_GET_MODULE(rv) == NS_ERROR_MODULE_SECURITY;
@@ -82,3 +64,15 @@ GetErrorName(nsresult rv, nsACString& name)
}
} // namespace mozilla
extern "C" {
// This is an extern "C" binding for the GetErrorName method which is used by
// the nsresult rust bindings in xpcom/rust/nserror.
void
Gecko_GetErrorName(nsresult aRv, nsACString& aName)
{
GetErrorName(aRv, aName);
}
}