| OLD | NEW |
| 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/full-codegen/full-codegen.h" | 5 #include "src/full-codegen/full-codegen.h" |
| 6 | 6 |
| 7 #include "src/ast/ast-numbering.h" | 7 #include "src/ast/ast-numbering.h" |
| 8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
| 9 #include "src/ast/prettyprinter.h" | 9 #include "src/ast/prettyprinter.h" |
| 10 #include "src/ast/scopes.h" | 10 #include "src/ast/scopes.h" |
| (...skipping 1964 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1975 codegen_->LoadContextField(codegen_->context_register(), | 1975 codegen_->LoadContextField(codegen_->context_register(), |
| 1976 Context::PREVIOUS_INDEX); | 1976 Context::PREVIOUS_INDEX); |
| 1977 // Update local stack frame context field. | 1977 // Update local stack frame context field. |
| 1978 codegen_->StoreToFrameField(StandardFrameConstants::kContextOffset, | 1978 codegen_->StoreToFrameField(StandardFrameConstants::kContextOffset, |
| 1979 codegen_->context_register()); | 1979 codegen_->context_register()); |
| 1980 } | 1980 } |
| 1981 codegen_->PrepareForBailoutForId(exit_id_, BailoutState::NO_REGISTERS); | 1981 codegen_->PrepareForBailoutForId(exit_id_, BailoutState::NO_REGISTERS); |
| 1982 codegen_->scope_ = saved_scope_; | 1982 codegen_->scope_ = saved_scope_; |
| 1983 } | 1983 } |
| 1984 | 1984 |
| 1985 | |
| 1986 bool FullCodeGenerator::NeedsHoleCheckForLoad(VariableProxy* proxy) { | |
| 1987 Variable* var = proxy->var(); | |
| 1988 | |
| 1989 if (!var->binding_needs_init()) { | |
| 1990 return false; | |
| 1991 } | |
| 1992 | |
| 1993 // var->scope() may be NULL when the proxy is located in eval code and | |
| 1994 // refers to a potential outside binding. Currently those bindings are | |
| 1995 // always looked up dynamically, i.e. in that case | |
| 1996 // var->location() == LOOKUP. | |
| 1997 // always holds. | |
| 1998 DCHECK(var->scope() != NULL); | |
| 1999 DCHECK(var->location() == VariableLocation::PARAMETER || | |
| 2000 var->location() == VariableLocation::LOCAL || | |
| 2001 var->location() == VariableLocation::CONTEXT); | |
| 2002 | |
| 2003 // Check if the binding really needs an initialization check. The check | |
| 2004 // can be skipped in the following situation: we have a LET or CONST | |
| 2005 // binding in harmony mode, both the Variable and the VariableProxy have | |
| 2006 // the same declaration scope (i.e. they are both in global code, in the | |
| 2007 // same function or in the same eval code), the VariableProxy is in | |
| 2008 // the source physically located after the initializer of the variable, | |
| 2009 // and that the initializer cannot be skipped due to a nonlinear scope. | |
| 2010 // | |
| 2011 // We cannot skip any initialization checks for CONST in non-harmony | |
| 2012 // mode because const variables may be declared but never initialized: | |
| 2013 // if (false) { const x; }; var y = x; | |
| 2014 // | |
| 2015 // The condition on the declaration scopes is a conservative check for | |
| 2016 // nested functions that access a binding and are called before the | |
| 2017 // binding is initialized: | |
| 2018 // function() { f(); let x = 1; function f() { x = 2; } } | |
| 2019 // | |
| 2020 // The check cannot be skipped on non-linear scopes, namely switch | |
| 2021 // scopes, to ensure tests are done in cases like the following: | |
| 2022 // switch (1) { case 0: let x = 2; case 1: f(x); } | |
| 2023 // The scope of the variable needs to be checked, in case the use is | |
| 2024 // in a sub-block which may be linear. | |
| 2025 if (var->scope()->GetDeclarationScope() != scope()->GetDeclarationScope()) { | |
| 2026 return true; | |
| 2027 } | |
| 2028 | |
| 2029 if (var->is_this()) { | |
| 2030 DCHECK(literal() != nullptr && | |
| 2031 (literal()->kind() & kSubclassConstructor) != 0); | |
| 2032 // TODO(littledan): implement 'this' hole check elimination. | |
| 2033 return true; | |
| 2034 } | |
| 2035 | |
| 2036 // Check that we always have valid source position. | |
| 2037 DCHECK(var->initializer_position() != kNoSourcePosition); | |
| 2038 DCHECK(proxy->position() != kNoSourcePosition); | |
| 2039 | |
| 2040 return var->scope()->is_nonlinear() || | |
| 2041 var->initializer_position() >= proxy->position(); | |
| 2042 } | |
| 2043 | |
| 2044 Handle<Script> FullCodeGenerator::script() { return info_->script(); } | 1985 Handle<Script> FullCodeGenerator::script() { return info_->script(); } |
| 2045 | 1986 |
| 2046 LanguageMode FullCodeGenerator::language_mode() { | 1987 LanguageMode FullCodeGenerator::language_mode() { |
| 2047 return scope()->language_mode(); | 1988 return scope()->language_mode(); |
| 2048 } | 1989 } |
| 2049 | 1990 |
| 2050 bool FullCodeGenerator::has_simple_parameters() { | 1991 bool FullCodeGenerator::has_simple_parameters() { |
| 2051 return info_->has_simple_parameters(); | 1992 return info_->has_simple_parameters(); |
| 2052 } | 1993 } |
| 2053 | 1994 |
| 2054 FunctionLiteral* FullCodeGenerator::literal() const { return info_->literal(); } | 1995 FunctionLiteral* FullCodeGenerator::literal() const { return info_->literal(); } |
| 2055 | 1996 |
| 2056 #undef __ | 1997 #undef __ |
| 2057 | 1998 |
| 2058 | 1999 |
| 2059 } // namespace internal | 2000 } // namespace internal |
| 2060 } // namespace v8 | 2001 } // namespace v8 |
| OLD | NEW |