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