]> git.saurik.com Git - apple/javascriptcore.git/blame - runtime/RegExpMatchesArray.h
JavaScriptCore-7600.1.4.11.8.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
81345200 43 DECLARE_INFO;
6fe7ccc8 44
93a37866 45 static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
6fe7ccc8 46 {
81345200 47 return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), 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
81345200 70 static bool getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
9dae56ea 71 {
81345200 72 RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(object);
6fe7ccc8
A
73 thisObject->reifyAllPropertiesIfNecessary(exec);
74 return JSArray::getOwnPropertySlot(thisObject, exec, propertyName, slot);
9dae56ea
A
75 }
76
81345200 77 static bool getOwnPropertySlotByIndex(JSObject* object, ExecState* exec, unsigned propertyName, PropertySlot& slot)
f9bf01c6 78 {
81345200 79 RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(object);
6fe7ccc8
A
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 void put(JSCell* cell, ExecState* exec, PropertyName propertyName, JSValue v, PutPropertySlot& slot)
9dae56ea 88 {
6fe7ccc8
A
89 RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(cell);
90 thisObject->reifyAllPropertiesIfNecessary(exec);
91 JSArray::put(thisObject, exec, propertyName, v, slot);
92 }
93
94 static void putByIndex(JSCell* cell, ExecState* exec, unsigned propertyName, JSValue v, bool shouldThrow)
95 {
96 RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(cell);
97 thisObject->reifyAllPropertiesIfNecessary(exec);
98 JSArray::putByIndex(thisObject, exec, propertyName, v, shouldThrow);
99 }
100
93a37866 101 static bool deleteProperty(JSCell* cell, ExecState* exec, PropertyName propertyName)
6fe7ccc8
A
102 {
103 RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(cell);
104 thisObject->reifyAllPropertiesIfNecessary(exec);
105 return JSArray::deleteProperty(thisObject, exec, propertyName);
9dae56ea
A
106 }
107
6fe7ccc8 108 static bool deletePropertyByIndex(JSCell* cell, ExecState* exec, unsigned propertyName)
9dae56ea 109 {
6fe7ccc8
A
110 RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(cell);
111 thisObject->reifyAllPropertiesIfNecessary(exec);
112 return JSArray::deletePropertyByIndex(thisObject, exec, propertyName);
9dae56ea
A
113 }
114
6fe7ccc8 115 static void getOwnPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& arr, EnumerationMode mode = ExcludeDontEnumProperties)
9dae56ea 116 {
6fe7ccc8
A
117 RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(object);
118 thisObject->reifyAllPropertiesIfNecessary(exec);
119 JSArray::getOwnPropertyNames(thisObject, exec, arr, mode);
9dae56ea
A
120 }
121
81345200 122 static bool defineOwnProperty(JSObject* object, ExecState* exec, PropertyName propertyName, const PropertyDescriptor& descriptor, bool shouldThrow)
9dae56ea 123 {
6fe7ccc8
A
124 RegExpMatchesArray* thisObject = jsCast<RegExpMatchesArray*>(object);
125 thisObject->reifyAllPropertiesIfNecessary(exec);
126 return JSArray::defineOwnProperty(object, exec, propertyName, descriptor, shouldThrow);
9dae56ea
A
127 }
128
6fe7ccc8
A
129 void reifyAllProperties(ExecState*);
130 void reifyMatchProperty(ExecState*);
131
132 WriteBarrier<JSString> m_input;
133 WriteBarrier<RegExp> m_regExp;
134 MatchResult m_result;
135 ReifiedState m_state;
9dae56ea
A
136};
137
81345200
A
138inline bool isRegExpMatchesArray(JSValue value)
139{
140 return value.isCell() && value.asCell()->classInfo() == RegExpMatchesArray::info();
141}
142
9dae56ea
A
143}
144
145#endif // RegExpMatchesArray_h