
With this change, we now have ~1200 CellAllocators across both LibJS and LibWeb in a normal WebContent instance. This gives us a minimum heap size of 4.7 MiB in the scenario where we only have one cell allocated per type. Of course, in practice there will be many more of each type, so the effective overhead is quite a bit smaller than that in practice. I left a few types unconverted to this mechanism because I got tired of doing this. :^)
67 lines
1.9 KiB
C++
67 lines
1.9 KiB
C++
/*
|
|
* Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibWeb/Bindings/CSSSupportsRulePrototype.h>
|
|
#include <LibWeb/Bindings/Intrinsics.h>
|
|
#include <LibWeb/CSS/CSSSupportsRule.h>
|
|
#include <LibWeb/CSS/Parser/Parser.h>
|
|
|
|
namespace Web::CSS {
|
|
|
|
JS_DEFINE_ALLOCATOR(CSSSupportsRule);
|
|
|
|
JS::NonnullGCPtr<CSSSupportsRule> CSSSupportsRule::create(JS::Realm& realm, NonnullRefPtr<Supports>&& supports, CSSRuleList& rules)
|
|
{
|
|
return realm.heap().allocate<CSSSupportsRule>(realm, realm, move(supports), rules);
|
|
}
|
|
|
|
CSSSupportsRule::CSSSupportsRule(JS::Realm& realm, NonnullRefPtr<Supports>&& supports, CSSRuleList& rules)
|
|
: CSSConditionRule(realm, rules)
|
|
, m_supports(move(supports))
|
|
{
|
|
}
|
|
|
|
void CSSSupportsRule::initialize(JS::Realm& realm)
|
|
{
|
|
Base::initialize(realm);
|
|
set_prototype(&Bindings::ensure_web_prototype<Bindings::CSSSupportsRulePrototype>(realm, "CSSSupportsRule"));
|
|
}
|
|
|
|
String CSSSupportsRule::condition_text() const
|
|
{
|
|
return m_supports->to_string();
|
|
}
|
|
|
|
void CSSSupportsRule::set_condition_text(String const& text)
|
|
{
|
|
if (auto new_supports = parse_css_supports(Parser::ParsingContext { realm() }, text))
|
|
m_supports = new_supports.release_nonnull();
|
|
}
|
|
|
|
// https://www.w3.org/TR/cssom-1/#serialize-a-css-rule
|
|
DeprecatedString CSSSupportsRule::serialized() const
|
|
{
|
|
// Note: The spec doesn't cover this yet, so I'm roughly following the spec for the @media rule.
|
|
// It should be pretty close!
|
|
|
|
StringBuilder builder;
|
|
|
|
builder.append("@supports "sv);
|
|
builder.append(condition_text());
|
|
builder.append(" {\n"sv);
|
|
for (size_t i = 0; i < css_rules().length(); i++) {
|
|
auto rule = css_rules().item(i);
|
|
if (i != 0)
|
|
builder.append("\n"sv);
|
|
builder.append(" "sv);
|
|
builder.append(rule->css_text());
|
|
}
|
|
builder.append("\n}"sv);
|
|
|
|
return builder.to_deprecated_string();
|
|
}
|
|
|
|
}
|