Changeset 49734 in webkit for trunk/JavaScriptCore/runtime/JSPropertyNameIterator.h
- Timestamp:
- Oct 16, 2009, 10:52:20 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/JSPropertyNameIterator.h
r49726 r49734 32 32 #include "JSObject.h" 33 33 #include "JSString.h" 34 #include "Operations.h" 34 35 #include "PropertyNameArray.h" 35 36 … … 40 41 41 42 class JSPropertyNameIterator : public JSCell { 43 friend class JIT; 44 42 45 public: 43 static JSPropertyNameIterator* create(ExecState*, JSValue); 44 45 virtual ~JSPropertyNameIterator(); 46 47 virtual void markChildren(MarkStack&); 48 49 JSValue next(ExecState*); 50 void invalidate(); 46 static JSPropertyNameIterator* create(ExecState*, JSObject*); 51 47 52 48 static PassRefPtr<Structure> createStructure(JSValue prototype) … … 54 50 return Structure::create(prototype, TypeInfo(CompoundType, OverridesMarkChildren)); 55 51 } 52 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 56 64 private: 57 JSPropertyNameIterator(ExecState*); 58 JSPropertyNameIterator(ExecState*, JSObject*, PassRefPtr<PropertyNameArrayData> propertyNameArrayData); 65 JSPropertyNameIterator(ExecState*, PropertyNameArrayData* propertyNameArrayData); 59 66 60 JSObject* m_object;61 RefPtr< PropertyNameArrayData> m_data;62 PropertyNameArrayData::const_iterator m_position;63 PropertyNameArrayData::const_iterator m_end;67 Structure* m_cachedStructure; 68 RefPtr<StructureChain> m_cachedPrototypeChain; 69 size_t m_jsStringsSize; 70 OwnArrayPtr<JSValue> m_jsStrings; 64 71 }; 65 72 66 inline JSPropertyNameIterator::JSPropertyNameIterator(ExecState* exec )73 inline JSPropertyNameIterator::JSPropertyNameIterator(ExecState* exec, PropertyNameArrayData* propertyNameArrayData) 67 74 : JSCell(exec->globalData().propertyNameIteratorStructure.get()) 68 , m_ object(0)69 , m_ position(0)70 , m_ end(0)75 , m_cachedStructure(0) 76 , m_jsStringsSize(propertyNameArrayData->propertyNameVector().size()) 77 , m_jsStrings(new JSValue[m_jsStringsSize]) 71 78 { 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()); 72 82 } 73 83 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()) 84 inline void Structure::setEnumerationCache(JSPropertyNameIterator* enumerationCache) 80 85 { 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(); 86 ASSERT(!isDictionary()); 87 m_enumerationCache = enumerationCache; 109 88 } 110 89
Note:
See TracChangeset
for help on using the changeset viewer.