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