2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
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.
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.
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
20 #ifndef RegExpMatchesArray_h
21 #define RegExpMatchesArray_h
24 #include "JSGlobalObject.h"
25 #include "RegExpObject.h"
29 class RegExpMatchesArray
: public JSArray
{
31 RegExpMatchesArray(JSGlobalData
& globalData
, JSGlobalObject
* globalObject
, JSString
* input
, RegExp
* regExp
, MatchResult result
)
32 : JSArray(globalData
, globalObject
->regExpMatchesArrayStructure())
34 , m_state(ReifiedNone
)
36 m_input
.set(globalData
, this, input
);
37 m_regExp
.set(globalData
, this, regExp
);
40 enum ReifiedState
{ ReifiedNone
, ReifiedMatch
, ReifiedAll
};
45 static RegExpMatchesArray
* create(ExecState
* exec
, JSString
* input
, RegExp
* regExp
, MatchResult 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
);
54 JSString
* leftContext(ExecState
*);
55 JSString
* rightContext(ExecState
*);
57 static const ClassInfo s_info
;
59 static Structure
* createStructure(JSGlobalData
& globalData
, JSGlobalObject
* globalObject
, JSValue prototype
)
61 return Structure::create(globalData
, globalObject
, prototype
, TypeInfo(ObjectType
, StructureFlags
), &s_info
);
64 static void visitChildren(JSCell
*, SlotVisitor
&);
67 void finishCreation(JSGlobalData
&);
69 static const unsigned StructureFlags
= OverridesGetOwnPropertySlot
| OverridesVisitChildren
| OverridesGetPropertyNames
| Base::StructureFlags
;
72 ALWAYS_INLINE
void reifyAllPropertiesIfNecessary(ExecState
* exec
)
74 if (m_state
!= ReifiedAll
)
75 reifyAllProperties(exec
);
78 ALWAYS_INLINE
void reifyMatchPropertyIfNecessary(ExecState
* exec
)
80 if (m_state
== ReifiedNone
)
81 reifyMatchProperty(exec
);
84 static bool getOwnPropertySlot(JSCell
* cell
, ExecState
* exec
, const Identifier
& propertyName
, PropertySlot
& slot
)
86 RegExpMatchesArray
* thisObject
= jsCast
<RegExpMatchesArray
*>(cell
);
87 thisObject
->reifyAllPropertiesIfNecessary(exec
);
88 return JSArray::getOwnPropertySlot(thisObject
, exec
, propertyName
, slot
);
91 static bool getOwnPropertySlotByIndex(JSCell
* cell
, ExecState
* exec
, unsigned propertyName
, PropertySlot
& slot
)
93 RegExpMatchesArray
* thisObject
= jsCast
<RegExpMatchesArray
*>(cell
);
95 thisObject
->reifyAllPropertiesIfNecessary(exec
);
97 thisObject
->reifyMatchPropertyIfNecessary(exec
);
98 return JSArray::getOwnPropertySlotByIndex(thisObject
, exec
, propertyName
, slot
);
101 static bool getOwnPropertyDescriptor(JSObject
* object
, ExecState
* exec
, const Identifier
& propertyName
, PropertyDescriptor
& descriptor
)
103 RegExpMatchesArray
* thisObject
= jsCast
<RegExpMatchesArray
*>(object
);
104 thisObject
->reifyAllPropertiesIfNecessary(exec
);
105 return JSArray::getOwnPropertyDescriptor(thisObject
, exec
, propertyName
, descriptor
);
108 static void put(JSCell
* cell
, ExecState
* exec
, const Identifier
& propertyName
, JSValue v
, PutPropertySlot
& slot
)
110 RegExpMatchesArray
* thisObject
= jsCast
<RegExpMatchesArray
*>(cell
);
111 thisObject
->reifyAllPropertiesIfNecessary(exec
);
112 JSArray::put(thisObject
, exec
, propertyName
, v
, slot
);
115 static void putByIndex(JSCell
* cell
, ExecState
* exec
, unsigned propertyName
, JSValue v
, bool shouldThrow
)
117 RegExpMatchesArray
* thisObject
= jsCast
<RegExpMatchesArray
*>(cell
);
118 thisObject
->reifyAllPropertiesIfNecessary(exec
);
119 JSArray::putByIndex(thisObject
, exec
, propertyName
, v
, shouldThrow
);
122 static bool deleteProperty(JSCell
* cell
, ExecState
* exec
, const Identifier
& propertyName
)
124 RegExpMatchesArray
* thisObject
= jsCast
<RegExpMatchesArray
*>(cell
);
125 thisObject
->reifyAllPropertiesIfNecessary(exec
);
126 return JSArray::deleteProperty(thisObject
, exec
, propertyName
);
129 static bool deletePropertyByIndex(JSCell
* cell
, ExecState
* exec
, unsigned propertyName
)
131 RegExpMatchesArray
* thisObject
= jsCast
<RegExpMatchesArray
*>(cell
);
132 thisObject
->reifyAllPropertiesIfNecessary(exec
);
133 return JSArray::deletePropertyByIndex(thisObject
, exec
, propertyName
);
136 static void getOwnPropertyNames(JSObject
* object
, ExecState
* exec
, PropertyNameArray
& arr
, EnumerationMode mode
= ExcludeDontEnumProperties
)
138 RegExpMatchesArray
* thisObject
= jsCast
<RegExpMatchesArray
*>(object
);
139 thisObject
->reifyAllPropertiesIfNecessary(exec
);
140 JSArray::getOwnPropertyNames(thisObject
, exec
, arr
, mode
);
143 static bool defineOwnProperty(JSObject
* object
, ExecState
* exec
, const Identifier
& propertyName
, PropertyDescriptor
& descriptor
, bool shouldThrow
)
145 RegExpMatchesArray
* thisObject
= jsCast
<RegExpMatchesArray
*>(object
);
146 thisObject
->reifyAllPropertiesIfNecessary(exec
);
147 return JSArray::defineOwnProperty(object
, exec
, propertyName
, descriptor
, shouldThrow
);
150 void reifyAllProperties(ExecState
*);
151 void reifyMatchProperty(ExecState
*);
153 WriteBarrier
<JSString
> m_input
;
154 WriteBarrier
<RegExp
> m_regExp
;
155 MatchResult m_result
;
156 ReifiedState m_state
;
161 #endif // RegExpMatchesArray_h