v8  3.11.10(node0.8.26)
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  NORMAL = 0, // only in slow mode
59  FIELD = 1, // only in fast mode
60  CONSTANT_FUNCTION = 2, // only in fast mode
61  CALLBACKS = 3,
62  HANDLER = 4, // only in lookup results, not in descriptors
63  INTERCEPTOR = 5, // only in lookup results, not in descriptors
64  // All properties before MAP_TRANSITION are real.
65  MAP_TRANSITION = 6, // only in fast mode
66  CONSTANT_TRANSITION = 7, // only in fast mode
67  NULL_DESCRIPTOR = 8, // only in fast mode
68  // There are no IC stubs for NULL_DESCRIPTORS. Therefore,
69  // NULL_DESCRIPTOR can be used as the type flag for IC stubs for
70  // nonexistent properties.
72 };
73 
74 
75 // PropertyDetails captures type and attributes for a property.
76 // They are used both in property dictionaries and instance descriptors.
77 class PropertyDetails BASE_EMBEDDED {
78  public:
81  int index = 0) {
82  ASSERT(TypeField::is_valid(type));
83  ASSERT(AttributesField::is_valid(attributes));
84  ASSERT(StorageField::is_valid(index));
85 
86  value_ = TypeField::encode(type)
87  | AttributesField::encode(attributes)
88  | StorageField::encode(index);
89 
90  ASSERT(type == this->type());
91  ASSERT(attributes == this->attributes());
92  ASSERT(index == this->index());
93  }
94 
95  // Conversion for storing details as Object*.
96  explicit inline PropertyDetails(Smi* smi);
97  inline Smi* AsSmi();
98 
99  PropertyType type() { return TypeField::decode(value_); }
100 
101  PropertyAttributes attributes() { return AttributesField::decode(value_); }
102 
103  int index() { return StorageField::decode(value_); }
104 
105  inline PropertyDetails AsDeleted();
106 
107  static bool IsValidIndex(int index) {
108  return StorageField::is_valid(index);
109  }
110 
111  bool IsReadOnly() { return (attributes() & READ_ONLY) != 0; }
112  bool IsDontDelete() { return (attributes() & DONT_DELETE) != 0; }
113  bool IsDontEnum() { return (attributes() & DONT_ENUM) != 0; }
114  bool IsDeleted() { return DeletedField::decode(value_) != 0;}
115 
116  // Bit fields in value_ (type, shift, size). Must be public so the
117  // constants can be embedded in generated code.
118  class TypeField: public BitField<PropertyType, 0, 4> {};
119  class AttributesField: public BitField<PropertyAttributes, 4, 3> {};
120  class DeletedField: public BitField<uint32_t, 7, 1> {};
121  class StorageField: public BitField<uint32_t, 8, 32-8> {};
122 
123  static const int kInitialIndex = 1;
124 
125  private:
126  uint32_t value_;
127 };
128 
129 } } // namespace v8::internal
130 
131 #endif // V8_PROPERTY_DETAILS_H_
PropertyDetails(PropertyAttributes attributes, PropertyType type, int index=0)
#define ASSERT(condition)
Definition: checks.h:270
PropertyAttributes
static bool IsValidIndex(int index)
#define BASE_EMBEDDED
Definition: allocation.h:68
Definition: v8.h:1401
PropertyAttributes attributes()
FlagType type() const
Definition: flags.cc:1358