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

#include "JSWebGLProgram.h"

#include "WebGLProgram.h"
#include <wtf/GetPtr.h>

using namespace JSC;

namespace WebCore {

/* Hash table */

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

static const HashTable JSWebGLProgramTable = { 2, 1, true, JSWebGLProgramTableValues, 0 };
/* Hash table for constructor */

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

static const HashTable JSWebGLProgramConstructorTable = { 1, 0, false, JSWebGLProgramConstructorTableValues, 0 };
const ClassInfo JSWebGLProgramConstructor::s_info = { "WebGLProgramConstructor", &Base::s_info, &JSWebGLProgramConstructorTable, 0, CREATE_METHOD_TABLE(JSWebGLProgramConstructor) };

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

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

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

/* Hash table for prototype */

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

static const HashTable JSWebGLProgramPrototypeTable = { 1, 0, false, JSWebGLProgramPrototypeTableValues, 0 };
const ClassInfo JSWebGLProgramPrototype::s_info = { "WebGLProgramPrototype", &Base::s_info, &JSWebGLProgramPrototypeTable, 0, CREATE_METHOD_TABLE(JSWebGLProgramPrototype) };

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

const ClassInfo JSWebGLProgram::s_info = { "WebGLProgram", &Base::s_info, &JSWebGLProgramTable, 0 , CREATE_METHOD_TABLE(JSWebGLProgram) };

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

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

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

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

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

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

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

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

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

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

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

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

WebGLProgram* toWebGLProgram(JSC::JSValue value)
{
    return value.inherits(JSWebGLProgram::info()) ? &jsCast<JSWebGLProgram*>(value)->impl() : 0;
}

}

#endif // ENABLE(WEBGL)
