X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/ba379fdc102753d6be2c4d937058fe40257329fe..93a3786624b2768d89bfa27e46598dc64e2fb70a:/runtime/JSPropertyNameIterator.h diff --git a/runtime/JSPropertyNameIterator.h b/runtime/JSPropertyNameIterator.h index 9817c07..ba931b1 100644 --- a/runtime/JSPropertyNameIterator.h +++ b/runtime/JSPropertyNameIterator.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008 Apple Inc. All rights reserved. + * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -31,85 +31,87 @@ #include "JSObject.h" #include "JSString.h" +#include "Operations.h" #include "PropertyNameArray.h" namespace JSC { class Identifier; class JSObject; + class LLIntOffsetsExtractor; class JSPropertyNameIterator : public JSCell { - public: - static JSPropertyNameIterator* create(ExecState*, JSValue); - - virtual ~JSPropertyNameIterator(); - - virtual JSValue toPrimitive(ExecState*, PreferredPrimitiveType) const; - virtual bool getPrimitiveNumber(ExecState*, double&, JSValue&); - virtual bool toBoolean(ExecState*) const; - virtual double toNumber(ExecState*) const; - virtual UString toString(ExecState*) const; - virtual JSObject* toObject(ExecState*) const; + friend class JIT; - virtual void mark(); - - JSValue next(ExecState*); - void invalidate(); + public: + typedef JSCell Base; + + static JSPropertyNameIterator* create(ExecState*, JSObject*); + + static const bool needsDestruction = true; + static const bool hasImmortalStructure = true; + static void destroy(JSCell*); + + static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype) + { + return Structure::create(vm, globalObject, prototype, TypeInfo(CompoundType, OverridesVisitChildren), &s_info); + } + + static void visitChildren(JSCell*, SlotVisitor&); + + JSValue get(ExecState*, JSObject*, size_t i); + size_t size() { return m_jsStringsSize; } + + void setCachedStructure(VM& vm, Structure* structure) + { + ASSERT(!m_cachedStructure); + ASSERT(structure); + m_cachedStructure.set(vm, this, structure); + } + Structure* cachedStructure() { return m_cachedStructure.get(); } + + void setCachedPrototypeChain(VM& vm, StructureChain* cachedPrototypeChain) { m_cachedPrototypeChain.set(vm, this, cachedPrototypeChain); } + StructureChain* cachedPrototypeChain() { return m_cachedPrototypeChain.get(); } + + static JS_EXPORTDATA const ClassInfo s_info; + + protected: + void finishCreation(ExecState* exec, PropertyNameArrayData* propertyNameArrayData, JSObject* object) + { + Base::finishCreation(exec->vm()); + PropertyNameArrayData::PropertyNameVector& propertyNameVector = propertyNameArrayData->propertyNameVector(); + for (size_t i = 0; i < m_jsStringsSize; ++i) + m_jsStrings[i].set(exec->vm(), this, jsOwnedString(exec, propertyNameVector[i].string())); + m_cachedStructureInlineCapacity = object->structure()->inlineCapacity(); + } private: - JSPropertyNameIterator(); - JSPropertyNameIterator(JSObject*, PassRefPtr propertyNameArrayData); - - JSObject* m_object; - RefPtr m_data; - PropertyNameArrayData::const_iterator m_position; - PropertyNameArrayData::const_iterator m_end; + friend class LLIntOffsetsExtractor; + + JSPropertyNameIterator(ExecState*, PropertyNameArrayData* propertyNameArrayData, size_t numCacheableSlot); + + WriteBarrier m_cachedStructure; + WriteBarrier m_cachedPrototypeChain; + uint32_t m_numCacheableSlots; + uint32_t m_jsStringsSize; + unsigned m_cachedStructureInlineCapacity; + OwnArrayPtr > m_jsStrings; }; -inline JSPropertyNameIterator::JSPropertyNameIterator() - : JSCell(0) - , m_object(0) - , m_position(0) - , m_end(0) -{ -} - -inline JSPropertyNameIterator::JSPropertyNameIterator(JSObject* object, PassRefPtr propertyNameArrayData) - : JSCell(0) - , m_object(object) - , m_data(propertyNameArrayData) - , m_position(m_data->begin()) - , m_end(m_data->end()) -{ -} - -inline JSPropertyNameIterator* JSPropertyNameIterator::create(ExecState* exec, JSValue v) -{ - if (v.isUndefinedOrNull()) - return new (exec) JSPropertyNameIterator; - - JSObject* o = v.toObject(exec); - PropertyNameArray propertyNames(exec); - o->getPropertyNames(exec, propertyNames); - return new (exec) JSPropertyNameIterator(o, propertyNames.releaseData()); -} - -inline JSValue JSPropertyNameIterator::next(ExecState* exec) -{ - if (m_position == m_end) - return JSValue(); - - if (m_data->cachedStructure() == m_object->structure() && m_data->cachedPrototypeChain() == m_object->structure()->prototypeChain(exec)) - return jsOwnedString(exec, (*m_position++).ustring()); - - do { - if (m_object->hasProperty(exec, *m_position)) - return jsOwnedString(exec, (*m_position++).ustring()); - m_position++; - } while (m_position != m_end); - - return JSValue(); -} + ALWAYS_INLINE JSPropertyNameIterator* Register::propertyNameIterator() const + { + return jsCast(jsValue().asCell()); + } + + inline JSPropertyNameIterator* StructureRareData::enumerationCache() + { + return m_enumerationCache.get(); + } + + inline void StructureRareData::setEnumerationCache(VM& vm, const Structure* owner, JSPropertyNameIterator* value) + { + m_enumerationCache.set(vm, owner, value); + } } // namespace JSC