1 // Copyright 2011 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "src/ast/variables.h" 6 7 #include "src/ast/scopes.h" 8 #include "src/common/globals.h" 9 #include "src/objects/objects-inl.h" 10 11 namespace v8 { 12 namespace internal { 13 14 // ---------------------------------------------------------------------------- 15 // Implementation Variable. 16 Variable(Variable * other)17Variable::Variable(Variable* other) 18 : scope_(other->scope_), 19 name_(other->name_), 20 local_if_not_shadowed_(nullptr), 21 next_(nullptr), 22 index_(other->index_), 23 initializer_position_(other->initializer_position_), 24 bit_field_(other->bit_field_) {} 25 IsGlobalObjectProperty() const26bool Variable::IsGlobalObjectProperty() const { 27 // Temporaries are never global, they must always be allocated in the 28 // activation frame. 29 return (IsDynamicVariableMode(mode()) || mode() == VariableMode::kVar) && 30 scope_ != nullptr && scope_->is_script_scope(); 31 } 32 IsReplGlobal() const33bool Variable::IsReplGlobal() const { 34 return scope()->is_repl_mode_scope() && 35 (mode() == VariableMode::kLet || mode() == VariableMode::kConst); 36 } 37 RewriteLocationForRepl()38void Variable::RewriteLocationForRepl() { 39 DCHECK(scope_->is_repl_mode_scope()); 40 41 if (mode() == VariableMode::kLet || mode() == VariableMode::kConst) { 42 DCHECK_EQ(location(), VariableLocation::CONTEXT); 43 bit_field_ = 44 LocationField::update(bit_field_, VariableLocation::REPL_GLOBAL); 45 } 46 } 47 48 } // namespace internal 49 } // namespace v8 50