/*
    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(SQL_DATABASE)

#include "JSSQLException.h"

#include "SQLException.h"
#include "URL.h"
#include <runtime/JSString.h>
#include <wtf/GetPtr.h>

using namespace JSC;

namespace WebCore {

/* Hash table */

static const HashTableValue JSSQLExceptionTableValues[] =
{
    { "code", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSQLExceptionCode), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "message", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSQLExceptionMessage), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "constructor", DontEnum | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSQLExceptionConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { 0, 0, NoIntrinsic, 0, 0 }
};

static const HashTable JSSQLExceptionTable = { 9, 7, true, JSSQLExceptionTableValues, 0 };
/* Hash table for constructor */

static const HashTableValue JSSQLExceptionConstructorTableValues[] =
{
    { "UNKNOWN_ERR", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSQLExceptionUNKNOWN_ERR), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "DATABASE_ERR", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSQLExceptionDATABASE_ERR), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "VERSION_ERR", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSQLExceptionVERSION_ERR), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "TOO_LARGE_ERR", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSQLExceptionTOO_LARGE_ERR), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "QUOTA_ERR", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSQLExceptionQUOTA_ERR), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "SYNTAX_ERR", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSQLExceptionSYNTAX_ERR), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "CONSTRAINT_ERR", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSQLExceptionCONSTRAINT_ERR), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "TIMEOUT_ERR", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSQLExceptionTIMEOUT_ERR), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { 0, 0, NoIntrinsic, 0, 0 }
};

static const HashTable JSSQLExceptionConstructorTable = { 16, 15, true, JSSQLExceptionConstructorTableValues, 0 };
static const HashTable& getJSSQLExceptionConstructorTable(VM& vm)
{
    return getHashTableForGlobalData(vm, JSSQLExceptionConstructorTable);
}

const ClassInfo JSSQLExceptionConstructor::s_info = { "SQLExceptionConstructor", &Base::s_info, 0, getJSSQLExceptionConstructorTable, CREATE_METHOD_TABLE(JSSQLExceptionConstructor) };

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

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

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

/* Hash table for prototype */

static const HashTableValue JSSQLExceptionPrototypeTableValues[] =
{
    { "UNKNOWN_ERR", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSQLExceptionUNKNOWN_ERR), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "DATABASE_ERR", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSQLExceptionDATABASE_ERR), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "VERSION_ERR", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSQLExceptionVERSION_ERR), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "TOO_LARGE_ERR", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSQLExceptionTOO_LARGE_ERR), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "QUOTA_ERR", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSQLExceptionQUOTA_ERR), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "SYNTAX_ERR", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSQLExceptionSYNTAX_ERR), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "CONSTRAINT_ERR", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSQLExceptionCONSTRAINT_ERR), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "TIMEOUT_ERR", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSQLExceptionTIMEOUT_ERR), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { 0, 0, NoIntrinsic, 0, 0 }
};

static const HashTable JSSQLExceptionPrototypeTable = { 16, 15, true, JSSQLExceptionPrototypeTableValues, 0 };
static const HashTable& getJSSQLExceptionPrototypeTable(VM& vm)
{
    return getHashTableForGlobalData(vm, JSSQLExceptionPrototypeTable);
}

const ClassInfo JSSQLExceptionPrototype::s_info = { "SQLExceptionPrototype", &Base::s_info, 0, getJSSQLExceptionPrototypeTable, CREATE_METHOD_TABLE(JSSQLExceptionPrototype) };

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

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

static const HashTable& getJSSQLExceptionTable(VM& vm)
{
    return getHashTableForGlobalData(vm, JSSQLExceptionTable);
}

const ClassInfo JSSQLException::s_info = { "SQLException", &Base::s_info, 0, getJSSQLExceptionTable , CREATE_METHOD_TABLE(JSSQLException) };

JSSQLException::JSSQLException(Structure* structure, JSDOMGlobalObject* globalObject, PassRefPtr<SQLException> impl)
    : JSDOMWrapper(structure, globalObject)
    , m_impl(impl.leakRef())
{
}

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

JSObject* JSSQLException::createPrototype(VM& vm, JSGlobalObject* globalObject)
{
    return JSSQLExceptionPrototype::create(vm, globalObject, JSSQLExceptionPrototype::createStructure(vm, globalObject, globalObject->errorPrototype()));
}

