blob: 3771bfee1258bf22860575ea59fed51a6aa3ef21 [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 Murdochc8c1d9e2017-03-08 14:04:23 +000022 next_(nullptr),
Ben Murdoch014dc512016-03-22 12:00:34 +000023 index_(-1),
Ben Murdochf91f0612016-11-29 16:50:11 +000024 initializer_position_(kNoSourcePosition),
Ben Murdochf3b273f2017-01-17 12:11:28 +000025 bit_field_(MaybeAssignedFlagField::encode(maybe_assigned_flag) |
26 InitializationFlagField::encode(initialization_flag) |
27 VariableModeField::encode(mode) | IsUsedField::encode(false) |
28 ForceContextAllocationField::encode(false) |
29 LocationField::encode(VariableLocation::UNALLOCATED) |
30 VariableKindField::encode(kind)) {
Ben Murdoch014dc512016-03-22 12:00:34 +000031 // Var declared variables never need initialization.
32 DCHECK(!(mode == VAR && initialization_flag == kNeedsInitialization));
33}
34
35
36bool Variable::IsGlobalObjectProperty() const {
37 // Temporaries are never global, they must always be allocated in the
38 // activation frame.
Ben Murdochf3b273f2017-01-17 12:11:28 +000039 return (IsDynamicVariableMode(mode()) ||
40 (IsDeclaredVariableMode(mode()) && !IsLexicalVariableMode(mode()))) &&
Ben Murdochf91f0612016-11-29 16:50:11 +000041 scope_ != NULL && scope_->is_script_scope();
Ben Murdoch014dc512016-03-22 12:00:34 +000042}
43
Ben Murdoch014dc512016-03-22 12:00:34 +000044} // namespace internal
45} // namespace v8