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