Changeset 35022 in webkit for trunk/JavaScriptCore/kjs/JSArray.h
- Timestamp:
- Jul 5, 2008, 10:26:58 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/JSArray.h
r34964 r35022 27 27 namespace KJS { 28 28 29 typedef HashMap<unsigned, JSValue*> SparseArrayValueMap;29 typedef HashMap<unsigned, JSValue*> SparseArrayValueMap; 30 30 31 struct ArrayStorage {32 unsigned m_vectorLength;33 unsigned m_numValuesInVector;34 SparseArrayValueMap* m_sparseValueMap;35 void* lazyCreationData; // A JSArray subclass can use this to fill the vector lazily.36 JSValue* m_vector[1];37 };31 struct ArrayStorage { 32 unsigned m_vectorLength; 33 unsigned m_numValuesInVector; 34 SparseArrayValueMap* m_sparseValueMap; 35 void* lazyCreationData; // A JSArray subclass can use this to fill the vector lazily. 36 JSValue* m_vector[1]; 37 }; 38 38 39 class JSArray : public JSObject {40 public:41 JSArray(JSValue* prototype, unsigned initialLength);42 JSArray(JSObject* prototype, const ArgList& initialValues);43 virtual ~JSArray();39 class JSArray : public JSObject { 40 public: 41 JSArray(JSValue* prototype, unsigned initialLength); 42 JSArray(JSObject* prototype, const ArgList& initialValues); 43 virtual ~JSArray(); 44 44 45 virtual bool getOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);46 virtual bool getOwnPropertySlot(ExecState*, unsigned propertyName, PropertySlot&);47 virtual void put(ExecState*, unsigned propertyName, JSValue*); // FIXME: Make protected and add setItem.45 virtual bool getOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&); 46 virtual bool getOwnPropertySlot(ExecState*, unsigned propertyName, PropertySlot&); 47 virtual void put(ExecState*, unsigned propertyName, JSValue*); // FIXME: Make protected and add setItem. 48 48 49 static const ClassInfo info;49 static const ClassInfo info; 50 50 51 unsigned getLength() const { return m_length; }52 void setLength(unsigned); // OK to use on new arrays, but not if it might be a RegExpMatchArray.51 unsigned getLength() const { return m_length; } 52 void setLength(unsigned); // OK to use on new arrays, but not if it might be a RegExpMatchArray. 53 53 54 void sort(ExecState*);55 void sort(ExecState*, JSValue* compareFunction, CallType, const CallData&);54 void sort(ExecState*); 55 void sort(ExecState*, JSValue* compareFunction, CallType, const CallData&); 56 56 57 bool canGetIndex(unsigned i) { return i < m_fastAccessCutoff; }58 JSValue* getIndex(unsigned i)59 {60 ASSERT(canGetIndex(i));61 return m_storage->m_vector[i];62 }57 bool canGetIndex(unsigned i) { return i < m_fastAccessCutoff; } 58 JSValue* getIndex(unsigned i) 59 { 60 ASSERT(canGetIndex(i)); 61 return m_storage->m_vector[i]; 62 } 63 63 64 bool canSetIndex(unsigned i) { return i < m_fastAccessCutoff; }65 JSValue* setIndex(unsigned i, JSValue* v)66 {67 ASSERT(canSetIndex(i));68 return m_storage->m_vector[i] = v;69 }64 bool canSetIndex(unsigned i) { return i < m_fastAccessCutoff; } 65 JSValue* setIndex(unsigned i, JSValue* v) 66 { 67 ASSERT(canSetIndex(i)); 68 return m_storage->m_vector[i] = v; 69 } 70 70 71 protected:72 virtual void put(ExecState*, const Identifier& propertyName, JSValue*);73 virtual bool deleteProperty(ExecState*, const Identifier& propertyName);74 virtual bool deleteProperty(ExecState*, unsigned propertyName);75 virtual void getPropertyNames(ExecState*, PropertyNameArray&);76 virtual void mark();71 protected: 72 virtual void put(ExecState*, const Identifier& propertyName, JSValue*); 73 virtual bool deleteProperty(ExecState*, const Identifier& propertyName); 74 virtual bool deleteProperty(ExecState*, unsigned propertyName); 75 virtual void getPropertyNames(ExecState*, PropertyNameArray&); 76 virtual void mark(); 77 77 78 void* lazyCreationData();79 void setLazyCreationData(void*);78 void* lazyCreationData(); 79 void setLazyCreationData(void*); 80 80 81 private:82 virtual const ClassInfo* classInfo() const { return &info; }81 private: 82 virtual const ClassInfo* classInfo() const { return &info; } 83 83 84 static JSValue* lengthGetter(ExecState*, const Identifier&, const PropertySlot&);84 static JSValue* lengthGetter(ExecState*, const Identifier&, const PropertySlot&); 85 85 86 bool getOwnPropertySlotSlowCase(ExecState*, unsigned propertyName, PropertySlot&);87 void putSlowCase(ExecState*, unsigned propertyName, JSValue*);86 bool getOwnPropertySlotSlowCase(ExecState*, unsigned propertyName, PropertySlot&); 87 void putSlowCase(ExecState*, unsigned propertyName, JSValue*); 88 88 89 bool increaseVectorLength(unsigned newLength);90 91 unsigned compactForSorting();89 bool increaseVectorLength(unsigned newLength); 90 91 unsigned compactForSorting(); 92 92 93 enum ConsistencyCheckType { NormalConsistencyCheck, DestructorConsistencyCheck, SortConsistencyCheck };94 void checkConsistency(ConsistencyCheckType = NormalConsistencyCheck);93 enum ConsistencyCheckType { NormalConsistencyCheck, DestructorConsistencyCheck, SortConsistencyCheck }; 94 void checkConsistency(ConsistencyCheckType = NormalConsistencyCheck); 95 95 96 unsigned m_length;97 unsigned m_fastAccessCutoff;98 ArrayStorage* m_storage;99 };96 unsigned m_length; 97 unsigned m_fastAccessCutoff; 98 ArrayStorage* m_storage; 99 }; 100 100 101 JSArray* constructEmptyArray(ExecState*);102 JSArray* constructEmptyArray(ExecState*, unsigned initialLength);103 JSArray* constructArray(ExecState*, JSValue* singleItemValue);104 JSArray* constructArray(ExecState*, const ArgList& values);101 JSArray* constructEmptyArray(ExecState*); 102 JSArray* constructEmptyArray(ExecState*, unsigned initialLength); 103 JSArray* constructArray(ExecState*, JSValue* singleItemValue); 104 JSArray* constructArray(ExecState*, const ArgList& values); 105 105 106 106 } // namespace KJS 107 107 108 #endif 108 #endif // JSArray_h
Note:
See TracChangeset
for help on using the changeset viewer.