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

#include "File.h"
#include "URL.h"
#include <runtime/JSString.h>
#include <wtf/GetPtr.h>

using namespace JSC;

namespace WebCore {

/* Hash table */

static const HashTableValue JSFileTableValues[] =
{
    { "name", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFileName), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "lastModifiedDate", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFileLastModifiedDate), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
#if ENABLE(DIRECTORY_UPLOAD)
    { "webkitRelativePath", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFileWebkitRelativePath), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
#endif
    { "constructor", DontEnum | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsFileConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { 0, 0, NoIntrinsic, 0, 0 }
};

static const HashTable JSFileTable = { 9, 7, true, JSFileTableValues, 0 };
/* Hash table for constructor */

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

static const HashTable JSFileConstructorTable = { 1, 0, false, JSFileConstructorTableValues, 0 };
static const HashTable& getJSFileConstructorTable(VM& vm)
{
    return getHashTableForGlobalData(vm, JSFileConstructorTable);
}

const ClassInfo JSFileConstructor::s_info = { "FileConstructor", &Base::s_info, 0, getJSFileConstructorTable, CREATE_METHOD_TABLE(JSFileConstructor) };

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

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

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

/* Hash table for prototype */

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

static const HashTable JSFilePrototypeTable = { 1, 0, false, JSFilePrototypeTableValues, 0 };
static const HashTable& getJSFilePrototypeTable(VM& vm)
{
    return getHashTableForGlobalData(vm, JSFilePrototypeTable);
}

const ClassInfo JSFilePrototype::s_info = { "FilePrototype", &Base::s_info, 0, getJSFilePrototypeTable, CREATE_METHOD_TABLE(JSFilePrototype) };

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

static const HashTable& getJSFileTable(VM& vm)
{
    return getHashTableForGlobalData(vm, JSFileTable);
}

const ClassInfo JSFile::s_info = { "File", &Base::s_info, 0, getJSFileTable , CREATE_METHOD_TABLE(JSFile) };

JSFile::JSFile(Structure* structure, JSDOMGlobalObject* globalObject, PassRefPtr<File> impl)
    : JSBlob(structure, globalObject, impl)
{
}

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

JSObject* JSFile::createPrototype(VM& vm, JSGlobalObject* globalObject)
{
    return JSFilePrototype::create(vm, globalObject, JSFilePrototype::createStructure(vm, globalObject, JSBlobPrototype::self(vm, globalObject)));
}

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

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


EncodedJSValue jsFileLastModifiedDate(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSFile* castedThis = jsDynamicCast<JSFile*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    UNUSED_PARAM(exec);
    File& impl = castedThis->impl();
    JSValue result = jsDateOrNull(exec, impl.lastModifiedDate());
    return JSValue::encode(result);
}


#if ENABLE(DIRECTORY_UPLOAD)
EncodedJSValue jsFileWebkitRelativePath(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSFile* castedThis = jsDynamicCast<JSFile*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    UNUSED_PARAM(exec);
    File& impl = castedThis->impl();
    JSValue result = jsStringWithCache(exec, impl.webkitRelativePath());
    return JSValue::encode(result);
}

#endif

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

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

#if ENABLE(BINDING_INTEGRITY)
#if PLATFORM(WIN)
#pragma warning(disable: 4483)
extern "C" { extern void (*const __identifier("??_7File@WebCore@@6B@")[])(); }
#else
extern "C" { extern void* _ZTVN7WebCore4FileE[]; }
#endif
#endif
JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, File* impl)
{
    if (!impl)
        return jsNull();
    if (JSValue result = getExistingWrapper<JSFile>(exec, impl))
        return result;

#if ENABLE(BINDING_INTEGRITY)
    void* actualVTablePointer = *(reinterpret_cast<void**>(impl));
#if PLATFORM(WIN)
    void* expectedVTablePointer = reinterpret_cast<void*>(__identifier("??_7File@WebCore@@6B@"));
#else
    void* expectedVTablePointer = &_ZTVN7WebCore4FileE[2];
#if COMPILER(CLANG)
    // If this fails File does not have a vtable, so you need to add the
    // ImplementationLacksVTable attribute to the interface definition
    COMPILE_ASSERT(__is_polymorphic(File), File_is_not_polymorphic);
#endif
#endif
    // If you hit this assertion you either have a use after free bug, or
    // File has subclasses. If File has subclasses that get passed
    // to toJS() we currently require File you to opt out of binding hardening
    // by adding the SkipVTableValidation attribute to the interface IDL definition
    RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
#endif
    ReportMemoryCost<File>::reportMemoryCost(exec, impl);
    return createNewWrapper<JSFile>(exec, globalObject, impl);
}

File* toFile(JSC::JSValue value)
{
    return value.inherits(JSFile::info()) ? &jsCast<JSFile*>(value)->impl() : 0;
}

}
