Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: a41a909424f0b6a1e12afc674e8344d0dafaed38
      
https://github.com/WebKit/WebKit/commit/a41a909424f0b6a1e12afc674e8344d0dafaed38
  Author: Zak Ridouh <[email protected]>
  Date:   2026-05-08 (Fri, 08 May 2026)

  Changed paths:
    M Tools/TestWebKitAPI/Helpers/cocoa/Foundation+Extras.swift

  Log Message:
  -----------
  [Swift Testing] Add Swift-callable wrapper around InstanceMethodSwizzler for 
TestWebKitAPI
https://bugs.webkit.org/show_bug.cgi?id=312797
rdar://175186623

Reviewed by Richard Robinson.

Swift tests in TestWebKitAPI have no ergonomic way to mock Objective-C
runtime behavior: the C++ InstanceMethodSwizzler RAII helper is awkward
to use from Swift, which prefers scoped `with*` functions over dropping
an RAII handle on the floor. This is the first piece of infrastructure
needed to port AppKit-heavy tests (NSPasteboard mocks, NSMenu pop-ups,
gesture recognizers, drag-and-drop) to the new Swift Testing framework.

Add ObjectiveCMethodSwizzling.swift, exposing two scoped helpers:

  - `withSwizzledObjectiveCInstanceMethod(replacing:name:with:perform:)`
    swaps in a block-derived IMP for an instance method.
  - `withSwizzledObjectiveCClassMethod(replacing:name:with:perform:)`
    is the class-method counterpart, backed by `class_getClassMethod`.

Both take an `@convention(block)` closure whose first parameter is the
receiver (or receiving class) followed by the method's arguments, and
both restore the original implementation via `defer` before returning,
including on error paths. They also call `imp_removeBlock` to balance
`imp_implementationWithBlock`.

* Tools/TestWebKitAPI/Helpers/cocoa/Foundation+Extras.swift:

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



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

Reply via email to