]> git.saurik.com Git - apple/javascriptcore.git/blame - runtime/RegExpObject.h
JavaScriptCore-1097.3.3.tar.gz
[apple/javascriptcore.git] / runtime / RegExpObject.h
CommitLineData
9dae56ea
A
1/*
2 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
6fe7ccc8 3 * Copyright (C) 2003, 2007, 2008, 2012 Apple Inc. All Rights Reserved.
9dae56ea
A
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
6fe7ccc8 24#include "JSObject.h"
9dae56ea
A
25#include "RegExp.h"
26
27namespace JSC {
14957cd0 28
6fe7ccc8 29 class RegExpObject : public JSNonFinalObject {
9dae56ea 30 public:
6fe7ccc8 31 typedef JSNonFinalObject Base;
14957cd0 32
6fe7ccc8
A
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 }
9dae56ea 46
6fe7ccc8
A
47 void setRegExp(JSGlobalData& globalData, RegExp* r) { m_regExp.set(globalData, this, r); }
48 RegExp* regExp() const { return m_regExp.get(); }
9dae56ea 49
6fe7ccc8 50 void setLastIndex(ExecState* exec, size_t lastIndex)
14957cd0 51 {
6fe7ccc8
A
52 m_lastIndex.setWithoutWriteBarrier(jsNumber(lastIndex));
53 if (LIKELY(m_lastIndexIsWritable))
54 m_lastIndex.setWithoutWriteBarrier(jsNumber(lastIndex));
55 else
56 throwTypeError(exec, StrictModeReadonlyPropertyWriteError);
14957cd0 57 }
6fe7ccc8 58 void setLastIndex(ExecState* exec, JSValue lastIndex, bool shouldThrow)
14957cd0 59 {
6fe7ccc8
A
60 if (LIKELY(m_lastIndexIsWritable))
61 m_lastIndex.set(exec->globalData(), this, lastIndex);
62 else if (shouldThrow)
63 throwTypeError(exec, StrictModeReadonlyPropertyWriteError);
14957cd0
A
64 }
65 JSValue getLastIndex() const
66 {
6fe7ccc8 67 return m_lastIndex.get();
14957cd0 68 }
9dae56ea 69
6fe7ccc8
A
70 bool test(ExecState* exec, JSString* string) { return match(exec, string); }
71 JSValue exec(ExecState*, JSString*);
9dae56ea 72
6fe7ccc8
A
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&);
9dae56ea 76
14957cd0 77 static JS_EXPORTDATA const ClassInfo s_info;
9dae56ea 78
6fe7ccc8 79 static Structure* createStructure(JSGlobalData& globalData, JSGlobalObject* globalObject, JSValue prototype)
9dae56ea 80 {
6fe7ccc8 81 return Structure::create(globalData, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), &s_info);
9dae56ea
A
82 }
83
f9bf01c6 84 protected:
6fe7ccc8
A
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);
f9bf01c6 96
9dae56ea 97 private:
6fe7ccc8
A
98 MatchResult match(ExecState*, JSString*);
99
100 WriteBarrier<RegExp> m_regExp;
101 WriteBarrier<Unknown> m_lastIndex;
102 bool m_lastIndexIsWritable;
9dae56ea
A
103 };
104
ba379fdc 105 RegExpObject* asRegExpObject(JSValue);
9dae56ea 106
ba379fdc 107 inline RegExpObject* asRegExpObject(JSValue value)
9dae56ea 108 {
14957cd0 109 ASSERT(asObject(value)->inherits(&RegExpObject::s_info));
9dae56ea
A
110 return static_cast<RegExpObject*>(asObject(value));
111 }
112
113} // namespace JSC
114
115#endif // RegExpObject_h