initial import
[vuplus_webkit] / Source / JavaScriptCore / runtime / RegExpObject.h
1 /*
2  *  Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
3  *  Copyright (C) 2003, 2007, 2008 Apple Inc. All Rights Reserved.
4  *
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.
9  *
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.
14  *
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
18  *
19  */
20
21 #ifndef RegExpObject_h
22 #define RegExpObject_h
23
24 #include "JSObject.h"
25 #include "RegExp.h"
26
27 namespace JSC {
28     
29     class RegExpObject : public JSNonFinalObject {
30     public:
31         typedef JSNonFinalObject Base;
32
33         static RegExpObject* create(ExecState* exec, JSGlobalObject* globalObject, Structure* structure, RegExp* regExp)
34         {
35             RegExpObject* object = new (allocateCell<RegExpObject>(*exec->heap())) RegExpObject(globalObject, structure, regExp);
36             object->finishCreation(globalObject);
37             return object;
38         }
39         
40         static RegExpObject* create(JSGlobalData& globalData, JSGlobalObject* globalObject, Structure* structure, RegExp* regExp)
41         {
42             RegExpObject* object = new (allocateCell<RegExpObject>(globalData.heap)) RegExpObject(globalObject, structure, regExp);
43             object->finishCreation(globalObject);
44             return object;
45         }
46
47         virtual ~RegExpObject();
48
49         void setRegExp(JSGlobalData& globalData, RegExp* r) { d->regExp.set(globalData, this, r); }
50         RegExp* regExp() const { return d->regExp.get(); }
51
52         void setLastIndex(size_t lastIndex)
53         {
54             d->lastIndex.setWithoutWriteBarrier(jsNumber(lastIndex));
55         }
56         void setLastIndex(JSGlobalData& globalData, JSValue lastIndex)
57         {
58             d->lastIndex.set(globalData, this, lastIndex);
59         }
60         JSValue getLastIndex() const
61         {
62             return d->lastIndex.get();
63         }
64
65         JSValue test(ExecState*);
66         JSValue exec(ExecState*);
67
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&);
71
72         static JS_EXPORTDATA const ClassInfo s_info;
73
74         static Structure* createStructure(JSGlobalData& globalData, JSGlobalObject* globalObject, JSValue prototype)
75         {
76             return Structure::create(globalData, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), &s_info);
77         }
78
79     protected:
80         RegExpObject(JSGlobalObject*, Structure*, RegExp*);
81         void finishCreation(JSGlobalObject*);
82         static const unsigned StructureFlags = OverridesVisitChildren | OverridesGetOwnPropertySlot | Base::StructureFlags;
83
84     private:
85         virtual void visitChildren(SlotVisitor&);
86
87         bool match(ExecState*);
88
89         struct RegExpObjectData {
90             WTF_MAKE_FAST_ALLOCATED;
91         public:
92             RegExpObjectData(JSGlobalData& globalData, RegExpObject* owner, RegExp* regExp)
93                 : regExp(globalData, owner, regExp)
94             {
95                 lastIndex.setWithoutWriteBarrier(jsNumber(0));
96             }
97
98             WriteBarrier<RegExp> regExp;
99             WriteBarrier<Unknown> lastIndex;
100         };
101 #if COMPILER(MSVC)
102         friend void WTF::deleteOwnedPtr<RegExpObjectData>(RegExpObjectData*);
103 #endif
104         OwnPtr<RegExpObjectData> d;
105     };
106
107     RegExpObject* asRegExpObject(JSValue);
108
109     inline RegExpObject* asRegExpObject(JSValue value)
110     {
111         ASSERT(asObject(value)->inherits(&RegExpObject::s_info));
112         return static_cast<RegExpObject*>(asObject(value));
113     }
114
115 } // namespace JSC
116
117 #endif // RegExpObject_h