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

Side by Side Diff: src/full-codegen/full-codegen.cc

Issue 1312613003: Ensure hole checks take place in switch statement scopes (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: skip on TF; roll back arrows Created 5 years, 3 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
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/ast.h" 5 #include "src/ast.h"
6 #include "src/ast-numbering.h" 6 #include "src/ast-numbering.h"
7 #include "src/code-factory.h" 7 #include "src/code-factory.h"
8 #include "src/codegen.h" 8 #include "src/codegen.h"
9 #include "src/compiler.h" 9 #include "src/compiler.h"
10 #include "src/debug/debug.h" 10 #include "src/debug/debug.h"
(...skipping 1567 matching lines...) Expand 10 before | Expand all | Expand 10 after
1578 Context::PREVIOUS_INDEX); 1578 Context::PREVIOUS_INDEX);
1579 // Update local stack frame context field. 1579 // Update local stack frame context field.
1580 codegen_->StoreToFrameField(StandardFrameConstants::kContextOffset, 1580 codegen_->StoreToFrameField(StandardFrameConstants::kContextOffset,
1581 codegen_->context_register()); 1581 codegen_->context_register());
1582 } 1582 }
1583 codegen_->PrepareForBailoutForId(exit_id_, NO_REGISTERS); 1583 codegen_->PrepareForBailoutForId(exit_id_, NO_REGISTERS);
1584 codegen_->scope_ = saved_scope_; 1584 codegen_->scope_ = saved_scope_;
1585 } 1585 }
1586 1586
1587 1587
1588 bool FullCodeGenerator::NeedsHoleCheck(VariableProxy* proxy) {
1589 Variable* var = proxy->var();
1590
1591 if (!var->binding_needs_init()) {
1592 return false;
1593 }
1594
1595 // var->scope() may be NULL when the proxy is located in eval code and
1596 // refers to a potential outside binding. Currently those bindings are
1597 // always looked up dynamically, i.e. in that case
1598 // var->location() == LOOKUP.
1599 // always holds.
1600 DCHECK(var->scope() != NULL);
adamk 2015/08/24 22:15:01 Can you also add a DCHECK about the location? Now
Dan Ehrenberg 2015/08/25 01:48:13 Good idea, done
1601
1602 // Check if the binding really needs an initialization check. The check
1603 // can be skipped in the following situation: we have a LET or CONST
1604 // binding in harmony mode, both the Variable and the VariableProxy have
1605 // the same declaration scope (i.e. they are both in global code, in the
1606 // same function or in the same eval code) and the VariableProxy is in
1607 // the source physically located after the initializer of the variable.
1608 //
1609 // We cannot skip any initialization checks for CONST in non-harmony
1610 // mode because const variables may be declared but never initialized:
1611 // if (false) { const x; }; var y = x;
1612 //
1613 // The condition on the declaration scopes is a conservative check for
1614 // nested functions that access a binding and are called before the
1615 // binding is initialized:
1616 // function() { f(); let x = 1; function f() { x = 2; } }
1617 //
1618 // The check cannot be skipped on non-linear scopes, namely switch
adamk 2015/08/24 22:15:01 I think the bit about non-linear scopes should be
Dan Ehrenberg 2015/08/25 01:48:14 Done
1619 // scopes, to ensure tests are done in cases like the following:
1620 // switch (1) { case 0: let x = 2; case 1: f(x); }
1621 if (var->scope()->DeclarationScope() != scope()->DeclarationScope()) {
1622 return true;
1623 } else if (var->is_this()) {
adamk 2015/08/24 22:15:01 I'd just make this a separate if statement, no nee
Dan Ehrenberg 2015/08/25 01:48:14 Done
1624 CHECK(literal() != nullptr &&
adamk 2015/08/24 22:15:01 This CHECK looks scary, any idea why it's here?
Dan Ehrenberg 2015/08/25 01:48:14 Not exactly. I guess when 'this' occurs globally,
1625 (literal()->kind() & kSubclassConstructor) != 0);
1626 // TODO(littledan): implement 'this' hole check elimination.
1627 return true;
1628 } else {
adamk 2015/08/24 22:15:01 Same thing here, I'd remove the else.
Dan Ehrenberg 2015/08/25 01:48:14 Done
1629 // Check that we always have valid source position.
1630 DCHECK(var->initializer_position() != RelocInfo::kNoPosition);
1631 DCHECK(proxy->position() != RelocInfo::kNoPosition);
1632 return var->mode() == CONST_LEGACY || scope()->is_nonlinear() ||
adamk 2015/08/24 22:15:01 I think you need to be checking var->scope()->is_n
Dan Ehrenberg 2015/08/25 01:48:13 Oh, good catch! I fixed the bug and added a test b
1633 var->initializer_position() >= proxy->position();
1634 }
1635 }
1636
1637
1588 #undef __ 1638 #undef __
1589 1639
1590 1640
1591 } // namespace internal 1641 } // namespace internal
1592 } // namespace v8 1642 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698