[webkit-reviews] review granted: [Bug 224426] Make FontFace parsing worker-safe : [Attachment 426012] Patch

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Wed Apr 14 11:42:26 PDT 2021


Darin Adler <darin at apple.com> has granted Chris Lord <clord at igalia.com>'s
request for review:
Bug 224426: Make FontFace parsing worker-safe
https://bugs.webkit.org/show_bug.cgi?id=224426

Attachment 426012: Patch

https://bugs.webkit.org/attachment.cgi?id=426012&action=review




--- Comment #4 from Darin Adler <darin at apple.com> ---
Comment on attachment 426012
  --> https://bugs.webkit.org/attachment.cgi?id=426012
Patch

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

I think just "pool" or "valuePool" is a fine name for arguments or variables of
type CSSValuePool.

> Source/WebCore/ChangeLog:11
> +	   new CSSPropertyParserWorkerSafe and make sure they're safe to use in
a

Not 100% thrilled with the name "WorkerSafe". I feel about as good about it as
the term "ThreadSafe"; both seem insufficiently precise concepts to me.

To make this all win/win, and not *just* about fonts in onscreen canvas, it
would be great to make sure these separate property parsers are easy to use in
other cases too. Firing up the full CSS parser to parse once specific property
might be an unwanted pattern elsewhere too, unnecessarily inefficient for some
uses.

> Source/WebCore/css/FontFace.cpp:84
> -	       auto value = FontFace::parseString(string, CSSPropertySrc);
> -	       if (!is<CSSValueList>(value))
> -		   return Exception { SyntaxError };
> -	       CSSFontFace::appendSources(result->backing(),
downcast<CSSValueList>(*value), &document, false);
> -	       return { };
> +	       if (auto value =
CSSPropertyParserWorkerSafe::parseFontFaceSrc(string,
CSSParserContext(document))) {
> +		   CSSFontFace::appendSources(result->backing(), *value,
&document, false);
> +		   return { };
> +	       }
> +	       return Exception { SyntaxError };

Better: Guarding a local variable with a if.
Worse: Making the failure case the "main code" and the success case the guarded
block. There’s a clarity reason we prefer early return; too bad it’s
incompatible with guarding locals with if.

The call to CSSPropertyParserWorkerSafe::parseFontFaceSrc is so much more
verbose than the FontFace::parseString call with a really long class name. And
also, the need to explicitly write out CSSParserContext. Is there some way we
can keep this idiom a little simpler?

> Source/WebCore/css/FontFace.cpp:178
> +    if (familyNameToUse.contains('\'') && is<Document>(context) &&
downcast<Document>(context).quirks().shouldStripQuotationMarkInFontFaceSetFamil
y())

Seems like code running in workers will need quirks too, eventually, for the
same reason we need them for documents. Probably should inherit them from the
document it’s created from. This code change here is a stopgap measure.

