aboutsummaryrefslogtreecommitdiff
path: root/deps/v8/src/ast/variables.cc
blob: cc269cd0c7f850d76cf9861b1dd55d64406051bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright 2011 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "src/ast/variables.h"

#include "src/ast/scopes.h"
#include "src/globals.h"

namespace v8 {
namespace internal {

// ----------------------------------------------------------------------------
// Implementation Variable.

Variable::Variable(Scope* scope, const AstRawString* name, VariableMode mode,
                   VariableKind kind, InitializationFlag initialization_flag,
                   MaybeAssignedFlag maybe_assigned_flag)
    : scope_(scope),
      name_(name),
      local_if_not_shadowed_(nullptr),
      index_(-1),
      initializer_position_(kNoSourcePosition),
      bit_field_(MaybeAssignedFlagField::encode(maybe_assigned_flag) |
                 InitializationFlagField::encode(initialization_flag) |
                 VariableModeField::encode(mode) | IsUsedField::encode(false) |
                 ForceContextAllocationField::encode(false) |
                 LocationField::encode(VariableLocation::UNALLOCATED) |
                 VariableKindField::encode(kind)) {
  // Var declared variables never need initialization.
  DCHECK(!(mode == VAR && initialization_flag == kNeedsInitialization));
}


bool Variable::IsGlobalObjectProperty() const {
  // Temporaries are never global, they must always be allocated in the
  // activation frame.
  return (IsDynamicVariableMode(mode()) ||
          (IsDeclaredVariableMode(mode()) && !IsLexicalVariableMode(mode()))) &&
         scope_ != NULL && scope_->is_script_scope();
}


bool Variable::IsStaticGlobalObjectProperty() const {
  // Temporaries are never global, they must always be allocated in the
  // activation frame.
  return (IsDeclaredVariableMode(mode()) && !IsLexicalVariableMode(mode())) &&
         scope_ != NULL && scope_->is_script_scope();
}


}  // namespace internal
}  // namespace v8