OLD | NEW |
(Empty) | |
| 1 // Copyright 2011 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 |
| 36 enum PropertyAttributes { |
| 37 NONE = v8::None, |
| 38 READ_ONLY = v8::ReadOnly, |
| 39 DONT_ENUM = v8::DontEnum, |
| 40 DONT_DELETE = v8::DontDelete, |
| 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. |
| 57 enum PropertyType { |
| 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 MAP_TRANSITION = 6, // only in fast mode |
| 65 ELEMENTS_TRANSITION = 7, |
| 66 CONSTANT_TRANSITION = 8, // only in fast mode |
| 67 NULL_DESCRIPTOR = 9, // only in fast mode |
| 68 // All properties before MAP_TRANSITION are real. |
| 69 FIRST_PHANTOM_PROPERTY_TYPE = MAP_TRANSITION, |
| 70 // There are no IC stubs for NULL_DESCRIPTORS. Therefore, |
| 71 // NULL_DESCRIPTOR can be used as the type flag for IC stubs for |
| 72 // nonexistent properties. |
| 73 NONEXISTENT = NULL_DESCRIPTOR |
| 74 }; |
| 75 |
| 76 |
| 77 inline bool IsTransitionType(PropertyType type) { |
| 78 switch (type) { |
| 79 case MAP_TRANSITION: |
| 80 case CONSTANT_TRANSITION: |
| 81 case ELEMENTS_TRANSITION: |
| 82 return true; |
| 83 case NORMAL: |
| 84 case FIELD: |
| 85 case CONSTANT_FUNCTION: |
| 86 case CALLBACKS: |
| 87 case HANDLER: |
| 88 case INTERCEPTOR: |
| 89 case NULL_DESCRIPTOR: |
| 90 return false; |
| 91 } |
| 92 UNREACHABLE(); // keep the compiler happy |
| 93 return false; |
| 94 } |
| 95 |
| 96 |
| 97 // PropertyDetails captures type and attributes for a property. |
| 98 // They are used both in property dictionaries and instance descriptors. |
| 99 class PropertyDetails BASE_EMBEDDED { |
| 100 public: |
| 101 PropertyDetails(PropertyAttributes attributes, |
| 102 PropertyType type, |
| 103 int index = 0) { |
| 104 ASSERT(TypeField::is_valid(type)); |
| 105 ASSERT(AttributesField::is_valid(attributes)); |
| 106 ASSERT(StorageField::is_valid(index)); |
| 107 |
| 108 value_ = TypeField::encode(type) |
| 109 | AttributesField::encode(attributes) |
| 110 | StorageField::encode(index); |
| 111 |
| 112 ASSERT(type == this->type()); |
| 113 ASSERT(attributes == this->attributes()); |
| 114 ASSERT(index == this->index()); |
| 115 } |
| 116 |
| 117 // Conversion for storing details as Object*. |
| 118 explicit inline PropertyDetails(Smi* smi); |
| 119 inline Smi* AsSmi(); |
| 120 |
| 121 PropertyType type() { return TypeField::decode(value_); } |
| 122 |
| 123 bool IsTransition() { |
| 124 PropertyType t = type(); |
| 125 ASSERT(t != INTERCEPTOR); |
| 126 return IsTransitionType(t); |
| 127 } |
| 128 |
| 129 bool IsProperty() { |
| 130 return type() < FIRST_PHANTOM_PROPERTY_TYPE; |
| 131 } |
| 132 |
| 133 PropertyAttributes attributes() { return AttributesField::decode(value_); } |
| 134 |
| 135 int index() { return StorageField::decode(value_); } |
| 136 |
| 137 inline PropertyDetails AsDeleted(); |
| 138 |
| 139 static bool IsValidIndex(int index) { |
| 140 return StorageField::is_valid(index); |
| 141 } |
| 142 |
| 143 bool IsReadOnly() { return (attributes() & READ_ONLY) != 0; } |
| 144 bool IsDontDelete() { return (attributes() & DONT_DELETE) != 0; } |
| 145 bool IsDontEnum() { return (attributes() & DONT_ENUM) != 0; } |
| 146 bool IsDeleted() { return DeletedField::decode(value_) != 0;} |
| 147 |
| 148 // Bit fields in value_ (type, shift, size). Must be public so the |
| 149 // constants can be embedded in generated code. |
| 150 class TypeField: public BitField<PropertyType, 0, 4> {}; |
| 151 class AttributesField: public BitField<PropertyAttributes, 4, 3> {}; |
| 152 class DeletedField: public BitField<uint32_t, 7, 1> {}; |
| 153 class StorageField: public BitField<uint32_t, 8, 32-8> {}; |
| 154 |
| 155 static const int kInitialIndex = 1; |
| 156 |
| 157 private: |
| 158 uint32_t value_; |
| 159 }; |
| 160 |
| 161 } } // namespace v8::internal |
| 162 |
| 163 #endif // V8_PROPERTY_DETAILS_H_ |
OLD | NEW |