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

#include "CallbackFunction.h"
#include "Dictionary.h"
#include "Event.h"
#include "EventListener.h"
#include "ExceptionCode.h"
#include "JSDOMBinding.h"
#include "JSEvent.h"
#include "JSEventListener.h"
#include "JSMediaSourceStates.h"
#include "JSMediaStreamCapabilities.h"
#include "JSMediaStreamTrack.h"
#include "JSMediaStreamTrackSourcesCallback.h"
#include "JSMediaTrackConstraints.h"
#include "MediaSourceStates.h"
#include "MediaStreamCapabilities.h"
#include "MediaStreamTrack.h"
#include "MediaTrackConstraints.h"
#include "URL.h"
#include <runtime/Error.h>
#include <runtime/JSString.h>
#include <wtf/GetPtr.h>

using namespace JSC;

namespace WebCore {

/* Hash table */

static const HashTableValue JSMediaStreamTrackTableValues[] =
{
    { "kind", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsMediaStreamTrackKind), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "id", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsMediaStreamTrackId), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "label", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsMediaStreamTrackLabel), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "enabled", DontDelete, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsMediaStreamTrackEnabled), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSMediaStreamTrackEnabled) },
    { "muted", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsMediaStreamTrackMuted), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "onmute", DontDelete, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsMediaStreamTrackOnmute), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSMediaStreamTrackOnmute) },
    { "onunmute", DontDelete, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsMediaStreamTrackOnunmute), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSMediaStreamTrackOnunmute) },
    { "readonly", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsMediaStreamTrackReadonly), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "remote", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsMediaStreamTrackRemote), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "readyState", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsMediaStreamTrackReadyState), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "onstarted", DontDelete, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsMediaStreamTrackOnstarted), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSMediaStreamTrackOnstarted) },
    { "onended", DontDelete, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsMediaStreamTrackOnended), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSMediaStreamTrackOnended) },
    { "onoverconstrained", DontDelete, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsMediaStreamTrackOnoverconstrained), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSMediaStreamTrackOnoverconstrained) },
    { "constructor", DontEnum | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsMediaStreamTrackConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { 0, 0, NoIntrinsic, 0, 0 }
};

static const HashTable JSMediaStreamTrackTable = { 33, 31, true, JSMediaStreamTrackTableValues, 0 };
/* Hash table for constructor */

static const HashTableValue JSMediaStreamTrackConstructorTableValues[] =
{
    { "getSources", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsMediaStreamTrackConstructorFunctionGetSources), (intptr_t) (1) },
    { 0, 0, NoIntrinsic, 0, 0 }
};

static const HashTable JSMediaStreamTrackConstructorTable = { 1, 0, false, JSMediaStreamTrackConstructorTableValues, 0 };
const ClassInfo JSMediaStreamTrackConstructor::s_info = { "MediaStreamTrackConstructor", &Base::s_info, &JSMediaStreamTrackConstructorTable, 0, CREATE_METHOD_TABLE(JSMediaStreamTrackConstructor) };

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

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

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

/* Hash table for prototype */

static const HashTableValue JSMediaStreamTrackPrototypeTableValues[] =
{
    { "constraints", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsMediaStreamTrackPrototypeFunctionConstraints), (intptr_t) (0) },
    { "states", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsMediaStreamTrackPrototypeFunctionStates), (intptr_t) (0) },
    { "capabilities", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsMediaStreamTrackPrototypeFunctionCapabilities), (intptr_t) (0) },
    { "applyConstraints", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsMediaStreamTrackPrototypeFunctionApplyConstraints), (intptr_t) (1) },
    { "clone", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsMediaStreamTrackPrototypeFunctionClone), (intptr_t) (0) },
    { "stop", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsMediaStreamTrackPrototypeFunctionStop), (intptr_t) (0) },
    { "addEventListener", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsMediaStreamTrackPrototypeFunctionAddEventListener), (intptr_t) (2) },
    { "removeEventListener", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsMediaStreamTrackPrototypeFunctionRemoveEventListener), (intptr_t) (2) },
    { "dispatchEvent", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsMediaStreamTrackPrototypeFunctionDispatchEvent), (intptr_t) (1) },
    { 0, 0, NoIntrinsic, 0, 0 }
};

