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

Side by Side Diff: src/scopes.cc

Issue 1078483002: [es6]: Lexical arguments for arrow functions (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Make arguments() DCHECK instead Created 5 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/scopes.h ('k') | test/mjsunit/harmony/arrow-functions-lexical-arguments.js » ('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/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/bootstrapper.h" 8 #include "src/bootstrapper.h"
9 #include "src/messages.h" 9 #include "src/messages.h"
10 #include "src/parser.h" 10 #include "src/parser.h"
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 variables_.Declare(this, ast_value_factory_->new_target_string(), 321 variables_.Declare(this, ast_value_factory_->new_target_string(),
322 CONST, Variable::NEW_TARGET, kCreatedInitialized); 322 CONST, Variable::NEW_TARGET, kCreatedInitialized);
323 new_target_->AllocateTo(Variable::PARAMETER, -2); 323 new_target_->AllocateTo(Variable::PARAMETER, -2);
324 new_target_->set_is_used(); 324 new_target_->set_is_used();
325 } 325 }
326 } else { 326 } else {
327 DCHECK(outer_scope() != NULL); 327 DCHECK(outer_scope() != NULL);
328 receiver_ = outer_scope()->receiver(); 328 receiver_ = outer_scope()->receiver();
329 } 329 }
330 330
331 if (is_function_scope()) { 331 if (is_function_scope() && !is_arrow_scope()) {
332 // Declare 'arguments' variable which exists in all functions. 332 // Declare 'arguments' variable which exists in all non arrow functions.
333 // Note that it might never be accessed, in which case it won't be 333 // Note that it might never be accessed, in which case it won't be
334 // allocated during variable allocation. 334 // allocated during variable allocation.
335 variables_.Declare(this, 335 variables_.Declare(this,
336 ast_value_factory_->arguments_string(), 336 ast_value_factory_->arguments_string(),
337 VAR, 337 VAR,
338 Variable::ARGUMENTS, 338 Variable::ARGUMENTS,
339 kCreatedInitialized); 339 kCreatedInitialized);
340 } 340 }
341 } 341 }
342 342
(...skipping 945 matching lines...) Expand 10 before | Expand all | Expand 10 after
1288 1288
1289 1289
1290 void Scope::AllocateHeapSlot(Variable* var) { 1290 void Scope::AllocateHeapSlot(Variable* var) {
1291 var->AllocateTo(Variable::CONTEXT, num_heap_slots_++); 1291 var->AllocateTo(Variable::CONTEXT, num_heap_slots_++);
1292 } 1292 }
1293 1293
1294 1294
1295 void Scope::AllocateParameterLocals(Isolate* isolate) { 1295 void Scope::AllocateParameterLocals(Isolate* isolate) {
1296 DCHECK(is_function_scope()); 1296 DCHECK(is_function_scope());
1297 Variable* arguments = LookupLocal(ast_value_factory_->arguments_string()); 1297 Variable* arguments = LookupLocal(ast_value_factory_->arguments_string());
1298 DCHECK(arguments != NULL); // functions have 'arguments' declared implicitly 1298 // Functions have 'arguments' declared implicitly in all non arrow functions.
1299 DCHECK(arguments != nullptr || is_arrow_scope());
1299 1300
1300 bool uses_sloppy_arguments = false; 1301 bool uses_sloppy_arguments = false;
1301 1302
1302 if (MustAllocate(arguments) && !HasArgumentsParameter(isolate)) { 1303 if (arguments != nullptr && MustAllocate(arguments) &&
1304 !HasArgumentsParameter(isolate)) {
1303 // 'arguments' is used. Unless there is also a parameter called 1305 // 'arguments' is used. Unless there is also a parameter called
1304 // 'arguments', we must be conservative and allocate all parameters to 1306 // 'arguments', we must be conservative and allocate all parameters to
1305 // the context assuming they will be captured by the arguments object. 1307 // the context assuming they will be captured by the arguments object.
1306 // If we have a parameter named 'arguments', a (new) value is always 1308 // If we have a parameter named 'arguments', a (new) value is always
1307 // assigned to it via the function invocation. Then 'arguments' denotes 1309 // assigned to it via the function invocation. Then 'arguments' denotes
1308 // that specific parameter value and cannot be used to access the 1310 // that specific parameter value and cannot be used to access the
1309 // parameters, which is why we don't need to allocate an arguments 1311 // parameters, which is why we don't need to allocate an arguments
1310 // object in that case. 1312 // object in that case.
1311 1313
1312 // We are using 'arguments'. Tell the code generator that is needs to 1314 // We are using 'arguments'. Tell the code generator that is needs to
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1462 (function_ != NULL && function_->proxy()->var()->IsStackLocal() ? 1 : 0); 1464 (function_ != NULL && function_->proxy()->var()->IsStackLocal() ? 1 : 0);
1463 } 1465 }
1464 1466
1465 1467
1466 int Scope::ContextLocalCount() const { 1468 int Scope::ContextLocalCount() const {
1467 if (num_heap_slots() == 0) return 0; 1469 if (num_heap_slots() == 0) return 0;
1468 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - 1470 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS -
1469 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); 1471 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0);
1470 } 1472 }
1471 } } // namespace v8::internal 1473 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/scopes.h ('k') | test/mjsunit/harmony/arrow-functions-lexical-arguments.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698