зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1204024 - Part 2: Restrict PossibleError to non-recoverable errors, because it's not possible to recover from a pending error. r=arai
This commit is contained in:
Родитель
f215ab0267
Коммит
567f980b29
|
@ -3719,24 +3719,21 @@ Parser<ParseHandler>::matchLabel(YieldHandling yieldHandling, MutableHandle<Prop
|
|||
|
||||
template <typename ParseHandler>
|
||||
Parser<ParseHandler>::PossibleError::PossibleError(Parser<ParseHandler>& parser)
|
||||
: parser_(parser)
|
||||
{
|
||||
state_ = ErrorState::None;
|
||||
}
|
||||
: parser_(parser),
|
||||
state_(ErrorState::None)
|
||||
{}
|
||||
|
||||
template <typename ParseHandler>
|
||||
bool
|
||||
Parser<ParseHandler>::PossibleError::setPending(ParseReportKind kind, unsigned errorNumber,
|
||||
bool strict)
|
||||
Parser<ParseHandler>::PossibleError::setPending(Node pn, unsigned errorNumber)
|
||||
{
|
||||
// Don't overwrite a previously recorded error.
|
||||
if (hasError())
|
||||
return false;
|
||||
|
||||
// If we report an error later, we'll do it from the position where we set
|
||||
// the state to pending.
|
||||
offset_ = parser_.pos().begin;
|
||||
reportKind_ = kind;
|
||||
strict_ = strict;
|
||||
offset_ = (pn ? parser_.handler.getPosition(pn) : parser_.pos()).begin;
|
||||
errorNumber_ = errorNumber;
|
||||
state_ = ErrorState::Pending;
|
||||
|
||||
|
@ -3761,27 +3758,25 @@ template <typename ParseHandler>
|
|||
bool
|
||||
Parser<ParseHandler>::PossibleError::checkForExprErrors()
|
||||
{
|
||||
bool err = hasError();
|
||||
if (err)
|
||||
parser_.reportWithOffset(reportKind_, strict_, offset_, errorNumber_);
|
||||
return !err;
|
||||
if (hasError()) {
|
||||
parser_.reportWithOffset(ParseError, false, offset_, errorNumber_);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename ParseHandler>
|
||||
void
|
||||
Parser<ParseHandler>::PossibleError::transferErrorTo(PossibleError* other)
|
||||
{
|
||||
if (other) {
|
||||
MOZ_ASSERT(this != other);
|
||||
MOZ_ASSERT(!other->hasError());
|
||||
MOZ_ASSERT(other);
|
||||
MOZ_ASSERT(this != other);
|
||||
MOZ_ASSERT(&parser_ == &other->parser_,
|
||||
"Can't transfer fields to an instance which belongs to a different parser");
|
||||
|
||||
// We should never allow fields to be copied between instances
|
||||
// that point to different underlying parsers.
|
||||
MOZ_ASSERT(&parser_ == &other->parser_);
|
||||
if (hasError() && !other->hasError()) {
|
||||
other->offset_ = offset_;
|
||||
other->reportKind_ = reportKind_;
|
||||
other->errorNumber_ = errorNumber_;
|
||||
other->strict_ = strict_;
|
||||
other->state_ = state_;
|
||||
}
|
||||
}
|
||||
|
@ -8867,7 +8862,7 @@ Parser<ParseHandler>::objectLiteral(YieldHandling yieldHandling, PossibleError*
|
|||
// Here we set a pending error so that later in the parse, once we've
|
||||
// determined whether or not we're destructuring, the error can be
|
||||
// reported or ignored appropriately.
|
||||
if (!possibleError->setPending(ParseError, JSMSG_COLON_AFTER_ID, false)) {
|
||||
if (!possibleError->setPending(null(), JSMSG_COLON_AFTER_ID)) {
|
||||
// Report any previously pending error.
|
||||
possibleError->checkForExprErrors();
|
||||
return null();
|
||||
|
|
|
@ -722,6 +722,8 @@ template <typename ParseHandler>
|
|||
class Parser final : private JS::AutoGCRooter, public StrictModeGetter
|
||||
{
|
||||
private:
|
||||
using Node = typename ParseHandler::Node;
|
||||
|
||||
/*
|
||||
* A class for temporarily stashing errors while parsing continues.
|
||||
*
|
||||
|
@ -739,12 +741,12 @@ class Parser final : private JS::AutoGCRooter, public StrictModeGetter
|
|||
*
|
||||
* Ex:
|
||||
* PossibleError possibleError(*this);
|
||||
* possibleError.setPending(ParseError, JSMSG_BAD_PROP_ID, false);
|
||||
* possibleError.setPending(pn, JSMSG_BAD_PROP_ID);
|
||||
* // A JSMSG_BAD_PROP_ID ParseError is reported, returns false.
|
||||
* possibleError.checkForExprErrors();
|
||||
*
|
||||
* PossibleError possibleError(*this);
|
||||
* possibleError.setPending(ParseError, JSMSG_BAD_PROP_ID, false);
|
||||
* possibleError.setPending(pn, JSMSG_BAD_PROP_ID);
|
||||
* possibleError.setResolved();
|
||||
* // Returns true, no error is reported.
|
||||
* possibleError.checkForExprErrors();
|
||||
|
@ -756,22 +758,21 @@ class Parser final : private JS::AutoGCRooter, public StrictModeGetter
|
|||
class MOZ_STACK_CLASS PossibleError
|
||||
{
|
||||
protected:
|
||||
Parser<ParseHandler>& parser_;
|
||||
|
||||
enum ErrorState { None, Pending };
|
||||
ErrorState state_;
|
||||
|
||||
// Error reporting fields.
|
||||
uint32_t offset_;
|
||||
unsigned errorNumber_;
|
||||
ParseReportKind reportKind_;
|
||||
Parser<ParseHandler>& parser_;
|
||||
bool strict_;
|
||||
|
||||
public:
|
||||
explicit PossibleError(Parser<ParseHandler>& parser);
|
||||
|
||||
// Set a pending error. Only a single error may be set per instance.
|
||||
// Returns true on success or false on failure.
|
||||
bool setPending(ParseReportKind kind, unsigned errorNumber, bool strict);
|
||||
bool setPending(Node pn, unsigned errorNumber);
|
||||
|
||||
// Resolve any pending error.
|
||||
void setResolved();
|
||||
|
@ -834,8 +835,6 @@ class Parser final : private JS::AutoGCRooter, public StrictModeGetter
|
|||
/* Unexpected end of input, i.e. TOK_EOF not at top-level. */
|
||||
bool isUnexpectedEOF_:1;
|
||||
|
||||
typedef typename ParseHandler::Node Node;
|
||||
|
||||
public:
|
||||
/* State specific to the kind of parse being performed. */
|
||||
ParseHandler handler;
|
||||
|
|
Загрузка…
Ссылка в новой задаче