static const HashTable JSMediaStreamTrackPrototypeTable = { 33, 31, false, JSMediaStreamTrackPrototypeTableValues, 0 };
const ClassInfo JSMediaStreamTrackPrototype::s_info = { "MediaStreamTrackPrototype", &Base::s_info, &JSMediaStreamTrackPrototypeTable, 0, CREATE_METHOD_TABLE(JSMediaStreamTrackPrototype) };

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

bool JSMediaStreamTrackPrototype::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
{
    JSMediaStreamTrackPrototype* thisObject = jsCast<JSMediaStreamTrackPrototype*>(object);
    return getStaticFunctionSlot<JSObject>(exec, JSMediaStreamTrackPrototypeTable, thisObject, propertyName, slot);
}

const ClassInfo JSMediaStreamTrack::s_info = { "MediaStreamTrack", &Base::s_info, &JSMediaStreamTrackTable, 0 , CREATE_METHOD_TABLE(JSMediaStreamTrack) };

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

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

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

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

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

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

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


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


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


EncodedJSValue jsMediaStreamTrackEnabled(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSMediaStreamTrack* castedThis = jsDynamicCast<JSMediaStreamTrack*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    UNUSED_PARAM(exec);
    MediaStreamTrack& impl = castedThis->impl();
    JSValue result = jsBoolean(impl.enabled());
    return JSValue::encode(result);
}


EncodedJSValue jsMediaStreamTrackMuted(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSMediaStreamTrack* castedThis = jsDynamicCast<JSMediaStreamTrack*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    UNUSED_PARAM(exec);
    MediaStreamTrack& impl = castedThis->impl();
    JSValue result = jsBoolean(impl.muted());
    return JSValue::encode(result);
}


EncodedJSValue jsMediaStreamTrackOnmute(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSMediaStreamTrack* castedThis = jsDynamicCast<JSMediaStreamTrack*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    UNUSED_PARAM(exec);
    MediaStreamTrack& impl = castedThis->impl();
    if (EventListener* listener = impl.onmute()) {
        if (const JSEventListener* jsListener = JSEventListener::cast(listener)) {
            if (JSObject* jsFunction = jsListener->jsFunction(impl.scriptExecutionContext()))
                return JSValue::encode(jsFunction);
        }
    }
    return JSValue::encode(jsNull());
}


EncodedJSValue jsMediaStreamTrackOnunmute(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSMediaStreamTrack* castedThis = jsDynamicCast<JSMediaStreamTrack*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    UNUSED_PARAM(exec);
    MediaStreamTrack& impl = castedThis->impl();
    if (EventListener* listener = impl.onunmute()) {
        if (const JSEventListener* jsListener = JSEventListener::cast(listener)) {
            if (JSObject* jsFunction = jsListener->jsFunction(impl.scriptExecutionContext()))
                return JSValue::encode(jsFunction);
        }
    }
    return JSValue::encode(jsNull());
}


EncodedJSValue jsMediaStreamTrackReadonly(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSMediaStreamTrack* castedThis = jsDynamicCast<JSMediaStreamTrack*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    UNUSED_PARAM(exec);
    MediaStreamTrack& impl = castedThis->impl();
    JSValue result = jsBoolean(impl.readonly());
    return JSValue::encode(result);
}


EncodedJSValue jsMediaStreamTrackRemote(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSMediaStreamTrack* castedThis = jsDynamicCast<JSMediaStreamTrack*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    UNUSED_PARAM(exec);
    MediaStreamTrack& impl = castedThis->impl();
    JSValue result = jsBoolean(impl.remote());
    return JSValue::encode(result);
}


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


EncodedJSValue jsMediaStreamTrackOnstarted(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSMediaStreamTrack* castedThis = jsDynamicCast<JSMediaStreamTrack*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    UNUSED_PARAM(exec);
    MediaStreamTrack& impl = castedThis->impl();
    if (EventListener* listener = impl.onstarted()) {
        if (const JSEventListener* jsListener = JSEventListener::cast(listener)) {
            if (JSObject* jsFunction = jsListener->jsFunction(impl.scriptExecutionContext()))
                return JSValue::encode(jsFunction);
        }
    }
    return JSValue::encode(jsNull());
}


EncodedJSValue jsMediaStreamTrackOnended(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSMediaStreamTrack* castedThis = jsDynamicCast<JSMediaStreamTrack*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    UNUSED_PARAM(exec);
    MediaStreamTrack& impl = castedThis->impl();
    if (EventListener* listener = impl.onended()) {
        if (const JSEventListener* jsListener = JSEventListener::cast(listener)) {
            if (JSObject* jsFunction = jsListener->jsFunction(impl.scriptExecutionContext()))
                return JSValue::encode(jsFunction);
        }
    }
    return JSValue::encode(jsNull());
}


