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

#include "JSSVGMatrix.h"

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

using namespace JSC;

namespace WebCore {

/* Hash table */

static const HashTableValue JSSVGMatrixTableValues[] =
{
    { "a", DontDelete, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSVGMatrixA), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSSVGMatrixA) },
    { "b", DontDelete, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSVGMatrixB), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSSVGMatrixB) },
    { "c", DontDelete, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSVGMatrixC), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSSVGMatrixC) },
    { "d", DontDelete, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSVGMatrixD), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSSVGMatrixD) },
    { "e", DontDelete, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSVGMatrixE), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSSVGMatrixE) },
    { "f", DontDelete, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSVGMatrixF), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSSVGMatrixF) },
    { "constructor", DontEnum | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSVGMatrixConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { 0, 0, NoIntrinsic, 0, 0 }
};

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

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

static const HashTable JSSVGMatrixConstructorTable = { 1, 0, false, JSSVGMatrixConstructorTableValues, 0 };
const ClassInfo JSSVGMatrixConstructor::s_info = { "SVGMatrixConstructor", &Base::s_info, &JSSVGMatrixConstructorTable, 0, CREATE_METHOD_TABLE(JSSVGMatrixConstructor) };

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

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

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

/* Hash table for prototype */

static const HashTableValue JSSVGMatrixPrototypeTableValues[] =
{
    { "multiply", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsSVGMatrixPrototypeFunctionMultiply), (intptr_t) (1) },
    { "inverse", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsSVGMatrixPrototypeFunctionInverse), (intptr_t) (0) },
    { "translate", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsSVGMatrixPrototypeFunctionTranslate), (intptr_t) (2) },
    { "scale", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsSVGMatrixPrototypeFunctionScale), (intptr_t) (1) },
    { "scaleNonUniform", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsSVGMatrixPrototypeFunctionScaleNonUniform), (intptr_t) (2) },
    { "rotate", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsSVGMatrixPrototypeFunctionRotate), (intptr_t) (1) },
    { "rotateFromVector", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsSVGMatrixPrototypeFunctionRotateFromVector), (intptr_t) (2) },
    { "flipX", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsSVGMatrixPrototypeFunctionFlipX), (intptr_t) (0) },
    { "flipY", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsSVGMatrixPrototypeFunctionFlipY), (intptr_t) (0) },
    { "skewX", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsSVGMatrixPrototypeFunctionSkewX), (intptr_t) (1) },
    { "skewY", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsSVGMatrixPrototypeFunctionSkewY), (intptr_t) (1) },
    { 0, 0, NoIntrinsic, 0, 0 }
};

static const HashTable JSSVGMatrixPrototypeTable = { 33, 31, false, JSSVGMatrixPrototypeTableValues, 0 };
const ClassInfo JSSVGMatrixPrototype::s_info = { "SVGMatrixPrototype", &Base::s_info, &JSSVGMatrixPrototypeTable, 0, CREATE_METHOD_TABLE(JSSVGMatrixPrototype) };

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

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

const ClassInfo JSSVGMatrix::s_info = { "SVGMatrix", &Base::s_info, &JSSVGMatrixTable, 0 , CREATE_METHOD_TABLE(JSSVGMatrix) };

JSSVGMatrix::JSSVGMatrix(Structure* structure, JSDOMGlobalObject* globalObject, PassRefPtr<SVGPropertyTearOff<SVGMatrix> > impl)
    : JSDOMWrapper(structure, globalObject)
    , m_impl(impl.leakRef())
{
}

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

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

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

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

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

EncodedJSValue jsSVGMatrixA(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSSVGMatrix* castedThis = jsDynamicCast<JSSVGMatrix*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    UNUSED_PARAM(exec);
    SVGMatrix& impl = castedThis->impl().propertyReference();
    JSValue result = jsNumber(impl.a());
    return JSValue::encode(result);
}


EncodedJSValue jsSVGMatrixB(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSSVGMatrix* castedThis = jsDynamicCast<JSSVGMatrix*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    UNUSED_PARAM(exec);
    SVGMatrix& impl = castedThis->impl().propertyReference();
    JSValue result = jsNumber(impl.b());
    return JSValue::encode(result);
}


EncodedJSValue jsSVGMatrixC(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSSVGMatrix* castedThis = jsDynamicCast<JSSVGMatrix*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    UNUSED_PARAM(exec);
    SVGMatrix& impl = castedThis->impl().propertyReference();
    JSValue result = jsNumber(impl.c());
    return JSValue::encode(result);
}


