rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 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, |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 41 | |
| 42 | SEALED = DONT_ENUM | DONT_DELETE, |
| 43 | FROZEN = SEALED | READ_ONLY, |
| 44 | |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 45 | ABSENT = 16 // Used in runtime to indicate a property is absent. |
| 46 | // ABSENT can never be stored in or returned from a descriptor's attributes |
| 47 | // bitfield. It is only used as a return value meaning the attributes of |
| 48 | // a non-existent property. |
| 49 | }; |
| 50 | |
| 51 | |
| 52 | namespace v8 { |
| 53 | namespace internal { |
| 54 | |
| 55 | class Smi; |
| 56 | |
| 57 | // Type of properties. |
| 58 | // Order of properties is significant. |
| 59 | // Must fit in the BitField PropertyDetails::TypeField. |
| 60 | // A copy of this is in mirror-debugger.js. |
| 61 | enum PropertyType { |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 62 | // Only in slow mode. |
| 63 | NORMAL = 0, |
| 64 | // Only in fast mode. |
| 65 | FIELD = 1, |
| 66 | CONSTANT_FUNCTION = 2, |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 67 | CALLBACKS = 3, |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 68 | // Only in lookup results, not in descriptors. |
| 69 | HANDLER = 4, |
| 70 | INTERCEPTOR = 5, |
| 71 | TRANSITION = 6, |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 72 | // Only used as a marker in LookupResult. |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 73 | NONEXISTENT = 7 |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 77 | // PropertyDetails captures type and attributes for a property. |
| 78 | // They are used both in property dictionaries and instance descriptors. |
| 79 | class PropertyDetails BASE_EMBEDDED { |
| 80 | public: |
| 81 | PropertyDetails(PropertyAttributes attributes, |
| 82 | PropertyType type, |
| 83 | int index = 0) { |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 84 | value_ = TypeField::encode(type) |
| 85 | | AttributesField::encode(attributes) |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 86 | | DictionaryStorageField::encode(index); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 87 | |
| 88 | ASSERT(type == this->type()); |
| 89 | ASSERT(attributes == this->attributes()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 90 | ASSERT(index == this->dictionary_index()); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 91 | } |
| 92 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 93 | int pointer() { return DescriptorPointer::decode(value_); } |
| 94 | |
| 95 | PropertyDetails set_pointer(int i) { return PropertyDetails(value_, i); } |
| 96 | |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 97 | // Conversion for storing details as Object*. |
| 98 | explicit inline PropertyDetails(Smi* smi); |
| 99 | inline Smi* AsSmi(); |
| 100 | |
| 101 | PropertyType type() { return TypeField::decode(value_); } |
| 102 | |
jkummerow@chromium.org | c195667 | 2012-10-11 15:57:38 +0000 | [diff] [blame] | 103 | PropertyAttributes attributes() const { |
| 104 | return AttributesField::decode(value_); |
| 105 | } |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 106 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 107 | int dictionary_index() { |
| 108 | return DictionaryStorageField::decode(value_); |
| 109 | } |
| 110 | |
| 111 | int descriptor_index() { |
| 112 | return DescriptorStorageField::decode(value_); |
| 113 | } |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 114 | |
| 115 | inline PropertyDetails AsDeleted(); |
| 116 | |
| 117 | static bool IsValidIndex(int index) { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 118 | return DictionaryStorageField::is_valid(index); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 119 | } |
| 120 | |
jkummerow@chromium.org | c195667 | 2012-10-11 15:57:38 +0000 | [diff] [blame] | 121 | bool IsReadOnly() const { return (attributes() & READ_ONLY) != 0; } |
| 122 | bool IsDontDelete() const { return (attributes() & DONT_DELETE) != 0; } |
| 123 | bool IsDontEnum() const { return (attributes() & DONT_ENUM) != 0; } |
| 124 | bool IsDeleted() const { return DeletedField::decode(value_) != 0;} |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 125 | |
| 126 | // Bit fields in value_ (type, shift, size). Must be public so the |
| 127 | // constants can be embedded in generated code. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 128 | class TypeField: public BitField<PropertyType, 0, 3> {}; |
| 129 | class AttributesField: public BitField<PropertyAttributes, 3, 3> {}; |
| 130 | class DeletedField: public BitField<uint32_t, 6, 1> {}; |
| 131 | class DictionaryStorageField: public BitField<uint32_t, 7, 24> {}; |
| 132 | class DescriptorStorageField: public BitField<uint32_t, 7, 11> {}; |
| 133 | class DescriptorPointer: public BitField<uint32_t, 18, 11> {}; |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 134 | |
| 135 | static const int kInitialIndex = 1; |
| 136 | |
| 137 | private: |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 138 | PropertyDetails(int value, int pointer) { |
| 139 | value_ = DescriptorPointer::update(value, pointer); |
| 140 | } |
| 141 | |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 142 | uint32_t value_; |
| 143 | }; |
| 144 | |
| 145 | } } // namespace v8::internal |
| 146 | |
| 147 | #endif // V8_PROPERTY_DETAILS_H_ |