]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - runtime/RegExpMatchesArray.h
JavaScriptCore-1097.13.tar.gz
[apple/javascriptcore.git] / runtime / RegExpMatchesArray.h
index 358394117f1fd6af78e794a4b6499a715f4c73a6..595457bca16d221e79d575db124a61cb97cd3c1a 100644 (file)
 #define RegExpMatchesArray_h
 
 #include "JSArray.h"
+#include "JSGlobalObject.h"
+#include "RegExpObject.h"
 
 namespace JSC {
 
     class RegExpMatchesArray : public JSArray {
+    private:
+        RegExpMatchesArray(JSGlobalData& globalData, JSGlobalObject* globalObject, JSString* input, RegExp* regExp, MatchResult result)
+            : JSArray(globalData, globalObject->regExpMatchesArrayStructure())
+            , m_result(result)
+            , m_state(ReifiedNone)
+        {
+            m_input.set(globalData, this, input);
+            m_regExp.set(globalData, this, regExp);
+        }
+
+        enum ReifiedState { ReifiedNone, ReifiedMatch, ReifiedAll };
+
     public:
-        RegExpMatchesArray(ExecState*, RegExpConstructorPrivate*);
-        virtual ~RegExpMatchesArray();
+        typedef JSArray Base;
+
+        static RegExpMatchesArray* create(ExecState* exec, JSString* input, RegExp* regExp, MatchResult result)
+        {
+            ASSERT(result);
+            JSGlobalData& globalData = exec->globalData();
+            RegExpMatchesArray* array = new (NotNull, allocateCell<RegExpMatchesArray>(globalData.heap)) RegExpMatchesArray(globalData, exec->lexicalGlobalObject(), input, regExp, result);
+            array->finishCreation(globalData);
+            return array;
+        }
+
+        JSString* leftContext(ExecState*);
+        JSString* rightContext(ExecState*);
+
+        static const ClassInfo s_info;
+
+        static Structure* createStructure(JSGlobalData& globalData, JSGlobalObject* globalObject, JSValue prototype)
+        {
+            return Structure::create(globalData, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), &s_info);
+        }
+
+        static void visitChildren(JSCell*, SlotVisitor&);
+
+    protected:
+        void finishCreation(JSGlobalData&);
+
+        static const unsigned StructureFlags = OverridesGetOwnPropertySlot | OverridesVisitChildren | OverridesGetPropertyNames | Base::StructureFlags;
 
     private:
-        virtual bool getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
+        ALWAYS_INLINE void reifyAllPropertiesIfNecessary(ExecState* exec)
+        {
+            if (m_state != ReifiedAll)
+                reifyAllProperties(exec);
+        }
+
+        ALWAYS_INLINE void reifyMatchPropertyIfNecessary(ExecState* exec)
+        {
+            if (m_state == ReifiedNone)
+                reifyMatchProperty(exec);
+        }
+
+        static bool getOwnPropertySlot(JSCell* cell, ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
         {
-            if (lazyCreationData())
-                fillArrayInstance(exec);
-            return JSArray::getOwnPropertySlot(exec, propertyName, slot);
+            RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(cell);
+            thisObject->reifyAllPropertiesIfNecessary(exec);
+            return JSArray::getOwnPropertySlot(thisObject, exec, propertyName, slot);
         }
 
-        virtual bool getOwnPropertySlot(ExecState* exec, unsigned propertyName, PropertySlot& slot)
+        static bool getOwnPropertySlotByIndex(JSCell* cell, ExecState* exec, unsigned propertyName, PropertySlot& slot)
         {
-            if (lazyCreationData())
-                fillArrayInstance(exec);
-            return JSArray::getOwnPropertySlot(exec, propertyName, slot);
+            RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(cell);
+            if (propertyName)
+                thisObject->reifyAllPropertiesIfNecessary(exec);
+            else
+                thisObject->reifyMatchPropertyIfNecessary(exec);
+            return JSArray::getOwnPropertySlotByIndex(thisObject, exec, propertyName, slot);
         }
 
-        virtual void put(ExecState* exec, const Identifier& propertyName, JSValuePtr v, PutPropertySlot& slot)
+        static bool getOwnPropertyDescriptor(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
         {
-            if (lazyCreationData())
-                fillArrayInstance(exec);
-            JSArray::put(exec, propertyName, v, slot);
+            RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(object);
+            thisObject->reifyAllPropertiesIfNecessary(exec);
+            return JSArray::getOwnPropertyDescriptor(thisObject, exec, propertyName, descriptor);
         }
 
-        virtual void put(ExecState* exec, unsigned propertyName, JSValuePtr v)
+        static void put(JSCell* cell, ExecState* exec, const Identifier& propertyName, JSValue v, PutPropertySlot& slot)
+        {
+            RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(cell);
+            thisObject->reifyAllPropertiesIfNecessary(exec);
+            JSArray::put(thisObject, exec, propertyName, v, slot);
+        }
+        
+        static void putByIndex(JSCell* cell, ExecState* exec, unsigned propertyName, JSValue v, bool shouldThrow)
         {
-            if (lazyCreationData())
-                fillArrayInstance(exec);
-            JSArray::put(exec, propertyName, v);
+            RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(cell);
+            thisObject->reifyAllPropertiesIfNecessary(exec);
+            JSArray::putByIndex(thisObject, exec, propertyName, v, shouldThrow);
         }
 
-        virtual bool deleteProperty(ExecState* exec, const Identifier& propertyName)
+        static bool deleteProperty(JSCell* cell, ExecState* exec, const Identifier& propertyName)
         {
-            if (lazyCreationData())
-                fillArrayInstance(exec);
-            return JSArray::deleteProperty(exec, propertyName);
+            RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(cell);
+            thisObject->reifyAllPropertiesIfNecessary(exec);
+            return JSArray::deleteProperty(thisObject, exec, propertyName);
         }
 
-        virtual bool deleteProperty(ExecState* exec, unsigned propertyName)
+        static bool deletePropertyByIndex(JSCell* cell, ExecState* exec, unsigned propertyName)
         {
-            if (lazyCreationData())
-                fillArrayInstance(exec);
-            return JSArray::deleteProperty(exec, propertyName);
+            RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(cell);
+            thisObject->reifyAllPropertiesIfNecessary(exec);
+            return JSArray::deletePropertyByIndex(thisObject, exec, propertyName);
         }
 
-        virtual void getPropertyNames(ExecState* exec, PropertyNameArray& arr)
+        static void getOwnPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& arr, EnumerationMode mode = ExcludeDontEnumProperties)
         {
-            if (lazyCreationData())
-                fillArrayInstance(exec);
-            JSArray::getPropertyNames(exec, arr);
+            RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(object);
+            thisObject->reifyAllPropertiesIfNecessary(exec);
+            JSArray::getOwnPropertyNames(thisObject, exec, arr, mode);
         }
 
-        void fillArrayInstance(ExecState*);
+        static bool defineOwnProperty(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor, bool shouldThrow)
+        {
+            RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(object);
+            thisObject->reifyAllPropertiesIfNecessary(exec);
+            return JSArray::defineOwnProperty(object, exec, propertyName, descriptor, shouldThrow);
+        }
+
+        void reifyAllProperties(ExecState*);
+        void reifyMatchProperty(ExecState*);
+
+        WriteBarrier<JSString> m_input;
+        WriteBarrier<RegExp> m_regExp;
+        MatchResult m_result;
+        ReifiedState m_state;
 };
 
 }