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

#include "JSCryptoKeyPair.h"

#include "CryptoKey.h"
#include "CryptoKeyPair.h"
#include "JSCryptoKey.h"
#include <wtf/GetPtr.h>

using namespace JSC;

namespace WebCore {

/* Hash table */

static const HashTableValue JSCryptoKeyPairTableValues[] =
{
    { "publicKey", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsCryptoKeyPairPublicKey), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "privateKey", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsCryptoKeyPairPrivateKey), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { 0, 0, NoIntrinsic, 0, 0 }
};

static const HashTable JSCryptoKeyPairTable = { 4, 3, true, JSCryptoKeyPairTableValues, 0 };
/* Hash table for prototype */

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

static const HashTable JSCryptoKeyPairPrototypeTable = { 1, 0, false, JSCryptoKeyPairPrototypeTableValues, 0 };
const ClassInfo JSCryptoKeyPairPrototype::s_info = { "KeyPairPrototype", &Base::s_info, &JSCryptoKeyPairPrototypeTable, 0, CREATE_METHOD_TABLE(JSCryptoKeyPairPrototype) };

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

const ClassInfo JSCryptoKeyPair::s_info = { "KeyPair", &Base::s_info, &JSCryptoKeyPairTable, 0 , CREATE_METHOD_TABLE(JSCryptoKeyPair) };

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

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

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

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

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

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

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


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


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

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

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

CryptoKeyPair* toCryptoKeyPair(JSC::JSValue value)
{
    return value.inherits(JSCryptoKeyPair::info()) ? &jsCast<JSCryptoKeyPair*>(value)->impl() : 0;
}

}

#endif // ENABLE(SUBTLE_CRYPTO)
