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

Unified Diff: src/parser.h

Issue 1189743003: [destructuring] Implement parameter pattern matching. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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
Index: src/parser.h
diff --git a/src/parser.h b/src/parser.h
index 39d0d9278b132fd4dfc5a9ebd104661f1f846205..78f2176cae9cf01d838e60a8eac824111e1630ee 100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -751,6 +751,10 @@ class ParserTraits {
ZoneList<v8::internal::Statement*>* NewStatementList(int size, Zone* zone) {
return new(zone) ZoneList<v8::internal::Statement*>(size, zone);
}
+
+ V8_INLINE void AddParameterInitializationBlock(
+ ZoneList<v8::internal::Statement*>* body, bool* ok);
+
V8_INLINE Scope* NewScope(Scope* parent_scope, ScopeType scope_type,
FunctionKind kind = kNormalFunction);
@@ -1121,6 +1125,8 @@ class Parser : public ParserBase<ParserTraits> {
PreParser::PreParseResult ParseLazyFunctionBodyWithPreParser(
SingletonLogger* logger, Scanner::BookmarkScope* bookmark = nullptr);
+ Block* BuildParameterInitializationBlock(bool* ok);
+
// Consumes the ending }.
ZoneList<Statement*>* ParseEagerFunctionBody(
const AstRawString* function_name, int pos, Variable* fvar,
@@ -1274,13 +1280,14 @@ void ParserTraits::DeclareFormalParameter(Scope* scope, Expression* pattern,
ExpressionClassifier* classifier,
bool is_rest) {
bool is_duplicate = false;
- if (!pattern->IsVariableProxy()) {
- // TODO(dslomov): implement.
- DCHECK(parser_->allow_harmony_destructuring());
- return;
- }
- auto name = pattern->AsVariableProxy()->raw_name();
- Variable* var = scope->DeclareParameter(name, VAR, is_rest, &is_duplicate);
+ bool is_simple_name = pattern->IsVariableProxy();
+ DCHECK(parser_->allow_harmony_destructuring() || is_simple_name);
+
+ const AstRawString* name = is_simple_name
+ ? pattern->AsVariableProxy()->raw_name()
+ : parser_->ast_value_factory()->empty_string();
+ Variable* var = scope->DeclareParameter(
+ name, is_simple_name ? nullptr : pattern, VAR, is_rest, &is_duplicate);
if (is_sloppy(scope->language_mode())) {
// TODO(sigurds) Mark every parameter as maybe assigned. This is a
// conservative approximation necessary to account for parameters
@@ -1292,6 +1299,16 @@ void ParserTraits::DeclareFormalParameter(Scope* scope, Expression* pattern,
parser_->scanner()->location());
}
}
+
+
+void ParserTraits::AddParameterInitializationBlock(
+ ZoneList<v8::internal::Statement*>* body, bool* ok) {
+ auto* init_block = parser_->BuildParameterInitializationBlock(ok);
+ if (!*ok) return;
+ if (init_block != nullptr) {
+ body->Add(init_block, parser_->zone());
+ }
+}
} } // namespace v8::internal
#endif // V8_PARSER_H_
« no previous file with comments | « src/mips64/full-codegen-mips64.cc ('k') | src/parser.cc » ('j') | src/parser.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698