/*
    This file is part of the WebKit open source project.
    This file has been generated by generate-bindings.pl. DO NOT MODIFY!

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/

#include "config.h"

#if ENABLE(INDEXED_DATABASE)

#include "JSIDBOpenDBRequest.h"

#include "EventListener.h"
#include "IDBOpenDBRequest.h"
#include "JSEventListener.h"
#include <wtf/GetPtr.h>

using namespace JSC;

namespace WebCore {

/* Hash table */

static const HashTableValue JSIDBOpenDBRequestTableValues[] =
{
    { "onblocked", DontDelete, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsIDBOpenDBRequestOnblocked), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSIDBOpenDBRequestOnblocked) },
    { "onupgradeneeded", DontDelete, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsIDBOpenDBRequestOnupgradeneeded), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSIDBOpenDBRequestOnupgradeneeded) },
    { "constructor", DontEnum | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsIDBOpenDBRequestConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { 0, 0, NoIntrinsic, 0, 0 }
};

static const HashTable JSIDBOpenDBRequestTable = { 8, 7, true, JSIDBOpenDBRequestTableValues, 0 };
/* Hash table for constructor */

static const HashTableValue JSIDBOpenDBRequestConstructorTableValues[] =
{
    { 0, 0, NoIntrinsic, 0, 0 }
};

static const HashTable JSIDBOpenDBRequestConstructorTable = { 1, 0, false, JSIDBOpenDBRequestConstructorTableValues, 0 };
static const HashTable& getJSIDBOpenDBRequestConstructorTable(VM& vm)
{
    return getHashTableForGlobalData(vm, JSIDBOpenDBRequestConstructorTable);
}

const ClassInfo JSIDBOpenDBRequestConstructor::s_info = { "IDBOpenDBRequestConstructor", &Base::s_info, 0, getJSIDBOpenDBRequestConstructorTable, CREATE_METHOD_TABLE(JSIDBOpenDBRequestConstructor) };

JSIDBOpenDBRequestConstructor::JSIDBOpenDBRequestConstructor(Structure* structure, JSDOMGlobalObject* globalObject)
    : DOMConstructorObject(structure, globalObject)
{
}

void JSIDBOpenDBRequestConstructor::finishCreation(VM& vm, JSDOMGlobalObject* globalObject)
{
    Base::finishCreation(vm);
    ASSERT(inherits(info()));
    putDirect(vm, vm.propertyNames->prototype, JSIDBOpenDBRequestPrototype::self(vm, globalObject), DontDelete | ReadOnly);
    putDirect(vm, vm.propertyNames->length, jsNumber(0), ReadOnly | DontDelete | DontEnum);
}

bool JSIDBOpenDBRequestConstructor::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
{
    return getStaticValueSlot<JSIDBOpenDBRequestConstructor, JSDOMWrapper>(exec, getJSIDBOpenDBRequestConstructorTable(exec->vm()), jsCast<JSIDBOpenDBRequestConstructor*>(object), propertyName, slot);
}

/* Hash table for prototype */

static const HashTableValue JSIDBOpenDBRequestPrototypeTableValues[] =
{
    { 0, 0, NoIntrinsic, 0, 0 }
};

static const HashTable JSIDBOpenDBRequestPrototypeTable = { 1, 0, false, JSIDBOpenDBRequestPrototypeTableValues, 0 };
static const HashTable& getJSIDBOpenDBRequestPrototypeTable(VM& vm)
{
    return getHashTableForGlobalData(vm, JSIDBOpenDBRequestPrototypeTable);
}

const ClassInfo JSIDBOpenDBRequestPrototype::s_info = { "IDBOpenDBRequestPrototype", &Base::s_info, 0, getJSIDBOpenDBRequestPrototypeTable, CREATE_METHOD_TABLE(JSIDBOpenDBRequestPrototype) };

JSObject* JSIDBOpenDBRequestPrototype::self(VM& vm, JSGlobalObject* globalObject)
{
    return getDOMPrototype<JSIDBOpenDBRequest>(vm, globalObject);
}

static const HashTable& getJSIDBOpenDBRequestTable(VM& vm)
{
    return getHashTableForGlobalData(vm, JSIDBOpenDBRequestTable);
}

