1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 06:37:35 +00:00

LibWeb: Propagate errors from CSS Parser construction

This requires Parser to be movable, so we remove the `default`
destructors from Parser and TokenStream, and give them both move
constructors. Since TokenStream only holds a reference to its tokens,
(and it needs to, to avoid copying when given eg a function's contents,)
we add a manual move constructor for Parser which creates a new
TokenStream from the new Parser's tokens, and then manually copies the
old TokenStream's state.
This commit is contained in:
Sam Atkins 2023-03-06 17:17:08 +00:00 committed by Andreas Kling
parent 235018046e
commit ca30914fe9
3 changed files with 47 additions and 22 deletions

View file

@ -1,6 +1,6 @@
/*
* Copyright (c) 2020-2021, the SerenityOS developers.
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
* Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -57,8 +57,9 @@ private:
class Parser {
public:
Parser(ParsingContext const&, StringView input, StringView encoding = "utf-8"sv);
~Parser() = default;
static ErrorOr<Parser> create(ParsingContext const&, StringView input, StringView encoding = "utf-8"sv);
Parser(Parser&&);
CSSStyleSheet* parse_as_css_stylesheet(Optional<AK::URL> location);
ElementInlineCSSStyleDeclaration* parse_as_style_attribute(DOM::Element&);
@ -87,6 +88,8 @@ public:
static RefPtr<CalculatedStyleValue> parse_calculated_value(Badge<StyleComputer>, ParsingContext const&, Vector<ComponentValue> const&);
private:
Parser(ParsingContext const&, Vector<Token>);
enum class ParseError {
IncludesIgnoredVendorPrefix,
SyntaxError,