1/*
2 * Copyright (C) 1999-2000 Harri Porten ([email protected])
3 * Copyright (C) 2003-2019 Apple Inc. All Rights Reserved.
4 *
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.
9 *
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.
14 *
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
18 *
19 */
20
21#pragma once
22
23#include "InternalFunction.h"
24#include "RegExp.h"
25#include "RegExpCachedResult.h"
26#include "RegExpObject.h"
27
28namespace JSC {
29
30class RegExpPrototype;
31class GetterSetter;
32
33class RegExpConstructor final : public InternalFunction {
34public:
35 typedef InternalFunction Base;
36 static constexpr unsigned StructureFlags = Base::StructureFlags | HasStaticPropertyTable;
37
38 static RegExpConstructor* create(VM& vm, Structure* structure, RegExpPrototype* regExpPrototype, GetterSetter* species)
39 {
40 RegExpConstructor* constructor = new (NotNull, allocateCell<RegExpConstructor>(vm.heap)) RegExpConstructor(vm, structure);
41 constructor->finishCreation(vm, regExpPrototype, species);
42 return constructor;
43 }
44
45 static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
46 {
47 return Structure::create(vm, globalObject, prototype, TypeInfo(InternalFunctionType, StructureFlags), info());
48 }
49
50 DECLARE_INFO;
51
52protected:
53 void finishCreation(VM&, RegExpPrototype*, GetterSetter* species);
54
55private:
56 RegExpConstructor(VM&, Structure*);
57};
58
59static_assert(sizeof(RegExpConstructor) == sizeof(InternalFunction), "");
60
61JSObject* constructRegExp(JSGlobalObject*, const ArgList&, JSObject* callee = nullptr, JSValue newTarget = jsUndefined());
62
63ALWAYS_INLINE bool isRegExp(VM& vm, JSGlobalObject* globalObject, JSValue value)
64{
65 auto scope = DECLARE_THROW_SCOPE(vm);
66 if (!value.isObject())
67 return false;
68
69 JSObject* object = asObject(value);
70 JSValue matchValue = object->get(globalObject, vm.propertyNames->matchSymbol);
71 RETURN_IF_EXCEPTION(scope, false);
72 if (!matchValue.isUndefined())
73 return matchValue.toBoolean(globalObject);
74
75 return object->inherits<RegExpObject>(vm);
76}
77
78EncodedJSValue JSC_HOST_CALL esSpecRegExpCreate(JSGlobalObject*, CallFrame*);
79EncodedJSValue JSC_HOST_CALL esSpecIsRegExp(JSGlobalObject*, CallFrame*);
80
81} // namespace JSC
82