tizen beta release
[framework/web/webkit-efl.git] / DerivedSources / WebCore / JSFileReaderSync.cpp
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
23 #if ENABLE(BLOB)
24
25 #include "JSFileReaderSync.h"
26
27 #include "ExceptionCode.h"
28 #include "FileReaderSync.h"
29 #include "JSArrayBuffer.h"
30 #include "JSBlob.h"
31 #include "JSDOMBinding.h"
32 #include "KURL.h"
33 #include <runtime/Error.h>
34 #include <wtf/ArrayBuffer.h>
35 #include <wtf/GetPtr.h>
36
37 using namespace JSC;
38
39 namespace WebCore {
40
41 ASSERT_CLASS_FITS_IN_CELL(JSFileReaderSync);
42
43 /* Hash table */
44 #if ENABLE(JIT)
45 #define THUNK_GENERATOR(generator) , generator
46 #else
47 #define THUNK_GENERATOR(generator)
48 #endif
49 #if ENABLE(DFG_JIT)
50 #define INTRINSIC(intrinsic) , intrinsic
51 #else
52 #define INTRINSIC(intrinsic)
53 #endif
54
55 static const HashTableValue JSFileReaderSyncTableValues[] =
56 {
57     { "constructor", DontEnum | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFileReaderSyncConstructor), (intptr_t)0 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
58     { 0, 0, 0, 0 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) }
59 };
60
61 #undef THUNK_GENERATOR
62 static const HashTable JSFileReaderSyncTable = { 2, 1, JSFileReaderSyncTableValues, 0 };
63 /* Hash table for constructor */
64 #if ENABLE(JIT)
65 #define THUNK_GENERATOR(generator) , generator
66 #else
67 #define THUNK_GENERATOR(generator)
68 #endif
69 #if ENABLE(DFG_JIT)
70 #define INTRINSIC(intrinsic) , intrinsic
71 #else
72 #define INTRINSIC(intrinsic)
73 #endif
74
75 static const HashTableValue JSFileReaderSyncConstructorTableValues[] =
76 {
77     { 0, 0, 0, 0 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) }
78 };
79
80 #undef THUNK_GENERATOR
81 static const HashTable JSFileReaderSyncConstructorTable = { 1, 0, JSFileReaderSyncConstructorTableValues, 0 };
82 const ClassInfo JSFileReaderSyncConstructor::s_info = { "FileReaderSyncConstructor", &DOMConstructorObject::s_info, &JSFileReaderSyncConstructorTable, 0, CREATE_METHOD_TABLE(JSFileReaderSyncConstructor) };
83
84 JSFileReaderSyncConstructor::JSFileReaderSyncConstructor(Structure* structure, JSDOMGlobalObject* globalObject)
85     : DOMConstructorObject(structure, globalObject)
86 {
87 }
88
89 void JSFileReaderSyncConstructor::finishCreation(ExecState* exec, JSDOMGlobalObject* globalObject)
90 {
91     Base::finishCreation(exec->globalData());
92     ASSERT(inherits(&s_info));
93     putDirect(exec->globalData(), exec->propertyNames().prototype, JSFileReaderSyncPrototype::self(exec, globalObject), DontDelete | ReadOnly);
94 }
95
96 bool JSFileReaderSyncConstructor::getOwnPropertySlot(JSCell* cell, ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
97 {
98     return getStaticValueSlot<JSFileReaderSyncConstructor, JSDOMWrapper>(exec, &JSFileReaderSyncConstructorTable, static_cast<JSFileReaderSyncConstructor*>(cell), propertyName, slot);
99 }
100
101 bool JSFileReaderSyncConstructor::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
102 {
103     return getStaticValueDescriptor<JSFileReaderSyncConstructor, JSDOMWrapper>(exec, &JSFileReaderSyncConstructorTable, static_cast<JSFileReaderSyncConstructor*>(object), propertyName, descriptor);
104 }
105
106 EncodedJSValue JSC_HOST_CALL JSFileReaderSyncConstructor::constructJSFileReaderSync(ExecState* exec)
107 {
108     JSFileReaderSyncConstructor* jsConstructor = static_cast<JSFileReaderSyncConstructor*>(exec->callee());
109     RefPtr<FileReaderSync> object = FileReaderSync::create();
110     return JSValue::encode(asObject(toJS(exec, jsConstructor->globalObject(), object.get())));
111 }
112
113 ConstructType JSFileReaderSyncConstructor::getConstructData(JSCell*, ConstructData& constructData)
114 {
115     constructData.native.function = constructJSFileReaderSync;
116     return ConstructTypeHost;
117 }
118
119 /* Hash table for prototype */
120 #if ENABLE(JIT)
121 #define THUNK_GENERATOR(generator) , generator
122 #else
123 #define THUNK_GENERATOR(generator)
124 #endif
125 #if ENABLE(DFG_JIT)
126 #define INTRINSIC(intrinsic) , intrinsic
127 #else
128 #define INTRINSIC(intrinsic)
129 #endif
130
131 static const HashTableValue JSFileReaderSyncPrototypeTableValues[] =
132 {
133     { "readAsArrayBuffer", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsFileReaderSyncPrototypeFunctionReadAsArrayBuffer), (intptr_t)1 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
134     { "readAsBinaryString", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsFileReaderSyncPrototypeFunctionReadAsBinaryString), (intptr_t)1 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
135     { "readAsText", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsFileReaderSyncPrototypeFunctionReadAsText), (intptr_t)2 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
136     { "readAsDataURL", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsFileReaderSyncPrototypeFunctionReadAsDataURL), (intptr_t)1 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) },
137     { 0, 0, 0, 0 THUNK_GENERATOR(0) INTRINSIC(DFG::NoIntrinsic) }
138 };
139
140 #undef THUNK_GENERATOR
141 static const HashTable JSFileReaderSyncPrototypeTable = { 9, 7, JSFileReaderSyncPrototypeTableValues, 0 };
142 static const HashTable* getJSFileReaderSyncPrototypeTable(ExecState* exec)
143 {
144     return getHashTableForGlobalData(exec->globalData(), &JSFileReaderSyncPrototypeTable);
145 }
146
147 const ClassInfo JSFileReaderSyncPrototype::s_info = { "FileReaderSyncPrototype", &JSC::JSNonFinalObject::s_info, 0, getJSFileReaderSyncPrototypeTable, CREATE_METHOD_TABLE(JSFileReaderSyncPrototype) };
148
149 JSObject* JSFileReaderSyncPrototype::self(ExecState* exec, JSGlobalObject* globalObject)
150 {
151     return getDOMPrototype<JSFileReaderSync>(exec, globalObject);
152 }
153
154 bool JSFileReaderSyncPrototype::getOwnPropertySlot(JSCell* cell, ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
155 {
156     JSFileReaderSyncPrototype* thisObject = jsCast<JSFileReaderSyncPrototype*>(cell);
157     return getStaticFunctionSlot<JSObject>(exec, getJSFileReaderSyncPrototypeTable(exec), thisObject, propertyName, slot);
158 }
159
160 bool JSFileReaderSyncPrototype::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
161 {
162     JSFileReaderSyncPrototype* thisObject = jsCast<JSFileReaderSyncPrototype*>(object);
163     return getStaticFunctionDescriptor<JSObject>(exec, getJSFileReaderSyncPrototypeTable(exec), thisObject, propertyName, descriptor);
164 }
165
166 static const HashTable* getJSFileReaderSyncTable(ExecState* exec)
167 {
168     return getHashTableForGlobalData(exec->globalData(), &JSFileReaderSyncTable);
169 }
170
171 const ClassInfo JSFileReaderSync::s_info = { "FileReaderSync", &JSDOMWrapper::s_info, 0, getJSFileReaderSyncTable , CREATE_METHOD_TABLE(JSFileReaderSync) };
172
173 JSFileReaderSync::JSFileReaderSync(Structure* structure, JSDOMGlobalObject* globalObject, PassRefPtr<FileReaderSync> impl)
174     : JSDOMWrapper(structure, globalObject)
175     , m_impl(impl.leakRef())
176 {
177 }
178
179 void JSFileReaderSync::finishCreation(JSGlobalData& globalData)
180 {
181     Base::finishCreation(globalData);
182     ASSERT(inherits(&s_info));
183 }
184
185 JSObject* JSFileReaderSync::createPrototype(ExecState* exec, JSGlobalObject* globalObject)
186 {
187     return JSFileReaderSyncPrototype::create(exec->globalData(), globalObject, JSFileReaderSyncPrototype::createStructure(globalObject->globalData(), globalObject, globalObject->objectPrototype()));
188 }
189
190 bool JSFileReaderSync::getOwnPropertySlot(JSCell* cell, ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
191 {
192     JSFileReaderSync* thisObject = jsCast<JSFileReaderSync*>(cell);
193     ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);
194     return getStaticValueSlot<JSFileReaderSync, Base>(exec, getJSFileReaderSyncTable(exec), thisObject, propertyName, slot);
195 }
196
197 bool JSFileReaderSync::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
198 {
199     JSFileReaderSync* thisObject = jsCast<JSFileReaderSync*>(object);
200     ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);
201     return getStaticValueDescriptor<JSFileReaderSync, Base>(exec, getJSFileReaderSyncTable(exec), thisObject, propertyName, descriptor);
202 }
203
204 JSValue jsFileReaderSyncConstructor(ExecState* exec, JSValue slotBase, const Identifier&)
205 {
206     JSFileReaderSync* domObject = static_cast<JSFileReaderSync*>(asObject(slotBase));
207     return JSFileReaderSync::getConstructor(exec, domObject->globalObject());
208 }
209
210 JSValue JSFileReaderSync::getConstructor(ExecState* exec, JSGlobalObject* globalObject)
211 {
212     return getDOMConstructor<JSFileReaderSyncConstructor>(exec, static_cast<JSDOMGlobalObject*>(globalObject));
213 }
214
215 EncodedJSValue JSC_HOST_CALL jsFileReaderSyncPrototypeFunctionReadAsArrayBuffer(ExecState* exec)
216 {
217     JSValue thisValue = exec->hostThisValue();
218     if (!thisValue.inherits(&JSFileReaderSync::s_info))
219         return throwVMTypeError(exec);
220     JSFileReaderSync* castedThis = static_cast<JSFileReaderSync*>(asObject(thisValue));
221     ASSERT_GC_OBJECT_INHERITS(castedThis, &JSFileReaderSync::s_info);
222     FileReaderSync* imp = static_cast<FileReaderSync*>(castedThis->impl());
223     if (exec->argumentCount() < 1)
224         return throwVMError(exec, createTypeError(exec, "Not enough arguments"));
225     ExceptionCode ec = 0;
226     ScriptExecutionContext* scriptContext = static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->scriptExecutionContext();
227     if (!scriptContext)
228         return JSValue::encode(jsUndefined());
229     Blob* blob(toBlob(MAYBE_MISSING_PARAMETER(exec, 0, MissingIsUndefined)));
230     if (exec->hadException())
231         return JSValue::encode(jsUndefined());
232
233     JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(imp->readAsArrayBuffer(scriptContext, blob, ec)));
234     setDOMException(exec, ec);
235     return JSValue::encode(result);
236 }
237
238 EncodedJSValue JSC_HOST_CALL jsFileReaderSyncPrototypeFunctionReadAsBinaryString(ExecState* exec)
239 {
240     JSValue thisValue = exec->hostThisValue();
241     if (!thisValue.inherits(&JSFileReaderSync::s_info))
242         return throwVMTypeError(exec);
243     JSFileReaderSync* castedThis = static_cast<JSFileReaderSync*>(asObject(thisValue));
244     ASSERT_GC_OBJECT_INHERITS(castedThis, &JSFileReaderSync::s_info);
245     FileReaderSync* imp = static_cast<FileReaderSync*>(castedThis->impl());
246     if (exec->argumentCount() < 1)
247         return throwVMError(exec, createTypeError(exec, "Not enough arguments"));
248     ExceptionCode ec = 0;
249     ScriptExecutionContext* scriptContext = static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->scriptExecutionContext();
250     if (!scriptContext)
251         return JSValue::encode(jsUndefined());
252     Blob* blob(toBlob(MAYBE_MISSING_PARAMETER(exec, 0, MissingIsUndefined)));
253     if (exec->hadException())
254         return JSValue::encode(jsUndefined());
255
256     JSC::JSValue result = jsOwnedStringOrNull(exec, imp->readAsBinaryString(scriptContext, blob, ec));
257     setDOMException(exec, ec);
258     return JSValue::encode(result);
259 }
260
261 EncodedJSValue JSC_HOST_CALL jsFileReaderSyncPrototypeFunctionReadAsText(ExecState* exec)
262 {
263     JSValue thisValue = exec->hostThisValue();
264     if (!thisValue.inherits(&JSFileReaderSync::s_info))
265         return throwVMTypeError(exec);
266     JSFileReaderSync* castedThis = static_cast<JSFileReaderSync*>(asObject(thisValue));
267     ASSERT_GC_OBJECT_INHERITS(castedThis, &JSFileReaderSync::s_info);
268     FileReaderSync* imp = static_cast<FileReaderSync*>(castedThis->impl());
269     if (exec->argumentCount() < 1)
270         return throwVMError(exec, createTypeError(exec, "Not enough arguments"));
271     ExceptionCode ec = 0;
272     ScriptExecutionContext* scriptContext = static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->scriptExecutionContext();
273     if (!scriptContext)
274         return JSValue::encode(jsUndefined());
275     Blob* blob(toBlob(MAYBE_MISSING_PARAMETER(exec, 0, MissingIsUndefined)));
276     if (exec->hadException())
277         return JSValue::encode(jsUndefined());
278
279     size_t argsCount = exec->argumentCount();
280     if (argsCount <= 1) {
281
282         JSC::JSValue result = jsOwnedStringOrNull(exec, imp->readAsText(scriptContext, blob, ec));
283         setDOMException(exec, ec);
284         return JSValue::encode(result);
285     }
286
287     const String& encoding(ustringToString(MAYBE_MISSING_PARAMETER(exec, 1, MissingIsUndefined).isEmpty() ? UString() : MAYBE_MISSING_PARAMETER(exec, 1, MissingIsUndefined).toString(exec)));
288     if (exec->hadException())
289         return JSValue::encode(jsUndefined());
290
291     JSC::JSValue result = jsOwnedStringOrNull(exec, imp->readAsText(scriptContext, blob, encoding, ec));
292     setDOMException(exec, ec);
293     return JSValue::encode(result);
294 }
295
296 EncodedJSValue JSC_HOST_CALL jsFileReaderSyncPrototypeFunctionReadAsDataURL(ExecState* exec)
297 {
298     JSValue thisValue = exec->hostThisValue();
299     if (!thisValue.inherits(&JSFileReaderSync::s_info))
300         return throwVMTypeError(exec);
301     JSFileReaderSync* castedThis = static_cast<JSFileReaderSync*>(asObject(thisValue));
302     ASSERT_GC_OBJECT_INHERITS(castedThis, &JSFileReaderSync::s_info);
303     FileReaderSync* imp = static_cast<FileReaderSync*>(castedThis->impl());
304     if (exec->argumentCount() < 1)
305         return throwVMError(exec, createTypeError(exec, "Not enough arguments"));
306     ExceptionCode ec = 0;
307     ScriptExecutionContext* scriptContext = static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->scriptExecutionContext();
308     if (!scriptContext)
309         return JSValue::encode(jsUndefined());
310     Blob* blob(toBlob(MAYBE_MISSING_PARAMETER(exec, 0, MissingIsUndefined)));
311     if (exec->hadException())
312         return JSValue::encode(jsUndefined());
313
314     JSC::JSValue result = jsOwnedStringOrNull(exec, imp->readAsDataURL(scriptContext, blob, ec));
315     setDOMException(exec, ec);
316     return JSValue::encode(result);
317 }
318
319 static inline bool isObservable(JSFileReaderSync* jsFileReaderSync)
320 {
321     if (jsFileReaderSync->hasCustomProperties())
322         return true;
323     return false;
324 }
325
326 bool JSFileReaderSyncOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor)
327 {
328     JSFileReaderSync* jsFileReaderSync = static_cast<JSFileReaderSync*>(handle.get().asCell());
329     if (!isObservable(jsFileReaderSync))
330         return false;
331     UNUSED_PARAM(visitor);
332     return false;
333 }
334
335 void JSFileReaderSyncOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
336 {
337     JSFileReaderSync* jsFileReaderSync = static_cast<JSFileReaderSync*>(handle.get().asCell());
338     DOMWrapperWorld* world = static_cast<DOMWrapperWorld*>(context);
339     uncacheWrapper(world, jsFileReaderSync->impl(), jsFileReaderSync);
340     jsFileReaderSync->releaseImpl();
341 }
342
343 JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, FileReaderSync* impl)
344 {
345     return wrap<JSFileReaderSync>(exec, globalObject, impl);
346 }
347
348 FileReaderSync* toFileReaderSync(JSC::JSValue value)
349 {
350     return value.inherits(&JSFileReaderSync::s_info) ? static_cast<JSFileReaderSync*>(asObject(value))->impl() : 0;
351 }
352
353 }
354
355 #endif // ENABLE(BLOB)