blob: 27e56c0abc01425fe23b32d050e00aa45f144a0a [file] [log] [blame]
/*
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 "JSCryptoKey.h"
#include "JSDOMBinding.h"
#include "JSDOMConstructor.h"
#include "JSDOMConvert.h"
#include <runtime/FunctionPrototype.h>
#include <runtime/JSString.h>
#include <wtf/GetPtr.h>
using namespace JSC;
namespace WebCore {
template<typename T> Optional<T> parse(ExecState&, JSValue);
template<typename T> const char* expectedEnumerationValues();
JSString* jsStringWithCache(ExecState*, CryptoKey::Type);
JSString* jsStringWithCache(ExecState* state, CryptoKey::Type enumerationValue)
{
static NeverDestroyed<const String> values[] = {
ASCIILiteral("public"),
ASCIILiteral("private"),
ASCIILiteral("secret"),
};
static_assert(static_cast<size_t>(CryptoKey::Type::Public) == 0, "CryptoKey::Type::Public is not 0 as expected");
static_assert(static_cast<size_t>(CryptoKey::Type::Private) == 1, "CryptoKey::Type::Private is not 1 as expected");
static_assert(static_cast<size_t>(CryptoKey::Type::Secret) == 2, "CryptoKey::Type::Secret is not 2 as expected");
ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values));
return jsStringWithCache(state, values[static_cast<size_t>(enumerationValue)]);
}
template<> struct JSValueTraits<CryptoKey::Type> {
static JSString* arrayJSValue(ExecState* state, JSDOMGlobalObject*, CryptoKey::Type value) { return jsStringWithCache(state, value); }
};
template<> Optional<CryptoKey::Type> parse<CryptoKey::Type>(ExecState& state, JSValue value)
{
auto stringValue = value.toWTFString(&state);
if (stringValue == "public")
return CryptoKey::Type::Public;
if (stringValue == "private")
return CryptoKey::Type::Private;
if (stringValue == "secret")
return CryptoKey::Type::Secret;
return Nullopt;
}
template<> CryptoKey::Type convert<CryptoKey::Type>(ExecState& state, JSValue value)
{
VM& vm = state.vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
auto result = parse<CryptoKey::Type>(state, value);
if (UNLIKELY(!result)) {
throwTypeError(&state, throwScope);
return { };
}
return result.value();
}
template<> inline const char* expectedEnumerationValues<CryptoKey::Type>()
{
return "\"public\", \"private\", \"secret\"";
}
JSString* jsStringWithCache(ExecState*, CryptoKey::Usage);
JSString* jsStringWithCache(ExecState* state, CryptoKey::Usage enumerationValue)
{
static NeverDestroyed<const String> values[] = {
ASCIILiteral("encrypt"),
ASCIILiteral("decrypt"),
ASCIILiteral("sign"),
ASCIILiteral("verify"),
ASCIILiteral("deriveKey"),
ASCIILiteral("deriveBits"),
ASCIILiteral("wrapKey"),
ASCIILiteral("unwrapKey"),
};
static_assert(static_cast<size_t>(CryptoKey::Usage::Encrypt) == 0, "CryptoKey::Usage::Encrypt is not 0 as expected");
static_assert(static_cast<size_t>(CryptoKey::Usage::Decrypt) == 1, "CryptoKey::Usage::Decrypt is not 1 as expected");
static_assert(static_cast<size_t>(CryptoKey::Usage::Sign) == 2, "CryptoKey::Usage::Sign is not 2 as expected");
static_assert(static_cast<size_t>(CryptoKey::Usage::Verify) == 3, "CryptoKey::Usage::Verify is not 3 as expected");
static_assert(static_cast<size_t>(CryptoKey::Usage::DeriveKey) == 4, "CryptoKey::Usage::DeriveKey is not 4 as expected");
static_assert(static_cast<size_t>(CryptoKey::Usage::DeriveBits) == 5, "CryptoKey::Usage::DeriveBits is not 5 as expected");
static_assert(static_cast<size_t>(CryptoKey::Usage::WrapKey) == 6, "CryptoKey::Usage::WrapKey is not 6 as expected");
static_assert(static_cast<size_t>(CryptoKey::Usage::UnwrapKey) == 7, "CryptoKey::Usage::UnwrapKey is not 7 as expected");
ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values));
return jsStringWithCache(state, values[static_cast<size_t>(enumerationValue)]);
}
template<> struct JSValueTraits<CryptoKey::Usage> {
static JSString* arrayJSValue(ExecState* state, JSDOMGlobalObject*, CryptoKey::Usage value) { return jsStringWithCache(state, value); }
};
template<> Optional<CryptoKey::Usage> parse<CryptoKey::Usage>(ExecState& state, JSValue value)
{
auto stringValue = value.toWTFString(&state);
if (stringValue == "encrypt")
return CryptoKey::Usage::Encrypt;
if (stringValue == "decrypt")
return CryptoKey::Usage::Decrypt;
if (stringValue == "sign")
return CryptoKey::Usage::Sign;
if (stringValue == "verify")
return CryptoKey::Usage::Verify;
if (stringValue == "deriveKey")
return CryptoKey::Usage::DeriveKey;
if (stringValue == "deriveBits")
return CryptoKey::Usage::DeriveBits;
if (stringValue == "wrapKey")
return CryptoKey::Usage::WrapKey;
if (stringValue == "unwrapKey")
return CryptoKey::Usage::UnwrapKey;
return Nullopt;
}
template<> CryptoKey::Usage convert<CryptoKey::Usage>(ExecState& state, JSValue value)
{
VM& vm = state.vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
auto result = parse<CryptoKey::Usage>(state, value);
if (UNLIKELY(!result)) {
throwTypeError(&state, throwScope);
return { };
}
return result.value();
}
template<> inline const char* expectedEnumerationValues<CryptoKey::Usage>()
{
return "\"encrypt\", \"decrypt\", \"sign\", \"verify\", \"deriveKey\", \"deriveBits\", \"wrapKey\", \"unwrapKey\"";
}
// Attributes
JSC::EncodedJSValue jsCryptoKeyType(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
JSC::EncodedJSValue jsCryptoKeyExtractable(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
JSC::EncodedJSValue jsCryptoKeyAlgorithm(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
JSC::EncodedJSValue jsCryptoKeyUsages(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
JSC::EncodedJSValue jsCryptoKeyConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
bool setJSCryptoKeyConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
class JSCryptoKeyPrototype : public JSC::JSNonFinalObject {
public:
typedef JSC::JSNonFinalObject Base;
static JSCryptoKeyPrototype* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure)
{
JSCryptoKeyPrototype* ptr = new (NotNull, JSC::allocateCell<JSCryptoKeyPrototype>(vm.heap)) JSCryptoKeyPrototype(vm, globalObject, structure);
ptr->finishCreation(vm);
return ptr;
}
DECLARE_INFO;
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
}
private:
JSCryptoKeyPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
: JSC::JSNonFinalObject(vm, structure)
{
}
void finishCreation(JSC::VM&);
};
typedef JSDOMConstructorNotConstructable<JSCryptoKey> JSCryptoKeyConstructor;
template<> JSValue JSCryptoKeyConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
{
UNUSED_PARAM(vm);
return globalObject.functionPrototype();
}
template<> void JSCryptoKeyConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
{
putDirect(vm, vm.propertyNames->prototype, JSCryptoKey::prototype(vm, &globalObject), DontDelete | ReadOnly | DontEnum);
putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String(ASCIILiteral("CryptoKey"))), ReadOnly | DontEnum);
putDirect(vm, vm.propertyNames->length, jsNumber(0), ReadOnly | DontEnum);
}
template<> const ClassInfo JSCryptoKeyConstructor::s_info = { "CryptoKey", &Base::s_info, 0, CREATE_METHOD_TABLE(JSCryptoKeyConstructor) };
/* Hash table for prototype */
static const HashTableValue JSCryptoKeyPrototypeTableValues[] =
{
{ "constructor", DontEnum, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsCryptoKeyConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSCryptoKeyConstructor) } },
{ "type", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsCryptoKeyType), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
{ "extractable", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsCryptoKeyExtractable), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
{ "algorithm", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsCryptoKeyAlgorithm), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
{ "usages", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsCryptoKeyUsages), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
};
const ClassInfo JSCryptoKeyPrototype::s_info = { "CryptoKeyPrototype", &Base::s_info, 0, CREATE_METHOD_TABLE(JSCryptoKeyPrototype) };
void JSCryptoKeyPrototype::finishCreation(VM& vm)
{
Base::finishCreation(vm);
reifyStaticProperties(vm, JSCryptoKeyPrototypeTableValues, *this);
}
const ClassInfo JSCryptoKey::s_info = { "CryptoKey", &Base::s_info, 0, CREATE_METHOD_TABLE(JSCryptoKey) };
JSCryptoKey::JSCryptoKey(Structure* structure, JSDOMGlobalObject& globalObject, Ref<CryptoKey>&& impl)
: JSDOMWrapper<CryptoKey>(structure, globalObject, WTFMove(impl))
{
}
JSObject* JSCryptoKey::createPrototype(VM& vm, JSGlobalObject* globalObject)
{
return JSCryptoKeyPrototype::create(vm, globalObject, JSCryptoKeyPrototype::createStructure(vm, globalObject, globalObject->objectPrototype()));
}
JSObject* JSCryptoKey::prototype(VM& vm, JSGlobalObject* globalObject)
{
return getDOMPrototype<JSCryptoKey>(vm, globalObject);
}
void JSCryptoKey::destroy(JSC::JSCell* cell)
{
JSCryptoKey* thisObject = static_cast<JSCryptoKey*>(cell);
thisObject->JSCryptoKey::~JSCryptoKey();
}
EncodedJSValue jsCryptoKeyType(ExecState* state, EncodedJSValue thisValue, PropertyName)
{
VM& vm = state->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
UNUSED_PARAM(thisValue);
JSValue decodedThisValue = JSValue::decode(thisValue);
auto* castedThis = jsDynamicCast<JSCryptoKey*>(decodedThisValue);
if (UNLIKELY(!castedThis)) {
return throwGetterTypeError(*state, throwScope, "CryptoKey", "type");
}
auto& impl = castedThis->wrapped();
JSValue result = jsStringWithCache(state, impl.type());
return JSValue::encode(result);
}
EncodedJSValue jsCryptoKeyExtractable(ExecState* state, EncodedJSValue thisValue, PropertyName)
{
VM& vm = state->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
UNUSED_PARAM(thisValue);
JSValue decodedThisValue = JSValue::decode(thisValue);
auto* castedThis = jsDynamicCast<JSCryptoKey*>(decodedThisValue);
if (UNLIKELY(!castedThis)) {
return throwGetterTypeError(*state, throwScope, "CryptoKey", "extractable");
}
auto& impl = castedThis->wrapped();
JSValue result = jsBoolean(impl.extractable());
return JSValue::encode(result);
}
EncodedJSValue jsCryptoKeyAlgorithm(ExecState* state, EncodedJSValue thisValue, PropertyName)
{
VM& vm = state->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
UNUSED_PARAM(thisValue);
JSValue decodedThisValue = JSValue::decode(thisValue);
auto* castedThis = jsDynamicCast<JSCryptoKey*>(decodedThisValue);
if (UNLIKELY(!castedThis)) {
return throwGetterTypeError(*state, throwScope, "CryptoKey", "algorithm");
}
return JSValue::encode(castedThis->algorithm(*state));
}
EncodedJSValue jsCryptoKeyUsages(ExecState* state, EncodedJSValue thisValue, PropertyName)
{
VM& vm = state->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
UNUSED_PARAM(thisValue);
JSValue decodedThisValue = JSValue::decode(thisValue);
auto* castedThis = jsDynamicCast<JSCryptoKey*>(decodedThisValue);
if (UNLIKELY(!castedThis)) {
return throwGetterTypeError(*state, throwScope, "CryptoKey", "usages");
}
if (JSValue cachedValue = castedThis->m_usages.get())
return JSValue::encode(cachedValue);
auto& impl = castedThis->wrapped();
JSValue result = jsArray(state, castedThis->globalObject(), impl.usages());
castedThis->m_usages.set(state->vm(), castedThis, result);
return JSValue::encode(result);
}
EncodedJSValue jsCryptoKeyConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
{
VM& vm = state->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
JSCryptoKeyPrototype* domObject = jsDynamicCast<JSCryptoKeyPrototype*>(JSValue::decode(thisValue));
if (UNLIKELY(!domObject))
return throwVMTypeError(state, throwScope);
return JSValue::encode(JSCryptoKey::getConstructor(state->vm(), domObject->globalObject()));
}
bool setJSCryptoKeyConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
{
VM& vm = state->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
JSValue value = JSValue::decode(encodedValue);
JSCryptoKeyPrototype* domObject = jsDynamicCast<JSCryptoKeyPrototype*>(JSValue::decode(thisValue));
if (UNLIKELY(!domObject)) {
throwVMTypeError(state, throwScope);
return false;
}
// Shadowing a built-in constructor
return domObject->putDirect(state->vm(), state->propertyNames().constructor, value);
}
JSValue JSCryptoKey::getConstructor(VM& vm, const JSGlobalObject* globalObject)
{
return getDOMConstructor<JSCryptoKeyConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
}
void JSCryptoKey::visitChildren(JSCell* cell, SlotVisitor& visitor)
{
auto* thisObject = jsCast<JSCryptoKey*>(cell);
ASSERT_GC_OBJECT_INHERITS(thisObject, info());
Base::visitChildren(thisObject, visitor);
visitor.append(&thisObject->m_algorithm);
visitor.append(&thisObject->m_usages);
}
bool JSCryptoKeyOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor)
{
auto* jsCryptoKey = jsCast<JSCryptoKey*>(handle.slot()->asCell());
CryptoKey* root = &jsCryptoKey->wrapped();
return visitor.containsOpaqueRoot(root);
}
void JSCryptoKeyOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
{
auto* jsCryptoKey = jsCast<JSCryptoKey*>(handle.slot()->asCell());
auto& world = *static_cast<DOMWrapperWorld*>(context);
uncacheWrapper(world, &jsCryptoKey->wrapped(), jsCryptoKey);
}
JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<CryptoKey>&& impl)
{
return createWrapper<CryptoKey>(globalObject, WTFMove(impl));
}
JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, CryptoKey& impl)
{
return wrap(state, globalObject, impl);
}
CryptoKey* JSCryptoKey::toWrapped(JSC::JSValue value)
{
if (auto* wrapper = jsDynamicCast<JSCryptoKey*>(value))
return &wrapper->wrapped();
return nullptr;
}
}
#endif // ENABLE(SUBTLE_CRYPTO)