EncodedJSValue jsSVGMatrixD(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSSVGMatrix* castedThis = jsDynamicCast<JSSVGMatrix*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    UNUSED_PARAM(exec);
    SVGMatrix& impl = castedThis->impl().propertyReference();
    JSValue result = jsNumber(impl.d());
    return JSValue::encode(result);
}


EncodedJSValue jsSVGMatrixE(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSSVGMatrix* castedThis = jsDynamicCast<JSSVGMatrix*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    UNUSED_PARAM(exec);
    SVGMatrix& impl = castedThis->impl().propertyReference();
    JSValue result = jsNumber(impl.e());
    return JSValue::encode(result);
}


EncodedJSValue jsSVGMatrixF(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSSVGMatrix* castedThis = jsDynamicCast<JSSVGMatrix*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    UNUSED_PARAM(exec);
    SVGMatrix& impl = castedThis->impl().propertyReference();
    JSValue result = jsNumber(impl.f());
    return JSValue::encode(result);
}


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

void setJSSVGMatrixA(ExecState* exec, JSObject* /* baseObject */, EncodedJSValue thisValue, EncodedJSValue encodedValue)
{
    JSValue value = JSValue::decode(encodedValue);
    UNUSED_PARAM(exec);
    JSSVGMatrix* castedThis = jsDynamicCast<JSSVGMatrix*>(JSValue::decode(thisValue));
    if (!castedThis) {
        throwVMTypeError(exec);
        return;
    }
    SVGPropertyTearOff<SVGMatrix> & impl = castedThis->impl();
    double nativeValue(value.toNumber(exec));
    if (exec->hadException())
        return;
    if (impl.isReadOnly()) {
        setDOMException(exec, NO_MODIFICATION_ALLOWED_ERR);
        return;
    }
    SVGMatrix& podImpl = impl.propertyReference();
    podImpl.setA(nativeValue);
    impl.commitChange();
}


void setJSSVGMatrixB(ExecState* exec, JSObject* /* baseObject */, EncodedJSValue thisValue, EncodedJSValue encodedValue)
{
    JSValue value = JSValue::decode(encodedValue);
    UNUSED_PARAM(exec);
    JSSVGMatrix* castedThis = jsDynamicCast<JSSVGMatrix*>(JSValue::decode(thisValue));
    if (!castedThis) {
        throwVMTypeError(exec);
        return;
    }
    SVGPropertyTearOff<SVGMatrix> & impl = castedThis->impl();
    double nativeValue(value.toNumber(exec));
    if (exec->hadException())
        return;
    if (impl.isReadOnly()) {
        setDOMException(exec, NO_MODIFICATION_ALLOWED_ERR);
        return;
    }
    SVGMatrix& podImpl = impl.propertyReference();
    podImpl.setB(nativeValue);
    impl.commitChange();
}


void setJSSVGMatrixC(ExecState* exec, JSObject* /* baseObject */, EncodedJSValue thisValue, EncodedJSValue encodedValue)
{
    JSValue value = JSValue::decode(encodedValue);
    UNUSED_PARAM(exec);
    JSSVGMatrix* castedThis = jsDynamicCast<JSSVGMatrix*>(JSValue::decode(thisValue));
    if (!castedThis) {
        throwVMTypeError(exec);
        return;
    }
    SVGPropertyTearOff<SVGMatrix> & impl = castedThis->impl();
    double nativeValue(value.toNumber(exec));
    if (exec->hadException())
        return;
    if (impl.isReadOnly()) {
        setDOMException(exec, NO_MODIFICATION_ALLOWED_ERR);
        return;
    }
    SVGMatrix& podImpl = impl.propertyReference();
    podImpl.setC(nativeValue);
    impl.commitChange();
}


void setJSSVGMatrixD(ExecState* exec, JSObject* /* baseObject */, EncodedJSValue thisValue, EncodedJSValue encodedValue)
{
    JSValue value = JSValue::decode(encodedValue);
    UNUSED_PARAM(exec);
    JSSVGMatrix* castedThis = jsDynamicCast<JSSVGMatrix*>(JSValue::decode(thisValue));
    if (!castedThis) {
        throwVMTypeError(exec);
        return;
    }
    SVGPropertyTearOff<SVGMatrix> & impl = castedThis->impl();
    double nativeValue(value.toNumber(exec));
    if (exec->hadException())
        return;
    if (impl.isReadOnly()) {
        setDOMException(exec, NO_MODIFICATION_ALLOWED_ERR);
        return;
    }
    SVGMatrix& podImpl = impl.propertyReference();
    podImpl.setD(nativeValue);
    impl.commitChange();
}


