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

#include "JSPerformanceEntryList.h"

#include "ExceptionCode.h"
#include "JSDOMBinding.h"
#include "JSPerformanceEntry.h"
#include "PerformanceEntry.h"
#include "PerformanceEntryList.h"
#include <runtime/Error.h>
#include <runtime/PropertyNameArray.h>
#include <wtf/GetPtr.h>

using namespace JSC;

namespace WebCore {

/* Hash table */

static const HashTableValue JSPerformanceEntryListTableValues[] =
{
    { "length", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsPerformanceEntryListLength), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { 0, 0, NoIntrinsic, 0, 0 }
};

static const HashTable JSPerformanceEntryListTable = { 2, 1, true, JSPerformanceEntryListTableValues, 0 };
/* Hash table for prototype */

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

static const HashTable JSPerformanceEntryListPrototypeTable = { 2, 1, false, JSPerformanceEntryListPrototypeTableValues, 0 };
const ClassInfo JSPerformanceEntryListPrototype::s_info = { "PerformanceEntryListPrototype", &Base::s_info, &JSPerformanceEntryListPrototypeTable, 0, CREATE_METHOD_TABLE(JSPerformanceEntryListPrototype) };

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

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

const ClassInfo JSPerformanceEntryList::s_info = { "PerformanceEntryList", &Base::s_info, &JSPerformanceEntryListTable, 0 , CREATE_METHOD_TABLE(JSPerformanceEntryList) };

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

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

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

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

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

bool JSPerformanceEntryList::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
{
    JSPerformanceEntryList* thisObject = jsCast<JSPerformanceEntryList*>(object);
    ASSERT_GC_OBJECT_INHERITS(thisObject, info());
    const HashEntry* entry = getStaticValueSlotEntryWithoutCaching<JSPerformanceEntryList>(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<JSPerformanceEntryList, Base>(exec, JSPerformanceEntryListTable, thisObject, propertyName, slot);
}

bool JSPerformanceEntryList::getOwnPropertySlotByIndex(JSObject* object, ExecState* exec, unsigned index, PropertySlot& slot)
{
    JSPerformanceEntryList* thisObject = jsCast<JSPerformanceEntryList*>(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 jsPerformanceEntryListLength(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSPerformanceEntryList* castedThis = jsDynamicCast<JSPerformanceEntryList*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    UNUSED_PARAM(exec);
    PerformanceEntryList& impl = castedThis->impl();
    JSValue result = jsNumber(impl.length());
    return JSValue::encode(result);
}


void JSPerformanceEntryList::getOwnPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)
{
    JSPerformanceEntryList* thisObject = jsCast<JSPerformanceEntryList*>(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);
}

EncodedJSValue JSC_HOST_CALL jsPerformanceEntryListPrototypeFunctionItem(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    JSPerformanceEntryList* castedThis = jsDynamicCast<JSPerformanceEntryList*>(thisValue);
    if (!castedThis)
        return throwVMTypeError(exec);
    ASSERT_GC_OBJECT_INHERITS(castedThis, JSPerformanceEntryList::info());
    PerformanceEntryList& 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 JSPerformanceEntryList::indexGetter(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue, unsigned index)
{
    JSPerformanceEntryList* thisObj = jsCast<JSPerformanceEntryList*>(JSValue::decode(slotBase));
    ASSERT_GC_OBJECT_INHERITS(thisObj, info());
    return JSValue::encode(toJS(exec, thisObj->globalObject(), thisObj->impl().item(index)));
}

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

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

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

PerformanceEntryList* toPerformanceEntryList(JSC::JSValue value)
{
    return value.inherits(JSPerformanceEntryList::info()) ? &jsCast<JSPerformanceEntryList*>(value)->impl() : 0;
}

}

#endif // ENABLE(PERFORMANCE_TIMELINE)
