]> git.saurik.com Git - apple/javascriptcore.git/blame_incremental - runtime/RegExpObject.h
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / runtime / RegExpObject.h
... / ...
CommitLineData
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
27namespace JSC {
28
29class RegExpObject : public JSNonFinalObject {
30public:
31 typedef JSNonFinalObject Base;
32 static const unsigned StructureFlags = Base::StructureFlags | OverridesGetOwnPropertySlot | OverridesGetPropertyNames;
33
34 static RegExpObject* create(VM& vm, Structure* structure, RegExp* regExp)
35 {
36 RegExpObject* object = new (NotNull, allocateCell<RegExpObject>(vm.heap)) RegExpObject(vm, structure, regExp);
37 object->finishCreation(vm);
38 return object;
39 }
40
41 void setRegExp(VM& vm, RegExp* r) { m_regExp.set(vm, this, r); }
42 RegExp* regExp() const { return m_regExp.get(); }
43
44 void setLastIndex(ExecState* exec, size_t lastIndex)
45 {
46 m_lastIndex.setWithoutWriteBarrier(jsNumber(lastIndex));
47 if (LIKELY(m_lastIndexIsWritable))
48 m_lastIndex.setWithoutWriteBarrier(jsNumber(lastIndex));
49 else
50 throwTypeError(exec, StrictModeReadonlyPropertyWriteError);
51 }
52 void setLastIndex(ExecState* exec, JSValue lastIndex, bool shouldThrow)
53 {
54 if (LIKELY(m_lastIndexIsWritable))
55 m_lastIndex.set(exec->vm(), this, lastIndex);
56 else if (shouldThrow)
57 throwTypeError(exec, StrictModeReadonlyPropertyWriteError);
58 }
59 JSValue getLastIndex() const
60 {
61 return m_lastIndex.get();
62 }
63
64 bool test(ExecState* exec, JSString* string) { return match(exec, string); }
65 JSValue exec(ExecState*, JSString*);
66
67 static bool getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&);
68 static void put(JSCell*, ExecState*, PropertyName, JSValue, PutPropertySlot&);
69
70 DECLARE_EXPORT_INFO;
71
72 static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
73 {
74 return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
75 }
76
77protected:
78 JS_EXPORT_PRIVATE RegExpObject(VM&, Structure*, RegExp*);
79 JS_EXPORT_PRIVATE void finishCreation(VM&);
80
81 static void visitChildren(JSCell*, SlotVisitor&);
82
83 JS_EXPORT_PRIVATE static bool deleteProperty(JSCell*, ExecState*, PropertyName);
84 JS_EXPORT_PRIVATE static void getOwnNonIndexPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode);
85 JS_EXPORT_PRIVATE static void getPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode);
86 JS_EXPORT_PRIVATE static void getGenericPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode);
87 JS_EXPORT_PRIVATE static bool defineOwnProperty(JSObject*, ExecState*, PropertyName, const PropertyDescriptor&, bool shouldThrow);
88
89private:
90 MatchResult match(ExecState*, JSString*);
91
92 WriteBarrier<RegExp> m_regExp;
93 WriteBarrier<Unknown> m_lastIndex;
94 bool m_lastIndexIsWritable;
95};
96
97RegExpObject* asRegExpObject(JSValue);
98
99inline RegExpObject* asRegExpObject(JSValue value)
100{
101 ASSERT(asObject(value)->inherits(RegExpObject::info()));
102 return static_cast<RegExpObject*>(asObject(value));
103}
104
105} // namespace JSC
106
107#endif // RegExpObject_h