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

Unified Diff: src/preparser.h

Issue 1169853002: [es6] Parsing of new.target (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add constant Created 5 years, 6 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/preparser.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 7a68e835ff2870e5397c2be37f7f17acb4fed00f..1200870780fcea782aba432cba7495b6362d6032 100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -97,76 +97,36 @@ class ParserBase : public Traits {
allow_harmony_computed_property_names_(false),
allow_harmony_rest_params_(false),
allow_harmony_spreadcalls_(false),
+ allow_harmony_destructuring_(false),
+ allow_harmony_spread_arrays_(false),
+ allow_harmony_new_target_(false),
allow_strong_mode_(false) {}
- // Getters that indicate whether certain syntactical constructs are
- // allowed to be parsed by this instance of the parser.
- bool allow_lazy() const { return allow_lazy_; }
- bool allow_natives() const { return allow_natives_; }
- bool allow_harmony_arrow_functions() const {
- return allow_harmony_arrow_functions_;
- }
+#define ALLOW_ACCESSORS(name) \
+ bool allow_##name() const { return allow_##name##_; } \
+ void set_allow_##name(bool allow) { allow_##name##_ = allow; }
+
+ ALLOW_ACCESSORS(lazy);
+ ALLOW_ACCESSORS(natives);
+ ALLOW_ACCESSORS(harmony_arrow_functions);
+ ALLOW_ACCESSORS(harmony_object_literals);
+ ALLOW_ACCESSORS(harmony_sloppy);
+ ALLOW_ACCESSORS(harmony_computed_property_names);
+ ALLOW_ACCESSORS(harmony_rest_params);
+ ALLOW_ACCESSORS(harmony_spreadcalls);
+ ALLOW_ACCESSORS(harmony_destructuring);
+ ALLOW_ACCESSORS(harmony_spread_arrays);
+ ALLOW_ACCESSORS(harmony_new_target);
+ ALLOW_ACCESSORS(strong_mode);
+#undef ALLOW_ACCESSORS
+
bool allow_harmony_modules() const { return scanner()->HarmonyModules(); }
bool allow_harmony_classes() const { return scanner()->HarmonyClasses(); }
- bool allow_harmony_object_literals() const {
- return allow_harmony_object_literals_;
- }
- bool allow_harmony_sloppy() const { return allow_harmony_sloppy_; }
bool allow_harmony_unicode() const { return scanner()->HarmonyUnicode(); }
- bool allow_harmony_computed_property_names() const {
- return allow_harmony_computed_property_names_;
- }
- bool allow_harmony_rest_params() const {
- return allow_harmony_rest_params_;
- }
- bool allow_harmony_spreadcalls() const { return allow_harmony_spreadcalls_; }
- bool allow_harmony_destructuring() const {
- return allow_harmony_destructuring_;
- }
- bool allow_harmony_spread_arrays() const {
- return allow_harmony_spread_arrays_;
- }
-
- bool allow_strong_mode() const { return allow_strong_mode_; }
- // Setters that determine whether certain syntactical constructs are
- // allowed to be parsed by this instance of the parser.
- void set_allow_lazy(bool allow) { allow_lazy_ = allow; }
- void set_allow_natives(bool allow) { allow_natives_ = allow; }
- void set_allow_harmony_arrow_functions(bool allow) {
- allow_harmony_arrow_functions_ = allow;
- }
- void set_allow_harmony_modules(bool allow) {
- scanner()->SetHarmonyModules(allow);
- }
- void set_allow_harmony_classes(bool allow) {
- scanner()->SetHarmonyClasses(allow);
- }
- void set_allow_harmony_object_literals(bool allow) {
- allow_harmony_object_literals_ = allow;
- }
- void set_allow_harmony_sloppy(bool allow) {
- allow_harmony_sloppy_ = allow;
- }
- void set_allow_harmony_unicode(bool allow) {
- scanner()->SetHarmonyUnicode(allow);
- }
- void set_allow_harmony_computed_property_names(bool allow) {
- allow_harmony_computed_property_names_ = allow;
- }
- void set_allow_harmony_rest_params(bool allow) {
- allow_harmony_rest_params_ = allow;
- }
- void set_allow_harmony_spreadcalls(bool allow) {
- allow_harmony_spreadcalls_ = allow;
- }
- void set_allow_strong_mode(bool allow) { allow_strong_mode_ = allow; }
- void set_allow_harmony_destructuring(bool allow) {
- allow_harmony_destructuring_ = allow;
- }
- void set_allow_harmony_spread_arrays(bool allow) {
- allow_harmony_spread_arrays_ = allow;
- }
+ void set_allow_harmony_modules(bool a) { scanner()->SetHarmonyModules(a); }
+ void set_allow_harmony_classes(bool a) { scanner()->SetHarmonyClasses(a); }
+ void set_allow_harmony_unicode(bool a) { scanner()->SetHarmonyUnicode(a); }
protected:
enum AllowRestrictedIdentifiers {
@@ -349,7 +309,7 @@ class ParserBase : public Traits {
Scope* NewScope(Scope* parent, ScopeType scope_type, FunctionKind kind) {
DCHECK(ast_value_factory());
DCHECK(scope_type != MODULE_SCOPE || allow_harmony_modules());
- DCHECK(scope_type != ARROW_SCOPE || IsArrowFunction(kind));
+ DCHECK(!IsArrowFunction(kind) || scope_type == ARROW_SCOPE);
Scope* result = new (zone())
Scope(zone(), parent, scope_type, ast_value_factory(), kind);
result->Initialize();
@@ -912,6 +872,7 @@ class ParserBase : public Traits {
void AddTemplateExpression(ExpressionT);
ExpressionT ParseSuperExpression(bool is_new,
ExpressionClassifier* classifier, bool* ok);
+ ExpressionT ParseNewTargetExpression(bool* ok);
ExpressionT ParseStrongInitializationExpression(
ExpressionClassifier* classifier, bool* ok);
ExpressionT ParseStrongSuperCallExpression(ExpressionClassifier* classifier,
@@ -1022,6 +983,7 @@ class ParserBase : public Traits {
bool allow_harmony_spreadcalls_;
bool allow_harmony_destructuring_;
bool allow_harmony_spread_arrays_;
+ bool allow_harmony_new_target_;
bool allow_strong_mode_;
};
@@ -1731,6 +1693,12 @@ class PreParserTraits {
return PreParserExpression::Default();
}
+ static PreParserExpression NewTargetExpression(Scope* scope,
+ PreParserFactory* factory,
+ int pos) {
+ return PreParserExpression::Default();
+ }
+
static PreParserExpression DefaultConstructor(bool call_super, Scope* scope,
int pos, int end_pos) {
return PreParserExpression::Default();
@@ -3332,6 +3300,9 @@ ParserBase<Traits>::ParseMemberWithNewPrefixesExpression(
ExpressionClassifier* classifier, bool* ok) {
// NewExpression ::
// ('new')+ MemberExpression
+ //
+ // NewTarget ::
+ // 'new' '.' 'target'
// The grammar for new expressions is pretty warped. We can have several 'new'
// keywords following each other, and then a MemberExpression. When we see '('
@@ -3355,6 +3326,8 @@ ParserBase<Traits>::ParseMemberWithNewPrefixesExpression(
if (peek() == Token::SUPER) {
const bool is_new = true;
result = ParseSuperExpression(is_new, classifier, CHECK_OK);
+ } else if (allow_harmony_new_target() && peek() == Token::PERIOD) {
+ return ParseNewTargetExpression(CHECK_OK);
} else {
result = this->ParseMemberWithNewPrefixesExpression(classifier, CHECK_OK);
}
@@ -3578,7 +3551,6 @@ ParserBase<Traits>::ParseSuperExpression(bool is_new,
Expect(Token::SUPER, CHECK_OK);
Scope* scope = scope_->DeclarationScope();
-
while (scope->is_eval_scope() || scope->is_arrow_scope()) {
scope = scope->outer_scope();
DCHECK_NOT_NULL(scope);
@@ -3617,6 +3589,31 @@ ParserBase<Traits>::ParseSuperExpression(bool is_new,
template <class Traits>
typename ParserBase<Traits>::ExpressionT
+ParserBase<Traits>::ParseNewTargetExpression(bool* ok) {
+ int pos = position();
+ Consume(Token::PERIOD);
+ ExpectContextualKeyword(CStrVector("target"), CHECK_OK);
+
+ Scope* scope = scope_->DeclarationScope();
+ while (scope->is_eval_scope() || scope->is_arrow_scope()) {
+ scope = scope->outer_scope();
+ DCHECK_NOT_NULL(scope);
+ scope = scope->DeclarationScope();
+ }
+
+ if (!scope->is_function_scope()) {
+ ReportMessageAt(scanner()->location(),
+ MessageTemplate::kUnexpectedNewTarget);
+ *ok = false;
+ return this->EmptyExpression();
+ }
+
+ return this->NewTargetExpression(scope_, factory(), pos);
+}
+
+
+template <class Traits>
+typename ParserBase<Traits>::ExpressionT
ParserBase<Traits>::ParseMemberExpressionContinuation(
ExpressionT expression, ExpressionClassifier* classifier, bool* ok) {
// Parses this part of MemberExpression:
« no previous file with comments | « src/parser.cc ('k') | src/preparser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698