Binding generator should support interfaces with CustomConstructor and NoInterfaceObject
[WebKit-https.git] / Source / WebCore / bindings / scripts / test / JS / JSTestCustomConstructorWithNoInterfaceObject.cpp
1 /*
2     This file is part of the WebKit open source project.
3     This file has been generated by generate-bindings.pl. DO NOT MODIFY!
4
5     This library is free software; you can redistribute it and/or
6     modify it under the terms of the GNU Library 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     Library General Public License for more details.
14
15     You should have received a copy of the GNU Library General Public License
16     along with this library; see the file COPYING.LIB.  If not, write to
17     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18     Boston, MA 02110-1301, USA.
19 */
20
21 #include "config.h"
22 #include "JSTestCustomConstructorWithNoInterfaceObject.h"
23
24 #include "JSDOMBinding.h"
25 #include "TestCustomConstructorWithNoInterfaceObject.h"
26 #include <wtf/GetPtr.h>
27
28 using namespace JSC;
29
30 namespace WebCore {
31
32 // Attributes
33
34 JSC::EncodedJSValue jsTestCustomConstructorWithNoInterfaceObjectConstructor(JSC::ExecState*, JSC::JSObject*, JSC::EncodedJSValue, JSC::PropertyName);
35
36 class JSTestCustomConstructorWithNoInterfaceObjectPrototype : public JSC::JSNonFinalObject {
37 public:
38     typedef JSC::JSNonFinalObject Base;
39     static JSTestCustomConstructorWithNoInterfaceObjectPrototype* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure)
40     {
41         JSTestCustomConstructorWithNoInterfaceObjectPrototype* ptr = new (NotNull, JSC::allocateCell<JSTestCustomConstructorWithNoInterfaceObjectPrototype>(vm.heap)) JSTestCustomConstructorWithNoInterfaceObjectPrototype(vm, globalObject, structure);
42         ptr->finishCreation(vm);
43         return ptr;
44     }
45
46     DECLARE_INFO;
47     static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
48     {
49         return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
50     }
51
52 private:
53     JSTestCustomConstructorWithNoInterfaceObjectPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
54         : JSC::JSNonFinalObject(vm, structure)
55     {
56     }
57
58     void finishCreation(JSC::VM&);
59 };
60
61 class JSTestCustomConstructorWithNoInterfaceObjectConstructor : public DOMConstructorObject {
62 private:
63     JSTestCustomConstructorWithNoInterfaceObjectConstructor(JSC::Structure*, JSDOMGlobalObject*);
64     void finishCreation(JSC::VM&, JSDOMGlobalObject*);
65
66 public:
67     typedef DOMConstructorObject Base;
68     static JSTestCustomConstructorWithNoInterfaceObjectConstructor* create(JSC::VM& vm, JSC::Structure* structure, JSDOMGlobalObject* globalObject)
69     {
70         JSTestCustomConstructorWithNoInterfaceObjectConstructor* ptr = new (NotNull, JSC::allocateCell<JSTestCustomConstructorWithNoInterfaceObjectConstructor>(vm.heap)) JSTestCustomConstructorWithNoInterfaceObjectConstructor(structure, globalObject);
71         ptr->finishCreation(vm, globalObject);
72         return ptr;
73     }
74
75     DECLARE_INFO;
76     static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
77     {
78         return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
79     }
80     static JSC::ConstructType getConstructData(JSC::JSCell*, JSC::ConstructData&);
81 };
82
83 const ClassInfo JSTestCustomConstructorWithNoInterfaceObjectConstructor::s_info = { "TestCustomConstructorWithNoInterfaceObjectConstructor", &Base::s_info, 0, CREATE_METHOD_TABLE(JSTestCustomConstructorWithNoInterfaceObjectConstructor) };
84
85 JSTestCustomConstructorWithNoInterfaceObjectConstructor::JSTestCustomConstructorWithNoInterfaceObjectConstructor(Structure* structure, JSDOMGlobalObject* globalObject)
86     : DOMConstructorObject(structure, globalObject)
87 {
88 }
89
90 void JSTestCustomConstructorWithNoInterfaceObjectConstructor::finishCreation(VM& vm, JSDOMGlobalObject* globalObject)
91 {
92     Base::finishCreation(vm);
93     ASSERT(inherits(info()));
94     putDirect(vm, vm.propertyNames->prototype, JSTestCustomConstructorWithNoInterfaceObject::getPrototype(vm, globalObject), DontDelete | ReadOnly);
95     putDirect(vm, vm.propertyNames->length, jsNumber(0), ReadOnly | DontDelete | DontEnum);
96 }
97
98 ConstructType JSTestCustomConstructorWithNoInterfaceObjectConstructor::getConstructData(JSCell*, ConstructData& constructData)
99 {
100     constructData.native.function = constructJSTestCustomConstructorWithNoInterfaceObject;
101     return ConstructTypeHost;
102 }
103
104 /* Hash table for prototype */
105
106 static const HashTableValue JSTestCustomConstructorWithNoInterfaceObjectPrototypeTableValues[] =
107 {
108     { "constructor", DontEnum | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestCustomConstructorWithNoInterfaceObjectConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
109 };
110
111 const ClassInfo JSTestCustomConstructorWithNoInterfaceObjectPrototype::s_info = { "TestCustomConstructorWithNoInterfaceObjectPrototype", &Base::s_info, 0, CREATE_METHOD_TABLE(JSTestCustomConstructorWithNoInterfaceObjectPrototype) };
112
113 void JSTestCustomConstructorWithNoInterfaceObjectPrototype::finishCreation(VM& vm)
114 {
115     Base::finishCreation(vm);
116     reifyStaticProperties(vm, JSTestCustomConstructorWithNoInterfaceObjectPrototypeTableValues, *this);
117 }
118
119 const ClassInfo JSTestCustomConstructorWithNoInterfaceObject::s_info = { "TestCustomConstructorWithNoInterfaceObject", &Base::s_info, 0, CREATE_METHOD_TABLE(JSTestCustomConstructorWithNoInterfaceObject) };
120
121 JSTestCustomConstructorWithNoInterfaceObject::JSTestCustomConstructorWithNoInterfaceObject(Structure* structure, JSDOMGlobalObject* globalObject, Ref<TestCustomConstructorWithNoInterfaceObject>&& impl)
122     : JSDOMWrapper(structure, globalObject)
123     , m_impl(&impl.leakRef())
124 {
125 }
126
127 JSObject* JSTestCustomConstructorWithNoInterfaceObject::createPrototype(VM& vm, JSGlobalObject* globalObject)
128 {
129     return JSTestCustomConstructorWithNoInterfaceObjectPrototype::create(vm, globalObject, JSTestCustomConstructorWithNoInterfaceObjectPrototype::createStructure(vm, globalObject, globalObject->objectPrototype()));
130 }
131
132 JSObject* JSTestCustomConstructorWithNoInterfaceObject::getPrototype(VM& vm, JSGlobalObject* globalObject)
133 {
134     return getDOMPrototype<JSTestCustomConstructorWithNoInterfaceObject>(vm, globalObject);
135 }
136
137 void JSTestCustomConstructorWithNoInterfaceObject::destroy(JSC::JSCell* cell)
138 {
139     JSTestCustomConstructorWithNoInterfaceObject* thisObject = static_cast<JSTestCustomConstructorWithNoInterfaceObject*>(cell);
140     thisObject->JSTestCustomConstructorWithNoInterfaceObject::~JSTestCustomConstructorWithNoInterfaceObject();
141 }
142
143 JSTestCustomConstructorWithNoInterfaceObject::~JSTestCustomConstructorWithNoInterfaceObject()
144 {
145     releaseImpl();
146 }
147
148 EncodedJSValue jsTestCustomConstructorWithNoInterfaceObjectConstructor(ExecState* exec, JSObject* baseValue, EncodedJSValue, PropertyName)
149 {
150     JSTestCustomConstructorWithNoInterfaceObjectPrototype* domObject = jsDynamicCast<JSTestCustomConstructorWithNoInterfaceObjectPrototype*>(baseValue);
151     if (!domObject)
152         return throwVMTypeError(exec);
153     JSValue constructor = JSTestCustomConstructorWithNoInterfaceObjectConstructor::create(exec->vm(), JSTestCustomConstructorWithNoInterfaceObjectConstructor::createStructure(exec->vm(), domObject->globalObject(), domObject->globalObject()->objectPrototype()), jsCast<JSDOMGlobalObject*>(domObject->globalObject()));
154     // Shadowing constructor property to ensure reusing the same constructor object
155     domObject->putDirect(exec->vm(), exec->propertyNames().constructor, constructor, DontEnum | ReadOnly);
156     return JSValue::encode(constructor);
157 }
158
159 bool JSTestCustomConstructorWithNoInterfaceObjectOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor)
160 {
161     UNUSED_PARAM(handle);
162     UNUSED_PARAM(visitor);
163     return false;
164 }
165
166 void JSTestCustomConstructorWithNoInterfaceObjectOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
167 {
168     auto* jsTestCustomConstructorWithNoInterfaceObject = jsCast<JSTestCustomConstructorWithNoInterfaceObject*>(handle.slot()->asCell());
169     auto& world = *static_cast<DOMWrapperWorld*>(context);
170     uncacheWrapper(world, &jsTestCustomConstructorWithNoInterfaceObject->impl(), jsTestCustomConstructorWithNoInterfaceObject);
171 }
172
173 #if ENABLE(BINDING_INTEGRITY)
174 #if PLATFORM(WIN)
175 #pragma warning(disable: 4483)
176 extern "C" { extern void (*const __identifier("??_7TestCustomConstructorWithNoInterfaceObject@WebCore@@6B@")[])(); }
177 #else
178 extern "C" { extern void* _ZTVN7WebCore42TestCustomConstructorWithNoInterfaceObjectE[]; }
179 #endif
180 #endif
181 JSC::JSValue toJS(JSC::ExecState*, JSDOMGlobalObject* globalObject, TestCustomConstructorWithNoInterfaceObject* impl)
182 {
183     if (!impl)
184         return jsNull();
185     if (JSValue result = getExistingWrapper<JSTestCustomConstructorWithNoInterfaceObject>(globalObject, impl))
186         return result;
187
188 #if ENABLE(BINDING_INTEGRITY)
189     void* actualVTablePointer = *(reinterpret_cast<void**>(impl));
190 #if PLATFORM(WIN)
191     void* expectedVTablePointer = reinterpret_cast<void*>(__identifier("??_7TestCustomConstructorWithNoInterfaceObject@WebCore@@6B@"));
192 #else
193     void* expectedVTablePointer = &_ZTVN7WebCore42TestCustomConstructorWithNoInterfaceObjectE[2];
194 #if COMPILER(CLANG)
195     // If this fails TestCustomConstructorWithNoInterfaceObject does not have a vtable, so you need to add the
196     // ImplementationLacksVTable attribute to the interface definition
197     COMPILE_ASSERT(__is_polymorphic(TestCustomConstructorWithNoInterfaceObject), TestCustomConstructorWithNoInterfaceObject_is_not_polymorphic);
198 #endif
199 #endif
200     // If you hit this assertion you either have a use after free bug, or
201     // TestCustomConstructorWithNoInterfaceObject has subclasses. If TestCustomConstructorWithNoInterfaceObject has subclasses that get passed
202     // to toJS() we currently require TestCustomConstructorWithNoInterfaceObject you to opt out of binding hardening
203     // by adding the SkipVTableValidation attribute to the interface IDL definition
204     RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
205 #endif
206     return createNewWrapper<JSTestCustomConstructorWithNoInterfaceObject>(globalObject, impl);
207 }
208
209 TestCustomConstructorWithNoInterfaceObject* JSTestCustomConstructorWithNoInterfaceObject::toWrapped(JSC::JSValue value)
210 {
211     if (auto* wrapper = jsDynamicCast<JSTestCustomConstructorWithNoInterfaceObject*>(value))
212         return &wrapper->impl();
213     return nullptr;
214 }
215
216 }