darin | c758b28 | 2002-11-20 21:12:14 +0000 | [diff] [blame] | 1 | /* |
darin | c758b28 | 2002-11-20 21:12:14 +0000 | [diff] [blame] | 2 | * Copyright (C) 1999-2000 Harri Porten (porten@kde.org) |
oliver@apple.com | 5fca29f | 2009-08-11 04:35:02 +0000 | [diff] [blame] | 3 | * Copyright (C) 2003, 2007, 2008, 2009 Apple Inc. All rights reserved. |
darin | c758b28 | 2002-11-20 21:12:14 +0000 | [diff] [blame] | 4 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Lesser General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Lesser General Public |
| 16 | * License along with this library; if not, write to the Free Software |
mjs | cdff33b | 2006-01-23 21:41:36 +0000 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
darin | c758b28 | 2002-11-20 21:12:14 +0000 | [diff] [blame] | 18 | * |
| 19 | */ |
| 20 | |
darin@apple.com | 5c0863d | 2008-06-16 04:17:44 +0000 | [diff] [blame] | 21 | #ifndef JSArray_h |
| 22 | #define JSArray_h |
darin | c758b28 | 2002-11-20 21:12:14 +0000 | [diff] [blame] | 23 | |
darin@apple.com | 3dcb636 | 2008-06-16 04:00:19 +0000 | [diff] [blame] | 24 | #include "JSObject.h" |
darin | c758b28 | 2002-11-20 21:12:14 +0000 | [diff] [blame] | 25 | |
andreas.kling@nokia.com | d9acc42 | 2010-07-14 00:29:32 +0000 | [diff] [blame] | 26 | #define CHECK_ARRAY_CONSISTENCY 0 |
| 27 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 28 | namespace JSC { |
darin | c758b28 | 2002-11-20 21:12:14 +0000 | [diff] [blame] | 29 | |
oliver@apple.com | 168e506 | 2011-01-31 20:07:21 +0000 | [diff] [blame] | 30 | typedef HashMap<unsigned, WriteBarrier<Unknown> > SparseArrayValueMap; |
ggaren@apple.com | 1d72f77 | 2008-07-03 00:47:00 +0000 | [diff] [blame] | 31 | |
barraclough@apple.com | a381210 | 2010-07-29 23:29:17 +0000 | [diff] [blame] | 32 | // This struct holds the actual data values of an array. A JSArray object points to it's contained ArrayStorage |
| 33 | // struct by pointing to m_vector. To access the contained ArrayStorage struct, use the getStorage() and |
| 34 | // setStorage() methods. It is important to note that there may be space before the ArrayStorage that |
| 35 | // is used to quick unshift / shift operation. The actual allocated pointer is available by using: |
| 36 | // getStorage() - m_indexBias * sizeof(JSValue) |
weinig@apple.com | 0e2d66e | 2008-07-06 05:26:58 +0000 | [diff] [blame] | 37 | struct ArrayStorage { |
barraclough@apple.com | a381210 | 2010-07-29 23:29:17 +0000 | [diff] [blame] | 38 | unsigned m_length; // The "length" property on the array |
weinig@apple.com | 0e2d66e | 2008-07-06 05:26:58 +0000 | [diff] [blame] | 39 | unsigned m_numValuesInVector; |
| 40 | SparseArrayValueMap* m_sparseValueMap; |
ap@apple.com | 8c4e21b | 2010-02-26 00:22:34 +0000 | [diff] [blame] | 41 | void* subclassData; // A JSArray subclass can use this to fill the vector lazily. |
barraclough@apple.com | 3549012 | 2010-08-03 21:29:32 +0000 | [diff] [blame] | 42 | void* m_allocBase; // Pointer to base address returned by malloc(). Keeping this pointer does eliminate false positives from the leak detector. |
ggaren@apple.com | c1fb8e4 | 2010-01-09 01:02:38 +0000 | [diff] [blame] | 43 | size_t reportedMapCapacity; |
andreas.kling@nokia.com | d9acc42 | 2010-07-14 00:29:32 +0000 | [diff] [blame] | 44 | #if CHECK_ARRAY_CONSISTENCY |
| 45 | bool m_inCompactInitialization; |
| 46 | #endif |
oliver@apple.com | 168e506 | 2011-01-31 20:07:21 +0000 | [diff] [blame] | 47 | WriteBarrier<Unknown> m_vector[1]; |
weinig@apple.com | 0e2d66e | 2008-07-06 05:26:58 +0000 | [diff] [blame] | 48 | }; |
darin | f860d02 | 2007-10-22 13:35:17 +0000 | [diff] [blame] | 49 | |
andreas.kling@nokia.com | d9acc42 | 2010-07-14 00:29:32 +0000 | [diff] [blame] | 50 | // The CreateCompact creation mode is used for fast construction of arrays |
| 51 | // whose size and contents are known at time of creation. |
| 52 | // |
| 53 | // There are two obligations when using this mode: |
| 54 | // |
| 55 | // - uncheckedSetIndex() must be used when initializing the array. |
| 56 | // - setLength() must be called after initialization. |
| 57 | |
| 58 | enum ArrayCreationMode { CreateCompact, CreateInitialized }; |
| 59 | |
barraclough@apple.com | 77da108 | 2011-02-16 21:35:19 +0000 | [diff] [blame] | 60 | class JSArray : public JSNonFinalObject { |
oliver@apple.com | 29443c4 | 2009-08-27 08:39:38 +0000 | [diff] [blame] | 61 | friend class Walker; |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 62 | |
oliver@apple.com | fcacd3c | 2011-07-18 17:47:13 +0000 | [diff] [blame] | 63 | protected: |
oliver@apple.com | b2fa0dc | 2011-04-15 23:55:42 +0000 | [diff] [blame] | 64 | explicit JSArray(JSGlobalData&, Structure*); |
| 65 | JSArray(JSGlobalData&, Structure*, unsigned initialLength, ArrayCreationMode); |
| 66 | JSArray(JSGlobalData&, Structure*, const ArgList& initialValues); |
oliver@apple.com | fcacd3c | 2011-07-18 17:47:13 +0000 | [diff] [blame] | 67 | |
| 68 | public: |
commit-queue@webkit.org | 6c25c52 | 2011-08-09 20:46:17 +0000 | [diff] [blame^] | 69 | typedef JSNonFinalObject Base; |
| 70 | |
oliver@apple.com | fcacd3c | 2011-07-18 17:47:13 +0000 | [diff] [blame] | 71 | JSArray(VPtrStealingHackType); |
weinig@apple.com | 0e2d66e | 2008-07-06 05:26:58 +0000 | [diff] [blame] | 72 | virtual ~JSArray(); |
darin | c758b28 | 2002-11-20 21:12:14 +0000 | [diff] [blame] | 73 | |
oliver@apple.com | fcacd3c | 2011-07-18 17:47:13 +0000 | [diff] [blame] | 74 | static JSArray* create(JSGlobalData& globalData, Structure* structure) |
| 75 | { |
| 76 | return new (allocateCell<JSArray>(globalData.heap)) JSArray(globalData, structure); |
| 77 | } |
| 78 | |
| 79 | static JSArray* create(JSGlobalData& globalData, Structure* structure, unsigned initialLength, ArrayCreationMode createMode) |
| 80 | { |
| 81 | return new (allocateCell<JSArray>(globalData.heap)) JSArray(globalData, structure, initialLength, createMode); |
| 82 | } |
| 83 | |
| 84 | static JSArray* create(JSGlobalData& globalData, Structure* structure, const ArgList& initialValues) |
| 85 | { |
| 86 | return new (allocateCell<JSArray>(globalData.heap)) JSArray(globalData, structure, initialValues); |
| 87 | } |
| 88 | |
weinig@apple.com | 0e2d66e | 2008-07-06 05:26:58 +0000 | [diff] [blame] | 89 | virtual bool getOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&); |
| 90 | virtual bool getOwnPropertySlot(ExecState*, unsigned propertyName, PropertySlot&); |
oliver@apple.com | 4b4f785 | 2009-08-26 16:52:15 +0000 | [diff] [blame] | 91 | virtual bool getOwnPropertyDescriptor(ExecState*, const Identifier&, PropertyDescriptor&); |
ggaren@apple.com | dc067b6 | 2009-05-01 22:43:39 +0000 | [diff] [blame] | 92 | virtual void put(ExecState*, unsigned propertyName, JSValue); // FIXME: Make protected and add setItem. |
darin | c758b28 | 2002-11-20 21:12:14 +0000 | [diff] [blame] | 93 | |
barraclough@apple.com | a5540da | 2011-02-19 21:55:44 +0000 | [diff] [blame] | 94 | static JS_EXPORTDATA const ClassInfo s_info; |
barraclough@apple.com | a381210 | 2010-07-29 23:29:17 +0000 | [diff] [blame] | 95 | |
eric@webkit.org | 29a10d7 | 2010-08-08 05:29:38 +0000 | [diff] [blame] | 96 | unsigned length() const { return m_storage->m_length; } |
weinig@apple.com | 0e2d66e | 2008-07-06 05:26:58 +0000 | [diff] [blame] | 97 | void setLength(unsigned); // OK to use on new arrays, but not if it might be a RegExpMatchArray. |
darin | f860d02 | 2007-10-22 13:35:17 +0000 | [diff] [blame] | 98 | |
weinig@apple.com | 0e2d66e | 2008-07-06 05:26:58 +0000 | [diff] [blame] | 99 | void sort(ExecState*); |
ggaren@apple.com | dc067b6 | 2009-05-01 22:43:39 +0000 | [diff] [blame] | 100 | void sort(ExecState*, JSValue compareFunction, CallType, const CallData&); |
| 101 | void sortNumeric(ExecState*, JSValue compareFunction, CallType, const CallData&); |
darin | f860d02 | 2007-10-22 13:35:17 +0000 | [diff] [blame] | 102 | |
ggaren@apple.com | dc067b6 | 2009-05-01 22:43:39 +0000 | [diff] [blame] | 103 | void push(ExecState*, JSValue); |
| 104 | JSValue pop(); |
darin@apple.com | ef5124b | 2008-09-22 21:04:45 +0000 | [diff] [blame] | 105 | |
barraclough@apple.com | a381210 | 2010-07-29 23:29:17 +0000 | [diff] [blame] | 106 | void shiftCount(ExecState*, int count); |
| 107 | void unshiftCount(ExecState*, int count); |
| 108 | |
eric@webkit.org | 29a10d7 | 2010-08-08 05:29:38 +0000 | [diff] [blame] | 109 | bool canGetIndex(unsigned i) { return i < m_vectorLength && m_storage->m_vector[i]; } |
ggaren@apple.com | dc067b6 | 2009-05-01 22:43:39 +0000 | [diff] [blame] | 110 | JSValue getIndex(unsigned i) |
weinig@apple.com | 0e2d66e | 2008-07-06 05:26:58 +0000 | [diff] [blame] | 111 | { |
| 112 | ASSERT(canGetIndex(i)); |
oliver@apple.com | 168e506 | 2011-01-31 20:07:21 +0000 | [diff] [blame] | 113 | return m_storage->m_vector[i].get(); |
weinig@apple.com | 0e2d66e | 2008-07-06 05:26:58 +0000 | [diff] [blame] | 114 | } |
ggaren@apple.com | 1d72f77 | 2008-07-03 00:47:00 +0000 | [diff] [blame] | 115 | |
ggaren@apple.com | 570483e | 2009-10-03 17:01:14 +0000 | [diff] [blame] | 116 | bool canSetIndex(unsigned i) { return i < m_vectorLength; } |
oliver@apple.com | 168e506 | 2011-01-31 20:07:21 +0000 | [diff] [blame] | 117 | void setIndex(JSGlobalData& globalData, unsigned i, JSValue v) |
weinig@apple.com | 0e2d66e | 2008-07-06 05:26:58 +0000 | [diff] [blame] | 118 | { |
| 119 | ASSERT(canSetIndex(i)); |
barraclough@apple.com | a381210 | 2010-07-29 23:29:17 +0000 | [diff] [blame] | 120 | |
oliver@apple.com | 168e506 | 2011-01-31 20:07:21 +0000 | [diff] [blame] | 121 | WriteBarrier<Unknown>& x = m_storage->m_vector[i]; |
ggaren@apple.com | 570483e | 2009-10-03 17:01:14 +0000 | [diff] [blame] | 122 | if (!x) { |
eric@webkit.org | 29a10d7 | 2010-08-08 05:29:38 +0000 | [diff] [blame] | 123 | ArrayStorage *storage = m_storage; |
barraclough@apple.com | a381210 | 2010-07-29 23:29:17 +0000 | [diff] [blame] | 124 | ++storage->m_numValuesInVector; |
| 125 | if (i >= storage->m_length) |
| 126 | storage->m_length = i + 1; |
ggaren@apple.com | 570483e | 2009-10-03 17:01:14 +0000 | [diff] [blame] | 127 | } |
oliver@apple.com | 168e506 | 2011-01-31 20:07:21 +0000 | [diff] [blame] | 128 | x.set(globalData, this, v); |
weinig@apple.com | 0e2d66e | 2008-07-06 05:26:58 +0000 | [diff] [blame] | 129 | } |
barraclough@apple.com | a381210 | 2010-07-29 23:29:17 +0000 | [diff] [blame] | 130 | |
oliver@apple.com | 168e506 | 2011-01-31 20:07:21 +0000 | [diff] [blame] | 131 | void uncheckedSetIndex(JSGlobalData& globalData, unsigned i, JSValue v) |
andreas.kling@nokia.com | d9acc42 | 2010-07-14 00:29:32 +0000 | [diff] [blame] | 132 | { |
| 133 | ASSERT(canSetIndex(i)); |
eric@webkit.org | 29a10d7 | 2010-08-08 05:29:38 +0000 | [diff] [blame] | 134 | ArrayStorage *storage = m_storage; |
andreas.kling@nokia.com | d9acc42 | 2010-07-14 00:29:32 +0000 | [diff] [blame] | 135 | #if CHECK_ARRAY_CONSISTENCY |
barraclough@apple.com | a381210 | 2010-07-29 23:29:17 +0000 | [diff] [blame] | 136 | ASSERT(storage->m_inCompactInitialization); |
andreas.kling@nokia.com | d9acc42 | 2010-07-14 00:29:32 +0000 | [diff] [blame] | 137 | #endif |
oliver@apple.com | 168e506 | 2011-01-31 20:07:21 +0000 | [diff] [blame] | 138 | storage->m_vector[i].set(globalData, this, v); |
andreas.kling@nokia.com | d9acc42 | 2010-07-14 00:29:32 +0000 | [diff] [blame] | 139 | } |
| 140 | |
oliver@apple.com | f32186e | 2009-04-30 01:21:52 +0000 | [diff] [blame] | 141 | void fillArgList(ExecState*, MarkedArgumentBuffer&); |
oliver@apple.com | 65e286e | 2009-04-08 23:08:28 +0000 | [diff] [blame] | 142 | void copyToRegisters(ExecState*, Register*, uint32_t); |
weinig@apple.com | cbf3ca9 | 2008-09-22 21:20:52 +0000 | [diff] [blame] | 143 | |
oliver@apple.com | b2fa0dc | 2011-04-15 23:55:42 +0000 | [diff] [blame] | 144 | static Structure* createStructure(JSGlobalData& globalData, JSValue prototype) |
darin@apple.com | 74e6ed6 | 2008-10-23 00:11:11 +0000 | [diff] [blame] | 145 | { |
oliver@apple.com | 90cf7d5 | 2011-03-16 20:09:07 +0000 | [diff] [blame] | 146 | return Structure::create(globalData, prototype, TypeInfo(ObjectType, StructureFlags), AnonymousSlotCount, &s_info); |
darin@apple.com | 74e6ed6 | 2008-10-23 00:11:11 +0000 | [diff] [blame] | 147 | } |
oliver@apple.com | 52000e7 | 2009-08-14 05:35:33 +0000 | [diff] [blame] | 148 | |
oliver@apple.com | 433d02f | 2011-04-21 23:08:15 +0000 | [diff] [blame] | 149 | inline void visitChildrenDirect(SlotVisitor&); |
darin@apple.com | 74e6ed6 | 2008-10-23 00:11:11 +0000 | [diff] [blame] | 150 | |
barraclough@apple.com | 66184e2 | 2011-03-13 21:16:29 +0000 | [diff] [blame] | 151 | static ptrdiff_t storageOffset() |
| 152 | { |
| 153 | return OBJECT_OFFSETOF(JSArray, m_storage); |
| 154 | } |
| 155 | |
| 156 | static ptrdiff_t vectorLengthOffset() |
| 157 | { |
| 158 | return OBJECT_OFFSETOF(JSArray, m_vectorLength); |
| 159 | } |
| 160 | |
weinig@apple.com | 0e2d66e | 2008-07-06 05:26:58 +0000 | [diff] [blame] | 161 | protected: |
oliver@apple.com | 433d02f | 2011-04-21 23:08:15 +0000 | [diff] [blame] | 162 | static const unsigned StructureFlags = OverridesGetOwnPropertySlot | OverridesVisitChildren | OverridesGetPropertyNames | JSObject::StructureFlags; |
ggaren@apple.com | dc067b6 | 2009-05-01 22:43:39 +0000 | [diff] [blame] | 163 | virtual void put(ExecState*, const Identifier& propertyName, JSValue, PutPropertySlot&); |
weinig@apple.com | 0e2d66e | 2008-07-06 05:26:58 +0000 | [diff] [blame] | 164 | virtual bool deleteProperty(ExecState*, const Identifier& propertyName); |
| 165 | virtual bool deleteProperty(ExecState*, unsigned propertyName); |
eric@webkit.org | c293f4c | 2010-01-13 00:58:21 +0000 | [diff] [blame] | 166 | virtual void getOwnPropertyNames(ExecState*, PropertyNameArray&, EnumerationMode mode = ExcludeDontEnumProperties); |
oliver@apple.com | 433d02f | 2011-04-21 23:08:15 +0000 | [diff] [blame] | 167 | virtual void visitChildren(SlotVisitor&); |
darin@apple.com | 1edff43 | 2008-06-24 05:23:17 +0000 | [diff] [blame] | 168 | |
ap@apple.com | 8c4e21b | 2010-02-26 00:22:34 +0000 | [diff] [blame] | 169 | void* subclassData() const; |
| 170 | void setSubclassData(void*); |
barraclough@apple.com | 66184e2 | 2011-03-13 21:16:29 +0000 | [diff] [blame] | 171 | |
weinig@apple.com | 0e2d66e | 2008-07-06 05:26:58 +0000 | [diff] [blame] | 172 | private: |
weinig@apple.com | 0e2d66e | 2008-07-06 05:26:58 +0000 | [diff] [blame] | 173 | bool getOwnPropertySlotSlowCase(ExecState*, unsigned propertyName, PropertySlot&); |
ggaren@apple.com | dc067b6 | 2009-05-01 22:43:39 +0000 | [diff] [blame] | 174 | void putSlowCase(ExecState*, unsigned propertyName, JSValue); |
mjs | 70d7421 | 2005-08-07 06:17:49 +0000 | [diff] [blame] | 175 | |
barraclough@apple.com | a381210 | 2010-07-29 23:29:17 +0000 | [diff] [blame] | 176 | unsigned getNewVectorLength(unsigned desiredLength); |
weinig@apple.com | 0e2d66e | 2008-07-06 05:26:58 +0000 | [diff] [blame] | 177 | bool increaseVectorLength(unsigned newLength); |
barraclough@apple.com | a381210 | 2010-07-29 23:29:17 +0000 | [diff] [blame] | 178 | bool increaseVectorPrefixLength(unsigned newLength); |
weinig@apple.com | 0e2d66e | 2008-07-06 05:26:58 +0000 | [diff] [blame] | 179 | |
| 180 | unsigned compactForSorting(); |
darin@apple.com | 772b773 | 2008-06-11 19:37:44 +0000 | [diff] [blame] | 181 | |
weinig@apple.com | 0e2d66e | 2008-07-06 05:26:58 +0000 | [diff] [blame] | 182 | enum ConsistencyCheckType { NormalConsistencyCheck, DestructorConsistencyCheck, SortConsistencyCheck }; |
| 183 | void checkConsistency(ConsistencyCheckType = NormalConsistencyCheck); |
mjs | 1a9f113 | 2002-11-24 07:49:26 +0000 | [diff] [blame] | 184 | |
barraclough@apple.com | a381210 | 2010-07-29 23:29:17 +0000 | [diff] [blame] | 185 | unsigned m_vectorLength; // The valid length of m_vector |
| 186 | int m_indexBias; // The number of JSValue sized blocks before ArrayStorage. |
eric@webkit.org | 29a10d7 | 2010-08-08 05:29:38 +0000 | [diff] [blame] | 187 | ArrayStorage *m_storage; |
weinig@apple.com | 0e2d66e | 2008-07-06 05:26:58 +0000 | [diff] [blame] | 188 | }; |
darin | c758b28 | 2002-11-20 21:12:14 +0000 | [diff] [blame] | 189 | |
ggaren@apple.com | dc067b6 | 2009-05-01 22:43:39 +0000 | [diff] [blame] | 190 | JSArray* asArray(JSValue); |
darin@apple.com | 5a49442 | 2008-10-18 23:08:12 +0000 | [diff] [blame] | 191 | |
darin@apple.com | 8a1a5b5 | 2009-09-04 19:03:33 +0000 | [diff] [blame] | 192 | inline JSArray* asArray(JSCell* cell) |
darin@apple.com | 5a49442 | 2008-10-18 23:08:12 +0000 | [diff] [blame] | 193 | { |
barraclough@apple.com | a5540da | 2011-02-19 21:55:44 +0000 | [diff] [blame] | 194 | ASSERT(cell->inherits(&JSArray::s_info)); |
darin@apple.com | 8a1a5b5 | 2009-09-04 19:03:33 +0000 | [diff] [blame] | 195 | return static_cast<JSArray*>(cell); |
darin@apple.com | 5a49442 | 2008-10-18 23:08:12 +0000 | [diff] [blame] | 196 | } |
| 197 | |
darin@apple.com | 8a1a5b5 | 2009-09-04 19:03:33 +0000 | [diff] [blame] | 198 | inline JSArray* asArray(JSValue value) |
| 199 | { |
| 200 | return asArray(value.asCell()); |
| 201 | } |
| 202 | |
oliver@apple.com | 29443c4 | 2009-08-27 08:39:38 +0000 | [diff] [blame] | 203 | inline bool isJSArray(JSGlobalData* globalData, JSCell* cell) { return cell->vptr() == globalData->jsArrayVPtr; } |
barraclough@apple.com | 66184e2 | 2011-03-13 21:16:29 +0000 | [diff] [blame] | 204 | inline bool isJSArray(JSGlobalData* globalData, JSValue v) { return v.isCell() && isJSArray(globalData, v.asCell()); } |
ggaren@apple.com | c3343bd | 2009-02-24 03:58:09 +0000 | [diff] [blame] | 205 | |
oliver@apple.com | 433d02f | 2011-04-21 23:08:15 +0000 | [diff] [blame] | 206 | inline void JSArray::visitChildrenDirect(SlotVisitor& visitor) |
darin@apple.com | 8a1a5b5 | 2009-09-04 19:03:33 +0000 | [diff] [blame] | 207 | { |
oliver@apple.com | 433d02f | 2011-04-21 23:08:15 +0000 | [diff] [blame] | 208 | JSObject::visitChildrenDirect(visitor); |
oliver@apple.com | 52000e7 | 2009-08-14 05:35:33 +0000 | [diff] [blame] | 209 | |
eric@webkit.org | 29a10d7 | 2010-08-08 05:29:38 +0000 | [diff] [blame] | 210 | ArrayStorage* storage = m_storage; |
darin@apple.com | 8a1a5b5 | 2009-09-04 19:03:33 +0000 | [diff] [blame] | 211 | |
ggaren@apple.com | 570483e | 2009-10-03 17:01:14 +0000 | [diff] [blame] | 212 | unsigned usedVectorLength = std::min(storage->m_length, m_vectorLength); |
ggaren@apple.com | 053223f | 2011-05-25 19:37:18 +0000 | [diff] [blame] | 213 | visitor.appendValues(storage->m_vector, usedVectorLength); |
darin@apple.com | 8a1a5b5 | 2009-09-04 19:03:33 +0000 | [diff] [blame] | 214 | |
oliver@apple.com | 52000e7 | 2009-08-14 05:35:33 +0000 | [diff] [blame] | 215 | if (SparseArrayValueMap* map = storage->m_sparseValueMap) { |
| 216 | SparseArrayValueMap::iterator end = map->end(); |
| 217 | for (SparseArrayValueMap::iterator it = map->begin(); it != end; ++it) |
oliver@apple.com | 433d02f | 2011-04-21 23:08:15 +0000 | [diff] [blame] | 218 | visitor.append(&it->second); |
oliver@apple.com | 52000e7 | 2009-08-14 05:35:33 +0000 | [diff] [blame] | 219 | } |
| 220 | } |
| 221 | |
barraclough@apple.com | 3158a38 | 2010-08-13 07:35:45 +0000 | [diff] [blame] | 222 | // Rule from ECMA 15.2 about what an array index is. |
| 223 | // Must exactly match string form of an unsigned integer, and be less than 2^32 - 1. |
barraclough@apple.com | 794f461 | 2010-08-18 07:41:22 +0000 | [diff] [blame] | 224 | inline unsigned Identifier::toArrayIndex(bool& ok) const |
barraclough@apple.com | 3158a38 | 2010-08-13 07:35:45 +0000 | [diff] [blame] | 225 | { |
barraclough@apple.com | 794f461 | 2010-08-18 07:41:22 +0000 | [diff] [blame] | 226 | unsigned i = toUInt32(ok); |
barraclough@apple.com | 3158a38 | 2010-08-13 07:35:45 +0000 | [diff] [blame] | 227 | if (ok && i >= 0xFFFFFFFFU) |
barraclough@apple.com | 794f461 | 2010-08-18 07:41:22 +0000 | [diff] [blame] | 228 | ok = false; |
barraclough@apple.com | 3158a38 | 2010-08-13 07:35:45 +0000 | [diff] [blame] | 229 | return i; |
| 230 | } |
| 231 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 232 | } // namespace JSC |
darin | c758b28 | 2002-11-20 21:12:14 +0000 | [diff] [blame] | 233 | |
weinig@apple.com | 0e2d66e | 2008-07-06 05:26:58 +0000 | [diff] [blame] | 234 | #endif // JSArray_h |