mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 22:47:44 +00:00
LibWeb: Make CSSStyleDeclaration GC-allocated
This commit is contained in:
parent
12042f0757
commit
72bacba97b
18 changed files with 146 additions and 129 deletions
|
@ -1,62 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibJS/Runtime/Completion.h>
|
||||
#include <LibWeb/Bindings/CSSStyleDeclarationWrapper.h>
|
||||
#include <LibWeb/DOM/Element.h>
|
||||
|
||||
namespace Web::Bindings {
|
||||
|
||||
static CSS::PropertyID property_id_from_name(StringView name)
|
||||
{
|
||||
// FIXME: Perhaps this should go in the code generator.
|
||||
if (name == "cssFloat"sv)
|
||||
return CSS::PropertyID::Float;
|
||||
|
||||
if (auto property_id = CSS::property_id_from_camel_case_string(name); property_id != CSS::PropertyID::Invalid)
|
||||
return property_id;
|
||||
|
||||
if (auto property_id = CSS::property_id_from_string(name); property_id != CSS::PropertyID::Invalid)
|
||||
return property_id;
|
||||
|
||||
return CSS::PropertyID::Invalid;
|
||||
}
|
||||
|
||||
JS::ThrowCompletionOr<bool> CSSStyleDeclarationWrapper::internal_has_property(JS::PropertyKey const& name) const
|
||||
{
|
||||
if (!name.is_string())
|
||||
return Base::internal_has_property(name);
|
||||
return property_id_from_name(name.to_string()) != CSS::PropertyID::Invalid;
|
||||
}
|
||||
|
||||
JS::ThrowCompletionOr<JS::Value> CSSStyleDeclarationWrapper::internal_get(JS::PropertyKey const& name, JS::Value receiver) const
|
||||
{
|
||||
if (!name.is_string())
|
||||
return Base::internal_get(name, receiver);
|
||||
auto property_id = property_id_from_name(name.to_string());
|
||||
if (property_id == CSS::PropertyID::Invalid)
|
||||
return Base::internal_get(name, receiver);
|
||||
if (auto maybe_property = impl().property(property_id); maybe_property.has_value())
|
||||
return { js_string(vm(), maybe_property->value->to_string()) };
|
||||
return { js_string(vm(), String::empty()) };
|
||||
}
|
||||
|
||||
JS::ThrowCompletionOr<bool> CSSStyleDeclarationWrapper::internal_set(JS::PropertyKey const& name, JS::Value value, JS::Value receiver)
|
||||
{
|
||||
if (!name.is_string())
|
||||
return Base::internal_set(name, value, receiver);
|
||||
auto& vm = this->vm();
|
||||
auto property_id = property_id_from_name(name.to_string());
|
||||
if (property_id == CSS::PropertyID::Invalid)
|
||||
return Base::internal_set(name, value, receiver);
|
||||
|
||||
auto css_text = TRY(value.to_string(vm));
|
||||
|
||||
impl().set_property(property_id, css_text);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -14,7 +14,6 @@
|
|||
#include <LibJS/Runtime/Shape.h>
|
||||
#include <LibTextCodec/Decoder.h>
|
||||
#include <LibWeb/Bindings/CSSNamespace.h>
|
||||
#include <LibWeb/Bindings/CSSStyleDeclarationWrapper.h>
|
||||
#include <LibWeb/Bindings/CryptoWrapper.h>
|
||||
#include <LibWeb/Bindings/DocumentWrapper.h>
|
||||
#include <LibWeb/Bindings/ElementWrapper.h>
|
||||
|
@ -526,7 +525,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::get_computed_style)
|
|||
if (!is<ElementWrapper>(object))
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "DOM element");
|
||||
|
||||
return wrap(realm, impl->get_computed_style(static_cast<ElementWrapper*>(object)->impl()));
|
||||
return wrap(realm, *impl->get_computed_style(static_cast<ElementWrapper*>(object)->impl()));
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(WindowObject::get_selection)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue