Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic Invocation #19

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Dynamic Invocation #19

wants to merge 6 commits into from

Conversation

steipete
Copy link
Owner

@steipete steipete commented Jun 18, 2020

With using objc_msgForward, we can add hooks without offering a type signature.

_ = try testObj.hook(#selector(TestClass.executeBlock)) { bSelf in
  print("Before Interposing Dynamic Hook for \(bSelf)")
}

This is slightly slower than the typed call, but way more convenient

This is achieved with a few tricks:

  1. We install the subclass
  2. The hooked method gets a super trampoline
  3. we add a interpose_origMethod and copy the implementation (which is the super trampoline)
  4. change orig impl to objc_msgForward
  5. Custom forward handler calls hooks, changes invocation selector to interpose_
  6. super handler in interpose changes _cmd back to expected and calls super

TODO:

  • class-based not just objects (can't easily fix the selector then...
  • pass on invocation + helpers to get parameters
  • copy block parameters as needed
  • check block type signature
  • Generalize interpose _cmd filter

@codecov
Copy link

codecov bot commented Jun 18, 2020

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

@crsantos
Copy link

Hey Peter, hope you're fine.

Honest question, was there any work left to do on this PR?
Because this would be an awesome feature ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants