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 "JSPerformanceObserver.h"
23
24#include "JSDOMAttribute.h"
25#include "JSDOMBinding.h"
26#include "JSDOMConstructor.h"
27#include "JSDOMConvertCallbacks.h"
28#include "JSDOMConvertInterface.h"
29#include "JSDOMConvertSequences.h"
30#include "JSDOMConvertStrings.h"
31#include "JSDOMExceptionHandling.h"
32#include "JSDOMGlobalObject.h"
33#include "JSDOMOperation.h"
34#include "JSDOMWrapperCache.h"
35#include "JSPerformanceObserverCallback.h"
36#include "ScriptExecutionContext.h"
37#include <JavaScriptCore/FunctionPrototype.h>
38#include <JavaScriptCore/HeapSnapshotBuilder.h>
39#include <JavaScriptCore/JSArray.h>
40#include <JavaScriptCore/JSCInlines.h>
41#include <wtf/GetPtr.h>
42#include <wtf/PointerPreparations.h>
43#include <wtf/URL.h>
44
45
46namespace WebCore {
47using namespace JSC;
48
49template<> PerformanceObserver::Init convertDictionary<PerformanceObserver::Init>(ExecState& state, JSValue value)
50{
51 VM& vm = state.vm();
52 auto throwScope = DECLARE_THROW_SCOPE(vm);
53 bool isNullOrUndefined = value.isUndefinedOrNull();
54 auto* object = isNullOrUndefined ? nullptr : value.getObject();
55 if (UNLIKELY(!isNullOrUndefined && !object)) {
56 throwTypeError(&state, throwScope);
57 return { };
58 }
59 PerformanceObserver::Init result;
60 JSValue entryTypesValue;
61 if (isNullOrUndefined)
62 entryTypesValue = jsUndefined();
63 else {
64 entryTypesValue = object->get(&state, Identifier::fromString(&state, "entryTypes"));
65 RETURN_IF_EXCEPTION(throwScope, { });
66 }
67 if (!entryTypesValue.isUndefined()) {
68 result.entryTypes = convert<IDLSequence<IDLDOMString>>(state, entryTypesValue);
69 RETURN_IF_EXCEPTION(throwScope, { });
70 } else {
71 throwRequiredMemberTypeError(state, throwScope, "entryTypes", "PerformanceObserverInit", "sequence");
72 return { };
73 }
74 return result;
75}
76
77// Functions
78
79JSC::EncodedJSValue JSC_HOST_CALL jsPerformanceObserverPrototypeFunctionObserve(JSC::ExecState*);
80JSC::EncodedJSValue JSC_HOST_CALL jsPerformanceObserverPrototypeFunctionDisconnect(JSC::ExecState*);
81
82// Attributes
83
84JSC::EncodedJSValue jsPerformanceObserverConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
85bool setJSPerformanceObserverConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
86JSC::EncodedJSValue jsPerformanceObserverConstructorSupportedEntryTypes(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
87
88class JSPerformanceObserverPrototype : public JSC::JSNonFinalObject {
89public:
90 using Base = JSC::JSNonFinalObject;
91 static JSPerformanceObserverPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
92 {
93 JSPerformanceObserverPrototype* ptr = new (NotNull, JSC::allocateCell<JSPerformanceObserverPrototype>(vm.heap)) JSPerformanceObserverPrototype(vm, globalObject, structure);
94 ptr->finishCreation(vm);
95 return ptr;
96 }
97
98 DECLARE_INFO;
99 static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
100 {
101 return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
102 }
103
104private:
105 JSPerformanceObserverPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
106 : JSC::JSNonFinalObject(vm, structure)
107 {
108 }
109
110 void finishCreation(JSC::VM&);
111};
112
113using JSPerformanceObserverConstructor = JSDOMConstructor<JSPerformanceObserver>;
114
115/* Hash table for constructor */
116
117static const HashTableValue JSPerformanceObserverConstructorTableValues[] =
118{
119 { "supportedEntryTypes", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsPerformanceObserverConstructorSupportedEntryTypes), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
120};
121
122template<> EncodedJSValue JSC_HOST_CALL JSPerformanceObserverConstructor::construct(ExecState* state)
123{
124 VM& vm = state->vm();
125 auto throwScope = DECLARE_THROW_SCOPE(vm);
126 UNUSED_PARAM(throwScope);
127 auto* castedThis = jsCast<JSPerformanceObserverConstructor*>(state->jsCallee());
128 ASSERT(castedThis);
129 if (UNLIKELY(state->argumentCount() < 1))
130 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
131 auto* context = castedThis->scriptExecutionContext();
132 if (UNLIKELY(!context))
133 return throwConstructorScriptExecutionContextUnavailableError(*state, throwScope, "PerformanceObserver");
134 auto callback = convert<IDLCallbackFunction<JSPerformanceObserverCallback>>(*state, state->uncheckedArgument(0), *castedThis->globalObject(), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentMustBeFunctionError(state, scope, 0, "callback", "PerformanceObserver", nullptr); });
135 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
136 auto object = PerformanceObserver::create(*context, callback.releaseNonNull());
137 return JSValue::encode(toJSNewlyCreated<IDLInterface<PerformanceObserver>>(*state, *castedThis->globalObject(), WTFMove(object)));
138}
139
140template<> JSValue JSPerformanceObserverConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
141{
142 UNUSED_PARAM(vm);
143 return globalObject.functionPrototype();
144}
145
146template<> void JSPerformanceObserverConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
147{
148 putDirect(vm, vm.propertyNames->prototype, JSPerformanceObserver::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
149 putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("PerformanceObserver"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
150 putDirect(vm, vm.propertyNames->length, jsNumber(1), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
151 reifyStaticProperties(vm, JSPerformanceObserver::info(), JSPerformanceObserverConstructorTableValues, *this);
152}
153
154template<> const ClassInfo JSPerformanceObserverConstructor::s_info = { "PerformanceObserver", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSPerformanceObserverConstructor) };
155
156/* Hash table for prototype */
157
158static const HashTableValue JSPerformanceObserverPrototypeTableValues[] =
159{
160 { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsPerformanceObserverConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSPerformanceObserverConstructor) } },
161 { "observe", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsPerformanceObserverPrototypeFunctionObserve), (intptr_t) (1) } },
162 { "disconnect", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsPerformanceObserverPrototypeFunctionDisconnect), (intptr_t) (0) } },
163};
164
165const ClassInfo JSPerformanceObserverPrototype::s_info = { "PerformanceObserverPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSPerformanceObserverPrototype) };
166
167void JSPerformanceObserverPrototype::finishCreation(VM& vm)
168{
169 Base::finishCreation(vm);
170 reifyStaticProperties(vm, JSPerformanceObserver::info(), JSPerformanceObserverPrototypeTableValues, *this);
171}
172
173const ClassInfo JSPerformanceObserver::s_info = { "PerformanceObserver", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSPerformanceObserver) };
174
175JSPerformanceObserver::JSPerformanceObserver(Structure* structure, JSDOMGlobalObject& globalObject, Ref<PerformanceObserver>&& impl)
176 : JSDOMWrapper<PerformanceObserver>(structure, globalObject, WTFMove(impl))
177{
178}
179
180void JSPerformanceObserver::finishCreation(VM& vm)
181{
182 Base::finishCreation(vm);
183 ASSERT(inherits(vm, info()));
184
185}
186
187JSObject* JSPerformanceObserver::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
188{
189 return JSPerformanceObserverPrototype::create(vm, &globalObject, JSPerformanceObserverPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype()));
190}
191
192JSObject* JSPerformanceObserver::prototype(VM& vm, JSDOMGlobalObject& globalObject)
193{
194 return getDOMPrototype<JSPerformanceObserver>(vm, globalObject);
195}
196
197JSValue JSPerformanceObserver::getConstructor(VM& vm, const JSGlobalObject* globalObject)
198{
199 return getDOMConstructor<JSPerformanceObserverConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
200}
201
202void JSPerformanceObserver::destroy(JSC::JSCell* cell)
203{
204 JSPerformanceObserver* thisObject = static_cast<JSPerformanceObserver*>(cell);
205 thisObject->JSPerformanceObserver::~JSPerformanceObserver();
206}
207
208template<> inline JSPerformanceObserver* IDLAttribute<JSPerformanceObserver>::cast(ExecState& state, EncodedJSValue thisValue)
209{
210 return jsDynamicCast<JSPerformanceObserver*>(state.vm(), JSValue::decode(thisValue));
211}
212
213template<> inline JSPerformanceObserver* IDLOperation<JSPerformanceObserver>::cast(ExecState& state)
214{
215 return jsDynamicCast<JSPerformanceObserver*>(state.vm(), state.thisValue());
216}
217
218EncodedJSValue jsPerformanceObserverConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
219{
220 VM& vm = state->vm();
221 auto throwScope = DECLARE_THROW_SCOPE(vm);
222 auto* prototype = jsDynamicCast<JSPerformanceObserverPrototype*>(vm, JSValue::decode(thisValue));
223 if (UNLIKELY(!prototype))
224 return throwVMTypeError(state, throwScope);
225 return JSValue::encode(JSPerformanceObserver::getConstructor(state->vm(), prototype->globalObject()));
226}
227
228bool setJSPerformanceObserverConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
229{
230 VM& vm = state->vm();
231 auto throwScope = DECLARE_THROW_SCOPE(vm);
232 auto* prototype = jsDynamicCast<JSPerformanceObserverPrototype*>(vm, JSValue::decode(thisValue));
233 if (UNLIKELY(!prototype)) {
234 throwVMTypeError(state, throwScope);
235 return false;
236 }
237 // Shadowing a built-in constructor
238 return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
239}
240
241static inline JSValue jsPerformanceObserverConstructorSupportedEntryTypesGetter(ExecState& state, ThrowScope& throwScope)
242{
243 UNUSED_PARAM(throwScope);
244 UNUSED_PARAM(state);
245 JSValue result = toJS<IDLFrozenArray<IDLDOMString>>(state, *jsCast<JSDOMGlobalObject*>(state.lexicalGlobalObject()), throwScope, PerformanceObserver::supportedEntryTypes());
246 return result;
247}
248
249EncodedJSValue jsPerformanceObserverConstructorSupportedEntryTypes(ExecState* state, EncodedJSValue thisValue, PropertyName)
250{
251 return IDLAttribute<JSPerformanceObserver>::getStatic<jsPerformanceObserverConstructorSupportedEntryTypesGetter>(*state, thisValue, "supportedEntryTypes");
252}
253
254static inline JSC::EncodedJSValue jsPerformanceObserverPrototypeFunctionObserveBody(JSC::ExecState* state, typename IDLOperation<JSPerformanceObserver>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
255{
256 UNUSED_PARAM(state);
257 UNUSED_PARAM(throwScope);
258 auto& impl = castedThis->wrapped();
259 if (UNLIKELY(state->argumentCount() < 1))
260 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
261 auto options = convert<IDLDictionary<PerformanceObserver::Init>>(*state, state->uncheckedArgument(0));
262 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
263 propagateException(*state, throwScope, impl.observe(WTFMove(options)));
264 return JSValue::encode(jsUndefined());
265}
266
267EncodedJSValue JSC_HOST_CALL jsPerformanceObserverPrototypeFunctionObserve(ExecState* state)
268{
269 return IDLOperation<JSPerformanceObserver>::call<jsPerformanceObserverPrototypeFunctionObserveBody>(*state, "observe");
270}
271
272static inline JSC::EncodedJSValue jsPerformanceObserverPrototypeFunctionDisconnectBody(JSC::ExecState* state, typename IDLOperation<JSPerformanceObserver>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
273{
274 UNUSED_PARAM(state);
275 UNUSED_PARAM(throwScope);
276 auto& impl = castedThis->wrapped();
277 impl.disconnect();
278 return JSValue::encode(jsUndefined());
279}
280
281EncodedJSValue JSC_HOST_CALL jsPerformanceObserverPrototypeFunctionDisconnect(ExecState* state)
282{
283 return IDLOperation<JSPerformanceObserver>::call<jsPerformanceObserverPrototypeFunctionDisconnectBody>(*state, "disconnect");
284}
285
286void JSPerformanceObserver::visitChildren(JSCell* cell, SlotVisitor& visitor)
287{
288 auto* thisObject = jsCast<JSPerformanceObserver*>(cell);
289 ASSERT_GC_OBJECT_INHERITS(thisObject, info());
290 Base::visitChildren(thisObject, visitor);
291 thisObject->visitAdditionalChildren(visitor);
292}
293
294void JSPerformanceObserver::visitOutputConstraints(JSCell* cell, SlotVisitor& visitor)
295{
296 auto* thisObject = jsCast<JSPerformanceObserver*>(cell);
297 ASSERT_GC_OBJECT_INHERITS(thisObject, info());
298 Base::visitOutputConstraints(thisObject, visitor);
299 thisObject->visitAdditionalChildren(visitor);
300}
301
302void JSPerformanceObserver::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
303{
304 auto* thisObject = jsCast<JSPerformanceObserver*>(cell);
305 builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
306 if (thisObject->scriptExecutionContext())
307 builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
308 Base::heapSnapshot(cell, builder);
309}
310
311void JSPerformanceObserverOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
312{
313 auto* jsPerformanceObserver = static_cast<JSPerformanceObserver*>(handle.slot()->asCell());
314 auto& world = *static_cast<DOMWrapperWorld*>(context);
315 uncacheWrapper(world, &jsPerformanceObserver->wrapped(), jsPerformanceObserver);
316}
317
318JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<PerformanceObserver>&& impl)
319{
320 // If you hit this failure the interface definition has the ImplementationLacksVTable
321 // attribute. You should remove that attribute. If the class has subclasses
322 // that may be passed through this toJS() function you should use the SkipVTableValidation
323 // attribute to PerformanceObserver.
324 static_assert(!std::is_polymorphic<PerformanceObserver>::value, "PerformanceObserver is polymorphic but the IDL claims it is not");
325 return createWrapper<PerformanceObserver>(globalObject, WTFMove(impl));
326}
327
328JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, PerformanceObserver& impl)
329{
330 return wrap(state, globalObject, impl);
331}
332
333PerformanceObserver* JSPerformanceObserver::toWrapped(JSC::VM& vm, JSC::JSValue value)
334{
335 if (auto* wrapper = jsDynamicCast<JSPerformanceObserver*>(vm, value))
336 return &wrapper->wrapped();
337 return nullptr;
338}
339
340}
341