]> git.saurik.com Git - apple/javascriptcore.git/blame - runtime/RegExpMatchesArray.h
JavaScriptCore-1097.13.tar.gz
[apple/javascriptcore.git] / runtime / RegExpMatchesArray.h
CommitLineData
9dae56ea
A
1/*
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 *
18 */
19
20#ifndef RegExpMatchesArray_h
21#define RegExpMatchesArray_h
22
23#include "JSArray.h"
6fe7ccc8
A
24#include "JSGlobalObject.h"
25#include "RegExpObject.h"
9dae56ea
A
26
27namespace JSC {
28
29 class RegExpMatchesArray : public JSArray {
6fe7ccc8
A
30 private:
31 RegExpMatchesArray(JSGlobalData& globalData, JSGlobalObject* globalObject, JSString* input, RegExp* regExp, MatchResult result)
32 : JSArray(globalData, globalObject->regExpMatchesArrayStructure())
33 , m_result(result)
34 , m_state(ReifiedNone)
35 {
36 m_input.set(globalData, this, input);
37 m_regExp.set(globalData, this, regExp);
38 }
39
40 enum ReifiedState { ReifiedNone, ReifiedMatch, ReifiedAll };
41
9dae56ea 42 public:
6fe7ccc8
A
43 typedef JSArray Base;
44
45 static RegExpMatchesArray* create(ExecState* exec, JSString* input, RegExp* regExp, MatchResult result)
46 {
47 ASSERT(result);
48 JSGlobalData& globalData = exec->globalData();
49 RegExpMatchesArray* array = new (NotNull, allocateCell<RegExpMatchesArray>(globalData.heap)) RegExpMatchesArray(globalData, exec->lexicalGlobalObject(), input, regExp, result);
50 array->finishCreation(globalData);
51 return array;
52 }
53
54 JSString* leftContext(ExecState*);
55 JSString* rightContext(ExecState*);
56
57 static const ClassInfo s_info;
58
59 static Structure* createStructure(JSGlobalData& globalData, JSGlobalObject* globalObject, JSValue prototype)
60 {
61 return Structure::create(globalData, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), &s_info);
62 }
63
64 static void visitChildren(JSCell*, SlotVisitor&);
65
66 protected:
67 void finishCreation(JSGlobalData&);
68
69 static const unsigned StructureFlags = OverridesGetOwnPropertySlot | OverridesVisitChildren | OverridesGetPropertyNames | Base::StructureFlags;
9dae56ea
A
70
71 private:
6fe7ccc8
A
72 ALWAYS_INLINE void reifyAllPropertiesIfNecessary(ExecState* exec)
73 {
74 if (m_state != ReifiedAll)
75 reifyAllProperties(exec);
76 }
77
78 ALWAYS_INLINE void reifyMatchPropertyIfNecessary(ExecState* exec)
9dae56ea 79 {
6fe7ccc8
A
80 if (m_state == ReifiedNone)
81 reifyMatchProperty(exec);
9dae56ea
A
82 }
83
6fe7ccc8 84 static bool getOwnPropertySlot(JSCell* cell, ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
9dae56ea 85 {
6fe7ccc8
A
86 RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(cell);
87 thisObject->reifyAllPropertiesIfNecessary(exec);
88 return JSArray::getOwnPropertySlot(thisObject, exec, propertyName, slot);
9dae56ea
A
89 }
90
6fe7ccc8 91 static bool getOwnPropertySlotByIndex(JSCell* cell, ExecState* exec, unsigned propertyName, PropertySlot& slot)
f9bf01c6 92 {
6fe7ccc8
A
93 RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(cell);
94 if (propertyName)
95 thisObject->reifyAllPropertiesIfNecessary(exec);
96 else
97 thisObject->reifyMatchPropertyIfNecessary(exec);
98 return JSArray::getOwnPropertySlotByIndex(thisObject, exec, propertyName, slot);
f9bf01c6
A
99 }
100
6fe7ccc8 101 static bool getOwnPropertyDescriptor(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
9dae56ea 102 {
6fe7ccc8
A
103 RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(object);
104 thisObject->reifyAllPropertiesIfNecessary(exec);
105 return JSArray::getOwnPropertyDescriptor(thisObject, exec, propertyName, descriptor);
9dae56ea
A
106 }
107
6fe7ccc8 108 static void put(JSCell* cell, ExecState* exec, const Identifier& propertyName, JSValue v, PutPropertySlot& slot)
9dae56ea 109 {
6fe7ccc8
A
110 RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(cell);
111 thisObject->reifyAllPropertiesIfNecessary(exec);
112 JSArray::put(thisObject, exec, propertyName, v, slot);
113 }
114
115 static void putByIndex(JSCell* cell, ExecState* exec, unsigned propertyName, JSValue v, bool shouldThrow)
116 {
117 RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(cell);
118 thisObject->reifyAllPropertiesIfNecessary(exec);
119 JSArray::putByIndex(thisObject, exec, propertyName, v, shouldThrow);
120 }
121
122 static bool deleteProperty(JSCell* cell, ExecState* exec, const Identifier& propertyName)
123 {
124 RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(cell);
125 thisObject->reifyAllPropertiesIfNecessary(exec);
126 return JSArray::deleteProperty(thisObject, exec, propertyName);
9dae56ea
A
127 }
128
6fe7ccc8 129 static bool deletePropertyByIndex(JSCell* cell, ExecState* exec, unsigned propertyName)
9dae56ea 130 {
6fe7ccc8
A
131 RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(cell);
132 thisObject->reifyAllPropertiesIfNecessary(exec);
133 return JSArray::deletePropertyByIndex(thisObject, exec, propertyName);
9dae56ea
A
134 }
135
6fe7ccc8 136 static void getOwnPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& arr, EnumerationMode mode = ExcludeDontEnumProperties)
9dae56ea 137 {
6fe7ccc8
A
138 RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(object);
139 thisObject->reifyAllPropertiesIfNecessary(exec);
140 JSArray::getOwnPropertyNames(thisObject, exec, arr, mode);
9dae56ea
A
141 }
142
6fe7ccc8 143 static bool defineOwnProperty(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor, bool shouldThrow)
9dae56ea 144 {
6fe7ccc8
A
145 RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(object);
146 thisObject->reifyAllPropertiesIfNecessary(exec);
147 return JSArray::defineOwnProperty(object, exec, propertyName, descriptor, shouldThrow);
9dae56ea
A
148 }
149
6fe7ccc8
A
150 void reifyAllProperties(ExecState*);
151 void reifyMatchProperty(ExecState*);
152
153 WriteBarrier<JSString> m_input;
154 WriteBarrier<RegExp> m_regExp;
155 MatchResult m_result;
156 ReifiedState m_state;
9dae56ea
A
157};
158
159}
160
161#endif // RegExpMatchesArray_h