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