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 "JSFileReader.h"
23
24#include "EventNames.h"
25#include "JSBlob.h"
26#include "JSDOMAttribute.h"
27#include "JSDOMBinding.h"
28#include "JSDOMConstructor.h"
29#include "JSDOMConvertBufferSource.h"
30#include "JSDOMConvertInterface.h"
31#include "JSDOMConvertNullable.h"
32#include "JSDOMConvertNumbers.h"
33#include "JSDOMConvertStrings.h"
34#include "JSDOMConvertUnion.h"
35#include "JSDOMExceptionHandling.h"
36#include "JSDOMGlobalObject.h"
37#include "JSDOMOperation.h"
38#include "JSDOMWrapperCache.h"
39#include "JSEventListener.h"
40#include "JSFileError.h"
41#include "ScriptExecutionContext.h"
42#include <JavaScriptCore/HeapSnapshotBuilder.h>
43#include <JavaScriptCore/JSCInlines.h>
44#include <wtf/GetPtr.h>
45#include <wtf/PointerPreparations.h>
46#include <wtf/URL.h>
47#include <wtf/Variant.h>
48
49
50namespace WebCore {
51using namespace JSC;
52
53// Functions
54
55JSC::EncodedJSValue JSC_HOST_CALL jsFileReaderPrototypeFunctionReadAsArrayBuffer(JSC::ExecState*);
56JSC::EncodedJSValue JSC_HOST_CALL jsFileReaderPrototypeFunctionReadAsBinaryString(JSC::ExecState*);
57JSC::EncodedJSValue JSC_HOST_CALL jsFileReaderPrototypeFunctionReadAsText(JSC::ExecState*);
58JSC::EncodedJSValue JSC_HOST_CALL jsFileReaderPrototypeFunctionReadAsDataURL(JSC::ExecState*);
59JSC::EncodedJSValue JSC_HOST_CALL jsFileReaderPrototypeFunctionAbort(JSC::ExecState*);
60
61// Attributes
62
63JSC::EncodedJSValue jsFileReaderConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
64bool setJSFileReaderConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
65JSC::EncodedJSValue jsFileReaderReadyState(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
66JSC::EncodedJSValue jsFileReaderResult(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
67JSC::EncodedJSValue jsFileReaderError(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
68JSC::EncodedJSValue jsFileReaderOnloadstart(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
69bool setJSFileReaderOnloadstart(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
70JSC::EncodedJSValue jsFileReaderOnprogress(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
71bool setJSFileReaderOnprogress(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
72JSC::EncodedJSValue jsFileReaderOnload(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
73bool setJSFileReaderOnload(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
74JSC::EncodedJSValue jsFileReaderOnabort(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
75bool setJSFileReaderOnabort(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
76JSC::EncodedJSValue jsFileReaderOnerror(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
77bool setJSFileReaderOnerror(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
78JSC::EncodedJSValue jsFileReaderOnloadend(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
79bool setJSFileReaderOnloadend(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
80
81class JSFileReaderPrototype : public JSC::JSNonFinalObject {
82public:
83 using Base = JSC::JSNonFinalObject;
84 static JSFileReaderPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
85 {
86 JSFileReaderPrototype* ptr = new (NotNull, JSC::allocateCell<JSFileReaderPrototype>(vm.heap)) JSFileReaderPrototype(vm, globalObject, structure);
87 ptr->finishCreation(vm);
88 return ptr;
89 }
90
91 DECLARE_INFO;
92 static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
93 {
94 return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
95 }
96
97private:
98 JSFileReaderPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
99 : JSC::JSNonFinalObject(vm, structure)
100 {
101 }
102
103 void finishCreation(JSC::VM&);
104};
105
106using JSFileReaderConstructor = JSDOMConstructor<JSFileReader>;
107
108/* Hash table for constructor */
109
110static const HashTableValue JSFileReaderConstructorTableValues[] =
111{
112 { "EMPTY", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(0) } },
113 { "LOADING", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(1) } },
114 { "DONE", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(2) } },
115};
116
117static_assert(FileReader::EMPTY == 0, "EMPTY in FileReader does not match value from IDL");
118static_assert(FileReader::LOADING == 1, "LOADING in FileReader does not match value from IDL");
119static_assert(FileReader::DONE == 2, "DONE in FileReader does not match value from IDL");
120
121template<> EncodedJSValue JSC_HOST_CALL JSFileReaderConstructor::construct(ExecState* state)
122{
123 VM& vm = state->vm();
124 auto throwScope = DECLARE_THROW_SCOPE(vm);
125 UNUSED_PARAM(throwScope);
126 auto* castedThis = jsCast<JSFileReaderConstructor*>(state->jsCallee());
127 ASSERT(castedThis);
128 auto* context = castedThis->scriptExecutionContext();
129 if (UNLIKELY(!context))
130 return throwConstructorScriptExecutionContextUnavailableError(*state, throwScope, "FileReader");
131 auto object = FileReader::create(*context);
132 return JSValue::encode(toJSNewlyCreated<IDLInterface<FileReader>>(*state, *castedThis->globalObject(), WTFMove(object)));
133}
134
135template<> JSValue JSFileReaderConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
136{
137 return JSEventTarget::getConstructor(vm, &globalObject);
138}
139
140template<> void JSFileReaderConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
141{
142 putDirect(vm, vm.propertyNames->prototype, JSFileReader::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
143 putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("FileReader"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
144 putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
145 reifyStaticProperties(vm, JSFileReader::info(), JSFileReaderConstructorTableValues, *this);
146}
147
148template<> const ClassInfo JSFileReaderConstructor::s_info = { "FileReader", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSFileReaderConstructor) };
149
150/* Hash table for prototype */
151
152static const HashTableValue JSFileReaderPrototypeTableValues[] =
153{
154 { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFileReaderConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSFileReaderConstructor) } },
155 { "readyState", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFileReaderReadyState), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
156 { "result", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFileReaderResult), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
157 { "error", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFileReaderError), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
158 { "onloadstart", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFileReaderOnloadstart), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSFileReaderOnloadstart) } },
159 { "onprogress", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFileReaderOnprogress), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSFileReaderOnprogress) } },
160 { "onload", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFileReaderOnload), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSFileReaderOnload) } },
161 { "onabort", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFileReaderOnabort), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSFileReaderOnabort) } },
162 { "onerror", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFileReaderOnerror), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSFileReaderOnerror) } },
163 { "onloadend", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFileReaderOnloadend), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSFileReaderOnloadend) } },
164 { "readAsArrayBuffer", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsFileReaderPrototypeFunctionReadAsArrayBuffer), (intptr_t) (1) } },
165 { "readAsBinaryString", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsFileReaderPrototypeFunctionReadAsBinaryString), (intptr_t) (1) } },
166 { "readAsText", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsFileReaderPrototypeFunctionReadAsText), (intptr_t) (1) } },
167 { "readAsDataURL", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsFileReaderPrototypeFunctionReadAsDataURL), (intptr_t) (1) } },
168 { "abort", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsFileReaderPrototypeFunctionAbort), (intptr_t) (0) } },
169 { "EMPTY", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(0) } },
170 { "LOADING", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(1) } },
171 { "DONE", JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(2) } },
172};
173
174const ClassInfo JSFileReaderPrototype::s_info = { "FileReaderPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSFileReaderPrototype) };
175
176void JSFileReaderPrototype::finishCreation(VM& vm)
177{
178 Base::finishCreation(vm);
179 reifyStaticProperties(vm, JSFileReader::info(), JSFileReaderPrototypeTableValues, *this);
180}
181
182const ClassInfo JSFileReader::s_info = { "FileReader", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSFileReader) };
183
184JSFileReader::JSFileReader(Structure* structure, JSDOMGlobalObject& globalObject, Ref<FileReader>&& impl)
185 : JSEventTarget(structure, globalObject, WTFMove(impl))
186{
187}
188
189void JSFileReader::finishCreation(VM& vm)
190{
191 Base::finishCreation(vm);
192 ASSERT(inherits(vm, info()));
193
194}
195
196JSObject* JSFileReader::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
197{
198 return JSFileReaderPrototype::create(vm, &globalObject, JSFileReaderPrototype::createStructure(vm, &globalObject, JSEventTarget::prototype(vm, globalObject)));
199}
200
201JSObject* JSFileReader::prototype(VM& vm, JSDOMGlobalObject& globalObject)
202{
203 return getDOMPrototype<JSFileReader>(vm, globalObject);
204}
205
206JSValue JSFileReader::getConstructor(VM& vm, const JSGlobalObject* globalObject)
207{
208 return getDOMConstructor<JSFileReaderConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
209}
210
211template<> inline JSFileReader* IDLAttribute<JSFileReader>::cast(ExecState& state, EncodedJSValue thisValue)
212{
213 return jsDynamicCast<JSFileReader*>(state.vm(), JSValue::decode(thisValue));
214}
215
216template<> inline JSFileReader* IDLOperation<JSFileReader>::cast(ExecState& state)
217{
218 return jsDynamicCast<JSFileReader*>(state.vm(), state.thisValue());
219}
220
221EncodedJSValue jsFileReaderConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
222{
223 VM& vm = state->vm();
224 auto throwScope = DECLARE_THROW_SCOPE(vm);
225 auto* prototype = jsDynamicCast<JSFileReaderPrototype*>(vm, JSValue::decode(thisValue));
226 if (UNLIKELY(!prototype))
227 return throwVMTypeError(state, throwScope);
228 return JSValue::encode(JSFileReader::getConstructor(state->vm(), prototype->globalObject()));
229}
230
231bool setJSFileReaderConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
232{
233 VM& vm = state->vm();
234 auto throwScope = DECLARE_THROW_SCOPE(vm);
235 auto* prototype = jsDynamicCast<JSFileReaderPrototype*>(vm, JSValue::decode(thisValue));
236 if (UNLIKELY(!prototype)) {
237 throwVMTypeError(state, throwScope);
238 return false;
239 }
240 // Shadowing a built-in constructor
241 return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
242}
243
244static inline JSValue jsFileReaderReadyStateGetter(ExecState& state, JSFileReader& thisObject, ThrowScope& throwScope)
245{
246 UNUSED_PARAM(throwScope);
247 UNUSED_PARAM(state);
248 auto& impl = thisObject.wrapped();
249 JSValue result = toJS<IDLUnsignedShort>(state, throwScope, impl.readyState());
250 return result;
251}
252
253EncodedJSValue jsFileReaderReadyState(ExecState* state, EncodedJSValue thisValue, PropertyName)
254{
255 return IDLAttribute<JSFileReader>::get<jsFileReaderReadyStateGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "readyState");
256}
257
258static inline JSValue jsFileReaderResultGetter(ExecState& state, JSFileReader& thisObject, ThrowScope& throwScope)
259{
260 UNUSED_PARAM(throwScope);
261 UNUSED_PARAM(state);
262 auto& impl = thisObject.wrapped();
263 JSValue result = toJS<IDLNullable<IDLUnion<IDLDOMString, IDLArrayBuffer>>>(state, *thisObject.globalObject(), throwScope, impl.result());
264 return result;
265}
266
267EncodedJSValue jsFileReaderResult(ExecState* state, EncodedJSValue thisValue, PropertyName)
268{
269 return IDLAttribute<JSFileReader>::get<jsFileReaderResultGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "result");
270}
271
272static inline JSValue jsFileReaderErrorGetter(ExecState& state, JSFileReader& thisObject, ThrowScope& throwScope)
273{
274 UNUSED_PARAM(throwScope);
275 UNUSED_PARAM(state);
276 auto& impl = thisObject.wrapped();
277 JSValue result = toJS<IDLInterface<FileError>>(state, *thisObject.globalObject(), throwScope, impl.error());
278 return result;
279}
280
281EncodedJSValue jsFileReaderError(ExecState* state, EncodedJSValue thisValue, PropertyName)
282{
283 return IDLAttribute<JSFileReader>::get<jsFileReaderErrorGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "error");
284}
285
286static inline JSValue jsFileReaderOnloadstartGetter(ExecState& state, JSFileReader& thisObject, ThrowScope& throwScope)
287{
288 UNUSED_PARAM(throwScope);
289 UNUSED_PARAM(state);
290 return eventHandlerAttribute(thisObject.wrapped(), eventNames().loadstartEvent, worldForDOMObject(thisObject));
291}
292
293EncodedJSValue jsFileReaderOnloadstart(ExecState* state, EncodedJSValue thisValue, PropertyName)
294{
295 return IDLAttribute<JSFileReader>::get<jsFileReaderOnloadstartGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "onloadstart");
296}
297
298static inline bool setJSFileReaderOnloadstartSetter(ExecState& state, JSFileReader& thisObject, JSValue value, ThrowScope& throwScope)
299{
300 UNUSED_PARAM(throwScope);
301 setEventHandlerAttribute(state, thisObject, thisObject.wrapped(), eventNames().loadstartEvent, value);
302 return true;
303}
304
305bool setJSFileReaderOnloadstart(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
306{
307 return IDLAttribute<JSFileReader>::set<setJSFileReaderOnloadstartSetter>(*state, thisValue, encodedValue, "onloadstart");
308}
309
310static inline JSValue jsFileReaderOnprogressGetter(ExecState& state, JSFileReader& thisObject, ThrowScope& throwScope)
311{
312 UNUSED_PARAM(throwScope);
313 UNUSED_PARAM(state);
314 return eventHandlerAttribute(thisObject.wrapped(), eventNames().progressEvent, worldForDOMObject(thisObject));
315}
316
317EncodedJSValue jsFileReaderOnprogress(ExecState* state, EncodedJSValue thisValue, PropertyName)
318{
319 return IDLAttribute<JSFileReader>::get<jsFileReaderOnprogressGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "onprogress");
320}
321
322static inline bool setJSFileReaderOnprogressSetter(ExecState& state, JSFileReader& thisObject, JSValue value, ThrowScope& throwScope)
323{
324 UNUSED_PARAM(throwScope);
325 setEventHandlerAttribute(state, thisObject, thisObject.wrapped(), eventNames().progressEvent, value);
326 return true;
327}
328
329bool setJSFileReaderOnprogress(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
330{
331 return IDLAttribute<JSFileReader>::set<setJSFileReaderOnprogressSetter>(*state, thisValue, encodedValue, "onprogress");
332}
333
334static inline JSValue jsFileReaderOnloadGetter(ExecState& state, JSFileReader& thisObject, ThrowScope& throwScope)
335{
336 UNUSED_PARAM(throwScope);
337 UNUSED_PARAM(state);
338 return eventHandlerAttribute(thisObject.wrapped(), eventNames().loadEvent, worldForDOMObject(thisObject));
339}
340
341EncodedJSValue jsFileReaderOnload(ExecState* state, EncodedJSValue thisValue, PropertyName)
342{
343 return IDLAttribute<JSFileReader>::get<jsFileReaderOnloadGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "onload");
344}
345
346static inline bool setJSFileReaderOnloadSetter(ExecState& state, JSFileReader& thisObject, JSValue value, ThrowScope& throwScope)
347{
348 UNUSED_PARAM(throwScope);
349 setEventHandlerAttribute(state, thisObject, thisObject.wrapped(), eventNames().loadEvent, value);
350 return true;
351}
352
353bool setJSFileReaderOnload(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
354{
355 return IDLAttribute<JSFileReader>::set<setJSFileReaderOnloadSetter>(*state, thisValue, encodedValue, "onload");
356}
357
358static inline JSValue jsFileReaderOnabortGetter(ExecState& state, JSFileReader& thisObject, ThrowScope& throwScope)
359{
360 UNUSED_PARAM(throwScope);
361 UNUSED_PARAM(state);
362 return eventHandlerAttribute(thisObject.wrapped(), eventNames().abortEvent, worldForDOMObject(thisObject));
363}
364
365EncodedJSValue jsFileReaderOnabort(ExecState* state, EncodedJSValue thisValue, PropertyName)
366{
367 return IDLAttribute<JSFileReader>::get<jsFileReaderOnabortGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "onabort");
368}
369
370static inline bool setJSFileReaderOnabortSetter(ExecState& state, JSFileReader& thisObject, JSValue value, ThrowScope& throwScope)
371{
372 UNUSED_PARAM(throwScope);
373 setEventHandlerAttribute(state, thisObject, thisObject.wrapped(), eventNames().abortEvent, value);
374 return true;
375}
376
377bool setJSFileReaderOnabort(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
378{
379 return IDLAttribute<JSFileReader>::set<setJSFileReaderOnabortSetter>(*state, thisValue, encodedValue, "onabort");
380}
381
382static inline JSValue jsFileReaderOnerrorGetter(ExecState& state, JSFileReader& thisObject, ThrowScope& throwScope)
383{
384 UNUSED_PARAM(throwScope);
385 UNUSED_PARAM(state);
386 return eventHandlerAttribute(thisObject.wrapped(), eventNames().errorEvent, worldForDOMObject(thisObject));
387}
388
389EncodedJSValue jsFileReaderOnerror(ExecState* state, EncodedJSValue thisValue, PropertyName)
390{
391 return IDLAttribute<JSFileReader>::get<jsFileReaderOnerrorGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "onerror");
392}
393
394static inline bool setJSFileReaderOnerrorSetter(ExecState& state, JSFileReader& thisObject, JSValue value, ThrowScope& throwScope)
395{
396 UNUSED_PARAM(throwScope);
397 setEventHandlerAttribute(state, thisObject, thisObject.wrapped(), eventNames().errorEvent, value);
398 return true;
399}
400
401bool setJSFileReaderOnerror(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
402{
403 return IDLAttribute<JSFileReader>::set<setJSFileReaderOnerrorSetter>(*state, thisValue, encodedValue, "onerror");
404}
405
406static inline JSValue jsFileReaderOnloadendGetter(ExecState& state, JSFileReader& thisObject, ThrowScope& throwScope)
407{
408 UNUSED_PARAM(throwScope);
409 UNUSED_PARAM(state);
410 return eventHandlerAttribute(thisObject.wrapped(), eventNames().loadendEvent, worldForDOMObject(thisObject));
411}
412
413EncodedJSValue jsFileReaderOnloadend(ExecState* state, EncodedJSValue thisValue, PropertyName)
414{
415 return IDLAttribute<JSFileReader>::get<jsFileReaderOnloadendGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "onloadend");
416}
417
418static inline bool setJSFileReaderOnloadendSetter(ExecState& state, JSFileReader& thisObject, JSValue value, ThrowScope& throwScope)
419{
420 UNUSED_PARAM(throwScope);
421 setEventHandlerAttribute(state, thisObject, thisObject.wrapped(), eventNames().loadendEvent, value);
422 return true;
423}
424
425bool setJSFileReaderOnloadend(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
426{
427 return IDLAttribute<JSFileReader>::set<setJSFileReaderOnloadendSetter>(*state, thisValue, encodedValue, "onloadend");
428}
429
430static inline JSC::EncodedJSValue jsFileReaderPrototypeFunctionReadAsArrayBufferBody(JSC::ExecState* state, typename IDLOperation<JSFileReader>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
431{
432 UNUSED_PARAM(state);
433 UNUSED_PARAM(throwScope);
434 auto& impl = castedThis->wrapped();
435 if (UNLIKELY(state->argumentCount() < 1))
436 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
437 auto blob = convert<IDLNullable<IDLInterface<Blob>>>(*state, state->uncheckedArgument(0), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentTypeError(state, scope, 0, "blob", "FileReader", "readAsArrayBuffer", "Blob"); });
438 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
439 propagateException(*state, throwScope, impl.readAsArrayBuffer(WTFMove(blob)));
440 return JSValue::encode(jsUndefined());
441}
442
443EncodedJSValue JSC_HOST_CALL jsFileReaderPrototypeFunctionReadAsArrayBuffer(ExecState* state)
444{
445 return IDLOperation<JSFileReader>::call<jsFileReaderPrototypeFunctionReadAsArrayBufferBody>(*state, "readAsArrayBuffer");
446}
447
448static inline JSC::EncodedJSValue jsFileReaderPrototypeFunctionReadAsBinaryStringBody(JSC::ExecState* state, typename IDLOperation<JSFileReader>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
449{
450 UNUSED_PARAM(state);
451 UNUSED_PARAM(throwScope);
452 auto& impl = castedThis->wrapped();
453 if (UNLIKELY(state->argumentCount() < 1))
454 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
455 auto blob = convert<IDLNullable<IDLInterface<Blob>>>(*state, state->uncheckedArgument(0), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentTypeError(state, scope, 0, "blob", "FileReader", "readAsBinaryString", "Blob"); });
456 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
457 propagateException(*state, throwScope, impl.readAsBinaryString(WTFMove(blob)));
458 return JSValue::encode(jsUndefined());
459}
460
461EncodedJSValue JSC_HOST_CALL jsFileReaderPrototypeFunctionReadAsBinaryString(ExecState* state)
462{
463 return IDLOperation<JSFileReader>::call<jsFileReaderPrototypeFunctionReadAsBinaryStringBody>(*state, "readAsBinaryString");
464}
465
466static inline JSC::EncodedJSValue jsFileReaderPrototypeFunctionReadAsTextBody(JSC::ExecState* state, typename IDLOperation<JSFileReader>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
467{
468 UNUSED_PARAM(state);
469 UNUSED_PARAM(throwScope);
470 auto& impl = castedThis->wrapped();
471 if (UNLIKELY(state->argumentCount() < 1))
472 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
473 auto blob = convert<IDLNullable<IDLInterface<Blob>>>(*state, state->uncheckedArgument(0), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentTypeError(state, scope, 0, "blob", "FileReader", "readAsText", "Blob"); });
474 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
475 auto encoding = state->argument(1).isUndefined() ? String() : convert<IDLDOMString>(*state, state->uncheckedArgument(1));
476 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
477 propagateException(*state, throwScope, impl.readAsText(WTFMove(blob), WTFMove(encoding)));
478 return JSValue::encode(jsUndefined());
479}
480
481EncodedJSValue JSC_HOST_CALL jsFileReaderPrototypeFunctionReadAsText(ExecState* state)
482{
483 return IDLOperation<JSFileReader>::call<jsFileReaderPrototypeFunctionReadAsTextBody>(*state, "readAsText");
484}
485
486static inline JSC::EncodedJSValue jsFileReaderPrototypeFunctionReadAsDataURLBody(JSC::ExecState* state, typename IDLOperation<JSFileReader>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
487{
488 UNUSED_PARAM(state);
489 UNUSED_PARAM(throwScope);
490 auto& impl = castedThis->wrapped();
491 if (UNLIKELY(state->argumentCount() < 1))
492 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
493 auto blob = convert<IDLNullable<IDLInterface<Blob>>>(*state, state->uncheckedArgument(0), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentTypeError(state, scope, 0, "blob", "FileReader", "readAsDataURL", "Blob"); });
494 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
495 propagateException(*state, throwScope, impl.readAsDataURL(WTFMove(blob)));
496 return JSValue::encode(jsUndefined());
497}
498
499EncodedJSValue JSC_HOST_CALL jsFileReaderPrototypeFunctionReadAsDataURL(ExecState* state)
500{
501 return IDLOperation<JSFileReader>::call<jsFileReaderPrototypeFunctionReadAsDataURLBody>(*state, "readAsDataURL");
502}
503
504static inline JSC::EncodedJSValue jsFileReaderPrototypeFunctionAbortBody(JSC::ExecState* state, typename IDLOperation<JSFileReader>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
505{
506 UNUSED_PARAM(state);
507 UNUSED_PARAM(throwScope);
508 auto& impl = castedThis->wrapped();
509 impl.abort();
510 return JSValue::encode(jsUndefined());
511}
512
513EncodedJSValue JSC_HOST_CALL jsFileReaderPrototypeFunctionAbort(ExecState* state)
514{
515 return IDLOperation<JSFileReader>::call<jsFileReaderPrototypeFunctionAbortBody>(*state, "abort");
516}
517
518void JSFileReader::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
519{
520 auto* thisObject = jsCast<JSFileReader*>(cell);
521 builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
522 if (thisObject->scriptExecutionContext())
523 builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
524 Base::heapSnapshot(cell, builder);
525}
526
527bool JSFileReaderOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason)
528{
529 auto* jsFileReader = jsCast<JSFileReader*>(handle.slot()->asCell());
530 if (jsFileReader->wrapped().hasPendingActivity()) {
531 if (UNLIKELY(reason))
532 *reason = "ActiveDOMObject with pending activity";
533 return true;
534 }
535 if (jsFileReader->wrapped().isFiringEventListeners()) {
536 if (UNLIKELY(reason))
537 *reason = "EventTarget firing event listeners";
538 return true;
539 }
540 UNUSED_PARAM(visitor);
541 UNUSED_PARAM(reason);
542 return false;
543}
544
545void JSFileReaderOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
546{
547 auto* jsFileReader = static_cast<JSFileReader*>(handle.slot()->asCell());
548 auto& world = *static_cast<DOMWrapperWorld*>(context);
549 uncacheWrapper(world, &jsFileReader->wrapped(), jsFileReader);
550}
551
552#if ENABLE(BINDING_INTEGRITY)
553#if PLATFORM(WIN)
554#pragma warning(disable: 4483)
555extern "C" { extern void (*const __identifier("??_7FileReader@WebCore@@6B@")[])(); }
556#else
557extern "C" { extern void* _ZTVN7WebCore10FileReaderE[]; }
558#endif
559#endif
560
561JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<FileReader>&& impl)
562{
563
564#if ENABLE(BINDING_INTEGRITY)
565 void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
566#if PLATFORM(WIN)
567 void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7FileReader@WebCore@@6B@"));
568#else
569 void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore10FileReaderE[2]);
570#endif
571
572 // If this fails FileReader does not have a vtable, so you need to add the
573 // ImplementationLacksVTable attribute to the interface definition
574 static_assert(std::is_polymorphic<FileReader>::value, "FileReader is not polymorphic");
575
576 // If you hit this assertion you either have a use after free bug, or
577 // FileReader has subclasses. If FileReader has subclasses that get passed
578 // to toJS() we currently require FileReader you to opt out of binding hardening
579 // by adding the SkipVTableValidation attribute to the interface IDL definition
580 RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
581#endif
582 return createWrapper<FileReader>(globalObject, WTFMove(impl));
583}
584
585JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, FileReader& impl)
586{
587 return wrap(state, globalObject, impl);
588}
589
590FileReader* JSFileReader::toWrapped(JSC::VM& vm, JSC::JSValue value)
591{
592 if (auto* wrapper = jsDynamicCast<JSFileReader*>(vm, value))
593 return &wrapper->wrapped();
594 return nullptr;
595}
596
597}
598