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(INDEXED_DATABASE)
24 
25 #include "JSIDBDatabase.h"
26 
27 #include "DOMStringList.h"
28 #include "Event.h"
29 #include "EventListener.h"
30 #include "ExceptionCode.h"
31 #include "IDBDatabase.h"
32 #include "IDBObjectStore.h"
33 #include "IDBTransaction.h"
34 #include "IDBVersionChangeRequest.h"
35 #include "JSDOMBinding.h"
36 #include "JSDOMStringList.h"
37 #include "JSEvent.h"
38 #include "JSEventListener.h"
39 #include "JSIDBObjectStore.h"
40 #include "JSIDBTransaction.h"
41 #include "JSIDBVersionChangeRequest.h"
42 #include "JSOptionsObject.h"
43 #include "KURL.h"
44 #include <runtime/Error.h>
45 #include <runtime/JSString.h>
46 #include <wtf/GetPtr.h>
47 
48 using namespace JSC;
49 
50 namespace WebCore {
51 
52 ASSERT_CLASS_FITS_IN_CELL(JSIDBDatabase);
53 
54 /* Hash table */
55 #if ENABLE(JIT)
56 #define THUNK_GENERATOR(generator) , generator
57 #else
58 #define THUNK_GENERATOR(generator)
59 #endif
60 
61 static const HashTableValue JSIDBDatabaseTableValues[8] =
62 {
63     { "name", DontDelete | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsIDBDatabaseName), (intptr_t)0 THUNK_GENERATOR(0) },
64     { "version", DontDelete | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsIDBDatabaseVersion), (intptr_t)0 THUNK_GENERATOR(0) },
65     { "objectStoreNames", DontDelete | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsIDBDatabaseObjectStoreNames), (intptr_t)0 THUNK_GENERATOR(0) },
66     { "onabort", DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsIDBDatabaseOnabort), (intptr_t)setJSIDBDatabaseOnabort THUNK_GENERATOR(0) },
67     { "onerror", DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsIDBDatabaseOnerror), (intptr_t)setJSIDBDatabaseOnerror THUNK_GENERATOR(0) },
68     { "onversionchange", DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsIDBDatabaseOnversionchange), (intptr_t)setJSIDBDatabaseOnversionchange THUNK_GENERATOR(0) },
69     { "constructor", DontEnum | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsIDBDatabaseConstructor), (intptr_t)0 THUNK_GENERATOR(0) },
70     { 0, 0, 0, 0 THUNK_GENERATOR(0) }
71 };
72 
73 #undef THUNK_GENERATOR
74 static JSC_CONST_HASHTABLE HashTable JSIDBDatabaseTable = { 17, 15, JSIDBDatabaseTableValues, 0 };
75 /* Hash table for constructor */
76 #if ENABLE(JIT)
77 #define THUNK_GENERATOR(generator) , generator
78 #else
79 #define THUNK_GENERATOR(generator)
80 #endif
81 
82 static const HashTableValue JSIDBDatabaseConstructorTableValues[1] =
83 {
84     { 0, 0, 0, 0 THUNK_GENERATOR(0) }
85 };
86 
87 #undef THUNK_GENERATOR
88 static JSC_CONST_HASHTABLE HashTable JSIDBDatabaseConstructorTable = { 1, 0, JSIDBDatabaseConstructorTableValues, 0 };
89 class JSIDBDatabaseConstructor : public DOMConstructorObject {
90 public:
91     JSIDBDatabaseConstructor(JSC::ExecState*, JSC::Structure*, JSDOMGlobalObject*);
92 
93     virtual bool getOwnPropertySlot(JSC::ExecState*, const JSC::Identifier&, JSC::PropertySlot&);
94     virtual bool getOwnPropertyDescriptor(JSC::ExecState*, const JSC::Identifier&, JSC::PropertyDescriptor&);
95     static const JSC::ClassInfo s_info;
createStructure(JSC::JSGlobalData & globalData,JSC::JSValue prototype)96     static JSC::Structure* createStructure(JSC::JSGlobalData& globalData, JSC::JSValue prototype)
97     {
98         return JSC::Structure::create(globalData, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), AnonymousSlotCount, &s_info);
99     }
100 protected:
101     static const unsigned StructureFlags = JSC::OverridesGetOwnPropertySlot | JSC::ImplementsHasInstance | DOMConstructorObject::StructureFlags;
102 };
103 
104 const ClassInfo JSIDBDatabaseConstructor::s_info = { "IDBDatabaseConstructor", &DOMConstructorObject::s_info, &JSIDBDatabaseConstructorTable, 0 };
105 
JSIDBDatabaseConstructor(ExecState * exec,Structure * structure,JSDOMGlobalObject * globalObject)106 JSIDBDatabaseConstructor::JSIDBDatabaseConstructor(ExecState* exec, Structure* structure, JSDOMGlobalObject* globalObject)
107     : DOMConstructorObject(structure, globalObject)
108 {
109     ASSERT(inherits(&s_info));
110     putDirect(exec->globalData(), exec->propertyNames().prototype, JSIDBDatabasePrototype::self(exec, globalObject), DontDelete | ReadOnly);
111 }
112 
getOwnPropertySlot(ExecState * exec,const Identifier & propertyName,PropertySlot & slot)113 bool JSIDBDatabaseConstructor::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
114 {
115     return getStaticValueSlot<JSIDBDatabaseConstructor, JSDOMWrapper>(exec, &JSIDBDatabaseConstructorTable, this, propertyName, slot);
116 }
117 
getOwnPropertyDescriptor(ExecState * exec,const Identifier & propertyName,PropertyDescriptor & descriptor)118 bool JSIDBDatabaseConstructor::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
119 {
120     return getStaticValueDescriptor<JSIDBDatabaseConstructor, JSDOMWrapper>(exec, &JSIDBDatabaseConstructorTable, this, propertyName, descriptor);
121 }
122 
123 /* Hash table for prototype */
124 #if ENABLE(JIT)
125 #define THUNK_GENERATOR(generator) , generator
126 #else
127 #define THUNK_GENERATOR(generator)
128 #endif
129 
130 static const HashTableValue JSIDBDatabasePrototypeTableValues[9] =
131 {
132     { "createObjectStore", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsIDBDatabasePrototypeFunctionCreateObjectStore), (intptr_t)2 THUNK_GENERATOR(0) },
133     { "deleteObjectStore", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsIDBDatabasePrototypeFunctionDeleteObjectStore), (intptr_t)1 THUNK_GENERATOR(0) },
134     { "setVersion", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsIDBDatabasePrototypeFunctionSetVersion), (intptr_t)1 THUNK_GENERATOR(0) },
135     { "transaction", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsIDBDatabasePrototypeFunctionTransaction), (intptr_t)2 THUNK_GENERATOR(0) },
136     { "close", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsIDBDatabasePrototypeFunctionClose), (intptr_t)0 THUNK_GENERATOR(0) },
137     { "addEventListener", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsIDBDatabasePrototypeFunctionAddEventListener), (intptr_t)3 THUNK_GENERATOR(0) },
138     { "removeEventListener", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsIDBDatabasePrototypeFunctionRemoveEventListener), (intptr_t)3 THUNK_GENERATOR(0) },
139     { "dispatchEvent", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsIDBDatabasePrototypeFunctionDispatchEvent), (intptr_t)1 THUNK_GENERATOR(0) },
140     { 0, 0, 0, 0 THUNK_GENERATOR(0) }
141 };
142 
143 #undef THUNK_GENERATOR
144 static JSC_CONST_HASHTABLE HashTable JSIDBDatabasePrototypeTable = { 16, 15, JSIDBDatabasePrototypeTableValues, 0 };
145 const ClassInfo JSIDBDatabasePrototype::s_info = { "IDBDatabasePrototype", &JSC::JSObjectWithGlobalObject::s_info, &JSIDBDatabasePrototypeTable, 0 };
146 
self(ExecState * exec,JSGlobalObject * globalObject)147 JSObject* JSIDBDatabasePrototype::self(ExecState* exec, JSGlobalObject* globalObject)
148 {
149     return getDOMPrototype<JSIDBDatabase>(exec, globalObject);
150 }
151 
getOwnPropertySlot(ExecState * exec,const Identifier & propertyName,PropertySlot & slot)152 bool JSIDBDatabasePrototype::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
153 {
154     return getStaticFunctionSlot<JSObject>(exec, &JSIDBDatabasePrototypeTable, this, propertyName, slot);
155 }
156 
getOwnPropertyDescriptor(ExecState * exec,const Identifier & propertyName,PropertyDescriptor & descriptor)157 bool JSIDBDatabasePrototype::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
158 {
159     return getStaticFunctionDescriptor<JSObject>(exec, &JSIDBDatabasePrototypeTable, this, propertyName, descriptor);
160 }
161 
162 const ClassInfo JSIDBDatabase::s_info = { "IDBDatabase", &JSDOMWrapper::s_info, &JSIDBDatabaseTable, 0 };
163 
JSIDBDatabase(Structure * structure,JSDOMGlobalObject * globalObject,PassRefPtr<IDBDatabase> impl)164 JSIDBDatabase::JSIDBDatabase(Structure* structure, JSDOMGlobalObject* globalObject, PassRefPtr<IDBDatabase> impl)
165     : JSDOMWrapper(structure, globalObject)
166     , m_impl(impl)
167 {
168     ASSERT(inherits(&s_info));
169 }
170 
visitChildren(SlotVisitor & visitor)171 void JSIDBDatabase::visitChildren(SlotVisitor& visitor)
172 {
173     Base::visitChildren(visitor);
174     impl()->visitJSEventListeners(visitor);
175 }
176 
createPrototype(ExecState * exec,JSGlobalObject * globalObject)177 JSObject* JSIDBDatabase::createPrototype(ExecState* exec, JSGlobalObject* globalObject)
178 {
179     return new (exec) JSIDBDatabasePrototype(exec->globalData(), globalObject, JSIDBDatabasePrototype::createStructure(globalObject->globalData(), globalObject->objectPrototype()));
180 }
181 
getOwnPropertySlot(ExecState * exec,const Identifier & propertyName,PropertySlot & slot)182 bool JSIDBDatabase::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
183 {
184     return getStaticValueSlot<JSIDBDatabase, Base>(exec, &JSIDBDatabaseTable, this, propertyName, slot);
185 }
186 
getOwnPropertyDescriptor(ExecState * exec,const Identifier & propertyName,PropertyDescriptor & descriptor)187 bool JSIDBDatabase::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
188 {
189     return getStaticValueDescriptor<JSIDBDatabase, Base>(exec, &JSIDBDatabaseTable, this, propertyName, descriptor);
190 }
191 
jsIDBDatabaseName(ExecState * exec,JSValue slotBase,const Identifier &)192 JSValue jsIDBDatabaseName(ExecState* exec, JSValue slotBase, const Identifier&)
193 {
194     JSIDBDatabase* castedThis = static_cast<JSIDBDatabase*>(asObject(slotBase));
195     UNUSED_PARAM(exec);
196     IDBDatabase* imp = static_cast<IDBDatabase*>(castedThis->impl());
197     JSValue result = jsString(exec, imp->name());
198     return result;
199 }
200 
201 
jsIDBDatabaseVersion(ExecState * exec,JSValue slotBase,const Identifier &)202 JSValue jsIDBDatabaseVersion(ExecState* exec, JSValue slotBase, const Identifier&)
203 {
204     JSIDBDatabase* castedThis = static_cast<JSIDBDatabase*>(asObject(slotBase));
205     UNUSED_PARAM(exec);
206     IDBDatabase* imp = static_cast<IDBDatabase*>(castedThis->impl());
207     JSValue result = jsString(exec, imp->version());
208     return result;
209 }
210 
211 
jsIDBDatabaseObjectStoreNames(ExecState * exec,JSValue slotBase,const Identifier &)212 JSValue jsIDBDatabaseObjectStoreNames(ExecState* exec, JSValue slotBase, const Identifier&)
213 {
214     JSIDBDatabase* castedThis = static_cast<JSIDBDatabase*>(asObject(slotBase));
215     UNUSED_PARAM(exec);
216     IDBDatabase* imp = static_cast<IDBDatabase*>(castedThis->impl());
217     JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(imp->objectStoreNames()));
218     return result;
219 }
220 
221 
jsIDBDatabaseOnabort(ExecState * exec,JSValue slotBase,const Identifier &)222 JSValue jsIDBDatabaseOnabort(ExecState* exec, JSValue slotBase, const Identifier&)
223 {
224     JSIDBDatabase* castedThis = static_cast<JSIDBDatabase*>(asObject(slotBase));
225     UNUSED_PARAM(exec);
226     IDBDatabase* imp = static_cast<IDBDatabase*>(castedThis->impl());
227     if (EventListener* listener = imp->onabort()) {
228         if (const JSEventListener* jsListener = JSEventListener::cast(listener)) {
229             if (JSObject* jsFunction = jsListener->jsFunction(imp->scriptExecutionContext()))
230                 return jsFunction;
231         }
232     }
233     return jsNull();
234 }
235 
236 
jsIDBDatabaseOnerror(ExecState * exec,JSValue slotBase,const Identifier &)237 JSValue jsIDBDatabaseOnerror(ExecState* exec, JSValue slotBase, const Identifier&)
238 {
239     JSIDBDatabase* castedThis = static_cast<JSIDBDatabase*>(asObject(slotBase));
240     UNUSED_PARAM(exec);
241     IDBDatabase* imp = static_cast<IDBDatabase*>(castedThis->impl());
242     if (EventListener* listener = imp->onerror()) {
243         if (const JSEventListener* jsListener = JSEventListener::cast(listener)) {
244             if (JSObject* jsFunction = jsListener->jsFunction(imp->scriptExecutionContext()))
245                 return jsFunction;
246         }
247     }
248     return jsNull();
249 }
250 
251 
jsIDBDatabaseOnversionchange(ExecState * exec,JSValue slotBase,const Identifier &)252 JSValue jsIDBDatabaseOnversionchange(ExecState* exec, JSValue slotBase, const Identifier&)
253 {
254     JSIDBDatabase* castedThis = static_cast<JSIDBDatabase*>(asObject(slotBase));
255     UNUSED_PARAM(exec);
256     IDBDatabase* imp = static_cast<IDBDatabase*>(castedThis->impl());
257     if (EventListener* listener = imp->onversionchange()) {
258         if (const JSEventListener* jsListener = JSEventListener::cast(listener)) {
259             if (JSObject* jsFunction = jsListener->jsFunction(imp->scriptExecutionContext()))
260                 return jsFunction;
261         }
262     }
263     return jsNull();
264 }
265 
266 
jsIDBDatabaseConstructor(ExecState * exec,JSValue slotBase,const Identifier &)267 JSValue jsIDBDatabaseConstructor(ExecState* exec, JSValue slotBase, const Identifier&)
268 {
269     JSIDBDatabase* domObject = static_cast<JSIDBDatabase*>(asObject(slotBase));
270     return JSIDBDatabase::getConstructor(exec, domObject->globalObject());
271 }
272 
put(ExecState * exec,const Identifier & propertyName,JSValue value,PutPropertySlot & slot)273 void JSIDBDatabase::put(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot)
274 {
275     lookupPut<JSIDBDatabase, Base>(exec, propertyName, value, &JSIDBDatabaseTable, this, slot);
276 }
277 
setJSIDBDatabaseOnabort(ExecState * exec,JSObject * thisObject,JSValue value)278 void setJSIDBDatabaseOnabort(ExecState* exec, JSObject* thisObject, JSValue value)
279 {
280     UNUSED_PARAM(exec);
281     JSIDBDatabase* castedThis = static_cast<JSIDBDatabase*>(thisObject);
282     IDBDatabase* imp = static_cast<IDBDatabase*>(castedThis->impl());
283     imp->setOnabort(createJSAttributeEventListener(exec, value, thisObject));
284 }
285 
286 
setJSIDBDatabaseOnerror(ExecState * exec,JSObject * thisObject,JSValue value)287 void setJSIDBDatabaseOnerror(ExecState* exec, JSObject* thisObject, JSValue value)
288 {
289     UNUSED_PARAM(exec);
290     JSIDBDatabase* castedThis = static_cast<JSIDBDatabase*>(thisObject);
291     IDBDatabase* imp = static_cast<IDBDatabase*>(castedThis->impl());
292     imp->setOnerror(createJSAttributeEventListener(exec, value, thisObject));
293 }
294 
295 
setJSIDBDatabaseOnversionchange(ExecState * exec,JSObject * thisObject,JSValue value)296 void setJSIDBDatabaseOnversionchange(ExecState* exec, JSObject* thisObject, JSValue value)
297 {
298     UNUSED_PARAM(exec);
299     JSIDBDatabase* castedThis = static_cast<JSIDBDatabase*>(thisObject);
300     IDBDatabase* imp = static_cast<IDBDatabase*>(castedThis->impl());
301     imp->setOnversionchange(createJSAttributeEventListener(exec, value, thisObject));
302 }
303 
304 
getConstructor(ExecState * exec,JSGlobalObject * globalObject)305 JSValue JSIDBDatabase::getConstructor(ExecState* exec, JSGlobalObject* globalObject)
306 {
307     return getDOMConstructor<JSIDBDatabaseConstructor>(exec, static_cast<JSDOMGlobalObject*>(globalObject));
308 }
309 
jsIDBDatabasePrototypeFunctionCreateObjectStore(ExecState * exec)310 EncodedJSValue JSC_HOST_CALL jsIDBDatabasePrototypeFunctionCreateObjectStore(ExecState* exec)
311 {
312     JSValue thisValue = exec->hostThisValue();
313     if (!thisValue.inherits(&JSIDBDatabase::s_info))
314         return throwVMTypeError(exec);
315     JSIDBDatabase* castedThis = static_cast<JSIDBDatabase*>(asObject(thisValue));
316     IDBDatabase* imp = static_cast<IDBDatabase*>(castedThis->impl());
317     ExceptionCode ec = 0;
318     const String& name(ustringToString(exec->argument(0).toString(exec)));
319     if (exec->hadException())
320         return JSValue::encode(jsUndefined());
321 
322     int argsCount = exec->argumentCount();
323     if (argsCount <= 1) {
324 
325         JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(imp->createObjectStore(name, ec)));
326         setDOMException(exec, ec);
327         return JSValue::encode(result);
328     }
329 
330     OptionsObject* options(toOptionsObject(exec->argument(1)));
331     if (exec->hadException())
332         return JSValue::encode(jsUndefined());
333 
334 
335     JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(imp->createObjectStore(name, options, ec)));
336     setDOMException(exec, ec);
337     return JSValue::encode(result);
338 }
339 
jsIDBDatabasePrototypeFunctionDeleteObjectStore(ExecState * exec)340 EncodedJSValue JSC_HOST_CALL jsIDBDatabasePrototypeFunctionDeleteObjectStore(ExecState* exec)
341 {
342     JSValue thisValue = exec->hostThisValue();
343     if (!thisValue.inherits(&JSIDBDatabase::s_info))
344         return throwVMTypeError(exec);
345     JSIDBDatabase* castedThis = static_cast<JSIDBDatabase*>(asObject(thisValue));
346     IDBDatabase* imp = static_cast<IDBDatabase*>(castedThis->impl());
347     ExceptionCode ec = 0;
348     const String& name(ustringToString(exec->argument(0).toString(exec)));
349     if (exec->hadException())
350         return JSValue::encode(jsUndefined());
351 
352     imp->deleteObjectStore(name, ec);
353     setDOMException(exec, ec);
354     return JSValue::encode(jsUndefined());
355 }
356 
jsIDBDatabasePrototypeFunctionSetVersion(ExecState * exec)357 EncodedJSValue JSC_HOST_CALL jsIDBDatabasePrototypeFunctionSetVersion(ExecState* exec)
358 {
359     JSValue thisValue = exec->hostThisValue();
360     if (!thisValue.inherits(&JSIDBDatabase::s_info))
361         return throwVMTypeError(exec);
362     JSIDBDatabase* castedThis = static_cast<JSIDBDatabase*>(asObject(thisValue));
363     IDBDatabase* imp = static_cast<IDBDatabase*>(castedThis->impl());
364     ExceptionCode ec = 0;
365     ScriptExecutionContext* scriptContext = static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->scriptExecutionContext();
366     if (!scriptContext)
367         return JSValue::encode(jsUndefined());
368     const String& version(ustringToString(exec->argument(0).toString(exec)));
369     if (exec->hadException())
370         return JSValue::encode(jsUndefined());
371 
372 
373     JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(imp->setVersion(scriptContext, version, ec)));
374     setDOMException(exec, ec);
375     return JSValue::encode(result);
376 }
377 
jsIDBDatabasePrototypeFunctionTransaction(ExecState * exec)378 EncodedJSValue JSC_HOST_CALL jsIDBDatabasePrototypeFunctionTransaction(ExecState* exec)
379 {
380     JSValue thisValue = exec->hostThisValue();
381     if (!thisValue.inherits(&JSIDBDatabase::s_info))
382         return throwVMTypeError(exec);
383     JSIDBDatabase* castedThis = static_cast<JSIDBDatabase*>(asObject(thisValue));
384     IDBDatabase* imp = static_cast<IDBDatabase*>(castedThis->impl());
385     ExceptionCode ec = 0;
386     ScriptExecutionContext* scriptContext = static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->scriptExecutionContext();
387     if (!scriptContext)
388         return JSValue::encode(jsUndefined());
389 
390     int argsCount = exec->argumentCount();
391     if (argsCount <= 0) {
392 
393         JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(imp->transaction(scriptContext, ec)));
394         setDOMException(exec, ec);
395         return JSValue::encode(result);
396     }
397 
398     DOMStringList* storeNames(toDOMStringList(exec->argument(0)));
399     if (exec->hadException())
400         return JSValue::encode(jsUndefined());
401     if (argsCount <= 1) {
402 
403         JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(imp->transaction(scriptContext, storeNames, ec)));
404         setDOMException(exec, ec);
405         return JSValue::encode(result);
406     }
407 
408     unsigned short mode(exec->argument(1).toUInt32(exec));
409     if (exec->hadException())
410         return JSValue::encode(jsUndefined());
411 
412 
413     JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(imp->transaction(scriptContext, storeNames, mode, ec)));
414     setDOMException(exec, ec);
415     return JSValue::encode(result);
416 }
417 
jsIDBDatabasePrototypeFunctionClose(ExecState * exec)418 EncodedJSValue JSC_HOST_CALL jsIDBDatabasePrototypeFunctionClose(ExecState* exec)
419 {
420     JSValue thisValue = exec->hostThisValue();
421     if (!thisValue.inherits(&JSIDBDatabase::s_info))
422         return throwVMTypeError(exec);
423     JSIDBDatabase* castedThis = static_cast<JSIDBDatabase*>(asObject(thisValue));
424     IDBDatabase* imp = static_cast<IDBDatabase*>(castedThis->impl());
425 
426     imp->close();
427     return JSValue::encode(jsUndefined());
428 }
429 
jsIDBDatabasePrototypeFunctionAddEventListener(ExecState * exec)430 EncodedJSValue JSC_HOST_CALL jsIDBDatabasePrototypeFunctionAddEventListener(ExecState* exec)
431 {
432     JSValue thisValue = exec->hostThisValue();
433     if (!thisValue.inherits(&JSIDBDatabase::s_info))
434         return throwVMTypeError(exec);
435     JSIDBDatabase* castedThis = static_cast<JSIDBDatabase*>(asObject(thisValue));
436     IDBDatabase* imp = static_cast<IDBDatabase*>(castedThis->impl());
437     JSValue listener = exec->argument(1);
438     if (!listener.isObject())
439         return JSValue::encode(jsUndefined());
440     imp->addEventListener(ustringToAtomicString(exec->argument(0).toString(exec)), JSEventListener::create(asObject(listener), castedThis, false, currentWorld(exec)), exec->argument(2).toBoolean(exec));
441     return JSValue::encode(jsUndefined());
442 }
443 
jsIDBDatabasePrototypeFunctionRemoveEventListener(ExecState * exec)444 EncodedJSValue JSC_HOST_CALL jsIDBDatabasePrototypeFunctionRemoveEventListener(ExecState* exec)
445 {
446     JSValue thisValue = exec->hostThisValue();
447     if (!thisValue.inherits(&JSIDBDatabase::s_info))
448         return throwVMTypeError(exec);
449     JSIDBDatabase* castedThis = static_cast<JSIDBDatabase*>(asObject(thisValue));
450     IDBDatabase* imp = static_cast<IDBDatabase*>(castedThis->impl());
451     JSValue listener = exec->argument(1);
452     if (!listener.isObject())
453         return JSValue::encode(jsUndefined());
454     imp->removeEventListener(ustringToAtomicString(exec->argument(0).toString(exec)), JSEventListener::create(asObject(listener), castedThis, false, currentWorld(exec)).get(), exec->argument(2).toBoolean(exec));
455     return JSValue::encode(jsUndefined());
456 }
457 
jsIDBDatabasePrototypeFunctionDispatchEvent(ExecState * exec)458 EncodedJSValue JSC_HOST_CALL jsIDBDatabasePrototypeFunctionDispatchEvent(ExecState* exec)
459 {
460     JSValue thisValue = exec->hostThisValue();
461     if (!thisValue.inherits(&JSIDBDatabase::s_info))
462         return throwVMTypeError(exec);
463     JSIDBDatabase* castedThis = static_cast<JSIDBDatabase*>(asObject(thisValue));
464     IDBDatabase* imp = static_cast<IDBDatabase*>(castedThis->impl());
465     ExceptionCode ec = 0;
466     Event* evt(toEvent(exec->argument(0)));
467     if (exec->hadException())
468         return JSValue::encode(jsUndefined());
469 
470 
471     JSC::JSValue result = jsBoolean(imp->dispatchEvent(evt, ec));
472     setDOMException(exec, ec);
473     return JSValue::encode(result);
474 }
475 
isObservable(JSIDBDatabase * jsIDBDatabase)476 static inline bool isObservable(JSIDBDatabase* jsIDBDatabase)
477 {
478     if (jsIDBDatabase->hasCustomProperties())
479         return true;
480     if (jsIDBDatabase->impl()->hasEventListeners())
481         return true;
482     return false;
483 }
484 
isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle,void *,SlotVisitor & visitor)485 bool JSIDBDatabaseOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor)
486 {
487     JSIDBDatabase* jsIDBDatabase = static_cast<JSIDBDatabase*>(handle.get().asCell());
488     if (jsIDBDatabase->impl()->hasPendingActivity())
489         return true;
490     if (!isObservable(jsIDBDatabase))
491         return false;
492     UNUSED_PARAM(visitor);
493     return false;
494 }
495 
finalize(JSC::Handle<JSC::Unknown> handle,void * context)496 void JSIDBDatabaseOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
497 {
498     JSIDBDatabase* jsIDBDatabase = static_cast<JSIDBDatabase*>(handle.get().asCell());
499     DOMWrapperWorld* world = static_cast<DOMWrapperWorld*>(context);
500     uncacheWrapper(world, jsIDBDatabase->impl(), jsIDBDatabase);
501 }
502 
toJS(JSC::ExecState * exec,JSDOMGlobalObject * globalObject,IDBDatabase * impl)503 JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, IDBDatabase* impl)
504 {
505     return wrap<JSIDBDatabase>(exec, globalObject, impl);
506 }
507 
toIDBDatabase(JSC::JSValue value)508 IDBDatabase* toIDBDatabase(JSC::JSValue value)
509 {
510     return value.inherits(&JSIDBDatabase::s_info) ? static_cast<JSIDBDatabase*>(asObject(value))->impl() : 0;
511 }
512 
513 }
514 
515 #endif // ENABLE(INDEXED_DATABASE)
516