]> git.saurik.com Git - apple/javascriptcore.git/blame_incremental - runtime/RegExpMatchesArray.h
JavaScriptCore-1218.34.tar.gz
[apple/javascriptcore.git] / runtime / RegExpMatchesArray.h
... / ...
CommitLineData
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"
24#include "JSGlobalObject.h"
25#include "RegExpObject.h"
26
27namespace JSC {
28
29 class RegExpMatchesArray : public JSArray {
30 private:
31 RegExpMatchesArray(VM&, Butterfly*, JSGlobalObject*, JSString*, RegExp*, MatchResult);
32
33 enum ReifiedState { ReifiedNone, ReifiedMatch, ReifiedAll };
34
35 public:
36 typedef JSArray Base;
37
38 static RegExpMatchesArray* create(ExecState*, JSString*, RegExp*, MatchResult);
39
40 JSString* leftContext(ExecState*);
41 JSString* rightContext(ExecState*);
42
43 static const ClassInfo s_info;
44
45 static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
46 {
47 return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), &s_info, ArrayWithSlowPutArrayStorage);
48 }
49
50 static void visitChildren(JSCell*, SlotVisitor&);
51
52 protected:
53 void finishCreation(VM&);
54
55 static const unsigned StructureFlags = OverridesGetOwnPropertySlot | OverridesVisitChildren | OverridesGetPropertyNames | Base::StructureFlags;
56
57 private:
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)
65 {
66 if (m_state == ReifiedNone)
67 reifyMatchProperty(exec);
68 }
69
70 static bool getOwnPropertySlot(JSCell* cell, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
71 {
72 RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(cell);
73 thisObject->reifyAllPropertiesIfNecessary(exec);
74 return JSArray::getOwnPropertySlot(thisObject, exec, propertyName, slot);
75 }
76
77 static bool getOwnPropertySlotByIndex(JSCell* cell, ExecState* exec, unsigned propertyName, PropertySlot& slot)
78 {
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);
85 }
86
87 static bool getOwnPropertyDescriptor(JSObject* object, ExecState* exec, PropertyName propertyName, PropertyDescriptor& descriptor)
88 {
89 RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(object);
90 thisObject->reifyAllPropertiesIfNecessary(exec);
91 return JSArray::getOwnPropertyDescriptor(thisObject, exec, propertyName, descriptor);
92 }
93
94 static void put(JSCell* cell, ExecState* exec, PropertyName propertyName, JSValue v, PutPropertySlot& slot)
95 {
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
108 static bool deleteProperty(JSCell* cell, ExecState* exec, PropertyName propertyName)
109 {
110 RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(cell);
111 thisObject->reifyAllPropertiesIfNecessary(exec);
112 return JSArray::deleteProperty(thisObject, exec, propertyName);
113 }
114
115 static bool deletePropertyByIndex(JSCell* cell, ExecState* exec, unsigned propertyName)
116 {
117 RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(cell);
118 thisObject->reifyAllPropertiesIfNecessary(exec);
119 return JSArray::deletePropertyByIndex(thisObject, exec, propertyName);
120 }
121
122 static void getOwnPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& arr, EnumerationMode mode = ExcludeDontEnumProperties)
123 {
124 RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(object);
125 thisObject->reifyAllPropertiesIfNecessary(exec);
126 JSArray::getOwnPropertyNames(thisObject, exec, arr, mode);
127 }
128
129 static bool defineOwnProperty(JSObject* object, ExecState* exec, PropertyName propertyName, PropertyDescriptor& descriptor, bool shouldThrow)
130 {
131 RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(object);
132 thisObject->reifyAllPropertiesIfNecessary(exec);
133 return JSArray::defineOwnProperty(object, exec, propertyName, descriptor, shouldThrow);
134 }
135
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;
143};
144
145}
146
147#endif // RegExpMatchesArray_h