void setJSSVGMatrixE(ExecState* exec, JSObject* /* baseObject */, EncodedJSValue thisValue, EncodedJSValue encodedValue)
{
    JSValue value = JSValue::decode(encodedValue);
    UNUSED_PARAM(exec);
    JSSVGMatrix* castedThis = jsDynamicCast<JSSVGMatrix*>(JSValue::decode(thisValue));
    if (!castedThis) {
        throwVMTypeError(exec);
        return;
    }
    SVGPropertyTearOff<SVGMatrix> & impl = castedThis->impl();
    double nativeValue(value.toNumber(exec));
    if (exec->hadException())
        return;
    if (impl.isReadOnly()) {
        setDOMException(exec, NO_MODIFICATION_ALLOWED_ERR);
        return;
    }
    SVGMatrix& podImpl = impl.propertyReference();
    podImpl.setE(nativeValue);
    impl.commitChange();
}


void setJSSVGMatrixF(ExecState* exec, JSObject* /* baseObject */, EncodedJSValue thisValue, EncodedJSValue encodedValue)
{
    JSValue value = JSValue::decode(encodedValue);
    UNUSED_PARAM(exec);
    JSSVGMatrix* castedThis = jsDynamicCast<JSSVGMatrix*>(JSValue::decode(thisValue));
    if (!castedThis) {
        throwVMTypeError(exec);
        return;
    }
    SVGPropertyTearOff<SVGMatrix> & impl = castedThis->impl();
    double nativeValue(value.toNumber(exec));
    if (exec->hadException())
        return;
    if (impl.isReadOnly()) {
        setDOMException(exec, NO_MODIFICATION_ALLOWED_ERR);
        return;
    }
    SVGMatrix& podImpl = impl.propertyReference();
    podImpl.setF(nativeValue);
    impl.commitChange();
}


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

EncodedJSValue JSC_HOST_CALL jsSVGMatrixPrototypeFunctionMultiply(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    JSSVGMatrix* castedThis = jsDynamicCast<JSSVGMatrix*>(thisValue);
    if (!castedThis)
        return throwVMTypeError(exec);
    ASSERT_GC_OBJECT_INHERITS(castedThis, JSSVGMatrix::info());
    SVGPropertyTearOff<SVGMatrix> & impl = castedThis->impl();
    if (impl.isReadOnly()) {
        setDOMException(exec, NO_MODIFICATION_ALLOWED_ERR);
        return JSValue::encode(jsUndefined());
    }
    SVGMatrix& podImpl = impl.propertyReference();
    if (exec->argumentCount() < 1)
        return throwVMError(exec, createNotEnoughArgumentsError(exec));
    if (exec->argumentCount() > 0 && !exec->argument(0).isUndefinedOrNull() && !exec->argument(0).inherits(JSSVGMatrix::info()))
        return throwVMTypeError(exec);
    SVGPropertyTearOff<SVGMatrix>* secondMatrix(toSVGMatrix(exec->argument(0)));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());
    if (!secondMatrix) {
        setDOMException(exec, TYPE_MISMATCH_ERR);
        return JSValue::encode(jsUndefined());
    }

    JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(SVGPropertyTearOff<SVGMatrix>::create(podImpl.multiply(secondMatrix->propertyReference()))));
    return JSValue::encode(result);
}

EncodedJSValue JSC_HOST_CALL jsSVGMatrixPrototypeFunctionInverse(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    JSSVGMatrix* castedThis = jsDynamicCast<JSSVGMatrix*>(thisValue);
    if (!castedThis)
        return throwVMTypeError(exec);
    ASSERT_GC_OBJECT_INHERITS(castedThis, JSSVGMatrix::info());
    SVGPropertyTearOff<SVGMatrix> & impl = castedThis->impl();
    if (impl.isReadOnly()) {
        setDOMException(exec, NO_MODIFICATION_ALLOWED_ERR);
        return JSValue::encode(jsUndefined());
    }
    SVGMatrix& podImpl = impl.propertyReference();
    ExceptionCode ec = 0;

    JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(SVGPropertyTearOff<SVGMatrix>::create(podImpl.inverse(ec))));
    setDOMException(exec, ec);
    return JSValue::encode(result);
}

