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

Unified Diff: src/preparser.h

Issue 480543002: Parse 'super' keyword. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Patch for landing (minor fix for tests in release mode) Created 6 years, 4 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/parser.cc ('k') | src/prettyprinter.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/preparser.h
diff --git a/src/preparser.h b/src/preparser.h
index 8a932582586ed15b6b5b886ccecbe6933ee6d7e1..7609a3a866b536d8a273f1035d347dec1a62275a 100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -95,6 +95,7 @@ class ParserBase : public Traits {
bool allow_harmony_numeric_literals() const {
return scanner()->HarmonyNumericLiterals();
}
+ bool allow_classes() const { return scanner()->HarmonyClasses(); }
// Setters that determine whether certain syntactical constructs are
// allowed to be parsed by this instance of the parser.
@@ -109,6 +110,9 @@ class ParserBase : public Traits {
void set_allow_harmony_numeric_literals(bool allow) {
scanner()->SetHarmonyNumericLiterals(allow);
}
+ void set_allow_classes(bool allow) {
+ scanner()->SetHarmonyClasses(allow);
+ }
protected:
friend class Traits::Type::Checkpoint;
@@ -677,6 +681,10 @@ class PreParserExpression {
return PreParserExpression(kThisExpression);
}
+ static PreParserExpression Super() {
+ return PreParserExpression(kSuperExpression);
+ }
+
static PreParserExpression ThisProperty() {
return PreParserExpression(kThisPropertyExpression);
}
@@ -798,7 +806,8 @@ class PreParserExpression {
kThisExpression = (1 << 4),
kThisPropertyExpression = (2 << 4),
kPropertyExpression = (3 << 4),
- kCallExpression = (4 << 4)
+ kCallExpression = (4 << 4),
+ kSuperExpression = (5 << 4)
};
explicit PreParserExpression(int expression_code) : code_(expression_code) {}
@@ -1248,6 +1257,11 @@ class PreParserTraits {
return PreParserExpression::This();
}
+ static PreParserExpression SuperReference(PreParserScope* scope,
+ PreParserFactory* factory) {
+ return PreParserExpression::Super();
+ }
+
static PreParserExpression ExpressionFromLiteral(
Token::Value token, int pos, Scanner* scanner,
PreParserFactory* factory) {
@@ -2383,7 +2397,12 @@ ParserBase<Traits>::ParseMemberWithNewPrefixesExpression(bool* ok) {
if (peek() == Token::NEW) {
Consume(Token::NEW);
int new_pos = position();
- ExpressionT result = this->ParseMemberWithNewPrefixesExpression(CHECK_OK);
+ ExpressionT result = this->EmptyExpression();
+ if (Check(Token::SUPER)) {
+ result = this->SuperReference(scope_, factory());
+ } else {
+ result = this->ParseMemberWithNewPrefixesExpression(CHECK_OK);
+ }
if (peek() == Token::LPAREN) {
// NewExpression with arguments.
typename Traits::Type::ExpressionList args =
@@ -2397,7 +2416,7 @@ ParserBase<Traits>::ParseMemberWithNewPrefixesExpression(bool* ok) {
return factory()->NewCallNew(result, this->NewExpressionList(0, zone_),
new_pos);
}
- // No 'new' keyword.
+ // No 'new' or 'super' keyword.
return this->ParseMemberExpression(ok);
}
@@ -2438,6 +2457,19 @@ ParserBase<Traits>::ParseMemberExpression(bool* ok) {
function_type,
FunctionLiteral::NORMAL_ARITY,
CHECK_OK);
+ } else if (peek() == Token::SUPER) {
+ int beg_pos = position();
+ Consume(Token::SUPER);
+ Token::Value next = peek();
+ if (next == Token::PERIOD || next == Token::LBRACK ||
+ next == Token::LPAREN) {
+ result = this->SuperReference(scope_, factory());
+ } else {
+ ReportMessageAt(Scanner::Location(beg_pos, position()),
+ "unexpected_super");
+ *ok = false;
+ return this->EmptyExpression();
+ }
} else {
result = ParsePrimaryExpression(CHECK_OK);
}
« no previous file with comments | « src/parser.cc ('k') | src/prettyprinter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698