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

#include "JSAnalyserNode.h"

#include "AnalyserNode.h"
#include "ExceptionCode.h"
#include "JSDOMBinding.h"
#include <runtime/Error.h>
#include <wtf/GetPtr.h>

using namespace JSC;

namespace WebCore {

/* Hash table */

static const HashTableValue JSAnalyserNodeTableValues[] =
{
    { "fftSize", DontDelete, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsAnalyserNodeFftSize), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSAnalyserNodeFftSize) },
    { "frequencyBinCount", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsAnalyserNodeFrequencyBinCount), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "minDecibels", DontDelete, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsAnalyserNodeMinDecibels), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSAnalyserNodeMinDecibels) },
    { "maxDecibels", DontDelete, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsAnalyserNodeMaxDecibels), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSAnalyserNodeMaxDecibels) },
    { "smoothingTimeConstant", DontDelete, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsAnalyserNodeSmoothingTimeConstant), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSAnalyserNodeSmoothingTimeConstant) },
    { "constructor", DontEnum | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsAnalyserNodeConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { 0, 0, NoIntrinsic, 0, 0 }
};

static const HashTable JSAnalyserNodeTable = { 17, 15, true, JSAnalyserNodeTableValues, 0 };
/* Hash table for constructor */

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

static const HashTable JSAnalyserNodeConstructorTable = { 1, 0, false, JSAnalyserNodeConstructorTableValues, 0 };
const ClassInfo JSAnalyserNodeConstructor::s_info = { "AnalyserNodeConstructor", &Base::s_info, &JSAnalyserNodeConstructorTable, 0, CREATE_METHOD_TABLE(JSAnalyserNodeConstructor) };

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

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

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

/* Hash table for prototype */

static const HashTableValue JSAnalyserNodePrototypeTableValues[] =
{
    { "getFloatFrequencyData", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsAnalyserNodePrototypeFunctionGetFloatFrequencyData), (intptr_t) (1) },
    { "getByteFrequencyData", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsAnalyserNodePrototypeFunctionGetByteFrequencyData), (intptr_t) (1) },
    { "getByteTimeDomainData", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsAnalyserNodePrototypeFunctionGetByteTimeDomainData), (intptr_t) (1) },
    { 0, 0, NoIntrinsic, 0, 0 }
};

static const HashTable JSAnalyserNodePrototypeTable = { 8, 7, false, JSAnalyserNodePrototypeTableValues, 0 };
const ClassInfo JSAnalyserNodePrototype::s_info = { "AnalyserNodePrototype", &Base::s_info, &JSAnalyserNodePrototypeTable, 0, CREATE_METHOD_TABLE(JSAnalyserNodePrototype) };

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

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

const ClassInfo JSAnalyserNode::s_info = { "AnalyserNode", &Base::s_info, &JSAnalyserNodeTable, 0 , CREATE_METHOD_TABLE(JSAnalyserNode) };

JSAnalyserNode::JSAnalyserNode(Structure* structure, JSDOMGlobalObject* globalObject, PassRefPtr<AnalyserNode> impl)
    : JSAudioNode(structure, globalObject, impl)
{
}

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

JSObject* JSAnalyserNode::createPrototype(VM& vm, JSGlobalObject* globalObject)
{
    return JSAnalyserNodePrototype::create(vm, globalObject, JSAnalyserNodePrototype::createStructure(vm, globalObject, JSAudioNodePrototype::self(vm, globalObject)));
}

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

EncodedJSValue jsAnalyserNodeFftSize(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSAnalyserNode* castedThis = jsDynamicCast<JSAnalyserNode*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    UNUSED_PARAM(exec);
    AnalyserNode& impl = castedThis->impl();
    JSValue result = jsNumber(impl.fftSize());
    return JSValue::encode(result);
}


EncodedJSValue jsAnalyserNodeFrequencyBinCount(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSAnalyserNode* castedThis = jsDynamicCast<JSAnalyserNode*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    UNUSED_PARAM(exec);
    AnalyserNode& impl = castedThis->impl();
    JSValue result = jsNumber(impl.frequencyBinCount());
    return JSValue::encode(result);
}


EncodedJSValue jsAnalyserNodeMinDecibels(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSAnalyserNode* castedThis = jsDynamicCast<JSAnalyserNode*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    UNUSED_PARAM(exec);
    AnalyserNode& impl = castedThis->impl();
    JSValue result = jsNumber(impl.minDecibels());
    return JSValue::encode(result);
}


EncodedJSValue jsAnalyserNodeMaxDecibels(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSAnalyserNode* castedThis = jsDynamicCast<JSAnalyserNode*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    UNUSED_PARAM(exec);
    AnalyserNode& impl = castedThis->impl();
    JSValue result = jsNumber(impl.maxDecibels());
    return JSValue::encode(result);
}


EncodedJSValue jsAnalyserNodeSmoothingTimeConstant(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSAnalyserNode* castedThis = jsDynamicCast<JSAnalyserNode*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    UNUSED_PARAM(exec);
    AnalyserNode& impl = castedThis->impl();
    JSValue result = jsNumber(impl.smoothingTimeConstant());
    return JSValue::encode(result);
}


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