EncodedJSValue jsMediaStreamTrackOnoverconstrained(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSMediaStreamTrack* castedThis = jsDynamicCast<JSMediaStreamTrack*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    UNUSED_PARAM(exec);
    MediaStreamTrack& impl = castedThis->impl();
    if (EventListener* listener = impl.onoverconstrained()) {
        if (const JSEventListener* jsListener = JSEventListener::cast(listener)) {
            if (JSObject* jsFunction = jsListener->jsFunction(impl.scriptExecutionContext()))
                return JSValue::encode(jsFunction);
        }
    }
    return JSValue::encode(jsNull());
}


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

void setJSMediaStreamTrackEnabled(ExecState* exec, JSObject* /* baseObject */, EncodedJSValue thisValue, EncodedJSValue encodedValue)
{
    JSValue value = JSValue::decode(encodedValue);
    UNUSED_PARAM(exec);
    JSMediaStreamTrack* castedThis = jsDynamicCast<JSMediaStreamTrack*>(JSValue::decode(thisValue));
    if (!castedThis) {
        throwVMTypeError(exec);
        return;
    }
    MediaStreamTrack& impl = castedThis->impl();
    bool nativeValue(value.toBoolean(exec));
    if (exec->hadException())
        return;
    impl.setEnabled(nativeValue);
}


void setJSMediaStreamTrackOnmute(ExecState* exec, JSObject* /* baseObject */, EncodedJSValue thisValue, EncodedJSValue encodedValue)
{
    JSValue value = JSValue::decode(encodedValue);
    UNUSED_PARAM(exec);
    JSMediaStreamTrack* castedThis = jsDynamicCast<JSMediaStreamTrack*>(JSValue::decode(thisValue));
    if (!castedThis) {
        throwVMTypeError(exec);
        return;
    }
    UNUSED_PARAM(exec);
    MediaStreamTrack& impl = castedThis->impl();
    impl.setOnmute(createJSAttributeEventListener(exec, value, castedThis));
}


void setJSMediaStreamTrackOnunmute(ExecState* exec, JSObject* /* baseObject */, EncodedJSValue thisValue, EncodedJSValue encodedValue)
{
    JSValue value = JSValue::decode(encodedValue);
    UNUSED_PARAM(exec);
    JSMediaStreamTrack* castedThis = jsDynamicCast<JSMediaStreamTrack*>(JSValue::decode(thisValue));
    if (!castedThis) {
        throwVMTypeError(exec);
        return;
    }
    UNUSED_PARAM(exec);
    MediaStreamTrack& impl = castedThis->impl();
    impl.setOnunmute(createJSAttributeEventListener(exec, value, castedThis));
}


void setJSMediaStreamTrackOnstarted(ExecState* exec, JSObject* /* baseObject */, EncodedJSValue thisValue, EncodedJSValue encodedValue)
{
    JSValue value = JSValue::decode(encodedValue);
    UNUSED_PARAM(exec);
    JSMediaStreamTrack* castedThis = jsDynamicCast<JSMediaStreamTrack*>(JSValue::decode(thisValue));
    if (!castedThis) {
        throwVMTypeError(exec);
        return;
    }
    UNUSED_PARAM(exec);
    MediaStreamTrack& impl = castedThis->impl();
    impl.setOnstarted(createJSAttributeEventListener(exec, value, castedThis));
}


void setJSMediaStreamTrackOnended(ExecState* exec, JSObject* /* baseObject */, EncodedJSValue thisValue, EncodedJSValue encodedValue)
{
    JSValue value = JSValue::decode(encodedValue);
    UNUSED_PARAM(exec);
    JSMediaStreamTrack* castedThis = jsDynamicCast<JSMediaStreamTrack*>(JSValue::decode(thisValue));
    if (!castedThis) {
        throwVMTypeError(exec);
        return;
    }
    UNUSED_PARAM(exec);
    MediaStreamTrack& impl = castedThis->impl();
    impl.setOnended(createJSAttributeEventListener(exec, value, castedThis));
}


