Changeset 49726 in webkit for trunk/JavaScriptCore/runtime/JSPropertyNameIterator.h
- Timestamp:
- Oct 16, 2009, 7:31:42 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/JSPropertyNameIterator.h
r49717 r49726 32 32 #include "JSObject.h" 33 33 #include "JSString.h" 34 #include "Operations.h"35 34 #include "PropertyNameArray.h" 36 35 … … 41 40 42 41 class JSPropertyNameIterator : public JSCell { 43 friend class JIT; 42 public: 43 static JSPropertyNameIterator* create(ExecState*, JSValue); 44 44 45 public: 46 static JSPropertyNameIterator* create(ExecState*, JSObject*); 45 virtual ~JSPropertyNameIterator(); 46 47 virtual void markChildren(MarkStack&); 48 49 JSValue next(ExecState*); 50 void invalidate(); 47 51 48 52 static PassRefPtr<Structure> createStructure(JSValue prototype) … … 50 54 return Structure::create(prototype, TypeInfo(CompoundType, OverridesMarkChildren)); 51 55 } 56 private: 57 JSPropertyNameIterator(ExecState*); 58 JSPropertyNameIterator(ExecState*, JSObject*, PassRefPtr<PropertyNameArrayData> propertyNameArrayData); 52 59 53 virtual void markChildren(MarkStack&); 54 55 JSValue get(ExecState*, JSObject*, size_t i); 56 size_t size() { return m_jsStringsSize; } 57 58 void setCachedStructure(Structure* structure) { m_cachedStructure = structure; } 59 Structure* cachedStructure() { return m_cachedStructure; } 60 61 void setCachedPrototypeChain(NonNullPassRefPtr<StructureChain> cachedPrototypeChain) { m_cachedPrototypeChain = cachedPrototypeChain; } 62 StructureChain* cachedPrototypeChain() { return m_cachedPrototypeChain.get(); } 63 64 private: 65 JSPropertyNameIterator(ExecState*, PropertyNameArrayData* propertyNameArrayData); 66 67 Structure* m_cachedStructure; 68 RefPtr<StructureChain> m_cachedPrototypeChain; 69 size_t m_jsStringsSize; 70 OwnArrayPtr<JSValue> m_jsStrings; 60 JSObject* m_object; 61 RefPtr<PropertyNameArrayData> m_data; 62 PropertyNameArrayData::const_iterator m_position; 63 PropertyNameArrayData::const_iterator m_end; 71 64 }; 72 65 73 inline JSPropertyNameIterator::JSPropertyNameIterator(ExecState* exec , PropertyNameArrayData* propertyNameArrayData)66 inline JSPropertyNameIterator::JSPropertyNameIterator(ExecState* exec) 74 67 : JSCell(exec->globalData().propertyNameIteratorStructure.get()) 75 , m_ cachedStructure(0)76 , m_ jsStringsSize(propertyNameArrayData->propertyNameVector().size())77 , m_ jsStrings(new JSValue[m_jsStringsSize])68 , m_object(0) 69 , m_position(0) 70 , m_end(0) 78 71 { 79 PropertyNameArrayData::PropertyNameVector& propertyNameVector = propertyNameArrayData->propertyNameVector();80 for (size_t i = 0; i < m_jsStringsSize; ++i)81 m_jsStrings[i] = jsOwnedString(exec, propertyNameVector[i].ustring());82 72 } 83 73 84 inline void Structure::setEnumerationCache(JSPropertyNameIterator* enumerationCache) 74 inline JSPropertyNameIterator::JSPropertyNameIterator(ExecState* exec, JSObject* object, PassRefPtr<PropertyNameArrayData> propertyNameArrayData) 75 : JSCell(exec->globalData().propertyNameIteratorStructure.get()) 76 , m_object(object) 77 , m_data(propertyNameArrayData) 78 , m_position(m_data->begin()) 79 , m_end(m_data->end()) 85 80 { 86 ASSERT(!isDictionary()); 87 m_enumerationCache = enumerationCache; 81 } 82 83 inline JSPropertyNameIterator* JSPropertyNameIterator::create(ExecState* exec, JSValue v) 84 { 85 if (v.isUndefinedOrNull()) 86 return new (exec) JSPropertyNameIterator(exec); 87 88 JSObject* o = v.toObject(exec); 89 PropertyNameArray propertyNames(exec); 90 o->getPropertyNames(exec, propertyNames); 91 return new (exec) JSPropertyNameIterator(exec, o, propertyNames.releaseData()); 92 } 93 94 inline JSValue JSPropertyNameIterator::next(ExecState* exec) 95 { 96 if (m_position == m_end) 97 return JSValue(); 98 99 if (m_data->cachedStructure() == m_object->structure() && m_data->cachedPrototypeChain() == m_object->structure()->prototypeChain(exec)) 100 return jsOwnedString(exec, (*m_position++).ustring()); 101 102 do { 103 if (m_object->hasProperty(exec, *m_position)) 104 return jsOwnedString(exec, (*m_position++).ustring()); 105 m_position++; 106 } while (m_position != m_end); 107 108 return JSValue(); 88 109 } 89 110
Note:
See TracChangeset
for help on using the changeset viewer.