Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Unified Diff: src/parsing/preparser.cc

Issue 2154253002: [parser] Refactor some CHECK_OK calls (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/parsing/preparser.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parsing/preparser.cc
diff --git a/src/parsing/preparser.cc b/src/parsing/preparser.cc
index 08d5eafd4de581828aaa0d3090f2b0db9ddb1a64..f8f06d4b4ec9afe6e79f585feb110bdf1f8f872f 100644
--- a/src/parsing/preparser.cc
+++ b/src/parsing/preparser.cc
@@ -20,6 +20,27 @@
namespace v8 {
namespace internal {
+// ----------------------------------------------------------------------------
+// The CHECK_OK macro is a convenient macro to enforce error
+// handling for functions that may fail (by returning !*ok).
+//
+// CAUTION: This macro appends extra statements after a call,
+// thus it must never be used where only a single statement
+// is correct (e.g. an if statement branch w/o braces)!
+
+#define CHECK_OK ok); \
+ if (!*ok) return Statement::Default(); \
+ ((void)0
+#define DUMMY ) // to make indentation work
+#undef DUMMY
+
+// Used in functions where the return type is not ExpressionT.
+#define CHECK_OK_CUSTOM(x) ok); \
+ if (!*ok) return this->x(); \
+ ((void)0
+#define DUMMY ) // to make indentation work
+#undef DUMMY
+
void PreParserTraits::ReportMessageAt(Scanner::Location location,
MessageTemplate::Template message,
const char* arg,
@@ -226,8 +247,7 @@ void PreParser::ParseStatementList(int end_token, bool* ok,
}
bool starts_with_identifier = peek() == Token::IDENTIFIER;
Scanner::Location token_loc = scanner()->peek_location();
- Statement statement = ParseStatementListItem(ok);
- if (!*ok) return;
+ Statement statement = ParseStatementListItem(CHECK_OK_CUSTOM(Void));
if (directive_prologue) {
bool use_strict_found = statement.IsUseStrictLiteral();
@@ -268,12 +288,6 @@ void PreParser::ParseStatementList(int end_token, bool* ok,
}
-#define CHECK_OK ok); \
- if (!*ok) return Statement::Default(); \
- ((void)0
-#define DUMMY ) // to make indentation work
-#undef DUMMY
-
PreParser::Statement PreParser::ParseStatement(
AllowLabelledFunctionStatement allow_function, bool* ok) {
// Statement ::
@@ -918,8 +932,7 @@ PreParser::Statement PreParser::ParseForStatement(bool* ok) {
ExpressionClassifier classifier(this);
Expression lhs = ParseExpression(false, &classifier, CHECK_OK);
int lhs_end_pos = scanner()->location().end_pos;
- bool is_for_each = CheckInOrOf(&mode, ok);
- if (!*ok) return Statement::Default();
+ bool is_for_each = CheckInOrOf(&mode, CHECK_OK);
bool is_destructuring = is_for_each &&
(lhs->IsArrayLiteral() || lhs->IsObjectLiteral());
@@ -1078,6 +1091,7 @@ PreParser::Statement PreParser::ParseDebuggerStatement(bool* ok) {
}
+// Redefinition of CHECK_OK for parsing expressions.
#undef CHECK_OK
#define CHECK_OK ok); \
if (!*ok) return Expression::Default(); \
@@ -1301,14 +1315,14 @@ void PreParserTraits::ParseAsyncArrowSingleExpressionBody(
Scope* scope = pre_parser_->scope_;
scope->ForceContextAllocation();
- PreParserExpression return_value =
- pre_parser_->ParseAssignmentExpression(accept_IN, classifier, ok);
- if (!*ok) return;
+ PreParserExpression return_value = pre_parser_->ParseAssignmentExpression(
+ accept_IN, classifier, CHECK_OK_CUSTOM(Void));
body->Add(PreParserStatement::ExpressionStatement(return_value), zone());
}
#undef CHECK_OK
+#undef CHECK_OK_CUSTOM
} // namespace internal
« no previous file with comments | « src/parsing/preparser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698