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(RESIZE_OBSERVER)
24
25#include "JSResizeObserver.h"
26
27#include "Document.h"
28#include "JSDOMBinding.h"
29#include "JSDOMConstructor.h"
30#include "JSDOMConvertInterface.h"
31#include "JSDOMExceptionHandling.h"
32#include "JSDOMOperation.h"
33#include "JSDOMWrapperCache.h"
34#include "JSElement.h"
35#include "ScriptExecutionContext.h"
36#include <JavaScriptCore/FunctionPrototype.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#if ENABLE(RESIZE_OBSERVER)
44#include "JSDOMConvertCallbacks.h"
45#include "JSDOMGlobalObject.h"
46#include "JSResizeObserverCallback.h"
47#endif
48
49
50namespace WebCore {
51using namespace JSC;
52
53// Functions
54
55JSC::EncodedJSValue JSC_HOST_CALL jsResizeObserverPrototypeFunctionObserve(JSC::ExecState*);
56JSC::EncodedJSValue JSC_HOST_CALL jsResizeObserverPrototypeFunctionUnobserve(JSC::ExecState*);
57JSC::EncodedJSValue JSC_HOST_CALL jsResizeObserverPrototypeFunctionDisconnect(JSC::ExecState*);
58
59// Attributes
60
61JSC::EncodedJSValue jsResizeObserverConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
62bool setJSResizeObserverConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
63
64class JSResizeObserverPrototype : public JSC::JSNonFinalObject {
65public:
66 using Base = JSC::JSNonFinalObject;
67 static JSResizeObserverPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
68 {
69 JSResizeObserverPrototype* ptr = new (NotNull, JSC::allocateCell<JSResizeObserverPrototype>(vm.heap)) JSResizeObserverPrototype(vm, globalObject, structure);
70 ptr->finishCreation(vm);
71 return ptr;
72 }
73
74 DECLARE_INFO;
75 static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
76 {
77 return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
78 }
79
80private:
81 JSResizeObserverPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
82 : JSC::JSNonFinalObject(vm, structure)
83 {
84 }
85
86 void finishCreation(JSC::VM&);
87};
88
89using JSResizeObserverConstructor = JSDOMConstructor<JSResizeObserver>;
90
91template<> EncodedJSValue JSC_HOST_CALL JSResizeObserverConstructor::construct(ExecState* state)
92{
93 VM& vm = state->vm();
94 auto throwScope = DECLARE_THROW_SCOPE(vm);
95 UNUSED_PARAM(throwScope);
96 auto* castedThis = jsCast<JSResizeObserverConstructor*>(state->jsCallee());
97 ASSERT(castedThis);
98 if (UNLIKELY(state->argumentCount() < 1))
99 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
100 auto* context = castedThis->scriptExecutionContext();
101 if (UNLIKELY(!context))
102 return throwConstructorScriptExecutionContextUnavailableError(*state, throwScope, "ResizeObserver");
103 ASSERT(context->isDocument());
104 auto& document = downcast<Document>(*context);
105 auto callback = convert<IDLCallbackFunction<JSResizeObserverCallback>>(*state, state->uncheckedArgument(0), *castedThis->globalObject(), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentMustBeFunctionError(state, scope, 0, "callback", "ResizeObserver", nullptr); });
106 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
107 auto object = ResizeObserver::create(document, callback.releaseNonNull());
108 return JSValue::encode(toJSNewlyCreated<IDLInterface<ResizeObserver>>(*state, *castedThis->globalObject(), WTFMove(object)));
109}
110
111template<> JSValue JSResizeObserverConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
112{
113 UNUSED_PARAM(vm);
114 return globalObject.functionPrototype();
115}
116
117template<> void JSResizeObserverConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
118{
119 putDirect(vm, vm.propertyNames->prototype, JSResizeObserver::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
120 putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("ResizeObserver"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
121 putDirect(vm, vm.propertyNames->length, jsNumber(1), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
122}
123
124template<> const ClassInfo JSResizeObserverConstructor::s_info = { "ResizeObserver", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSResizeObserverConstructor) };
125
126/* Hash table for prototype */
127
128static const HashTableValue JSResizeObserverPrototypeTableValues[] =
129{
130 { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsResizeObserverConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSResizeObserverConstructor) } },
131 { "observe", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsResizeObserverPrototypeFunctionObserve), (intptr_t) (1) } },
132 { "unobserve", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsResizeObserverPrototypeFunctionUnobserve), (intptr_t) (1) } },
133 { "disconnect", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsResizeObserverPrototypeFunctionDisconnect), (intptr_t) (0) } },
134};
135
136const ClassInfo JSResizeObserverPrototype::s_info = { "ResizeObserverPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSResizeObserverPrototype) };
137
138void JSResizeObserverPrototype::finishCreation(VM& vm)
139{
140 Base::finishCreation(vm);
141 reifyStaticProperties(vm, JSResizeObserver::info(), JSResizeObserverPrototypeTableValues, *this);
142}
143
144const ClassInfo JSResizeObserver::s_info = { "ResizeObserver", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSResizeObserver) };
145
146JSResizeObserver::JSResizeObserver(Structure* structure, JSDOMGlobalObject& globalObject, Ref<ResizeObserver>&& impl)
147 : JSDOMWrapper<ResizeObserver>(structure, globalObject, WTFMove(impl))
148{
149}
150
151void JSResizeObserver::finishCreation(VM& vm)
152{
153 Base::finishCreation(vm);
154 ASSERT(inherits(vm, info()));
155
156}
157
158JSObject* JSResizeObserver::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
159{
160 return JSResizeObserverPrototype::create(vm, &globalObject, JSResizeObserverPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype()));
161}
162
163JSObject* JSResizeObserver::prototype(VM& vm, JSDOMGlobalObject& globalObject)
164{
165 return getDOMPrototype<JSResizeObserver>(vm, globalObject);
166}
167
168JSValue JSResizeObserver::getConstructor(VM& vm, const JSGlobalObject* globalObject)
169{
170 return getDOMConstructor<JSResizeObserverConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
171}
172
173void JSResizeObserver::destroy(JSC::JSCell* cell)
174{
175 JSResizeObserver* thisObject = static_cast<JSResizeObserver*>(cell);
176 thisObject->JSResizeObserver::~JSResizeObserver();
177}
178
179template<> inline JSResizeObserver* IDLOperation<JSResizeObserver>::cast(ExecState& state)
180{
181 return jsDynamicCast<JSResizeObserver*>(state.vm(), state.thisValue());
182}
183
184EncodedJSValue jsResizeObserverConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
185{
186 VM& vm = state->vm();
187 auto throwScope = DECLARE_THROW_SCOPE(vm);
188 auto* prototype = jsDynamicCast<JSResizeObserverPrototype*>(vm, JSValue::decode(thisValue));
189 if (UNLIKELY(!prototype))
190 return throwVMTypeError(state, throwScope);
191 return JSValue::encode(JSResizeObserver::getConstructor(state->vm(), prototype->globalObject()));
192}
193
194bool setJSResizeObserverConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
195{
196 VM& vm = state->vm();
197 auto throwScope = DECLARE_THROW_SCOPE(vm);
198 auto* prototype = jsDynamicCast<JSResizeObserverPrototype*>(vm, JSValue::decode(thisValue));
199 if (UNLIKELY(!prototype)) {
200 throwVMTypeError(state, throwScope);
201 return false;
202 }
203 // Shadowing a built-in constructor
204 return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
205}
206
207static inline JSC::EncodedJSValue jsResizeObserverPrototypeFunctionObserveBody(JSC::ExecState* state, typename IDLOperation<JSResizeObserver>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
208{
209 UNUSED_PARAM(state);
210 UNUSED_PARAM(throwScope);
211 auto& impl = castedThis->wrapped();
212 if (UNLIKELY(state->argumentCount() < 1))
213 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
214 auto target = convert<IDLInterface<Element>>(*state, state->uncheckedArgument(0), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentTypeError(state, scope, 0, "target", "ResizeObserver", "observe", "Element"); });
215 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
216 impl.observe(*target);
217 return JSValue::encode(jsUndefined());
218}
219
220EncodedJSValue JSC_HOST_CALL jsResizeObserverPrototypeFunctionObserve(ExecState* state)
221{
222 return IDLOperation<JSResizeObserver>::call<jsResizeObserverPrototypeFunctionObserveBody>(*state, "observe");
223}
224
225static inline JSC::EncodedJSValue jsResizeObserverPrototypeFunctionUnobserveBody(JSC::ExecState* state, typename IDLOperation<JSResizeObserver>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
226{
227 UNUSED_PARAM(state);
228 UNUSED_PARAM(throwScope);
229 auto& impl = castedThis->wrapped();
230 if (UNLIKELY(state->argumentCount() < 1))
231 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
232 auto target = convert<IDLInterface<Element>>(*state, state->uncheckedArgument(0), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentTypeError(state, scope, 0, "target", "ResizeObserver", "unobserve", "Element"); });
233 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
234 impl.unobserve(*target);
235 return JSValue::encode(jsUndefined());
236}
237
238EncodedJSValue JSC_HOST_CALL jsResizeObserverPrototypeFunctionUnobserve(ExecState* state)
239{
240 return IDLOperation<JSResizeObserver>::call<jsResizeObserverPrototypeFunctionUnobserveBody>(*state, "unobserve");
241}
242
243static inline JSC::EncodedJSValue jsResizeObserverPrototypeFunctionDisconnectBody(JSC::ExecState* state, typename IDLOperation<JSResizeObserver>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
244{
245 UNUSED_PARAM(state);
246 UNUSED_PARAM(throwScope);
247 auto& impl = castedThis->wrapped();
248 impl.disconnect();
249 return JSValue::encode(jsUndefined());
250}
251
252EncodedJSValue JSC_HOST_CALL jsResizeObserverPrototypeFunctionDisconnect(ExecState* state)
253{
254 return IDLOperation<JSResizeObserver>::call<jsResizeObserverPrototypeFunctionDisconnectBody>(*state, "disconnect");
255}
256
257void JSResizeObserver::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
258{
259 auto* thisObject = jsCast<JSResizeObserver*>(cell);
260 builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
261 if (thisObject->scriptExecutionContext())
262 builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
263 Base::heapSnapshot(cell, builder);
264}
265
266bool JSResizeObserverOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason)
267{
268 auto* jsResizeObserver = jsCast<JSResizeObserver*>(handle.slot()->asCell());
269 if (jsResizeObserver->wrapped().hasPendingActivity()) {
270 if (UNLIKELY(reason))
271 *reason = "ActiveDOMObject with pending activity";
272 return true;
273 }
274 UNUSED_PARAM(visitor);
275 UNUSED_PARAM(reason);
276 return false;
277}
278
279void JSResizeObserverOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
280{
281 auto* jsResizeObserver = static_cast<JSResizeObserver*>(handle.slot()->asCell());
282 auto& world = *static_cast<DOMWrapperWorld*>(context);
283 uncacheWrapper(world, &jsResizeObserver->wrapped(), jsResizeObserver);
284}
285
286#if ENABLE(BINDING_INTEGRITY)
287#if PLATFORM(WIN)
288#pragma warning(disable: 4483)
289extern "C" { extern void (*const __identifier("??_7ResizeObserver@WebCore@@6B@")[])(); }
290#else
291extern "C" { extern void* _ZTVN7WebCore14ResizeObserverE[]; }
292#endif
293#endif
294
295JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<ResizeObserver>&& impl)
296{
297
298#if ENABLE(BINDING_INTEGRITY)
299 void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
300#if PLATFORM(WIN)
301 void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7ResizeObserver@WebCore@@6B@"));
302#else
303 void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore14ResizeObserverE[2]);
304#endif
305
306 // If this fails ResizeObserver does not have a vtable, so you need to add the
307 // ImplementationLacksVTable attribute to the interface definition
308 static_assert(std::is_polymorphic<ResizeObserver>::value, "ResizeObserver is not polymorphic");
309
310 // If you hit this assertion you either have a use after free bug, or
311 // ResizeObserver has subclasses. If ResizeObserver has subclasses that get passed
312 // to toJS() we currently require ResizeObserver you to opt out of binding hardening
313 // by adding the SkipVTableValidation attribute to the interface IDL definition
314 RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
315#endif
316 return createWrapper<ResizeObserver>(globalObject, WTFMove(impl));
317}
318
319JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, ResizeObserver& impl)
320{
321 return wrap(state, globalObject, impl);
322}
323
324ResizeObserver* JSResizeObserver::toWrapped(JSC::VM& vm, JSC::JSValue value)
325{
326 if (auto* wrapper = jsDynamicCast<JSResizeObserver*>(vm, value))
327 return &wrapper->wrapped();
328 return nullptr;
329}
330
331}
332
333#endif // ENABLE(RESIZE_OBSERVER)
334