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

#include "JSMessageChannel.h"

#include "ExceptionCode.h"
#include "JSDOMBinding.h"
#include "JSMessagePort.h"
#include "MessageChannel.h"
#include "MessagePort.h"
#include <runtime/Error.h>
#include <wtf/GetPtr.h>

using namespace JSC;

namespace WebCore {

/* Hash table */

static const HashTableValue JSMessageChannelTableValues[] =
{
    { "port1", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsMessageChannelPort1), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "port2", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsMessageChannelPort2), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "constructor", DontEnum | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsMessageChannelConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { 0, 0, NoIntrinsic, 0, 0 }
};

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

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

static const HashTable JSMessageChannelConstructorTable = { 1, 0, false, JSMessageChannelConstructorTableValues, 0 };
EncodedJSValue JSC_HOST_CALL JSMessageChannelConstructor::constructJSMessageChannel(ExecState* exec)
{
    JSMessageChannelConstructor* castedThis = jsCast<JSMessageChannelConstructor*>(exec->callee());
    ScriptExecutionContext* context = castedThis->scriptExecutionContext();
    if (!context)
        return throwVMError(exec, createReferenceError(exec, "MessageChannel constructor associated document is unavailable"));
    RefPtr<MessageChannel> object = MessageChannel::create(*context);
    return JSValue::encode(asObject(toJS(exec, castedThis->globalObject(), object.get())));
}

static const HashTable& getJSMessageChannelConstructorTable(VM& vm)
{
    return getHashTableForGlobalData(vm, JSMessageChannelConstructorTable);
}

const ClassInfo JSMessageChannelConstructor::s_info = { "MessageChannelConstructor", &Base::s_info, 0, getJSMessageChannelConstructorTable, CREATE_METHOD_TABLE(JSMessageChannelConstructor) };

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

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

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

ConstructType JSMessageChannelConstructor::getConstructData(JSCell*, ConstructData& constructData)
{
    constructData.native.function = constructJSMessageChannel;
    return ConstructTypeHost;
}

/* Hash table for prototype */

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

static const HashTable JSMessageChannelPrototypeTable = { 1, 0, false, JSMessageChannelPrototypeTableValues, 0 };
static const HashTable& getJSMessageChannelPrototypeTable(VM& vm)
{
    return getHashTableForGlobalData(vm, JSMessageChannelPrototypeTable);
}

const ClassInfo JSMessageChannelPrototype::s_info = { "MessageChannelPrototype", &Base::s_info, 0, getJSMessageChannelPrototypeTable, CREATE_METHOD_TABLE(JSMessageChannelPrototype) };

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

static const HashTable& getJSMessageChannelTable(VM& vm)
{
    return getHashTableForGlobalData(vm, JSMessageChannelTable);
}

const ClassInfo JSMessageChannel::s_info = { "MessageChannel", &Base::s_info, 0, getJSMessageChannelTable , CREATE_METHOD_TABLE(JSMessageChannel) };

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

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

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

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

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

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

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


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


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

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

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

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

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

MessageChannel* toMessageChannel(JSC::JSValue value)
{
    return value.inherits(JSMessageChannel::info()) ? &jsCast<JSMessageChannel*>(value)->impl() : 0;
}

}

#endif // ENABLE(CHANNEL_MESSAGING)
