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

Unified 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, 4 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/full-codegen/full-codegen.cc
diff --git a/src/full-codegen/full-codegen.cc b/src/full-codegen/full-codegen.cc
index 8b71eb7f9d08ad398695d9f8c74893a887faa320..572e15a195805d9f3504ab03c61b97e308161e9d 100644
--- a/src/full-codegen/full-codegen.cc
+++ b/src/full-codegen/full-codegen.cc
@@ -1585,6 +1585,56 @@ FullCodeGenerator::EnterBlockScopeIfNeeded::~EnterBlockScopeIfNeeded() {
}
+bool FullCodeGenerator::NeedsHoleCheck(VariableProxy* proxy) {
+ Variable* var = proxy->var();
+
+ if (!var->binding_needs_init()) {
+ return false;
+ }
+
+ // var->scope() may be NULL when the proxy is located in eval code and
+ // refers to a potential outside binding. Currently those bindings are
+ // always looked up dynamically, i.e. in that case
+ // var->location() == LOOKUP.
+ // always holds.
+ 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
+
+ // Check if the binding really needs an initialization check. The check
+ // can be skipped in the following situation: we have a LET or CONST
+ // binding in harmony mode, both the Variable and the VariableProxy have
+ // the same declaration scope (i.e. they are both in global code, in the
+ // same function or in the same eval code) and the VariableProxy is in
+ // the source physically located after the initializer of the variable.
+ //
+ // We cannot skip any initialization checks for CONST in non-harmony
+ // mode because const variables may be declared but never initialized:
+ // if (false) { const x; }; var y = x;
+ //
+ // The condition on the declaration scopes is a conservative check for
+ // nested functions that access a binding and are called before the
+ // binding is initialized:
+ // function() { f(); let x = 1; function f() { x = 2; } }
+ //
+ // 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
+ // scopes, to ensure tests are done in cases like the following:
+ // switch (1) { case 0: let x = 2; case 1: f(x); }
+ if (var->scope()->DeclarationScope() != scope()->DeclarationScope()) {
+ return true;
+ } 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
+ 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,
+ (literal()->kind() & kSubclassConstructor) != 0);
+ // TODO(littledan): implement 'this' hole check elimination.
+ return true;
+ } 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
+ // Check that we always have valid source position.
+ DCHECK(var->initializer_position() != RelocInfo::kNoPosition);
+ DCHECK(proxy->position() != RelocInfo::kNoPosition);
+ 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
+ var->initializer_position() >= proxy->position();
+ }
+}
+
+
#undef __

Powered by Google App Engine
This is Rietveld 408576698