1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-15 08:04:59 +00:00
serenity/Userland/Libraries/LibWeb/Crypto/CryptoBindings.cpp
stelar7 3e0c0ce7ae LibWeb: Move dictionaries to separate file
Co-Authored-By: Andrew Kaster <akaster@serenityos.org>
2024-01-23 14:07:06 -07:00

53 lines
1.5 KiB
C++

/*
* Copyright (c) 2023, stelar7 <dudedbz@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibJS/Runtime/AbstractOperations.h>
#include <LibJS/Runtime/GlobalObject.h>
#include <LibWeb/Bindings/ExceptionOrUtils.h>
#include <LibWeb/Crypto/CryptoBindings.h>
namespace Web::Bindings {
JS_DEFINE_ALLOCATOR(KeyAlgorithm);
JS::NonnullGCPtr<KeyAlgorithm> KeyAlgorithm::create(JS::Realm& realm)
{
return realm.heap().allocate<KeyAlgorithm>(realm, realm);
}
KeyAlgorithm::KeyAlgorithm(JS::Realm& realm)
: Object(ConstructWithPrototypeTag::Tag, realm.intrinsics().object_prototype())
{
}
void KeyAlgorithm::initialize(JS::Realm& realm)
{
define_native_accessor(realm, "name", name_getter, {}, JS::Attribute::Enumerable | JS::Attribute::Configurable);
Base::initialize(realm);
}
static JS::ThrowCompletionOr<KeyAlgorithm*> impl_from(JS::VM& vm)
{
auto this_value = vm.this_value();
JS::Object* this_object = nullptr;
if (this_value.is_nullish())
this_object = &vm.current_realm()->global_object();
else
this_object = TRY(this_value.to_object(vm));
if (!is<KeyAlgorithm>(this_object))
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "KeyAlgorithm");
return static_cast<KeyAlgorithm*>(this_object);
}
JS_DEFINE_NATIVE_FUNCTION(KeyAlgorithm::name_getter)
{
auto* impl = TRY(impl_from(vm));
auto name = TRY(throw_dom_exception_if_needed(vm, [&] { return impl->name(); }));
return JS::PrimitiveString::create(vm, name);
}
}