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