/*
    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"
#include "JSHTMLFormElement.h"

#include "ExceptionCode.h"
#include "HTMLCollection.h"
#include "HTMLFormElement.h"
#include "HTMLNames.h"
#include "JSDOMBinding.h"
#include "JSHTMLCollection.h"
#include "KURL.h"
#include "wtf/text/AtomicString.h"
#include <runtime/Error.h>
#include <runtime/JSString.h>
#include <runtime/PropertyNameArray.h>
#include <wtf/GetPtr.h>

using namespace JSC;

namespace WebCore {

ASSERT_CLASS_FITS_IN_CELL(JSHTMLFormElement);

/* Hash table */
#if ENABLE(JIT)
#define THUNK_GENERATOR(generator) , generator
#else
#define THUNK_GENERATOR(generator)
#endif

static const HashTableValue JSHTMLFormElementTableValues[12] =
{
    { "elements", DontDelete | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsHTMLFormElementElements), (intptr_t)0 THUNK_GENERATOR(0) },
    { "length", DontDelete | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsHTMLFormElementLength), (intptr_t)0 THUNK_GENERATOR(0) },
    { "name", DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsHTMLFormElementName), (intptr_t)setJSHTMLFormElementName THUNK_GENERATOR(0) },
    { "noValidate", DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsHTMLFormElementNoValidate), (intptr_t)setJSHTMLFormElementNoValidate THUNK_GENERATOR(0) },
    { "acceptCharset", DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsHTMLFormElementAcceptCharset), (intptr_t)setJSHTMLFormElementAcceptCharset THUNK_GENERATOR(0) },
    { "action", DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsHTMLFormElementAction), (intptr_t)setJSHTMLFormElementAction THUNK_GENERATOR(0) },
    { "encoding", DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsHTMLFormElementEncoding), (intptr_t)setJSHTMLFormElementEncoding THUNK_GENERATOR(0) },
    { "enctype", DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsHTMLFormElementEnctype), (intptr_t)setJSHTMLFormElementEnctype THUNK_GENERATOR(0) },
    { "method", DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsHTMLFormElementMethod), (intptr_t)setJSHTMLFormElementMethod THUNK_GENERATOR(0) },
    { "target", DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsHTMLFormElementTarget), (intptr_t)setJSHTMLFormElementTarget THUNK_GENERATOR(0) },
    { "constructor", DontEnum | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsHTMLFormElementConstructor), (intptr_t)0 THUNK_GENERATOR(0) },
    { 0, 0, 0, 0 THUNK_GENERATOR(0) }
};

#undef THUNK_GENERATOR
static JSC_CONST_HASHTABLE HashTable JSHTMLFormElementTable = { 35, 31, JSHTMLFormElementTableValues, 0 };
/* Hash table for constructor */
#if ENABLE(JIT)
#define THUNK_GENERATOR(generator) , generator
#else
#define THUNK_GENERATOR(generator)
#endif

static const HashTableValue JSHTMLFormElementConstructorTableValues[1] =
{
    { 0, 0, 0, 0 THUNK_GENERATOR(0) }
};

#undef THUNK_GENERATOR
static JSC_CONST_HASHTABLE HashTable JSHTMLFormElementConstructorTable = { 1, 0, JSHTMLFormElementConstructorTableValues, 0 };
class JSHTMLFormElementConstructor : public DOMConstructorObject {
public:
    JSHTMLFormElementConstructor(JSC::ExecState*, JSC::Structure*, JSDOMGlobalObject*);

    virtual bool getOwnPropertySlot(JSC::ExecState*, const JSC::Identifier&, JSC::PropertySlot&);
    virtual bool getOwnPropertyDescriptor(JSC::ExecState*, const JSC::Identifier&, JSC::PropertyDescriptor&);
    static const JSC::ClassInfo s_info;
    static JSC::Structure* createStructure(JSC::JSGlobalData& globalData, JSC::JSValue prototype)
    {
        return JSC::Structure::create(globalData, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), AnonymousSlotCount, &s_info);
    }
protected:
    static const unsigned StructureFlags = JSC::OverridesGetOwnPropertySlot | JSC::ImplementsHasInstance | DOMConstructorObject::StructureFlags;
};

