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

#include "JSTimeRanges.h"

#include "ExceptionCode.h"
#include "JSDOMBinding.h"
#include "TimeRanges.h"
#include <runtime/Error.h>
#include <wtf/GetPtr.h>

using namespace JSC;

namespace WebCore {

/* Hash table */

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

static const HashTable JSTimeRangesTable = { 5, 3, true, JSTimeRangesTableValues, 0 };
/* Hash table for constructor */

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

static const HashTable JSTimeRangesConstructorTable = { 1, 0, false, JSTimeRangesConstructorTableValues, 0 };
const ClassInfo JSTimeRangesConstructor::s_info = { "TimeRangesConstructor", &Base::s_info, &JSTimeRangesConstructorTable, 0, CREATE_METHOD_TABLE(JSTimeRangesConstructor) };

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

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

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

/* Hash table for prototype */

static const HashTableValue JSTimeRangesPrototypeTableValues[] =
{
    { "start", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsTimeRangesPrototypeFunctionStart), (intptr_t) (1) },
    { "end", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsTimeRangesPrototypeFunctionEnd), (intptr_t) (1) },
    { 0, 0, NoIntrinsic, 0, 0 }
};

static const HashTable JSTimeRangesPrototypeTable = { 5, 3, false, JSTimeRangesPrototypeTableValues, 0 };
const ClassInfo JSTimeRangesPrototype::s_info = { "TimeRangesPrototype", &Base::s_info, &JSTimeRangesPrototypeTable, 0, CREATE_METHOD_TABLE(JSTimeRangesPrototype) };

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

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

const ClassInfo JSTimeRanges::s_info = { "TimeRanges", &Base::s_info, &JSTimeRangesTable, 0 , CREATE_METHOD_TABLE(JSTimeRanges) };

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

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

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

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

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

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

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


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

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

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

    JSC::JSValue result = jsNumber(impl.start(index, ec));
    setDOMException(exec, ec);
    return JSValue::encode(result);
}

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

    JSC::JSValue result = jsNumber(impl.end(index, ec));
    setDOMException(exec, ec);
    return JSValue::encode(result);
}

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

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

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

TimeRanges* toTimeRanges(JSC::JSValue value)
{
    return value.inherits(JSTimeRanges::info()) ? &jsCast<JSTimeRanges*>(value)->impl() : 0;
}

}

#endif // ENABLE(VIDEO)
