/*
    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 "JSFileList.h"

#include "ExceptionCode.h"
#include "File.h"
#include "FileList.h"
#include "JSDOMBinding.h"
#include "JSFile.h"
#include <runtime/Error.h>
#include <runtime/PropertyNameArray.h>
#include <wtf/GetPtr.h>

using namespace JSC;

namespace WebCore {

/* Hash table */

static const HashTableValue JSFileListTableValues[] =
{
    { "length", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFileListLength), (intptr_t)0 },
    { "constructor", DontEnum | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFileListConstructor), (intptr_t)0 },
    { 0, 0, NoIntrinsic, 0, 0 }
};

static const HashTable JSFileListTable = { 5, 3, JSFileListTableValues, 0 };
/* Hash table for constructor */

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

static const HashTable JSFileListConstructorTable = { 1, 0, JSFileListConstructorTableValues, 0 };
static const HashTable& getJSFileListConstructorTable(ExecState* exec)
{
    return getHashTableForGlobalData(exec->vm(), JSFileListConstructorTable);
}

const ClassInfo JSFileListConstructor::s_info = { "FileListConstructor", &Base::s_info, 0, getJSFileListConstructorTable, CREATE_METHOD_TABLE(JSFileListConstructor) };

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

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

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

/* Hash table for prototype */

static const HashTableValue JSFileListPrototypeTableValues[] =
{
    { "item", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsFileListPrototypeFunctionItem), (intptr_t)1 },
    { 0, 0, NoIntrinsic, 0, 0 }
};

static const HashTable JSFileListPrototypeTable = { 2, 1, JSFileListPrototypeTableValues, 0 };
static const HashTable& getJSFileListPrototypeTable(ExecState* exec)
{
    return getHashTableForGlobalData(exec->vm(), JSFileListPrototypeTable);
}

const ClassInfo JSFileListPrototype::s_info = { "FileListPrototype", &Base::s_info, 0, getJSFileListPrototypeTable, CREATE_METHOD_TABLE(JSFileListPrototype) };

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

bool JSFileListPrototype::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
{
    JSFileListPrototype* thisObject = jsCast<JSFileListPrototype*>(object);
    return getStaticFunctionSlot<JSObject>(exec, getJSFileListPrototypeTable(exec), thisObject, propertyName, slot);
}

static const HashTable& getJSFileListTable(ExecState* exec)
{
    return getHashTableForGlobalData(exec->vm(), JSFileListTable);
}

const ClassInfo JSFileList::s_info = { "FileList", &Base::s_info, 0, getJSFileListTable , CREATE_METHOD_TABLE(JSFileList) };

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

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

JSObject* JSFileList::createPrototype(VM& vm, JSGlobalObject* globalObject)
{
    return JSFileListPrototype::create(vm, globalObject, JSFileListPrototype::createStructure(vm, globalObject, globalObject->objectPrototype()));
}

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

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

bool JSFileList::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
{
    JSFileList* thisObject = jsCast<JSFileList*>(object);
    ASSERT_GC_OBJECT_INHERITS(thisObject, info());
    const HashEntry* entry = getStaticValueSlotEntryWithoutCaching<JSFileList>(exec, propertyName);
    if (entry) {
        slot.setCustom(thisObject, entry->attributes(), entry->propertyGetter());
        return true;
    }
    unsigned index = propertyName.asIndex();
    if (index != PropertyName::NotAnIndex && index < thisObject->impl().length()) {
        unsigned attributes = DontDelete | ReadOnly;
        slot.setCustomIndex(thisObject, attributes, index, indexGetter);
        return true;
    }
    return getStaticValueSlot<JSFileList, Base>(exec, getJSFileListTable(exec), thisObject, propertyName, slot);
}

bool JSFileList::getOwnPropertySlotByIndex(JSObject* object, ExecState* exec, unsigned index, PropertySlot& slot)
{
    JSFileList* thisObject = jsCast<JSFileList*>(object);
    ASSERT_GC_OBJECT_INHERITS(thisObject, info());
    if (index < thisObject->impl().length()) {
        unsigned attributes = DontDelete | ReadOnly;
        slot.setCustomIndex(thisObject, attributes, index, thisObject->indexGetter);
        return true;
    }
    return Base::getOwnPropertySlotByIndex(thisObject, exec, index, slot);
}

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


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

void JSFileList::getOwnPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)
{
    JSFileList* thisObject = jsCast<JSFileList*>(object);
    ASSERT_GC_OBJECT_INHERITS(thisObject, info());
    for (unsigned i = 0, count = thisObject->impl().length(); i < count; ++i)
        propertyNames.add(Identifier::from(exec, i));
     Base::getOwnPropertyNames(thisObject, exec, propertyNames, mode);
}

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

EncodedJSValue JSC_HOST_CALL jsFileListPrototypeFunctionItem(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    JSFileList* castedThis = jsDynamicCast<JSFileList*>(thisValue);
    if (!castedThis)
        return throwVMTypeError(exec);
    ASSERT_GC_OBJECT_INHERITS(castedThis, JSFileList::info());
    FileList& impl = castedThis->impl();
    if (exec->argumentCount() < 1)
        return throwVMError(exec, createNotEnoughArgumentsError(exec));
    unsigned index(toUInt32(exec, exec->argument(0), NormalConversion));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());

    JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(impl.item(index)));
    return JSValue::encode(result);
}


EncodedJSValue JSFileList::indexGetter(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue, unsigned index)
{
    JSFileList* thisObj = jsCast<JSFileList*>(JSValue::decode(slotBase));
    ASSERT_GC_OBJECT_INHERITS(thisObj, info());
    return JSValue::encode(toJS(exec, thisObj->globalObject(), thisObj->impl().item(index)));
}

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

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

JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, FileList* impl)
{
    if (!impl)
        return jsNull();
    if (JSValue result = getExistingWrapper<JSFileList>(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 FileList.
    COMPILE_ASSERT(!__is_polymorphic(FileList), FileList_is_polymorphic_but_idl_claims_not_to_be);
#endif
    ReportMemoryCost<FileList>::reportMemoryCost(exec, impl);
    return createNewWrapper<JSFileList>(exec, globalObject, impl);
}

FileList* toFileList(JSC::JSValue value)
{
    return value.inherits(JSFileList::info()) ? &jsCast<JSFileList*>(value)->impl() : 0;
}

}