const ClassInfo JSHTMLFormElementConstructor::s_info = { "HTMLFormElementConstructor", &DOMConstructorObject::s_info, &JSHTMLFormElementConstructorTable, 0 };

JSHTMLFormElementConstructor::JSHTMLFormElementConstructor(ExecState* exec, Structure* structure, JSDOMGlobalObject* globalObject)
    : DOMConstructorObject(structure, globalObject)
{
    ASSERT(inherits(&s_info));
    putDirect(exec->globalData(), exec->propertyNames().prototype, JSHTMLFormElementPrototype::self(exec, globalObject), DontDelete | ReadOnly);
}

bool JSHTMLFormElementConstructor::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
{
    return getStaticValueSlot<JSHTMLFormElementConstructor, JSDOMWrapper>(exec, &JSHTMLFormElementConstructorTable, this, propertyName, slot);
}

bool JSHTMLFormElementConstructor::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
{
    return getStaticValueDescriptor<JSHTMLFormElementConstructor, JSDOMWrapper>(exec, &JSHTMLFormElementConstructorTable, this, propertyName, descriptor);
}

/* Hash table for prototype */
#if ENABLE(JIT)
#define THUNK_GENERATOR(generator) , generator
#else
#define THUNK_GENERATOR(generator)
#endif

static const HashTableValue JSHTMLFormElementPrototypeTableValues[4] =
{
    { "submit", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsHTMLFormElementPrototypeFunctionSubmit), (intptr_t)0 THUNK_GENERATOR(0) },
    { "reset", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsHTMLFormElementPrototypeFunctionReset), (intptr_t)0 THUNK_GENERATOR(0) },
    { "checkValidity", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsHTMLFormElementPrototypeFunctionCheckValidity), (intptr_t)0 THUNK_GENERATOR(0) },
    { 0, 0, 0, 0 THUNK_GENERATOR(0) }
};

#undef THUNK_GENERATOR
static JSC_CONST_HASHTABLE HashTable JSHTMLFormElementPrototypeTable = { 9, 7, JSHTMLFormElementPrototypeTableValues, 0 };
const ClassInfo JSHTMLFormElementPrototype::s_info = { "HTMLFormElementPrototype", &JSC::JSObjectWithGlobalObject::s_info, &JSHTMLFormElementPrototypeTable, 0 };

JSObject* JSHTMLFormElementPrototype::self(ExecState* exec, JSGlobalObject* globalObject)
{
    return getDOMPrototype<JSHTMLFormElement>(exec, globalObject);
}

bool JSHTMLFormElementPrototype::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
{
    return getStaticFunctionSlot<JSObject>(exec, &JSHTMLFormElementPrototypeTable, this, propertyName, slot);
}

bool JSHTMLFormElementPrototype::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
{
    return getStaticFunctionDescriptor<JSObject>(exec, &JSHTMLFormElementPrototypeTable, this, propertyName, descriptor);
}

const ClassInfo JSHTMLFormElement::s_info = { "HTMLFormElement", &JSHTMLElement::s_info, &JSHTMLFormElementTable, 0 };

JSHTMLFormElement::JSHTMLFormElement(Structure* structure, JSDOMGlobalObject* globalObject, PassRefPtr<HTMLFormElement> impl)
    : JSHTMLElement(structure, globalObject, impl)
{
    ASSERT(inherits(&s_info));
}

JSObject* JSHTMLFormElement::createPrototype(ExecState* exec, JSGlobalObject* globalObject)
{
    return new (exec) JSHTMLFormElementPrototype(exec->globalData(), globalObject, JSHTMLFormElementPrototype::createStructure(exec->globalData(), JSHTMLElementPrototype::self(exec, globalObject)));
}

bool JSHTMLFormElement::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
{
    bool ok;
    unsigned index = propertyName.toUInt32(ok);
    if (ok && index < static_cast<HTMLFormElement*>(impl())->length()) {
        slot.setCustomIndex(this, index, indexGetter);
        return true;
    }
    if (canGetItemsForName(exec, static_cast<HTMLFormElement*>(impl()), propertyName)) {
        slot.setCustom(this, nameGetter);
        return true;
    }
    const HashEntry* entry = JSHTMLFormElementTable.entry(exec, propertyName);
    if (entry) {
        slot.setCustom(this, entry->propertyGetter());
        return true;
    }
    return getStaticValueSlot<JSHTMLFormElement, Base>(exec, &JSHTMLFormElementTable, this, propertyName, slot);
}

