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(ExecState
* exec
, JSGlobalObject
* globalObject
, Structure
* structure
, RegExp
* regExp
)
35 RegExpObject
* object
= new (NotNull
, allocateCell
<RegExpObject
>(*exec
->heap())) RegExpObject(globalObject
, structure
, regExp
);
36 object
->finishCreation(globalObject
);
40 static RegExpObject
* create(JSGlobalData
& globalData
, JSGlobalObject
* globalObject
, Structure
* structure
, RegExp
* regExp
)
42 RegExpObject
* object
= new (NotNull
, allocateCell
<RegExpObject
>(globalData
.heap
)) RegExpObject(globalObject
, structure
, regExp
);
43 object
->finishCreation(globalObject
);
47 void setRegExp(JSGlobalData
& globalData
, RegExp
* r
) { m_regExp
.set(globalData
, this, r
); }
48 RegExp
* regExp() const { return m_regExp
.get(); }
50 void setLastIndex(ExecState
* exec
, size_t lastIndex
)
52 m_lastIndex
.setWithoutWriteBarrier(jsNumber(lastIndex
));
53 if (LIKELY(m_lastIndexIsWritable
))
54 m_lastIndex
.setWithoutWriteBarrier(jsNumber(lastIndex
));
56 throwTypeError(exec
, StrictModeReadonlyPropertyWriteError
);
58 void setLastIndex(ExecState
* exec
, JSValue lastIndex
, bool shouldThrow
)
60 if (LIKELY(m_lastIndexIsWritable
))
61 m_lastIndex
.set(exec
->globalData(), this, lastIndex
);
63 throwTypeError(exec
, StrictModeReadonlyPropertyWriteError
);
65 JSValue
getLastIndex() const
67 return m_lastIndex
.get();
70 bool test(ExecState
* exec
, JSString
* string
) { return match(exec
, string
); }
71 JSValue
exec(ExecState
*, JSString
*);
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
&);
77 static JS_EXPORTDATA
const ClassInfo s_info
;
79 static Structure
* createStructure(JSGlobalData
& globalData
, JSGlobalObject
* globalObject
, JSValue prototype
)
81 return Structure::create(globalData
, globalObject
, prototype
, TypeInfo(ObjectType
, StructureFlags
), &s_info
);
85 JS_EXPORT_PRIVATE
RegExpObject(JSGlobalObject
*, Structure
*, RegExp
*);
86 JS_EXPORT_PRIVATE
void finishCreation(JSGlobalObject
*);
88 static const unsigned StructureFlags
= OverridesVisitChildren
| OverridesGetOwnPropertySlot
| Base::StructureFlags
;
90 static void visitChildren(JSCell
*, SlotVisitor
&);
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
);
98 MatchResult
match(ExecState
*, JSString
*);
100 WriteBarrier
<RegExp
> m_regExp
;
101 WriteBarrier
<Unknown
> m_lastIndex
;
102 bool m_lastIndexIsWritable
;
105 RegExpObject
* asRegExpObject(JSValue
);
107 inline RegExpObject
* asRegExpObject(JSValue value
)
109 ASSERT(asObject(value
)->inherits(&RegExpObject::s_info
));
110 return static_cast<RegExpObject
*>(asObject(value
));
115 #endif // RegExpObject_h