| 1 | /* |
| 2 | * Copyright (C) 1999-2000 Harri Porten (porten@kde.org) |
| 3 | * Copyright (C) 2003-2018 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 | |
| 28 | namespace JSC { |
| 29 | |
| 30 | class RegExpPrototype; |
| 31 | class GetterSetter; |
| 32 | |
| 33 | class RegExpConstructor final : public InternalFunction { |
| 34 | public: |
| 35 | typedef InternalFunction Base; |
| 36 | static const 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 | |
| 52 | protected: |
| 53 | void finishCreation(VM&, RegExpPrototype*, GetterSetter* species); |
| 54 | |
| 55 | private: |
| 56 | RegExpConstructor(VM&, Structure*); |
| 57 | }; |
| 58 | |
| 59 | static_assert(sizeof(RegExpConstructor) == sizeof(InternalFunction), "" ); |
| 60 | |
| 61 | JSObject* constructRegExp(ExecState*, JSGlobalObject*, const ArgList&, JSObject* callee = nullptr, JSValue newTarget = jsUndefined()); |
| 62 | |
| 63 | ALWAYS_INLINE bool isRegExp(VM& vm, ExecState* exec, 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(exec, vm.propertyNames->matchSymbol); |
| 71 | RETURN_IF_EXCEPTION(scope, false); |
| 72 | if (!matchValue.isUndefined()) |
| 73 | return matchValue.toBoolean(exec); |
| 74 | |
| 75 | return object->inherits<RegExpObject>(vm); |
| 76 | } |
| 77 | |
| 78 | EncodedJSValue JSC_HOST_CALL esSpecRegExpCreate(ExecState*); |
| 79 | |
| 80 | } // namespace JSC |
| 81 | |