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 | |
59 | namespace WebCore { |
60 | using namespace JSC; |
61 | |
62 | #if ENABLE(INTERSECTION_OBSERVER) |
63 | |
64 | template<> 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 | |
118 | JSC::EncodedJSValue JSC_HOST_CALL jsIntersectionObserverPrototypeFunctionObserve(JSC::ExecState*); |
119 | JSC::EncodedJSValue JSC_HOST_CALL jsIntersectionObserverPrototypeFunctionUnobserve(JSC::ExecState*); |
120 | JSC::EncodedJSValue JSC_HOST_CALL jsIntersectionObserverPrototypeFunctionDisconnect(JSC::ExecState*); |
121 | JSC::EncodedJSValue JSC_HOST_CALL jsIntersectionObserverPrototypeFunctionTakeRecords(JSC::ExecState*); |
122 | |
123 | // Attributes |
124 | |
125 | JSC::EncodedJSValue jsIntersectionObserverConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
126 | bool setJSIntersectionObserverConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue); |
127 | JSC::EncodedJSValue jsIntersectionObserverRoot(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
128 | JSC::EncodedJSValue jsIntersectionObserverRootMargin(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
129 | JSC::EncodedJSValue jsIntersectionObserverThresholds(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName); |
130 | |
131 | class JSIntersectionObserverPrototype : public JSC::JSNonFinalObject { |
132 | public: |
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 | |
147 | private: |
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 | |
156 | using JSIntersectionObserverConstructor = JSDOMConstructor<JSIntersectionObserver>; |
157 | |
158 | template<> 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 | |
180 | template<> JSValue JSIntersectionObserverConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject) |
181 | { |
182 | UNUSED_PARAM(vm); |
183 | return globalObject.functionPrototype(); |
184 | } |
185 | |
186 | template<> 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 | |
193 | template<> const ClassInfo JSIntersectionObserverConstructor::s_info = { "IntersectionObserver" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSIntersectionObserverConstructor) }; |
194 | |
195 | /* Hash table for prototype */ |
196 | |
197 | static 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 | |
209 | const ClassInfo JSIntersectionObserverPrototype::s_info = { "IntersectionObserverPrototype" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSIntersectionObserverPrototype) }; |
210 | |
211 | void JSIntersectionObserverPrototype::finishCreation(VM& vm) |
212 | { |
213 | Base::finishCreation(vm); |
214 | reifyStaticProperties(vm, JSIntersectionObserver::info(), JSIntersectionObserverPrototypeTableValues, *this); |
215 | } |
216 | |
217 | const ClassInfo JSIntersectionObserver::s_info = { "IntersectionObserver" , &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSIntersectionObserver) }; |
218 | |
219 | JSIntersectionObserver::JSIntersectionObserver(Structure* structure, JSDOMGlobalObject& globalObject, Ref<IntersectionObserver>&& impl) |
220 | : JSDOMWrapper<IntersectionObserver>(structure, globalObject, WTFMove(impl)) |
221 | { |
222 | } |
223 | |
224 | void JSIntersectionObserver::finishCreation(VM& vm) |
225 | { |
226 | Base::finishCreation(vm); |
227 | ASSERT(inherits(vm, info())); |
228 | |
229 | } |
230 | |
231 | JSObject* JSIntersectionObserver::createPrototype(VM& vm, JSDOMGlobalObject& globalObject) |
232 | { |
233 | return JSIntersectionObserverPrototype::create(vm, &globalObject, JSIntersectionObserverPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype())); |
234 | } |
235 | |
236 | JSObject* JSIntersectionObserver::prototype(VM& vm, JSDOMGlobalObject& globalObject) |
237 | { |
238 | return getDOMPrototype<JSIntersectionObserver>(vm, globalObject); |
239 | } |
240 | |
241 | JSValue JSIntersectionObserver::getConstructor(VM& vm, const JSGlobalObject* globalObject) |
242 | { |
243 | return getDOMConstructor<JSIntersectionObserverConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); |
244 | } |
245 | |
246 | void JSIntersectionObserver::destroy(JSC::JSCell* cell) |
247 | { |
248 | JSIntersectionObserver* thisObject = static_cast<JSIntersectionObserver*>(cell); |
249 | thisObject->JSIntersectionObserver::~JSIntersectionObserver(); |
250 | } |
251 | |
252 | template<> inline JSIntersectionObserver* IDLAttribute<JSIntersectionObserver>::cast(ExecState& state, EncodedJSValue thisValue) |
253 | { |
254 | return jsDynamicCast<JSIntersectionObserver*>(state.vm(), JSValue::decode(thisValue)); |
255 | } |
256 | |
257 | template<> inline JSIntersectionObserver* IDLOperation<JSIntersectionObserver>::cast(ExecState& state) |
258 | { |
259 | return jsDynamicCast<JSIntersectionObserver*>(state.vm(), state.thisValue()); |
260 | } |
261 | |
262 | EncodedJSValue 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 | |
272 | bool 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 | |
285 | static 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 | |
294 | EncodedJSValue jsIntersectionObserverRoot(ExecState* state, EncodedJSValue thisValue, PropertyName) |
295 | { |
296 | return IDLAttribute<JSIntersectionObserver>::get<jsIntersectionObserverRootGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "root" ); |
297 | } |
298 | |
299 | static 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 | |
308 | EncodedJSValue jsIntersectionObserverRootMargin(ExecState* state, EncodedJSValue thisValue, PropertyName) |
309 | { |
310 | return IDLAttribute<JSIntersectionObserver>::get<jsIntersectionObserverRootMarginGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "rootMargin" ); |
311 | } |
312 | |
313 | static 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 | |
322 | EncodedJSValue jsIntersectionObserverThresholds(ExecState* state, EncodedJSValue thisValue, PropertyName) |
323 | { |
324 | return IDLAttribute<JSIntersectionObserver>::get<jsIntersectionObserverThresholdsGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "thresholds" ); |
325 | } |
326 | |
327 | static 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 | |
340 | EncodedJSValue JSC_HOST_CALL jsIntersectionObserverPrototypeFunctionObserve(ExecState* state) |
341 | { |
342 | return IDLOperation<JSIntersectionObserver>::call<jsIntersectionObserverPrototypeFunctionObserveBody>(*state, "observe" ); |
343 | } |
344 | |
345 | static 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 | |
358 | EncodedJSValue JSC_HOST_CALL jsIntersectionObserverPrototypeFunctionUnobserve(ExecState* state) |
359 | { |
360 | return IDLOperation<JSIntersectionObserver>::call<jsIntersectionObserverPrototypeFunctionUnobserveBody>(*state, "unobserve" ); |
361 | } |
362 | |
363 | static 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 | |
372 | EncodedJSValue JSC_HOST_CALL jsIntersectionObserverPrototypeFunctionDisconnect(ExecState* state) |
373 | { |
374 | return IDLOperation<JSIntersectionObserver>::call<jsIntersectionObserverPrototypeFunctionDisconnectBody>(*state, "disconnect" ); |
375 | } |
376 | |
377 | static 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 | |
386 | EncodedJSValue JSC_HOST_CALL jsIntersectionObserverPrototypeFunctionTakeRecords(ExecState* state) |
387 | { |
388 | return IDLOperation<JSIntersectionObserver>::call<jsIntersectionObserverPrototypeFunctionTakeRecordsBody>(*state, "takeRecords" ); |
389 | } |
390 | |
391 | void 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 | |
400 | bool 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 | |
413 | void 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) |
423 | extern "C" { extern void (*const __identifier("??_7IntersectionObserver@WebCore@@6B@" )[])(); } |
424 | #else |
425 | extern "C" { extern void* _ZTVN7WebCore20IntersectionObserverE[]; } |
426 | #endif |
427 | #endif |
428 | |
429 | JSC::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 | |
453 | JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, IntersectionObserver& impl) |
454 | { |
455 | return wrap(state, globalObject, impl); |
456 | } |
457 | |
458 | IntersectionObserver* 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 | |