]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - runtime/StructureChain.h
JavaScriptCore-1097.13.tar.gz
[apple/javascriptcore.git] / runtime / StructureChain.h
index 795e6494a7b72cb716db3f247de203f7ad0f19a1..3b19d4cf16baf6ae63f4ab2e07e32a2f61312c46 100644 (file)
 #ifndef StructureChain_h
 #define StructureChain_h
 
+#include "JSCell.h"
+#include "JSObject.h"
+#include "Structure.h"
+
 #include <wtf/OwnArrayPtr.h>
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefCounted.h>
 
 namespace JSC {
 
+    class LLIntOffsetsExtractor;
     class Structure;
 
-    class StructureChain : public RefCounted<StructureChain> {
+    class StructureChain : public JSCell {
+        friend class JIT;
+
     public:
-        static PassRefPtr<StructureChain> create(Structure* head) { return adoptRef(new StructureChain(head)); }
-        RefPtr<Structure>* head() { return m_vector.get(); }
+        typedef JSCell Base;
 
-    private:
-        StructureChain(Structure* head);
+        static StructureChain* create(JSGlobalData& globalData, Structure* head)
+        { 
+            StructureChain* chain = new (NotNull, allocateCell<StructureChain>(globalData.heap)) StructureChain(globalData, globalData.structureChainStructure.get());
+            chain->finishCreation(globalData, head);
+            return chain;
+        }
+        WriteBarrier<Structure>* head() { return m_vector.get(); }
+        static void visitChildren(JSCell*, SlotVisitor&);
+
+        static Structure* createStructure(JSGlobalData& globalData, JSGlobalObject* globalObject, JSValue prototype) { return Structure::create(globalData, globalObject, prototype, TypeInfo(CompoundType, OverridesVisitChildren), &s_info); }
+        
+        static ClassInfo s_info;
 
-        OwnArrayPtr<RefPtr<Structure> > m_vector;
+    protected:
+        void finishCreation(JSGlobalData& globalData, Structure* head)
+        {
+            Base::finishCreation(globalData);
+            size_t size = 0;
+            for (Structure* current = head; current; current = current->storedPrototype().isNull() ? 0 : asObject(current->storedPrototype())->structure())
+                ++size;
+    
+            m_vector = adoptArrayPtr(new WriteBarrier<Structure>[size + 1]);
+
+            size_t i = 0;
+            for (Structure* current = head; current; current = current->storedPrototype().isNull() ? 0 : asObject(current->storedPrototype())->structure())
+                m_vector[i++].set(globalData, this, current);
+        }
+
+    private:
+        friend class LLIntOffsetsExtractor;
+        
+        StructureChain(JSGlobalData&, Structure*);
+        static void destroy(JSCell*);
+        OwnArrayPtr<WriteBarrier<Structure> > m_vector;
     };
 
 } // namespace JSC