Add infrastructure for pointer preparation.
[WebKit-https.git] / Source / WebCore / bindings / scripts / test / JS / JSTestOverloadedConstructors.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 "JSTestOverloadedConstructors.h"
23
24 #include "JSBlob.h"
25 #include "JSDOMBinding.h"
26 #include "JSDOMConstructor.h"
27 #include "JSDOMConvertBufferSource.h"
28 #include "JSDOMConvertInterface.h"
29 #include "JSDOMConvertNumbers.h"
30 #include "JSDOMConvertStrings.h"
31 #include "JSDOMConvertVariadic.h"
32 #include "JSDOMExceptionHandling.h"
33 #include "JSDOMWrapperCache.h"
34 #include <runtime/FunctionPrototype.h>
35 #include <runtime/JSCInlines.h>
36 #include <wtf/GetPtr.h>
37 #include <wtf/PointerPreparations.h>
38
39
40 namespace WebCore {
41 using namespace JSC;
42
43 // Attributes
44
45 JSC::EncodedJSValue jsTestOverloadedConstructorsConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
46 bool setJSTestOverloadedConstructorsConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
47
48 class JSTestOverloadedConstructorsPrototype : public JSC::JSNonFinalObject {
49 public:
50     using Base = JSC::JSNonFinalObject;
51     static JSTestOverloadedConstructorsPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
52     {
53         JSTestOverloadedConstructorsPrototype* ptr = new (NotNull, JSC::allocateCell<JSTestOverloadedConstructorsPrototype>(vm.heap)) JSTestOverloadedConstructorsPrototype(vm, globalObject, structure);
54         ptr->finishCreation(vm);
55         return ptr;
56     }
57
58     DECLARE_INFO;
59     static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
60     {
61         return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
62     }
63
64 private:
65     JSTestOverloadedConstructorsPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
66         : JSC::JSNonFinalObject(vm, structure)
67     {
68     }
69
70     void finishCreation(JSC::VM&);
71 };
72
73 using JSTestOverloadedConstructorsConstructor = JSDOMConstructor<JSTestOverloadedConstructors>;
74
75 static inline EncodedJSValue constructJSTestOverloadedConstructors1(ExecState* state)
76 {
77     VM& vm = state->vm();
78     auto throwScope = DECLARE_THROW_SCOPE(vm);
79     UNUSED_PARAM(throwScope);
80     auto* castedThis = jsCast<JSTestOverloadedConstructorsConstructor*>(state->jsCallee());
81     ASSERT(castedThis);
82     auto arrayBuffer = convert<IDLArrayBuffer>(*state, state->uncheckedArgument(0), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentTypeError(state, scope, 0, "arrayBuffer", "TestOverloadedConstructors", nullptr, "ArrayBuffer"); });
83     RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
84     auto object = TestOverloadedConstructors::create(*arrayBuffer);
85     return JSValue::encode(toJSNewlyCreated<IDLInterface<TestOverloadedConstructors>>(*state, *castedThis->globalObject(), WTFMove(object)));
86 }
87
88 static inline EncodedJSValue constructJSTestOverloadedConstructors2(ExecState* state)
89 {
90     VM& vm = state->vm();
91     auto throwScope = DECLARE_THROW_SCOPE(vm);
92     UNUSED_PARAM(throwScope);
93     auto* castedThis = jsCast<JSTestOverloadedConstructorsConstructor*>(state->jsCallee());
94     ASSERT(castedThis);
95     auto arrayBufferView = convert<IDLArrayBufferView>(*state, state->uncheckedArgument(0), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentTypeError(state, scope, 0, "arrayBufferView", "TestOverloadedConstructors", nullptr, "ArrayBufferView"); });
96     RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
97     auto object = TestOverloadedConstructors::create(arrayBufferView.releaseNonNull());
98     return JSValue::encode(toJSNewlyCreated<IDLInterface<TestOverloadedConstructors>>(*state, *castedThis->globalObject(), WTFMove(object)));
99 }
100
101 static inline EncodedJSValue constructJSTestOverloadedConstructors3(ExecState* state)
102 {
103     VM& vm = state->vm();
104     auto throwScope = DECLARE_THROW_SCOPE(vm);
105     UNUSED_PARAM(throwScope);
106     auto* castedThis = jsCast<JSTestOverloadedConstructorsConstructor*>(state->jsCallee());
107     ASSERT(castedThis);
108     auto blob = convert<IDLInterface<Blob>>(*state, state->uncheckedArgument(0), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentTypeError(state, scope, 0, "blob", "TestOverloadedConstructors", nullptr, "Blob"); });
109     RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
110     auto object = TestOverloadedConstructors::create(*blob);
111     return JSValue::encode(toJSNewlyCreated<IDLInterface<TestOverloadedConstructors>>(*state, *castedThis->globalObject(), WTFMove(object)));
112 }
113
114 static inline EncodedJSValue constructJSTestOverloadedConstructors4(ExecState* state)
115 {
116     VM& vm = state->vm();
117     auto throwScope = DECLARE_THROW_SCOPE(vm);
118     UNUSED_PARAM(throwScope);
119     auto* castedThis = jsCast<JSTestOverloadedConstructorsConstructor*>(state->jsCallee());
120     ASSERT(castedThis);
121     auto string = convert<IDLDOMString>(*state, state->uncheckedArgument(0));
122     RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
123     auto object = TestOverloadedConstructors::create(WTFMove(string));
124     return JSValue::encode(toJSNewlyCreated<IDLInterface<TestOverloadedConstructors>>(*state, *castedThis->globalObject(), WTFMove(object)));
125 }
126
127 static inline EncodedJSValue constructJSTestOverloadedConstructors5(ExecState* state)
128 {
129     VM& vm = state->vm();
130     auto throwScope = DECLARE_THROW_SCOPE(vm);
131     UNUSED_PARAM(throwScope);
132     auto* castedThis = jsCast<JSTestOverloadedConstructorsConstructor*>(state->jsCallee());
133     ASSERT(castedThis);
134     auto longArgs = convertVariadicArguments<IDLLong>(*state, 0);
135     RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
136     auto object = TestOverloadedConstructors::create(WTFMove(longArgs));
137     return JSValue::encode(toJSNewlyCreated<IDLInterface<TestOverloadedConstructors>>(*state, *castedThis->globalObject(), WTFMove(object)));
138 }
139
140 template<> EncodedJSValue JSC_HOST_CALL JSTestOverloadedConstructorsConstructor::construct(ExecState* state)
141 {
142     VM& vm = state->vm();
143     auto throwScope = DECLARE_THROW_SCOPE(vm);
144     UNUSED_PARAM(throwScope);
145     size_t argsCount = std::min<size_t>(1, state->argumentCount());
146     if (argsCount == 0) {
147         return constructJSTestOverloadedConstructors5(state);
148     }
149     if (argsCount == 1) {
150         JSValue distinguishingArg = state->uncheckedArgument(0);
151         if (distinguishingArg.isObject() && asObject(distinguishingArg)->inherits(vm, JSArrayBuffer::info()))
152             return constructJSTestOverloadedConstructors1(state);
153         if (distinguishingArg.isObject() && asObject(distinguishingArg)->inherits(vm, JSArrayBufferView::info()))
154             return constructJSTestOverloadedConstructors2(state);
155         if (distinguishingArg.isObject() && asObject(distinguishingArg)->inherits(vm, JSBlob::info()))
156             return constructJSTestOverloadedConstructors3(state);
157         if (distinguishingArg.isNumber())
158             return constructJSTestOverloadedConstructors5(state);
159         return constructJSTestOverloadedConstructors4(state);
160     }
161     return throwVMTypeError(state, throwScope);
162 }
163
164 template<> JSValue JSTestOverloadedConstructorsConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
165 {
166     UNUSED_PARAM(vm);
167     return globalObject.functionPrototype();
168 }
169
170 template<> void JSTestOverloadedConstructorsConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
171 {
172     putDirect(vm, vm.propertyNames->prototype, JSTestOverloadedConstructors::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
173     putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String(ASCIILiteral("TestOverloadedConstructors"))), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
174     putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
175 }
176
177 template<> const ClassInfo JSTestOverloadedConstructorsConstructor::s_info = { "TestOverloadedConstructors", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestOverloadedConstructorsConstructor) };
178
179 /* Hash table for prototype */
180
181 static const HashTableValue JSTestOverloadedConstructorsPrototypeTableValues[] =
182 {
183     { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestOverloadedConstructorsConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestOverloadedConstructorsConstructor) } },
184 };
185
186 const ClassInfo JSTestOverloadedConstructorsPrototype::s_info = { "TestOverloadedConstructorsPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestOverloadedConstructorsPrototype) };
187
188 void JSTestOverloadedConstructorsPrototype::finishCreation(VM& vm)
189 {
190     Base::finishCreation(vm);
191     reifyStaticProperties(vm, JSTestOverloadedConstructors::info(), JSTestOverloadedConstructorsPrototypeTableValues, *this);
192 }
193
194 const ClassInfo JSTestOverloadedConstructors::s_info = { "TestOverloadedConstructors", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestOverloadedConstructors) };
195
196 JSTestOverloadedConstructors::JSTestOverloadedConstructors(Structure* structure, JSDOMGlobalObject& globalObject, Ref<TestOverloadedConstructors>&& impl)
197     : JSDOMWrapper<TestOverloadedConstructors>(structure, globalObject, WTFMove(impl))
198 {
199 }
200
201 void JSTestOverloadedConstructors::finishCreation(VM& vm)
202 {
203     Base::finishCreation(vm);
204     ASSERT(inherits(vm, info()));
205
206 }
207
208 JSObject* JSTestOverloadedConstructors::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
209 {
210     return JSTestOverloadedConstructorsPrototype::create(vm, &globalObject, JSTestOverloadedConstructorsPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype()));
211 }
212
213 JSObject* JSTestOverloadedConstructors::prototype(VM& vm, JSDOMGlobalObject& globalObject)
214 {
215     return getDOMPrototype<JSTestOverloadedConstructors>(vm, globalObject);
216 }
217
218 JSValue JSTestOverloadedConstructors::getConstructor(VM& vm, const JSGlobalObject* globalObject)
219 {
220     return getDOMConstructor<JSTestOverloadedConstructorsConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
221 }
222
223 void JSTestOverloadedConstructors::destroy(JSC::JSCell* cell)
224 {
225     JSTestOverloadedConstructors* thisObject = static_cast<JSTestOverloadedConstructors*>(cell);
226     thisObject->JSTestOverloadedConstructors::~JSTestOverloadedConstructors();
227 }
228
229 EncodedJSValue jsTestOverloadedConstructorsConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
230 {
231     VM& vm = state->vm();
232     auto throwScope = DECLARE_THROW_SCOPE(vm);
233     auto* prototype = jsDynamicDowncast<JSTestOverloadedConstructorsPrototype*>(vm, JSValue::decode(thisValue));
234     if (UNLIKELY(!prototype))
235         return throwVMTypeError(state, throwScope);
236     return JSValue::encode(JSTestOverloadedConstructors::getConstructor(state->vm(), prototype->globalObject()));
237 }
238
239 bool setJSTestOverloadedConstructorsConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
240 {
241     VM& vm = state->vm();
242     auto throwScope = DECLARE_THROW_SCOPE(vm);
243     auto* prototype = jsDynamicDowncast<JSTestOverloadedConstructorsPrototype*>(vm, JSValue::decode(thisValue));
244     if (UNLIKELY(!prototype)) {
245         throwVMTypeError(state, throwScope);
246         return false;
247     }
248     // Shadowing a built-in constructor
249     return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
250 }
251
252 bool JSTestOverloadedConstructorsOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor)
253 {
254     UNUSED_PARAM(handle);
255     UNUSED_PARAM(visitor);
256     return false;
257 }
258
259 void JSTestOverloadedConstructorsOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
260 {
261     auto* jsTestOverloadedConstructors = static_cast<JSTestOverloadedConstructors*>(handle.slot()->asCell());
262     auto& world = *static_cast<DOMWrapperWorld*>(context);
263     uncacheWrapper(world, &jsTestOverloadedConstructors->wrapped(), jsTestOverloadedConstructors);
264 }
265
266 #if ENABLE(BINDING_INTEGRITY)
267 #if PLATFORM(WIN)
268 #pragma warning(disable: 4483)
269 extern "C" { extern void (*const __identifier("??_7TestOverloadedConstructors@WebCore@@6B@")[])(); }
270 #else
271 extern "C" { extern void* _ZTVN7WebCore26TestOverloadedConstructorsE[]; }
272 #endif
273 #endif
274
275 JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<TestOverloadedConstructors>&& impl)
276 {
277
278 #if ENABLE(BINDING_INTEGRITY)
279     void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
280 #if PLATFORM(WIN)
281     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7TestOverloadedConstructors@WebCore@@6B@"));
282 #else
283     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore26TestOverloadedConstructorsE[2]);
284 #endif
285
286     // If this fails TestOverloadedConstructors does not have a vtable, so you need to add the
287     // ImplementationLacksVTable attribute to the interface definition
288     static_assert(std::is_polymorphic<TestOverloadedConstructors>::value, "TestOverloadedConstructors is not polymorphic");
289
290     // If you hit this assertion you either have a use after free bug, or
291     // TestOverloadedConstructors has subclasses. If TestOverloadedConstructors has subclasses that get passed
292     // to toJS() we currently require TestOverloadedConstructors you to opt out of binding hardening
293     // by adding the SkipVTableValidation attribute to the interface IDL definition
294     RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
295 #endif
296     return createWrapper<TestOverloadedConstructors>(globalObject, WTFMove(impl));
297 }
298
299 JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, TestOverloadedConstructors& impl)
300 {
301     return wrap(state, globalObject, impl);
302 }
303
304 TestOverloadedConstructors* JSTestOverloadedConstructors::toWrapped(JSC::VM& vm, JSC::JSValue value)
305 {
306     if (auto* wrapper = jsDynamicDowncast<JSTestOverloadedConstructors*>(vm, value))
307         return &wrapper->wrapped();
308     return nullptr;
309 }
310
311 }