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