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