Skip to content

Commit

Permalink
fix: fix crash due to css property parser.
Browse files Browse the repository at this point in the history
  • Loading branch information
andycall committed Sep 27, 2024
1 parent ed6c05e commit 6a8b126
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 20 deletions.
7 changes: 7 additions & 0 deletions bridge/core/css/css_value_pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@

namespace webf {

CSSValuePool::CSSValuePool() {
identifier_value_cache_.reserve(kMaximumCacheableIntegerValue);
pixel_value_cache_.reserve(kMaximumCacheableIntegerValue);
percent_value_cache_.reserve(kMaximumCacheableIntegerValue);
number_value_cache_.reserve(kMaximumCacheableIntegerValue);
}

CSSValuePool& CssValuePool() {
thread_local static CSSValuePool pool;
return pool;
Expand Down
28 changes: 14 additions & 14 deletions bridge/core/css/css_value_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class CSSValuePool {
public:
using PassKey = webf::PassKey<CSSValuePool>;

CSSValuePool();

static const int kMaximumCacheableIntegerValue = 255;
using CSSColor = cssvalue::CSSColor;
using CSSUnsetValue = cssvalue::CSSUnsetValue;
Expand All @@ -80,21 +82,20 @@ class CSSValuePool {
// CSSValuePool& operator=(const CSSValuePool&) = delete;
//
// // Cached individual values.
std::shared_ptr<const CSSColor> TransparentColor() const { return color_transparent_; }
std::shared_ptr<const CSSColor> WhiteColor() const { return color_white_; }
std::shared_ptr<const CSSColor> BlackColor() const { return color_black_; }
std::shared_ptr<const CSSInheritedValue> InheritedValue() { return inherited_value_; }
std::shared_ptr<const CSSInitialValue> InitialValue() const { return initial_value_; }
std::shared_ptr<const CSSInitialValue> InitialSharedPointerValue() const { return initial_value_; }
std::shared_ptr<const CSSUnsetValue> const UnsetValue() { return unset_value_; }
std::shared_ptr<const CSSRevertValue> const RevertValue() { return revert_value_; }
std::shared_ptr<const CSSRevertLayerValue> const RevertLayerValue() { return revert_layer_value_; }
std::shared_ptr<const CSSInvalidVariableValue> const InvalidVariableValue() { return invalid_variable_value_; }
// CSSCyclicVariableValue* CyclicVariableValue() { return cyclic_variable_value_.get(); }
std::shared_ptr<const CSSInitialColorValue> const InitialColorValue() { return initial_color_value_; }
const std::shared_ptr<const CSSColor>& TransparentColor() const { return color_transparent_; }
const std::shared_ptr<const CSSColor>& WhiteColor() const { return color_white_; }
const std::shared_ptr<const CSSColor>& BlackColor() const { return color_black_; }
const std::shared_ptr<const CSSInheritedValue>& InheritedValue() { return inherited_value_; }
const std::shared_ptr<const CSSInitialValue>& InitialValue() const { return initial_value_; }
const std::shared_ptr<const CSSInitialValue>& InitialSharedPointerValue() const { return initial_value_; }
const std::shared_ptr<const CSSUnsetValue>& UnsetValue() { return unset_value_; }
const std::shared_ptr<const CSSRevertValue>& RevertValue() { return revert_value_; }
const std::shared_ptr<const CSSRevertLayerValue>& RevertLayerValue() { return revert_layer_value_; }
const std::shared_ptr<const CSSInvalidVariableValue>& InvalidVariableValue() { return invalid_variable_value_; }
const std::shared_ptr<const CSSInitialColorValue>& InitialColorValue() { return initial_color_value_; }

// Vector caches.
std::shared_ptr<const CSSIdentifierValue> IdentifierCacheValue(CSSValueID ident) {
const std::shared_ptr<const CSSIdentifierValue>& IdentifierCacheValue(CSSValueID ident) {
return identifier_value_cache_[static_cast<int>(ident)];
}
std::shared_ptr<const CSSIdentifierValue> SetIdentifierCacheValue(
Expand Down Expand Up @@ -183,7 +184,6 @@ class CSSValuePool {
std::shared_ptr<const CSSRevertValue> revert_value_;
std::shared_ptr<const CSSRevertLayerValue> revert_layer_value_;
std::shared_ptr<const CSSInvalidVariableValue> invalid_variable_value_;
// Member<CSSCyclicVariableValue> cyclic_variable_value_;
std::shared_ptr<const CSSInitialColorValue> initial_color_value_;
std::shared_ptr<const CSSColor> color_transparent_;
std::shared_ptr<const CSSColor> color_white_;
Expand Down
2 changes: 1 addition & 1 deletion bridge/core/css/parser/css_parser_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ void CSSParserImpl::ConsumeDeclarationValue(CSSParserTokenStream& stream,
StyleRule::RuleType rule_type) {
const bool allow_important_annotation =
is_in_declaration_list && rule_type != StyleRule::kKeyframe && rule_type != StyleRule::kPositionTry;
CSSPropertyParser::ParseValue(unresolved_property, allow_important_annotation, stream, context_.get(),
CSSPropertyParser::ParseValue(unresolved_property, allow_important_annotation, stream, context_,
parsed_properties_, rule_type);
}

Expand Down
4 changes: 2 additions & 2 deletions bridge/core/css/parser/css_property_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ bool IsPropertyAllowedInRule(const CSSProperty& property, StyleRule::RuleType ru
} // namespace

CSSPropertyParser::CSSPropertyParser(CSSParserTokenStream& stream,
const CSSParserContext* context,
std::shared_ptr<const CSSParserContext> context,
std::vector<CSSPropertyValue>* parsed_properties)
: stream_(stream), context_(context), parsed_properties_(parsed_properties) {
// Strip initial whitespace/comments from stream_.
Expand Down Expand Up @@ -218,7 +218,7 @@ bool CSSPropertyParser::ParseValueStart(webf::CSSPropertyID unresolved_property,
bool CSSPropertyParser::ParseValue(CSSPropertyID unresolved_property,
bool allow_important_annotation,
CSSParserTokenStream& stream,
const CSSParserContext* context,
std::shared_ptr<const CSSParserContext> context,
std::vector<CSSPropertyValue>& parsed_properties,
StyleRule::RuleType rule_type) {
CSSPropertyParser parser(stream, context, &parsed_properties);
Expand Down
4 changes: 2 additions & 2 deletions bridge/core/css/parser/css_property_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class CSSPropertyParser {
static bool ParseValue(CSSPropertyID,
bool allow_important_annotation,
CSSParserTokenStream&,
const CSSParserContext*,
std::shared_ptr<const CSSParserContext>,
std::vector<CSSPropertyValue>&,
StyleRule::RuleType);

Expand All @@ -85,7 +85,7 @@ class CSSPropertyParser {

private:
CSSPropertyParser(CSSParserTokenStream&,
const CSSParserContext*,
std::shared_ptr<const CSSParserContext>,
std::vector<CSSPropertyValue>*);

// TODO(timloh): Rename once the CSSParserValue-based parseValue is removed
Expand Down
2 changes: 1 addition & 1 deletion bridge/core/css/style_element.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ StyleElement::ProcessingResult StyleElement::CreateSheet(Element& element, const

loading_ = true;

auto* new_sheet = document.EnsureStyleEngine().CreateSheet(element, text);//
auto* new_sheet = document.EnsureStyleEngine().CreateSheet(element, text);
sheet_ = new_sheet;

return kProcessingSuccessful;
Expand Down

0 comments on commit 6a8b126

Please sign in to comment.