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

Side by Side Diff: src/parsing/preparser.h

Issue 1723313002: [parser] Enforce module-specific identifier restriction (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add an initializer for `parsing_module_` attribute Created 4 years, 8 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 unified diff | Download patch
« no previous file with comments | « src/parsing/parser-base.h ('k') | src/parsing/preparser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_PARSING_PREPARSER_H 5 #ifndef V8_PARSING_PREPARSER_H
6 #define V8_PARSING_PREPARSER_H 6 #define V8_PARSING_PREPARSER_H
7 7
8 #include "src/ast/scopes.h" 8 #include "src/ast/scopes.h"
9 #include "src/bailout-reason.h" 9 #include "src/bailout-reason.h"
10 #include "src/hashmap.h" 10 #include "src/hashmap.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 } 48 }
49 static PreParserIdentifier Yield() { 49 static PreParserIdentifier Yield() {
50 return PreParserIdentifier(kYieldIdentifier); 50 return PreParserIdentifier(kYieldIdentifier);
51 } 51 }
52 static PreParserIdentifier Prototype() { 52 static PreParserIdentifier Prototype() {
53 return PreParserIdentifier(kPrototypeIdentifier); 53 return PreParserIdentifier(kPrototypeIdentifier);
54 } 54 }
55 static PreParserIdentifier Constructor() { 55 static PreParserIdentifier Constructor() {
56 return PreParserIdentifier(kConstructorIdentifier); 56 return PreParserIdentifier(kConstructorIdentifier);
57 } 57 }
58 static PreParserIdentifier Enum() {
59 return PreParserIdentifier(kEnumIdentifier);
60 }
61 static PreParserIdentifier Await() {
62 return PreParserIdentifier(kAwaitIdentifier);
63 }
58 bool IsEval() const { return type_ == kEvalIdentifier; } 64 bool IsEval() const { return type_ == kEvalIdentifier; }
59 bool IsArguments() const { return type_ == kArgumentsIdentifier; } 65 bool IsArguments() const { return type_ == kArgumentsIdentifier; }
60 bool IsEvalOrArguments() const { return IsEval() || IsArguments(); } 66 bool IsEvalOrArguments() const { return IsEval() || IsArguments(); }
61 bool IsUndefined() const { return type_ == kUndefinedIdentifier; } 67 bool IsUndefined() const { return type_ == kUndefinedIdentifier; }
62 bool IsLet() const { return type_ == kLetIdentifier; } 68 bool IsLet() const { return type_ == kLetIdentifier; }
63 bool IsStatic() const { return type_ == kStaticIdentifier; } 69 bool IsStatic() const { return type_ == kStaticIdentifier; }
64 bool IsYield() const { return type_ == kYieldIdentifier; } 70 bool IsYield() const { return type_ == kYieldIdentifier; }
65 bool IsPrototype() const { return type_ == kPrototypeIdentifier; } 71 bool IsPrototype() const { return type_ == kPrototypeIdentifier; }
66 bool IsConstructor() const { return type_ == kConstructorIdentifier; } 72 bool IsConstructor() const { return type_ == kConstructorIdentifier; }
67 bool IsFutureReserved() const { return type_ == kFutureReservedIdentifier; } 73 bool IsEnum() const { return type_ == kEnumIdentifier; }
74 bool IsAwait() const { return type_ == kAwaitIdentifier; }
68 bool IsFutureStrictReserved() const { 75 bool IsFutureStrictReserved() const {
69 return type_ == kFutureStrictReservedIdentifier || 76 return type_ == kFutureStrictReservedIdentifier ||
70 type_ == kLetIdentifier || type_ == kStaticIdentifier || 77 type_ == kLetIdentifier || type_ == kStaticIdentifier ||
71 type_ == kYieldIdentifier; 78 type_ == kYieldIdentifier;
72 } 79 }
73 80
74 // Allow identifier->name()[->length()] to work. The preparser 81 // Allow identifier->name()[->length()] to work. The preparser
75 // does not need the actual positions/lengths of the identifiers. 82 // does not need the actual positions/lengths of the identifiers.
76 const PreParserIdentifier* operator->() const { return this; } 83 const PreParserIdentifier* operator->() const { return this; }
77 const PreParserIdentifier raw_name() const { return *this; } 84 const PreParserIdentifier raw_name() const { return *this; }
78 85
79 int position() const { return 0; } 86 int position() const { return 0; }
80 int length() const { return 0; } 87 int length() const { return 0; }
81 88
82 private: 89 private:
83 enum Type { 90 enum Type {
84 kUnknownIdentifier, 91 kUnknownIdentifier,
85 kFutureReservedIdentifier, 92 kFutureReservedIdentifier,
86 kFutureStrictReservedIdentifier, 93 kFutureStrictReservedIdentifier,
87 kLetIdentifier, 94 kLetIdentifier,
88 kStaticIdentifier, 95 kStaticIdentifier,
89 kYieldIdentifier, 96 kYieldIdentifier,
90 kEvalIdentifier, 97 kEvalIdentifier,
91 kArgumentsIdentifier, 98 kArgumentsIdentifier,
92 kUndefinedIdentifier, 99 kUndefinedIdentifier,
93 kPrototypeIdentifier, 100 kPrototypeIdentifier,
94 kConstructorIdentifier 101 kConstructorIdentifier,
102 kEnumIdentifier,
103 kAwaitIdentifier
95 }; 104 };
96 105
97 explicit PreParserIdentifier(Type type) : type_(type) {} 106 explicit PreParserIdentifier(Type type) : type_(type) {}
98 Type type_; 107 Type type_;
99 108
100 friend class PreParserExpression; 109 friend class PreParserExpression;
101 }; 110 };
102 111
103 112
104 class PreParserExpression { 113 class PreParserExpression {
(...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 ParserRecorder* log, uintptr_t stack_limit) 973 ParserRecorder* log, uintptr_t stack_limit)
965 : ParserBase<PreParserTraits>(zone, scanner, stack_limit, NULL, 974 : ParserBase<PreParserTraits>(zone, scanner, stack_limit, NULL,
966 ast_value_factory, log, this) {} 975 ast_value_factory, log, this) {}
967 976
968 // Pre-parse the program from the character stream; returns true on 977 // Pre-parse the program from the character stream; returns true on
969 // success (even if parsing failed, the pre-parse data successfully 978 // success (even if parsing failed, the pre-parse data successfully
970 // captured the syntax error), and false if a stack-overflow happened 979 // captured the syntax error), and false if a stack-overflow happened
971 // during parsing. 980 // during parsing.
972 PreParseResult PreParseProgram(int* materialized_literals = 0, 981 PreParseResult PreParseProgram(int* materialized_literals = 0,
973 bool is_module = false) { 982 bool is_module = false) {
974 Scope* scope = NewScope(scope_, is_module ? MODULE_SCOPE : SCRIPT_SCOPE); 983 Scope* scope = NewScope(scope_, is_module ? MODULE_SCOPE : SCRIPT_SCOPE);
adamk 2016/04/23 00:05:49 This is where the trouble lies. MODULE_SCOPE can't
975 PreParserFactory factory(NULL); 984 PreParserFactory factory(NULL);
976 FunctionState top_scope(&function_state_, &scope_, scope, kNormalFunction, 985 FunctionState top_scope(&function_state_, &scope_, scope, kNormalFunction,
977 &factory); 986 &factory);
978 bool ok = true; 987 bool ok = true;
979 int start_position = scanner()->peek_location().beg_pos; 988 int start_position = scanner()->peek_location().beg_pos;
989 parsing_module_ = is_module;
980 ParseStatementList(Token::EOS, &ok); 990 ParseStatementList(Token::EOS, &ok);
981 if (stack_overflow()) return kPreParseStackOverflow; 991 if (stack_overflow()) return kPreParseStackOverflow;
982 if (!ok) { 992 if (!ok) {
983 ReportUnexpectedToken(scanner()->current_token()); 993 ReportUnexpectedToken(scanner()->current_token());
984 } else if (is_strict(scope_->language_mode())) { 994 } else if (is_strict(scope_->language_mode())) {
985 CheckStrictOctalLiteral(start_position, scanner()->location().end_pos, 995 CheckStrictOctalLiteral(start_position, scanner()->location().end_pos,
986 &ok); 996 &ok);
987 } 997 }
988 if (materialized_literals) { 998 if (materialized_literals) {
989 *materialized_literals = function_state_->materialized_literal_count(); 999 *materialized_literals = function_state_->materialized_literal_count();
990 } 1000 }
991 return kPreParseSuccess; 1001 return kPreParseSuccess;
992 } 1002 }
993 1003
994 // Parses a single function literal, from the opening parentheses before 1004 // Parses a single function literal, from the opening parentheses before
995 // parameters to the closing brace after the body. 1005 // parameters to the closing brace after the body.
996 // Returns a FunctionEntry describing the body of the function in enough 1006 // Returns a FunctionEntry describing the body of the function in enough
997 // detail that it can be lazily compiled. 1007 // detail that it can be lazily compiled.
998 // The scanner is expected to have matched the "function" or "function*" 1008 // The scanner is expected to have matched the "function" or "function*"
999 // keyword and parameters, and have consumed the initial '{'. 1009 // keyword and parameters, and have consumed the initial '{'.
1000 // At return, unless an error occurred, the scanner is positioned before the 1010 // At return, unless an error occurred, the scanner is positioned before the
1001 // the final '}'. 1011 // the final '}'.
1002 PreParseResult PreParseLazyFunction( 1012 PreParseResult PreParseLazyFunction(
1003 LanguageMode language_mode, FunctionKind kind, bool has_simple_parameters, 1013 LanguageMode language_mode, FunctionKind kind, bool has_simple_parameters,
1004 ParserRecorder* log, Scanner::BookmarkScope* bookmark = nullptr); 1014 bool parsing_module, ParserRecorder* log,
1015 Scanner::BookmarkScope* bookmark = nullptr);
1005 1016
1006 private: 1017 private:
1007 friend class PreParserTraits; 1018 friend class PreParserTraits;
1008 1019
1009 static const int kLazyParseTrialLimit = 200; 1020 static const int kLazyParseTrialLimit = 200;
1010 1021
1011 // These types form an algebra over syntactic categories that is just 1022 // These types form an algebra over syntactic categories that is just
1012 // rich enough to let us recognize and propagate the constructs that 1023 // rich enough to let us recognize and propagate the constructs that
1013 // are either being counted in the preparser data, or is important 1024 // are either being counted in the preparser data, or is important
1014 // to throw the correct syntax error exceptions. 1025 // to throw the correct syntax error exceptions.
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1169 const PreParserFormalParameters& parameters, FunctionKind kind, 1180 const PreParserFormalParameters& parameters, FunctionKind kind,
1170 FunctionLiteral::FunctionType function_type, bool* ok) { 1181 FunctionLiteral::FunctionType function_type, bool* ok) {
1171 return pre_parser_->ParseEagerFunctionBody(function_name, pos, parameters, 1182 return pre_parser_->ParseEagerFunctionBody(function_name, pos, parameters,
1172 kind, function_type, ok); 1183 kind, function_type, ok);
1173 } 1184 }
1174 1185
1175 } // namespace internal 1186 } // namespace internal
1176 } // namespace v8 1187 } // namespace v8
1177 1188
1178 #endif // V8_PARSING_PREPARSER_H 1189 #endif // V8_PARSING_PREPARSER_H
OLDNEW
« no previous file with comments | « src/parsing/parser-base.h ('k') | src/parsing/preparser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698