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