]>
git.saurik.com Git - apple/javascriptcore.git/blob - runtime/RegExpObject.cpp
42bfceffbc9c705ed0caae23be2e0c42c73c27eb
2 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
3 * Copyright (C) 2003, 2007, 2008 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
22 #include "RegExpObject.h"
26 #include "JSGlobalObject.h"
28 #include "RegExpConstructor.h"
29 #include "RegExpPrototype.h"
33 static JSValue
regExpObjectGlobal(ExecState
*, const Identifier
&, const PropertySlot
&);
34 static JSValue
regExpObjectIgnoreCase(ExecState
*, const Identifier
&, const PropertySlot
&);
35 static JSValue
regExpObjectMultiline(ExecState
*, const Identifier
&, const PropertySlot
&);
36 static JSValue
regExpObjectSource(ExecState
*, const Identifier
&, const PropertySlot
&);
37 static JSValue
regExpObjectLastIndex(ExecState
*, const Identifier
&, const PropertySlot
&);
38 static void setRegExpObjectLastIndex(ExecState
*, JSObject
*, JSValue
);
42 #include "RegExpObject.lut.h"
46 ASSERT_CLASS_FITS_IN_CELL(RegExpObject
);
48 const ClassInfo
RegExpObject::info
= { "RegExp", 0, 0, ExecState::regExpTable
};
50 /* Source for RegExpObject.lut.h
52 global regExpObjectGlobal DontDelete|ReadOnly|DontEnum
53 ignoreCase regExpObjectIgnoreCase DontDelete|ReadOnly|DontEnum
54 multiline regExpObjectMultiline DontDelete|ReadOnly|DontEnum
55 source regExpObjectSource DontDelete|ReadOnly|DontEnum
56 lastIndex regExpObjectLastIndex DontDelete|DontEnum
60 RegExpObject::RegExpObject(NonNullPassRefPtr
<Structure
> structure
, NonNullPassRefPtr
<RegExp
> regExp
)
62 , d(new RegExpObjectData(regExp
, 0))
66 RegExpObject::~RegExpObject()
70 bool RegExpObject::getOwnPropertySlot(ExecState
* exec
, const Identifier
& propertyName
, PropertySlot
& slot
)
72 return getStaticValueSlot
<RegExpObject
, JSObject
>(exec
, ExecState::regExpTable(exec
), this, propertyName
, slot
);
75 bool RegExpObject::getOwnPropertyDescriptor(ExecState
* exec
, const Identifier
& propertyName
, PropertyDescriptor
& descriptor
)
77 return getStaticValueDescriptor
<RegExpObject
, JSObject
>(exec
, ExecState::regExpTable(exec
), this, propertyName
, descriptor
);
80 JSValue
regExpObjectGlobal(ExecState
*, const Identifier
&, const PropertySlot
& slot
)
82 return jsBoolean(asRegExpObject(slot
.slotBase())->regExp()->global());
85 JSValue
regExpObjectIgnoreCase(ExecState
*, const Identifier
&, const PropertySlot
& slot
)
87 return jsBoolean(asRegExpObject(slot
.slotBase())->regExp()->ignoreCase());
90 JSValue
regExpObjectMultiline(ExecState
*, const Identifier
&, const PropertySlot
& slot
)
92 return jsBoolean(asRegExpObject(slot
.slotBase())->regExp()->multiline());
95 JSValue
regExpObjectSource(ExecState
* exec
, const Identifier
&, const PropertySlot
& slot
)
97 return jsString(exec
, asRegExpObject(slot
.slotBase())->regExp()->pattern());
100 JSValue
regExpObjectLastIndex(ExecState
* exec
, const Identifier
&, const PropertySlot
& slot
)
102 return jsNumber(exec
, asRegExpObject(slot
.slotBase())->lastIndex());
105 void RegExpObject::put(ExecState
* exec
, const Identifier
& propertyName
, JSValue value
, PutPropertySlot
& slot
)
107 lookupPut
<RegExpObject
, JSObject
>(exec
, propertyName
, value
, ExecState::regExpTable(exec
), this, slot
);
110 void setRegExpObjectLastIndex(ExecState
* exec
, JSObject
* baseObject
, JSValue value
)
112 asRegExpObject(baseObject
)->setLastIndex(value
.toInteger(exec
));
115 JSValue
RegExpObject::test(ExecState
* exec
, const ArgList
& args
)
117 return jsBoolean(match(exec
, args
));
120 JSValue
RegExpObject::exec(ExecState
* exec
, const ArgList
& args
)
122 if (match(exec
, args
))
123 return exec
->lexicalGlobalObject()->regExpConstructor()->arrayOfMatches(exec
);
127 static JSValue JSC_HOST_CALL
callRegExpObject(ExecState
* exec
, JSObject
* function
, JSValue
, const ArgList
& args
)
129 return asRegExpObject(function
)->exec(exec
, args
);
132 CallType
RegExpObject::getCallData(CallData
& callData
)
134 callData
.native
.function
= callRegExpObject
;
138 // Shared implementation used by test and exec.
139 bool RegExpObject::match(ExecState
* exec
, const ArgList
& args
)
141 RegExpConstructor
* regExpConstructor
= exec
->lexicalGlobalObject()->regExpConstructor();
143 UString input
= args
.isEmpty() ? regExpConstructor
->input() : args
.at(0).toString(exec
);
144 if (input
.isNull()) {
145 throwError(exec
, GeneralError
, makeString("No input to ", toString(exec
), "."));
149 if (!regExp()->global()) {
152 regExpConstructor
->performMatch(d
->regExp
.get(), input
, 0, position
, length
);
153 return position
>= 0;
156 if (d
->lastIndex
< 0 || d
->lastIndex
> input
.size()) {
163 regExpConstructor
->performMatch(d
->regExp
.get(), input
, static_cast<int>(d
->lastIndex
), position
, length
);
169 d
->lastIndex
= position
+ length
;