Bug 239483

Summary: Implement most of CSS typed OM object stringifiers
Product: WebKit Reporter: Alex Christensen <achristensen>
Component: New BugsAssignee: Alex Christensen <achristensen>
Status: RESOLVED FIXED    
Severity: Normal CC: esprehn+autocc, ews-watchlist, glenn, gyuyoung.kim, macpherson, menard, sam, simon.fraser, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=239529
Attachments:
Description Flags
Patch
none
Patch
none
Patch none

Description Alex Christensen 2022-04-18 23:20:04 PDT
Implement most of CSS typed OM object stringifiers
Comment 1 Alex Christensen 2022-04-18 23:22:09 PDT
Created attachment 457859 [details]
Patch
Comment 2 Alex Christensen 2022-04-19 11:20:02 PDT
Comment on attachment 457859 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=457859&action=review

> LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-serialization/cssTransformValue.tentative-expected.txt:13
> +FAIL CSSPerspective with negative length serializes correctly assert_equals: expected "perspective(calc(-1px))" but got "perspective(-1px)"

Filed https://github.com/w3c/css-houdini-drafts/issues/1069 about this test.
Comment 3 Alex Christensen 2022-04-19 12:37:05 PDT
Created attachment 457930 [details]
Patch
Comment 4 Simon Fraser (smfr) 2022-04-19 15:23:47 PDT
Comment on attachment 457930 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=457930&action=review

> Source/WebCore/css/typedom/CSSOMVariableReferenceValue.cpp:64
> +    serialize(builder, false, false);

Can we use an OptionSet<> instead of two bools? Hard to know what false, false mean here.

> Source/WebCore/css/typedom/numeric/CSSMathInvert.cpp:79
> +    if (!withoutParentheses)

Double negative makes my brain hurt.
Comment 5 Alex Christensen 2022-04-19 16:25:40 PDT
Created attachment 457941 [details]
Patch
Comment 6 EWS 2022-04-19 17:46:37 PDT
Committed r293052 (249787@main): <https://commits.webkit.org/249787@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 457941 [details].
Comment 7 Radar WebKit Bug Importer 2022-04-19 17:47:14 PDT
<rdar://problem/91997078>
Comment 8 Sam Weinig 2022-04-19 18:14:59 PDT
Comment on attachment 457930 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=457930&action=review

> Source/WebCore/css/typedom/CSSStyleValue.h:106
> +    virtual void serialize(StringBuilder&, bool nested = false, bool withoutParentheses = false) const;

I think these bools would be better as an OptionSet (SerializationOptions?). We generally shy away from bool arguments these unless it is clear at call sites what is happening.

> Source/WebCore/css/typedom/CSSUnitValue.cpp:117
> +    builder.append(FormattedCSSNumber::create(m_value));
> +    builder.append(unitSerialization());

This can all be in one call:

builder.append(FormattedCSSNumber::create(m_value), unitSerialization());

This is also not a very efficient way to implement this as it is doing unnecessary temporary string allocation. It would be better to have StringTypeAdapters for these types. (For an example, see ColorSerialization.cpp)
Comment 9 Alex Christensen 2022-04-19 18:55:06 PDT
Comment on attachment 457941 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=457941&action=review

> Source/WebCore/css/typedom/CSSUnitValue.cpp:117
> +    builder.append(unitSerialization());

I agree this can be optimized to reduce String allocations, but I think that should be done by fixing the FIXME at the definition of CSSPrimitiveValue::unitTypeString and making it return a const char*
Comment 10 Sam Weinig 2022-04-19 19:24:01 PDT
(In reply to Alex Christensen from comment #9)
> Comment on attachment 457941 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=457941&action=review
> 
> > Source/WebCore/css/typedom/CSSUnitValue.cpp:117
> > +    builder.append(unitSerialization());
> 
> I agree this can be optimized to reduce String allocations, but I think that
> should be done by fixing the FIXME at the definition of
> CSSPrimitiveValue::unitTypeString and making it return a const char*

Ok. Or an ASCIILiteral would be good too.

I would also think we should rename FormattedCSSNumber::create(). create() has the connotation in our source base that it will allocate something, and that should just be a normal constructor (or a free function called formattedCSSNumber() like pad().