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
parent cae0d0c98c
commit 0255a0299e
4 changed files with 23 additions and 9 deletions

View File

@ -5851,13 +5851,6 @@ Parser<FullParseHandler>::classStatement()
return null(); 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); bool savedStrictness = setLocalStrictMode(true);
StmtInfoPC classStmt(context); StmtInfoPC classStmt(context);
@ -5865,6 +5858,25 @@ Parser<FullParseHandler>::classStatement()
if (!classBlock) if (!classBlock)
return null(); 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); ParseNode *classMethods = propertyList(ClassBody);
if (!classMethods) if (!classMethods)
return null(); return null();
@ -5886,7 +5898,7 @@ Parser<FullParseHandler>::classStatement()
MOZ_ALWAYS_TRUE(setLocalStrictMode(savedStrictness)); MOZ_ALWAYS_TRUE(setLocalStrictMode(savedStrictness));
return handler.newClass(nameNode, null(), classBlock); return handler.newClass(nameNode, classHeritage, classBlock);
} }
template <> template <>

View File

@ -111,6 +111,7 @@
macro(EXPORT, "keyword 'export'") \ macro(EXPORT, "keyword 'export'") \
macro(IMPORT, "keyword 'import'") \ macro(IMPORT, "keyword 'import'") \
macro(CLASS, "keyword 'class'") \ macro(CLASS, "keyword 'class'") \
macro(EXTENDS, "keyword 'extends'") \
macro(RESERVED, "reserved keyword") \ macro(RESERVED, "reserved keyword") \
/* reserved keywords in strict mode */ \ /* reserved keywords in strict mode */ \
macro(STRICT_RESERVED, "reserved keyword") \ macro(STRICT_RESERVED, "reserved keyword") \

View File

@ -979,6 +979,7 @@ TokenStream::checkForKeyword(const KeywordInfo *kw, TokenKind *ttp)
if (kw->tokentype == TOK_RESERVED if (kw->tokentype == TOK_RESERVED
#ifndef JS_HAS_CLASSES #ifndef JS_HAS_CLASSES
|| kw->tokentype == TOK_CLASS || kw->tokentype == TOK_CLASS
|| kw->tokentype == TOK_EXTENDS
#endif #endif
) )
{ {

View File

@ -44,9 +44,9 @@
macro(import, import, TOK_IMPORT, JSVERSION_DEFAULT) \ macro(import, import, TOK_IMPORT, JSVERSION_DEFAULT) \
macro(export, export, TOK_EXPORT, JSVERSION_DEFAULT) \ macro(export, export, TOK_EXPORT, JSVERSION_DEFAULT) \
macro(class, class_, TOK_CLASS, JSVERSION_DEFAULT) \ macro(class, class_, TOK_CLASS, JSVERSION_DEFAULT) \
macro(extends, extends, TOK_EXTENDS, JSVERSION_DEFAULT) \
/* Reserved keywords. */ \ /* Reserved keywords. */ \
macro(enum, enum_, TOK_RESERVED, JSVERSION_DEFAULT) \ macro(enum, enum_, TOK_RESERVED, JSVERSION_DEFAULT) \
macro(extends, extends, TOK_RESERVED, JSVERSION_DEFAULT) \
macro(super, super, TOK_RESERVED, JSVERSION_DEFAULT) \ macro(super, super, TOK_RESERVED, JSVERSION_DEFAULT) \
/* Future reserved keywords, but only in strict mode. */ \ /* Future reserved keywords, but only in strict mode. */ \
macro(implements, implements, TOK_STRICT_RESERVED, JSVERSION_DEFAULT) \ macro(implements, implements, TOK_STRICT_RESERVED, JSVERSION_DEFAULT) \