void setJSAnalyserNodeFftSize(ExecState* exec, JSObject* /* baseObject */, EncodedJSValue thisValue, EncodedJSValue encodedValue)
{
    JSValue value = JSValue::decode(encodedValue);
    UNUSED_PARAM(exec);
    JSAnalyserNode* castedThis = jsDynamicCast<JSAnalyserNode*>(JSValue::decode(thisValue));
    if (!castedThis) {
        throwVMTypeError(exec);
        return;
    }
    AnalyserNode& impl = castedThis->impl();
    ExceptionCode ec = 0;
    unsigned nativeValue(toUInt32(exec, value, NormalConversion));
    if (exec->hadException())
        return;
    impl.setFftSize(nativeValue, ec);
    setDOMException(exec, ec);
}


void setJSAnalyserNodeMinDecibels(ExecState* exec, JSObject* /* baseObject */, EncodedJSValue thisValue, EncodedJSValue encodedValue)
{
    JSValue value = JSValue::decode(encodedValue);
    UNUSED_PARAM(exec);
    JSAnalyserNode* castedThis = jsDynamicCast<JSAnalyserNode*>(JSValue::decode(thisValue));
    if (!castedThis) {
        throwVMTypeError(exec);
        return;
    }
    AnalyserNode& impl = castedThis->impl();
    ExceptionCode ec = 0;
    double nativeValue(value.toNumber(exec));
    if (exec->hadException())
        return;
    impl.setMinDecibels(nativeValue, ec);
    setDOMException(exec, ec);
}


void setJSAnalyserNodeMaxDecibels(ExecState* exec, JSObject* /* baseObject */, EncodedJSValue thisValue, EncodedJSValue encodedValue)
{
    JSValue value = JSValue::decode(encodedValue);
    UNUSED_PARAM(exec);
    JSAnalyserNode* castedThis = jsDynamicCast<JSAnalyserNode*>(JSValue::decode(thisValue));
    if (!castedThis) {
        throwVMTypeError(exec);
        return;
    }
    AnalyserNode& impl = castedThis->impl();
    ExceptionCode ec = 0;
    double nativeValue(value.toNumber(exec));
    if (exec->hadException())
        return;
    impl.setMaxDecibels(nativeValue, ec);
    setDOMException(exec, ec);
}


void setJSAnalyserNodeSmoothingTimeConstant(ExecState* exec, JSObject* /* baseObject */, EncodedJSValue thisValue, EncodedJSValue encodedValue)
{
    JSValue value = JSValue::decode(encodedValue);
    UNUSED_PARAM(exec);
    JSAnalyserNode* castedThis = jsDynamicCast<JSAnalyserNode*>(JSValue::decode(thisValue));
    if (!castedThis) {
        throwVMTypeError(exec);
        return;
    }
    AnalyserNode& impl = castedThis->impl();
    ExceptionCode ec = 0;
    double nativeValue(value.toNumber(exec));
    if (exec->hadException())
        return;
    impl.setSmoothingTimeConstant(nativeValue, ec);
    setDOMException(exec, ec);
}


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

EncodedJSValue JSC_HOST_CALL jsAnalyserNodePrototypeFunctionGetFloatFrequencyData(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    JSAnalyserNode* castedThis = jsDynamicCast<JSAnalyserNode*>(thisValue);
    if (!castedThis)
        return throwVMTypeError(exec);
    ASSERT_GC_OBJECT_INHERITS(castedThis, JSAnalyserNode::info());
    AnalyserNode& impl = castedThis->impl();
    if (exec->argumentCount() < 1)
        return throwVMError(exec, createNotEnoughArgumentsError(exec));
    RefPtr<Float32Array> array(toFloat32Array(exec->argument(0)));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());
    impl.getFloatFrequencyData(array.get());
    return JSValue::encode(jsUndefined());
}

EncodedJSValue JSC_HOST_CALL jsAnalyserNodePrototypeFunctionGetByteFrequencyData(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    JSAnalyserNode* castedThis = jsDynamicCast<JSAnalyserNode*>(thisValue);
    if (!castedThis)
        return throwVMTypeError(exec);
    ASSERT_GC_OBJECT_INHERITS(castedThis, JSAnalyserNode::info());
    AnalyserNode& impl = castedThis->impl();
    if (exec->argumentCount() < 1)
        return throwVMError(exec, createNotEnoughArgumentsError(exec));
    RefPtr<Uint8Array> array(toUint8Array(exec->argument(0)));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());
    impl.getByteFrequencyData(array.get());
    return JSValue::encode(jsUndefined());
}

EncodedJSValue JSC_HOST_CALL jsAnalyserNodePrototypeFunctionGetByteTimeDomainData(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    JSAnalyserNode* castedThis = jsDynamicCast<JSAnalyserNode*>(thisValue);
    if (!castedThis)
        return throwVMTypeError(exec);
    ASSERT_GC_OBJECT_INHERITS(castedThis, JSAnalyserNode::info());
    AnalyserNode& impl = castedThis->impl();
    if (exec->argumentCount() < 1)
        return throwVMError(exec, createNotEnoughArgumentsError(exec));
    RefPtr<Uint8Array> array(toUint8Array(exec->argument(0)));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());
    impl.getByteTimeDomainData(array.get());
    return JSValue::encode(jsUndefined());
}

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

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


}

#endif // ENABLE(WEB_AUDIO)
