2 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
3 * Copyright (C) 2003, 2007, 2008 Apple Inc. All Rights Reserved.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef RegExpObject_h
22 #define RegExpObject_h
24 #include "JSObjectWithGlobalObject.h"
29 class RegExpObject
: public JSObjectWithGlobalObject
{
31 typedef JSObjectWithGlobalObject Base
;
33 RegExpObject(JSGlobalObject
*, Structure
*, RegExp
*);
34 virtual ~RegExpObject();
36 void setRegExp(JSGlobalData
& globalData
, RegExp
* r
) { d
->regExp
.set(globalData
, this, r
); }
37 RegExp
* regExp() const { return d
->regExp
.get(); }
39 void setLastIndex(size_t lastIndex
)
41 d
->lastIndex
.setWithoutWriteBarrier(jsNumber(lastIndex
));
43 void setLastIndex(JSGlobalData
& globalData
, JSValue lastIndex
)
45 d
->lastIndex
.set(globalData
, this, lastIndex
);
47 JSValue
getLastIndex() const
49 return d
->lastIndex
.get();
52 JSValue
test(ExecState
*);
53 JSValue
exec(ExecState
*);
55 virtual bool getOwnPropertySlot(ExecState
*, const Identifier
& propertyName
, PropertySlot
&);
56 virtual bool getOwnPropertyDescriptor(ExecState
*, const Identifier
&, PropertyDescriptor
&);
57 virtual void put(ExecState
*, const Identifier
& propertyName
, JSValue
, PutPropertySlot
&);
59 static JS_EXPORTDATA
const ClassInfo s_info
;
61 static Structure
* createStructure(JSGlobalData
& globalData
, JSValue prototype
)
63 return Structure::create(globalData
, prototype
, TypeInfo(ObjectType
, StructureFlags
), AnonymousSlotCount
, &s_info
);
67 static const unsigned StructureFlags
= OverridesVisitChildren
| OverridesGetOwnPropertySlot
| JSObjectWithGlobalObject::StructureFlags
;
70 virtual void visitChildren(SlotVisitor
&);
72 bool match(ExecState
*);
74 struct RegExpObjectData
{
75 WTF_MAKE_FAST_ALLOCATED
;
77 RegExpObjectData(JSGlobalData
& globalData
, RegExpObject
* owner
, RegExp
* regExp
)
78 : regExp(globalData
, owner
, regExp
)
80 lastIndex
.setWithoutWriteBarrier(jsNumber(0));
83 WriteBarrier
<RegExp
> regExp
;
84 WriteBarrier
<Unknown
> lastIndex
;
87 friend void WTF::deleteOwnedPtr
<RegExpObjectData
>(RegExpObjectData
*);
89 OwnPtr
<RegExpObjectData
> d
;
92 RegExpObject
* asRegExpObject(JSValue
);
94 inline RegExpObject
* asRegExpObject(JSValue value
)
96 ASSERT(asObject(value
)->inherits(&RegExpObject::s_info
));
97 return static_cast<RegExpObject
*>(asObject(value
));
102 #endif // RegExpObject_h