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

Side by Side Diff: src/parsing/parser.cc

Issue 2056993004: Parser: Desugar default derived constructor to spread/rest (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: make rest arg optional Created 4 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 unified diff | Download patch
« no previous file with comments | « no previous file | test/test262/test262.status » ('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 #include "src/parsing/parser.h" 5 #include "src/parsing/parser.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/ast/ast.h" 8 #include "src/ast/ast.h"
9 #include "src/ast/ast-expression-rewriter.h" 9 #include "src/ast/ast-expression-rewriter.h"
10 #include "src/ast/ast-expression-visitor.h" 10 #include "src/ast/ast-expression-visitor.h"
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 int materialized_literal_count = -1; 185 int materialized_literal_count = -1;
186 int expected_property_count = -1; 186 int expected_property_count = -1;
187 int parameter_count = 0; 187 int parameter_count = 0;
188 if (name == nullptr) name = ast_value_factory()->empty_string(); 188 if (name == nullptr) name = ast_value_factory()->empty_string();
189 189
190 FunctionKind kind = call_super ? FunctionKind::kDefaultSubclassConstructor 190 FunctionKind kind = call_super ? FunctionKind::kDefaultSubclassConstructor
191 : FunctionKind::kDefaultBaseConstructor; 191 : FunctionKind::kDefaultBaseConstructor;
192 Scope* function_scope = NewScope(scope, FUNCTION_SCOPE, kind); 192 Scope* function_scope = NewScope(scope, FUNCTION_SCOPE, kind);
193 SetLanguageMode(function_scope, 193 SetLanguageMode(function_scope,
194 static_cast<LanguageMode>(language_mode | STRICT)); 194 static_cast<LanguageMode>(language_mode | STRICT));
195
Dan Ehrenberg 2016/06/11 01:48:57 Nit: revert whitespace change
gsathya 2016/06/11 01:54:02 Done.
195 // Set start and end position to the same value 196 // Set start and end position to the same value
196 function_scope->set_start_position(pos); 197 function_scope->set_start_position(pos);
197 function_scope->set_end_position(pos); 198 function_scope->set_end_position(pos);
198 ZoneList<Statement*>* body = NULL; 199 ZoneList<Statement*>* body = NULL;
199 200
200 { 201 {
201 AstNodeFactory function_factory(ast_value_factory()); 202 AstNodeFactory function_factory(ast_value_factory());
202 FunctionState function_state(&function_state_, &scope_, function_scope, 203 FunctionState function_state(&function_state_, &scope_, function_scope,
203 kind, &function_factory); 204 kind, &function_factory);
204 205
205 body = new (zone()) ZoneList<Statement*>(call_super ? 2 : 1, zone()); 206 body = new (zone()) ZoneList<Statement*>(call_super ? 2 : 1, zone());
206 if (call_super) { 207 if (call_super) {
207 // $super_constructor = %_GetSuperConstructor(<this-function>) 208 // $super_constructor = %_GetSuperConstructor(<this-function>)
208 // %reflect_construct($super_constructor, arguments, new.target) 209 // %reflect_construct(
210 // $super_constructor, InternalArray(...args), new.target)
211 auto constructor_args_name = ast_value_factory()->empty_string();
212 bool is_duplicate;
213 bool is_rest = true;
214 bool is_optional = false;
215 Variable* constructor_args =
216 function_scope->DeclareParameter(constructor_args_name, TEMPORARY,
217 is_optional, is_rest, &is_duplicate);
218
209 ZoneList<Expression*>* args = 219 ZoneList<Expression*>* args =
210 new (zone()) ZoneList<Expression*>(2, zone()); 220 new (zone()) ZoneList<Expression*>(2, zone());
211 VariableProxy* this_function_proxy = scope_->NewUnresolved( 221 VariableProxy* this_function_proxy = scope_->NewUnresolved(
212 factory(), ast_value_factory()->this_function_string(), 222 factory(), ast_value_factory()->this_function_string(),
213 Variable::NORMAL, pos); 223 Variable::NORMAL, pos);
214 ZoneList<Expression*>* tmp = 224 ZoneList<Expression*>* tmp =
215 new (zone()) ZoneList<Expression*>(1, zone()); 225 new (zone()) ZoneList<Expression*>(1, zone());
216 tmp->Add(this_function_proxy, zone()); 226 tmp->Add(this_function_proxy, zone());
217 Expression* super_constructor = factory()->NewCallRuntime( 227 Expression* super_constructor = factory()->NewCallRuntime(
218 Runtime::kInlineGetSuperConstructor, tmp, pos); 228 Runtime::kInlineGetSuperConstructor, tmp, pos);
219 args->Add(super_constructor, zone()); 229 args->Add(super_constructor, zone());
220 VariableProxy* arguments_proxy = scope_->NewUnresolved( 230 Spread* spread_args = factory()->NewSpread(
221 factory(), ast_value_factory()->arguments_string(), Variable::NORMAL, 231 factory()->NewVariableProxy(constructor_args), pos, pos);
222 pos); 232 ZoneList<Expression*>* spread_args_expr =
223 args->Add(arguments_proxy, zone()); 233 new (zone()) ZoneList<Expression*>(1, zone());
234 spread_args_expr->Add(spread_args, zone());
235 args->AddAll(*PrepareSpreadArguments(spread_args_expr), zone());
224 VariableProxy* new_target_proxy = scope_->NewUnresolved( 236 VariableProxy* new_target_proxy = scope_->NewUnresolved(
225 factory(), ast_value_factory()->new_target_string(), Variable::NORMAL, 237 factory(), ast_value_factory()->new_target_string(), Variable::NORMAL,
226 pos); 238 pos);
227 args->Add(new_target_proxy, zone()); 239 args->Add(new_target_proxy, zone());
228 CallRuntime* call = factory()->NewCallRuntime( 240 CallRuntime* call = factory()->NewCallRuntime(
229 Context::REFLECT_CONSTRUCT_INDEX, args, pos); 241 Context::REFLECT_CONSTRUCT_INDEX, args, pos);
230 body->Add(factory()->NewReturnStatement(call, pos), zone()); 242 body->Add(factory()->NewReturnStatement(call, pos), zone());
231 } 243 }
232 244
233 materialized_literal_count = function_state.materialized_literal_count(); 245 materialized_literal_count = function_state.materialized_literal_count();
(...skipping 6731 matching lines...) Expand 10 before | Expand all | Expand 10 after
6965 try_block, target); 6977 try_block, target);
6966 final_loop = target; 6978 final_loop = target;
6967 } 6979 }
6968 6980
6969 return final_loop; 6981 return final_loop;
6970 } 6982 }
6971 6983
6972 6984
6973 } // namespace internal 6985 } // namespace internal
6974 } // namespace v8 6986 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/test262/test262.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698