0dcf4aff716f24cb3054332c98fab79afd551166
[WebKit.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         didBecomePrototype();
148     }
149
150     void finishCreation(JSC::VM&);
151 };
152
153 using JSTestEventConstructorConstructor = JSDOMConstructor<JSTestEventConstructor>;
154
155 template<> EncodedJSValue JSC_HOST_CALL JSTestEventConstructorConstructor::construct(ExecState* state)
156 {
157     VM& vm = state->vm();
158     auto throwScope = DECLARE_THROW_SCOPE(vm);
159     UNUSED_PARAM(throwScope);
160     auto* castedThis = jsCast<JSTestEventConstructorConstructor*>(state->jsCallee());
161     ASSERT(castedThis);
162     if (UNLIKELY(state->argumentCount() < 1))
163         return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
164     auto type = convert<IDLDOMString>(*state, state->uncheckedArgument(0));
165     RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
166     auto eventInitDict = convert<IDLDictionary<TestEventConstructor::Init>>(*state, state->argument(1));
167     RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
168     auto object = TestEventConstructor::create(WTFMove(type), WTFMove(eventInitDict));
169     return JSValue::encode(toJSNewlyCreated<IDLInterface<TestEventConstructor>>(*state, *castedThis->globalObject(), WTFMove(object)));
170 }
171
172 template<> JSValue JSTestEventConstructorConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
173 {
174     auto result = JSEvent::getConstructor(vm, &globalObject);
175     result.getObject()->didBecomePrototype();
176     return result;
177 }
178
179 template<> void JSTestEventConstructorConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
180 {
181     putDirect(vm, vm.propertyNames->prototype, JSTestEventConstructor::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
182     putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("TestEventConstructor"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
183     putDirect(vm, vm.propertyNames->length, jsNumber(1), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
184 }
185
186 template<> const ClassInfo JSTestEventConstructorConstructor::s_info = { "TestEventConstructor", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestEventConstructorConstructor) };
187
188 /* Hash table for prototype */
189
190 static const HashTableValue JSTestEventConstructorPrototypeTableValues[] =
191 {
192     { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestEventConstructorConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestEventConstructorConstructor) } },
193     { "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) } },
194     { "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) } },
195 #if ENABLE(SPECIAL_EVENT)
196     { "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) } },
197 #else
198     { 0, 0, NoIntrinsic, { 0, 0 } },
199 #endif
200 };
201
202 const ClassInfo JSTestEventConstructorPrototype::s_info = { "TestEventConstructorPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestEventConstructorPrototype) };
203
204 void JSTestEventConstructorPrototype::finishCreation(VM& vm)
205 {
206     Base::finishCreation(vm);
207     reifyStaticProperties(vm, JSTestEventConstructor::info(), JSTestEventConstructorPrototypeTableValues, *this);
208 }
209
210 const ClassInfo JSTestEventConstructor::s_info = { "TestEventConstructor", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestEventConstructor) };
211
212 JSTestEventConstructor::JSTestEventConstructor(Structure* structure, JSDOMGlobalObject& globalObject, Ref<TestEventConstructor>&& impl)
213     : JSEvent(structure, globalObject, WTFMove(impl))
214 {
215 }
216
217 void JSTestEventConstructor::finishCreation(VM& vm)
218 {
219     Base::finishCreation(vm);
220     ASSERT(inherits(vm, info()));
221
222 }
223
224 JSObject* JSTestEventConstructor::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
225 {
226     return JSTestEventConstructorPrototype::create(vm, &globalObject, JSTestEventConstructorPrototype::createStructure(vm, &globalObject, JSEvent::prototype(vm, globalObject)));
227 }
228
229 JSObject* JSTestEventConstructor::prototype(VM& vm, JSDOMGlobalObject& globalObject)
230 {
231     return getDOMPrototype<JSTestEventConstructor>(vm, globalObject);
232 }
233
234 JSValue JSTestEventConstructor::getConstructor(VM& vm, const JSGlobalObject* globalObject)
235 {
236     return getDOMConstructor<JSTestEventConstructorConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
237 }
238
239 template<> inline JSTestEventConstructor* IDLAttribute<JSTestEventConstructor>::cast(ExecState& state, EncodedJSValue thisValue)
240 {
241     return jsDynamicCast<JSTestEventConstructor*>(state.vm(), JSValue::decode(thisValue));
242 }
243
244 EncodedJSValue jsTestEventConstructorConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
245 {
246     VM& vm = state->vm();
247     auto throwScope = DECLARE_THROW_SCOPE(vm);
248     auto* prototype = jsDynamicCast<JSTestEventConstructorPrototype*>(vm, JSValue::decode(thisValue));
249     if (UNLIKELY(!prototype))
250         return throwVMTypeError(state, throwScope);
251     return JSValue::encode(JSTestEventConstructor::getConstructor(state->vm(), prototype->globalObject()));
252 }
253
254 bool setJSTestEventConstructorConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
255 {
256     VM& vm = state->vm();
257     auto throwScope = DECLARE_THROW_SCOPE(vm);
258     auto* prototype = jsDynamicCast<JSTestEventConstructorPrototype*>(vm, JSValue::decode(thisValue));
259     if (UNLIKELY(!prototype)) {
260         throwVMTypeError(state, throwScope);
261         return false;
262     }
263     // Shadowing a built-in constructor
264     return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
265 }
266
267 static inline JSValue jsTestEventConstructorAttr1Getter(ExecState& state, JSTestEventConstructor& thisObject, ThrowScope& throwScope)
268 {
269     UNUSED_PARAM(throwScope);
270     UNUSED_PARAM(state);
271     auto& impl = thisObject.wrapped();
272     JSValue result = toJS<IDLDOMString>(state, throwScope, impl.attr1());
273     return result;
274 }
275
276 EncodedJSValue jsTestEventConstructorAttr1(ExecState* state, EncodedJSValue thisValue, PropertyName)
277 {
278     return IDLAttribute<JSTestEventConstructor>::get<jsTestEventConstructorAttr1Getter, CastedThisErrorBehavior::Assert>(*state, thisValue, "attr1");
279 }
280
281 static inline JSValue jsTestEventConstructorAttr2Getter(ExecState& state, JSTestEventConstructor& thisObject, ThrowScope& throwScope)
282 {
283     UNUSED_PARAM(throwScope);
284     UNUSED_PARAM(state);
285     auto& impl = thisObject.wrapped();
286     JSValue result = toJS<IDLDOMString>(state, throwScope, impl.attr2());
287     return result;
288 }
289
290 EncodedJSValue jsTestEventConstructorAttr2(ExecState* state, EncodedJSValue thisValue, PropertyName)
291 {
292     return IDLAttribute<JSTestEventConstructor>::get<jsTestEventConstructorAttr2Getter, CastedThisErrorBehavior::Assert>(*state, thisValue, "attr2");
293 }
294
295 #if ENABLE(SPECIAL_EVENT)
296 static inline JSValue jsTestEventConstructorAttr3Getter(ExecState& state, JSTestEventConstructor& thisObject, ThrowScope& throwScope)
297 {
298     UNUSED_PARAM(throwScope);
299     UNUSED_PARAM(state);
300     auto& impl = thisObject.wrapped();
301     JSValue result = toJS<IDLDOMString>(state, throwScope, impl.attr3());
302     return result;
303 }
304
305 EncodedJSValue jsTestEventConstructorAttr3(ExecState* state, EncodedJSValue thisValue, PropertyName)
306 {
307     return IDLAttribute<JSTestEventConstructor>::get<jsTestEventConstructorAttr3Getter, CastedThisErrorBehavior::Assert>(*state, thisValue, "attr3");
308 }
309
310 #endif
311
312 void JSTestEventConstructor::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
313 {
314     auto* thisObject = jsCast<JSTestEventConstructor*>(cell);
315     builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
316     if (thisObject->scriptExecutionContext())
317         builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
318     Base::heapSnapshot(cell, builder);
319 }
320
321 #if ENABLE(BINDING_INTEGRITY)
322 #if PLATFORM(WIN)
323 #pragma warning(disable: 4483)
324 extern "C" { extern void (*const __identifier("??_7TestEventConstructor@WebCore@@6B@")[])(); }
325 #else
326 extern "C" { extern void* _ZTVN7WebCore20TestEventConstructorE[]; }
327 #endif
328 #endif
329
330 JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<TestEventConstructor>&& impl)
331 {
332
333 #if ENABLE(BINDING_INTEGRITY)
334     void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
335 #if PLATFORM(WIN)
336     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7TestEventConstructor@WebCore@@6B@"));
337 #else
338     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore20TestEventConstructorE[2]);
339 #endif
340
341     // If this fails TestEventConstructor does not have a vtable, so you need to add the
342     // ImplementationLacksVTable attribute to the interface definition
343     static_assert(std::is_polymorphic<TestEventConstructor>::value, "TestEventConstructor is not polymorphic");
344
345     // If you hit this assertion you either have a use after free bug, or
346     // TestEventConstructor has subclasses. If TestEventConstructor has subclasses that get passed
347     // to toJS() we currently require TestEventConstructor you to opt out of binding hardening
348     // by adding the SkipVTableValidation attribute to the interface IDL definition
349     RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
350 #endif
351     return createWrapper<TestEventConstructor>(globalObject, WTFMove(impl));
352 }
353
354 JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, TestEventConstructor& impl)
355 {
356     return wrap(state, globalObject, impl);
357 }
358
359
360 }