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 "JSFileList.h"
23
24#include "JSDOMAttribute.h"
25#include "JSDOMBinding.h"
26#include "JSDOMConstructorNotConstructable.h"
27#include "JSDOMConvertInterface.h"
28#include "JSDOMConvertNumbers.h"
29#include "JSDOMExceptionHandling.h"
30#include "JSDOMGlobalObject.h"
31#include "JSDOMOperation.h"
32#include "JSDOMWrapperCache.h"
33#include "JSFile.h"
34#include "ScriptExecutionContext.h"
35#include <JavaScriptCore/ArrayPrototype.h>
36#include <JavaScriptCore/BuiltinNames.h>
37#include <JavaScriptCore/FunctionPrototype.h>
38#include <JavaScriptCore/HeapSnapshotBuilder.h>
39#include <JavaScriptCore/JSCInlines.h>
40#include <JavaScriptCore/PropertyNameArray.h>
41#include <wtf/GetPtr.h>
42#include <wtf/PointerPreparations.h>
43#include <wtf/URL.h>
44
45
46namespace WebCore {
47using namespace JSC;
48
49// Functions
50
51JSC::EncodedJSValue JSC_HOST_CALL jsFileListPrototypeFunctionItem(JSC::ExecState*);
52
53// Attributes
54
55JSC::EncodedJSValue jsFileListConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
56bool setJSFileListConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
57JSC::EncodedJSValue jsFileListLength(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
58
59class JSFileListPrototype : public JSC::JSNonFinalObject {
60public:
61 using Base = JSC::JSNonFinalObject;
62 static JSFileListPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
63 {
64 JSFileListPrototype* ptr = new (NotNull, JSC::allocateCell<JSFileListPrototype>(vm.heap)) JSFileListPrototype(vm, globalObject, structure);
65 ptr->finishCreation(vm);
66 return ptr;
67 }
68
69 DECLARE_INFO;
70 static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
71 {
72 return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
73 }
74
75private:
76 JSFileListPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
77 : JSC::JSNonFinalObject(vm, structure)
78 {
79 }
80
81 void finishCreation(JSC::VM&);
82};
83
84using JSFileListConstructor = JSDOMConstructorNotConstructable<JSFileList>;
85
86template<> JSValue JSFileListConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
87{
88 UNUSED_PARAM(vm);
89 return globalObject.functionPrototype();
90}
91
92template<> void JSFileListConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
93{
94 putDirect(vm, vm.propertyNames->prototype, JSFileList::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
95 putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("FileList"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
96 putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
97}
98
99template<> const ClassInfo JSFileListConstructor::s_info = { "FileList", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSFileListConstructor) };
100
101/* Hash table for prototype */
102
103static const HashTableValue JSFileListPrototypeTableValues[] =
104{
105 { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFileListConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSFileListConstructor) } },
106 { "length", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFileListLength), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
107 { "item", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsFileListPrototypeFunctionItem), (intptr_t) (1) } },
108};
109
110const ClassInfo JSFileListPrototype::s_info = { "FileListPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSFileListPrototype) };
111
112void JSFileListPrototype::finishCreation(VM& vm)
113{
114 Base::finishCreation(vm);
115 reifyStaticProperties(vm, JSFileList::info(), JSFileListPrototypeTableValues, *this);
116 putDirect(vm, vm.propertyNames->iteratorSymbol, globalObject()->arrayPrototype()->getDirect(vm, vm.propertyNames->builtinNames().valuesPrivateName()), static_cast<unsigned>(JSC::PropertyAttribute::DontEnum));
117}
118
119const ClassInfo JSFileList::s_info = { "FileList", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSFileList) };
120
121JSFileList::JSFileList(Structure* structure, JSDOMGlobalObject& globalObject, Ref<FileList>&& impl)
122 : JSDOMWrapper<FileList>(structure, globalObject, WTFMove(impl))
123{
124}
125
126void JSFileList::finishCreation(VM& vm)
127{
128 Base::finishCreation(vm);
129 ASSERT(inherits(vm, info()));
130
131}
132
133JSObject* JSFileList::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
134{
135 return JSFileListPrototype::create(vm, &globalObject, JSFileListPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype()));
136}
137
138JSObject* JSFileList::prototype(VM& vm, JSDOMGlobalObject& globalObject)
139{
140 return getDOMPrototype<JSFileList>(vm, globalObject);
141}
142
143JSValue JSFileList::getConstructor(VM& vm, const JSGlobalObject* globalObject)
144{
145 return getDOMConstructor<JSFileListConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
146}
147
148void JSFileList::destroy(JSC::JSCell* cell)
149{
150 JSFileList* thisObject = static_cast<JSFileList*>(cell);
151 thisObject->JSFileList::~JSFileList();
152}
153
154bool JSFileList::getOwnPropertySlot(JSObject* object, ExecState* state, PropertyName propertyName, PropertySlot& slot)
155{
156 auto* thisObject = jsCast<JSFileList*>(object);
157 ASSERT_GC_OBJECT_INHERITS(thisObject, info());
158 if (auto index = parseIndex(propertyName)) {
159 if (index.value() < thisObject->wrapped().length()) {
160 auto value = toJS<IDLInterface<File>>(*state, *thisObject->globalObject(), thisObject->wrapped().item(index.value()));
161 slot.setValue(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly), value);
162 return true;
163 }
164 }
165 return JSObject::getOwnPropertySlot(object, state, propertyName, slot);
166}
167
168bool JSFileList::getOwnPropertySlotByIndex(JSObject* object, ExecState* state, unsigned index, PropertySlot& slot)
169{
170 auto* thisObject = jsCast<JSFileList*>(object);
171 ASSERT_GC_OBJECT_INHERITS(thisObject, info());
172 if (LIKELY(index <= MAX_ARRAY_INDEX)) {
173 if (index < thisObject->wrapped().length()) {
174 auto value = toJS<IDLInterface<File>>(*state, *thisObject->globalObject(), thisObject->wrapped().item(index));
175 slot.setValue(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly), value);
176 return true;
177 }
178 }
179 return JSObject::getOwnPropertySlotByIndex(object, state, index, slot);
180}
181
182void JSFileList::getOwnPropertyNames(JSObject* object, ExecState* state, PropertyNameArray& propertyNames, EnumerationMode mode)
183{
184 auto* thisObject = jsCast<JSFileList*>(object);
185 ASSERT_GC_OBJECT_INHERITS(object, info());
186 for (unsigned i = 0, count = thisObject->wrapped().length(); i < count; ++i)
187 propertyNames.add(Identifier::from(state, i));
188 JSObject::getOwnPropertyNames(object, state, propertyNames, mode);
189}
190
191template<> inline JSFileList* IDLAttribute<JSFileList>::cast(ExecState& state, EncodedJSValue thisValue)
192{
193 return jsDynamicCast<JSFileList*>(state.vm(), JSValue::decode(thisValue));
194}
195
196template<> inline JSFileList* IDLOperation<JSFileList>::cast(ExecState& state)
197{
198 return jsDynamicCast<JSFileList*>(state.vm(), state.thisValue());
199}
200
201EncodedJSValue jsFileListConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
202{
203 VM& vm = state->vm();
204 auto throwScope = DECLARE_THROW_SCOPE(vm);
205 auto* prototype = jsDynamicCast<JSFileListPrototype*>(vm, JSValue::decode(thisValue));
206 if (UNLIKELY(!prototype))
207 return throwVMTypeError(state, throwScope);
208 return JSValue::encode(JSFileList::getConstructor(state->vm(), prototype->globalObject()));
209}
210
211bool setJSFileListConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
212{
213 VM& vm = state->vm();
214 auto throwScope = DECLARE_THROW_SCOPE(vm);
215 auto* prototype = jsDynamicCast<JSFileListPrototype*>(vm, JSValue::decode(thisValue));
216 if (UNLIKELY(!prototype)) {
217 throwVMTypeError(state, throwScope);
218 return false;
219 }
220 // Shadowing a built-in constructor
221 return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
222}
223
224static inline JSValue jsFileListLengthGetter(ExecState& state, JSFileList& thisObject, ThrowScope& throwScope)
225{
226 UNUSED_PARAM(throwScope);
227 UNUSED_PARAM(state);
228 auto& impl = thisObject.wrapped();
229 JSValue result = toJS<IDLUnsignedLong>(state, throwScope, impl.length());
230 return result;
231}
232
233EncodedJSValue jsFileListLength(ExecState* state, EncodedJSValue thisValue, PropertyName)
234{
235 return IDLAttribute<JSFileList>::get<jsFileListLengthGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "length");
236}
237
238static inline JSC::EncodedJSValue jsFileListPrototypeFunctionItemBody(JSC::ExecState* state, typename IDLOperation<JSFileList>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
239{
240 UNUSED_PARAM(state);
241 UNUSED_PARAM(throwScope);
242 auto& impl = castedThis->wrapped();
243 if (UNLIKELY(state->argumentCount() < 1))
244 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
245 auto index = convert<IDLUnsignedLong>(*state, state->uncheckedArgument(0));
246 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
247 return JSValue::encode(toJS<IDLInterface<File>>(*state, *castedThis->globalObject(), impl.item(WTFMove(index))));
248}
249
250EncodedJSValue JSC_HOST_CALL jsFileListPrototypeFunctionItem(ExecState* state)
251{
252 return IDLOperation<JSFileList>::call<jsFileListPrototypeFunctionItemBody>(*state, "item");
253}
254
255void JSFileList::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
256{
257 auto* thisObject = jsCast<JSFileList*>(cell);
258 builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
259 if (thisObject->scriptExecutionContext())
260 builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
261 Base::heapSnapshot(cell, builder);
262}
263
264bool JSFileListOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason)
265{
266 UNUSED_PARAM(handle);
267 UNUSED_PARAM(visitor);
268 UNUSED_PARAM(reason);
269 return false;
270}
271
272void JSFileListOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
273{
274 auto* jsFileList = static_cast<JSFileList*>(handle.slot()->asCell());
275 auto& world = *static_cast<DOMWrapperWorld*>(context);
276 uncacheWrapper(world, &jsFileList->wrapped(), jsFileList);
277}
278
279JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<FileList>&& impl)
280{
281 // If you hit this failure the interface definition has the ImplementationLacksVTable
282 // attribute. You should remove that attribute. If the class has subclasses
283 // that may be passed through this toJS() function you should use the SkipVTableValidation
284 // attribute to FileList.
285 static_assert(!std::is_polymorphic<FileList>::value, "FileList is polymorphic but the IDL claims it is not");
286 return createWrapper<FileList>(globalObject, WTFMove(impl));
287}
288
289JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, FileList& impl)
290{
291 return wrap(state, globalObject, impl);
292}
293
294FileList* JSFileList::toWrapped(JSC::VM& vm, JSC::JSValue value)
295{
296 if (auto* wrapper = jsDynamicCast<JSFileList*>(vm, value))
297 return &wrapper->wrapped();
298 return nullptr;
299}
300
301}
302