--- a/js/src/frontend/BinSource.cpp
+++ b/js/src/frontend/BinSource.cpp
@@ -137,17 +137,16 @@ private:
bool parsePatternAux(SimpleTokenReader* reader, const BinKind kind, const SimpleTokenReader::BinFields& fields, UniquePtr<ParseNode>& out);
bool parseBlockStatementAux(SimpleTokenReader* reader, const BinKind kind, const SimpleTokenReader::BinFields& fields, UniquePtr<ParseNode>& out);
bool parseExpressionStatementAux(SimpleTokenReader* reader, const BinKind kind, const SimpleTokenReader::BinFields& fields, UniquePtr<ParseNode>& out);
bool parseExpressionAux(SimpleTokenReader* reader, const BinKind kind, const SimpleTokenReader::BinFields& fields, UniquePtr<ParseNode>& out);
bool parseVariableDeclarationAux(SimpleTokenReader* reader, const BinKind kind, const SimpleTokenReader::BinFields& fields, UniquePtr<ParseNode>& out);
// --- Utilities.
- bool readString(SimpleTokenReader* reader, std::string&);
bool readString(SimpleTokenReader* reader, Maybe<std::string>&);
bool readString(SimpleTokenReader* reader, Maybe<std::u16string>&);
bool readString(SimpleTokenReader* reader, MutableHandleString);
bool readString(SimpleTokenReader* reader, MutableHandleAtom);
bool readString(SimpleTokenReader* reader, MutableHandle<PropertyName*>);
bool readBool(SimpleTokenReader* reader, Maybe<bool>&);
bool readNumber(SimpleTokenReader* reader, Maybe<double>&);
@@ -1220,28 +1219,31 @@ ASTReader::parseVariableDeclarationAux(S
ParseNodeKind kind = PNK_LIMIT;
JSOp op = JSOP_NOP;
UniquePtr<ParseNode> result;
for (auto field: fields) {
switch (field) {
case BinField::kind: {
- std::string kindName;
+ Maybe<std::string> kindName;
if (!this->readString(reader, kindName)) {
return false;
}
+ if (kindName.isNothing()) {
+ return this->raiseError();
+ }
- if (kindName == "let") {
+ if (*kindName == "let") {
kind = PNK_LET;
op = JSOP_DEFLET;
- } else if (kindName == "var") {
+ } else if (*kindName == "var") {
kind = PNK_VAR;
op = JSOP_DEFVAR;
- } else if (kindName == "const") {
+ } else if (*kindName == "const") {
kind = PNK_CONST;
op = JSOP_DEFCONST;
} else {
return this->raiseError();
}
break;
}
case BinField::declarations: {
@@ -1741,17 +1743,17 @@ ASTReader::parseExpressionAux(SimpleToke
result->setOp(JSOP_LAMBDA);
out = Move(result);
break;
}
case BinKind::unary_expression:
case BinKind::update_expression: {
UniquePtr<ParseNode> expr;
- std::string operation;
+ Maybe<std::string> operation;
Maybe<bool> prefix; // FIXME: Ignored for unary_expression?
for (auto field: fields) {
switch (field) {
case BinField::operator_:
if (!this->readString(reader, operation)) {
return false;
}
@@ -1766,45 +1768,45 @@ ASTReader::parseExpressionAux(SimpleToke
return false;
}
break;
default:
return this->raiseError();
}
}
- if (!expr || operation.length() == 0 || !prefix.isSome()) {
+ if (!expr || !operation == 0 || !prefix.isSome()) {
return this->raiseError();
}
ParseNodeKind pnk = PNK_LIMIT;
JSOp op = JSOP_NOP;
if (kind == BinKind::unary_expression) {
- if (operation == "-") {
+ if (*operation == "-") {
pnk = PNK_NEG;
op = JSOP_NEG;
- } else if (operation == "+") {
+ } else if (*operation == "+") {
pnk = PNK_POS;
op = JSOP_POS;
- } else if (operation == "!") {
+ } else if (*operation == "!") {
pnk = PNK_NOT;
op = JSOP_NOT;
- } else if (operation == "~") {
+ } else if (*operation == "~") {
pnk = PNK_BITNOT;
op = JSOP_BITNOT;
- } else if (operation == "typeof") {
+ } else if (*operation == "typeof") {
if (expr->isKind(PNK_NAME)) {
pnk = PNK_TYPEOFNAME;
} else {
pnk = PNK_TYPEOFEXPR;
}
- } else if (operation == "void") {
+ } else if (*operation == "void") {
pnk = PNK_VOID;
op = JSOP_VOID;
- } else if (operation == "delete") {
+ } else if (*operation == "delete") {
switch (expr->getKind()) {
case PNK_NAME:
expr->setOp(JSOP_DELNAME);
pnk = PNK_DELETENAME;
break;
case PNK_DOT:
pnk = PNK_DELETEPROP;
break;
@@ -1813,23 +1815,23 @@ ASTReader::parseExpressionAux(SimpleToke
break;
default:
pnk = PNK_DELETEEXPR;
}
} else {
return this->raiseError();
}
} else if (kind == BinKind::update_expression) {
- if (operation == "++") {
+ if (*operation == "++") {
if (*prefix) {
pnk = PNK_PREINCREMENT;
} else {
pnk = PNK_PREDECREMENT;
}
- } else if (operation == "--") {
+ } else if (*operation == "--") {
if (*prefix) {
pnk = PNK_PREDECREMENT;
} else {
pnk = PNK_POSTDECREMENT;
}
} else {
return this->raiseError();
}
@@ -1844,17 +1846,17 @@ ASTReader::parseExpressionAux(SimpleToke
out = Move(result);
break;
}
case BinKind::binary_expression: MOZ_FALLTHROUGH;
case BinKind::logical_expression: {
UniquePtr<ParseNode> left;
UniquePtr<ParseNode> right;
- std::string operation;
+ Maybe<std::string> operation;
for (auto field: fields) {
switch (field) {
case BinField::left:
if (!this->parseExpression(reader, left)) {
return false;
}
break;
case BinField::right:
@@ -1867,92 +1869,92 @@ ASTReader::parseExpressionAux(SimpleToke
return false;
}
break;
default:
return this->raiseError();
}
}
- if (!left || !right || operation.length() == 0) {
+ if (!left || !right || !operation == 0) {
return this->raiseError();
}
// FIXME: Instead of std::string, we should use atoms and comparison
// between atom ptr.
// FIXME: We should probably turn associative operations into lists.
ParseNodeKind pnk = PNK_LIMIT;
JSOp op;
- if (operation == "==") {
+ if (*operation == "==") {
pnk = PNK_EQ;
op = JSOP_EQ;
- } else if (operation == "!=") {
+ } else if (*operation == "!=") {
pnk = PNK_NE;
op = JSOP_NE;
- } else if (operation == "===") {
+ } else if (*operation == "===") {
pnk = PNK_STRICTEQ;
op = JSOP_STRICTEQ;
- } else if (operation == "!==") {
+ } else if (*operation == "!==") {
pnk = PNK_STRICTNE;
op = JSOP_STRICTNE;
- } else if (operation == "<") {
+ } else if (*operation == "<") {
pnk = PNK_LT;
op = JSOP_LT;
- } else if (operation == "<=") {
+ } else if (*operation == "<=") {
pnk = PNK_LE;
op = JSOP_LE;
- } else if (operation == ">") {
+ } else if (*operation == ">") {
pnk = PNK_GT;
op = JSOP_GT;
- } else if (operation == ">=") {
+ } else if (*operation == ">=") {
pnk = PNK_GE;
op = JSOP_GE;
- } else if (operation == "<<") {
+ } else if (*operation == "<<") {
pnk = PNK_LSH;
op = JSOP_LSH;
- } else if (operation == ">>") {
+ } else if (*operation == ">>") {
pnk = PNK_RSH;
op = JSOP_RSH;
- } else if (operation == ">>>") {
+ } else if (*operation == ">>>") {
pnk = PNK_URSH;
op = JSOP_URSH;
- } else if (operation == "+") {
+ } else if (*operation == "+") {
pnk = PNK_ADD;
op = JSOP_ADD;
- } else if (operation == "-") {
+ } else if (*operation == "-") {
pnk = PNK_SUB;
op = JSOP_SUB;
- } else if (operation == "*") {
+ } else if (*operation == "*") {
pnk = PNK_STAR;
op = JSOP_MUL;
- } else if (operation == "/") {
+ } else if (*operation == "/") {
pnk = PNK_DIV;
op = JSOP_DIV;
- } else if (operation == "%") {
+ } else if (*operation == "%") {
pnk = PNK_MOD;
op = JSOP_MOD;
- } else if (operation == "|") {
+ } else if (*operation == "|") {
pnk = PNK_BITOR;
op = JSOP_BITOR;
- } else if (operation == "^") {
+ } else if (*operation == "^") {
pnk = PNK_BITXOR;
op = JSOP_BITXOR;
- } else if (operation == "&") {
+ } else if (*operation == "&") {
pnk = PNK_BITAND;
op = JSOP_BITAND;
- } else if (operation == "in") {
+ } else if (*operation == "in") {
pnk = PNK_IN;
op = JSOP_IN;
- } else if (operation == "instanceof") {
+ } else if (*operation == "instanceof") {
pnk = PNK_INSTANCEOF;
op = JSOP_INSTANCEOF;
- } else if (operation == "||") {
+ } else if (*operation == "||") {
pnk = PNK_OR;
op = JSOP_OR;
- } else if (operation == "&&" ) {
+ } else if (*operation == "&&" ) {
pnk = PNK_AND;
op = JSOP_AND;
} else {
return this->raiseError();
}
UniquePtr<ParseNode> list(new_<ListNode>(pnk, JSOP_NOP, TokenPos()));
if (!list) {
@@ -1962,17 +1964,17 @@ ASTReader::parseExpressionAux(SimpleToke
list->append(left.release());
list->append(right.release());
out = Move(list);
break;
}
case BinKind::assignment_expression: {
UniquePtr<ParseNode> left;
UniquePtr<ParseNode> right;
- std::string operation;
+ Maybe<std::string> operation;
for (auto field: fields) {
switch (field) {
case BinField::left:
if (!this->parseExpression(reader, left)) {
return false;
}
break;
case BinField::right:
@@ -1985,58 +1987,58 @@ ASTReader::parseExpressionAux(SimpleToke
return false;
}
break;
default:
return this->raiseError();
}
}
- if (!left || !right || operation.length() == 0) {
+ if (!left || !right || !operation) {
return this->raiseError();
}
// FIXME: Instead of std::string, we should use atoms and comparison
// between atom ptr.
// FIXME: We should probably turn associative operations into lists.
ParseNodeKind pnk = PNK_LIMIT;
JSOp op = JSOP_NOP;
- if (operation == "=") {
+ if (*operation == "=") {
pnk = PNK_ASSIGN;
- } else if (operation == "+=") {
+ } else if (*operation == "+=") {
pnk = PNK_ADDASSIGN;
op = JSOP_ADD;
- } else if (operation == "-=") {
+ } else if (*operation == "-=") {
pnk = PNK_SUBASSIGN;
op = JSOP_SUB;
- } else if (operation == "*=") {
+ } else if (*operation == "*=") {
pnk = PNK_MULASSIGN;
op = JSOP_MUL;
- } else if (operation == "/=") {
+ } else if (*operation == "/=") {
pnk = PNK_DIVASSIGN;
op = JSOP_DIV;
- } else if (operation == "%=") {
+ } else if (*operation == "%=") {
pnk = PNK_MODASSIGN;
op = JSOP_MOD;
- } else if (operation == "<<=") {
+ } else if (*operation == "<<=") {
pnk = PNK_LSHASSIGN;
op = JSOP_LSH;
- } else if (operation == ">>=") {
+ } else if (*operation == ">>=") {
pnk = PNK_RSHASSIGN;
op = JSOP_RSH;
- } else if (operation == ">>>=") {
+ } else if (*operation == ">>>=") {
pnk = PNK_URSHASSIGN;
op = JSOP_URSH;
- } else if (operation == "|=") {
+ } else if (*operation == "|=") {
pnk = PNK_BITORASSIGN;
op = JSOP_BITOR;
- } else if (operation == "^=") {
+ } else if (*operation == "^=") {
pnk = PNK_BITXORASSIGN;
op = JSOP_BITXOR;
- } else if (operation == "&=") {
+ } else if (*operation == "&=") {
pnk = PNK_BITANDASSIGN;
op = JSOP_BITAND;
} else {
return this->raiseError();
}
UniquePtr<ParseNode> list(new_<BinaryNode>(pnk, JSOP_NOP, TokenPos(), left.get(), right.get()));
if (!list) {
@@ -2217,20 +2219,23 @@ ASTReader::parseDirectiveList(SimpleToke
uint32_t length;
SimpleTokenReader sub(this->cx);
if (!reader->readList(&length, &sub)) {
return false;
}
for (uint32_t i = 0; i < length; ++i) {
- std::string string;
+ Maybe<std::string> string; // Ignored
if (!this->readString(&sub, string)) {
return false;
}
+ if (!string) {
+ return this->raiseError();
+ }
}
return true;
}
bool
ASTReader::parseSwitchCase(SimpleTokenReader* reader, UniquePtr<ParseNode>& out) {
if (out) {
@@ -2278,16 +2283,32 @@ ASTReader::parseSwitchCase(SimpleTokenRe
result = UniquePtr<ParseNode>(new_<CaseClause>(test.get(), statements.get(), 0));
if (!result) {
return false;
}
Unused << test.release();
Unused << statements.release();
+
+ out = Move(result);
+ return true;
+}
+
+bool
+ASTReader::readString(SimpleTokenReader* reader, Maybe<std::string>& out) {
+ if (out) {
+ return this->raiseError();
+ }
+
+ if (!reader->readMaybeString(&out)) {
+ return false;
+ }
+
+ return true;
}
bool
ASTReader::readNumber(SimpleTokenReader* reader, Maybe<double>& out) {
if (out) {
return this->raiseError();
}