Move URL from WebCore to WTF
[WebKit-https.git] / Source / WebCore / bindings / scripts / test / JS / JSTestEventConstructor.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 "JSTestEventConstructor.h"
23
24 #include "JSDOMAttribute.h"
25 #include "JSDOMBinding.h"
26 #include "JSDOMConstructor.h"
27 #include "JSDOMConvertBoolean.h"
28 #include "JSDOMConvertInterface.h"
29 #include "JSDOMConvertStrings.h"
30 #include "JSDOMExceptionHandling.h"
31 #include "JSDOMWrapperCache.h"
32 #include "ScriptExecutionContext.h"
33 #include <JavaScriptCore/HeapSnapshotBuilder.h>
34 #include <JavaScriptCore/JSCInlines.h>
35 #include <wtf/GetPtr.h>
36 #include <wtf/PointerPreparations.h>
37 #include <wtf/URL.h>
38
39
40 namespace WebCore {
41 using namespace JSC;
42
43 template<> TestEventConstructor::Init convertDictionary<TestEventConstructor::Init>(ExecState& state, JSValue value)
44 {
45     VM& vm = state.vm();
46     auto throwScope = DECLARE_THROW_SCOPE(vm);
47     bool isNullOrUndefined = value.isUndefinedOrNull();
48     auto* object = isNullOrUndefined ? nullptr : value.getObject();
49     if (UNLIKELY(!isNullOrUndefined && !object)) {
50         throwTypeError(&state, throwScope);
51         return { };
52     }
53     TestEventConstructor::Init result;
54     JSValue bubblesValue;
55     if (isNullOrUndefined)
56         bubblesValue = jsUndefined();
57     else {
58         bubblesValue = object->get(&state, Identifier::fromString(&state, "bubbles"));
59         RETURN_IF_EXCEPTION(throwScope, { });
60     }
61     if (!bubblesValue.isUndefined()) {
62         result.bubbles = convert<IDLBoolean>(state, bubblesValue);
63         RETURN_IF_EXCEPTION(throwScope, { });
64     } else
65         result.bubbles = false;
66     JSValue cancelableValue;
67     if (isNullOrUndefined)
68         cancelableValue = jsUndefined();
69     else {
70         cancelableValue = object->get(&state, Identifier::fromString(&state, "cancelable"));
71         RETURN_IF_EXCEPTION(throwScope, { });
72     }
73     if (!cancelableValue.isUndefined()) {
74         result.cancelable = convert<IDLBoolean>(state, cancelableValue);
75         RETURN_IF_EXCEPTION(throwScope, { });
76     } else
77         result.cancelable = false;
78     JSValue composedValue;
79     if (isNullOrUndefined)
80         composedValue = jsUndefined();
81     else {
82         composedValue = object->get(&state, Identifier::fromString(&state, "composed"));
83         RETURN_IF_EXCEPTION(throwScope, { });
84     }
85     if (!composedValue.isUndefined()) {
86         result.composed = convert<IDLBoolean>(state, composedValue);
87         RETURN_IF_EXCEPTION(throwScope, { });
88     } else
89         result.composed = false;
90     JSValue attr2Value;
91     if (isNullOrUndefined)
92         attr2Value = jsUndefined();
93     else {
94         attr2Value = object->get(&state, Identifier::fromString(&state, "attr2"));
95         RETURN_IF_EXCEPTION(throwScope, { });
96     }
97     if (!attr2Value.isUndefined()) {
98         result.attr2 = convert<IDLDOMString>(state, attr2Value);
99         RETURN_IF_EXCEPTION(throwScope, { });
100     } else
101         result.attr2 = emptyString();
102     JSValue attr3Value;
103     if (isNullOrUndefined)
104         attr3Value = jsUndefined();
105     else {
106         attr3Value = object->get(&state, Identifier::fromString(&state, "attr3"));
107         RETURN_IF_EXCEPTION(throwScope, { });
108     }
109     if (!attr3Value.isUndefined()) {
110         result.attr3 = convert<IDLDOMString>(state, attr3Value);
111         RETURN_IF_EXCEPTION(throwScope, { });
112     } else
113         result.attr3 = emptyString();
114     return result;
115 }
116
117 // Attributes
118
119 JSC::EncodedJSValue jsTestEventConstructorConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
120 bool setJSTestEventConstructorConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
121 JSC::EncodedJSValue jsTestEventConstructorAttr1(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
122 JSC::EncodedJSValue jsTestEventConstructorAttr2(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
123 #if ENABLE(SPECIAL_EVENT)
124 JSC::EncodedJSValue jsTestEventConstructorAttr3(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
125 #endif
126
127 class JSTestEventConstructorPrototype : public JSC::JSNonFinalObject {
128 public:
129     using Base = JSC::JSNonFinalObject;
130     static JSTestEventConstructorPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
131     {
132         JSTestEventConstructorPrototype* ptr = new (NotNull, JSC::allocateCell<JSTestEventConstructorPrototype>(vm.heap)) JSTestEventConstructorPrototype(vm, globalObject, structure);
133         ptr->finishCreation(vm);
134         return ptr;
135     }
136
137     DECLARE_INFO;
138     static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
139     {
140         return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
141     }
142
143 private:
144     JSTestEventConstructorPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
145         : JSC::JSNonFinalObject(vm, structure)
146     {
147     }
148
149     void finishCreation(JSC::VM&);
150 };
151
152 using JSTestEventConstructorConstructor = JSDOMConstructor<JSTestEventConstructor>;
153
154 template<> EncodedJSValue JSC_HOST_CALL JSTestEventConstructorConstructor::construct(ExecState* state)
155 {
156     VM& vm = state->vm();
157     auto throwScope = DECLARE_THROW_SCOPE(vm);
158     UNUSED_PARAM(throwScope);
159     auto* castedThis = jsCast<JSTestEventConstructorConstructor*>(state->jsCallee());
160     ASSERT(castedThis);
161     if (UNLIKELY(state->argumentCount() < 1))
162         return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
163     auto type = convert<IDLDOMString>(*state, state->uncheckedArgument(0));
164     RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
165     auto eventInitDict = convert<IDLDictionary<TestEventConstructor::Init>>(*state, state->argument(1));
166     RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
167     auto object = TestEventConstructor::create(WTFMove(type), WTFMove(eventInitDict));
168     return JSValue::encode(toJSNewlyCreated<IDLInterface<TestEventConstructor>>(*state, *castedThis->globalObject(), WTFMove(object)));
169 }
170
171 template<> JSValue JSTestEventConstructorConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
172 {
173     return JSEvent::getConstructor(vm, &globalObject);
174 }
175
176 template<> void JSTestEventConstructorConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
177 {
178     putDirect(vm, vm.propertyNames->prototype, JSTestEventConstructor::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
179     putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("TestEventConstructor"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
180     putDirect(vm, vm.propertyNames->length, jsNumber(1), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
181 }
182
183 template<> const ClassInfo JSTestEventConstructorConstructor::s_info = { "TestEventConstructor", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestEventConstructorConstructor) };
184
185 /* Hash table for prototype */
186
187 static const HashTableValue JSTestEventConstructorPrototypeTableValues[] =
188 {
189     { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestEventConstructorConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestEventConstructorConstructor) } },
190     { "attr1", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestEventConstructorAttr1), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
191     { "attr2", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestEventConstructorAttr2), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
192 #if ENABLE(SPECIAL_EVENT)
193     { "attr3", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestEventConstructorAttr3), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
194 #else
195     { 0, 0, NoIntrinsic, { 0, 0 } },
196 #endif
197 };
198
199 const ClassInfo JSTestEventConstructorPrototype::s_info = { "TestEventConstructorPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestEventConstructorPrototype) };
200
201 void JSTestEventConstructorPrototype::finishCreation(VM& vm)
202 {
203     Base::finishCreation(vm);
204     reifyStaticProperties(vm, JSTestEventConstructor::info(), JSTestEventConstructorPrototypeTableValues, *this);
205 }
206
207 const ClassInfo JSTestEventConstructor::s_info = { "TestEventConstructor", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestEventConstructor) };
208
209 JSTestEventConstructor::JSTestEventConstructor(Structure* structure, JSDOMGlobalObject& globalObject, Ref<TestEventConstructor>&& impl)
210     : JSEvent(structure, globalObject, WTFMove(impl))
211 {
212 }
213
214 void JSTestEventConstructor::finishCreation(VM& vm)
215 {
216     Base::finishCreation(vm);
217     ASSERT(inherits(vm, info()));
218
219 }
220
221 JSObject* JSTestEventConstructor::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
222 {
223     return JSTestEventConstructorPrototype::create(vm, &globalObject, JSTestEventConstructorPrototype::createStructure(vm, &globalObject, JSEvent::prototype(vm, globalObject)));
224 }
225
226 JSObject* JSTestEventConstructor::prototype(VM& vm, JSDOMGlobalObject& globalObject)
227 {
228     return getDOMPrototype<JSTestEventConstructor>(vm, globalObject);
229 }
230
231 JSValue JSTestEventConstructor::getConstructor(VM& vm, const JSGlobalObject* globalObject)
232 {
233     return getDOMConstructor<JSTestEventConstructorConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
234 }
235
236 template<> inline JSTestEventConstructor* IDLAttribute<JSTestEventConstructor>::cast(ExecState& state, EncodedJSValue thisValue)
237 {
238     return jsDynamicCast<JSTestEventConstructor*>(state.vm(), JSValue::decode(thisValue));
239 }
240
241 EncodedJSValue jsTestEventConstructorConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
242 {
243     VM& vm = state->vm();
244     auto throwScope = DECLARE_THROW_SCOPE(vm);
245     auto* prototype = jsDynamicCast<JSTestEventConstructorPrototype*>(vm, JSValue::decode(thisValue));
246     if (UNLIKELY(!prototype))
247         return throwVMTypeError(state, throwScope);
248     return JSValue::encode(JSTestEventConstructor::getConstructor(state->vm(), prototype->globalObject()));
249 }
250
251 bool setJSTestEventConstructorConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
252 {
253     VM& vm = state->vm();
254     auto throwScope = DECLARE_THROW_SCOPE(vm);
255     auto* prototype = jsDynamicCast<JSTestEventConstructorPrototype*>(vm, JSValue::decode(thisValue));
256     if (UNLIKELY(!prototype)) {
257         throwVMTypeError(state, throwScope);
258         return false;
259     }
260     // Shadowing a built-in constructor
261     return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
262 }
263
264 static inline JSValue jsTestEventConstructorAttr1Getter(ExecState& state, JSTestEventConstructor& thisObject, ThrowScope& throwScope)
265 {
266     UNUSED_PARAM(throwScope);
267     UNUSED_PARAM(state);
268     auto& impl = thisObject.wrapped();
269     JSValue result = toJS<IDLDOMString>(state, throwScope, impl.attr1());
270     return result;
271 }
272
273 EncodedJSValue jsTestEventConstructorAttr1(ExecState* state, EncodedJSValue thisValue, PropertyName)
274 {
275     return IDLAttribute<JSTestEventConstructor>::get<jsTestEventConstructorAttr1Getter, CastedThisErrorBehavior::Assert>(*state, thisValue, "attr1");
276 }
277
278 static inline JSValue jsTestEventConstructorAttr2Getter(ExecState& state, JSTestEventConstructor& thisObject, ThrowScope& throwScope)
279 {
280     UNUSED_PARAM(throwScope);
281     UNUSED_PARAM(state);
282     auto& impl = thisObject.wrapped();
283     JSValue result = toJS<IDLDOMString>(state, throwScope, impl.attr2());
284     return result;
285 }
286
287 EncodedJSValue jsTestEventConstructorAttr2(ExecState* state, EncodedJSValue thisValue, PropertyName)
288 {
289     return IDLAttribute<JSTestEventConstructor>::get<jsTestEventConstructorAttr2Getter, CastedThisErrorBehavior::Assert>(*state, thisValue, "attr2");
290 }
291
292 #if ENABLE(SPECIAL_EVENT)
293 static inline JSValue jsTestEventConstructorAttr3Getter(ExecState& state, JSTestEventConstructor& thisObject, ThrowScope& throwScope)
294 {
295     UNUSED_PARAM(throwScope);
296     UNUSED_PARAM(state);
297     auto& impl = thisObject.wrapped();
298     JSValue result = toJS<IDLDOMString>(state, throwScope, impl.attr3());
299     return result;
300 }
301
302 EncodedJSValue jsTestEventConstructorAttr3(ExecState* state, EncodedJSValue thisValue, PropertyName)
303 {
304     return IDLAttribute<JSTestEventConstructor>::get<jsTestEventConstructorAttr3Getter, CastedThisErrorBehavior::Assert>(*state, thisValue, "attr3");
305 }
306
307 #endif
308
309 void JSTestEventConstructor::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
310 {
311     auto* thisObject = jsCast<JSTestEventConstructor*>(cell);
312     builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
313     if (thisObject->scriptExecutionContext())
314         builder.setLabelForCell(cell, String::format("url %s", thisObject->scriptExecutionContext()->url().string().utf8().data()));
315     Base::heapSnapshot(cell, builder);
316 }
317
318 #if ENABLE(BINDING_INTEGRITY)
319 #if PLATFORM(WIN)
320 #pragma warning(disable: 4483)
321 extern "C" { extern void (*const __identifier("??_7TestEventConstructor@WebCore@@6B@")[])(); }
322 #else
323 extern "C" { extern void* _ZTVN7WebCore20TestEventConstructorE[]; }
324 #endif
325 #endif
326
327 JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<TestEventConstructor>&& impl)
328 {
329
330 #if ENABLE(BINDING_INTEGRITY)
331     void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
332 #if PLATFORM(WIN)
333     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7TestEventConstructor@WebCore@@6B@"));
334 #else
335     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore20TestEventConstructorE[2]);
336 #endif
337
338     // If this fails TestEventConstructor does not have a vtable, so you need to add the
339     // ImplementationLacksVTable attribute to the interface definition
340     static_assert(std::is_polymorphic<TestEventConstructor>::value, "TestEventConstructor is not polymorphic");
341
342     // If you hit this assertion you either have a use after free bug, or
343     // TestEventConstructor has subclasses. If TestEventConstructor has subclasses that get passed
344     // to toJS() we currently require TestEventConstructor you to opt out of binding hardening
345     // by adding the SkipVTableValidation attribute to the interface IDL definition
346     RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
347 #endif
348     return createWrapper<TestEventConstructor>(globalObject, WTFMove(impl));
349 }
350
351 JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, TestEventConstructor& impl)
352 {
353     return wrap(state, globalObject, impl);
354 }
355
356
357 }