OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/ast/variables.h" | 5 #include "src/ast/variables.h" |
6 | 6 |
7 #include "src/ast/scopes.h" | 7 #include "src/ast/scopes.h" |
8 #include "src/globals.h" | 8 #include "src/globals.h" |
9 #include "src/objects-inl.h" | 9 #include "src/objects-inl.h" |
10 | 10 |
11 namespace v8 { | 11 namespace v8 { |
12 namespace internal { | 12 namespace internal { |
13 | 13 |
14 // ---------------------------------------------------------------------------- | 14 // ---------------------------------------------------------------------------- |
15 // Implementation Variable. | 15 // Implementation Variable. |
16 | 16 |
17 Variable::Variable(Scope* scope, const AstRawString* name, VariableMode mode, | |
18 VariableKind kind, InitializationFlag initialization_flag, | |
19 MaybeAssignedFlag maybe_assigned_flag) | |
20 : scope_(scope), | |
21 name_(name), | |
22 local_if_not_shadowed_(nullptr), | |
23 next_(nullptr), | |
24 index_(-1), | |
25 initializer_position_(kNoSourcePosition), | |
26 bit_field_(MaybeAssignedFlagField::encode(maybe_assigned_flag) | | |
27 InitializationFlagField::encode(initialization_flag) | | |
28 VariableModeField::encode(mode) | IsUsedField::encode(false) | | |
29 ForceContextAllocationField::encode(false) | | |
30 ForceHoleInitializationField::encode(false) | | |
31 LocationField::encode(VariableLocation::UNALLOCATED) | | |
32 VariableKindField::encode(kind)) { | |
33 // Var declared variables never need initialization. | |
34 DCHECK(!(mode == VAR && initialization_flag == kNeedsInitialization)); | |
35 } | |
36 | |
37 Variable::Variable(Variable* other) | 17 Variable::Variable(Variable* other) |
38 : scope_(other->scope_), | 18 : scope_(other->scope_), |
39 name_(other->name_), | 19 name_(other->name_), |
40 local_if_not_shadowed_(nullptr), | 20 local_if_not_shadowed_(nullptr), |
41 next_(nullptr), | 21 next_(nullptr), |
42 index_(other->index_), | 22 index_(other->index_), |
43 initializer_position_(other->initializer_position_), | 23 initializer_position_(other->initializer_position_), |
44 bit_field_(other->bit_field_) {} | 24 bit_field_(other->bit_field_) {} |
45 | 25 |
46 bool Variable::IsGlobalObjectProperty() const { | 26 bool Variable::IsGlobalObjectProperty() const { |
47 // Temporaries are never global, they must always be allocated in the | 27 // Temporaries are never global, they must always be allocated in the |
48 // activation frame. | 28 // activation frame. |
49 return (IsDynamicVariableMode(mode()) || mode() == VAR) && | 29 return (IsDynamicVariableMode(mode()) || mode() == VAR) && |
50 scope_ != nullptr && scope_->is_script_scope(); | 30 scope_ != nullptr && scope_->is_script_scope(); |
51 } | 31 } |
52 | 32 |
53 } // namespace internal | 33 } // namespace internal |
54 } // namespace v8 | 34 } // namespace v8 |
OLD | NEW |