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