EncodedJSValue JSC_HOST_CALL jsSVGMatrixPrototypeFunctionTranslate(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    JSSVGMatrix* castedThis = jsDynamicCast<JSSVGMatrix*>(thisValue);
    if (!castedThis)
        return throwVMTypeError(exec);
    ASSERT_GC_OBJECT_INHERITS(castedThis, JSSVGMatrix::info());
    SVGPropertyTearOff<SVGMatrix> & impl = castedThis->impl();
    if (impl.isReadOnly()) {
        setDOMException(exec, NO_MODIFICATION_ALLOWED_ERR);
        return JSValue::encode(jsUndefined());
    }
    SVGMatrix& podImpl = impl.propertyReference();
    if (exec->argumentCount() < 2)
        return throwVMError(exec, createNotEnoughArgumentsError(exec));
    float x(exec->argument(0).toFloat(exec));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());
    float y(exec->argument(1).toFloat(exec));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());

    JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(SVGPropertyTearOff<SVGMatrix>::create(podImpl.translate(x, y))));
    return JSValue::encode(result);
}

EncodedJSValue JSC_HOST_CALL jsSVGMatrixPrototypeFunctionScale(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    JSSVGMatrix* castedThis = jsDynamicCast<JSSVGMatrix*>(thisValue);
    if (!castedThis)
        return throwVMTypeError(exec);
    ASSERT_GC_OBJECT_INHERITS(castedThis, JSSVGMatrix::info());
    SVGPropertyTearOff<SVGMatrix> & impl = castedThis->impl();
    if (impl.isReadOnly()) {
        setDOMException(exec, NO_MODIFICATION_ALLOWED_ERR);
        return JSValue::encode(jsUndefined());
    }
    SVGMatrix& podImpl = impl.propertyReference();
    if (exec->argumentCount() < 1)
        return throwVMError(exec, createNotEnoughArgumentsError(exec));
    float scaleFactor(exec->argument(0).toFloat(exec));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());

    JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(SVGPropertyTearOff<SVGMatrix>::create(podImpl.scale(scaleFactor))));
    return JSValue::encode(result);
}

EncodedJSValue JSC_HOST_CALL jsSVGMatrixPrototypeFunctionScaleNonUniform(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    JSSVGMatrix* castedThis = jsDynamicCast<JSSVGMatrix*>(thisValue);
    if (!castedThis)
        return throwVMTypeError(exec);
    ASSERT_GC_OBJECT_INHERITS(castedThis, JSSVGMatrix::info());
    SVGPropertyTearOff<SVGMatrix> & impl = castedThis->impl();
    if (impl.isReadOnly()) {
        setDOMException(exec, NO_MODIFICATION_ALLOWED_ERR);
        return JSValue::encode(jsUndefined());
    }
    SVGMatrix& podImpl = impl.propertyReference();
    if (exec->argumentCount() < 2)
        return throwVMError(exec, createNotEnoughArgumentsError(exec));
    float scaleFactorX(exec->argument(0).toFloat(exec));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());
    float scaleFactorY(exec->argument(1).toFloat(exec));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());

    JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(SVGPropertyTearOff<SVGMatrix>::create(podImpl.scaleNonUniform(scaleFactorX, scaleFactorY))));
    return JSValue::encode(result);
}

EncodedJSValue JSC_HOST_CALL jsSVGMatrixPrototypeFunctionRotate(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    JSSVGMatrix* castedThis = jsDynamicCast<JSSVGMatrix*>(thisValue);
    if (!castedThis)
        return throwVMTypeError(exec);
    ASSERT_GC_OBJECT_INHERITS(castedThis, JSSVGMatrix::info());
    SVGPropertyTearOff<SVGMatrix> & impl = castedThis->impl();
    if (impl.isReadOnly()) {
        setDOMException(exec, NO_MODIFICATION_ALLOWED_ERR);
        return JSValue::encode(jsUndefined());
    }
    SVGMatrix& podImpl = impl.propertyReference();
    if (exec->argumentCount() < 1)
        return throwVMError(exec, createNotEnoughArgumentsError(exec));
    float angle(exec->argument(0).toFloat(exec));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());

    JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(SVGPropertyTearOff<SVGMatrix>::create(podImpl.rotate(angle))));
    return JSValue::encode(result);
}

EncodedJSValue JSC_HOST_CALL jsSVGMatrixPrototypeFunctionRotateFromVector(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    JSSVGMatrix* castedThis = jsDynamicCast<JSSVGMatrix*>(thisValue);
    if (!castedThis)
        return throwVMTypeError(exec);
    ASSERT_GC_OBJECT_INHERITS(castedThis, JSSVGMatrix::info());
    SVGPropertyTearOff<SVGMatrix> & impl = castedThis->impl();
    if (impl.isReadOnly()) {
        setDOMException(exec, NO_MODIFICATION_ALLOWED_ERR);
        return JSValue::encode(jsUndefined());
    }
    SVGMatrix& podImpl = impl.propertyReference();
    if (exec->argumentCount() < 2)
        return throwVMError(exec, createNotEnoughArgumentsError(exec));
    ExceptionCode ec = 0;
    float x(exec->argument(0).toFloat(exec));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());
    float y(exec->argument(1).toFloat(exec));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());

    JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(SVGPropertyTearOff<SVGMatrix>::create(podImpl.rotateFromVector(x, y, ec))));
    setDOMException(exec, ec);
    return JSValue::encode(result);
}

