RegExpConstructor.h [plain text]
#ifndef RegExpConstructor_h
#define RegExpConstructor_h
#include "InternalFunction.h"
#include "RegExp.h"
#include "RegExpCachedResult.h"
#include "RegExpObject.h"
#include <wtf/OwnPtr.h>
namespace JSC {
class RegExpPrototype;
class RegExpConstructor : public InternalFunction {
public:
typedef InternalFunction Base;
static RegExpConstructor* create(ExecState* exec, JSGlobalObject* globalObject, Structure* structure, RegExpPrototype* regExpPrototype)
{
RegExpConstructor* constructor = new (NotNull, allocateCell<RegExpConstructor>(*exec->heap())) RegExpConstructor(globalObject, structure, regExpPrototype);
constructor->finishCreation(exec, regExpPrototype);
return constructor;
}
static Structure* createStructure(JSGlobalData& globalData, JSGlobalObject* globalObject, JSValue prototype)
{
return Structure::create(globalData, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), &s_info);
}
static void put(JSCell*, ExecState*, const Identifier& propertyName, JSValue, PutPropertySlot&);
static bool getOwnPropertySlot(JSCell*, ExecState*, const Identifier& propertyName, PropertySlot&);
static bool getOwnPropertyDescriptor(JSObject*, ExecState*, const Identifier&, PropertyDescriptor&);
static const ClassInfo s_info;
MatchResult performMatch(JSGlobalData&, RegExp*, JSString*, const UString&, int startOffset, int** ovector);
MatchResult performMatch(JSGlobalData&, RegExp*, JSString*, const UString&, int startOffset);
void setMultiline(bool multiline) { m_multiline = multiline; }
bool multiline() const { return m_multiline; }
JSValue getBackref(ExecState*, unsigned);
JSValue getLastParen(ExecState*);
JSValue getLeftContext(ExecState*);
JSValue getRightContext(ExecState*);
void setInput(ExecState* exec, JSString* string) { m_cachedResult.setInput(exec, this, string); }
JSString* input() { return m_cachedResult.input(); }
static void visitChildren(JSCell*, SlotVisitor&);
protected:
void finishCreation(ExecState*, RegExpPrototype*);
static const unsigned StructureFlags = OverridesGetOwnPropertySlot | OverridesVisitChildren | Base::StructureFlags;
private:
RegExpConstructor(JSGlobalObject*, Structure*, RegExpPrototype*);
static void destroy(JSCell*);
static ConstructType getConstructData(JSCell*, ConstructData&);
static CallType getCallData(JSCell*, CallData&);
RegExpCachedResult m_cachedResult;
bool m_multiline;
Vector<int, 32> m_ovector;
};
RegExpConstructor* asRegExpConstructor(JSValue);
JSObject* constructRegExp(ExecState*, JSGlobalObject*, const ArgList&, bool callAsConstructor = false);
inline RegExpConstructor* asRegExpConstructor(JSValue value)
{
ASSERT(asObject(value)->inherits(&RegExpConstructor::s_info));
return static_cast<RegExpConstructor*>(asObject(value));
}
ALWAYS_INLINE MatchResult RegExpConstructor::performMatch(JSGlobalData& globalData, RegExp* regExp, JSString* string, const UString& input, int startOffset, int** ovector)
{
int position = regExp->match(globalData, input, startOffset, m_ovector);
if (ovector)
*ovector = m_ovector.data();
if (position == -1)
return MatchResult::failed();
ASSERT(!m_ovector.isEmpty());
ASSERT(m_ovector[0] == position);
ASSERT(m_ovector[1] >= position);
size_t end = m_ovector[1];
m_cachedResult.record(globalData, this, regExp, string, MatchResult(position, end));
return MatchResult(position, end);
}
ALWAYS_INLINE MatchResult RegExpConstructor::performMatch(JSGlobalData& globalData, RegExp* regExp, JSString* string, const UString& input, int startOffset)
{
MatchResult result = regExp->match(globalData, input, startOffset);
if (result)
m_cachedResult.record(globalData, this, regExp, string, result);
return result;
}
}
#endif // RegExpConstructor_h