]> git.saurik.com Git - apple/javascriptcore.git/blame - runtime/RegExpMatchesArray.h
JavaScriptCore-1218.35.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 30 private:
93a37866 31 RegExpMatchesArray(VM&, Butterfly*, JSGlobalObject*, JSString*, RegExp*, MatchResult);
6fe7ccc8
A
32
33 enum ReifiedState { ReifiedNone, ReifiedMatch, ReifiedAll };
34
9dae56ea 35 public:
6fe7ccc8
A
36 typedef JSArray Base;
37
93a37866 38 static RegExpMatchesArray* create(ExecState*, JSString*, RegExp*, MatchResult);
6fe7ccc8
A
39
40 JSString* leftContext(ExecState*);
41 JSString* rightContext(ExecState*);
42
43 static const ClassInfo s_info;
44
93a37866 45 static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
6fe7ccc8 46 {
12899fa2 47 return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), &s_info, ArrayWithSlowPutArrayStorage);
6fe7ccc8
A
48 }
49
50 static void visitChildren(JSCell*, SlotVisitor&);
51
52 protected:
93a37866 53 void finishCreation(VM&);
6fe7ccc8
A
54
55 static const unsigned StructureFlags = OverridesGetOwnPropertySlot | OverridesVisitChildren | OverridesGetPropertyNames | Base::StructureFlags;
9dae56ea
A
56
57 private:
6fe7ccc8
A
58 ALWAYS_INLINE void reifyAllPropertiesIfNecessary(ExecState* exec)
59 {
60 if (m_state != ReifiedAll)
61 reifyAllProperties(exec);
62 }
63
64 ALWAYS_INLINE void reifyMatchPropertyIfNecessary(ExecState* exec)
9dae56ea 65 {
6fe7ccc8
A
66 if (m_state == ReifiedNone)
67 reifyMatchProperty(exec);
9dae56ea
A
68 }
69
93a37866 70 static bool getOwnPropertySlot(JSCell* cell, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
9dae56ea 71 {
6fe7ccc8
A
72 RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(cell);
73 thisObject->reifyAllPropertiesIfNecessary(exec);
74 return JSArray::getOwnPropertySlot(thisObject, exec, propertyName, slot);
9dae56ea
A
75 }
76
6fe7ccc8 77 static bool getOwnPropertySlotByIndex(JSCell* cell, ExecState* exec, unsigned propertyName, PropertySlot& slot)
f9bf01c6 78 {
6fe7ccc8
A
79 RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(cell);
80 if (propertyName)
81 thisObject->reifyAllPropertiesIfNecessary(exec);
82 else
83 thisObject->reifyMatchPropertyIfNecessary(exec);
84 return JSArray::getOwnPropertySlotByIndex(thisObject, exec, propertyName, slot);
f9bf01c6
A
85 }
86
93a37866 87 static bool getOwnPropertyDescriptor(JSObject* object, ExecState* exec, PropertyName propertyName, PropertyDescriptor& descriptor)
9dae56ea 88 {
6fe7ccc8
A
89 RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(object);
90 thisObject->reifyAllPropertiesIfNecessary(exec);
91 return JSArray::getOwnPropertyDescriptor(thisObject, exec, propertyName, descriptor);
9dae56ea
A
92 }
93
93a37866 94 static void put(JSCell* cell, ExecState* exec, PropertyName propertyName, JSValue v, PutPropertySlot& slot)
9dae56ea 95 {
6fe7ccc8
A
96 RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(cell);
97 thisObject->reifyAllPropertiesIfNecessary(exec);
98 JSArray::put(thisObject, exec, propertyName, v, slot);
99 }
100
101 static void putByIndex(JSCell* cell, ExecState* exec, unsigned propertyName, JSValue v, bool shouldThrow)
102 {
103 RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(cell);
104 thisObject->reifyAllPropertiesIfNecessary(exec);
105 JSArray::putByIndex(thisObject, exec, propertyName, v, shouldThrow);
106 }
107
93a37866 108 static bool deleteProperty(JSCell* cell, ExecState* exec, PropertyName propertyName)
6fe7ccc8
A
109 {
110 RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(cell);
111 thisObject->reifyAllPropertiesIfNecessary(exec);
112 return JSArray::deleteProperty(thisObject, exec, propertyName);
9dae56ea
A
113 }
114
6fe7ccc8 115 static bool deletePropertyByIndex(JSCell* cell, ExecState* exec, unsigned propertyName)
9dae56ea 116 {
6fe7ccc8
A
117 RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(cell);
118 thisObject->reifyAllPropertiesIfNecessary(exec);
119 return JSArray::deletePropertyByIndex(thisObject, exec, propertyName);
9dae56ea
A
120 }
121
6fe7ccc8 122 static void getOwnPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& arr, EnumerationMode mode = ExcludeDontEnumProperties)
9dae56ea 123 {
6fe7ccc8
A
124 RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(object);
125 thisObject->reifyAllPropertiesIfNecessary(exec);
126 JSArray::getOwnPropertyNames(thisObject, exec, arr, mode);
9dae56ea
A
127 }
128
93a37866 129 static bool defineOwnProperty(JSObject* object, ExecState* exec, PropertyName propertyName, PropertyDescriptor& descriptor, bool shouldThrow)
9dae56ea 130 {
6fe7ccc8
A
131 RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(object);
132 thisObject->reifyAllPropertiesIfNecessary(exec);
133 return JSArray::defineOwnProperty(object, exec, propertyName, descriptor, shouldThrow);
9dae56ea
A
134 }
135
6fe7ccc8
A
136 void reifyAllProperties(ExecState*);
137 void reifyMatchProperty(ExecState*);
138
139 WriteBarrier<JSString> m_input;
140 WriteBarrier<RegExp> m_regExp;
141 MatchResult m_result;
142 ReifiedState m_state;
9dae56ea
A
143};
144
145}
146
147#endif // RegExpMatchesArray_h