EncodedJSValue JSC_HOST_CALL jsSVGMatrixPrototypeFunctionFlipX(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    JSSVGMatrix* castedThis = jsDynamicCast<JSSVGMatrix*>(thisValue);
    if (!castedThis)
        return throwVMTypeError(exec);
    ASSERT_GC_OBJECT_INHERITS(castedThis, JSSVGMatrix::info());
    SVGPropertyTearOff<SVGMatrix> & impl = castedThis->impl();
    if (impl.isReadOnly()) {
        setDOMException(exec, NO_MODIFICATION_ALLOWED_ERR);
        return JSValue::encode(jsUndefined());
    }
    SVGMatrix& podImpl = impl.propertyReference();

    JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(SVGPropertyTearOff<SVGMatrix>::create(podImpl.flipX())));
    return JSValue::encode(result);
}

EncodedJSValue JSC_HOST_CALL jsSVGMatrixPrototypeFunctionFlipY(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    JSSVGMatrix* castedThis = jsDynamicCast<JSSVGMatrix*>(thisValue);
    if (!castedThis)
        return throwVMTypeError(exec);
    ASSERT_GC_OBJECT_INHERITS(castedThis, JSSVGMatrix::info());
    SVGPropertyTearOff<SVGMatrix> & impl = castedThis->impl();
    if (impl.isReadOnly()) {
        setDOMException(exec, NO_MODIFICATION_ALLOWED_ERR);
        return JSValue::encode(jsUndefined());
    }
    SVGMatrix& podImpl = impl.propertyReference();

    JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(SVGPropertyTearOff<SVGMatrix>::create(podImpl.flipY())));
    return JSValue::encode(result);
}

EncodedJSValue JSC_HOST_CALL jsSVGMatrixPrototypeFunctionSkewX(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    JSSVGMatrix* castedThis = jsDynamicCast<JSSVGMatrix*>(thisValue);
    if (!castedThis)
        return throwVMTypeError(exec);
    ASSERT_GC_OBJECT_INHERITS(castedThis, JSSVGMatrix::info());
    SVGPropertyTearOff<SVGMatrix> & impl = castedThis->impl();
    if (impl.isReadOnly()) {
        setDOMException(exec, NO_MODIFICATION_ALLOWED_ERR);
        return JSValue::encode(jsUndefined());
    }
    SVGMatrix& podImpl = impl.propertyReference();
    if (exec->argumentCount() < 1)
        return throwVMError(exec, createNotEnoughArgumentsError(exec));
    float angle(exec->argument(0).toFloat(exec));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());

    JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(SVGPropertyTearOff<SVGMatrix>::create(podImpl.skewX(angle))));
    return JSValue::encode(result);
}

EncodedJSValue JSC_HOST_CALL jsSVGMatrixPrototypeFunctionSkewY(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    JSSVGMatrix* castedThis = jsDynamicCast<JSSVGMatrix*>(thisValue);
    if (!castedThis)
        return throwVMTypeError(exec);
    ASSERT_GC_OBJECT_INHERITS(castedThis, JSSVGMatrix::info());
    SVGPropertyTearOff<SVGMatrix> & impl = castedThis->impl();
    if (impl.isReadOnly()) {
        setDOMException(exec, NO_MODIFICATION_ALLOWED_ERR);
        return JSValue::encode(jsUndefined());
    }
    SVGMatrix& podImpl = impl.propertyReference();
    if (exec->argumentCount() < 1)
        return throwVMError(exec, createNotEnoughArgumentsError(exec));
    float angle(exec->argument(0).toFloat(exec));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());

    JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(SVGPropertyTearOff<SVGMatrix>::create(podImpl.skewY(angle))));
    return JSValue::encode(result);
}

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

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

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

SVGPropertyTearOff<SVGMatrix> * toSVGMatrix(JSC::JSValue value)
{
    return value.inherits(JSSVGMatrix::info()) ? &jsCast<JSSVGMatrix*>(value)->impl() : 0;
}

}

#endif // ENABLE(SVG)
