Bug 1629293 - Make JS::PrintError take either JSErrorReport or JS::ErrorReportBuilder. r=evilpie

From the existing usage of the function, it seems like it should either
take a JSErrorReport with no toStringResult, or a JS::ErrorReportBuilder
where it can get both the JSErrorReport and the toStringResult.

Differential Revision: https://phabricator.services.mozilla.com/D73523
This commit is contained in:
Philip Chimento 2020-05-13 16:11:48 +00:00
Родитель d6b8de58f7
Коммит 491271880d
8 изменённых файлов: 33 добавлений и 24 удалений

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

@ -306,9 +306,9 @@ struct MOZ_STACK_CLASS JS_PUBLIC_API ErrorReportBuilder {
bool init(JSContext* cx, const JS::ExceptionStack& exnStack,
SniffingBehavior sniffingBehavior);
JSErrorReport* report() { return reportp; }
JSErrorReport* report() const { return reportp; }
const JS::ConstUTF8CharsZ toStringResult() { return toStringResult_; }
const JS::ConstUTF8CharsZ toStringResult() const { return toStringResult_; }
private:
// More or less an equivalent of JS_ReportErrorNumber/js::ReportErrorNumberVA
@ -348,10 +348,13 @@ struct MOZ_STACK_CLASS JS_PUBLIC_API ErrorReportBuilder {
// Writes a full report to a file descriptor. Does nothing for JSErrorReports
// which are warnings, unless reportWarnings is set.
extern JS_PUBLIC_API void PrintError(JSContext* cx, FILE* file,
ConstUTF8CharsZ toStringResult,
JSErrorReport* report,
bool reportWarnings);
extern JS_PUBLIC_API void PrintError(JSContext* cx, FILE* file,
const JS::ErrorReportBuilder& builder,
bool reportWarnings);
} // namespace JS
#endif /* js_ErrorReport_h */

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

@ -399,8 +399,7 @@ void runTestFromPath(JSContext* cx, const char* path) {
MOZ_CRASH("Couldn't report txtExn");
}
PrintError(cx, stderr, report.toStringResult(), report.report(),
/* reportWarnings */ true);
PrintError(cx, stderr, report, /* reportWarnings */ true);
MOZ_CRASH("Binary parser accepted a file that text parser rejected");
}
@ -412,8 +411,7 @@ void runTestFromPath(JSContext* cx, const char* path) {
MOZ_CRASH("Couldn't report binExn");
}
PrintError(cx, stderr, report.toStringResult(), report.report(),
/* reportWarnings */ true);
PrintError(cx, stderr, report, /* reportWarnings */ true);
MOZ_CRASH("Binary parser rejected a file that text parser accepted");
}

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

