Bug 1773324 - Separate use of JSContext for allocation into its own parameter r=arai

Differential Revision: https://phabricator.services.mozilla.com/D149996
This commit is contained in:
Bryan Thrall 2022-07-25 18:57:29 +00:00
Родитель 0c6e2a1839
Коммит 5c931e7083
7 изменённых файлов: 44 добавлений и 33 удалений

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

@ -144,7 +144,7 @@ class ErrorReportMixin : public StrictModeGetter {
return;
}
ReportCompileErrorLatin1(getContext(), std::move(metadata),
ReportCompileErrorLatin1(getContext(), getContext(), std::move(metadata),
std::move(notes), errorNumber, args);
}
@ -298,7 +298,7 @@ class ErrorReportMixin : public StrictModeGetter {
return false;
}
ReportCompileErrorLatin1(getContext(), std::move(metadata),
ReportCompileErrorLatin1(getContext(), getContext(), std::move(metadata),
std::move(notes), errorNumber, args);
return false;
}
@ -307,7 +307,7 @@ class ErrorReportMixin : public StrictModeGetter {
[[nodiscard]] bool compileWarning(ErrorMetadata&& metadata,
UniquePtr<JSErrorNotes> notes,
unsigned errorNumber, va_list* args) {
return ReportCompileWarning(getContext(), std::move(metadata),
return ReportCompileWarning(getContext(), getContext(), std::move(metadata),
std::move(notes), errorNumber, args);
}
};

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

@ -546,7 +546,7 @@ void ReportSmooshCompileError(JSContext* cx, ErrorMetadata&& metadata,
int errorNumber, ...) {
va_list args;
va_start(args, errorNumber);
ReportCompileErrorUTF8(cx, std::move(metadata), /* notes = */ nullptr,
ReportCompileErrorUTF8(cx, cx, std::move(metadata), /* notes = */ nullptr,
errorNumber, &args);
va_end(args);
}

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

@ -609,7 +609,8 @@ void TokenStreamAnyChars::reportErrorNoOffsetVA(unsigned errorNumber,
ErrorMetadata metadata;
computeErrorMetadataNoOffset(&metadata);
ReportCompileErrorLatin1(cx, std::move(metadata), nullptr, errorNumber, args);
ReportCompileErrorLatin1(cx, cx, std::move(metadata), nullptr, errorNumber,
args);
}
[[nodiscard]] MOZ_ALWAYS_INLINE bool
@ -1039,8 +1040,8 @@ MOZ_COLD void TokenStreamChars<Utf8Unit, AnyCharsAccess>::internalEncodingError(
break;
}
ReportCompileErrorLatin1(anyChars.cx, std::move(err), std::move(notes),
errorNumber, &args);
ReportCompileErrorLatin1(anyChars.cx, anyChars.cx, std::move(err),
std::move(notes), errorNumber, &args);
} while (false);
va_end(args);

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

@ -259,8 +259,8 @@ static void ReportSyntaxError(TokenStreamAnyChars& ts,
va_list args;
va_start(args, length);
ReportCompileErrorLatin1(ts.context(), std::move(err), nullptr, errorNumber,
&args);
ReportCompileErrorLatin1(ts.context(), ts.context(), std::move(err), nullptr,
errorNumber, &args);
va_end(args);
}

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

@ -52,7 +52,8 @@ bool js::ReportExceptionClosure::operator()(JSContext* cx) {
return false;
}
bool js::ReportCompileWarning(JSContext* cx, ErrorMetadata&& metadata,
bool js::ReportCompileWarning(JSContext* cx, JSAllocator* alloc,
ErrorMetadata&& metadata,
UniquePtr<JSErrorNotes> notes,
unsigned errorNumber, va_list* args) {
// On the main thread, report the error immediately. When compiling off
@ -90,7 +91,8 @@ bool js::ReportCompileWarning(JSContext* cx, ErrorMetadata&& metadata,
return true;
}
static void ReportCompileErrorImpl(JSContext* cx, js::ErrorMetadata&& metadata,
static void ReportCompileErrorImpl(JSContext* cx, JSAllocator* alloc,
js::ErrorMetadata&& metadata,
js::UniquePtr<JSErrorNotes> notes,
unsigned errorNumber, va_list* args,
ErrorArgumentsType argumentsType) {
@ -117,8 +119,8 @@ static void ReportCompileErrorImpl(JSContext* cx, js::ErrorMetadata&& metadata,
metadata.tokenOffset);
}
if (!js::ExpandErrorArgumentsVA(cx, js::GetErrorMessage, nullptr, errorNumber,
argumentsType, err, *args)) {
if (!js::ExpandErrorArgumentsVA(alloc, js::GetErrorMessage, nullptr,
errorNumber, argumentsType, err, *args)) {
return;
}
@ -132,18 +134,20 @@ static void ReportCompileErrorImpl(JSContext* cx, js::ErrorMetadata&& metadata,
}
}
void js::ReportCompileErrorLatin1(JSContext* cx, ErrorMetadata&& metadata,
void js::ReportCompileErrorLatin1(JSContext* cx, JSAllocator* alloc,
ErrorMetadata&& metadata,
UniquePtr<JSErrorNotes> notes,
unsigned errorNumber, va_list* args) {
ReportCompileErrorImpl(cx, std::move(metadata), std::move(notes), errorNumber,
args, ArgumentsAreLatin1);
ReportCompileErrorImpl(cx, alloc, std::move(metadata), std::move(notes),
errorNumber, args, ArgumentsAreLatin1);
}
void js::ReportCompileErrorUTF8(JSContext* cx, ErrorMetadata&& metadata,
void js::ReportCompileErrorUTF8(JSContext* cx, JSAllocator* alloc,
ErrorMetadata&& metadata,
UniquePtr<JSErrorNotes> notes,
unsigned errorNumber, va_list* args) {
ReportCompileErrorImpl(cx, std::move(metadata), std::move(notes), errorNumber,
args, ArgumentsAreUTF8);
ReportCompileErrorImpl(cx, alloc, std::move(metadata), std::move(notes),
errorNumber, args, ArgumentsAreUTF8);
}
void js::ReportErrorToGlobal(JSContext* cx, Handle<GlobalObject*> global,
@ -248,7 +252,7 @@ class MOZ_RAII AutoMessageArgs {
* if argsArg were strongly typed we'd still need casting below for this to
* compile, because typeArg is not known at compile-time here.
*/
bool init(JSContext* cx, void* argsArg, uint16_t countArg,
bool init(JSAllocator* alloc, void* argsArg, uint16_t countArg,
ErrorArgumentsType typeArg, va_list ap) {
MOZ_ASSERT(countArg > 0);
@ -271,7 +275,7 @@ class MOZ_RAII AutoMessageArgs {
const Latin1Char* latin1 = va_arg(ap, Latin1Char*);
size_t len = strlen(reinterpret_cast<const char*>(latin1));
mozilla::Range<const Latin1Char> range(latin1, len);
char* utf8 = JS::CharsToNewUTF8CharsZ(cx, range).c_str();
char* utf8 = JS::CharsToNewUTF8CharsZ(alloc, range).c_str();
if (!utf8) {
return false;
}
@ -287,7 +291,7 @@ class MOZ_RAII AutoMessageArgs {
: va_arg(ap, const char16_t*);
size_t len = js_strlen(uc);
mozilla::Range<const char16_t> range(uc, len);
char* utf8 = JS::CharsToNewUTF8CharsZ(cx, range).c_str();
char* utf8 = JS::CharsToNewUTF8CharsZ(alloc, range).c_str();
if (!utf8) {
return false;
}
@ -333,7 +337,7 @@ static bool ExpandErrorArgumentsHelper(JSContext* cx, JSErrorCallback callback,
}
{
gc::AutoSuppressGC suppressGC(cx);
gc::AutoSuppressGC suppressGC(cx); // TODO bug 1773324 remove JSContext use
efs = callback(userRef, errorNumber);
}
@ -474,14 +478,14 @@ bool js::ReportErrorNumberVA(JSContext* cx, IsWarning isWarning,
JSErrorReport report;
report.isWarning_ = isWarning == IsWarning::Yes;
report.errorNumber = errorNumber;
PopulateReportBlame(cx, &report);
PopulateReportBlame(cx, &report); // TODO bug 1773324
if (!ExpandErrorArgumentsVA(cx, callback, userRef, errorNumber, argumentsType,
&report, ap)) {
return false;
}
ReportError(cx, &report, callback, userRef);
ReportError(cx, &report, callback, userRef); // TODO bug 1773324
return report.isWarning();
}

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

@ -18,6 +18,12 @@
namespace js {
/**
* Use this type instead of JSContext when the object is only used for its
* ability to allocate memory (via its MallocProvider methods).
*/
using JSAllocator = JSContext;
/**
* Metadata for a compilation error (or warning) at a particular offset, or at
* no offset (i.e. with respect to a script overall).
@ -83,11 +89,13 @@ extern void CallWarningReporter(JSContext* cx, JSErrorReport* report);
* Report a compile error during script processing prior to execution of the
* script.
*/
extern void ReportCompileErrorLatin1(JSContext* cx, ErrorMetadata&& metadata,
extern void ReportCompileErrorLatin1(JSContext* cx, JSAllocator* alloc,
ErrorMetadata&& metadata,
UniquePtr<JSErrorNotes> notes,
unsigned errorNumber, va_list* args);
extern void ReportCompileErrorUTF8(JSContext* cx, ErrorMetadata&& metadata,
extern void ReportCompileErrorUTF8(JSContext* cx, JSAllocator* alloc,
ErrorMetadata&& metadata,
UniquePtr<JSErrorNotes> notes,
unsigned errorNumber, va_list* args);
@ -96,11 +104,9 @@ extern void ReportCompileErrorUTF8(JSContext* cx, ErrorMetadata&& metadata,
* script. Returns true if the warning was successfully reported, false if an
* error occurred.
*/
[[nodiscard]] extern bool ReportCompileWarning(JSContext* cx,
ErrorMetadata&& metadata,
UniquePtr<JSErrorNotes> notes,
unsigned errorNumber,
va_list* args);
[[nodiscard]] extern bool ReportCompileWarning(
JSContext* cx, JSAllocator* alloc, ErrorMetadata&& metadata,
UniquePtr<JSErrorNotes> notes, unsigned errorNumber, va_list* args);
class GlobalObject;

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

@ -1931,7 +1931,7 @@ class MOZ_STACK_CLASS ModuleValidator : public ModuleValidatorShared {
ErrorMetadata metadata;
if (ts.computeErrorMetadata(&metadata, AsVariant(offset))) {
if (ts.anyCharsAccess().options().throwOnAsmJSValidationFailureOption) {
ReportCompileErrorLatin1(cx_, std::move(metadata), nullptr,
ReportCompileErrorLatin1(cx_, cx_, std::move(metadata), nullptr,
JSMSG_USE_ASM_TYPE_FAIL, &args);
} else {
// asm.js type failure is indicated by calling one of the fail*