void setJSMediaStreamTrackOnoverconstrained(ExecState* exec, JSObject* /* baseObject */, EncodedJSValue thisValue, EncodedJSValue encodedValue)
{
    JSValue value = JSValue::decode(encodedValue);
    UNUSED_PARAM(exec);
    JSMediaStreamTrack* castedThis = jsDynamicCast<JSMediaStreamTrack*>(JSValue::decode(thisValue));
    if (!castedThis) {
        throwVMTypeError(exec);
        return;
    }
    UNUSED_PARAM(exec);
    MediaStreamTrack& impl = castedThis->impl();
    impl.setOnoverconstrained(createJSAttributeEventListener(exec, value, castedThis));
}


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

EncodedJSValue JSC_HOST_CALL jsMediaStreamTrackConstructorFunctionGetSources(ExecState* exec)
{
    if (exec->argumentCount() < 1)
        return throwVMError(exec, createNotEnoughArgumentsError(exec));
    ExceptionCode ec = 0;
    ScriptExecutionContext* scriptContext = jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->scriptExecutionContext();
    if (!scriptContext)
        return JSValue::encode(jsUndefined());
    if (!exec->argument(0).isFunction())
        return throwVMTypeError(exec);
    RefPtr<MediaStreamTrackSourcesCallback> callback = createFunctionOnlyCallback<JSMediaStreamTrackSourcesCallback>(exec, jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()), exec->uncheckedArgument(0));
    MediaStreamTrack::getSources(scriptContext, callback, ec);
    setDOMException(exec, ec);
    return JSValue::encode(jsUndefined());
}

EncodedJSValue JSC_HOST_CALL jsMediaStreamTrackPrototypeFunctionConstraints(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    JSMediaStreamTrack* castedThis = jsDynamicCast<JSMediaStreamTrack*>(thisValue);
    if (!castedThis)
        return throwVMTypeError(exec);
    ASSERT_GC_OBJECT_INHERITS(castedThis, JSMediaStreamTrack::info());
    MediaStreamTrack& impl = castedThis->impl();

    JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(impl.constraints()));
    return JSValue::encode(result);
}

EncodedJSValue JSC_HOST_CALL jsMediaStreamTrackPrototypeFunctionStates(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    JSMediaStreamTrack* castedThis = jsDynamicCast<JSMediaStreamTrack*>(thisValue);
    if (!castedThis)
        return throwVMTypeError(exec);
    ASSERT_GC_OBJECT_INHERITS(castedThis, JSMediaStreamTrack::info());
    MediaStreamTrack& impl = castedThis->impl();

    JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(impl.states()));
    return JSValue::encode(result);
}

EncodedJSValue JSC_HOST_CALL jsMediaStreamTrackPrototypeFunctionCapabilities(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    JSMediaStreamTrack* castedThis = jsDynamicCast<JSMediaStreamTrack*>(thisValue);
    if (!castedThis)
        return throwVMTypeError(exec);
    ASSERT_GC_OBJECT_INHERITS(castedThis, JSMediaStreamTrack::info());
    MediaStreamTrack& impl = castedThis->impl();

    JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(impl.capabilities()));
    return JSValue::encode(result);
}

EncodedJSValue JSC_HOST_CALL jsMediaStreamTrackPrototypeFunctionApplyConstraints(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    JSMediaStreamTrack* castedThis = jsDynamicCast<JSMediaStreamTrack*>(thisValue);
    if (!castedThis)
        return throwVMTypeError(exec);
    ASSERT_GC_OBJECT_INHERITS(castedThis, JSMediaStreamTrack::info());
    MediaStreamTrack& impl = castedThis->impl();
    if (exec->argumentCount() < 1)
        return throwVMError(exec, createNotEnoughArgumentsError(exec));
    Dictionary constraints(exec, exec->argument(0));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());
    impl.applyConstraints(constraints);
    return JSValue::encode(jsUndefined());
}

EncodedJSValue JSC_HOST_CALL jsMediaStreamTrackPrototypeFunctionClone(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    JSMediaStreamTrack* castedThis = jsDynamicCast<JSMediaStreamTrack*>(thisValue);
    if (!castedThis)
        return throwVMTypeError(exec);
    ASSERT_GC_OBJECT_INHERITS(castedThis, JSMediaStreamTrack::info());
    MediaStreamTrack& impl = castedThis->impl();

    JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(impl.clone()));
    return JSValue::encode(result);
}

