Make addSynchronousHookWithName private

Summary: It's not widely used, and you can do something equivalent anyway by using existing public API.

Reviewed By: javache

Differential Revision: D3518896

fbshipit-source-id: 6995a5d840aecfff4ffd78ac43f3f592a4f47f91
This commit is contained in:
Adam Ernst 2016-07-07 13:31:23 -07:00 committed by Facebook Github Bot 2
parent 65120d7052
commit a203cf4791
2 changed files with 15 additions and 21 deletions

View File

@ -85,10 +85,4 @@ typedef void (^RCTJavaScriptCallback)(id json, NSError *error);
*/ */
- (void)executeAsyncBlockOnJavaScriptQueue:(dispatch_block_t)block; - (void)executeAsyncBlockOnJavaScriptQueue:(dispatch_block_t)block;
/**
* For executors that support it, this method can be used to add a synchronous
* callback function for communicating with the javascript context.
*/
- (void)addSynchronousHookWithName:(NSString *)name usingBlock:(id)block;
@end @end

View File

@ -323,7 +323,7 @@ static void RCTInstallJSCProfiler(RCTBridge *bridge, JSContextRef context)
return self.context.context; return self.context.context;
} }
- (void)addSynchronousHookWithName:(NSString *)name usingBlock:(id)block - (void)_addSynchronousHookWithName:(NSString *)name usingBlock:(id)block
{ {
__weak RCTJSCExecutor *weakSelf = self; __weak RCTJSCExecutor *weakSelf = self;
[self executeBlockOnJavaScriptQueue:^{ [self executeBlockOnJavaScriptQueue:^{
@ -364,9 +364,9 @@ static void RCTInstallJSCProfiler(RCTBridge *bridge, JSContextRef context)
} }
}]; }];
[self addSynchronousHookWithName:@"noop" usingBlock:^{}]; [self _addSynchronousHookWithName:@"noop" usingBlock:^{}];
[self addSynchronousHookWithName:@"nativeLoggingHook" usingBlock:^(NSString *message, NSNumber *logLevel) { [self _addSynchronousHookWithName:@"nativeLoggingHook" usingBlock:^(NSString *message, NSNumber *logLevel) {
RCTLogLevel level = RCTLogLevelInfo; RCTLogLevel level = RCTLogLevelInfo;
if (logLevel) { if (logLevel) {
level = MAX(level, (RCTLogLevel)logLevel.integerValue); level = MAX(level, (RCTLogLevel)logLevel.integerValue);
@ -375,7 +375,7 @@ static void RCTInstallJSCProfiler(RCTBridge *bridge, JSContextRef context)
_RCTLogJavaScriptInternal(level, message); _RCTLogJavaScriptInternal(level, message);
}]; }];
[self addSynchronousHookWithName:@"nativeRequireModuleConfig" usingBlock:^NSString *(NSString *moduleName) { [self _addSynchronousHookWithName:@"nativeRequireModuleConfig" usingBlock:^NSString *(NSString *moduleName) {
RCTJSCExecutor *strongSelf = weakSelf; RCTJSCExecutor *strongSelf = weakSelf;
if (!strongSelf.valid) { if (!strongSelf.valid) {
return nil; return nil;
@ -388,7 +388,7 @@ static void RCTInstallJSCProfiler(RCTBridge *bridge, JSContextRef context)
return result; return result;
}]; }];
[self addSynchronousHookWithName:@"nativeFlushQueueImmediate" usingBlock:^(NSArray<NSArray *> *calls){ [self _addSynchronousHookWithName:@"nativeFlushQueueImmediate" usingBlock:^(NSArray<NSArray *> *calls){
RCTJSCExecutor *strongSelf = weakSelf; RCTJSCExecutor *strongSelf = weakSelf;
if (!strongSelf.valid || !calls) { if (!strongSelf.valid || !calls) {
return; return;
@ -399,18 +399,18 @@ static void RCTInstallJSCProfiler(RCTBridge *bridge, JSContextRef context)
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"js_call", nil); RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"js_call", nil);
}]; }];
[self addSynchronousHookWithName:@"nativePerformanceNow" usingBlock:^{ [self _addSynchronousHookWithName:@"nativePerformanceNow" usingBlock:^{
return @(CACurrentMediaTime() * 1000); return @(CACurrentMediaTime() * 1000);
}]; }];
#if RCT_PROFILE #if RCT_PROFILE
if (RCTProfileIsProfiling()) { if (RCTProfileIsProfiling()) {
// Cheating, since it's not a "hook", but meh // Cheating, since it's not a "hook", but meh
[self addSynchronousHookWithName:@"__RCTProfileIsProfiling" usingBlock:@YES]; [self _addSynchronousHookWithName:@"__RCTProfileIsProfiling" usingBlock:@YES];
} }
_cookieMap = CFDictionaryCreateMutable(NULL, 0, NULL, NULL); _cookieMap = CFDictionaryCreateMutable(NULL, 0, NULL, NULL);
[self addSynchronousHookWithName:@"nativeTraceBeginAsyncSection" usingBlock:^(uint64_t tag, NSString *name, NSUInteger cookie) { [self _addSynchronousHookWithName:@"nativeTraceBeginAsyncSection" usingBlock:^(uint64_t tag, NSString *name, NSUInteger cookie) {
RCTJSCExecutor *strongSelf = weakSelf; RCTJSCExecutor *strongSelf = weakSelf;
if (!strongSelf) { if (!strongSelf) {
return; return;
@ -419,7 +419,7 @@ static void RCTInstallJSCProfiler(RCTBridge *bridge, JSContextRef context)
CFDictionarySetValue(strongSelf->_cookieMap, (const void *)cookie, (const void *)newCookie); CFDictionarySetValue(strongSelf->_cookieMap, (const void *)cookie, (const void *)newCookie);
}]; }];
[self addSynchronousHookWithName:@"nativeTraceEndAsyncSection" usingBlock:^(uint64_t tag, NSString *name, NSUInteger cookie) { [self _addSynchronousHookWithName:@"nativeTraceEndAsyncSection" usingBlock:^(uint64_t tag, NSString *name, NSUInteger cookie) {
RCTJSCExecutor *strongSelf = weakSelf; RCTJSCExecutor *strongSelf = weakSelf;
if (!strongSelf) { if (!strongSelf) {
return; return;
@ -429,7 +429,7 @@ static void RCTInstallJSCProfiler(RCTBridge *bridge, JSContextRef context)
CFDictionaryRemoveValue(strongSelf->_cookieMap, (const void *)cookie); CFDictionaryRemoveValue(strongSelf->_cookieMap, (const void *)cookie);
}]; }];
[self addSynchronousHookWithName:@"nativeTraceBeginSection" usingBlock:^(NSNumber *tag, NSString *profileName, NSDictionary *args) { [self _addSynchronousHookWithName:@"nativeTraceBeginSection" usingBlock:^(NSNumber *tag, NSString *profileName, NSDictionary *args) {
static int profileCounter = 1; static int profileCounter = 1;
if (!profileName) { if (!profileName) {
profileName = [NSString stringWithFormat:@"Profile %d", profileCounter++]; profileName = [NSString stringWithFormat:@"Profile %d", profileCounter++];
@ -438,7 +438,7 @@ static void RCTInstallJSCProfiler(RCTBridge *bridge, JSContextRef context)
RCT_PROFILE_BEGIN_EVENT(tag.longLongValue, profileName, args); RCT_PROFILE_BEGIN_EVENT(tag.longLongValue, profileName, args);
}]; }];
[self addSynchronousHookWithName:@"nativeTraceEndSection" usingBlock:^(NSNumber *tag) { [self _addSynchronousHookWithName:@"nativeTraceEndSection" usingBlock:^(NSNumber *tag) {
RCT_PROFILE_END_EVENT(tag.longLongValue, @"console", nil); RCT_PROFILE_END_EVENT(tag.longLongValue, @"console", nil);
}]; }];
@ -447,7 +447,7 @@ static void RCTInstallJSCProfiler(RCTBridge *bridge, JSContextRef context)
_bridge.flowIDMap = CFDictionaryCreateMutable(NULL, 0, NULL, NULL); _bridge.flowIDMap = CFDictionaryCreateMutable(NULL, 0, NULL, NULL);
#endif #endif
_bridge.flowIDMapLock = [NSLock new]; _bridge.flowIDMapLock = [NSLock new];
[self addSynchronousHookWithName:@"nativeTraceBeginAsyncFlow" usingBlock:^(__unused uint64_t tag, __unused NSString *name, int64_t cookie) { [self _addSynchronousHookWithName:@"nativeTraceBeginAsyncFlow" usingBlock:^(__unused uint64_t tag, __unused NSString *name, int64_t cookie) {
if (RCTProfileIsProfiling()) { if (RCTProfileIsProfiling()) {
[weakBridge.flowIDMapLock lock]; [weakBridge.flowIDMapLock lock];
int64_t newCookie = [_RCTProfileBeginFlowEvent() longLongValue]; int64_t newCookie = [_RCTProfileBeginFlowEvent() longLongValue];
@ -456,7 +456,7 @@ static void RCTInstallJSCProfiler(RCTBridge *bridge, JSContextRef context)
} }
}]; }];
[self addSynchronousHookWithName:@"nativeTraceEndAsyncFlow" usingBlock:^(__unused uint64_t tag, __unused NSString *name, int64_t cookie) { [self _addSynchronousHookWithName:@"nativeTraceEndAsyncFlow" usingBlock:^(__unused uint64_t tag, __unused NSString *name, int64_t cookie) {
if (RCTProfileIsProfiling()) { if (RCTProfileIsProfiling()) {
[weakBridge.flowIDMapLock lock]; [weakBridge.flowIDMapLock lock];
int64_t newCookie = (int64_t)CFDictionaryGetValue(weakBridge.flowIDMap, (const void *)cookie); int64_t newCookie = (int64_t)CFDictionaryGetValue(weakBridge.flowIDMap, (const void *)cookie);
@ -486,7 +486,7 @@ static void RCTInstallJSCProfiler(RCTBridge *bridge, JSContextRef context)
}]; }];
// Inject handler used by HMR // Inject handler used by HMR
[self addSynchronousHookWithName:@"nativeInjectHMRUpdate" usingBlock:^(NSString *sourceCode, NSString *sourceCodeURL) { [self _addSynchronousHookWithName:@"nativeInjectHMRUpdate" usingBlock:^(NSString *sourceCode, NSString *sourceCodeURL) {
RCTJSCExecutor *strongSelf = weakSelf; RCTJSCExecutor *strongSelf = weakSelf;
if (!strongSelf.valid) { if (!strongSelf.valid) {
return; return;
@ -803,7 +803,7 @@ static void executeRandomAccessModule(RCTJSCExecutor *executor, uint32_t moduleI
[_performanceLogger setValue:0 forTag:RCTPLRAMNativeRequiresSize]; [_performanceLogger setValue:0 forTag:RCTPLRAMNativeRequiresSize];
__weak RCTJSCExecutor *weakSelf = self; __weak RCTJSCExecutor *weakSelf = self;
[self addSynchronousHookWithName:@"nativeRequire" usingBlock:^(NSNumber *moduleID) { [self _addSynchronousHookWithName:@"nativeRequire" usingBlock:^(NSNumber *moduleID) {
RCTJSCExecutor *strongSelf = weakSelf; RCTJSCExecutor *strongSelf = weakSelf;
if (!strongSelf || !moduleID) { if (!strongSelf || !moduleID) {
return; return;