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

#include "JSDataTransferItem.h"

#include "Blob.h"
#include "DataTransferItem.h"
#include "ExceptionCode.h"
#include "JSBlob.h"
#include "JSDOMBinding.h"
#include "JSStringCallback.h"
#include "URL.h"
#include <runtime/Error.h>
#include <runtime/JSString.h>
#include <wtf/GetPtr.h>

using namespace JSC;

namespace WebCore {

/* Hash table */

static const HashTableValue JSDataTransferItemTableValues[] =
{
    { "kind", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDataTransferItemKind), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "type", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsDataTransferItemType), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { 0, 0, NoIntrinsic, 0, 0 }
};

static const HashTable JSDataTransferItemTable = { 4, 3, true, JSDataTransferItemTableValues, 0 };
/* Hash table for prototype */

static const HashTableValue JSDataTransferItemPrototypeTableValues[] =
{
    { "getAsString", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsDataTransferItemPrototypeFunctionGetAsString), (intptr_t) (0) },
    { "getAsFile", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsDataTransferItemPrototypeFunctionGetAsFile), (intptr_t) (0) },
    { 0, 0, NoIntrinsic, 0, 0 }
};

static const HashTable JSDataTransferItemPrototypeTable = { 4, 3, false, JSDataTransferItemPrototypeTableValues, 0 };
const ClassInfo JSDataTransferItemPrototype::s_info = { "DataTransferItemPrototype", &Base::s_info, &JSDataTransferItemPrototypeTable, 0, CREATE_METHOD_TABLE(JSDataTransferItemPrototype) };

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

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

const ClassInfo JSDataTransferItem::s_info = { "DataTransferItem", &Base::s_info, &JSDataTransferItemTable, 0 , CREATE_METHOD_TABLE(JSDataTransferItem) };

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

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

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

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

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

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

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


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


EncodedJSValue JSC_HOST_CALL jsDataTransferItemPrototypeFunctionGetAsString(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    JSDataTransferItem* castedThis = jsDynamicCast<JSDataTransferItem*>(thisValue);
    if (!castedThis)
        return throwVMTypeError(exec);
    ASSERT_GC_OBJECT_INHERITS(castedThis, JSDataTransferItem::info());
    DataTransferItem& impl = castedThis->impl();
    RefPtr<StringCallback> callback;
    if (!exec->argument(0).isUndefinedOrNull()) {
        if (!exec->uncheckedArgument(0).isFunction())
            return throwVMTypeError(exec);
        callback = JSStringCallback::create(asObject(exec->uncheckedArgument(0)), castedThis->globalObject());
    }
    impl.getAsString(callback);
    return JSValue::encode(jsUndefined());
}

EncodedJSValue JSC_HOST_CALL jsDataTransferItemPrototypeFunctionGetAsFile(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    JSDataTransferItem* castedThis = jsDynamicCast<JSDataTransferItem*>(thisValue);
    if (!castedThis)
        return throwVMTypeError(exec);
    ASSERT_GC_OBJECT_INHERITS(castedThis, JSDataTransferItem::info());
    DataTransferItem& impl = castedThis->impl();

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

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

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

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

DataTransferItem* toDataTransferItem(JSC::JSValue value)
{
    return value.inherits(JSDataTransferItem::info()) ? &jsCast<JSDataTransferItem*>(value)->impl() : 0;
}

}

#endif // ENABLE(DATA_TRANSFER_ITEMS)
