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 "JSDOMPluginArray.h"
23
24#include "JSDOMAbstractOperations.h"
25#include "JSDOMAttribute.h"
26#include "JSDOMBinding.h"
27#include "JSDOMConstructorNotConstructable.h"
28#include "JSDOMConvertBoolean.h"
29#include "JSDOMConvertInterface.h"
30#include "JSDOMConvertNullable.h"
31#include "JSDOMConvertNumbers.h"
32#include "JSDOMConvertStrings.h"
33#include "JSDOMExceptionHandling.h"
34#include "JSDOMGlobalObject.h"
35#include "JSDOMOperation.h"
36#include "JSDOMPlugin.h"
37#include "JSDOMWrapperCache.h"
38#include "ScriptExecutionContext.h"
39#include <JavaScriptCore/ArrayPrototype.h>
40#include <JavaScriptCore/BuiltinNames.h>
41#include <JavaScriptCore/FunctionPrototype.h>
42#include <JavaScriptCore/HeapSnapshotBuilder.h>
43#include <JavaScriptCore/JSCInlines.h>
44#include <JavaScriptCore/PropertyNameArray.h>
45#include <wtf/GetPtr.h>
46#include <wtf/PointerPreparations.h>
47#include <wtf/URL.h>
48
49
50namespace WebCore {
51using namespace JSC;
52
53// Functions
54
55JSC::EncodedJSValue JSC_HOST_CALL jsDOMPluginArrayPrototypeFunctionItem(JSC::ExecState*);
56JSC::EncodedJSValue JSC_HOST_CALL jsDOMPluginArrayPrototypeFunctionNamedItem(JSC::ExecState*);
57JSC::EncodedJSValue JSC_HOST_CALL jsDOMPluginArrayPrototypeFunctionRefresh(JSC::ExecState*);
58
59// Attributes
60
61JSC::EncodedJSValue jsDOMPluginArrayConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
62bool setJSDOMPluginArrayConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
63JSC::EncodedJSValue jsDOMPluginArrayLength(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
64
65class JSDOMPluginArrayPrototype : public JSC::JSNonFinalObject {
66public:
67 using Base = JSC::JSNonFinalObject;
68 static JSDOMPluginArrayPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
69 {
70 JSDOMPluginArrayPrototype* ptr = new (NotNull, JSC::allocateCell<JSDOMPluginArrayPrototype>(vm.heap)) JSDOMPluginArrayPrototype(vm, globalObject, structure);
71 ptr->finishCreation(vm);
72 return ptr;
73 }
74
75 DECLARE_INFO;
76 static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
77 {
78 return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
79 }
80
81private:
82 JSDOMPluginArrayPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
83 : JSC::JSNonFinalObject(vm, structure)
84 {
85 }
86
87 void finishCreation(JSC::VM&);
88};
89
90using JSDOMPluginArrayConstructor = JSDOMConstructorNotConstructable<JSDOMPluginArray>;
91
92template<> JSValue JSDOMPluginArrayConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
93{
94 UNUSED_PARAM(vm);
95 return globalObject.functionPrototype();
96}
97
98template<> void JSDOMPluginArrayConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
99{
100 putDirect(vm, vm.propertyNames->prototype, JSDOMPluginArray::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
101 putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("PluginArray"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
102 putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
103}
104
105template<> const ClassInfo JSDOMPluginArrayConstructor::s_info = { "PluginArray", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDOMPluginArrayConstructor) };
106
107/* Hash table for prototype */
108
109static const HashTableValue JSDOMPluginArrayPrototypeTableValues[] =
110{
111 { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDOMPluginArrayConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSDOMPluginArrayConstructor) } },
112 { "length", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDOMPluginArrayLength), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
113 { "item", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsDOMPluginArrayPrototypeFunctionItem), (intptr_t) (1) } },
114 { "namedItem", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsDOMPluginArrayPrototypeFunctionNamedItem), (intptr_t) (1) } },
115 { "refresh", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsDOMPluginArrayPrototypeFunctionRefresh), (intptr_t) (0) } },
116};
117
118const ClassInfo JSDOMPluginArrayPrototype::s_info = { "PluginArrayPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDOMPluginArrayPrototype) };
119
120void JSDOMPluginArrayPrototype::finishCreation(VM& vm)
121{
122 Base::finishCreation(vm);
123 reifyStaticProperties(vm, JSDOMPluginArray::info(), JSDOMPluginArrayPrototypeTableValues, *this);
124 putDirect(vm, vm.propertyNames->iteratorSymbol, globalObject()->arrayPrototype()->getDirect(vm, vm.propertyNames->builtinNames().valuesPrivateName()), static_cast<unsigned>(JSC::PropertyAttribute::DontEnum));
125}
126
127const ClassInfo JSDOMPluginArray::s_info = { "PluginArray", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDOMPluginArray) };
128
129JSDOMPluginArray::JSDOMPluginArray(Structure* structure, JSDOMGlobalObject& globalObject, Ref<DOMPluginArray>&& impl)
130 : JSDOMWrapper<DOMPluginArray>(structure, globalObject, WTFMove(impl))
131{
132}
133
134void JSDOMPluginArray::finishCreation(VM& vm)
135{
136 Base::finishCreation(vm);
137 ASSERT(inherits(vm, info()));
138
139}
140
141JSObject* JSDOMPluginArray::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
142{
143 return JSDOMPluginArrayPrototype::create(vm, &globalObject, JSDOMPluginArrayPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype()));
144}
145
146JSObject* JSDOMPluginArray::prototype(VM& vm, JSDOMGlobalObject& globalObject)
147{
148 return getDOMPrototype<JSDOMPluginArray>(vm, globalObject);
149}
150
151JSValue JSDOMPluginArray::getConstructor(VM& vm, const JSGlobalObject* globalObject)
152{
153 return getDOMConstructor<JSDOMPluginArrayConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
154}
155
156void JSDOMPluginArray::destroy(JSC::JSCell* cell)
157{
158 JSDOMPluginArray* thisObject = static_cast<JSDOMPluginArray*>(cell);
159 thisObject->JSDOMPluginArray::~JSDOMPluginArray();
160}
161
162bool JSDOMPluginArray::getOwnPropertySlot(JSObject* object, ExecState* state, PropertyName propertyName, PropertySlot& slot)
163{
164 auto* thisObject = jsCast<JSDOMPluginArray*>(object);
165 ASSERT_GC_OBJECT_INHERITS(thisObject, info());
166 if (auto index = parseIndex(propertyName)) {
167 if (index.value() < thisObject->wrapped().length()) {
168 auto value = toJS<IDLNullable<IDLInterface<DOMPlugin>>>(*state, *thisObject->globalObject(), thisObject->wrapped().item(index.value()));
169 slot.setValue(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly), value);
170 return true;
171 }
172 return JSObject::getOwnPropertySlot(object, state, propertyName, slot);
173 }
174 using GetterIDLType = IDLInterface<DOMPlugin>;
175 auto getterFunctor = [] (auto& thisObject, auto propertyName) -> Optional<typename GetterIDLType::ImplementationType> {
176 auto result = thisObject.wrapped().namedItem(propertyNameToAtomString(propertyName));
177 if (!GetterIDLType::isNullValue(result))
178 return typename GetterIDLType::ImplementationType { GetterIDLType::extractValueFromNullable(result) };
179 return WTF::nullopt;
180 };
181 if (auto namedProperty = accessVisibleNamedProperty<OverrideBuiltins::No>(*state, *thisObject, propertyName, getterFunctor)) {
182 auto value = toJS<IDLNullable<IDLInterface<DOMPlugin>>>(*state, *thisObject->globalObject(), WTFMove(namedProperty.value()));
183 slot.setValue(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum), value);
184 return true;
185 }
186 return JSObject::getOwnPropertySlot(object, state, propertyName, slot);
187}
188
189bool JSDOMPluginArray::getOwnPropertySlotByIndex(JSObject* object, ExecState* state, unsigned index, PropertySlot& slot)
190{
191 auto* thisObject = jsCast<JSDOMPluginArray*>(object);
192 ASSERT_GC_OBJECT_INHERITS(thisObject, info());
193 if (LIKELY(index <= MAX_ARRAY_INDEX)) {
194 if (index < thisObject->wrapped().length()) {
195 auto value = toJS<IDLNullable<IDLInterface<DOMPlugin>>>(*state, *thisObject->globalObject(), thisObject->wrapped().item(index));
196 slot.setValue(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly), value);
197 return true;
198 }
199 return JSObject::getOwnPropertySlotByIndex(object, state, index, slot);
200 }
201 auto propertyName = Identifier::from(state, index);
202 using GetterIDLType = IDLInterface<DOMPlugin>;
203 auto getterFunctor = [] (auto& thisObject, auto propertyName) -> Optional<typename GetterIDLType::ImplementationType> {
204 auto result = thisObject.wrapped().namedItem(propertyNameToAtomString(propertyName));
205 if (!GetterIDLType::isNullValue(result))
206 return typename GetterIDLType::ImplementationType { GetterIDLType::extractValueFromNullable(result) };
207 return WTF::nullopt;
208 };
209 if (auto namedProperty = accessVisibleNamedProperty<OverrideBuiltins::No>(*state, *thisObject, propertyName, getterFunctor)) {
210 auto value = toJS<IDLNullable<IDLInterface<DOMPlugin>>>(*state, *thisObject->globalObject(), WTFMove(namedProperty.value()));
211 slot.setValue(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum), value);
212 return true;
213 }
214 return JSObject::getOwnPropertySlotByIndex(object, state, index, slot);
215}
216
217void JSDOMPluginArray::getOwnPropertyNames(JSObject* object, ExecState* state, PropertyNameArray& propertyNames, EnumerationMode mode)
218{
219 auto* thisObject = jsCast<JSDOMPluginArray*>(object);
220 ASSERT_GC_OBJECT_INHERITS(object, info());
221 for (unsigned i = 0, count = thisObject->wrapped().length(); i < count; ++i)
222 propertyNames.add(Identifier::from(state, i));
223 if (mode.includeDontEnumProperties()) {
224 for (auto& propertyName : thisObject->wrapped().supportedPropertyNames())
225 propertyNames.add(Identifier::fromString(state, propertyName));
226 }
227 JSObject::getOwnPropertyNames(object, state, propertyNames, mode);
228}
229
230template<> inline JSDOMPluginArray* IDLAttribute<JSDOMPluginArray>::cast(ExecState& state, EncodedJSValue thisValue)
231{
232 return jsDynamicCast<JSDOMPluginArray*>(state.vm(), JSValue::decode(thisValue));
233}
234
235template<> inline JSDOMPluginArray* IDLOperation<JSDOMPluginArray>::cast(ExecState& state)
236{
237 return jsDynamicCast<JSDOMPluginArray*>(state.vm(), state.thisValue());
238}
239
240EncodedJSValue jsDOMPluginArrayConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
241{
242 VM& vm = state->vm();
243 auto throwScope = DECLARE_THROW_SCOPE(vm);
244 auto* prototype = jsDynamicCast<JSDOMPluginArrayPrototype*>(vm, JSValue::decode(thisValue));
245 if (UNLIKELY(!prototype))
246 return throwVMTypeError(state, throwScope);
247 return JSValue::encode(JSDOMPluginArray::getConstructor(state->vm(), prototype->globalObject()));
248}
249
250bool setJSDOMPluginArrayConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
251{
252 VM& vm = state->vm();
253 auto throwScope = DECLARE_THROW_SCOPE(vm);
254 auto* prototype = jsDynamicCast<JSDOMPluginArrayPrototype*>(vm, JSValue::decode(thisValue));
255 if (UNLIKELY(!prototype)) {
256 throwVMTypeError(state, throwScope);
257 return false;
258 }
259 // Shadowing a built-in constructor
260 return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
261}
262
263static inline JSValue jsDOMPluginArrayLengthGetter(ExecState& state, JSDOMPluginArray& thisObject, ThrowScope& throwScope)
264{
265 UNUSED_PARAM(throwScope);
266 UNUSED_PARAM(state);
267 auto& impl = thisObject.wrapped();
268 JSValue result = toJS<IDLUnsignedLong>(state, throwScope, impl.length());
269 return result;
270}
271
272EncodedJSValue jsDOMPluginArrayLength(ExecState* state, EncodedJSValue thisValue, PropertyName)
273{
274 return IDLAttribute<JSDOMPluginArray>::get<jsDOMPluginArrayLengthGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "length");
275}
276
277static inline JSC::EncodedJSValue jsDOMPluginArrayPrototypeFunctionItemBody(JSC::ExecState* state, typename IDLOperation<JSDOMPluginArray>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
278{
279 UNUSED_PARAM(state);
280 UNUSED_PARAM(throwScope);
281 auto& impl = castedThis->wrapped();
282 if (UNLIKELY(state->argumentCount() < 1))
283 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
284 auto index = convert<IDLUnsignedLong>(*state, state->uncheckedArgument(0));
285 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
286 return JSValue::encode(toJS<IDLNullable<IDLInterface<DOMPlugin>>>(*state, *castedThis->globalObject(), impl.item(WTFMove(index))));
287}
288
289EncodedJSValue JSC_HOST_CALL jsDOMPluginArrayPrototypeFunctionItem(ExecState* state)
290{
291 return IDLOperation<JSDOMPluginArray>::call<jsDOMPluginArrayPrototypeFunctionItemBody>(*state, "item");
292}
293
294static inline JSC::EncodedJSValue jsDOMPluginArrayPrototypeFunctionNamedItemBody(JSC::ExecState* state, typename IDLOperation<JSDOMPluginArray>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
295{
296 UNUSED_PARAM(state);
297 UNUSED_PARAM(throwScope);
298 auto& impl = castedThis->wrapped();
299 if (UNLIKELY(state->argumentCount() < 1))
300 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
301 auto name = convert<IDLDOMString>(*state, state->uncheckedArgument(0));
302 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
303 return JSValue::encode(toJS<IDLNullable<IDLInterface<DOMPlugin>>>(*state, *castedThis->globalObject(), impl.namedItem(WTFMove(name))));
304}
305
306EncodedJSValue JSC_HOST_CALL jsDOMPluginArrayPrototypeFunctionNamedItem(ExecState* state)
307{
308 return IDLOperation<JSDOMPluginArray>::call<jsDOMPluginArrayPrototypeFunctionNamedItemBody>(*state, "namedItem");
309}
310
311static inline JSC::EncodedJSValue jsDOMPluginArrayPrototypeFunctionRefreshBody(JSC::ExecState* state, typename IDLOperation<JSDOMPluginArray>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
312{
313 UNUSED_PARAM(state);
314 UNUSED_PARAM(throwScope);
315 auto& impl = castedThis->wrapped();
316 auto reload = convert<IDLBoolean>(*state, state->argument(0));
317 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
318 impl.refresh(WTFMove(reload));
319 return JSValue::encode(jsUndefined());
320}
321
322EncodedJSValue JSC_HOST_CALL jsDOMPluginArrayPrototypeFunctionRefresh(ExecState* state)
323{
324 return IDLOperation<JSDOMPluginArray>::call<jsDOMPluginArrayPrototypeFunctionRefreshBody>(*state, "refresh");
325}
326
327void JSDOMPluginArray::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
328{
329 auto* thisObject = jsCast<JSDOMPluginArray*>(cell);
330 builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
331 if (thisObject->scriptExecutionContext())
332 builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
333 Base::heapSnapshot(cell, builder);
334}
335
336bool JSDOMPluginArrayOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason)
337{
338 auto* jsDOMPluginArray = jsCast<JSDOMPluginArray*>(handle.slot()->asCell());
339 Frame* root = WTF::getPtr(jsDOMPluginArray->wrapped().frame());
340 if (!root)
341 return false;
342 if (UNLIKELY(reason))
343 *reason = "Reachable from Frame";
344 return visitor.containsOpaqueRoot(root);
345}
346
347void JSDOMPluginArrayOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
348{
349 auto* jsDOMPluginArray = static_cast<JSDOMPluginArray*>(handle.slot()->asCell());
350 auto& world = *static_cast<DOMWrapperWorld*>(context);
351 uncacheWrapper(world, &jsDOMPluginArray->wrapped(), jsDOMPluginArray);
352}
353
354JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<DOMPluginArray>&& impl)
355{
356 // If you hit this failure the interface definition has the ImplementationLacksVTable
357 // attribute. You should remove that attribute. If the class has subclasses
358 // that may be passed through this toJS() function you should use the SkipVTableValidation
359 // attribute to DOMPluginArray.
360 static_assert(!std::is_polymorphic<DOMPluginArray>::value, "DOMPluginArray is polymorphic but the IDL claims it is not");
361 return createWrapper<DOMPluginArray>(globalObject, WTFMove(impl));
362}
363
364JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, DOMPluginArray& impl)
365{
366 return wrap(state, globalObject, impl);
367}
368
369DOMPluginArray* JSDOMPluginArray::toWrapped(JSC::VM& vm, JSC::JSValue value)
370{
371 if (auto* wrapper = jsDynamicCast<JSDOMPluginArray*>(vm, value))
372 return &wrapper->wrapped();
373 return nullptr;
374}
375
376}
377