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

#include "CanvasRenderingContext.h"
#include "HTMLCanvasElement.h"
#include "JSHTMLCanvasElement.h"
#include <wtf/GetPtr.h>

using namespace JSC;

namespace WebCore {

/* Hash table */

static const HashTableValue JSCanvasRenderingContextTableValues[] =
{
    { "canvas", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsCanvasRenderingContextCanvas), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { 0, 0, NoIntrinsic, 0, 0 }
};

static const HashTable JSCanvasRenderingContextTable = { 2, 1, true, JSCanvasRenderingContextTableValues, 0 };
/* Hash table for prototype */

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

static const HashTable JSCanvasRenderingContextPrototypeTable = { 1, 0, false, JSCanvasRenderingContextPrototypeTableValues, 0 };
const ClassInfo JSCanvasRenderingContextPrototype::s_info = { "CanvasRenderingContextPrototype", &Base::s_info, &JSCanvasRenderingContextPrototypeTable, 0, CREATE_METHOD_TABLE(JSCanvasRenderingContextPrototype) };

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

const ClassInfo JSCanvasRenderingContext::s_info = { "CanvasRenderingContext", &Base::s_info, &JSCanvasRenderingContextTable, 0 , CREATE_METHOD_TABLE(JSCanvasRenderingContext) };

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

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

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

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

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

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

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


static inline bool isObservable(JSCanvasRenderingContext* jsCanvasRenderingContext)
{
    if (jsCanvasRenderingContext->hasCustomProperties())
        return true;
    return false;
}

bool JSCanvasRenderingContextOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor)
{
    JSCanvasRenderingContext* jsCanvasRenderingContext = jsCast<JSCanvasRenderingContext*>(handle.get().asCell());
    if (!isObservable(jsCanvasRenderingContext))
        return false;
    void* root = WebCore::root(jsCanvasRenderingContext->impl().canvas());
    return visitor.containsOpaqueRoot(root);
}

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

CanvasRenderingContext* toCanvasRenderingContext(JSC::JSValue value)
{
    return value.inherits(JSCanvasRenderingContext::info()) ? &jsCast<JSCanvasRenderingContext*>(value)->impl() : 0;
}

}