bool JSHTMLFormElement::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
{
    bool ok;
    unsigned index = propertyName.toUInt32(ok);
    if (ok && index < static_cast<HTMLFormElement*>(impl())->length()) {
        PropertySlot slot;
        slot.setCustomIndex(this, index, indexGetter);
        descriptor.setDescriptor(slot.getValue(exec, propertyName), DontDelete | ReadOnly);
        return true;
    }
    if (canGetItemsForName(exec, static_cast<HTMLFormElement*>(impl()), propertyName)) {
        PropertySlot slot;
        slot.setCustom(this, nameGetter);
        descriptor.setDescriptor(slot.getValue(exec, propertyName), ReadOnly | DontDelete | DontEnum);
        return true;
    }
    const HashEntry* entry = JSHTMLFormElementTable.entry(exec, propertyName);
    if (entry) {
        PropertySlot slot;
        slot.setCustom(this, entry->propertyGetter());
        descriptor.setDescriptor(slot.getValue(exec, propertyName), entry->attributes());
        return true;
    }
    return getStaticValueDescriptor<JSHTMLFormElement, Base>(exec, &JSHTMLFormElementTable, this, propertyName, descriptor);
}

JSValue jsHTMLFormElementElements(ExecState* exec, JSValue slotBase, const Identifier&)
{
    JSHTMLFormElement* castedThis = static_cast<JSHTMLFormElement*>(asObject(slotBase));
    UNUSED_PARAM(exec);
    HTMLFormElement* imp = static_cast<HTMLFormElement*>(castedThis->impl());
    JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(imp->elements()));
    return result;
}


JSValue jsHTMLFormElementLength(ExecState* exec, JSValue slotBase, const Identifier&)
{
    JSHTMLFormElement* castedThis = static_cast<JSHTMLFormElement*>(asObject(slotBase));
    UNUSED_PARAM(exec);
    HTMLFormElement* imp = static_cast<HTMLFormElement*>(castedThis->impl());
    JSValue result = jsNumber(imp->length());
    return result;
}


JSValue jsHTMLFormElementName(ExecState* exec, JSValue slotBase, const Identifier&)
{
    JSHTMLFormElement* castedThis = static_cast<JSHTMLFormElement*>(asObject(slotBase));
    UNUSED_PARAM(exec);
    HTMLFormElement* imp = static_cast<HTMLFormElement*>(castedThis->impl());
    JSValue result = jsString(exec, imp->getAttribute(WebCore::HTMLNames::nameAttr));
    return result;
}


JSValue jsHTMLFormElementNoValidate(ExecState* exec, JSValue slotBase, const Identifier&)
{
    JSHTMLFormElement* castedThis = static_cast<JSHTMLFormElement*>(asObject(slotBase));
    UNUSED_PARAM(exec);
    HTMLFormElement* imp = static_cast<HTMLFormElement*>(castedThis->impl());
    JSValue result = jsBoolean(imp->hasAttribute(WebCore::HTMLNames::novalidateAttr));
    return result;
}


JSValue jsHTMLFormElementAcceptCharset(ExecState* exec, JSValue slotBase, const Identifier&)
{
    JSHTMLFormElement* castedThis = static_cast<JSHTMLFormElement*>(asObject(slotBase));
    UNUSED_PARAM(exec);
    HTMLFormElement* imp = static_cast<HTMLFormElement*>(castedThis->impl());
    JSValue result = jsString(exec, imp->getAttribute(WebCore::HTMLNames::accept_charsetAttr));
    return result;
}


JSValue jsHTMLFormElementAction(ExecState* exec, JSValue slotBase, const Identifier&)
{
    JSHTMLFormElement* castedThis = static_cast<JSHTMLFormElement*>(asObject(slotBase));
    UNUSED_PARAM(exec);
    HTMLFormElement* imp = static_cast<HTMLFormElement*>(castedThis->impl());
    JSValue result = jsString(exec, imp->getURLAttribute(WebCore::HTMLNames::actionAttr));
    return result;
}


