Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 90bb9d02b08e21cce5f0d88506febb34275855a1
      
https://github.com/WebKit/WebKit/commit/90bb9d02b08e21cce5f0d88506febb34275855a1
  Author: Adrian Taylor <[email protected]>
  Date:   2026-08-10 (Mon, 10 Aug 2026)

  Changed paths:
    M Source/WTF/wtf/Borrow.h
    M Source/WTF/wtf/BorrowedBytes.h
    M Source/WebCore/PAL/pal/crypto/WTFExtras.swift
    M Tools/TestWebKitAPI/CMakeLists.txt
    M Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
    A Tools/TestWebKitAPI/Tests/WTF/Borrow.cpp
    M Tools/TestWebKitAPI/Tests/WTF/BorrowedBytes.cpp

  Log Message:
  -----------
  Fix Borrow and BorrowedBytes bugs
https://bugs.webkit.org/show_bug.cgi?id=321171
rdar://184218933

Reviewed by Geoffrey Garen.

WTF::Borrow and WTF::BorrowedBytes are primitives to allow dynamically-checked
borrowing of things across the C++/Swift language boundary.

This commit fixes bugs in each.

* BorrowedBytes had a debug-only range check, which is now release mode too.
* In Borrow, there was an assertion that the Borrow was on the stack. This
  didn't work, due to passing multiple assertions to the ASSERT macro that
  supports only one.
* BorrowedBytes did not use such a check that it was on the stack. The stack
  check has been abstracted from Borrow and is now used from both.
  (It may be that in future this is redundant if we add static analysis to
  confirm that WTF_FORBID_HEAP_ALLOCATION are only ever embedded in other
  such WTF_FORBID_HEAP_ALLOCATION objects.)
* BorrowedBytes had a debug assertion that it was not still in use from
  Swift when it went out of scope. This has been boosted to be a release
  mode assertion too, partly for better debuggability but also for thread
  safety.

Various tests have been added for both.

Tests: Tools/TestWebKitAPI/Tests/WTF/Borrow.cpp
       Tools/TestWebKitAPI/Tests/WTF/BorrowedBytes.cpp

* Source/WTF/wtf/Borrow.h:
(WTF::assertIsOnStack):
(WTF::Borrow::Borrow):
(WTF::Borrow::assertIsOnStack): Deleted.
* Source/WTF/wtf/BorrowedBytes.h:
(WTF::BorrowedBytesScopeBase::BorrowedBytesScopeBase):
(WTF::BorrowedBytesScopeBase::~BorrowedBytesScopeBase):
* Source/WTF/wtf/Compiler.h:
* Source/WebCore/PAL/pal/crypto/WTFExtras.swift:
* Tools/TestWebKitAPI/CMakeLists.txt:
* Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* Tools/TestWebKitAPI/Tests/WTF/Borrow.cpp: Added.
(TestWebKitAPI::ObservableBorrowable::isBorrowed const):
(TestWebKitAPI::ObservableBorrowable::crashIfBorrowedCount const):
(TestWebKitAPI::ObservableBorrowable::value const):
(TestWebKitAPI::ObservableBorrowable::crashIfBorrowed const):
(TestWebKitAPI::ObservableBorrowable::setIsBorrowed const):
(TestWebKitAPI::Borrowable::value const):
(TestWebKitAPI::TEST(WTF_Borrow, BorrowMarksAndUnmarksTheObject)):
(TestWebKitAPI::TEST(WTF_Borrow, BorrowExposesTheObject)):
(TestWebKitAPI::TEST(WTF_Borrow, BorrowHelperFunction)):
(TestWebKitAPI::TEST(WTF_Borrow, NestedBorrowsRestorePreviousState)):
(TestWebKitAPI::TEST(WTF_Borrow, CrashIfBorrowedIsReachedThroughTheProtocol)):
(TestWebKitAPI::TEST(WTF_Borrow, DestroyAfterBorrowEndsIsFine)):
(TestWebKitAPI::TEST(WTF_BorrowDeathTest, 
MAYBE_ASSERT_ENABLED_DEATH_TEST(DestroyWhileBorrowedCrashes)):
(TestWebKitAPI::TEST(WTF_BorrowDeathTest, 
MAYBE_ASSERT_ENABLED_DEATH_TEST(CrashIfBorrowedWhileBorrowedCrashes)):
(TestWebKitAPI::TEST(WTF_BorrowDeathTest, 
MAYBE_ASSERT_ENABLED_DEATH_TEST(HeapAllocatedBorrowCrashes)):
* Tools/TestWebKitAPI/Tests/WTF/BorrowedBytes.cpp:
(TestWebKitAPI::TEST(WTF_BorrowedBytes, ViewIdentityIsPerScope)):
(TestWebKitAPI::TEST(WTF_BorrowedBytesDeathTest, StashedViewCrashesAtScopeEnd)):
(TestWebKitAPI::TEST(WTF_BorrowedBytesDeathTest, 
StashedViewOverASpanCrashesAtScopeEnd)):
(TestWebKitAPI::TEST(WTF_BorrowedBytesDeathTest, 
ViewEscapedToTheHeapCrashesAtScopeEnd)):
(TestWebKitAPI::TEST(WTF_BorrowedBytes, 
ViewEscapedToTheHeapAndReleasedInTimeIsFine)):
(TestWebKitAPI::TEST(WTF_BorrowedBytesDeathTest, 
MAYBE_ASSERT_ENABLED_DEATH_TEST(HeapAllocatedScopeCrashes)):
(TestWebKitAPI::TEST(WTF_BorrowedBytesDeathTest, 
MAYBE_ASSERT_ENABLED_DEATH_TEST(StashedViewCrashesAtScopeEnd)): Deleted.

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



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

Reply via email to