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
23#if ENABLE(SERVICE_WORKER)
24
25#include "JSExtendableEvent.h"
26
27#include "DOMPromiseProxy.h"
28#include "JSDOMBinding.h"
29#include "JSDOMConstructor.h"
30#include "JSDOMConvertAny.h"
31#include "JSDOMConvertInterface.h"
32#include "JSDOMConvertPromise.h"
33#include "JSDOMExceptionHandling.h"
34#include "JSDOMOperation.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#if ENABLE(SERVICE_WORKER)
44#include "JSDOMConvertDictionary.h"
45#include "JSDOMConvertStrings.h"
46#include "JSExtendableEventInit.h"
47#endif
48
49
50namespace WebCore {
51using namespace JSC;
52
53// Functions
54
55JSC::EncodedJSValue JSC_HOST_CALL jsExtendableEventPrototypeFunctionWaitUntil(JSC::ExecState*);
56
57// Attributes
58
59JSC::EncodedJSValue jsExtendableEventConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
60bool setJSExtendableEventConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
61
62class JSExtendableEventPrototype : public JSC::JSNonFinalObject {
63public:
64 using Base = JSC::JSNonFinalObject;
65 static JSExtendableEventPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
66 {
67 JSExtendableEventPrototype* ptr = new (NotNull, JSC::allocateCell<JSExtendableEventPrototype>(vm.heap)) JSExtendableEventPrototype(vm, globalObject, structure);
68 ptr->finishCreation(vm);
69 return ptr;
70 }
71
72 DECLARE_INFO;
73 static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
74 {
75 return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
76 }
77
78private:
79 JSExtendableEventPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
80 : JSC::JSNonFinalObject(vm, structure)
81 {
82 }
83
84 void finishCreation(JSC::VM&);
85};
86
87using JSExtendableEventConstructor = JSDOMConstructor<JSExtendableEvent>;
88
89template<> EncodedJSValue JSC_HOST_CALL JSExtendableEventConstructor::construct(ExecState* state)
90{
91 VM& vm = state->vm();
92 auto throwScope = DECLARE_THROW_SCOPE(vm);
93 UNUSED_PARAM(throwScope);
94 auto* castedThis = jsCast<JSExtendableEventConstructor*>(state->jsCallee());
95 ASSERT(castedThis);
96 if (UNLIKELY(state->argumentCount() < 1))
97 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
98 auto type = convert<IDLDOMString>(*state, state->uncheckedArgument(0));
99 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
100 auto eventInitDict = convert<IDLDictionary<ExtendableEventInit>>(*state, state->argument(1));
101 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
102 auto object = ExtendableEvent::create(WTFMove(type), WTFMove(eventInitDict));
103 return JSValue::encode(toJSNewlyCreated<IDLInterface<ExtendableEvent>>(*state, *castedThis->globalObject(), WTFMove(object)));
104}
105
106template<> JSValue JSExtendableEventConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
107{
108 return JSEvent::getConstructor(vm, &globalObject);
109}
110
111template<> void JSExtendableEventConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
112{
113 putDirect(vm, vm.propertyNames->prototype, JSExtendableEvent::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
114 putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("ExtendableEvent"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
115 putDirect(vm, vm.propertyNames->length, jsNumber(1), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
116}
117
118template<> const ClassInfo JSExtendableEventConstructor::s_info = { "ExtendableEvent", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSExtendableEventConstructor) };
119
120/* Hash table for prototype */
121
122static const HashTableValue JSExtendableEventPrototypeTableValues[] =
123{
124 { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsExtendableEventConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSExtendableEventConstructor) } },
125 { "waitUntil", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsExtendableEventPrototypeFunctionWaitUntil), (intptr_t) (1) } },
126};
127
128const ClassInfo JSExtendableEventPrototype::s_info = { "ExtendableEventPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSExtendableEventPrototype) };
129
130void JSExtendableEventPrototype::finishCreation(VM& vm)
131{
132 Base::finishCreation(vm);
133 reifyStaticProperties(vm, JSExtendableEvent::info(), JSExtendableEventPrototypeTableValues, *this);
134}
135
136const ClassInfo JSExtendableEvent::s_info = { "ExtendableEvent", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSExtendableEvent) };
137
138JSExtendableEvent::JSExtendableEvent(Structure* structure, JSDOMGlobalObject& globalObject, Ref<ExtendableEvent>&& impl)
139 : JSEvent(structure, globalObject, WTFMove(impl))
140{
141}
142
143void JSExtendableEvent::finishCreation(VM& vm)
144{
145 Base::finishCreation(vm);
146 ASSERT(inherits(vm, info()));
147
148}
149
150JSObject* JSExtendableEvent::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
151{
152 return JSExtendableEventPrototype::create(vm, &globalObject, JSExtendableEventPrototype::createStructure(vm, &globalObject, JSEvent::prototype(vm, globalObject)));
153}
154
155JSObject* JSExtendableEvent::prototype(VM& vm, JSDOMGlobalObject& globalObject)
156{
157 return getDOMPrototype<JSExtendableEvent>(vm, globalObject);
158}
159
160JSValue JSExtendableEvent::getConstructor(VM& vm, const JSGlobalObject* globalObject)
161{
162 return getDOMConstructor<JSExtendableEventConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
163}
164
165template<> inline JSExtendableEvent* IDLOperation<JSExtendableEvent>::cast(ExecState& state)
166{
167 return jsDynamicCast<JSExtendableEvent*>(state.vm(), state.thisValue());
168}
169
170EncodedJSValue jsExtendableEventConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
171{
172 VM& vm = state->vm();
173 auto throwScope = DECLARE_THROW_SCOPE(vm);
174 auto* prototype = jsDynamicCast<JSExtendableEventPrototype*>(vm, JSValue::decode(thisValue));
175 if (UNLIKELY(!prototype))
176 return throwVMTypeError(state, throwScope);
177 return JSValue::encode(JSExtendableEvent::getConstructor(state->vm(), prototype->globalObject()));
178}
179
180bool setJSExtendableEventConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
181{
182 VM& vm = state->vm();
183 auto throwScope = DECLARE_THROW_SCOPE(vm);
184 auto* prototype = jsDynamicCast<JSExtendableEventPrototype*>(vm, JSValue::decode(thisValue));
185 if (UNLIKELY(!prototype)) {
186 throwVMTypeError(state, throwScope);
187 return false;
188 }
189 // Shadowing a built-in constructor
190 return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
191}
192
193static inline JSC::EncodedJSValue jsExtendableEventPrototypeFunctionWaitUntilBody(JSC::ExecState* state, typename IDLOperation<JSExtendableEvent>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
194{
195 UNUSED_PARAM(state);
196 UNUSED_PARAM(throwScope);
197 auto& impl = castedThis->wrapped();
198 if (UNLIKELY(state->argumentCount() < 1))
199 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
200 auto f = convert<IDLPromise<IDLAny>>(*state, state->uncheckedArgument(0));
201 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
202 propagateException(*state, throwScope, impl.waitUntil(f.releaseNonNull()));
203 return JSValue::encode(jsUndefined());
204}
205
206EncodedJSValue JSC_HOST_CALL jsExtendableEventPrototypeFunctionWaitUntil(ExecState* state)
207{
208 return IDLOperation<JSExtendableEvent>::call<jsExtendableEventPrototypeFunctionWaitUntilBody>(*state, "waitUntil");
209}
210
211void JSExtendableEvent::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
212{
213 auto* thisObject = jsCast<JSExtendableEvent*>(cell);
214 builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
215 if (thisObject->scriptExecutionContext())
216 builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
217 Base::heapSnapshot(cell, builder);
218}
219
220#if ENABLE(BINDING_INTEGRITY)
221#if PLATFORM(WIN)
222#pragma warning(disable: 4483)
223extern "C" { extern void (*const __identifier("??_7ExtendableEvent@WebCore@@6B@")[])(); }
224#else
225extern "C" { extern void* _ZTVN7WebCore15ExtendableEventE[]; }
226#endif
227#endif
228
229JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<ExtendableEvent>&& impl)
230{
231
232#if ENABLE(BINDING_INTEGRITY)
233 void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
234#if PLATFORM(WIN)
235 void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7ExtendableEvent@WebCore@@6B@"));
236#else
237 void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore15ExtendableEventE[2]);
238#endif
239
240 // If this fails ExtendableEvent does not have a vtable, so you need to add the
241 // ImplementationLacksVTable attribute to the interface definition
242 static_assert(std::is_polymorphic<ExtendableEvent>::value, "ExtendableEvent is not polymorphic");
243
244 // If you hit this assertion you either have a use after free bug, or
245 // ExtendableEvent has subclasses. If ExtendableEvent has subclasses that get passed
246 // to toJS() we currently require ExtendableEvent you to opt out of binding hardening
247 // by adding the SkipVTableValidation attribute to the interface IDL definition
248 RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
249#endif
250 return createWrapper<ExtendableEvent>(globalObject, WTFMove(impl));
251}
252
253JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, ExtendableEvent& impl)
254{
255 return wrap(state, globalObject, impl);
256}
257
258ExtendableEvent* JSExtendableEvent::toWrapped(JSC::VM& vm, JSC::JSValue value)
259{
260 if (auto* wrapper = jsDynamicCast<JSExtendableEvent*>(vm, value))
261 return &wrapper->wrapped();
262 return nullptr;
263}
264
265}
266
267#endif // ENABLE(SERVICE_WORKER)
268