blob: cd1d8f77b712eeab6058faacb19c285513453508 [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 Murdoch62ed6312017-06-06 11:06:27 +01009#include "src/objects-inl.h"
Ben Murdoch014dc512016-03-22 12:00:34 +000010
11namespace v8 {
12namespace internal {
13
14// ----------------------------------------------------------------------------
15// Implementation Variable.
16
Ben Murdoch014dc512016-03-22 12:00:34 +000017Variable::Variable(Scope* scope, const AstRawString* name, VariableMode mode,
Ben Murdochf3b273f2017-01-17 12:11:28 +000018 VariableKind kind, InitializationFlag initialization_flag,
Ben Murdoch014dc512016-03-22 12:00:34 +000019 MaybeAssignedFlag maybe_assigned_flag)
20 : scope_(scope),
21 name_(name),
Ben Murdochf3b273f2017-01-17 12:11:28 +000022 local_if_not_shadowed_(nullptr),
Ben Murdochc8c1d9e2017-03-08 14:04:23 +000023 next_(nullptr),
Ben Murdoch014dc512016-03-22 12:00:34 +000024 index_(-1),
Ben Murdochf91f0612016-11-29 16:50:11 +000025 initializer_position_(kNoSourcePosition),
Ben Murdochf3b273f2017-01-17 12:11:28 +000026 bit_field_(MaybeAssignedFlagField::encode(maybe_assigned_flag) |
27 InitializationFlagField::encode(initialization_flag) |
28 VariableModeField::encode(mode) | IsUsedField::encode(false) |
29 ForceContextAllocationField::encode(false) |
30 LocationField::encode(VariableLocation::UNALLOCATED) |
31 VariableKindField::encode(kind)) {
Ben Murdoch014dc512016-03-22 12:00:34 +000032 // Var declared variables never need initialization.
33 DCHECK(!(mode == VAR && initialization_flag == kNeedsInitialization));
34}
35
36
37bool Variable::IsGlobalObjectProperty() const {
38 // Temporaries are never global, they must always be allocated in the
39 // activation frame.
Ben Murdoch62ed6312017-06-06 11:06:27 +010040 return (IsDynamicVariableMode(mode()) || mode() == VAR) &&
41 scope_ != nullptr && 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