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(VM
&, Butterfly
*, JSGlobalObject
*, JSString
*, RegExp
*, MatchResult
); 
  33         enum ReifiedState 
{ ReifiedNone
, ReifiedMatch
, ReifiedAll 
}; 
  38         static RegExpMatchesArray
* create(ExecState
*, JSString
*, RegExp
*, MatchResult
); 
  40         JSString
* leftContext(ExecState
*); 
  41         JSString
* rightContext(ExecState
*); 
  43         static const ClassInfo s_info
; 
  45         static Structure
* createStructure(VM
& vm
, JSGlobalObject
* globalObject
, JSValue prototype
) 
  47             return Structure::create(vm
, globalObject
, prototype
, TypeInfo(ObjectType
, StructureFlags
), &s_info
, ArrayWithArrayStorage
); 
  50         static void visitChildren(JSCell
*, SlotVisitor
&); 
  53         void finishCreation(VM
&); 
  55         static const unsigned StructureFlags 
= OverridesGetOwnPropertySlot 
| OverridesVisitChildren 
| OverridesGetPropertyNames 
| Base::StructureFlags
; 
  58         ALWAYS_INLINE 
void reifyAllPropertiesIfNecessary(ExecState
* exec
) 
  60             if (m_state 
!= ReifiedAll
) 
  61                 reifyAllProperties(exec
); 
  64         ALWAYS_INLINE 
void reifyMatchPropertyIfNecessary(ExecState
* exec
) 
  66             if (m_state 
== ReifiedNone
) 
  67                 reifyMatchProperty(exec
); 
  70         static bool getOwnPropertySlot(JSCell
* cell
, ExecState
* exec
, PropertyName propertyName
, PropertySlot
& slot
) 
  72             RegExpMatchesArray
* thisObject 
= jsCast
<RegExpMatchesArray
*>(cell
); 
  73             thisObject
->reifyAllPropertiesIfNecessary(exec
); 
  74             return JSArray::getOwnPropertySlot(thisObject
, exec
, propertyName
, slot
); 
  77         static bool getOwnPropertySlotByIndex(JSCell
* cell
, ExecState
* exec
, unsigned propertyName
, PropertySlot
& slot
) 
  79             RegExpMatchesArray
* thisObject 
= jsCast
<RegExpMatchesArray
*>(cell
); 
  81                 thisObject
->reifyAllPropertiesIfNecessary(exec
); 
  83                 thisObject
->reifyMatchPropertyIfNecessary(exec
); 
  84             return JSArray::getOwnPropertySlotByIndex(thisObject
, exec
, propertyName
, slot
); 
  87         static bool getOwnPropertyDescriptor(JSObject
* object
, ExecState
* exec
, PropertyName propertyName
, PropertyDescriptor
& descriptor
) 
  89             RegExpMatchesArray
* thisObject 
= jsCast
<RegExpMatchesArray
*>(object
); 
  90             thisObject
->reifyAllPropertiesIfNecessary(exec
); 
  91             return JSArray::getOwnPropertyDescriptor(thisObject
, exec
, propertyName
, descriptor
); 
  94         static void put(JSCell
* cell
, ExecState
* exec
, PropertyName propertyName
, JSValue v
, PutPropertySlot
& slot
) 
  96             RegExpMatchesArray
* thisObject 
= jsCast
<RegExpMatchesArray
*>(cell
); 
  97             thisObject
->reifyAllPropertiesIfNecessary(exec
); 
  98             JSArray::put(thisObject
, exec
, propertyName
, v
, slot
); 
 101         static void putByIndex(JSCell
* cell
, ExecState
* exec
, unsigned propertyName
, JSValue v
, bool shouldThrow
) 
 103             RegExpMatchesArray
* thisObject 
= jsCast
<RegExpMatchesArray
*>(cell
); 
 104             thisObject
->reifyAllPropertiesIfNecessary(exec
); 
 105             JSArray::putByIndex(thisObject
, exec
, propertyName
, v
, shouldThrow
); 
 108         static bool deleteProperty(JSCell
* cell
, ExecState
* exec
, PropertyName propertyName
) 
 110             RegExpMatchesArray
* thisObject 
= jsCast
<RegExpMatchesArray
*>(cell
); 
 111             thisObject
->reifyAllPropertiesIfNecessary(exec
); 
 112             return JSArray::deleteProperty(thisObject
, exec
, propertyName
); 
 115         static bool deletePropertyByIndex(JSCell
* cell
, ExecState
* exec
, unsigned propertyName
) 
 117             RegExpMatchesArray
* thisObject 
= jsCast
<RegExpMatchesArray
*>(cell
); 
 118             thisObject
->reifyAllPropertiesIfNecessary(exec
); 
 119             return JSArray::deletePropertyByIndex(thisObject
, exec
, propertyName
); 
 122         static void getOwnPropertyNames(JSObject
* object
, ExecState
* exec
, PropertyNameArray
& arr
, EnumerationMode mode 
= ExcludeDontEnumProperties
) 
 124             RegExpMatchesArray
* thisObject 
= jsCast
<RegExpMatchesArray
*>(object
); 
 125             thisObject
->reifyAllPropertiesIfNecessary(exec
); 
 126             JSArray::getOwnPropertyNames(thisObject
, exec
, arr
, mode
); 
 129         static bool defineOwnProperty(JSObject
* object
, ExecState
* exec
, PropertyName propertyName
, PropertyDescriptor
& descriptor
, bool shouldThrow
) 
 131             RegExpMatchesArray
* thisObject 
= jsCast
<RegExpMatchesArray
*>(object
); 
 132             thisObject
->reifyAllPropertiesIfNecessary(exec
); 
 133             return JSArray::defineOwnProperty(object
, exec
, propertyName
, descriptor
, shouldThrow
); 
 136         void reifyAllProperties(ExecState
*); 
 137         void reifyMatchProperty(ExecState
*); 
 139         WriteBarrier
<JSString
> m_input
; 
 140         WriteBarrier
<RegExp
> m_regExp
; 
 141         MatchResult m_result
; 
 142         ReifiedState m_state
; 
 147 #endif // RegExpMatchesArray_h