Skip to content

Commit

Permalink
Some code incorrectly compares Document objects using CSSParserContex…
Browse files Browse the repository at this point in the history
…t's comparison operator

https://bugs.webkit.org/show_bug.cgi?id=261044

Reviewed by Ryosuke Niwa and Darin Adler.

Use a named operator==() in CSSParserContext to avoid so that can no longer
happen and fix code doing bad comparisons.

* Source/WebCore/css/parser/CSSParserContext.cpp:
(WebCore::operator==): Deleted.
* Source/WebCore/css/parser/CSSParserContext.h:
* Source/WebCore/editing/cocoa/EditorCocoa.mm:
(WebCore::Editor::replaceNodeFromPasteboard):
* Source/WebCore/html/HTMLElement.cpp:
(WebCore::checkPopoverValidity):
* Source/WebCore/page/csp/ContentSecurityPolicy.cpp:
(WebCore::ContentSecurityPolicy::reportViolation const):

Canonical link: https://commits.webkit.org/267577@main
  • Loading branch information
cdumez committed Sep 2, 2023
1 parent 9dc842e commit 1dc257f
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 45 deletions.
40 changes: 0 additions & 40 deletions Source/WebCore/css/parser/CSSParserContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,46 +109,6 @@ CSSParserContext::CSSParserContext(const Document& document, const URL& sheetBas
{
}

bool operator==(const CSSParserContext& a, const CSSParserContext& b)
{
return a.baseURL == b.baseURL
&& a.charset == b.charset
&& a.mode == b.mode
&& a.enclosingRuleType == b.enclosingRuleType
&& a.isHTMLDocument == b.isHTMLDocument
&& a.hasDocumentSecurityOrigin == b.hasDocumentSecurityOrigin
&& a.isContentOpaque == b.isContentOpaque
&& a.useSystemAppearance == b.useSystemAppearance
&& a.shouldIgnoreImportRules == b.shouldIgnoreImportRules
&& a.colorContrastEnabled == b.colorContrastEnabled
&& a.colorMixEnabled == b.colorMixEnabled
&& a.constantPropertiesEnabled == b.constantPropertiesEnabled
&& a.counterStyleAtRuleImageSymbolsEnabled == b.counterStyleAtRuleImageSymbolsEnabled
&& a.cssColor4 == b.cssColor4
&& a.relativeColorSyntaxEnabled == b.relativeColorSyntaxEnabled
&& a.springTimingFunctionEnabled == b.springTimingFunctionEnabled
#if ENABLE(CSS_TRANSFORM_STYLE_OPTIMIZED_3D)
&& a.transformStyleOptimized3DEnabled == b.transformStyleOptimized3DEnabled
#endif
&& a.useLegacyBackgroundSizeShorthandBehavior == b.useLegacyBackgroundSizeShorthandBehavior
&& a.focusVisibleEnabled == b.focusVisibleEnabled
&& a.hasPseudoClassEnabled == b.hasPseudoClassEnabled
&& a.cascadeLayersEnabled == b.cascadeLayersEnabled
&& a.overflowClipEnabled == b.overflowClipEnabled
&& a.gradientPremultipliedAlphaInterpolationEnabled == b.gradientPremultipliedAlphaInterpolationEnabled
&& a.gradientInterpolationColorSpacesEnabled == b.gradientInterpolationColorSpacesEnabled
&& a.subgridEnabled == b.subgridEnabled
&& a.masonryEnabled == b.masonryEnabled
&& a.cssNestingEnabled == b.cssNestingEnabled
&& a.cssPaintingAPIEnabled == b.cssPaintingAPIEnabled
&& a.cssTextUnderlinePositionLeftRightEnabled == b.cssTextUnderlinePositionLeftRightEnabled
&& a.cssTextWrapNewValuesEnabled == b.cssTextWrapNewValuesEnabled
&& a.cssWordBreakAutoEnabled == b.cssWordBreakAutoEnabled
&& a.sidewaysWritingModesEnabled == b.sidewaysWritingModesEnabled
&& a.propertySettings == b.propertySettings
;
}

void add(Hasher& hasher, const CSSParserContext& context)
{
uint64_t bits = context.isHTMLDocument << 0
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/css/parser/CSSParserContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ struct CSSParserContext {
CSSParserContext(CSSParserMode, const URL& baseURL = URL());
WEBCORE_EXPORT CSSParserContext(const Document&, const URL& baseURL = URL(), const String& charset = emptyString());
ResolvedURL completeURL(const String&) const;
};

bool operator==(const CSSParserContext&, const CSSParserContext&);
bool operator==(const CSSParserContext&) const = default;
};

void add(Hasher&, const CSSParserContext&);

Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/editing/cocoa/EditorCocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ static void maybeCopyNodeAttributesToFragment(const Node& node, DocumentFragment

void Editor::replaceNodeFromPasteboard(Node& node, const String& pasteboardName, EditAction action)
{
if (node.document() != m_document)
if (&node.document() != &m_document)
return;

auto range = makeRangeSelectingNode(node);
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/html/HTMLElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1249,7 +1249,7 @@ static ExceptionOr<bool> checkPopoverValidity(HTMLElement& element, PopoverVisib
if (!element.isConnected())
return Exception { InvalidStateError, "Element is not connected"_s };

if (expectedDocument && element.document() != *expectedDocument)
if (expectedDocument && &element.document() != expectedDocument)
return Exception { InvalidStateError, "Invalid when the document changes while showing or hiding a popover element"_s };

if (is<HTMLDialogElement>(element) && downcast<HTMLDialogElement>(element).isModal())
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/page/csp/ContentSecurityPolicy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ void ContentSecurityPolicy::reportViolation(const String& effectiveViolatedDirec
m_client->enqueueSecurityPolicyViolationEvent(WTFMove(violationEventInit));
else {
auto& document = downcast<Document>(*m_scriptExecutionContext);
if (element && element->document() == document)
if (element && &element->document() == &document)
element->enqueueSecurityPolicyViolationEvent(WTFMove(violationEventInit));
else
document.enqueueSecurityPolicyViolationEvent(WTFMove(violationEventInit));
Expand Down

0 comments on commit 1dc257f

Please sign in to comment.