]> git.saurik.com Git - apple/javascriptcore.git/blob - runtime/RegExpObject.h
JavaScriptCore-1097.13.tar.gz
[apple/javascriptcore.git] / runtime / RegExpObject.h
1 /*
2 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
3 * Copyright (C) 2003, 2007, 2008, 2012 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 (NotNull, 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 (NotNull, allocateCell<RegExpObject>(globalData.heap)) RegExpObject(globalObject, structure, regExp);
43 object->finishCreation(globalObject);
44 return object;
45 }
46
47 void setRegExp(JSGlobalData& globalData, RegExp* r) { m_regExp.set(globalData, this, r); }
48 RegExp* regExp() const { return m_regExp.get(); }
49
50 void setLastIndex(ExecState* exec, size_t lastIndex)
51 {
52 m_lastIndex.setWithoutWriteBarrier(jsNumber(lastIndex));
53 if (LIKELY(m_lastIndexIsWritable))
54 m_lastIndex.setWithoutWriteBarrier(jsNumber(lastIndex));
55 else
56 throwTypeError(exec, StrictModeReadonlyPropertyWriteError);
57 }
58 void setLastIndex(ExecState* exec, JSValue lastIndex, bool shouldThrow)
59 {
60 if (LIKELY(m_lastIndexIsWritable))
61 m_lastIndex.set(exec->globalData(), this, lastIndex);
62 else if (shouldThrow)
63 throwTypeError(exec, StrictModeReadonlyPropertyWriteError);
64 }
65 JSValue getLastIndex() const
66 {
67 return m_lastIndex.get();
68 }
69
70 bool test(ExecState* exec, JSString* string) { return match(exec, string); }
71 JSValue exec(ExecState*, JSString*);
72
73 static bool getOwnPropertySlot(JSCell*, ExecState*, const Identifier& propertyName, PropertySlot&);
74 static bool getOwnPropertyDescriptor(JSObject*, ExecState*, const Identifier&, PropertyDescriptor&);
75 static void put(JSCell*, ExecState*, const Identifier& propertyName, JSValue, PutPropertySlot&);
76
77 static JS_EXPORTDATA const ClassInfo s_info;
78
79 static Structure* createStructure(JSGlobalData& globalData, JSGlobalObject* globalObject, JSValue prototype)
80 {
81 return Structure::create(globalData, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), &s_info);
82 }
83
84 protected:
85 JS_EXPORT_PRIVATE RegExpObject(JSGlobalObject*, Structure*, RegExp*);
86 JS_EXPORT_PRIVATE void finishCreation(JSGlobalObject*);
87
88 static const unsigned StructureFlags = OverridesVisitChildren | OverridesGetOwnPropertySlot | Base::StructureFlags;
89
90 static void visitChildren(JSCell*, SlotVisitor&);
91
92 JS_EXPORT_PRIVATE static bool deleteProperty(JSCell*, ExecState*, const Identifier& propertyName);
93 JS_EXPORT_PRIVATE static void getOwnPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode);
94 JS_EXPORT_PRIVATE static void getPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode);
95 JS_EXPORT_PRIVATE static bool defineOwnProperty(JSObject*, ExecState*, const Identifier& propertyName, PropertyDescriptor&, bool shouldThrow);
96
97 private:
98 MatchResult match(ExecState*, JSString*);
99
100 WriteBarrier<RegExp> m_regExp;
101 WriteBarrier<Unknown> m_lastIndex;
102 bool m_lastIndexIsWritable;
103 };
104
105 RegExpObject* asRegExpObject(JSValue);
106
107 inline RegExpObject* asRegExpObject(JSValue value)
108 {
109 ASSERT(asObject(value)->inherits(&RegExpObject::s_info));
110 return static_cast<RegExpObject*>(asObject(value));
111 }
112
113 } // namespace JSC
114
115 #endif // RegExpObject_h