| 1 | /* |
| 2 | * Copyright (C) 2015, 2016 Canon Inc. All rights reserved. |
| 3 | * Copyright (C) 2016 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 | #pragma once |
| 21 | |
| 22 | #include "JSDOMConstructorBase.h" |
| 23 | |
| 24 | namespace WebCore { |
| 25 | |
| 26 | template<typename JSClass> class JSDOMConstructorNotConstructable : public JSDOMConstructorBase { |
| 27 | public: |
| 28 | using Base = JSDOMConstructorBase; |
| 29 | |
| 30 | static JSDOMConstructorNotConstructable* create(JSC::VM&, JSC::Structure*, JSDOMGlobalObject&); |
| 31 | static JSC::Structure* createStructure(JSC::VM&, JSC::JSGlobalObject&, JSC::JSValue prototype); |
| 32 | |
| 33 | DECLARE_INFO; |
| 34 | |
| 35 | // Must be defined for each specialization class. |
| 36 | static JSC::JSValue prototypeForStructure(JSC::VM&, const JSDOMGlobalObject&); |
| 37 | |
| 38 | private: |
| 39 | JSDOMConstructorNotConstructable(JSC::Structure* structure, JSDOMGlobalObject& globalObject) |
| 40 | : Base(structure, globalObject) |
| 41 | { |
| 42 | } |
| 43 | |
| 44 | void finishCreation(JSC::VM&, JSDOMGlobalObject&); |
| 45 | |
| 46 | // Usually defined for each specialization class. |
| 47 | void initializeProperties(JSC::VM&, JSDOMGlobalObject&) { } |
| 48 | |
| 49 | static JSC::EncodedJSValue JSC_HOST_CALL callThrowTypeError(JSC::ExecState* exec) |
| 50 | { |
| 51 | JSC::VM& vm = exec->vm(); |
| 52 | auto scope = DECLARE_THROW_SCOPE(vm); |
| 53 | JSC::throwTypeError(exec, scope, "Illegal constructor"_s ); |
| 54 | return JSC::JSValue::encode(JSC::jsNull()); |
| 55 | } |
| 56 | |
| 57 | static JSC::CallType getCallData(JSC::JSCell*, JSC::CallData& callData) |
| 58 | { |
| 59 | callData.native.function = callThrowTypeError; |
| 60 | return JSC::CallType::Host; |
| 61 | } |
| 62 | }; |
| 63 | |
| 64 | template<typename JSClass> inline JSDOMConstructorNotConstructable<JSClass>* JSDOMConstructorNotConstructable<JSClass>::create(JSC::VM& vm, JSC::Structure* structure, JSDOMGlobalObject& globalObject) |
| 65 | { |
| 66 | JSDOMConstructorNotConstructable* constructor = new (NotNull, JSC::allocateCell<JSDOMConstructorNotConstructable>(vm.heap)) JSDOMConstructorNotConstructable(structure, globalObject); |
| 67 | constructor->finishCreation(vm, globalObject); |
| 68 | return constructor; |
| 69 | } |
| 70 | |
| 71 | template<typename JSClass> inline JSC::Structure* JSDOMConstructorNotConstructable<JSClass>::createStructure(JSC::VM& vm, JSC::JSGlobalObject& globalObject, JSC::JSValue prototype) |
| 72 | { |
| 73 | return JSC::Structure::create(vm, &globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info()); |
| 74 | } |
| 75 | |
| 76 | template<typename JSClass> inline void JSDOMConstructorNotConstructable<JSClass>::finishCreation(JSC::VM& vm, JSDOMGlobalObject& globalObject) |
| 77 | { |
| 78 | Base::finishCreation(vm); |
| 79 | ASSERT(inherits(vm, info())); |
| 80 | initializeProperties(vm, globalObject); |
| 81 | } |
| 82 | |
| 83 | } // namespace WebCore |
| 84 | |