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