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 "JSEventSource.h"
23
24#include "EventNames.h"
25#include "JSDOMAttribute.h"
26#include "JSDOMBinding.h"
27#include "JSDOMConstructor.h"
28#include "JSDOMConvertBoolean.h"
29#include "JSDOMConvertInterface.h"
30#include "JSDOMConvertNumbers.h"
31#include "JSDOMConvertStrings.h"
32#include "JSDOMExceptionHandling.h"
33#include "JSDOMOperation.h"
34#include "JSDOMWrapperCache.h"
35#include "JSEventListener.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
44namespace WebCore {
45using namespace JSC;
46
47template<> EventSource::Init convertDictionary<EventSource::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 EventSource::Init result;
58 JSValue withCredentialsValue;
59 if (isNullOrUndefined)
60 withCredentialsValue = jsUndefined();
61 else {
62 withCredentialsValue = object->get(&state, Identifier::fromString(&state, "withCredentials"));
63 RETURN_IF_EXCEPTION(throwScope, { });
64 }
65 if (!withCredentialsValue.isUndefined()) {
66 result.withCredentials = convert<IDLBoolean>(state, withCredentialsValue);
67 RETURN_IF_EXCEPTION(throwScope, { });
68 } else
69 result.withCredentials = false;
70 return result;
71}
72
73// Functions
74
75JSC::EncodedJSValue JSC_HOST_CALL jsEventSourcePrototypeFunctionClose(JSC::ExecState*);
76
77// Attributes
78
79JSC::EncodedJSValue jsEventSourceConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
80bool setJSEventSourceConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
81JSC::EncodedJSValue jsEventSourceURL(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
82JSC::EncodedJSValue jsEventSourceUrl(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
83JSC::EncodedJSValue jsEventSourceWithCredentials(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
84JSC::EncodedJSValue jsEventSourceReadyState(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
85JSC::EncodedJSValue jsEventSourceOnopen(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
86bool setJSEventSourceOnopen(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
87JSC::EncodedJSValue jsEventSourceOnmessage(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
88bool setJSEventSourceOnmessage(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
89JSC::EncodedJSValue jsEventSourceOnerror(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
90bool setJSEventSourceOnerror(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
91
92class JSEventSourcePrototype : public JSC::JSNonFinalObject {
93public:
94 using Base = JSC::JSNonFinalObject;
95 static JSEventSourcePrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
96 {
97 JSEventSourcePrototype* ptr = new (NotNull, JSC::allocateCell<JSEventSourcePrototype>(vm.heap)) JSEventSourcePrototype(vm, globalObject, structure);
98 ptr->finishCreation(vm);
99 return ptr;
100 }
101
102 DECLARE_INFO;
103 static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
104 {
105 return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
106 }
107
108private:
109 JSEventSourcePrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
110 : JSC::JSNonFinalObject(vm, structure)
111 {
112 }
113
114 void finishCreation(JSC::VM&);
115};
116
117using JSEventSourceConstructor = JSDOMConstructor<JSEventSource>;
118
119/* Hash table for constructor */
120
121static const HashTableValue JSEventSourceConstructorTableValues[] =
122{
123 { "CONNECTING", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(0) } },
124 { "OPEN", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(1) } },
125 { "CLOSED", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(2) } },
126};
127
128static_assert(EventSource::CONNECTING == 0, "CONNECTING in EventSource does not match value from IDL");
129static_assert(EventSource::OPEN == 1, "OPEN in EventSource does not match value from IDL");
130static_assert(EventSource::CLOSED == 2, "CLOSED in EventSource does not match value from IDL");
131
132template<> EncodedJSValue JSC_HOST_CALL JSEventSourceConstructor::construct(ExecState* state)
133{
134 VM& vm = state->vm();
135 auto throwScope = DECLARE_THROW_SCOPE(vm);
136 UNUSED_PARAM(throwScope);
137 auto* castedThis = jsCast<JSEventSourceConstructor*>(state->jsCallee());
138 ASSERT(castedThis);
139 if (UNLIKELY(state->argumentCount() < 1))
140 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
141 auto* context = castedThis->scriptExecutionContext();
142 if (UNLIKELY(!context))
143 return throwConstructorScriptExecutionContextUnavailableError(*state, throwScope, "EventSource");
144 auto url = convert<IDLUSVString>(*state, state->uncheckedArgument(0));
145 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
146 auto eventSourceInitDict = convert<IDLDictionary<EventSource::Init>>(*state, state->argument(1));
147 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
148 auto object = EventSource::create(*context, WTFMove(url), WTFMove(eventSourceInitDict));
149 return JSValue::encode(toJSNewlyCreated<IDLInterface<EventSource>>(*state, *castedThis->globalObject(), throwScope, WTFMove(object)));
150}
151
152template<> JSValue JSEventSourceConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
153{
154 return JSEventTarget::getConstructor(vm, &globalObject);
155}
156
157template<> void JSEventSourceConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
158{
159 putDirect(vm, vm.propertyNames->prototype, JSEventSource::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
160 putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("EventSource"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
161 putDirect(vm, vm.propertyNames->length, jsNumber(1), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
162 reifyStaticProperties(vm, JSEventSource::info(), JSEventSourceConstructorTableValues, *this);
163}
164
165template<> const ClassInfo JSEventSourceConstructor::s_info = { "EventSource", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSEventSourceConstructor) };
166
167/* Hash table for prototype */
168
169static const HashTableValue JSEventSourcePrototypeTableValues[] =
170{
171 { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventSourceConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSEventSourceConstructor) } },
172 { "URL", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventSourceURL), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
173 { "url", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventSourceUrl), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
174 { "withCredentials", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventSourceWithCredentials), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
175 { "readyState", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventSourceReadyState), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
176 { "onopen", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventSourceOnopen), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSEventSourceOnopen) } },
177 { "onmessage", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventSourceOnmessage), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSEventSourceOnmessage) } },
178 { "onerror", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventSourceOnerror), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSEventSourceOnerror) } },
179 { "close", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsEventSourcePrototypeFunctionClose), (intptr_t) (0) } },
180 { "CONNECTING", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(0) } },
181 { "OPEN", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(1) } },
182 { "CLOSED", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(2) } },
183};
184
185const ClassInfo JSEventSourcePrototype::s_info = { "EventSourcePrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSEventSourcePrototype) };
186
187void JSEventSourcePrototype::finishCreation(VM& vm)
188{
189 Base::finishCreation(vm);
190 reifyStaticProperties(vm, JSEventSource::info(), JSEventSourcePrototypeTableValues, *this);
191}
192
193const ClassInfo JSEventSource::s_info = { "EventSource", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSEventSource) };
194
195JSEventSource::JSEventSource(Structure* structure, JSDOMGlobalObject& globalObject, Ref<EventSource>&& impl)
196 : JSEventTarget(structure, globalObject, WTFMove(impl))
197{
198}
199
200void JSEventSource::finishCreation(VM& vm)
201{
202 Base::finishCreation(vm);
203 ASSERT(inherits(vm, info()));
204
205}
206
207JSObject* JSEventSource::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
208{
209 return JSEventSourcePrototype::create(vm, &globalObject, JSEventSourcePrototype::createStructure(vm, &globalObject, JSEventTarget::prototype(vm, globalObject)));
210}
211
212JSObject* JSEventSource::prototype(VM& vm, JSDOMGlobalObject& globalObject)
213{
214 return getDOMPrototype<JSEventSource>(vm, globalObject);
215}
216
217JSValue JSEventSource::getConstructor(VM& vm, const JSGlobalObject* globalObject)
218{
219 return getDOMConstructor<JSEventSourceConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
220}
221
222template<> inline JSEventSource* IDLAttribute<JSEventSource>::cast(ExecState& state, EncodedJSValue thisValue)
223{
224 return jsDynamicCast<JSEventSource*>(state.vm(), JSValue::decode(thisValue));
225}
226
227template<> inline JSEventSource* IDLOperation<JSEventSource>::cast(ExecState& state)
228{
229 return jsDynamicCast<JSEventSource*>(state.vm(), state.thisValue());
230}
231
232EncodedJSValue jsEventSourceConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
233{
234 VM& vm = state->vm();
235 auto throwScope = DECLARE_THROW_SCOPE(vm);
236 auto* prototype = jsDynamicCast<JSEventSourcePrototype*>(vm, JSValue::decode(thisValue));
237 if (UNLIKELY(!prototype))
238 return throwVMTypeError(state, throwScope);
239 return JSValue::encode(JSEventSource::getConstructor(state->vm(), prototype->globalObject()));
240}
241
242bool setJSEventSourceConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
243{
244 VM& vm = state->vm();
245 auto throwScope = DECLARE_THROW_SCOPE(vm);
246 auto* prototype = jsDynamicCast<JSEventSourcePrototype*>(vm, JSValue::decode(thisValue));
247 if (UNLIKELY(!prototype)) {
248 throwVMTypeError(state, throwScope);
249 return false;
250 }
251 // Shadowing a built-in constructor
252 return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
253}
254
255static inline JSValue jsEventSourceURLGetter(ExecState& state, JSEventSource& thisObject, ThrowScope& throwScope)
256{
257 UNUSED_PARAM(throwScope);
258 UNUSED_PARAM(state);
259 auto& impl = thisObject.wrapped();
260 JSValue result = toJS<IDLUSVString>(state, throwScope, impl.url());
261 return result;
262}
263
264EncodedJSValue jsEventSourceURL(ExecState* state, EncodedJSValue thisValue, PropertyName)
265{
266 return IDLAttribute<JSEventSource>::get<jsEventSourceURLGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "URL");
267}
268
269static inline JSValue jsEventSourceUrlGetter(ExecState& state, JSEventSource& thisObject, ThrowScope& throwScope)
270{
271 UNUSED_PARAM(throwScope);
272 UNUSED_PARAM(state);
273 auto& impl = thisObject.wrapped();
274 JSValue result = toJS<IDLUSVString>(state, throwScope, impl.url());
275 return result;
276}
277
278EncodedJSValue jsEventSourceUrl(ExecState* state, EncodedJSValue thisValue, PropertyName)
279{
280 return IDLAttribute<JSEventSource>::get<jsEventSourceUrlGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "url");
281}
282
283static inline JSValue jsEventSourceWithCredentialsGetter(ExecState& state, JSEventSource& thisObject, ThrowScope& throwScope)
284{
285 UNUSED_PARAM(throwScope);
286 UNUSED_PARAM(state);
287 auto& impl = thisObject.wrapped();
288 JSValue result = toJS<IDLBoolean>(state, throwScope, impl.withCredentials());
289 return result;
290}
291
292EncodedJSValue jsEventSourceWithCredentials(ExecState* state, EncodedJSValue thisValue, PropertyName)
293{
294 return IDLAttribute<JSEventSource>::get<jsEventSourceWithCredentialsGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "withCredentials");
295}
296
297static inline JSValue jsEventSourceReadyStateGetter(ExecState& state, JSEventSource& thisObject, ThrowScope& throwScope)
298{
299 UNUSED_PARAM(throwScope);
300 UNUSED_PARAM(state);
301 auto& impl = thisObject.wrapped();
302 JSValue result = toJS<IDLUnsignedShort>(state, throwScope, impl.readyState());
303 return result;
304}
305
306EncodedJSValue jsEventSourceReadyState(ExecState* state, EncodedJSValue thisValue, PropertyName)
307{
308 return IDLAttribute<JSEventSource>::get<jsEventSourceReadyStateGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "readyState");
309}
310
311static inline JSValue jsEventSourceOnopenGetter(ExecState& state, JSEventSource& thisObject, ThrowScope& throwScope)
312{
313 UNUSED_PARAM(throwScope);
314 UNUSED_PARAM(state);
315 return eventHandlerAttribute(thisObject.wrapped(), eventNames().openEvent, worldForDOMObject(thisObject));
316}
317
318EncodedJSValue jsEventSourceOnopen(ExecState* state, EncodedJSValue thisValue, PropertyName)
319{
320 return IDLAttribute<JSEventSource>::get<jsEventSourceOnopenGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "onopen");
321}
322
323static inline bool setJSEventSourceOnopenSetter(ExecState& state, JSEventSource& thisObject, JSValue value, ThrowScope& throwScope)
324{
325 UNUSED_PARAM(throwScope);
326 setEventHandlerAttribute(state, thisObject, thisObject.wrapped(), eventNames().openEvent, value);
327 return true;
328}
329
330bool setJSEventSourceOnopen(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
331{
332 return IDLAttribute<JSEventSource>::set<setJSEventSourceOnopenSetter>(*state, thisValue, encodedValue, "onopen");
333}
334
335static inline JSValue jsEventSourceOnmessageGetter(ExecState& state, JSEventSource& thisObject, ThrowScope& throwScope)
336{
337 UNUSED_PARAM(throwScope);
338 UNUSED_PARAM(state);
339 return eventHandlerAttribute(thisObject.wrapped(), eventNames().messageEvent, worldForDOMObject(thisObject));
340}
341
342EncodedJSValue jsEventSourceOnmessage(ExecState* state, EncodedJSValue thisValue, PropertyName)
343{
344 return IDLAttribute<JSEventSource>::get<jsEventSourceOnmessageGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "onmessage");
345}
346
347static inline bool setJSEventSourceOnmessageSetter(ExecState& state, JSEventSource& thisObject, JSValue value, ThrowScope& throwScope)
348{
349 UNUSED_PARAM(throwScope);
350 setEventHandlerAttribute(state, thisObject, thisObject.wrapped(), eventNames().messageEvent, value);
351 return true;
352}
353
354bool setJSEventSourceOnmessage(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
355{
356 return IDLAttribute<JSEventSource>::set<setJSEventSourceOnmessageSetter>(*state, thisValue, encodedValue, "onmessage");
357}
358
359static inline JSValue jsEventSourceOnerrorGetter(ExecState& state, JSEventSource& thisObject, ThrowScope& throwScope)
360{
361 UNUSED_PARAM(throwScope);
362 UNUSED_PARAM(state);
363 return eventHandlerAttribute(thisObject.wrapped(), eventNames().errorEvent, worldForDOMObject(thisObject));
364}
365
366EncodedJSValue jsEventSourceOnerror(ExecState* state, EncodedJSValue thisValue, PropertyName)
367{
368 return IDLAttribute<JSEventSource>::get<jsEventSourceOnerrorGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "onerror");
369}
370
371static inline bool setJSEventSourceOnerrorSetter(ExecState& state, JSEventSource& thisObject, JSValue value, ThrowScope& throwScope)
372{
373 UNUSED_PARAM(throwScope);
374 setEventHandlerAttribute(state, thisObject, thisObject.wrapped(), eventNames().errorEvent, value);
375 return true;
376}
377
378bool setJSEventSourceOnerror(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
379{
380 return IDLAttribute<JSEventSource>::set<setJSEventSourceOnerrorSetter>(*state, thisValue, encodedValue, "onerror");
381}
382
383static inline JSC::EncodedJSValue jsEventSourcePrototypeFunctionCloseBody(JSC::ExecState* state, typename IDLOperation<JSEventSource>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
384{
385 UNUSED_PARAM(state);
386 UNUSED_PARAM(throwScope);
387 auto& impl = castedThis->wrapped();
388 impl.close();
389 return JSValue::encode(jsUndefined());
390}
391
392EncodedJSValue JSC_HOST_CALL jsEventSourcePrototypeFunctionClose(ExecState* state)
393{
394 return IDLOperation<JSEventSource>::call<jsEventSourcePrototypeFunctionCloseBody>(*state, "close");
395}
396
397void JSEventSource::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
398{
399 auto* thisObject = jsCast<JSEventSource*>(cell);
400 builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
401 if (thisObject->scriptExecutionContext())
402 builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
403 Base::heapSnapshot(cell, builder);
404}
405
406bool JSEventSourceOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason)
407{
408 auto* jsEventSource = jsCast<JSEventSource*>(handle.slot()->asCell());
409 if (jsEventSource->wrapped().hasPendingActivity()) {
410 if (UNLIKELY(reason))
411 *reason = "ActiveDOMObject with pending activity";
412 return true;
413 }
414 if (jsEventSource->wrapped().isFiringEventListeners()) {
415 if (UNLIKELY(reason))
416 *reason = "EventTarget firing event listeners";
417 return true;
418 }
419 UNUSED_PARAM(visitor);
420 UNUSED_PARAM(reason);
421 return false;
422}
423
424void JSEventSourceOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
425{
426 auto* jsEventSource = static_cast<JSEventSource*>(handle.slot()->asCell());
427 auto& world = *static_cast<DOMWrapperWorld*>(context);
428 uncacheWrapper(world, &jsEventSource->wrapped(), jsEventSource);
429}
430
431#if ENABLE(BINDING_INTEGRITY)
432#if PLATFORM(WIN)
433#pragma warning(disable: 4483)
434extern "C" { extern void (*const __identifier("??_7EventSource@WebCore@@6B@")[])(); }
435#else
436extern "C" { extern void* _ZTVN7WebCore11EventSourceE[]; }
437#endif
438#endif
439
440JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<EventSource>&& impl)
441{
442
443#if ENABLE(BINDING_INTEGRITY)
444 void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
445#if PLATFORM(WIN)
446 void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7EventSource@WebCore@@6B@"));
447#else
448 void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore11EventSourceE[2]);
449#endif
450
451 // If this fails EventSource does not have a vtable, so you need to add the
452 // ImplementationLacksVTable attribute to the interface definition
453 static_assert(std::is_polymorphic<EventSource>::value, "EventSource is not polymorphic");
454
455 // If you hit this assertion you either have a use after free bug, or
456 // EventSource has subclasses. If EventSource has subclasses that get passed
457 // to toJS() we currently require EventSource you to opt out of binding hardening
458 // by adding the SkipVTableValidation attribute to the interface IDL definition
459 RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
460#endif
461 return createWrapper<EventSource>(globalObject, WTFMove(impl));
462}
463
464JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, EventSource& impl)
465{
466 return wrap(state, globalObject, impl);
467}
468
469EventSource* JSEventSource::toWrapped(JSC::VM& vm, JSC::JSValue value)
470{
471 if (auto* wrapper = jsDynamicCast<JSEventSource*>(vm, value))
472 return &wrapper->wrapped();
473 return nullptr;
474}
475
476}
477