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