2 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
3 * Copyright (C) 2003, 2007, 2008, 2012 Apple Inc. All Rights Reserved.
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.
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.
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
21 #ifndef RegExpObject_h
22 #define RegExpObject_h
29 class RegExpObject
: public JSNonFinalObject
{
31 typedef JSNonFinalObject Base
;
33 static RegExpObject
* create(VM
& vm
, Structure
* structure
, RegExp
* regExp
)
35 RegExpObject
* object
= new (NotNull
, allocateCell
<RegExpObject
>(vm
.heap
)) RegExpObject(vm
, structure
, regExp
);
36 object
->finishCreation(vm
);
40 void setRegExp(VM
& vm
, RegExp
* r
) { m_regExp
.set(vm
, this, r
); }
41 RegExp
* regExp() const { return m_regExp
.get(); }
43 void setLastIndex(ExecState
* exec
, size_t lastIndex
)
45 m_lastIndex
.setWithoutWriteBarrier(jsNumber(lastIndex
));
46 if (LIKELY(m_lastIndexIsWritable
))
47 m_lastIndex
.setWithoutWriteBarrier(jsNumber(lastIndex
));
49 throwTypeError(exec
, StrictModeReadonlyPropertyWriteError
);
51 void setLastIndex(ExecState
* exec
, JSValue lastIndex
, bool shouldThrow
)
53 if (LIKELY(m_lastIndexIsWritable
))
54 m_lastIndex
.set(exec
->vm(), this, lastIndex
);
56 throwTypeError(exec
, StrictModeReadonlyPropertyWriteError
);
58 JSValue
getLastIndex() const
60 return m_lastIndex
.get();
63 bool test(ExecState
* exec
, JSString
* string
) { return match(exec
, string
); }
64 JSValue
exec(ExecState
*, JSString
*);
66 static bool getOwnPropertySlot(JSObject
*, ExecState
*, PropertyName
, PropertySlot
&);
67 static void put(JSCell
*, ExecState
*, PropertyName
, JSValue
, PutPropertySlot
&);
71 static Structure
* createStructure(VM
& vm
, JSGlobalObject
* globalObject
, JSValue prototype
)
73 return Structure::create(vm
, globalObject
, prototype
, TypeInfo(ObjectType
, StructureFlags
), info());
77 JS_EXPORT_PRIVATE
RegExpObject(VM
&, Structure
*, RegExp
*);
78 JS_EXPORT_PRIVATE
void finishCreation(VM
&);
80 static const unsigned StructureFlags
= OverridesVisitChildren
| OverridesGetOwnPropertySlot
| Base::StructureFlags
;
82 static void visitChildren(JSCell
*, SlotVisitor
&);
84 JS_EXPORT_PRIVATE
static bool deleteProperty(JSCell
*, ExecState
*, PropertyName
);
85 JS_EXPORT_PRIVATE
static void getOwnNonIndexPropertyNames(JSObject
*, ExecState
*, PropertyNameArray
&, EnumerationMode
);
86 JS_EXPORT_PRIVATE
static void getPropertyNames(JSObject
*, ExecState
*, PropertyNameArray
&, EnumerationMode
);
87 JS_EXPORT_PRIVATE
static bool defineOwnProperty(JSObject
*, ExecState
*, PropertyName
, const PropertyDescriptor
&, bool shouldThrow
);
90 MatchResult
match(ExecState
*, JSString
*);
92 WriteBarrier
<RegExp
> m_regExp
;
93 WriteBarrier
<Unknown
> m_lastIndex
;
94 bool m_lastIndexIsWritable
;
97 RegExpObject
* asRegExpObject(JSValue
);
99 inline RegExpObject
* asRegExpObject(JSValue value
)
101 ASSERT(asObject(value
)->inherits(RegExpObject::info()));
102 return static_cast<RegExpObject
*>(asObject(value
));
107 #endif // RegExpObject_h