StikDebug/StikJIT/MiniToolSupport/JSSupport/NSInvocation.m
Huge_Black dca36d5c00
Heartbeat Rework + Mini Tool (#299)
* Heartbeat rework

* remove some debug loggings

* stik mini tool poc

* Saperate JITEnableContext into extensions and put each feature into their own files.
Fix local pairing file is removed after switched to external device by directly loading the remote device's pairing file in place.

* custom origin & xmlhttprequest

* Fix some memory leak

* allow background script access idevice (codes are from the old JSSupport branch)

Tests are not carried out but most of the js api should work.

Do we need to obfuscate some functions' name?

* Fix JITEnableContext singleton initializer race condition

* Fix instprox callback

---------

Co-authored-by: Stephen B <158498287+StephenDev0@users.noreply.github.com>
2025-12-14 11:35:32 -05:00

44 lines
1.4 KiB
Objective-C

//
// NSInvocation.m
// StikJIT
// Source: http://blog.jayway.com/2010/03/30/performing-any-selector-on-the-main-thread/
// Created by s s on 2025/4/24.
//
@import Foundation;
@implementation NSInvocation(MCUtilities)
-(void)invokeOnMainThreadWaitUntilDone:(BOOL)wait
{
[self performSelectorOnMainThread:@selector(invoke)
withObject:nil
waitUntilDone:wait];
}
+(NSInvocation*)invocationWithTarget:(id)target
selector:(SEL)aSelector
retainArguments:(BOOL)retainArguments, ...
{
va_list ap;
va_start(ap, retainArguments);
char* args = (char*)ap;
NSMethodSignature* signature = [target methodSignatureForSelector:aSelector];
NSInvocation* invocation = [NSInvocation invocationWithMethodSignature:signature];
if (retainArguments) {
[invocation retainArguments];
}
[invocation setTarget:target];
[invocation setSelector:aSelector];
for (int index = 2; index < [signature numberOfArguments]; index++) {
const char *type = [signature getArgumentTypeAtIndex:index];
NSUInteger size, align;
NSGetSizeAndAlignment(type, &size, &align);
NSUInteger mod = (NSUInteger)args % align;
if (mod != 0) {
args += (align - mod);
}
[invocation setArgument:args atIndex:index];
args += size;
}
va_end(ap);
return invocation;
}
@end