> Source/WebCore/css/FontFace.cpp:196
> -    if (auto value = parseString(style, CSSPropertyFontStyle)) {
> +    if (auto value = CSSPropertyParserWorkerSafe::parseFontFaceStyle(style,
HTMLStandardMode, context.cssValuePool())) {

Frustrating that this code gets so verbose. Any way to cut down on the
arguments?

> Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:100
> +    explicit CalcParser(CSSParserTokenRange& range, CalculationCategory
destinationCategory, ValueRange valueRange = ValueRangeAll, CSSValuePool&
cssValuePool = CSSValuePool::singleton())

This argument name does not need "css" in it.

> Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:203
> +    CSSValuePool& m_cssValuePool;

This member name does not need "css" in it.

> Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:431
> +RefPtr<CSSPrimitiveValue> consumePercentWorkerSafe(CSSParserTokenRange&
range, ValueRange valueRange, CSSValuePool& cssValuePool)

This argument name does not need "css" in it.

> Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:536
>  RefPtr<CSSPrimitiveValue> consumeAngle(CSSParserTokenRange& range,
CSSParserMode cssParserMode, UnitlessQuirk unitless, UnitlessZeroQuirk
unitlessZero)

This argument name does not need "css" in it.

> Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:541
> +RefPtr<CSSPrimitiveValue> consumeAngleWorkerSafe(CSSParserTokenRange& range,
CSSParserMode cssParserMode, CSSValuePool& cssValuePool, UnitlessQuirk
unitless, UnitlessZeroQuirk unitlessZero)

This argument name does not need "css" in it.

> Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:649
> +RefPtr<CSSPrimitiveValue> consumeIdentWorkerSafe(CSSParserTokenRange& range,
CSSValuePool& cssValuePool)

This argument name does not need "css" in it.

> Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:3023
> +Optional<FontRaw> consumeFontRaw(CSSParserTokenRange& range, CSSParserMode
cssParserMode)

This argument name does not need "css" in it.

> Source/WebCore/css/parser/CSSPropertyParserWorkerSafe.cpp:50
> +using namespace CSSPropertyParserHelpers;
> +using namespace CSSPropertyParserHelpersWorkerSafe;

We should typically strive to avoid these kinds of "using namespace".

I’m not sure what the namespaces achieve exactly, so I’m not sure what to
recommend.

> Source/WebCore/css/parser/CSSPropertyParserWorkerSafe.cpp:52
> +Optional<FontRaw> CSSPropertyParserWorkerSafe::parseFont(const String&
string, CSSParserMode cssParserMode)

This argument name does not need "css" in it.

> Source/WebCore/css/parser/CSSPropertyParserWorkerSafe.cpp:87
> +RefPtr<CSSValue> CSSPropertyParserWorkerSafe::parseFontFaceStyle(const
String& string, const CSSParserContext& context, CSSValuePool& cssValuePool)

This argument name does not need "css" in it.

> Source/WebCore/css/parser/CSSPropertyParserWorkerSafe.cpp:106
> +RefPtr<CSSValue> CSSPropertyParserWorkerSafe::parseFontFaceWeight(const
String& string, const CSSParserContext& context, CSSValuePool& cssValuePool)

This argument name does not need "css" in it.

> Source/WebCore/css/parser/CSSPropertyParserWorkerSafe.cpp:125
> +RefPtr<CSSValue> CSSPropertyParserWorkerSafe::parseFontFaceStretch(const
String& string, const CSSParserContext& context, CSSValuePool& cssValuePool)

This argument name does not need "css" in it.

> Source/WebCore/css/parser/CSSPropertyParserWorkerSafe.cpp:144
> +RefPtr<CSSValue>
CSSPropertyParserWorkerSafe::parseFontFaceUnicodeRange(const String& string,
const CSSParserContext& context)

This argument name does not need "css" in it.

> Source/WebCore/css/parser/CSSPropertyParserWorkerSafe.cpp:158
> +RefPtr<CSSValue>
CSSPropertyParserWorkerSafe::parseFontFaceFeatureSettings(const String& string,
const CSSParserContext& context, CSSValuePool& cssValuePool)

This argument name does not need "css" in it.

> Source/WebCore/css/parser/CSSPropertyParserWorkerSafe.cpp:172
> +RefPtr<CSSValue> CSSPropertyParserWorkerSafe::parseFontFaceDisplay(const
String& string, const CSSParserContext& context, CSSValuePool& cssValuePool)

This argument name does not need "css" in it.

> Source/WebCore/css/parser/CSSPropertyParserWorkerSafe.cpp:186
> +namespace CSSPropertyParserHelpersWorkerSafe {

Not sure why we need a namespace here.

> Source/WebCore/css/parser/CSSPropertyParserWorkerSafe.cpp:248
> +RefPtr<CSSFontStyleValue> consumeFontStyle(CSSParserTokenRange& range,
CSSParserMode cssParserMode, CSSValuePool& cssValuePool)

These argument names do not need "css" in them.

> Source/WebCore/css/parser/CSSPropertyParserWorkerSafe.cpp:263
> +static RefPtr<CSSPrimitiveValue>
consumeFontStyleKeywordValue(CSSParserTokenRange& range, CSSValuePool&
cssValuePool)

This argument name does not need "css" in it.

> Source/WebCore/css/parser/CSSPropertyParserWorkerSafe.cpp:268
> +RefPtr<CSSFontStyleRangeValue> consumeFontStyleRange(CSSParserTokenRange&
range, CSSParserMode cssParserMode, CSSValuePool& cssValuePool)

These argument names do not need "css" in them.

> Source/WebCore/css/parser/CSSPropertyParserWorkerSafe.cpp:305
> +static RefPtr<CSSPrimitiveValue>
consumeFontWeightAbsoluteKeywordValue(CSSParserTokenRange& range, CSSValuePool&
cssValuePool)

This argument name does not need "css" in it.

> Source/WebCore/css/parser/CSSPropertyParserWorkerSafe.cpp:311
> +RefPtr<CSSValue> consumeFontWeightAbsoluteRange(CSSParserTokenRange& range,
CSSValuePool& cssValuePool)

This argument name does not need "css" in it.

> Source/WebCore/css/parser/CSSPropertyParserWorkerSafe.cpp:329
> +RefPtr<CSSPrimitiveValue> consumeFontWeightAbsolute(CSSParserTokenRange&
range, CSSValuePool& cssValuePool)

This argument name does not need "css" in it.

> Source/WebCore/css/parser/CSSPropertyParserWorkerSafe.cpp:337
> +RefPtr<CSSPrimitiveValue>
consumeFontStretchKeywordValue(CSSParserTokenRange& range, CSSValuePool&
cssValuePool)

This argument name does not need "css" in it.

> Source/WebCore/css/parser/CSSPropertyParserWorkerSafe.cpp:351
> +RefPtr<CSSPrimitiveValue> consumeFontStretch(CSSParserTokenRange& range,
CSSValuePool& cssValuePool)

This argument name does not need "css" in it.

> Source/WebCore/css/parser/CSSPropertyParserWorkerSafe.cpp:363
> +RefPtr<CSSValue> consumeFontStretchRange(CSSParserTokenRange& range,
CSSValuePool& cssValuePool)

This argument name does not need "css" in it.

> Source/WebCore/css/parser/CSSPropertyParserWorkerSafe.cpp:435
> +RefPtr<CSSValue> consumeFontFeatureSettings(CSSParserTokenRange& range,
CSSValuePool& cssValuePool)

This argument name does not need "css" in it.

> Source/WebCore/css/parser/CSSPropertyParserWorkerSafe.cpp:449
> +RefPtr<CSSPrimitiveValue> consumeFontFaceFontDisplay(CSSParserTokenRange&
range, CSSValuePool& cssValuePool)

This argument name does not need "css" in it.

> Source/WebCore/css/parser/CSSPropertyParserWorkerSafe.h:42
> +namespace CSSPropertyParserHelpers {

Not sure why this needs to go in a namespace.

> Source/WebCore/css/parser/CSSPropertyParserWorkerSafe.h:60
> +namespace CSSPropertyParserHelpersWorkerSafe {

Not sure why these need to go in a namespace.

> Source/WebCore/css/parser/CSSPropertyParserWorkerSafe.h:76
> +#if ENABLE(VARIATION_FONTS)
> +RefPtr<CSSFontStyleRangeValue> consumeFontStyleRange(CSSParserTokenRange&,
CSSParserMode, CSSValuePool&);
> +RefPtr<CSSValue> consumeFontWeightAbsoluteRange(CSSParserTokenRange&,
CSSValuePool&);
> +RefPtr<CSSValue> consumeFontStretchRange(CSSParserTokenRange&,
CSSValuePool&);
> +#endif
> +#if !ENABLE(VARIATION_FONTS)
> +RefPtr<CSSPrimitiveValue> consumeFontWeightAbsolute(CSSParserTokenRange&,
CSSValuePool&);
> +#endif

Some blank lines would make the paragraphing easier to read I think.

> Source/WebCore/dom/ScriptExecutionContext.cpp:240
> +CSSValuePool& ScriptExecutionContext::cssValuePool()
> +{
> +    return CSSValuePool::singleton();
> +}

Maybe this should go in Document and it should be pure virtual in
ScriptExecutionContext?

> Source/WebCore/dom/ScriptExecutionContext.h:171
> +    virtual CSSValuePool& cssValuePool();

Not sure I fully understand why each script execution context has its own CSS
value pool.


More information about the webkit-reviews mailing list