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 "JSFetchEvent.h"
26
27#include "DOMPromiseProxy.h"
28#include "JSDOMAttribute.h"
29#include "JSDOMBinding.h"
30#include "JSDOMConstructor.h"
31#include "JSDOMConvertBoolean.h"
32#include "JSDOMConvertInterface.h"
33#include "JSDOMConvertPromise.h"
34#include "JSDOMConvertStrings.h"
35#include "JSDOMExceptionHandling.h"
36#include "JSDOMGlobalObject.h"
37#include "JSDOMOperation.h"
38#include "JSDOMWrapperCache.h"
39#include "JSFetchRequest.h"
40#include "JSFetchResponse.h"
41#include "ScriptExecutionContext.h"
42#include <JavaScriptCore/HeapSnapshotBuilder.h>
43#include <JavaScriptCore/JSCInlines.h>
44#include <wtf/GetPtr.h>
45#include <wtf/PointerPreparations.h>
46#include <wtf/URL.h>
47
48
49namespace WebCore {
50using namespace JSC;
51
52template<> FetchEvent::Init convertDictionary<FetchEvent::Init>(ExecState& state, JSValue value)
53{
54 VM& vm = state.vm();
55 auto throwScope = DECLARE_THROW_SCOPE(vm);
56 bool isNullOrUndefined = value.isUndefinedOrNull();
57 auto* object = isNullOrUndefined ? nullptr : value.getObject();
58 if (UNLIKELY(!isNullOrUndefined && !object)) {
59 throwTypeError(&state, throwScope);
60 return { };
61 }
62 FetchEvent::Init result;
63 JSValue bubblesValue;
64 if (isNullOrUndefined)
65 bubblesValue = jsUndefined();
66 else {
67 bubblesValue = object->get(&state, Identifier::fromString(&state, "bubbles"));
68 RETURN_IF_EXCEPTION(throwScope, { });
69 }
70 if (!bubblesValue.isUndefined()) {
71 result.bubbles = convert<IDLBoolean>(state, bubblesValue);
72 RETURN_IF_EXCEPTION(throwScope, { });
73 } else
74 result.bubbles = false;
75 JSValue cancelableValue;
76 if (isNullOrUndefined)
77 cancelableValue = jsUndefined();
78 else {
79 cancelableValue = object->get(&state, Identifier::fromString(&state, "cancelable"));
80 RETURN_IF_EXCEPTION(throwScope, { });
81 }
82 if (!cancelableValue.isUndefined()) {
83 result.cancelable = convert<IDLBoolean>(state, cancelableValue);
84 RETURN_IF_EXCEPTION(throwScope, { });
85 } else
86 result.cancelable = false;
87 JSValue composedValue;
88 if (isNullOrUndefined)
89 composedValue = jsUndefined();
90 else {
91 composedValue = object->get(&state, Identifier::fromString(&state, "composed"));
92 RETURN_IF_EXCEPTION(throwScope, { });
93 }
94 if (!composedValue.isUndefined()) {
95 result.composed = convert<IDLBoolean>(state, composedValue);
96 RETURN_IF_EXCEPTION(throwScope, { });
97 } else
98 result.composed = false;
99 JSValue clientIdValue;
100 if (isNullOrUndefined)
101 clientIdValue = jsUndefined();
102 else {
103 clientIdValue = object->get(&state, Identifier::fromString(&state, "clientId"));
104 RETURN_IF_EXCEPTION(throwScope, { });
105 }
106 if (!clientIdValue.isUndefined()) {
107 result.clientId = convert<IDLDOMString>(state, clientIdValue);
108 RETURN_IF_EXCEPTION(throwScope, { });
109 } else
110 result.clientId = emptyString();
111 JSValue requestValue;
112 if (isNullOrUndefined)
113 requestValue = jsUndefined();
114 else {
115 requestValue = object->get(&state, Identifier::fromString(&state, "request"));
116 RETURN_IF_EXCEPTION(throwScope, { });
117 }
118 if (!requestValue.isUndefined()) {
119 result.request = convert<IDLInterface<FetchRequest>>(state, requestValue);
120 RETURN_IF_EXCEPTION(throwScope, { });
121 } else {
122 throwRequiredMemberTypeError(state, throwScope, "request", "FetchEventInit", "FetchRequest");
123 return { };
124 }
125 JSValue reservedClientIdValue;
126 if (isNullOrUndefined)
127 reservedClientIdValue = jsUndefined();
128 else {
129 reservedClientIdValue = object->get(&state, Identifier::fromString(&state, "reservedClientId"));
130 RETURN_IF_EXCEPTION(throwScope, { });
131 }
132 if (!reservedClientIdValue.isUndefined()) {
133 result.reservedClientId = convert<IDLDOMString>(state, reservedClientIdValue);
134 RETURN_IF_EXCEPTION(throwScope, { });
135 } else
136 result.reservedClientId = emptyString();
137 JSValue targetClientIdValue;
138 if (isNullOrUndefined)
139 targetClientIdValue = jsUndefined();
140 else {
141 targetClientIdValue = object->get(&state, Identifier::fromString(&state, "targetClientId"));
142 RETURN_IF_EXCEPTION(throwScope, { });
143 }
144 if (!targetClientIdValue.isUndefined()) {
145 result.targetClientId = convert<IDLDOMString>(state, targetClientIdValue);
146 RETURN_IF_EXCEPTION(throwScope, { });
147 } else
148 result.targetClientId = emptyString();
149 return result;
150}
151
152// Functions
153
154JSC::EncodedJSValue JSC_HOST_CALL jsFetchEventPrototypeFunctionRespondWith(JSC::ExecState*);
155
156// Attributes
157
158JSC::EncodedJSValue jsFetchEventConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
159bool setJSFetchEventConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
160JSC::EncodedJSValue jsFetchEventRequest(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
161JSC::EncodedJSValue jsFetchEventClientId(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
162JSC::EncodedJSValue jsFetchEventReservedClientId(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
163JSC::EncodedJSValue jsFetchEventTargetClientId(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
164
165class JSFetchEventPrototype : public JSC::JSNonFinalObject {
166public:
167 using Base = JSC::JSNonFinalObject;
168 static JSFetchEventPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
169 {
170 JSFetchEventPrototype* ptr = new (NotNull, JSC::allocateCell<JSFetchEventPrototype>(vm.heap)) JSFetchEventPrototype(vm, globalObject, structure);
171 ptr->finishCreation(vm);
172 return ptr;
173 }
174
175 DECLARE_INFO;
176 static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
177 {
178 return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
179 }
180
181private:
182 JSFetchEventPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
183 : JSC::JSNonFinalObject(vm, structure)
184 {
185 }
186
187 void finishCreation(JSC::VM&);
188};
189
190using JSFetchEventConstructor = JSDOMConstructor<JSFetchEvent>;
191
192template<> EncodedJSValue JSC_HOST_CALL JSFetchEventConstructor::construct(ExecState* state)
193{
194 VM& vm = state->vm();
195 auto throwScope = DECLARE_THROW_SCOPE(vm);
196 UNUSED_PARAM(throwScope);
197 auto* castedThis = jsCast<JSFetchEventConstructor*>(state->jsCallee());
198 ASSERT(castedThis);
199 if (UNLIKELY(state->argumentCount() < 2))
200 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
201 auto type = convert<IDLDOMString>(*state, state->uncheckedArgument(0));
202 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
203 auto eventInitDict = convert<IDLDictionary<FetchEvent::Init>>(*state, state->uncheckedArgument(1));
204 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
205 auto object = FetchEvent::create(WTFMove(type), WTFMove(eventInitDict));
206 return JSValue::encode(toJSNewlyCreated<IDLInterface<FetchEvent>>(*state, *castedThis->globalObject(), WTFMove(object)));
207}
208
209template<> JSValue JSFetchEventConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
210{
211 return JSExtendableEvent::getConstructor(vm, &globalObject);
212}
213
214template<> void JSFetchEventConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
215{
216 putDirect(vm, vm.propertyNames->prototype, JSFetchEvent::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
217 putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("FetchEvent"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
218 putDirect(vm, vm.propertyNames->length, jsNumber(2), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
219}
220
221template<> const ClassInfo JSFetchEventConstructor::s_info = { "FetchEvent", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSFetchEventConstructor) };
222
223/* Hash table for prototype */
224
225static const HashTableValue JSFetchEventPrototypeTableValues[] =
226{
227 { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFetchEventConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSFetchEventConstructor) } },
228 { "request", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFetchEventRequest), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
229 { "clientId", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFetchEventClientId), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
230 { "reservedClientId", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFetchEventReservedClientId), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
231 { "targetClientId", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFetchEventTargetClientId), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
232 { "respondWith", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsFetchEventPrototypeFunctionRespondWith), (intptr_t) (1) } },
233};
234
235const ClassInfo JSFetchEventPrototype::s_info = { "FetchEventPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSFetchEventPrototype) };
236
237void JSFetchEventPrototype::finishCreation(VM& vm)
238{
239 Base::finishCreation(vm);
240 reifyStaticProperties(vm, JSFetchEvent::info(), JSFetchEventPrototypeTableValues, *this);
241}
242
243const ClassInfo JSFetchEvent::s_info = { "FetchEvent", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSFetchEvent) };
244
245JSFetchEvent::JSFetchEvent(Structure* structure, JSDOMGlobalObject& globalObject, Ref<FetchEvent>&& impl)
246 : JSExtendableEvent(structure, globalObject, WTFMove(impl))
247{
248}
249
250void JSFetchEvent::finishCreation(VM& vm)
251{
252 Base::finishCreation(vm);
253 ASSERT(inherits(vm, info()));
254
255}
256
257JSObject* JSFetchEvent::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
258{
259 return JSFetchEventPrototype::create(vm, &globalObject, JSFetchEventPrototype::createStructure(vm, &globalObject, JSExtendableEvent::prototype(vm, globalObject)));
260}
261
262JSObject* JSFetchEvent::prototype(VM& vm, JSDOMGlobalObject& globalObject)
263{
264 return getDOMPrototype<JSFetchEvent>(vm, globalObject);
265}
266
267JSValue JSFetchEvent::getConstructor(VM& vm, const JSGlobalObject* globalObject)
268{
269 return getDOMConstructor<JSFetchEventConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
270}
271
272template<> inline JSFetchEvent* IDLAttribute<JSFetchEvent>::cast(ExecState& state, EncodedJSValue thisValue)
273{
274 return jsDynamicCast<JSFetchEvent*>(state.vm(), JSValue::decode(thisValue));
275}
276
277template<> inline JSFetchEvent* IDLOperation<JSFetchEvent>::cast(ExecState& state)
278{
279 return jsDynamicCast<JSFetchEvent*>(state.vm(), state.thisValue());
280}
281
282EncodedJSValue jsFetchEventConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
283{
284 VM& vm = state->vm();
285 auto throwScope = DECLARE_THROW_SCOPE(vm);
286 auto* prototype = jsDynamicCast<JSFetchEventPrototype*>(vm, JSValue::decode(thisValue));
287 if (UNLIKELY(!prototype))
288 return throwVMTypeError(state, throwScope);
289 return JSValue::encode(JSFetchEvent::getConstructor(state->vm(), prototype->globalObject()));
290}
291
292bool setJSFetchEventConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
293{
294 VM& vm = state->vm();
295 auto throwScope = DECLARE_THROW_SCOPE(vm);
296 auto* prototype = jsDynamicCast<JSFetchEventPrototype*>(vm, JSValue::decode(thisValue));
297 if (UNLIKELY(!prototype)) {
298 throwVMTypeError(state, throwScope);
299 return false;
300 }
301 // Shadowing a built-in constructor
302 return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
303}
304
305static inline JSValue jsFetchEventRequestGetter(ExecState& state, JSFetchEvent& thisObject, ThrowScope& throwScope)
306{
307 UNUSED_PARAM(throwScope);
308 UNUSED_PARAM(state);
309 auto& impl = thisObject.wrapped();
310 JSValue result = toJS<IDLInterface<FetchRequest>>(state, *thisObject.globalObject(), throwScope, impl.request());
311 return result;
312}
313
314EncodedJSValue jsFetchEventRequest(ExecState* state, EncodedJSValue thisValue, PropertyName)
315{
316 return IDLAttribute<JSFetchEvent>::get<jsFetchEventRequestGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "request");
317}
318
319static inline JSValue jsFetchEventClientIdGetter(ExecState& state, JSFetchEvent& thisObject, ThrowScope& throwScope)
320{
321 UNUSED_PARAM(throwScope);
322 UNUSED_PARAM(state);
323 auto& impl = thisObject.wrapped();
324 JSValue result = toJS<IDLDOMString>(state, throwScope, impl.clientId());
325 return result;
326}
327
328EncodedJSValue jsFetchEventClientId(ExecState* state, EncodedJSValue thisValue, PropertyName)
329{
330 return IDLAttribute<JSFetchEvent>::get<jsFetchEventClientIdGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "clientId");
331}
332
333static inline JSValue jsFetchEventReservedClientIdGetter(ExecState& state, JSFetchEvent& thisObject, ThrowScope& throwScope)
334{
335 UNUSED_PARAM(throwScope);
336 UNUSED_PARAM(state);
337 auto& impl = thisObject.wrapped();
338 JSValue result = toJS<IDLDOMString>(state, throwScope, impl.reservedClientId());
339 return result;
340}
341
342EncodedJSValue jsFetchEventReservedClientId(ExecState* state, EncodedJSValue thisValue, PropertyName)
343{
344 return IDLAttribute<JSFetchEvent>::get<jsFetchEventReservedClientIdGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "reservedClientId");
345}
346
347static inline JSValue jsFetchEventTargetClientIdGetter(ExecState& state, JSFetchEvent& thisObject, ThrowScope& throwScope)
348{
349 UNUSED_PARAM(throwScope);
350 UNUSED_PARAM(state);
351 auto& impl = thisObject.wrapped();
352 JSValue result = toJS<IDLDOMString>(state, throwScope, impl.targetClientId());
353 return result;
354}
355
356EncodedJSValue jsFetchEventTargetClientId(ExecState* state, EncodedJSValue thisValue, PropertyName)
357{
358 return IDLAttribute<JSFetchEvent>::get<jsFetchEventTargetClientIdGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "targetClientId");
359}
360
361static inline JSC::EncodedJSValue jsFetchEventPrototypeFunctionRespondWithBody(JSC::ExecState* state, typename IDLOperation<JSFetchEvent>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
362{
363 UNUSED_PARAM(state);
364 UNUSED_PARAM(throwScope);
365 auto& impl = castedThis->wrapped();
366 if (UNLIKELY(state->argumentCount() < 1))
367 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
368 auto r = convert<IDLPromise<IDLInterface<FetchResponse>>>(*state, state->uncheckedArgument(0));
369 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
370 propagateException(*state, throwScope, impl.respondWith(r.releaseNonNull()));
371 return JSValue::encode(jsUndefined());
372}
373
374EncodedJSValue JSC_HOST_CALL jsFetchEventPrototypeFunctionRespondWith(ExecState* state)
375{
376 return IDLOperation<JSFetchEvent>::call<jsFetchEventPrototypeFunctionRespondWithBody>(*state, "respondWith");
377}
378
379void JSFetchEvent::visitChildren(JSCell* cell, SlotVisitor& visitor)
380{
381 auto* thisObject = jsCast<JSFetchEvent*>(cell);
382 ASSERT_GC_OBJECT_INHERITS(thisObject, info());
383 Base::visitChildren(thisObject, visitor);
384 thisObject->visitAdditionalChildren(visitor);
385}
386
387void JSFetchEvent::visitOutputConstraints(JSCell* cell, SlotVisitor& visitor)
388{
389 auto* thisObject = jsCast<JSFetchEvent*>(cell);
390 ASSERT_GC_OBJECT_INHERITS(thisObject, info());
391 Base::visitOutputConstraints(thisObject, visitor);
392 thisObject->visitAdditionalChildren(visitor);
393}
394
395void JSFetchEvent::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
396{
397 auto* thisObject = jsCast<JSFetchEvent*>(cell);
398 builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
399 if (thisObject->scriptExecutionContext())
400 builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
401 Base::heapSnapshot(cell, builder);
402}
403
404#if ENABLE(BINDING_INTEGRITY)
405#if PLATFORM(WIN)
406#pragma warning(disable: 4483)
407extern "C" { extern void (*const __identifier("??_7FetchEvent@WebCore@@6B@")[])(); }
408#else
409extern "C" { extern void* _ZTVN7WebCore10FetchEventE[]; }
410#endif
411#endif
412
413JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<FetchEvent>&& impl)
414{
415
416#if ENABLE(BINDING_INTEGRITY)
417 void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
418#if PLATFORM(WIN)
419 void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7FetchEvent@WebCore@@6B@"));
420#else
421 void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore10FetchEventE[2]);
422#endif
423
424 // If this fails FetchEvent does not have a vtable, so you need to add the
425 // ImplementationLacksVTable attribute to the interface definition
426 static_assert(std::is_polymorphic<FetchEvent>::value, "FetchEvent is not polymorphic");
427
428 // If you hit this assertion you either have a use after free bug, or
429 // FetchEvent has subclasses. If FetchEvent has subclasses that get passed
430 // to toJS() we currently require FetchEvent you to opt out of binding hardening
431 // by adding the SkipVTableValidation attribute to the interface IDL definition
432 RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
433#endif
434 return createWrapper<FetchEvent>(globalObject, WTFMove(impl));
435}
436
437JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, FetchEvent& impl)
438{
439 return wrap(state, globalObject, impl);
440}
441
442FetchEvent* JSFetchEvent::toWrapped(JSC::VM& vm, JSC::JSValue value)
443{
444 if (auto* wrapper = jsDynamicCast<JSFetchEvent*>(vm, value))
445 return &wrapper->wrapped();
446 return nullptr;
447}
448
449}
450
451#endif // ENABLE(SERVICE_WORKER)
452