Skip to content

Commit

Permalink
Bug 1066234 - Part 1: Parser support for 'extends' in ES6 Classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
rmottola committed Apr 17, 2019
1 parent f28b6f2 commit 7782e67
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
28 changes: 20 additions & 8 deletions js/src/frontend/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5728,20 +5728,32 @@ Parser<FullParseHandler>::classStatement()
return null();
}

// Because the binding definitions keep track of their blockId, we need to
// create at least the inner binding later. Keep track of the name's position
// in order to provide it for the nodes created later.
TokenPos namePos = pos();

MUST_MATCH_TOKEN(TOK_LC, JSMSG_CURLY_BEFORE_CLASS);

bool savedStrictness = setLocalStrictMode(true);

StmtInfoPC classStmt(context);
ParseNode *classBlock = pushLexicalScope(&classStmt);
if (!classBlock)
return null();

// Because the binding definitions keep track of their blockId, we need to
// create at least the inner binding later. Keep track of the name's position
// in order to provide it for the nodes created later.
TokenPos namePos = pos();

ParseNode *classHeritage = null();
bool hasHeritage;
if (!tokenStream.matchToken(&hasHeritage, TOK_EXTENDS))
return null();
if (hasHeritage) {
if (!tokenStream.getToken(&tt))
return null();
classHeritage = memberExpr(tt, true);
if (!classHeritage)
return null();
}

MUST_MATCH_TOKEN(TOK_LC, JSMSG_CURLY_BEFORE_CLASS);

ParseNode *classMethods = propertyList(ClassBody);
if (!classMethods)
return null();
Expand All @@ -5763,7 +5775,7 @@ Parser<FullParseHandler>::classStatement()

MOZ_ALWAYS_TRUE(setLocalStrictMode(savedStrictness));

return handler.newClass(nameNode, null(), classBlock);
return handler.newClass(nameNode, classHeritage, classBlock);
}

template <>
Expand Down
1 change: 1 addition & 0 deletions js/src/frontend/TokenKind.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
macro(EXPORT, "keyword 'export'") \
macro(IMPORT, "keyword 'import'") \
macro(CLASS, "keyword 'class'") \
macro(EXTENDS, "keyword 'extends'") \
macro(RESERVED, "reserved keyword") \
/* reserved keywords in strict mode */ \
macro(STRICT_RESERVED, "reserved keyword") \
Expand Down
1 change: 1 addition & 0 deletions js/src/frontend/TokenStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,7 @@ TokenStream::checkForKeyword(const KeywordInfo* kw, TokenKind* ttp)
if (kw->tokentype == TOK_RESERVED
#ifndef JS_HAS_CLASSES
|| kw->tokentype == TOK_CLASS
|| kw->tokentype == TOK_EXTENDS
#endif
)
{
Expand Down
2 changes: 1 addition & 1 deletion js/src/vm/Keywords.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
macro(import, import, TOK_IMPORT, JSVERSION_DEFAULT) \
macro(export, export, TOK_EXPORT, JSVERSION_DEFAULT) \
macro(class, class_, TOK_CLASS, JSVERSION_DEFAULT) \
macro(extends, extends, TOK_EXTENDS, JSVERSION_DEFAULT) \
/* Reserved keywords. */ \
macro(enum, enum_, TOK_RESERVED, JSVERSION_DEFAULT) \
macro(extends, extends, TOK_RESERVED, JSVERSION_DEFAULT) \
macro(super, super, TOK_RESERVED, JSVERSION_DEFAULT) \
/* Future reserved keywords, but only in strict mode. */ \
macro(implements, implements, TOK_STRICT_RESERVED, JSVERSION_DEFAULT) \
Expand Down

0 comments on commit 7782e67

Please sign in to comment.