| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #ifndef V8_ELEMENTS_H_ | 28 #ifndef V8_ELEMENTS_H_ |
| 29 #define V8_ELEMENTS_H_ | 29 #define V8_ELEMENTS_H_ |
| 30 | 30 |
| 31 #include "objects.h" | 31 #include "objects.h" |
| 32 #include "heap.h" |
| 33 #include "isolate.h" |
| 32 | 34 |
| 33 namespace v8 { | 35 namespace v8 { |
| 34 namespace internal { | 36 namespace internal { |
| 35 | 37 |
| 36 // Abstract base class for handles that can operate on objects with differing | 38 // Abstract base class for handles that can operate on objects with differing |
| 37 // ElementsKinds. | 39 // ElementsKinds. |
| 38 class ElementsAccessor { | 40 class ElementsAccessor { |
| 39 public: | 41 public: |
| 40 explicit ElementsAccessor(const char* name) : name_(name) { } | 42 explicit ElementsAccessor(const char* name) : name_(name) { } |
| 41 virtual ~ElementsAccessor() { } | 43 virtual ~ElementsAccessor() { } |
| 42 | 44 |
| 43 virtual const char* name() const { return name_; } | 45 virtual ElementsKind kind() const = 0; |
| 46 const char* name() const { return name_; } |
| 44 | 47 |
| 45 // Returns true if a holder contains an element with the specified key | 48 // Returns true if a holder contains an element with the specified key |
| 46 // without iterating up the prototype chain. The caller can optionally pass | 49 // without iterating up the prototype chain. The caller can optionally pass |
| 47 // in the backing store to use for the check, which must be compatible with | 50 // in the backing store to use for the check, which must be compatible with |
| 48 // the ElementsKind of the ElementsAccessor. If backing_store is NULL, the | 51 // the ElementsKind of the ElementsAccessor. If backing_store is NULL, the |
| 49 // holder->elements() is used as the backing store. | 52 // holder->elements() is used as the backing store. |
| 50 virtual bool HasElement(Object* receiver, | 53 virtual bool HasElement(Object* receiver, |
| 51 JSObject* holder, | 54 JSObject* holder, |
| 52 uint32_t key, | 55 uint32_t key, |
| 53 FixedArrayBase* backing_store = NULL) = 0; | 56 FixedArrayBase* backing_store = NULL) = 0; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 78 // EcmaScript 5.1 semantics. | 81 // EcmaScript 5.1 semantics. |
| 79 virtual MaybeObject* SetCapacityAndLength(JSArray* array, | 82 virtual MaybeObject* SetCapacityAndLength(JSArray* array, |
| 80 int capacity, | 83 int capacity, |
| 81 int length) = 0; | 84 int length) = 0; |
| 82 | 85 |
| 83 // Deletes an element in an object, returning a new elements backing store. | 86 // Deletes an element in an object, returning a new elements backing store. |
| 84 virtual MaybeObject* Delete(JSObject* holder, | 87 virtual MaybeObject* Delete(JSObject* holder, |
| 85 uint32_t key, | 88 uint32_t key, |
| 86 JSReceiver::DeleteMode mode) = 0; | 89 JSReceiver::DeleteMode mode) = 0; |
| 87 | 90 |
| 91 // Copy elements from one backing store to another. Typically, callers specify |
| 92 // the source JSObject or JSArray in source_holder. If the holder's backing |
| 93 // store is available, it can be passed in source and source_holder is |
| 94 // ignored. |
| 95 virtual MaybeObject* CopyElements(JSObject* source_holder, |
| 96 uint32_t source_start, |
| 97 FixedArrayBase* destination, |
| 98 ElementsKind destination_kind, |
| 99 uint32_t destination_start, |
| 100 int copy_size, |
| 101 FixedArrayBase* source = NULL) = 0; |
| 102 |
| 103 MaybeObject* CopyElements(JSObject* from_holder, |
| 104 FixedArrayBase* to, |
| 105 ElementsKind to_kind, |
| 106 FixedArrayBase* from = NULL) { |
| 107 return CopyElements(from_holder, 0, to, to_kind, 0, -1, from); |
| 108 } |
| 109 |
| 88 virtual MaybeObject* AddElementsToFixedArray(Object* receiver, | 110 virtual MaybeObject* AddElementsToFixedArray(Object* receiver, |
| 89 JSObject* holder, | 111 JSObject* holder, |
| 90 FixedArray* to, | 112 FixedArray* to, |
| 91 FixedArrayBase* from = NULL) = 0; | 113 FixedArrayBase* from = NULL) = 0; |
| 92 | 114 |
| 93 // Returns a shared ElementsAccessor for the specified ElementsKind. | 115 // Returns a shared ElementsAccessor for the specified ElementsKind. |
| 94 static ElementsAccessor* ForKind(ElementsKind elements_kind) { | 116 static ElementsAccessor* ForKind(ElementsKind elements_kind) { |
| 95 ASSERT(elements_kind < kElementsKindCount); | 117 ASSERT(elements_kind < kElementsKindCount); |
| 96 return elements_accessors_[elements_kind]; | 118 return elements_accessors_[elements_kind]; |
| 97 } | 119 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 116 virtual uint32_t GetKeyForIndex(FixedArrayBase* backing_store, | 138 virtual uint32_t GetKeyForIndex(FixedArrayBase* backing_store, |
| 117 uint32_t index) = 0; | 139 uint32_t index) = 0; |
| 118 | 140 |
| 119 private: | 141 private: |
| 120 static ElementsAccessor** elements_accessors_; | 142 static ElementsAccessor** elements_accessors_; |
| 121 const char* name_; | 143 const char* name_; |
| 122 | 144 |
| 123 DISALLOW_COPY_AND_ASSIGN(ElementsAccessor); | 145 DISALLOW_COPY_AND_ASSIGN(ElementsAccessor); |
| 124 }; | 146 }; |
| 125 | 147 |
| 148 |
| 149 void CopyObjectToObjectElements(AssertNoAllocation* no_gc, |
| 150 FixedArray* from_obj, |
| 151 ElementsKind from_kind, |
| 152 uint32_t from_start, |
| 153 FixedArray* to_obj, |
| 154 ElementsKind to_kind, |
| 155 uint32_t to_start, |
| 156 int copy_size); |
| 157 |
| 158 |
| 126 } } // namespace v8::internal | 159 } } // namespace v8::internal |
| 127 | 160 |
| 128 #endif // V8_ELEMENTS_H_ | 161 #endif // V8_ELEMENTS_H_ |
| OLD | NEW |