JSValue jsHTMLFormElementEncoding(ExecState* exec, JSValue slotBase, const Identifier&)
{
    JSHTMLFormElement* castedThis = static_cast<JSHTMLFormElement*>(asObject(slotBase));
    UNUSED_PARAM(exec);
    HTMLFormElement* imp = static_cast<HTMLFormElement*>(castedThis->impl());
    JSValue result = jsString(exec, imp->encoding());
    return result;
}


JSValue jsHTMLFormElementEnctype(ExecState* exec, JSValue slotBase, const Identifier&)
{
    JSHTMLFormElement* castedThis = static_cast<JSHTMLFormElement*>(asObject(slotBase));
    UNUSED_PARAM(exec);
    HTMLFormElement* imp = static_cast<HTMLFormElement*>(castedThis->impl());
    JSValue result = jsString(exec, imp->enctype());
    return result;
}


JSValue jsHTMLFormElementMethod(ExecState* exec, JSValue slotBase, const Identifier&)
{
    JSHTMLFormElement* castedThis = static_cast<JSHTMLFormElement*>(asObject(slotBase));
    UNUSED_PARAM(exec);
    HTMLFormElement* imp = static_cast<HTMLFormElement*>(castedThis->impl());
    JSValue result = jsString(exec, imp->getAttribute(WebCore::HTMLNames::methodAttr));
    return result;
}


JSValue jsHTMLFormElementTarget(ExecState* exec, JSValue slotBase, const Identifier&)
{
    JSHTMLFormElement* castedThis = static_cast<JSHTMLFormElement*>(asObject(slotBase));
    UNUSED_PARAM(exec);
    HTMLFormElement* imp = static_cast<HTMLFormElement*>(castedThis->impl());
    JSValue result = jsString(exec, imp->getAttribute(WebCore::HTMLNames::targetAttr));
    return result;
}


JSValue jsHTMLFormElementConstructor(ExecState* exec, JSValue slotBase, const Identifier&)
{
    JSHTMLFormElement* domObject = static_cast<JSHTMLFormElement*>(asObject(slotBase));
    return JSHTMLFormElement::getConstructor(exec, domObject->globalObject());
}

void JSHTMLFormElement::put(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot)
{
    lookupPut<JSHTMLFormElement, Base>(exec, propertyName, value, &JSHTMLFormElementTable, this, slot);
}

void setJSHTMLFormElementName(ExecState* exec, JSObject* thisObject, JSValue value)
{
    JSHTMLFormElement* castedThis = static_cast<JSHTMLFormElement*>(thisObject);
    HTMLFormElement* imp = static_cast<HTMLFormElement*>(castedThis->impl());
    imp->setAttribute(WebCore::HTMLNames::nameAttr, valueToStringWithNullCheck(exec, value));
}


void setJSHTMLFormElementNoValidate(ExecState* exec, JSObject* thisObject, JSValue value)
{
    JSHTMLFormElement* castedThis = static_cast<JSHTMLFormElement*>(thisObject);
    HTMLFormElement* imp = static_cast<HTMLFormElement*>(castedThis->impl());
    imp->setBooleanAttribute(WebCore::HTMLNames::novalidateAttr, value.toBoolean(exec));
}


void setJSHTMLFormElementAcceptCharset(ExecState* exec, JSObject* thisObject, JSValue value)
{
    JSHTMLFormElement* castedThis = static_cast<JSHTMLFormElement*>(thisObject);
    HTMLFormElement* imp = static_cast<HTMLFormElement*>(castedThis->impl());
    imp->setAttribute(WebCore::HTMLNames::accept_charsetAttr, valueToStringWithNullCheck(exec, value));
}


void setJSHTMLFormElementAction(ExecState* exec, JSObject* thisObject, JSValue value)
{
    JSHTMLFormElement* castedThis = static_cast<JSHTMLFormElement*>(thisObject);
    HTMLFormElement* imp = static_cast<HTMLFormElement*>(castedThis->impl());
    imp->setAttribute(WebCore::HTMLNames::actionAttr, valueToStringWithNullCheck(exec, value));
}


