From 8d209e7ee46440f2bf8bbea3421cdf53808353f7 Mon Sep 17 00:00:00 2001 From: Jason Orendorff Date: Thu, 22 Oct 2015 16:17:39 -0500 Subject: [PATCH] Bug 1221737 - Drop some BytecodeEmitter checks for cases that the Parser rules out. r=jonco. --HG-- extra : commitid : AdGjcp4XF2w extra : rebase_source : 29da4df939bcdf4a078f55a87c8f8eb12bf9091f --- js/src/frontend/BytecodeEmitter.cpp | 22 ++++------------------ js/src/frontend/BytecodeEmitter.h | 3 --- js/src/js.msg | 5 ++--- 3 files changed, 6 insertions(+), 24 deletions(-) diff --git a/js/src/frontend/BytecodeEmitter.cpp b/js/src/frontend/BytecodeEmitter.cpp index 4a49a5d49ec3..e5e768d64d31 100644 --- a/js/src/frontend/BytecodeEmitter.cpp +++ b/js/src/frontend/BytecodeEmitter.cpp @@ -8034,13 +8034,11 @@ BytecodeEmitter::emitTree(ParseNode* pn, EmitLineNumberNote emitLineNote) break; case PNK_IMPORT: - if (!checkIsModule()) - return false; + MOZ_ASSERT(sc->isModuleBox()); break; case PNK_EXPORT: - if (!checkIsModule()) - return false; + MOZ_ASSERT(sc->isModuleBox()); if (pn->pn_kid->getKind() != PNK_EXPORT_SPEC_LIST) { if (!emitTree(pn->pn_kid)) return false; @@ -8048,8 +8046,7 @@ BytecodeEmitter::emitTree(ParseNode* pn, EmitLineNumberNote emitLineNote) break; case PNK_EXPORT_DEFAULT: - if (!checkIsModule()) - return false; + MOZ_ASSERT(sc->isModuleBox()); if (!emitTree(pn->pn_kid)) return false; if (pn->pn_right) { @@ -8061,8 +8058,7 @@ BytecodeEmitter::emitTree(ParseNode* pn, EmitLineNumberNote emitLineNote) break; case PNK_EXPORT_FROM: - if (!checkIsModule()) - return false; + MOZ_ASSERT(sc->isModuleBox()); break; case PNK_ARRAYPUSH: @@ -8170,16 +8166,6 @@ BytecodeEmitter::emitTree(ParseNode* pn, EmitLineNumberNote emitLineNote) return true; } -bool -BytecodeEmitter::checkIsModule() -{ - if (!sc->isModuleBox()) { - reportError(nullptr, JSMSG_INVALID_OUTSIDE_MODULE); - return false; - } - return true; -} - static bool AllocSrcNote(ExclusiveContext* cx, SrcNotesVector& notes, unsigned* index) { diff --git a/js/src/frontend/BytecodeEmitter.h b/js/src/frontend/BytecodeEmitter.h index 2d33fdec4c0b..4e00f5583811 100644 --- a/js/src/frontend/BytecodeEmitter.h +++ b/js/src/frontend/BytecodeEmitter.h @@ -351,9 +351,6 @@ struct BytecodeEmitter // Emit module code for the tree rooted at body. bool emitModuleScript(ParseNode* body); - // Report an error if we are not processing a module. - bool checkIsModule(); - // If op is JOF_TYPESET (see the type barriers comment in TypeInference.h), // reserve a type set to store its result. void checkTypeSet(JSOp op); diff --git a/js/src/js.msg b/js/src/js.msg index 988aed7e09ec..b7a7b42e1493 100644 --- a/js/src/js.msg +++ b/js/src/js.msg @@ -255,16 +255,15 @@ MSG_DEF(JSMSG_DUPLICATE_LABEL, 0, JSEXN_SYNTAXERR, "duplicate label") MSG_DEF(JSMSG_DUPLICATE_PROPERTY, 1, JSEXN_SYNTAXERR, "property name {0} appears more than once in object literal") MSG_DEF(JSMSG_EMPTY_CONSEQUENT, 0, JSEXN_SYNTAXERR, "mistyped ; after conditional?") MSG_DEF(JSMSG_EQUAL_AS_ASSIGN, 0, JSEXN_SYNTAXERR, "test for equality (==) mistyped as assignment (=)?") -MSG_DEF(JSMSG_EXPORT_DECL_AT_TOP_LEVEL,0, JSEXN_SYNTAXERR, "export declarations may only appear at top level") +MSG_DEF(JSMSG_EXPORT_DECL_AT_TOP_LEVEL,0, JSEXN_SYNTAXERR, "export declarations may only appear at top level of a module") MSG_DEF(JSMSG_FINALLY_WITHOUT_TRY, 0, JSEXN_SYNTAXERR, "finally without try") MSG_DEF(JSMSG_FROM_AFTER_IMPORT_CLAUSE, 0, JSEXN_SYNTAXERR, "missing keyword 'from' after import clause") MSG_DEF(JSMSG_FROM_AFTER_EXPORT_STAR, 0, JSEXN_SYNTAXERR, "missing keyword 'from' after export *") MSG_DEF(JSMSG_GARBAGE_AFTER_INPUT, 2, JSEXN_SYNTAXERR, "unexpected garbage after {0}, starting with {1}") MSG_DEF(JSMSG_IDSTART_AFTER_NUMBER, 0, JSEXN_SYNTAXERR, "identifier starts immediately after numeric literal") MSG_DEF(JSMSG_ILLEGAL_CHARACTER, 0, JSEXN_SYNTAXERR, "illegal character") -MSG_DEF(JSMSG_IMPORT_DECL_AT_TOP_LEVEL, 0, JSEXN_SYNTAXERR, "import declarations may only appear at top level") +MSG_DEF(JSMSG_IMPORT_DECL_AT_TOP_LEVEL, 0, JSEXN_SYNTAXERR, "import declarations may only appear at top level of a module") MSG_DEF(JSMSG_INVALID_FOR_INOF_DECL_WITH_INIT,1,JSEXN_SYNTAXERR,"for-{0} loop head declarations may not have initializers") -MSG_DEF(JSMSG_INVALID_OUTSIDE_MODULE, 0, JSEXN_SYNTAXERR, "import and export declarations are only valid at the top level of a module") MSG_DEF(JSMSG_IN_AFTER_FOR_NAME, 0, JSEXN_SYNTAXERR, "missing 'in' or 'of' after for") MSG_DEF(JSMSG_LABEL_NOT_FOUND, 0, JSEXN_SYNTAXERR, "label not found") MSG_DEF(JSMSG_LET_CLASS_BINDING, 0, JSEXN_SYNTAXERR, "'let' is not a valid name for a class")