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
29 class RegExpObject : public JSNonFinalObject {
31 typedef JSNonFinalObject Base;
33 static RegExpObject* create(ExecState* exec, JSGlobalObject* globalObject, Structure* structure, RegExp* regExp)
35 RegExpObject* object = new (allocateCell<RegExpObject>(*exec->heap())) RegExpObject(globalObject, structure, regExp);
36 object->finishCreation(globalObject);
40 static RegExpObject* create(JSGlobalData& globalData, JSGlobalObject* globalObject, Structure* structure, RegExp* regExp)
42 RegExpObject* object = new (allocateCell<RegExpObject>(globalData.heap)) RegExpObject(globalObject, structure, regExp);
43 object->finishCreation(globalObject);
47 virtual ~RegExpObject();
49 void setRegExp(JSGlobalData& globalData, RegExp* r) { d->regExp.set(globalData, this, r); }
50 RegExp* regExp() const { return d->regExp.get(); }
52 void setLastIndex(size_t lastIndex)
54 d->lastIndex.setWithoutWriteBarrier(jsNumber(lastIndex));
56 void setLastIndex(JSGlobalData& globalData, JSValue lastIndex)
58 d->lastIndex.set(globalData, this, lastIndex);
60 JSValue getLastIndex() const
62 return d->lastIndex.get();
65 JSValue test(ExecState*);
66 JSValue exec(ExecState*);
68 virtual bool getOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
69 virtual bool getOwnPropertyDescriptor(ExecState*, const Identifier&, PropertyDescriptor&);
70 virtual void put(ExecState*, const Identifier& propertyName, JSValue, PutPropertySlot&);
72 static JS_EXPORTDATA const ClassInfo s_info;
74 static Structure* createStructure(JSGlobalData& globalData, JSGlobalObject* globalObject, JSValue prototype)
76 return Structure::create(globalData, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), &s_info);
80 RegExpObject(JSGlobalObject*, Structure*, RegExp*);
81 void finishCreation(JSGlobalObject*);
82 static const unsigned StructureFlags = OverridesVisitChildren | OverridesGetOwnPropertySlot | Base::StructureFlags;
85 virtual void visitChildren(SlotVisitor&);
87 bool match(ExecState*);
89 struct RegExpObjectData {
90 WTF_MAKE_FAST_ALLOCATED;
92 RegExpObjectData(JSGlobalData& globalData, RegExpObject* owner, RegExp* regExp)
93 : regExp(globalData, owner, regExp)
95 lastIndex.setWithoutWriteBarrier(jsNumber(0));
98 WriteBarrier<RegExp> regExp;
99 WriteBarrier<Unknown> lastIndex;
102 friend void WTF::deleteOwnedPtr<RegExpObjectData>(RegExpObjectData*);
104 OwnPtr<RegExpObjectData> d;
107 RegExpObject* asRegExpObject(JSValue);
109 inline RegExpObject* asRegExpObject(JSValue value)
111 ASSERT(asObject(value)->inherits(&RegExpObject::s_info));
112 return static_cast<RegExpObject*>(asObject(value));
117 #endif // RegExpObject_h