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

#include "JSRTCSessionDescription.h"

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

using namespace JSC;

namespace WebCore {

/* Hash table */

static const HashTableValue JSRTCSessionDescriptionTableValues[] =
{
    { "type", DontDelete, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsRTCSessionDescriptionType), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSRTCSessionDescriptionType) },
    { "sdp", DontDelete, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsRTCSessionDescriptionSdp), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSRTCSessionDescriptionSdp) },
    { "constructor", DontEnum | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsRTCSessionDescriptionConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { 0, 0, NoIntrinsic, 0, 0 }
};

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

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

static const HashTable JSRTCSessionDescriptionConstructorTable = { 1, 0, false, JSRTCSessionDescriptionConstructorTableValues, 0 };
const ClassInfo JSRTCSessionDescriptionConstructor::s_info = { "RTCSessionDescriptionConstructor", &Base::s_info, &JSRTCSessionDescriptionConstructorTable, 0, CREATE_METHOD_TABLE(JSRTCSessionDescriptionConstructor) };

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

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

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

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

/* Hash table for prototype */

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

static const HashTable JSRTCSessionDescriptionPrototypeTable = { 1, 0, false, JSRTCSessionDescriptionPrototypeTableValues, 0 };
const ClassInfo JSRTCSessionDescriptionPrototype::s_info = { "RTCSessionDescriptionPrototype", &Base::s_info, &JSRTCSessionDescriptionPrototypeTable, 0, CREATE_METHOD_TABLE(JSRTCSessionDescriptionPrototype) };

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

const ClassInfo JSRTCSessionDescription::s_info = { "RTCSessionDescription", &Base::s_info, &JSRTCSessionDescriptionTable, 0 , CREATE_METHOD_TABLE(JSRTCSessionDescription) };

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

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

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

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

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

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

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


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


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

void setJSRTCSessionDescriptionType(ExecState* exec, JSObject* /* baseObject */, EncodedJSValue thisValue, EncodedJSValue encodedValue)
{
    JSValue value = JSValue::decode(encodedValue);
    UNUSED_PARAM(exec);
    JSRTCSessionDescription* castedThis = jsDynamicCast<JSRTCSessionDescription*>(JSValue::decode(thisValue));
    if (!castedThis) {
        throwVMTypeError(exec);
        return;
    }
    RTCSessionDescription& impl = castedThis->impl();
    ExceptionCode ec = 0;
    const String& nativeValue(value.isEmpty() ? String() : value.toString(exec)->value(exec));
    if (exec->hadException())
        return;
    impl.setType(nativeValue, ec);
    setDOMException(exec, ec);
}


void setJSRTCSessionDescriptionSdp(ExecState* exec, JSObject* /* baseObject */, EncodedJSValue thisValue, EncodedJSValue encodedValue)
{
    JSValue value = JSValue::decode(encodedValue);
    UNUSED_PARAM(exec);
    JSRTCSessionDescription* castedThis = jsDynamicCast<JSRTCSessionDescription*>(JSValue::decode(thisValue));
    if (!castedThis) {
        throwVMTypeError(exec);
        return;
    }
    RTCSessionDescription& impl = castedThis->impl();
    const String& nativeValue(value.isEmpty() ? String() : value.toString(exec)->value(exec));
    if (exec->hadException())
        return;
    impl.setSdp(nativeValue);
}


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

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

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

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

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

RTCSessionDescription* toRTCSessionDescription(JSC::JSValue value)
{
    return value.inherits(JSRTCSessionDescription::info()) ? &jsCast<JSRTCSessionDescription*>(value)->impl() : 0;
}

}

#endif // ENABLE(MEDIA_STREAM)
