Bug 932216 - Remove code conditional on JS_HAS_CONST, JS_HAS_BLOCK_SCOPE. r=jorendorff

This commit is contained in:
Andy Wingo 2013-10-29 11:23:51 +01:00
parent 2d417d2685
commit 8a8be6dd57
5 changed files with 13 additions and 62 deletions

View File

@ -2293,7 +2293,6 @@ EmitSwitch(ExclusiveContext *cx, BytecodeEmitter *bce, ParseNode *pn)
defaultOffset = -1;
pn2 = pn->pn_right;
#if JS_HAS_BLOCK_SCOPE
/*
* If there are hoisted let declarations, their stack slots go under the
* discriminant's value so push their slots now and enter the block later.
@ -2306,26 +2305,20 @@ EmitSwitch(ExclusiveContext *cx, BytecodeEmitter *bce, ParseNode *pn)
return false;
}
}
#endif
/* Push the discriminant. */
if (!EmitTree(cx, bce, pn->pn_left))
return false;
#if JS_HAS_BLOCK_SCOPE
if (pn2->isKind(PNK_LEXICALSCOPE)) {
PushBlockScopeBCE(bce, &stmtInfo, pn2->pn_objbox->object->as<StaticBlockObject>(), -1);
stmtInfo.type = STMT_SWITCH;
if (!EmitEnterBlock(cx, bce, pn2, JSOP_ENTERLET1))
return false;
}
#endif
/* Switch bytecodes run from here till end of final case. */
top = bce->offset();
#if !JS_HAS_BLOCK_SCOPE
PushStatementBCE(bce, &stmtInfo, STMT_SWITCH, top);
#else
if (pn2->isKind(PNK_STATEMENTLIST)) {
PushStatementBCE(bce, &stmtInfo, STMT_SWITCH, top);
} else {
@ -2338,7 +2331,6 @@ EmitSwitch(ExclusiveContext *cx, BytecodeEmitter *bce, ParseNode *pn)
/* Advance pn2 to refer to the switch case list. */
pn2 = pn2->expr();
}
#endif
uint32_t caseCount = pn2->pn_count;
uint32_t tableLength = 0;
@ -2614,10 +2606,8 @@ EmitSwitch(ExclusiveContext *cx, BytecodeEmitter *bce, ParseNode *pn)
if (!PopStatementBCE(cx, bce))
return false;
#if JS_HAS_BLOCK_SCOPE
if (pn->pn_right->isKind(PNK_LEXICALSCOPE))
EMIT_UINT16_IMM_OP(JSOP_LEAVEBLOCK, blockObjCount);
#endif
return true;
}
@ -4155,7 +4145,6 @@ EmitIf(ExclusiveContext *cx, BytecodeEmitter *bce, ParseNode *pn)
return PopStatementBCE(cx, bce);
}
#if JS_HAS_BLOCK_SCOPE
/*
* pnLet represents one of:
*
@ -4228,7 +4217,6 @@ EmitLet(ExclusiveContext *cx, BytecodeEmitter *bce, ParseNode *pnLet)
return PopStatementBCE(cx, bce);
}
#endif
/*
* Using MOZ_NEVER_INLINE in here is a workaround for llvm.org/pr14047. See
@ -6455,13 +6443,12 @@ frontend::EmitTree(ExclusiveContext *cx, BytecodeEmitter *bce, ParseNode *pn)
ok = EmitLexicalScope(cx, bce, pn);
break;
#if JS_HAS_BLOCK_SCOPE
case PNK_LET:
ok = pn->isArity(PN_BINARY)
? EmitLet(cx, bce, pn)
: EmitVariables(cx, bce, pn, InitializeVars);
break;
#endif /* JS_HAS_BLOCK_SCOPE */
case PNK_ARRAYPUSH: {
int slot;

View File

@ -3278,8 +3278,6 @@ Parser<ParseHandler>::pushLexicalScope(StmtInfoPC *stmt)
return pushLexicalScope(blockObj, stmt);
}
#if JS_HAS_BLOCK_SCOPE
struct AddLetDecl
{
uint32_t blockid;
@ -3408,8 +3406,6 @@ Parser<ParseHandler>::letBlock(LetContext letContext)
return pnlet;
}
#endif /* JS_HAS_BLOCK_SCOPE */
template <typename ParseHandler>
static bool
PushBlocklikeStatement(TokenStream &ts, StmtInfoPC *stmt, StmtType type,
@ -3590,7 +3586,6 @@ Parser<ParseHandler>::variables(ParseNodeKind kind, bool *psimple,
return pn;
}
#if JS_HAS_BLOCK_SCOPE
template <>
ParseNode *
Parser<FullParseHandler>::letStatement()
@ -3712,8 +3707,6 @@ Parser<SyntaxParseHandler>::letStatement()
return SyntaxParseHandler::NodeFailure;
}
#endif // JS_HAS_BLOCK_SCOPE
template <typename ParseHandler>
typename ParseHandler::Node
Parser<ParseHandler>::expressionStatement()
@ -3936,7 +3929,6 @@ Parser<FullParseHandler>::forStatement()
tokenStream.consumeKnownToken(tt);
pn1 = variables(tt == TOK_VAR ? PNK_VAR : PNK_CONST);
}
#if JS_HAS_BLOCK_SCOPE
else if (tt == TOK_LET) {
handler.disableSyntaxParser();
(void) tokenStream.getToken();
@ -3950,7 +3942,6 @@ Parser<FullParseHandler>::forStatement()
pn1 = variables(PNK_LET, nullptr, blockObj, DontHoistVars);
}
}
#endif
else {
pn1 = expr();
}
@ -4188,10 +4179,8 @@ Parser<FullParseHandler>::forStatement()
if (!body)
return null();
#if JS_HAS_BLOCK_SCOPE
if (blockObj)
PopStatementPC(tokenStream, pc);
#endif
PopStatementPC(tokenStream, pc);
ParseNode *forLoop = handler.newForStatement(begin, forHead, body, iflags);
@ -4265,12 +4254,10 @@ Parser<SyntaxParseHandler>::forStatement()
tokenStream.consumeKnownToken(tt);
lhsNode = variables(tt == TOK_VAR ? PNK_VAR : PNK_CONST, &simpleForDecl);
}
#if JS_HAS_BLOCK_SCOPE
else if (tt == TOK_CONST || tt == TOK_LET) {
JS_ALWAYS_FALSE(abortIfSyntaxParser());
return null();
}
#endif
else {
lhsNode = expr();
}
@ -4997,11 +4984,8 @@ Parser<ParseHandler>::statement(bool canHaveDirectives)
return pn;
}
#if JS_HAS_BLOCK_SCOPE
case TOK_LET:
return letStatement();
#endif
case TOK_SEMI:
return handler.newEmptyStatement(pos());
case TOK_IF:
@ -6809,10 +6793,8 @@ Parser<ParseHandler>::primaryExpr(TokenKind tt)
case TOK_LC:
return objectLiteral();
#if JS_HAS_BLOCK_SCOPE
case TOK_LET:
return letBlock(LetExpresion);
#endif
case TOK_LP:
{

View File

@ -513,9 +513,7 @@ class Parser : private AutoGCRooter, public StrictModeGetter
Node tryStatement();
Node debuggerStatement();
#if JS_HAS_BLOCK_SCOPE
Node letStatement();
#endif
Node expressionStatement();
Node variables(ParseNodeKind kind, bool *psimple = nullptr,
StaticBlockObject *blockObj = nullptr,

View File

@ -182,11 +182,7 @@ TokenKindIsAssignment(TokenKind tt)
inline bool
TokenKindIsDecl(TokenKind tt)
{
#if JS_HAS_BLOCK_SCOPE
return tt == TOK_VAR || tt == TOK_LET;
#else
return tt == TOK_VAR;
#endif
}
struct TokenPos {

View File

@ -9,29 +9,15 @@
#ifndef vm_Keywords_h
#define vm_Keywords_h
#if JS_HAS_CONST
# define FOR_CONST_KEYWORD(macro) \
macro(const, const_, TOK_CONST, JSVERSION_DEFAULT)
#else
# define FOR_CONST_KEYWORD(macro) \
macro(const, const_, TOK_RESERVED, JSVERSION_DEFAULT)
#endif
#if JS_HAS_BLOCK_SCOPE
# define FOR_LET_KEYWORD(macro) \
macro(let, let, TOK_LET, JSVERSION_1_7)
#else
# define FOR_LET_KEYWORD(macro) \
macro(let, let, TOK_STRICT_RESERVED, JSVERSION_1_7)
#endif
#define FOR_EACH_JAVASCRIPT_KEYWORD(macro) \
macro(false, false_, TOK_FALSE, JSVERSION_DEFAULT) \
macro(true, true_, TOK_TRUE, JSVERSION_DEFAULT) \
macro(null, null, TOK_NULL, JSVERSION_DEFAULT) \
/* ES5 Keywords. */ \
/* Keywords. */ \
macro(break, break_, TOK_BREAK, JSVERSION_DEFAULT) \
macro(case, case_, TOK_CASE, JSVERSION_DEFAULT) \
macro(catch, catch_, TOK_CATCH, JSVERSION_DEFAULT) \
macro(const, const_, TOK_CONST, JSVERSION_DEFAULT) \
macro(continue, continue_, TOK_CONTINUE, JSVERSION_DEFAULT) \
macro(debugger, debugger, TOK_DEBUGGER, JSVERSION_DEFAULT) \
macro(default, default_, TOK_DEFAULT, JSVERSION_DEFAULT) \
@ -55,14 +41,14 @@
macro(void, void_, TOK_VOID, JSVERSION_DEFAULT) \
macro(while, while_, TOK_WHILE, JSVERSION_DEFAULT) \
macro(with, with, TOK_WITH, JSVERSION_DEFAULT) \
/* ES5 reserved keywords reserved in all code. */ \
/* Reserved keywords. */ \
macro(class, class_, TOK_RESERVED, JSVERSION_DEFAULT) \
macro(enum, enum_, TOK_RESERVED, JSVERSION_DEFAULT) \
macro(export, export, TOK_RESERVED, JSVERSION_DEFAULT) \
macro(extends, extends, TOK_RESERVED, JSVERSION_DEFAULT) \
macro(import, import, TOK_RESERVED, JSVERSION_DEFAULT) \
macro(super, super, TOK_RESERVED, JSVERSION_DEFAULT) \
/* ES5 future reserved keywords in strict mode. */ \
/* Future reserved keywords, but only in strict mode. */ \
macro(implements, implements, TOK_STRICT_RESERVED, JSVERSION_DEFAULT) \
macro(interface, interface, TOK_STRICT_RESERVED, JSVERSION_DEFAULT) \
macro(package, package, TOK_STRICT_RESERVED, JSVERSION_DEFAULT) \
@ -71,13 +57,15 @@
macro(public, public_, TOK_STRICT_RESERVED, JSVERSION_DEFAULT) \
macro(static, static_, TOK_STRICT_RESERVED, JSVERSION_DEFAULT) \
/* \
* ES5 future reserved keyword in strict mode, keyword in JS1.7 even when \
* not strict, keyword inside function* in all versions. Punt logic to \
* parser. \
* Yield is a token inside function*. Outside of a function*, it is a \
* future reserved keyword in strict mode, but a keyword in JS1.7 even \
* when strict. Punt logic to parser. \
*/ \
macro(yield, yield, TOK_YIELD, JSVERSION_DEFAULT) \
/* Various conditional keywords. */ \
FOR_CONST_KEYWORD(macro) \
FOR_LET_KEYWORD(macro)
/* \
* Let is a future reserved keyword in strict mode, and a keyword in \
* JS1.7. \
*/ \
macro(let, let, TOK_LET, JSVERSION_1_7)
#endif /* vm_Keywords_h */