blob: 7c6cccde4eb96627899506471bd84f865e5b1568 [file] [log] [blame]
weinig@apple.com343e3d72008-06-29 00:09:26 +00001/*
2 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
mark.lam@apple.com5aca4992016-04-07 03:17:58 +00003 * Copyright (C) 2003, 2007-2008, 2016 Apple Inc. All Rights Reserved.
mjs@apple.com0a30b7a2009-07-04 14:21:30 +00004 * Copyright (C) 2009 Torch Mobile, Inc.
weinig@apple.com343e3d72008-06-29 00:09:26 +00005 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 */
21
22#include "config.h"
23#include "RegExpConstructor.h"
weinig@apple.com343e3d72008-06-29 00:09:26 +000024
bweinstein@apple.com6ef016b2009-08-13 22:22:50 +000025#include "Error.h"
keith_miller@apple.com8af3d8d2016-01-22 18:44:46 +000026#include "GetterSetter.h"
fpizlo@apple.comfb7eff22014-02-11 01:45:50 +000027#include "JSCInlines.h"
weinig@apple.com343e3d72008-06-29 00:09:26 +000028#include "RegExpPrototype.h"
keith_miller@apple.com8dc2c352016-01-06 18:25:01 +000029#include "StructureInlines.h"
weinig@apple.com343e3d72008-06-29 00:09:26 +000030
cwzwarich@webkit.org3f782f62008-09-08 01:28:33 +000031namespace JSC {
weinig@apple.com343e3d72008-06-29 00:09:26 +000032
utatane.tea@gmail.comd80165c2016-06-06 01:56:11 +000033static EncodedJSValue regExpConstructorInput(ExecState*, EncodedJSValue, PropertyName);
34static EncodedJSValue regExpConstructorMultiline(ExecState*, EncodedJSValue, PropertyName);
35static EncodedJSValue regExpConstructorLastMatch(ExecState*, EncodedJSValue, PropertyName);
36static EncodedJSValue regExpConstructorLastParen(ExecState*, EncodedJSValue, PropertyName);
37static EncodedJSValue regExpConstructorLeftContext(ExecState*, EncodedJSValue, PropertyName);
38static EncodedJSValue regExpConstructorRightContext(ExecState*, EncodedJSValue, PropertyName);
utatane.tea@gmail.com6b509c82016-05-24 06:24:44 +000039template<int N>
utatane.tea@gmail.comd80165c2016-06-06 01:56:11 +000040static EncodedJSValue regExpConstructorDollar(ExecState*, EncodedJSValue, PropertyName);
weinig@apple.comcaf5e3b2008-09-27 02:36:15 +000041
utatane.tea@gmail.com78b50c62016-03-11 17:28:46 +000042static bool setRegExpConstructorInput(ExecState*, EncodedJSValue, EncodedJSValue);
43static bool setRegExpConstructorMultiline(ExecState*, EncodedJSValue, EncodedJSValue);
weinig@apple.comcaf5e3b2008-09-27 02:36:15 +000044
45} // namespace JSC
46
47#include "RegExpConstructor.lut.h"
48
49namespace JSC {
50
akling@apple.com2de49b72014-07-30 22:26:22 +000051const ClassInfo RegExpConstructor::s_info = { "Function", &InternalFunction::s_info, &regExpConstructorTable, CREATE_METHOD_TABLE(RegExpConstructor) };
weinig@apple.com343e3d72008-06-29 00:09:26 +000052
53/* Source for RegExpConstructor.lut.h
54@begin regExpConstructorTable
weinig@apple.comcaf5e3b2008-09-27 02:36:15 +000055 input regExpConstructorInput None
56 $_ regExpConstructorInput DontEnum
57 multiline regExpConstructorMultiline None
58 $* regExpConstructorMultiline DontEnum
59 lastMatch regExpConstructorLastMatch DontDelete|ReadOnly
60 $& regExpConstructorLastMatch DontDelete|ReadOnly|DontEnum
61 lastParen regExpConstructorLastParen DontDelete|ReadOnly
62 $+ regExpConstructorLastParen DontDelete|ReadOnly|DontEnum
63 leftContext regExpConstructorLeftContext DontDelete|ReadOnly
64 $` regExpConstructorLeftContext DontDelete|ReadOnly|DontEnum
65 rightContext regExpConstructorRightContext DontDelete|ReadOnly
66 $' regExpConstructorRightContext DontDelete|ReadOnly|DontEnum
utatane.tea@gmail.com6b509c82016-05-24 06:24:44 +000067 $1 regExpConstructorDollar<1> DontDelete|ReadOnly
68 $2 regExpConstructorDollar<2> DontDelete|ReadOnly
69 $3 regExpConstructorDollar<3> DontDelete|ReadOnly
70 $4 regExpConstructorDollar<4> DontDelete|ReadOnly
71 $5 regExpConstructorDollar<5> DontDelete|ReadOnly
72 $6 regExpConstructorDollar<6> DontDelete|ReadOnly
73 $7 regExpConstructorDollar<7> DontDelete|ReadOnly
74 $8 regExpConstructorDollar<8> DontDelete|ReadOnly
75 $9 regExpConstructorDollar<9> DontDelete|ReadOnly
weinig@apple.com343e3d72008-06-29 00:09:26 +000076@end
77*/
78
akling@apple.com59875522013-09-30 03:45:30 +000079RegExpConstructor::RegExpConstructor(VM& vm, Structure* structure, RegExpPrototype* regExpPrototype)
80 : InternalFunction(vm, structure)
mark.lam@apple.comff5f4f32016-03-18 23:14:34 +000081 , m_cachedResult(vm, this, regExpPrototype->emptyRegExp())
barraclough@apple.com0a0af1a2012-03-23 19:57:28 +000082 , m_multiline(false)
weinig@apple.com343e3d72008-06-29 00:09:26 +000083{
mhahnenberg@apple.com7317a7f2011-09-09 21:43:14 +000084}
85
keith_miller@apple.com8af3d8d2016-01-22 18:44:46 +000086void RegExpConstructor::finishCreation(VM& vm, RegExpPrototype* regExpPrototype, GetterSetter* speciesSymbol)
mhahnenberg@apple.com7317a7f2011-09-09 21:43:14 +000087{
mark.lam@apple.comff5f4f32016-03-18 23:14:34 +000088 Base::finishCreation(vm, ASCIILiteral("RegExp"));
fpizlo@apple.com10ae2d02013-08-14 02:41:47 +000089 ASSERT(inherits(info()));
barraclough@apple.com737a1582011-02-21 19:31:42 +000090
commit-queue@webkit.org5fb80322014-04-15 17:46:42 +000091 putDirectWithoutTransition(vm, vm.propertyNames->prototype, regExpPrototype, DontEnum | DontDelete | ReadOnly);
weinig@apple.com343e3d72008-06-29 00:09:26 +000092
weinig@apple.com2947a912008-07-07 02:49:29 +000093 // no. of arguments for constructor
akling@apple.com22558062013-09-26 21:43:49 +000094 putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(2), ReadOnly | DontDelete | DontEnum);
keith_miller@apple.com8af3d8d2016-01-22 18:44:46 +000095
keith_miller@apple.com73c6d4b2016-02-11 04:06:37 +000096 putDirectNonIndexAccessor(vm, vm.propertyNames->speciesSymbol, speciesSymbol, Accessor | ReadOnly | DontEnum);
weinig@apple.com343e3d72008-06-29 00:09:26 +000097}
98
mhahnenberg@apple.comc58d54d2011-12-16 19:06:44 +000099void RegExpConstructor::destroy(JSCell* cell)
100{
ggaren@apple.com72da8112012-05-26 22:40:46 +0000101 static_cast<RegExpConstructor*>(cell)->RegExpConstructor::~RegExpConstructor();
mhahnenberg@apple.comc58d54d2011-12-16 19:06:44 +0000102}
103
barraclough@apple.com0a0af1a2012-03-23 19:57:28 +0000104void RegExpConstructor::visitChildren(JSCell* cell, SlotVisitor& visitor)
weinig@apple.com343e3d72008-06-29 00:09:26 +0000105{
barraclough@apple.com0a0af1a2012-03-23 19:57:28 +0000106 RegExpConstructor* thisObject = jsCast<RegExpConstructor*>(cell);
fpizlo@apple.com10ae2d02013-08-14 02:41:47 +0000107 ASSERT_GC_OBJECT_INHERITS(thisObject, info());
barraclough@apple.com0a0af1a2012-03-23 19:57:28 +0000108 Base::visitChildren(thisObject, visitor);
109 thisObject->m_cachedResult.visitChildren(visitor);
commit-queue@webkit.org6e5671b2011-09-01 23:49:23 +0000110}
111
barraclough@apple.com0a0af1a2012-03-23 19:57:28 +0000112JSValue RegExpConstructor::getBackref(ExecState* exec, unsigned i)
commit-queue@webkit.org6e5671b2011-09-01 23:49:23 +0000113{
akling@apple.comc98b79c2014-10-30 03:54:23 +0000114 JSArray* array = m_cachedResult.lastResult(exec, this);
weinig@apple.com343e3d72008-06-29 00:09:26 +0000115
barraclough@apple.com0a0af1a2012-03-23 19:57:28 +0000116 if (i < array->length()) {
117 JSValue result = JSValue(array).get(exec, i);
118 ASSERT(result.isString() || result.isUndefined());
119 if (!result.isUndefined())
120 return result;
darin@apple.come7945852008-08-31 06:58:07 +0000121 }
122 return jsEmptyString(exec);
weinig@apple.com343e3d72008-06-29 00:09:26 +0000123}
124
barraclough@apple.com0a0af1a2012-03-23 19:57:28 +0000125JSValue RegExpConstructor::getLastParen(ExecState* exec)
weinig@apple.com343e3d72008-06-29 00:09:26 +0000126{
akling@apple.comc98b79c2014-10-30 03:54:23 +0000127 JSArray* array = m_cachedResult.lastResult(exec, this);
barraclough@apple.com0a0af1a2012-03-23 19:57:28 +0000128 unsigned length = array->length();
129 if (length > 1) {
130 JSValue result = JSValue(array).get(exec, length - 1);
131 ASSERT(result.isString() || result.isUndefined());
132 if (!result.isUndefined())
133 return result;
weinig@apple.com2947a912008-07-07 02:49:29 +0000134 }
darin@apple.come7945852008-08-31 06:58:07 +0000135 return jsEmptyString(exec);
weinig@apple.com343e3d72008-06-29 00:09:26 +0000136}
137
barraclough@apple.com0a0af1a2012-03-23 19:57:28 +0000138JSValue RegExpConstructor::getLeftContext(ExecState* exec)
weinig@apple.com343e3d72008-06-29 00:09:26 +0000139{
akling@apple.comc98b79c2014-10-30 03:54:23 +0000140 return m_cachedResult.leftContext(exec, this);
weinig@apple.com343e3d72008-06-29 00:09:26 +0000141}
142
barraclough@apple.com0a0af1a2012-03-23 19:57:28 +0000143JSValue RegExpConstructor::getRightContext(ExecState* exec)
weinig@apple.com343e3d72008-06-29 00:09:26 +0000144{
akling@apple.comc98b79c2014-10-30 03:54:23 +0000145 return m_cachedResult.rightContext(exec, this);
weinig@apple.com343e3d72008-06-29 00:09:26 +0000146}
utatane.tea@gmail.com6b509c82016-05-24 06:24:44 +0000147
148template<int N>
utatane.tea@gmail.comd80165c2016-06-06 01:56:11 +0000149EncodedJSValue regExpConstructorDollar(ExecState* exec, EncodedJSValue thisValue, PropertyName)
oliver@apple.comae0687b2013-12-06 03:03:24 +0000150{
utatane.tea@gmail.com6b509c82016-05-24 06:24:44 +0000151 return JSValue::encode(asRegExpConstructor(JSValue::decode(thisValue))->getBackref(exec, N));
weinig@apple.comcaf5e3b2008-09-27 02:36:15 +0000152}
weinig@apple.com343e3d72008-06-29 00:09:26 +0000153
utatane.tea@gmail.comd80165c2016-06-06 01:56:11 +0000154EncodedJSValue regExpConstructorInput(ExecState*, EncodedJSValue thisValue, PropertyName)
weinig@apple.comcaf5e3b2008-09-27 02:36:15 +0000155{
barraclough@apple.com674f9cb2016-02-09 21:19:59 +0000156 return JSValue::encode(asRegExpConstructor(JSValue::decode(thisValue))->input());
weinig@apple.comcaf5e3b2008-09-27 02:36:15 +0000157}
158
utatane.tea@gmail.comd80165c2016-06-06 01:56:11 +0000159EncodedJSValue regExpConstructorMultiline(ExecState*, EncodedJSValue thisValue, PropertyName)
weinig@apple.comcaf5e3b2008-09-27 02:36:15 +0000160{
barraclough@apple.com674f9cb2016-02-09 21:19:59 +0000161 return JSValue::encode(jsBoolean(asRegExpConstructor(JSValue::decode(thisValue))->multiline()));
weinig@apple.comcaf5e3b2008-09-27 02:36:15 +0000162}
163
utatane.tea@gmail.comd80165c2016-06-06 01:56:11 +0000164EncodedJSValue regExpConstructorLastMatch(ExecState* exec, EncodedJSValue thisValue, PropertyName)
weinig@apple.comcaf5e3b2008-09-27 02:36:15 +0000165{
barraclough@apple.com674f9cb2016-02-09 21:19:59 +0000166 return JSValue::encode(asRegExpConstructor(JSValue::decode(thisValue))->getBackref(exec, 0));
weinig@apple.comcaf5e3b2008-09-27 02:36:15 +0000167}
168
utatane.tea@gmail.comd80165c2016-06-06 01:56:11 +0000169EncodedJSValue regExpConstructorLastParen(ExecState* exec, EncodedJSValue thisValue, PropertyName)
weinig@apple.comcaf5e3b2008-09-27 02:36:15 +0000170{
barraclough@apple.com674f9cb2016-02-09 21:19:59 +0000171 return JSValue::encode(asRegExpConstructor(JSValue::decode(thisValue))->getLastParen(exec));
weinig@apple.comcaf5e3b2008-09-27 02:36:15 +0000172}
173
utatane.tea@gmail.comd80165c2016-06-06 01:56:11 +0000174EncodedJSValue regExpConstructorLeftContext(ExecState* exec, EncodedJSValue thisValue, PropertyName)
weinig@apple.comcaf5e3b2008-09-27 02:36:15 +0000175{
barraclough@apple.com674f9cb2016-02-09 21:19:59 +0000176 return JSValue::encode(asRegExpConstructor(JSValue::decode(thisValue))->getLeftContext(exec));
weinig@apple.comcaf5e3b2008-09-27 02:36:15 +0000177}
178
utatane.tea@gmail.comd80165c2016-06-06 01:56:11 +0000179EncodedJSValue regExpConstructorRightContext(ExecState* exec, EncodedJSValue thisValue, PropertyName)
weinig@apple.comcaf5e3b2008-09-27 02:36:15 +0000180{
barraclough@apple.com674f9cb2016-02-09 21:19:59 +0000181 return JSValue::encode(asRegExpConstructor(JSValue::decode(thisValue))->getRightContext(exec));
weinig@apple.com343e3d72008-06-29 00:09:26 +0000182}
183
utatane.tea@gmail.com78b50c62016-03-11 17:28:46 +0000184bool setRegExpConstructorInput(ExecState* exec, EncodedJSValue thisValue, EncodedJSValue value)
weinig@apple.com343e3d72008-06-29 00:09:26 +0000185{
utatane.tea@gmail.com78b50c62016-03-11 17:28:46 +0000186 if (auto constructor = jsDynamicCast<RegExpConstructor*>(JSValue::decode(thisValue))) {
oliver@apple.com2b5f3732014-01-25 01:26:49 +0000187 constructor->setInput(exec, JSValue::decode(value).toString(exec));
utatane.tea@gmail.com78b50c62016-03-11 17:28:46 +0000188 return true;
189 }
190 return false;
weinig@apple.comcaf5e3b2008-09-27 02:36:15 +0000191}
192
utatane.tea@gmail.com78b50c62016-03-11 17:28:46 +0000193bool setRegExpConstructorMultiline(ExecState* exec, EncodedJSValue thisValue, EncodedJSValue value)
weinig@apple.comcaf5e3b2008-09-27 02:36:15 +0000194{
utatane.tea@gmail.com78b50c62016-03-11 17:28:46 +0000195 if (auto constructor = jsDynamicCast<RegExpConstructor*>(JSValue::decode(thisValue))) {
oliver@apple.com2b5f3732014-01-25 01:26:49 +0000196 constructor->setMultiline(JSValue::decode(value).toBoolean(exec));
utatane.tea@gmail.com78b50c62016-03-11 17:28:46 +0000197 return true;
198 }
199 return false;
weinig@apple.com343e3d72008-06-29 00:09:26 +0000200}
barraclough@apple.com12812932011-03-09 23:04:27 +0000201
keith_miller@apple.com3793b132016-01-11 21:31:04 +0000202inline Structure* getRegExpStructure(ExecState* exec, JSGlobalObject* globalObject, JSValue newTarget)
keith_miller@apple.com8dc2c352016-01-06 18:25:01 +0000203{
204 Structure* structure = globalObject->regExpStructure();
sbarati@apple.comf0654332016-02-23 00:51:02 +0000205 if (newTarget != jsUndefined())
keith_miller@apple.com3793b132016-01-11 21:31:04 +0000206 structure = InternalFunction::createSubclassStructure(exec, newTarget, structure);
keith_miller@apple.com8dc2c352016-01-06 18:25:01 +0000207 return structure;
208}
209
keith_miller@apple.comae261a82016-04-06 18:26:11 +0000210inline RegExpFlags toFlags(ExecState* exec, JSValue flags)
weinig@apple.com343e3d72008-06-29 00:09:26 +0000211{
mark.lam@apple.com284f4562016-08-30 20:54:54 +0000212 VM& vm = exec->vm();
213 auto scope = DECLARE_THROW_SCOPE(vm);
214
keith_miller@apple.comae261a82016-04-06 18:26:11 +0000215 if (flags.isUndefined())
216 return NoFlags;
217 JSString* flagsString = flags.toString(exec);
mark.lam@apple.com451de992016-09-07 22:10:50 +0000218 ASSERT(scope.exception() || flagsString);
keith_miller@apple.comae261a82016-04-06 18:26:11 +0000219 if (!flagsString) {
keith_miller@apple.comae261a82016-04-06 18:26:11 +0000220 return InvalidFlags;
221 }
weinig@apple.com2947a912008-07-07 02:49:29 +0000222
keith_miller@apple.comae261a82016-04-06 18:26:11 +0000223 RegExpFlags result = regExpFlags(flagsString->value(exec));
mark.lam@apple.come1ab17c2016-09-26 19:11:17 +0000224 RETURN_IF_EXCEPTION(scope, InvalidFlags);
keith_miller@apple.comae261a82016-04-06 18:26:11 +0000225 if (result == InvalidFlags)
mark.lam@apple.com284f4562016-08-30 20:54:54 +0000226 throwSyntaxError(exec, scope, ASCIILiteral("Invalid flags supplied to RegExp constructor."));
keith_miller@apple.comae261a82016-04-06 18:26:11 +0000227 return result;
228}
229
mark.lam@apple.com5aca4992016-04-07 03:17:58 +0000230static JSObject* regExpCreate(ExecState* exec, JSGlobalObject* globalObject, JSValue newTarget, JSValue patternArg, JSValue flagsArg)
231{
232 VM& vm = exec->vm();
mark.lam@apple.com284f4562016-08-30 20:54:54 +0000233 auto scope = DECLARE_THROW_SCOPE(vm);
234
mark.lam@apple.com5aca4992016-04-07 03:17:58 +0000235 String pattern = patternArg.isUndefined() ? emptyString() : patternArg.toString(exec)->value(exec);
mark.lam@apple.come1ab17c2016-09-26 19:11:17 +0000236 RETURN_IF_EXCEPTION(scope, nullptr);
mark.lam@apple.com5aca4992016-04-07 03:17:58 +0000237
238 RegExpFlags flags = toFlags(exec, flagsArg);
239 if (flags == InvalidFlags)
240 return nullptr;
241
242 RegExp* regExp = RegExp::create(vm, pattern, flags);
243 if (!regExp->isValid())
mark.lam@apple.com284f4562016-08-30 20:54:54 +0000244 return throwException(exec, scope, createSyntaxError(exec, regExp->errorMessage()));
mark.lam@apple.com5aca4992016-04-07 03:17:58 +0000245
246 Structure* structure = getRegExpStructure(exec, globalObject, newTarget);
mark.lam@apple.come1ab17c2016-09-26 19:11:17 +0000247 RETURN_IF_EXCEPTION(scope, nullptr);
mark.lam@apple.com5aca4992016-04-07 03:17:58 +0000248 return RegExpObject::create(vm, structure, regExp);
249}
250
keith_miller@apple.comae261a82016-04-06 18:26:11 +0000251JSObject* constructRegExp(ExecState* exec, JSGlobalObject* globalObject, const ArgList& args, JSObject* callee, JSValue newTarget)
252{
msaboff@apple.com85698572016-03-10 23:38:15 +0000253 VM& vm = exec->vm();
mark.lam@apple.com451de992016-09-07 22:10:50 +0000254 auto scope = DECLARE_THROW_SCOPE(vm);
keith_miller@apple.comae261a82016-04-06 18:26:11 +0000255 JSValue patternArg = args.at(0);
256 JSValue flagsArg = args.at(1);
257
258 bool isPatternRegExp = patternArg.inherits(RegExpObject::info());
259 bool constructAsRegexp = isRegExp(vm, exec, patternArg);
260
261 if (newTarget.isUndefined() && constructAsRegexp && flagsArg.isUndefined()) {
262 JSValue constructor = patternArg.get(exec, vm.propertyNames->constructor);
mark.lam@apple.come1ab17c2016-09-26 19:11:17 +0000263 RETURN_IF_EXCEPTION(scope, nullptr);
keith_miller@apple.comae261a82016-04-06 18:26:11 +0000264 if (callee == constructor) {
265 // We know that patternArg is a object otherwise constructAsRegexp would be false.
266 return patternArg.getObject();
barraclough@apple.com502e8742011-06-28 18:35:37 +0000267 }
weinig@apple.com2947a912008-07-07 02:49:29 +0000268 }
269
keith_miller@apple.comae261a82016-04-06 18:26:11 +0000270 if (isPatternRegExp) {
271 RegExp* regExp = jsCast<RegExpObject*>(patternArg)->regExp();
272 Structure* structure = getRegExpStructure(exec, globalObject, newTarget);
mark.lam@apple.come1ab17c2016-09-26 19:11:17 +0000273 RETURN_IF_EXCEPTION(scope, nullptr);
keith_miller@apple.comae261a82016-04-06 18:26:11 +0000274
275 if (!flagsArg.isUndefined()) {
276 RegExpFlags flags = toFlags(exec, flagsArg);
277 if (flags == InvalidFlags)
278 return nullptr;
279 regExp = RegExp::create(vm, regExp->pattern(), flags);
280 }
281
282 return RegExpObject::create(exec->vm(), structure, regExp);
283 }
284
285 if (constructAsRegexp) {
286 JSValue pattern = patternArg.get(exec, vm.propertyNames->source);
287 if (flagsArg.isUndefined())
288 flagsArg = patternArg.get(exec, vm.propertyNames->flags);
289 patternArg = pattern;
290 }
291
mark.lam@apple.com5aca4992016-04-07 03:17:58 +0000292 return regExpCreate(exec, globalObject, newTarget, patternArg, flagsArg);
293}
keith_miller@apple.comae261a82016-04-06 18:26:11 +0000294
mark.lam@apple.com5aca4992016-04-07 03:17:58 +0000295EncodedJSValue JSC_HOST_CALL esSpecRegExpCreate(ExecState* exec)
296{
297 JSGlobalObject* globalObject = exec->lexicalGlobalObject();
298 JSValue patternArg = exec->argument(0);
299 JSValue flagsArg = exec->argument(1);
300 return JSValue::encode(regExpCreate(exec, globalObject, jsUndefined(), patternArg, flagsArg));
weinig@apple.com343e3d72008-06-29 00:09:26 +0000301}
302
barraclough@apple.com11d351a2010-06-04 21:38:38 +0000303static EncodedJSValue JSC_HOST_CALL constructWithRegExpConstructor(ExecState* exec)
weinig@apple.com343e3d72008-06-29 00:09:26 +0000304{
barraclough@apple.com11d351a2010-06-04 21:38:38 +0000305 ArgList args(exec);
keith_miller@apple.comae261a82016-04-06 18:26:11 +0000306 return JSValue::encode(constructRegExp(exec, asInternalFunction(exec->callee())->globalObject(), args, exec->callee(), exec->newTarget()));
weinig@apple.com343e3d72008-06-29 00:09:26 +0000307}
308
mhahnenberg@apple.com79c8e6e2011-10-08 23:26:41 +0000309ConstructType RegExpConstructor::getConstructData(JSCell*, ConstructData& constructData)
310{
weinig@apple.com343e3d72008-06-29 00:09:26 +0000311 constructData.native.function = constructWithRegExpConstructor;
utatane.tea@gmail.comf76f1b42016-03-05 17:01:04 +0000312 return ConstructType::Host;
weinig@apple.com343e3d72008-06-29 00:09:26 +0000313}
314
barraclough@apple.com99ff3432010-06-03 20:00:18 +0000315static EncodedJSValue JSC_HOST_CALL callRegExpConstructor(ExecState* exec)
weinig@apple.com343e3d72008-06-29 00:09:26 +0000316{
ggaren@apple.comfea29f12010-05-29 06:33:05 +0000317 ArgList args(exec);
keith_miller@apple.comae261a82016-04-06 18:26:11 +0000318 return JSValue::encode(constructRegExp(exec, asInternalFunction(exec->callee())->globalObject(), args, exec->callee()));
weinig@apple.com343e3d72008-06-29 00:09:26 +0000319}
320
mhahnenberg@apple.com2413eb82011-09-27 22:46:51 +0000321CallType RegExpConstructor::getCallData(JSCell*, CallData& callData)
weinig@apple.com343e3d72008-06-29 00:09:26 +0000322{
323 callData.native.function = callRegExpConstructor;
utatane.tea@gmail.comf76f1b42016-03-05 17:01:04 +0000324 return CallType::Host;
weinig@apple.com343e3d72008-06-29 00:09:26 +0000325}
326
cwzwarich@webkit.org3f782f62008-09-08 01:28:33 +0000327} // namespace JSC