Bug 1839396 part 1 - Explicit Sprinter::forwardOutOfMemory(). r=mgaudet

This change move the error reporting to the JSContext to be an independent
function, such that we can later migrate `Sprinter::put` to become infallible.

Differential Revision: https://phabricator.services.mozilla.com/D181486
This commit is contained in:
Nicolas B. Pierron 2023-09-20 17:00:03 +00:00
Родитель 9a400afd70
Коммит df269a464c
2 изменённых файлов: 13 добавлений и 1 удалений

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

@ -134,6 +134,13 @@ class JS_PUBLIC_API Sprinter final : public GenericPrinter {
// first call to this function calls JS_ReportOutOfMemory, and sets this
// Sprinter's outOfMemory flag; subsequent calls do nothing.
virtual void reportOutOfMemory() override;
// When an OOM has already been reported on the Sprinter, this function will
// forward this error to the JSContext given in the Sprinter initialization.
//
// If no JSContext had been provided or the Sprinter is configured to not
// report OOM, then nothing happens.
void forwardOutOfMemory();
};
// Fprinter, print a string directly into a file.

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

@ -223,10 +223,15 @@ void Sprinter::reportOutOfMemory() {
if (hadOOM_) {
return;
}
hadOOM_ = true;
forwardOutOfMemory();
}
void Sprinter::forwardOutOfMemory() {
MOZ_ASSERT(hadOOM_);
if (maybeCx && shouldReportOOM) {
ReportOutOfMemory(maybeCx);
}
hadOOM_ = true;
}
bool Sprinter::jsprintf(const char* format, ...) {