blob: cc269cd0c7f850d76cf9861b1dd55d64406051bb [file] [log] [blame]
Ben Murdoch014dc512016-03-22 12:00:34 +00001// 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
Ben Murdoch014dc512016-03-22 12:00:34 +00007#include "src/ast/scopes.h"
Ben Murdochf91f0612016-11-29 16:50:11 +00008#include "src/globals.h"
Ben Murdoch014dc512016-03-22 12:00:34 +00009
10namespace v8 {
11namespace internal {
12
13// ----------------------------------------------------------------------------
14// Implementation Variable.
15
Ben Murdoch014dc512016-03-22 12:00:34 +000016Variable::Variable(Scope* scope, const AstRawString* name, VariableMode mode,
Ben Murdochf3b273f2017-01-17 12:11:28 +000017 VariableKind kind, InitializationFlag initialization_flag,
Ben Murdoch014dc512016-03-22 12:00:34 +000018 MaybeAssignedFlag maybe_assigned_flag)
19 : scope_(scope),
20 name_(name),
Ben Murdochf3b273f2017-01-17 12:11:28 +000021 local_if_not_shadowed_(nullptr),
Ben Murdoch014dc512016-03-22 12:00:34 +000022 index_(-1),
Ben Murdochf91f0612016-11-29 16:50:11 +000023 initializer_position_(kNoSourcePosition),
Ben Murdochf3b273f2017-01-17 12:11:28 +000024 bit_field_(MaybeAssignedFlagField::encode(maybe_assigned_flag) |
25 InitializationFlagField::encode(initialization_flag) |
26 VariableModeField::encode(mode) | IsUsedField::encode(false) |
27 ForceContextAllocationField::encode(false) |
28 LocationField::encode(VariableLocation::UNALLOCATED) |
29 VariableKindField::encode(kind)) {
Ben Murdoch014dc512016-03-22 12:00:34 +000030 // Var declared variables never need initialization.
31 DCHECK(!(mode == VAR && initialization_flag == kNeedsInitialization));
32}
33
34
35bool Variable::IsGlobalObjectProperty() const {
36 // Temporaries are never global, they must always be allocated in the
37 // activation frame.
Ben Murdochf3b273f2017-01-17 12:11:28 +000038 return (IsDynamicVariableMode(mode()) ||
39 (IsDeclaredVariableMode(mode()) && !IsLexicalVariableMode(mode()))) &&
Ben Murdochf91f0612016-11-29 16:50:11 +000040 scope_ != NULL && scope_->is_script_scope();
Ben Murdoch014dc512016-03-22 12:00:34 +000041}
42
43
44bool Variable::IsStaticGlobalObjectProperty() const {
45 // Temporaries are never global, they must always be allocated in the
46 // activation frame.
Ben Murdochf3b273f2017-01-17 12:11:28 +000047 return (IsDeclaredVariableMode(mode()) && !IsLexicalVariableMode(mode())) &&
Ben Murdochf91f0612016-11-29 16:50:11 +000048 scope_ != NULL && scope_->is_script_scope();
Ben Murdoch014dc512016-03-22 12:00:34 +000049}
50
51
Ben Murdoch014dc512016-03-22 12:00:34 +000052} // namespace internal
53} // namespace v8