const ClassInfo JSIDBOpenDBRequest::s_info = { "IDBOpenDBRequest", &Base::s_info, 0, getJSIDBOpenDBRequestTable , CREATE_METHOD_TABLE(JSIDBOpenDBRequest) };

JSIDBOpenDBRequest::JSIDBOpenDBRequest(Structure* structure, JSDOMGlobalObject* globalObject, PassRefPtr<IDBOpenDBRequest> impl)
    : JSIDBRequest(structure, globalObject, impl)
{
}

void JSIDBOpenDBRequest::finishCreation(VM& vm)
{
    Base::finishCreation(vm);
    ASSERT(inherits(info()));
}

JSObject* JSIDBOpenDBRequest::createPrototype(VM& vm, JSGlobalObject* globalObject)
{
    return JSIDBOpenDBRequestPrototype::create(vm, globalObject, JSIDBOpenDBRequestPrototype::createStructure(vm, globalObject, JSIDBRequestPrototype::self(vm, globalObject)));
}

bool JSIDBOpenDBRequest::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
{
    JSIDBOpenDBRequest* thisObject = jsCast<JSIDBOpenDBRequest*>(object);
    ASSERT_GC_OBJECT_INHERITS(thisObject, info());
    return getStaticValueSlot<JSIDBOpenDBRequest, Base>(exec, getJSIDBOpenDBRequestTable(exec->vm()), thisObject, propertyName, slot);
}

EncodedJSValue jsIDBOpenDBRequestOnblocked(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSIDBOpenDBRequest* castedThis = jsDynamicCast<JSIDBOpenDBRequest*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    UNUSED_PARAM(exec);
    IDBOpenDBRequest& impl = castedThis->impl();
    if (EventListener* listener = impl.onblocked()) {
        if (const JSEventListener* jsListener = JSEventListener::cast(listener)) {
            if (JSObject* jsFunction = jsListener->jsFunction(impl.scriptExecutionContext()))
                return JSValue::encode(jsFunction);
        }
    }
    return JSValue::encode(jsNull());
}


EncodedJSValue jsIDBOpenDBRequestOnupgradeneeded(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSIDBOpenDBRequest* castedThis = jsDynamicCast<JSIDBOpenDBRequest*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    UNUSED_PARAM(exec);
    IDBOpenDBRequest& impl = castedThis->impl();
    if (EventListener* listener = impl.onupgradeneeded()) {
        if (const JSEventListener* jsListener = JSEventListener::cast(listener)) {
            if (JSObject* jsFunction = jsListener->jsFunction(impl.scriptExecutionContext()))
                return JSValue::encode(jsFunction);
        }
    }
    return JSValue::encode(jsNull());
}


EncodedJSValue jsIDBOpenDBRequestConstructor(ExecState* exec, EncodedJSValue thisValue, EncodedJSValue, PropertyName)
{
    JSIDBOpenDBRequest* domObject = jsDynamicCast<JSIDBOpenDBRequest*>(JSValue::decode(thisValue));
    if (!domObject)
        return throwVMTypeError(exec);
    if (!domObject)
        return throwVMTypeError(exec);
    return JSValue::encode(JSIDBOpenDBRequest::getConstructor(exec->vm(), domObject->globalObject()));
}

void setJSIDBOpenDBRequestOnblocked(ExecState* exec, JSObject* /* baseObject */, EncodedJSValue thisValue, EncodedJSValue encodedValue)
{
    JSValue value = JSValue::decode(encodedValue);
    UNUSED_PARAM(exec);
    JSIDBOpenDBRequest* castedThis = jsDynamicCast<JSIDBOpenDBRequest*>(JSValue::decode(thisValue));
    if (!castedThis) {
        throwVMTypeError(exec);
        return;
    }
    UNUSED_PARAM(exec);
    IDBOpenDBRequest& impl = castedThis->impl();
    impl.setOnblocked(createJSAttributeEventListener(exec, value, castedThis));
}


