first commit

This commit is contained in:
2026-03-10 16:18:05 +00:00
commit 11f9c069b5
31635 changed files with 3187747 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <Foundation/Foundation.h>
#import <React/RCTDefines.h>
RCT_EXTERN_C_BEGIN
int RCTGetRetainCount(id _Nullable object);
void RCTAutoReleasePoolPush(void);
void RCTAutoReleasePoolPop(void);
RCT_EXTERN_C_END

View File

@@ -0,0 +1,45 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RCTMemoryUtils.h"
int RCTGetRetainCount(id _Nullable object)
{
return object != nil ? CFGetRetainCount((__bridge CFTypeRef)object) - 1 : 0;
}
OBJC_EXPORT
void *objc_autoreleasePoolPush(void) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0);
OBJC_EXPORT
void objc_autoreleasePoolPop(void *context) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0);
static NSString *const kAutoreleasePoolContextStackKey = @"autorelease_pool_context_stack";
void RCTAutoReleasePoolPush(void)
{
assert([NSThread isMainThread]);
NSMutableDictionary *dictionary = [[NSThread currentThread] threadDictionary];
void *context = objc_autoreleasePoolPush();
NSMutableArray<NSValue *> *contextStack = dictionary[kAutoreleasePoolContextStackKey];
if (!contextStack) {
contextStack = [NSMutableArray array];
dictionary[kAutoreleasePoolContextStackKey] = contextStack;
}
[contextStack addObject:[NSValue valueWithPointer:context]];
}
void RCTAutoReleasePoolPop(void)
{
assert([NSThread isMainThread]);
NSMutableDictionary *dictionary = [[NSThread currentThread] threadDictionary];
NSMutableArray<NSValue *> *contextStack = dictionary[kAutoreleasePoolContextStackKey];
assert(contextStack.count > 0);
NSValue *lastContext = contextStack.lastObject;
[contextStack removeLastObject];
objc_autoreleasePoolPop(lastContext.pointerValue);
}

View File

@@ -0,0 +1,16 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <Foundation/Foundation.h>
#import <React/RCTDefines.h>
RCT_EXTERN_C_BEGIN
void RCTSwizzleInstanceSelector(Class targetClass, Class swizzleClass, SEL selector);
RCT_EXTERN_C_END

View File

@@ -0,0 +1,17 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RCTSwizzleHelpers.h"
#import <objc/runtime.h>
void RCTSwizzleInstanceSelector(Class targetClass, Class swizzleClass, SEL selector)
{
Method originalMethod = class_getInstanceMethod(targetClass, selector);
Method swizzleMethod = class_getInstanceMethod(swizzleClass, selector);
method_exchangeImplementations(originalMethod, swizzleMethod);
}

View File

@@ -0,0 +1,21 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <Foundation/Foundation.h>
@interface ShimRCTInstance : NSObject
@property int initCount;
@property int invalidateCount;
@property NSDictionary *launchOptions;
@property NSString *jsModuleName;
@property NSString *method;
@property NSArray *args;
- (void)reset;
@end

View File

@@ -0,0 +1,78 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "ShimRCTInstance.h"
#import <ReactCommon/RCTInstance.h>
#import "RCTSwizzleHelpers.h"
static __weak ShimRCTInstance *weakShim = nil;
@implementation ShimRCTInstance
- (instancetype)init
{
if (self = [super init]) {
_initCount = 0;
RCTSwizzleInstanceSelector(
[RCTInstance class],
[ShimRCTInstance class],
@selector
(initWithDelegate:
jsRuntimeFactory:bundleManager:turboModuleManagerDelegate:moduleRegistry:parentInspectorTarget:launchOptions
:devMenuConfiguration:));
RCTSwizzleInstanceSelector([RCTInstance class], [ShimRCTInstance class], @selector(invalidate));
RCTSwizzleInstanceSelector(
[RCTInstance class], [ShimRCTInstance class], @selector(callFunctionOnJSModule:method:args:));
weakShim = self;
}
return self;
}
- (void)reset
{
RCTSwizzleInstanceSelector(
[RCTInstance class],
[ShimRCTInstance class],
@selector
(initWithDelegate:
jsRuntimeFactory:bundleManager:turboModuleManagerDelegate:moduleRegistry:parentInspectorTarget:launchOptions
:devMenuConfiguration:));
RCTSwizzleInstanceSelector([RCTInstance class], [ShimRCTInstance class], @selector(invalidate));
RCTSwizzleInstanceSelector(
[RCTInstance class], [ShimRCTInstance class], @selector(callFunctionOnJSModule:method:args:));
_initCount = 0;
_invalidateCount = 0;
}
- (instancetype)initWithDelegate:(id<RCTInstanceDelegate>)delegate
jsRuntimeFactory:(std::shared_ptr<facebook::react::JSRuntimeFactory>)jsRuntimeFactory
bundleManager:(RCTBundleManager *)bundleManager
turboModuleManagerDelegate:(id<RCTTurboModuleManagerDelegate>)tmmDelegate
moduleRegistry:(RCTModuleRegistry *)moduleRegistry
parentInspectorTarget:(facebook::react::jsinspector_modern::HostTarget *)parentInspectorTarget
launchOptions:(NSDictionary *)launchOptions
devMenuConfiguration:(RCTDevMenuConfiguration *)devMenuConfiguration
{
weakShim.initCount++;
return self;
}
- (void)invalidate
{
weakShim.invalidateCount++;
}
- (void)callFunctionOnJSModule:(NSString *)moduleName method:(NSString *)method args:(NSArray *)args
{
weakShim.jsModuleName = moduleName;
weakShim.method = method;
weakShim.args = [args copy];
}
@end