[webkit-changes] [WebKit/WebKit] 263f75: HashMap::get() / HashMap::take() return invalid Ob...

Chris Dumez noreply at github.com
Sat Oct 12 14:36:45 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 263f7591998f036f63cefd4581e156c809205b0f
      https://github.com/WebKit/WebKit/commit/263f7591998f036f63cefd4581e156c809205b0f
  Author: Chris Dumez <cdumez at apple.com>
  Date:   2024-10-12 (Sat, 12 Oct 2024)

  Changed paths:
    M Source/WTF/wtf/HashMap.h
    M Source/WTF/wtf/ObjectIdentifier.h
    M Source/WebCore/workers/service/server/SWServer.cpp

  Log Message:
  -----------
  HashMap::get() / HashMap::take() return invalid ObjectIdentifiers when the key is missing
https://bugs.webkit.org/show_bug.cgi?id=281306

Reviewed by Darin Adler.

An ObjectIdentifier cannot be invalid/empty, we normally use `std::optional<ObjectIdentifier>`
or `Markable<ObjectIdentifier>` to represent an invalid/empty identifier. The only way to
construct an "empty" ObjectIdentifier is via `HashTraits<ObjectIdentifier>::emptyValue()`,
which HashMap relies on internally. As long as the HashMap is only using this special value
internally, this is fine. However, HashMap::get() and HashMap::take() will return this
invalid "empty" value if the key is not present. This was very error-prone for
ObjectIdentifier since the client would receive an invalid ObjectIdentifier and have no way
to check if the ObjectIdentifier is valid or not (since we assume an ObjectIdentifier is
always valid).

To address the issue, Update HashMap::get() / HashMap::take() to return a std::optional
when the value type is ObjectIdentifier.

* Source/WTF/wtf/HashMap.h:
(WTF::Y>::takeOptional):
* Source/WTF/wtf/ObjectIdentifier.h:
* Source/WebCore/workers/service/server/SWServer.cpp:
(WebCore::SWServer::matchAll):

Canonical link: https://commits.webkit.org/285080@main



To unsubscribe from these emails, change your notification settings at https://github.com/WebKit/WebKit/settings/notifications


More information about the webkit-changes mailing list