void setJSIDBOpenDBRequestOnupgradeneeded(ExecState* exec, JSObject* /* baseObject */, EncodedJSValue thisValue, EncodedJSValue encodedValue)
{
    JSValue value = JSValue::decode(encodedValue);
    UNUSED_PARAM(exec);
    JSIDBOpenDBRequest* castedThis = jsDynamicCast<JSIDBOpenDBRequest*>(JSValue::decode(thisValue));
    if (!castedThis) {
        throwVMTypeError(exec);
        return;
    }
    UNUSED_PARAM(exec);
    IDBOpenDBRequest& impl = castedThis->impl();
    impl.setOnupgradeneeded(createJSAttributeEventListener(exec, value, castedThis));
}


JSValue JSIDBOpenDBRequest::getConstructor(VM& vm, JSGlobalObject* globalObject)
{
    return getDOMConstructor<JSIDBOpenDBRequestConstructor>(vm, jsCast<JSDOMGlobalObject*>(globalObject));
}

void JSIDBOpenDBRequest::visitChildren(JSCell* cell, SlotVisitor& visitor)
{
    JSIDBOpenDBRequest* thisObject = jsCast<JSIDBOpenDBRequest*>(cell);
    ASSERT_GC_OBJECT_INHERITS(thisObject, info());
    COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
    ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren());
    Base::visitChildren(thisObject, visitor);
    thisObject->impl().visitJSEventListeners(visitor);
}

bool JSIDBOpenDBRequestOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor)
{
    JSIDBOpenDBRequest* jsIDBOpenDBRequest = jsCast<JSIDBOpenDBRequest*>(handle.get().asCell());
    if (jsIDBOpenDBRequest->impl().hasPendingActivity())
        return true;
    if (jsIDBOpenDBRequest->impl().isFiringEventListeners())
        return true;
    UNUSED_PARAM(visitor);
    return false;
}

void JSIDBOpenDBRequestOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
{
    JSIDBOpenDBRequest* jsIDBOpenDBRequest = jsCast<JSIDBOpenDBRequest*>(handle.get().asCell());
    DOMWrapperWorld& world = *static_cast<DOMWrapperWorld*>(context);
    uncacheWrapper(world, &jsIDBOpenDBRequest->impl(), jsIDBOpenDBRequest);
    jsIDBOpenDBRequest->releaseImpl();
}

#if ENABLE(BINDING_INTEGRITY)
#if PLATFORM(WIN)
#pragma warning(disable: 4483)
extern "C" { extern void (*const __identifier("??_7IDBOpenDBRequest@WebCore@@6B@")[])(); }
#else
extern "C" { extern void* _ZTVN7WebCore16IDBOpenDBRequestE[]; }
#endif
#endif
JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, IDBOpenDBRequest* impl)
{
    if (!impl)
        return jsNull();
    if (JSValue result = getExistingWrapper<JSIDBOpenDBRequest>(exec, impl))
        return result;

#if ENABLE(BINDING_INTEGRITY)
    void* actualVTablePointer = *(reinterpret_cast<void**>(impl));
#if PLATFORM(WIN)
    void* expectedVTablePointer = reinterpret_cast<void*>(__identifier("??_7IDBOpenDBRequest@WebCore@@6B@"));
#else
    void* expectedVTablePointer = &_ZTVN7WebCore16IDBOpenDBRequestE[2];
#if COMPILER(CLANG)
    // If this fails IDBOpenDBRequest does not have a vtable, so you need to add the
    // ImplementationLacksVTable attribute to the interface definition
    COMPILE_ASSERT(__is_polymorphic(IDBOpenDBRequest), IDBOpenDBRequest_is_not_polymorphic);
#endif
#endif
    // If you hit this assertion you either have a use after free bug, or
    // IDBOpenDBRequest has subclasses. If IDBOpenDBRequest has subclasses that get passed
    // to toJS() we currently require IDBOpenDBRequest you to opt out of binding hardening
    // by adding the SkipVTableValidation attribute to the interface IDL definition
    RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
#endif
    ReportMemoryCost<IDBOpenDBRequest>::reportMemoryCost(exec, impl);
    return createNewWrapper<JSIDBOpenDBRequest>(exec, globalObject, impl);
}

IDBOpenDBRequest* toIDBOpenDBRequest(JSC::JSValue value)
{
    return value.inherits(JSIDBOpenDBRequest::info()) ? &jsCast<JSIDBOpenDBRequest*>(value)->impl() : 0;
}

}

#endif // ENABLE(INDEXED_DATABASE)
