Bug 1530238 - Use ParseContext::checkBreakStatement in Parser. r=Yoric
authorTooru Fujisawa <arai_a@mac.com>
Tue, 26 Feb 2019 13:20:54 +0000
changeset 519037 1d2a9559d6d6c38d2ae46d8f618cba55237e48c4
parent 519036 29032f75438b955adc0849f7ac435fc1b44ff39f
child 519038 85f7a0580ce94b1d58e63485108fe7ebe54fea2b
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersYoric
bugs1530238
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1530238 - Use ParseContext::checkBreakStatement in Parser. r=Yoric Depends on D20993 Differential Revision: https://phabricator.services.mozilla.com/D20994
js/src/frontend/Parser.cpp
--- a/js/src/frontend/Parser.cpp
+++ b/js/src/frontend/Parser.cpp
@@ -6182,37 +6182,25 @@ GeneralParser<ParseHandler, Unit>::break
   MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::Break));
   uint32_t begin = pos().begin;
 
   RootedPropertyName label(cx_);
   if (!matchLabel(yieldHandling, &label)) {
     return null();
   }
 
-  // Labeled 'break' statements target the nearest labeled statements (could
-  // be any kind) with the same label. Unlabeled 'break' statements target
-  // the innermost loop or switch statement.
-  if (label) {
-    auto hasSameLabel = [&label](ParseContext::LabelStatement* stmt) {
-      return stmt->label() == label;
-    };
-
-    if (!pc_->template findInnermostStatement<ParseContext::LabelStatement>(
-            hasSameLabel)) {
-      error(JSMSG_LABEL_NOT_FOUND);
-      return null();
-    }
-  } else {
-    auto isBreakTarget = [](ParseContext::Statement* stmt) {
-      return StatementKindIsUnlabeledBreakTarget(stmt->kind());
-    };
-
-    if (!pc_->findInnermostStatement(isBreakTarget)) {
-      errorAt(begin, JSMSG_TOUGH_BREAK);
-      return null();
+  auto validity = pc_->checkBreakStatement(label);
+  if (validity.isErr()) {
+    switch (validity.unwrapErr()) {
+      case ParseContext::BreakStatementError::ToughBreak:
+        errorAt(begin, JSMSG_TOUGH_BREAK);
+        return null();
+      case ParseContext::BreakStatementError::LabelNotFound:
+        error(JSMSG_LABEL_NOT_FOUND);
+        return null();
     }
   }
 
   if (!matchOrInsertSemicolon()) {
     return null();
   }
 
   return handler_.newBreakStatement(label, TokenPos(begin, pos().end));