void JSSQLException::destroy(JSC::JSCell* cell)
{
    JSSQLException* thisObject = static_cast<JSSQLException*>(cell);
    thisObject->JSSQLException::~JSSQLException();
}

JSSQLException::~JSSQLException()
{
    releaseImplIfNotNull();
}

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

EncodedJSValue jsSQLExceptionCode(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSSQLException* castedThis = jsDynamicCast<JSSQLException*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    UNUSED_PARAM(exec);
    SQLException& impl = castedThis->impl();
    JSValue result = jsNumber(impl.code());
    return JSValue::encode(result);
}


EncodedJSValue jsSQLExceptionMessage(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSSQLException* castedThis = jsDynamicCast<JSSQLException*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    UNUSED_PARAM(exec);
    SQLException& impl = castedThis->impl();
    JSValue result = jsStringWithCache(exec, impl.message());
    return JSValue::encode(result);
}


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

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

// Constant getters

EncodedJSValue jsSQLExceptionUNKNOWN_ERR(ExecState* exec, EncodedJSValue, EncodedJSValue, PropertyName)
{
    UNUSED_PARAM(exec);
    return JSValue::encode(jsNumber(static_cast<int>(0)));
}

EncodedJSValue jsSQLExceptionDATABASE_ERR(ExecState* exec, EncodedJSValue, EncodedJSValue, PropertyName)
{
    UNUSED_PARAM(exec);
    return JSValue::encode(jsNumber(static_cast<int>(1)));
}

EncodedJSValue jsSQLExceptionVERSION_ERR(ExecState* exec, EncodedJSValue, EncodedJSValue, PropertyName)
{
    UNUSED_PARAM(exec);
    return JSValue::encode(jsNumber(static_cast<int>(2)));
}

EncodedJSValue jsSQLExceptionTOO_LARGE_ERR(ExecState* exec, EncodedJSValue, EncodedJSValue, PropertyName)
{
    UNUSED_PARAM(exec);
    return JSValue::encode(jsNumber(static_cast<int>(3)));
}

EncodedJSValue jsSQLExceptionQUOTA_ERR(ExecState* exec, EncodedJSValue, EncodedJSValue, PropertyName)
{
    UNUSED_PARAM(exec);
    return JSValue::encode(jsNumber(static_cast<int>(4)));
}

EncodedJSValue jsSQLExceptionSYNTAX_ERR(ExecState* exec, EncodedJSValue, EncodedJSValue, PropertyName)
{
    UNUSED_PARAM(exec);
    return JSValue::encode(jsNumber(static_cast<int>(5)));
}

EncodedJSValue jsSQLExceptionCONSTRAINT_ERR(ExecState* exec, EncodedJSValue, EncodedJSValue, PropertyName)
{
    UNUSED_PARAM(exec);
    return JSValue::encode(jsNumber(static_cast<int>(6)));
}

EncodedJSValue jsSQLExceptionTIMEOUT_ERR(ExecState* exec, EncodedJSValue, EncodedJSValue, PropertyName)
{
    UNUSED_PARAM(exec);
    return JSValue::encode(jsNumber(static_cast<int>(7)));
}

bool JSSQLExceptionOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor)
{
    UNUSED_PARAM(handle);
    UNUSED_PARAM(visitor);
    return false;
}

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

JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, SQLException* impl)
{
    if (!impl)
        return jsNull();
    if (JSValue result = getExistingWrapper<JSSQLException>(exec, impl))
        return result;
#if COMPILER(CLANG)
    // If you hit this failure the interface definition has the ImplementationLacksVTable
    // attribute. You should remove that attribute. If the class has subclasses
    // that may be passed through this toJS() function you should use the SkipVTableValidation
    // attribute to SQLException.
    COMPILE_ASSERT(!__is_polymorphic(SQLException), SQLException_is_polymorphic_but_idl_claims_not_to_be);
#endif
    ReportMemoryCost<SQLException>::reportMemoryCost(exec, impl);
    return createNewWrapper<JSSQLException>(exec, globalObject, impl);
}

SQLException* toSQLException(JSC::JSValue value)
{
    return value.inherits(JSSQLException::info()) ? &jsCast<JSSQLException*>(value)->impl() : 0;
}

}

#endif // ENABLE(SQL_DATABASE)
