mirror of
https://github.com/status-im/react-native.git
synced 2025-01-29 18:54:58 +00:00
Pull native hook registration into class method
Summary: Ideally, native hooks should not require any sort of reference to self. Pull all those that fulfill this criteria into a class method (to make it impossible to accidentally capture self). Future diffs will pull more and more hooks into this category. Reviewed By: javache Differential Revision: D3528558 fbshipit-source-id: 270c5bec53674a91ec2129d55e5cad59440a51da
This commit is contained in:
parent
96b47eb933
commit
dd5bb7b9e0
@ -363,16 +363,7 @@ static void RCTInstallJSCProfiler(RCTBridge *bridge, JSContextRef context)
|
||||
|
||||
// Synchronous hooks:
|
||||
JSContext *context = strongSelf.context.context;
|
||||
context[@"noop"] = ^{};
|
||||
|
||||
context[@"nativeLoggingHook"] = ^(NSString *message, NSNumber *logLevel) {
|
||||
RCTLogLevel level = RCTLogLevelInfo;
|
||||
if (logLevel) {
|
||||
level = MAX(level, (RCTLogLevel)logLevel.integerValue);
|
||||
}
|
||||
|
||||
_RCTLogJavaScriptInternal(level, message);
|
||||
};
|
||||
[[self class] installSynchronousHooksOnContext:context];
|
||||
|
||||
context[@"nativeRequireModuleConfig"] = ^NSString *(NSString *moduleName) {
|
||||
RCTJSCExecutor *strongSelf2 = weakSelf;
|
||||
@ -398,16 +389,7 @@ static void RCTInstallJSCProfiler(RCTBridge *bridge, JSContextRef context)
|
||||
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"js_call", nil);
|
||||
};
|
||||
|
||||
context[@"nativePerformanceNow"] = ^{
|
||||
return @(CACurrentMediaTime() * 1000);
|
||||
};
|
||||
|
||||
#if RCT_PROFILE
|
||||
if (RCTProfileIsProfiling()) {
|
||||
// Cheating, since it's not a "hook", but meh
|
||||
context[@"__RCTProfileIsProfiling"] = @YES;
|
||||
}
|
||||
|
||||
context[@"nativeTraceBeginAsyncSection"] = ^(uint64_t tag, NSString *name, NSUInteger cookie) {
|
||||
RCTJSCExecutor *strongSelf2 = weakSelf;
|
||||
if (!strongSelf2) {
|
||||
@ -427,19 +409,6 @@ static void RCTInstallJSCProfiler(RCTBridge *bridge, JSContextRef context)
|
||||
CFDictionaryRemoveValue(strongSelf2->_cookieMap, (const void *)cookie);
|
||||
};
|
||||
|
||||
context[@"nativeTraceBeginSection"] = ^(NSNumber *tag, NSString *profileName, NSDictionary *args) {
|
||||
static int profileCounter = 1;
|
||||
if (!profileName) {
|
||||
profileName = [NSString stringWithFormat:@"Profile %d", profileCounter++];
|
||||
}
|
||||
|
||||
RCT_PROFILE_BEGIN_EVENT(tag.longLongValue, profileName, args);
|
||||
};
|
||||
|
||||
context[@"nativeTraceEndSection"] = ^(NSNumber *tag) {
|
||||
RCT_PROFILE_END_EVENT(tag.longLongValue, @"console", nil);
|
||||
};
|
||||
|
||||
context[@"nativeTraceBeginAsyncFlow"] = ^(__unused uint64_t tag, __unused NSString *name, int64_t cookie) {
|
||||
if (RCTProfileIsProfiling()) {
|
||||
[weakBridge.flowIDMapLock lock];
|
||||
@ -481,6 +450,39 @@ static void RCTInstallJSCProfiler(RCTBridge *bridge, JSContextRef context)
|
||||
}];
|
||||
}
|
||||
|
||||
+ (void)installSynchronousHooksOnContext:(JSContext *)context
|
||||
{
|
||||
context[@"noop"] = ^{};
|
||||
context[@"nativeLoggingHook"] = ^(NSString *message, NSNumber *logLevel) {
|
||||
RCTLogLevel level = RCTLogLevelInfo;
|
||||
if (logLevel) {
|
||||
level = MAX(level, (RCTLogLevel)logLevel.integerValue);
|
||||
}
|
||||
|
||||
_RCTLogJavaScriptInternal(level, message);
|
||||
};
|
||||
context[@"nativePerformanceNow"] = ^{
|
||||
return @(CACurrentMediaTime() * 1000);
|
||||
};
|
||||
#if RCT_PROFILE
|
||||
if (RCTProfileIsProfiling()) {
|
||||
// Cheating, since it's not a "hook", but meh
|
||||
context[@"__RCTProfileIsProfiling"] = @YES;
|
||||
}
|
||||
context[@"nativeTraceBeginSection"] = ^(NSNumber *tag, NSString *profileName, NSDictionary *args) {
|
||||
static int profileCounter = 1;
|
||||
if (!profileName) {
|
||||
profileName = [NSString stringWithFormat:@"Profile %d", profileCounter++];
|
||||
}
|
||||
|
||||
RCT_PROFILE_BEGIN_EVENT(tag.longLongValue, profileName, args);
|
||||
};
|
||||
context[@"nativeTraceEndSection"] = ^(NSNumber *tag) {
|
||||
RCT_PROFILE_END_EVENT(tag.longLongValue, @"console", nil);
|
||||
};
|
||||
#endif
|
||||
}
|
||||
|
||||
- (void)toggleProfilingFlag:(NSNotification *)notification
|
||||
{
|
||||
[self executeBlockOnJavaScriptQueue:^{
|
||||
|
Loading…
x
Reference in New Issue
Block a user