Bug 1066234 - Part 1: Parser support for 'extends' in ES6 Classes. (r=jorendorff)

This commit is contained in:
Eric Faust 2015-03-10 20:27:34 -07:00
Родитель cae0d0c98c
Коммит 0255a0299e
4 изменённых файлов: 23 добавлений и 9 удалений

Просмотреть файл

@ -5851,13 +5851,6 @@ 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);
@ -5865,6 +5858,25 @@ Parser<FullParseHandler>::classStatement()
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();
@ -5886,7 +5898,7 @@ Parser<FullParseHandler>::classStatement()
MOZ_ALWAYS_TRUE(setLocalStrictMode(savedStrictness));
return handler.newClass(nameNode, null(), classBlock);
return handler.newClass(nameNode, classHeritage, classBlock);
}
template <>

Просмотреть файл

@ -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") \

Просмотреть файл

@ -979,6 +979,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
)
{

Просмотреть файл

@ -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) \