v8  3.14.5(node0.10.28)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
property-details.h
Go to the documentation of this file.
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 #ifndef V8_PROPERTY_DETAILS_H_
29 #define V8_PROPERTY_DETAILS_H_
30 
31 #include "../include/v8.h"
32 #include "allocation.h"
33 #include "utils.h"
34 
35 // Ecma-262 3rd 8.6.1
41  ABSENT = 16 // Used in runtime to indicate a property is absent.
42  // ABSENT can never be stored in or returned from a descriptor's attributes
43  // bitfield. It is only used as a return value meaning the attributes of
44  // a non-existent property.
45 };
46 
47 
48 namespace v8 {
49 namespace internal {
50 
51 class Smi;
52 
53 // Type of properties.
54 // Order of properties is significant.
55 // Must fit in the BitField PropertyDetails::TypeField.
56 // A copy of this is in mirror-debugger.js.
58  // Only in slow mode.
59  NORMAL = 0,
60  // Only in fast mode.
61  FIELD = 1,
63  CALLBACKS = 3,
64  // Only in lookup results, not in descriptors.
65  HANDLER = 4,
68  // Only used as a marker in LookupResult.
70 };
71 
72 
73 // PropertyDetails captures type and attributes for a property.
74 // They are used both in property dictionaries and instance descriptors.
75 class PropertyDetails BASE_EMBEDDED {
76  public:
78  PropertyType type,
79  int index = 0) {
80  value_ = TypeField::encode(type)
81  | AttributesField::encode(attributes)
82  | DictionaryStorageField::encode(index);
83 
84  ASSERT(type == this->type());
85  ASSERT(attributes == this->attributes());
86  ASSERT(index == this->dictionary_index());
87  }
88 
89  int pointer() { return DescriptorPointer::decode(value_); }
90 
91  PropertyDetails set_pointer(int i) { return PropertyDetails(value_, i); }
92 
93  // Conversion for storing details as Object*.
94  explicit inline PropertyDetails(Smi* smi);
95  inline Smi* AsSmi();
96 
97  PropertyType type() { return TypeField::decode(value_); }
98 
100  return AttributesField::decode(value_);
101  }
102 
104  return DictionaryStorageField::decode(value_);
105  }
106 
108  return DescriptorStorageField::decode(value_);
109  }
110 
111  inline PropertyDetails AsDeleted();
112 
113  static bool IsValidIndex(int index) {
114  return DictionaryStorageField::is_valid(index);
115  }
116 
117  bool IsReadOnly() const { return (attributes() & READ_ONLY) != 0; }
118  bool IsDontDelete() const { return (attributes() & DONT_DELETE) != 0; }
119  bool IsDontEnum() const { return (attributes() & DONT_ENUM) != 0; }
120  bool IsDeleted() const { return DeletedField::decode(value_) != 0;}
121 
122  // Bit fields in value_ (type, shift, size). Must be public so the
123  // constants can be embedded in generated code.
124  class TypeField: public BitField<PropertyType, 0, 3> {};
125  class AttributesField: public BitField<PropertyAttributes, 3, 3> {};
126  class DeletedField: public BitField<uint32_t, 6, 1> {};
127  class DictionaryStorageField: public BitField<uint32_t, 7, 24> {};
128  class DescriptorStorageField: public BitField<uint32_t, 7, 11> {};
129  class DescriptorPointer: public BitField<uint32_t, 18, 11> {};
130 
131  static const int kInitialIndex = 1;
132 
133  private:
134  PropertyDetails(int value, int pointer) {
135  value_ = DescriptorPointer::update(value, pointer);
136  }
137 
138  uint32_t value_;
139 };
140 
141 } } // namespace v8::internal
142 
143 #endif // V8_PROPERTY_DETAILS_H_
PropertyDetails set_pointer(int i)
PropertyDetails(PropertyAttributes attributes, PropertyType type, int index=0)
#define ASSERT(condition)
Definition: checks.h:270
PropertyAttributes
PropertyAttributes attributes() const
static bool IsValidIndex(int index)
#define BASE_EMBEDDED
Definition: allocation.h:68
Definition: v8.h:1425