void setJSHTMLFormElementEncoding(ExecState* exec, JSObject* thisObject, JSValue value)
{
    JSHTMLFormElement* castedThis = static_cast<JSHTMLFormElement*>(thisObject);
    HTMLFormElement* imp = static_cast<HTMLFormElement*>(castedThis->impl());
    imp->setEncoding(valueToStringWithNullCheck(exec, value));
}


void setJSHTMLFormElementEnctype(ExecState* exec, JSObject* thisObject, JSValue value)
{
    JSHTMLFormElement* castedThis = static_cast<JSHTMLFormElement*>(thisObject);
    HTMLFormElement* imp = static_cast<HTMLFormElement*>(castedThis->impl());
    imp->setEnctype(valueToStringWithNullCheck(exec, value));
}


void setJSHTMLFormElementMethod(ExecState* exec, JSObject* thisObject, JSValue value)
{
    JSHTMLFormElement* castedThis = static_cast<JSHTMLFormElement*>(thisObject);
    HTMLFormElement* imp = static_cast<HTMLFormElement*>(castedThis->impl());
    imp->setAttribute(WebCore::HTMLNames::methodAttr, valueToStringWithNullCheck(exec, value));
}


void setJSHTMLFormElementTarget(ExecState* exec, JSObject* thisObject, JSValue value)
{
    JSHTMLFormElement* castedThis = static_cast<JSHTMLFormElement*>(thisObject);
    HTMLFormElement* imp = static_cast<HTMLFormElement*>(castedThis->impl());
    imp->setAttribute(WebCore::HTMLNames::targetAttr, valueToStringWithNullCheck(exec, value));
}


void JSHTMLFormElement::getOwnPropertyNames(ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)
{
    for (unsigned i = 0; i < static_cast<HTMLFormElement*>(impl())->length(); ++i)
        propertyNames.add(Identifier::from(exec, i));
     Base::getOwnPropertyNames(exec, propertyNames, mode);
}

JSValue JSHTMLFormElement::getConstructor(ExecState* exec, JSGlobalObject* globalObject)
{
    return getDOMConstructor<JSHTMLFormElementConstructor>(exec, static_cast<JSDOMGlobalObject*>(globalObject));
}

EncodedJSValue JSC_HOST_CALL jsHTMLFormElementPrototypeFunctionSubmit(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    if (!thisValue.inherits(&JSHTMLFormElement::s_info))
        return throwVMTypeError(exec);
    JSHTMLFormElement* castedThis = static_cast<JSHTMLFormElement*>(asObject(thisValue));
    HTMLFormElement* imp = static_cast<HTMLFormElement*>(castedThis->impl());

    imp->submitFromJavaScript();
    return JSValue::encode(jsUndefined());
}

EncodedJSValue JSC_HOST_CALL jsHTMLFormElementPrototypeFunctionReset(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    if (!thisValue.inherits(&JSHTMLFormElement::s_info))
        return throwVMTypeError(exec);
    JSHTMLFormElement* castedThis = static_cast<JSHTMLFormElement*>(asObject(thisValue));
    HTMLFormElement* imp = static_cast<HTMLFormElement*>(castedThis->impl());

    imp->reset();
    return JSValue::encode(jsUndefined());
}

EncodedJSValue JSC_HOST_CALL jsHTMLFormElementPrototypeFunctionCheckValidity(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    if (!thisValue.inherits(&JSHTMLFormElement::s_info))
        return throwVMTypeError(exec);
    JSHTMLFormElement* castedThis = static_cast<JSHTMLFormElement*>(asObject(thisValue));
    HTMLFormElement* imp = static_cast<HTMLFormElement*>(castedThis->impl());


    JSC::JSValue result = jsBoolean(imp->checkValidity());
    return JSValue::encode(result);
}


JSValue JSHTMLFormElement::indexGetter(ExecState* exec, JSValue slotBase, unsigned index)
{
    JSHTMLFormElement* thisObj = static_cast<JSHTMLFormElement*>(asObject(slotBase));
    return toJS(exec, thisObj->globalObject(), static_cast<HTMLFormElement*>(thisObj->impl())->item(index));
}


}