@ -52,8 +52,7 @@ BEGIN_TEST(testPrintError_Works) {
JS::ErrorReportBuilder builder(cx);
CHECK(builder.init(cx, exnStack, JS::ErrorReportBuilder::NoSideEffects));
JS::PrintError(cx, buf.stream(), builder.toStringResult(), builder.report(),
false);
JS::PrintError(cx, buf.stream(), builder, false);
CHECK(buf.contains("testPrintError_Works.js:3:1 uncaught exception: null\n"));
@ -72,7 +71,7 @@ static bool warningSuccess;
static void warningReporter(JSContext* cx, JSErrorReport* report) {
AutoStreamBuffer buf;
JS::PrintError(cx, buf.stream(), JS::ConstUTF8CharsZ(), report, false);
JS::PrintError(cx, buf.stream(), report, false);
warningSuccess = buf.contains("");
}
END_TEST(testPrintError_SkipWarning)
@ -90,7 +89,7 @@ static bool warningSuccess;
static void warningReporter(JSContext* cx, JSErrorReport* report) {
AutoStreamBuffer buf;
JS::PrintError(cx, buf.stream(), JS::ConstUTF8CharsZ(), report, true);
JS::PrintError(cx, buf.stream(), report, true);
warningSuccess = buf.contains("warning: warning message\n");
}
END_TEST(testPrintError_PrintWarning)
@ -112,8 +111,7 @@ BEGIN_TEST(testPrintError_UTF16CodePoints) {
JS::ErrorReportBuilder builder(cx);
CHECK(builder.init(cx, exnStack, JS::ErrorReportBuilder::NoSideEffects));
JS::PrintError(cx, buf.stream(), builder.toStringResult(), builder.report(),
false);
JS::PrintError(cx, buf.stream(), builder, false);
CHECK(buf.contains(
"testPrintError_UTF16CodePoints.js:3:4 SyntaxError: illegal character:\n"

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

@ -288,7 +288,7 @@ void js::ErrorToException(JSContext* cx, JSErrorReport* reportp,
// cannot construct the Error constructor without self-hosted code. Just
// print the error to stderr to help debugging.
if (cx->realm()->isSelfHostingRealm()) {
JS::PrintError(cx, stderr, JS::ConstUTF8CharsZ(), reportp, true);
JS::PrintError(cx, stderr, reportp, true);
return;
}

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

@ -9742,8 +9742,7 @@ js::shell::AutoReportException::~AutoReportException() {
MOZ_ASSERT(!report.report()->isWarning());
FILE* fp = ErrorFilePointer();
JS::PrintError(cx, fp, report.toStringResult(), report.report(),
reportWarnings);
JS::PrintError(cx, fp, report, reportWarnings);
JS_ClearPendingException(cx);
if (!PrintStackTrace(cx, exnStack.stack())) {
@ -9783,7 +9782,7 @@ void js::shell::WarningReporter(JSContext* cx, JSErrorReport* report) {
}
// Print the warning.
JS::PrintError(cx, fp, JS::ConstUTF8CharsZ(), report, reportWarnings);
JS::PrintError(cx, fp, report, reportWarnings);
}
static bool global_enumerate(JSContext* cx, JS::HandleObject obj,

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

@ -43,8 +43,7 @@ static void CrashOnPendingException() {
fprintf(stderr, "out of memory initializing JS::ErrorReportBuilder\n");
fflush(stderr);
} else {
JS::PrintError(gCx, stderr, report.toStringResult(), report.report(),
js::shell::reportWarnings);
JS::PrintError(gCx, stderr, report, js::shell::reportWarnings);
if (!js::shell::PrintStackTrace(gCx, exnStack.stack())) {
fputs("(Unable to print stack trace)\n", stderr);
}

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

@ -476,9 +476,9 @@ static void PrintSingleError(JSContext* cx, FILE* file,
fflush(file);
}
JS_PUBLIC_API void JS::PrintError(JSContext* cx, FILE* file,
JS::ConstUTF8CharsZ toStringResult,
JSErrorReport* report, bool reportWarnings) {
static void PrintErrorImpl(JSContext* cx, FILE* file,
JS::ConstUTF8CharsZ toStringResult,
JSErrorReport* report, bool reportWarnings) {
MOZ_ASSERT(report);
/* Conditionally ignore reported warnings. */
@ -500,6 +500,18 @@ JS_PUBLIC_API void JS::PrintError(JSContext* cx, FILE* file,
}
}
JS_PUBLIC_API void JS::PrintError(JSContext* cx, FILE* file,
JSErrorReport* report, bool reportWarnings) {
PrintErrorImpl(cx, file, JS::ConstUTF8CharsZ(), report, reportWarnings);
}
JS_PUBLIC_API void JS::PrintError(JSContext* cx, FILE* file,
const JS::ErrorReportBuilder& builder,
bool reportWarnings) {
PrintErrorImpl(cx, file, builder.toStringResult(), builder.report(),
reportWarnings);
}
void js::ReportIsNotDefined(JSContext* cx, HandleId id) {
if (UniqueChars printable =
IdToPrintableUTF8(cx, id, IdToPrintableBehavior::IdIsIdentifier)) {

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

@ -109,7 +109,7 @@ using mozilla::Maybe;
static void selfHosting_WarningReporter(JSContext* cx, JSErrorReport* report) {
MOZ_ASSERT(report->isWarning());
JS::PrintError(cx, stderr, JS::ConstUTF8CharsZ(), report, true);
JS::PrintError(cx, stderr, report, true);
}
static bool intrinsic_ToObject(JSContext* cx, unsigned argc, Value* vp) {
@ -2602,7 +2602,7 @@ static void MaybePrintAndClearPendingException(JSContext* cx, FILE* file) {
}
MOZ_ASSERT(!report.report()->isWarning());
JS::PrintError(cx, file, report.toStringResult(), report.report(), true);
JS::PrintError(cx, file, report, true);
}
class MOZ_STACK_CLASS AutoSelfHostingErrorReporter {