summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/runtime/RegExpMatchesArray.h
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@nokia.com>2012-05-07 11:21:11 +0200
committerSimon Hausmann <simon.hausmann@nokia.com>2012-05-07 11:21:11 +0200
commit2cf6c8816a73e0132bd8fa3b509d62d7c51b6e47 (patch)
tree988e8c5b116dd0466244ae2fe5af8ee9be926d76 /Source/JavaScriptCore/runtime/RegExpMatchesArray.h
parentdd91e772430dc294e3bf478c119ef8d43c0a3358 (diff)
downloadqtwebkit-2cf6c8816a73e0132bd8fa3b509d62d7c51b6e47.tar.gz
Imported WebKit commit 7e538425aa020340619e927792f3d895061fb54b (http://svn.webkit.org/repository/webkit/trunk@116286)
Diffstat (limited to 'Source/JavaScriptCore/runtime/RegExpMatchesArray.h')
-rw-r--r--Source/JavaScriptCore/runtime/RegExpMatchesArray.h88
1 files changed, 62 insertions, 26 deletions
diff --git a/Source/JavaScriptCore/runtime/RegExpMatchesArray.h b/Source/JavaScriptCore/runtime/RegExpMatchesArray.h
index a3c4497fc..595457bca 100644
--- a/Source/JavaScriptCore/runtime/RegExpMatchesArray.h
+++ b/Source/JavaScriptCore/runtime/RegExpMatchesArray.h
@@ -21,23 +21,38 @@
#define RegExpMatchesArray_h
#include "JSArray.h"
+#include "JSGlobalObject.h"
+#include "RegExpObject.h"
namespace JSC {
class RegExpMatchesArray : public JSArray {
private:
- RegExpMatchesArray(ExecState*);
+ 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:
typedef JSArray Base;
- static RegExpMatchesArray* create(ExecState* exec, const RegExpConstructorPrivate& ctorPrivate)
+ static RegExpMatchesArray* create(ExecState* exec, JSString* input, RegExp* regExp, MatchResult result)
{
- RegExpMatchesArray* regExp = new (NotNull, allocateCell<RegExpMatchesArray>(*exec->heap())) RegExpMatchesArray(exec);
- regExp->finishCreation(exec->globalData(), ctorPrivate);
- return regExp;
+ 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;
}
- static void destroy(JSCell*);
+
+ JSString* leftContext(ExecState*);
+ JSString* rightContext(ExecState*);
static const ClassInfo s_info;
@@ -46,78 +61,99 @@ namespace JSC {
return Structure::create(globalData, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), &s_info);
}
+ static void visitChildren(JSCell*, SlotVisitor&);
+
protected:
- void finishCreation(JSGlobalData&, const RegExpConstructorPrivate& data);
+ void finishCreation(JSGlobalData&);
+
+ static const unsigned StructureFlags = OverridesGetOwnPropertySlot | OverridesVisitChildren | OverridesGetPropertyNames | Base::StructureFlags;
private:
+ 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)
{
RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(cell);
- if (!thisObject->m_didFillArrayInstance)
- thisObject->fillArrayInstance(exec);
+ thisObject->reifyAllPropertiesIfNecessary(exec);
return JSArray::getOwnPropertySlot(thisObject, exec, propertyName, slot);
}
static bool getOwnPropertySlotByIndex(JSCell* cell, ExecState* exec, unsigned propertyName, PropertySlot& slot)
{
RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(cell);
- if (!thisObject->m_didFillArrayInstance)
- thisObject->fillArrayInstance(exec);
+ if (propertyName)
+ thisObject->reifyAllPropertiesIfNecessary(exec);
+ else
+ thisObject->reifyMatchPropertyIfNecessary(exec);
return JSArray::getOwnPropertySlotByIndex(thisObject, exec, propertyName, slot);
}
static bool getOwnPropertyDescriptor(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
{
RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(object);
- if (!thisObject->m_didFillArrayInstance)
- thisObject->fillArrayInstance(exec);
+ thisObject->reifyAllPropertiesIfNecessary(exec);
return JSArray::getOwnPropertyDescriptor(thisObject, exec, propertyName, descriptor);
}
static void put(JSCell* cell, ExecState* exec, const Identifier& propertyName, JSValue v, PutPropertySlot& slot)
{
RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(cell);
- if (!thisObject->m_didFillArrayInstance)
- thisObject->fillArrayInstance(exec);
+ thisObject->reifyAllPropertiesIfNecessary(exec);
JSArray::put(thisObject, exec, propertyName, v, slot);
}
static void putByIndex(JSCell* cell, ExecState* exec, unsigned propertyName, JSValue v, bool shouldThrow)
{
RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(cell);
- if (!thisObject->m_didFillArrayInstance)
- thisObject->fillArrayInstance(exec);
+ thisObject->reifyAllPropertiesIfNecessary(exec);
JSArray::putByIndex(thisObject, exec, propertyName, v, shouldThrow);
}
static bool deleteProperty(JSCell* cell, ExecState* exec, const Identifier& propertyName)
{
RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(cell);
- if (!thisObject->m_didFillArrayInstance)
- thisObject->fillArrayInstance(exec);
+ thisObject->reifyAllPropertiesIfNecessary(exec);
return JSArray::deleteProperty(thisObject, exec, propertyName);
}
static bool deletePropertyByIndex(JSCell* cell, ExecState* exec, unsigned propertyName)
{
RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(cell);
- if (!thisObject->m_didFillArrayInstance)
- thisObject->fillArrayInstance(exec);
+ thisObject->reifyAllPropertiesIfNecessary(exec);
return JSArray::deletePropertyByIndex(thisObject, exec, propertyName);
}
static void getOwnPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& arr, EnumerationMode mode = ExcludeDontEnumProperties)
{
RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(object);
- if (!thisObject->m_didFillArrayInstance)
- thisObject->fillArrayInstance(exec);
+ 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*);
- RegExpResult m_regExpResult;
- bool m_didFillArrayInstance;
+ WriteBarrier<JSString> m_input;
+ WriteBarrier<RegExp> m_regExp;
+ MatchResult m_result;
+ ReifiedState m_state;
};
}