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

Unified 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: Relax assertion criteria 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 side-by-side diff with in-line comments
Download patch
Index: src/parsing/preparser.h
diff --git a/src/parsing/preparser.h b/src/parsing/preparser.h
index ecea789cc0f6f0aaf081dac108c7eb69672bee4d..3fd3ce84807547a6ca8799c7ade400d0c74a616c 100644
--- a/src/parsing/preparser.h
+++ b/src/parsing/preparser.h
@@ -55,6 +55,12 @@ class PreParserIdentifier {
static PreParserIdentifier Constructor() {
return PreParserIdentifier(kConstructorIdentifier);
}
+ static PreParserIdentifier Enum() {
+ return PreParserIdentifier(kEnumIdentifier);
+ }
+ static PreParserIdentifier Await() {
+ return PreParserIdentifier(kAwaitIdentifier);
+ }
bool IsEval() const { return type_ == kEvalIdentifier; }
bool IsArguments() const { return type_ == kArgumentsIdentifier; }
bool IsEvalOrArguments() const { return IsEval() || IsArguments(); }
@@ -64,7 +70,8 @@ class PreParserIdentifier {
bool IsYield() const { return type_ == kYieldIdentifier; }
bool IsPrototype() const { return type_ == kPrototypeIdentifier; }
bool IsConstructor() const { return type_ == kConstructorIdentifier; }
- bool IsFutureReserved() const { return type_ == kFutureReservedIdentifier; }
+ bool IsEnum() const { return type_ == kEnumIdentifier; }
+ bool IsAwait() const { return type_ == kAwaitIdentifier; }
bool IsFutureStrictReserved() const {
return type_ == kFutureStrictReservedIdentifier ||
type_ == kLetIdentifier || type_ == kStaticIdentifier ||
@@ -91,7 +98,9 @@ class PreParserIdentifier {
kArgumentsIdentifier,
kUndefinedIdentifier,
kPrototypeIdentifier,
- kConstructorIdentifier
+ kConstructorIdentifier,
+ kEnumIdentifier,
+ kAwaitIdentifier
};
explicit PreParserIdentifier(Type type) : type_(type) {}
@@ -974,12 +983,21 @@ class PreParser : public ParserBase<PreParserTraits> {
// during parsing.
PreParseResult PreParseProgram(int* materialized_literals = 0,
bool is_module = false) {
- Scope* scope = NewScope(scope_, is_module ? MODULE_SCOPE : SCRIPT_SCOPE);
+ Scope* scope = NewScope(scope_, SCRIPT_SCOPE);
+
+ // ModuleDeclarationInstantiation for Source Text Module Records creates a
+ // new Module Environment Record whose outer lexical environment record is
+ // the global scope.
+ if (is_module) {
+ scope = NewScope(scope, MODULE_SCOPE);
+ }
+
PreParserFactory factory(NULL);
FunctionState top_scope(&function_state_, &scope_, scope, kNormalFunction,
&factory);
bool ok = true;
int start_position = scanner()->peek_location().beg_pos;
+ parsing_module_ = is_module;
ParseStatementList(Token::EOS, &ok);
if (stack_overflow()) return kPreParseStackOverflow;
if (!ok) {
@@ -1002,9 +1020,12 @@ class PreParser : public ParserBase<PreParserTraits> {
// keyword and parameters, and have consumed the initial '{'.
// At return, unless an error occurred, the scanner is positioned before the
// the final '}'.
- PreParseResult PreParseLazyFunction(
- LanguageMode language_mode, FunctionKind kind, bool has_simple_parameters,
- ParserRecorder* log, Scanner::BookmarkScope* bookmark, int* use_counts);
+ PreParseResult PreParseLazyFunction(LanguageMode language_mode,
+ FunctionKind kind,
+ bool has_simple_parameters,
+ bool parsing_module, ParserRecorder* log,
+ Scanner::BookmarkScope* bookmark,
+ int* use_counts);
private:
friend class PreParserTraits;
« no previous file with comments | « src/parsing/parser-base.h ('k') | src/parsing/preparser.cc » ('j') | test/cctest/test-parsing.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698