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

#include "CSSPrimitiveValue.h"
#include "JSCSSPrimitiveValue.h"
#include "RGBColor.h"
#include <wtf/GetPtr.h>

using namespace JSC;

namespace WebCore {

/* Hash table */

static const HashTableValue JSRGBColorTableValues[] =
{
    { "red", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsRGBColorRed), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "green", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsRGBColorGreen), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "blue", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsRGBColorBlue), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "constructor", DontEnum | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsRGBColorConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { 0, 0, NoIntrinsic, 0, 0 }
};

static const HashTable JSRGBColorTable = { 8, 7, true, JSRGBColorTableValues, 0 };
/* Hash table for constructor */

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

static const HashTable JSRGBColorConstructorTable = { 1, 0, false, JSRGBColorConstructorTableValues, 0 };
const ClassInfo JSRGBColorConstructor::s_info = { "RGBColorConstructor", &Base::s_info, &JSRGBColorConstructorTable, 0, CREATE_METHOD_TABLE(JSRGBColorConstructor) };

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

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

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

/* Hash table for prototype */

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

static const HashTable JSRGBColorPrototypeTable = { 1, 0, false, JSRGBColorPrototypeTableValues, 0 };
const ClassInfo JSRGBColorPrototype::s_info = { "RGBColorPrototype", &Base::s_info, &JSRGBColorPrototypeTable, 0, CREATE_METHOD_TABLE(JSRGBColorPrototype) };

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

const ClassInfo JSRGBColor::s_info = { "RGBColor", &Base::s_info, &JSRGBColorTable, 0 , CREATE_METHOD_TABLE(JSRGBColor) };

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

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

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

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

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

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

EncodedJSValue jsRGBColorRed(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSRGBColor* castedThis = jsDynamicCast<JSRGBColor*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    UNUSED_PARAM(exec);
    RGBColor& impl = castedThis->impl();
    JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(impl.red()));
    return JSValue::encode(result);
}


EncodedJSValue jsRGBColorGreen(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSRGBColor* castedThis = jsDynamicCast<JSRGBColor*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    UNUSED_PARAM(exec);
    RGBColor& impl = castedThis->impl();
    JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(impl.green()));
    return JSValue::encode(result);
}


EncodedJSValue jsRGBColorBlue(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSRGBColor* castedThis = jsDynamicCast<JSRGBColor*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    UNUSED_PARAM(exec);
    RGBColor& impl = castedThis->impl();
    JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(impl.blue()));
    return JSValue::encode(result);
}


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

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

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

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

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

RGBColor* toRGBColor(JSC::JSValue value)
{
    return value.inherits(JSRGBColor::info()) ? &jsCast<JSRGBColor*>(value)->impl() : 0;
}

}