EncodedJSValue JSC_HOST_CALL jsMediaStreamTrackPrototypeFunctionStop(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    JSMediaStreamTrack* castedThis = jsDynamicCast<JSMediaStreamTrack*>(thisValue);
    if (!castedThis)
        return throwVMTypeError(exec);
    ASSERT_GC_OBJECT_INHERITS(castedThis, JSMediaStreamTrack::info());
    MediaStreamTrack& impl = castedThis->impl();
    impl.stopProducingData();
    return JSValue::encode(jsUndefined());
}

EncodedJSValue JSC_HOST_CALL jsMediaStreamTrackPrototypeFunctionAddEventListener(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    JSMediaStreamTrack* castedThis = jsDynamicCast<JSMediaStreamTrack*>(thisValue);
    if (!castedThis)
        return throwVMTypeError(exec);
    ASSERT_GC_OBJECT_INHERITS(castedThis, JSMediaStreamTrack::info());
    MediaStreamTrack& impl = castedThis->impl();
    JSValue listener = exec->argument(1);
    if (!listener.isObject())
        return JSValue::encode(jsUndefined());
    impl.addEventListener(exec->argument(0).toString(exec)->value(exec), JSEventListener::create(asObject(listener), castedThis, false, currentWorld(exec)), exec->argument(2).toBoolean(exec));
    return JSValue::encode(jsUndefined());
}

EncodedJSValue JSC_HOST_CALL jsMediaStreamTrackPrototypeFunctionRemoveEventListener(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    JSMediaStreamTrack* castedThis = jsDynamicCast<JSMediaStreamTrack*>(thisValue);
    if (!castedThis)
        return throwVMTypeError(exec);
    ASSERT_GC_OBJECT_INHERITS(castedThis, JSMediaStreamTrack::info());
    MediaStreamTrack& impl = castedThis->impl();
    JSValue listener = exec->argument(1);
    if (!listener.isObject())
        return JSValue::encode(jsUndefined());
    impl.removeEventListener(exec->argument(0).toString(exec)->value(exec), JSEventListener::create(asObject(listener), castedThis, false, currentWorld(exec)).get(), exec->argument(2).toBoolean(exec));
    return JSValue::encode(jsUndefined());
}

EncodedJSValue JSC_HOST_CALL jsMediaStreamTrackPrototypeFunctionDispatchEvent(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    JSMediaStreamTrack* castedThis = jsDynamicCast<JSMediaStreamTrack*>(thisValue);
    if (!castedThis)
        return throwVMTypeError(exec);
    ASSERT_GC_OBJECT_INHERITS(castedThis, JSMediaStreamTrack::info());
    MediaStreamTrack& impl = castedThis->impl();
    if (exec->argumentCount() < 1)
        return throwVMError(exec, createNotEnoughArgumentsError(exec));
    ExceptionCode ec = 0;
    Event* event(toEvent(exec->argument(0)));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());

    JSC::JSValue result = jsBoolean(impl.dispatchEvent(event, ec));
    setDOMException(exec, ec);
    return JSValue::encode(result);
}

void JSMediaStreamTrack::visitChildren(JSCell* cell, SlotVisitor& visitor)
{
    JSMediaStreamTrack* thisObject = jsCast<JSMediaStreamTrack*>(cell);
    ASSERT_GC_OBJECT_INHERITS(thisObject, info());
    COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
    ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren());
    Base::visitChildren(thisObject, visitor);
    thisObject->impl().visitJSEventListeners(visitor);
}

bool JSMediaStreamTrackOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor)
{
    JSMediaStreamTrack* jsMediaStreamTrack = jsCast<JSMediaStreamTrack*>(handle.get().asCell());
    if (jsMediaStreamTrack->impl().hasPendingActivity())
        return true;
    if (jsMediaStreamTrack->impl().isFiringEventListeners())
        return true;
    UNUSED_PARAM(visitor);
    return false;
}

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

JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, MediaStreamTrack* impl)
{
    if (!impl)
        return jsNull();
    if (JSValue result = getExistingWrapper<JSMediaStreamTrack>(exec, impl))
        return result;
    ReportMemoryCost<MediaStreamTrack>::reportMemoryCost(exec, impl);
    return createNewWrapper<JSMediaStreamTrack>(exec, globalObject, impl);
}

MediaStreamTrack* toMediaStreamTrack(JSC::JSValue value)
{
    return value.inherits(JSMediaStreamTrack::info()) ? &jsCast<JSMediaStreamTrack*>(value)->impl() : 0;
}

}

#endif // ENABLE(MEDIA_STREAM)
