Bug 1773324 - Provide Parser ErrorContext as a constructor parameter. r=arai

This allows the Parser creator to provide the ErrorContext appropriate
for the situation (main thread or helper thread). For now, we just use
a flexible implementation.

I think the lifetime of the ErrorContext is the same as the Parser, so
putting the ErrorContext on the stack when the Parser is, too, should be
safe.

Differential Revision: https://phabricator.services.mozilla.com/D150642
This commit is contained in:
Bryan Thrall
2022-07-25 18:57:30 +00:00
parent 74613ebb60
commit 473d39f7e9
8 changed files with 49 additions and 30 deletions

View File

@@ -175,6 +175,7 @@
#include "vm/ArgumentsObject.h"
#include "vm/Compression.h"
#include "vm/ErrorObject.h"
#include "vm/ErrorReporting.h"
#include "vm/HelperThreads.h"
#include "vm/JSAtom.h"
#include "vm/JSContext.h"
@@ -5757,7 +5758,8 @@ static bool DumpAST(JSContext* cx, const JS::ReadOnlyCompileOptions& options,
js::frontend::ParseGoal goal) {
using namespace js::frontend;
Parser<FullParseHandler, Unit> parser(cx, options, units, length,
GeneralErrorContext ec(cx);
Parser<FullParseHandler, Unit> parser(cx, &ec, options, units, length,
/* foldConstants = */ false,
compilationState,
/* syntaxParser = */ nullptr);
@@ -6119,8 +6121,9 @@ static bool SyntaxParse(JSContext* cx, unsigned argc, Value* vp) {
return false;
}
GeneralErrorContext ec(cx);
Parser<frontend::SyntaxParseHandler, char16_t> parser(
cx, options, chars, length,
cx, &ec, options, chars, length,
/* foldConstants = */ false, compilationState,
/* syntaxParser = */ nullptr);
if (!parser.checkOptions()) {