Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 88b46e6bc7af5f00aaa938f3b0ec3d16edcb9477
https://github.com/WebKit/WebKit/commit/88b46e6bc7af5f00aaa938f3b0ec3d16edcb9477
Author: Adrian Taylor <[email protected]>
Date: 2026-08-19 (Wed, 19 Aug 2026)
Changed paths:
M Source/WTF/WTF.xcodeproj/project.pbxproj
R Source/WTF/wtf/BorrowedBytes.h
M Source/WTF/wtf/CMakeLists.txt
A Source/WTF/wtf/EscapableByteSpan.h
M Source/WebCore/PAL/Configurations/PAL.xcconfig
M Source/WebCore/PAL/pal/CMakeLists.txt
M Source/WebCore/PAL/pal/crypto/CryptoAlgorithmAESGCMCocoa.cpp
M Source/WebCore/PAL/pal/crypto/CryptoAlgorithmAESKWCocoaBridging.cpp
M Source/WebCore/PAL/pal/crypto/CryptoAlgorithmEd25519CocoaBridging.cpp
M Source/WebCore/PAL/pal/crypto/CryptoAlgorithmHKDFCocoaBridging.cpp
M Source/WebCore/PAL/pal/crypto/CryptoAlgorithmHMACCocoaBridging.cpp
M Source/WebCore/PAL/pal/crypto/CryptoAlgorithmX25519CocoaBridging.cpp
M Source/WebCore/PAL/pal/crypto/CryptoEDKeyBridging.cpp
M Source/WebCore/PAL/pal/crypto/CryptoKitShim.swift
M Source/WebCore/PAL/pal/crypto/CryptoTypes.h
M Source/WebCore/PAL/pal/crypto/PlatformECKey.cpp
M Source/WebCore/PAL/pal/crypto/WTFExtras.swift
M Source/WebCore/PAL/pal/crypto/commoncrypto/CryptoDigestCommonCrypto.cpp
M Tools/TestWebKitAPI/CMakeLists.txt
M Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
R Tools/TestWebKitAPI/Tests/WTF/BorrowedBytes.cpp
A Tools/TestWebKitAPI/Tests/WTF/EscapableByteSpan.cpp
Log Message:
-----------
Rename and simplify BorrowedBytes
https://bugs.webkit.org/show_bug.cgi?id=321509
rdar://184620319
Reviewed by Geoffrey Garen.
This makes significant changes to WTF::BorrowedBytes based on review
suggestions. It makes the minimum corresponding changes to the use of this type
within PAL crypto; future PRs will make more substantive changes to use these
new facilities both in PAL and WebGPU.
The changes are:
- BorrowedSpanScope renamed to EscapableByteSpan
- BorrowedVectorScope removed; we compose other primitives for it
- These types no longer "vend" a Swift-compatible EscapableByteSpan object.
Instead, they _are_ the Swift-compatible EscapableByteSpan object. Swift
can use these objects directly, and they continue to confirm to the
same protocols that EscapableByteSpan itself conformed to, allowing their
use within various pre-existing Swift APIs.
- This type is no longer a refcounted WebKit type. It always lives on
the stack; copies made on the Swift side update a reference count
in the original object. This is used to check whether it's still in
scope somewhere within Swift when it falls out of the original C++
scope, resulting in a safe panic. It no longer has any heap
allocation.
- Now that Vector fully impplements the CanBorrow protocol, this adds
death tests to ensure it works.
Test: Tools/TestWebKitAPI/Tests/WTF/EscapableByteSpan.cpp
* Source/WTF/wtf/EscapableByteSpan.h:
(WTF::BorrowedBase::size const):
(WTF::BorrowedBase::create):
(WTF::BorrowedBase::span const):
(WTF::BorrowedBase::BorrowedBase):
(WTF:: const):
(WTF::EscapableEscapableByteSpan::EscapableEscapableByteSpan):
(WTF::EscapableEscapableByteSpan::~EscapableEscapableByteSpan):
(WTF::EscapableEscapableByteSpan::size const):
(WTF::EscapableEscapableByteSpan::swiftRef const):
(WTF::EscapableEscapableByteSpan::swiftDeref const):
(WTF::EscapableByteSpan::size const): Deleted.
(WTF::EscapableByteSpan::ref const): Deleted.
(WTF::EscapableByteSpan::deref const): Deleted.
(WTF::EscapableByteSpan::create): Deleted.
(WTF::EscapableByteSpan::EscapableByteSpan): Deleted.
(WTF::EscapableByteSpan::revoke): Deleted.
(WTF::EscapableByteSpanScopeBase::EscapableByteSpanScopeBase): Deleted.
(WTF::EscapableByteSpanScopeBase::~EscapableByteSpanScopeBase): Deleted.
(WTF::escapableSpan):
* Source/WebCore/PAL/pal/crypto/CryptoAlgorithmAESGCMCocoa.cpp:
(PAL::Crypto::encryptCryptoKitAESGCM):
* Source/WebCore/PAL/pal/crypto/CryptoAlgorithmAESKWCocoaBridging.cpp:
(PAL::Crypto::wrapKeyAESKWCryptoKit):
(PAL::Crypto::unwrapKeyAESKWCryptoKit):
* Source/WebCore/PAL/pal/crypto/CryptoAlgorithmEd25519CocoaBridging.cpp:
(PAL::Crypto::signEd25519CryptoKit):
(PAL::Crypto::verifyEd25519CryptoKit):
* Source/WebCore/PAL/pal/crypto/CryptoAlgorithmHKDFCocoaBridging.cpp:
(PAL::Crypto::deriveBitsHKDFCryptoKit):
* Source/WebCore/PAL/pal/crypto/CryptoAlgorithmHMACCocoaBridging.cpp:
(PAL::Crypto::signHMACCryptoKit):
(PAL::Crypto::verifyHMACCryptoKit):
* Source/WebCore/PAL/pal/crypto/CryptoAlgorithmX25519CocoaBridging.cpp:
(PAL::Crypto::deriveBitsX25519CryptoKit):
* Source/WebCore/PAL/pal/crypto/CryptoEDKeyBridging.cpp:
(PAL::Crypto::EdKey::privateToPublic):
(PAL::Crypto::EdKey::privateToPublicKeyAgreement):
(PAL::Crypto::EdKey::validateKeyPair):
(PAL::Crypto::EdKey::validateKeyPairKeyAgreement):
* Source/WebCore/PAL/pal/crypto/CryptoKitShim.swift:
(Digest.update(_:)):
(Digest.sha1(_:)):
(Digest.sha256(_:)):
(Digest.sha384(_:)):
(Digest.sha512(_:)):
(ECKey.importX963Pub(_:curve:)):
(ECKey.importCompressedPub(_:curve:)):
(ECKey.importX963Private(_:curve:)):
(WTF.requireNonEmpty):
(Curve25519.signature(_:)):
(Curve25519.isValidSignature(_:data:)):
(Curve25519.sharedSecretFromKeyAgreement(_:)):
* Source/WebCore/PAL/pal/crypto/PlatformECKey.cpp:
(PAL::Crypto::PlatformECKey::sign const):
(PAL::Crypto::PlatformECKey::doVerify const):
(PAL::Crypto::PlatformECKey::importX963Pub):
(PAL::Crypto::PlatformECKey::importX963Private):
(PAL::Crypto::PlatformECKey::importCompressedPub):
* Source/WebCore/PAL/pal/crypto/WTFExtras.swift:
(WTF.regions):
* Source/WebCore/PAL/pal/crypto/commoncrypto/CryptoDigestCommonCrypto.cpp:
(PAL::Crypto::CryptoDigest::addBytes):
* Tools/TestWebKitAPI/Tests/WTF/EscapableByteSpan.cpp:
(TestWebKitAPI::TEST(WTF_EscapableByteSpan, EscapableByteSpanWrapsASpan)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpan,
DefaultConstructedEscapableByteSpanIsEmpty)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpan, EscapableByteSpanSubspan)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpanDeathTest,
EscapableByteSpanSubspanPastTheEndCrashes)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpanDeathTest,
EscapableByteSpanSubspanWithWrappedOffsetCrashes)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpan, EscapableExposesBytes)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpan, EscapableOverSubspan)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpan, EscapableVectorBytesExposesBytes)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpan, EscapableEmptySpan)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpan, EscapableEmptyVector)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpan, EscapableTransientReferenceIsFine)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpan, EscapableNestedVectorBorrows)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpan, EscapableViewIdentityIsPerBorrow)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpanDeathTest,
EscapableStashedViewCrashesWhenTheBorrowEnds)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpanDeathTest,
EscapableStashedViewOverASpanCrashesWhenTheBorrowEnds)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpanDeathTest,
EscapableViewEscapedToTheHeapCrashesWhenTheBorrowEnds)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpan,
EscapableViewEscapedToTheHeapAndReleasedInTimeIsFine)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpanDeathTest,
MAYBE_ASSERT_ENABLED_DEATH_TEST(EscapableVectorBytesReallocationWhileBorrowedCrashes)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpanDeathTest,
MAYBE_ASSERT_ENABLED_DEATH_TEST(EscapableVectorBytesDestroyedVectorWhileBorrowedCrashes)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpan,
EscapableVectorBytesNonReallocatingMutationIsFine)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpanDeathTest,
MAYBE_ASSERT_ENABLED_DEATH_TEST(EscapableHeapAllocatedBytesCrashes)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpan, BorrowedMutableBytesWrapsASpan)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpan,
DefaultConstructedBorrowedMutableBytesIsEmpty)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpan, BorrowedMutableBytesSubspan)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpanDeathTest,
BorrowedMutableBytesSubspanPastTheEndCrashes)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpanDeathTest,
BorrowedMutableBytesSubspanWithWrappedOffsetCrashes)):
(TestWebKitAPI:: const):
(TestWebKitAPI::TEST(WTF_EscapableByteSpan, BorrowedBaseOverANonByteElement)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpanDeathTest,
BorrowedBaseOverANonByteElementRangeChecks)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpan, SpanScopeExposesBytes)): Deleted.
(TestWebKitAPI::TEST(WTF_EscapableByteSpan, SpanScopeOverSubspan)): Deleted.
(TestWebKitAPI::TEST(WTF_EscapableByteSpan, VectorScopeExposesBytes)): Deleted.
(TestWebKitAPI::TEST(WTF_EscapableByteSpan, EmptySpan)): Deleted.
(TestWebKitAPI::TEST(WTF_EscapableByteSpan, EmptyVector)): Deleted.
(TestWebKitAPI::TEST(WTF_EscapableByteSpan, ScopeHoldsSoleReference)): Deleted.
(TestWebKitAPI::TEST(WTF_EscapableByteSpan, NestedVectorScopes)): Deleted.
(TestWebKitAPI::TEST(WTF_EscapableByteSpan, ViewIdentityIsPerScope)): Deleted.
(TestWebKitAPI::TEST(WTF_EscapableByteSpanDeathTest,
StashedViewCrashesAtScopeEnd)): Deleted.
(TestWebKitAPI::TEST(WTF_EscapableByteSpanDeathTest,
StashedViewOverASpanCrashesAtScopeEnd)): Deleted.
(TestWebKitAPI::TEST(WTF_EscapableByteSpanDeathTest,
ViewEscapedToTheHeapCrashesAtScopeEnd)): Deleted.
(TestWebKitAPI::TEST(WTF_EscapableByteSpan,
ViewEscapedToTheHeapAndReleasedInTimeIsFine)): Deleted.
(TestWebKitAPI::TEST(WTF_EscapableByteSpanDeathTest,
MAYBE_ASSERT_ENABLED_DEATH_TEST(HeapAllocatedScopeCrashes)): Deleted.
(TestWebKitAPI::TEST(WTF_EscapableByteSpan, EscapableTransientCopyIsFine)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpanDeathTest,
EscapableStashedCopyCrashesWhenTheBorrowEnds)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpanDeathTest,
EscapableStashedCopyOfACopyCrashesWhenTheBorrowEnds)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpanDeathTest,
EscapableStashedCopyOverASpanCrashesWhenTheBorrowEnds)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpanDeathTest,
EscapableCopyEscapedToTheHeapCrashesWhenTheBorrowEnds)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpan,
EscapableCopyEscapedToTheHeapAndReleasedInTimeIsFine)):
(TestWebKitAPI::takesBaseAsSwiftWould):
(TestWebKitAPI::TEST(WTF_EscapableByteSpan,
EscapableVectorBytesReleasesItsBorrowWhenTheScopeEnds)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpan,
EscapableVectorBytesReleasesItsBorrowAfterRepeatedBaseCopies)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpan, ExposesBytes)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpan, OverSubspan)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpan, VectorBytesExposesBytes)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpan, TransientCopyIsFine)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpan, NestedVectorBorrows)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpan, ViewIdentityIsPerBorrow)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpanDeathTest,
StashedCopyCrashesWhenTheBorrowEnds)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpanDeathTest,
StashedCopyOfACopyCrashesWhenTheBorrowEnds)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpanDeathTest,
StashedCopyOverASpanCrashesWhenTheBorrowEnds)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpanDeathTest,
CopyEscapedToTheHeapCrashesWhenTheBorrowEnds)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpan,
CopyEscapedToTheHeapAndReleasedInTimeIsFine)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpanDeathTest,
MAYBE_ASSERT_ENABLED_DEATH_TEST(VectorBytesReallocationWhileBorrowedCrashes)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpanDeathTest,
MAYBE_ASSERT_ENABLED_DEATH_TEST(VectorBytesDestroyedVectorWhileBorrowedCrashes)):
(TestWebKitAPI::takesByReferenceAsSwiftWould):
(TestWebKitAPI::TEST(WTF_EscapableByteSpan,
VectorBytesReleasesItsBorrowWhenTheScopeEnds)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpan,
VectorBytesReleasesItsBorrowAfterRepeatedCopies)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpan,
VectorBytesNonReallocatingMutationIsFine)):
(TestWebKitAPI::TEST(WTF_EscapableByteSpanDeathTest,
MAYBE_ASSERT_ENABLED_DEATH_TEST(HeapAllocatedBytesCrashes)):
* Source/WebCore/PAL/Configurations/PAL.xcconfig:
* Source/WebCore/PAL/pal/CMakeLists.txt:
* Source/WTF/WTF.xcodeproj/project.pbxproj:
* Source/WTF/wtf/BorrowedBytes.h: Removed.
* Source/WTF/wtf/CMakeLists.txt:
* Source/WebCore/PAL/pal/crypto/CryptoTypes.h:
* Tools/TestWebKitAPI/CMakeLists.txt:
* Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* Tools/TestWebKitAPI/Tests/WTF/BorrowedBytes.cpp: Removed.
Canonical link: https://commits.webkit.org/319488@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications