From 325228d6cf69535a45a736389996f2b2e9a36a7f Mon Sep 17 00:00:00 2001 From: Marc Horowitz Date: Wed, 19 Apr 2017 16:53:44 -0700 Subject: [PATCH] Remove RCTBatchedBridge rule and all uses from the tree Reviewed By: AaaChiuuu, javache Differential Revision: D4889438 fbshipit-source-id: ba103ace8802f0976e09af6b491442e9aa723f49 --- .../UIExplorerUnitTests/RCTAllocationTests.m | 41 ++----------------- .../UIExplorerUnitTests/RCTDevMenuTests.m | 16 +++++++- .../RCTEventDispatcherTests.m | 13 +++++- .../RCTModuleInitNotificationRaceTests.m | 2 - .../UIExplorerUnitTests/RCTModuleInitTests.m | 2 - Libraries/RCTTest/RCTTestRunner.m | 1 - React/Executors/RCTJSCExecutor.h | 17 -------- React/Executors/RCTJSCExecutor.mm | 8 ---- 8 files changed, 31 insertions(+), 69 deletions(-) diff --git a/Examples/UIExplorer/UIExplorerUnitTests/RCTAllocationTests.m b/Examples/UIExplorer/UIExplorerUnitTests/RCTAllocationTests.m index 97a1c9654..def2c5246 100644 --- a/Examples/UIExplorer/UIExplorerUnitTests/RCTAllocationTests.m +++ b/Examples/UIExplorer/UIExplorerUnitTests/RCTAllocationTests.m @@ -17,7 +17,6 @@ #import #import -#import #import #import @@ -78,9 +77,10 @@ RCT_EXPORT_METHOD(test:(__unused NSString *)a NSString *bundleContents = @"var __fbBatchedBridge = {" - " callFunctionReturnFlushedQueue: function() {}," - " invokeCallbackAndReturnFlushedQueue: function() {}," - " flushedQueue: function() {}," + " callFunctionReturnFlushedQueue: function() { return null; }," + " invokeCallbackAndReturnFlushedQueue: function() { return null; }," + " flushedQueue: function() { return null; }," + " callFunctionReturnResultAndFlushedQueue: function() { return null; }," "};"; NSURL *tempDir = [NSURL fileURLWithPath:NSTemporaryDirectory() isDirectory:YES]; @@ -167,39 +167,6 @@ RCT_EXPORT_METHOD(test:(__unused NSString *)a XCTAssertNil(weakMethod, @"RCTModuleMethod should have been deallocated"); } -- (void)testJavaScriptExecutorIsDeallocated -{ - __weak id weakExecutor; - @autoreleasepool { - RCTBridge *bridge = [[RCTBridge alloc] initWithBundleURL:_bundleURL - moduleProvider:nil - launchOptions:nil]; - weakExecutor = [bridge.batchedBridge valueForKey:@"javaScriptExecutor"]; - XCTAssertNotNil(weakExecutor, @"JavaScriptExecutor should have been created"); - (void)bridge; - } - - RUN_RUNLOOP_WHILE(weakExecutor); - XCTAssertNil(weakExecutor, @"JavaScriptExecutor should have been released"); -} - -- (void)testJavaScriptContextIsDeallocated -{ - __weak id weakContext; - @autoreleasepool { - RCTBridge *bridge = [[RCTBridge alloc] initWithBundleURL:_bundleURL - moduleProvider:nil - launchOptions:nil]; - id executor = [bridge.batchedBridge valueForKey:@"javaScriptExecutor"]; - RUN_RUNLOOP_WHILE(!(weakContext = [executor valueForKey:@"_context"])); - XCTAssertNotNil(weakContext, @"RCTJavaScriptContext should have been created"); - (void)bridge; - } - - RUN_RUNLOOP_WHILE(weakContext); - XCTAssertNil(weakContext, @"RCTJavaScriptContext should have been deallocated"); -} - - (void)testContentViewIsInvalidated { RCTBridge *bridge = [[RCTBridge alloc] initWithBundleURL:_bundleURL diff --git a/Examples/UIExplorer/UIExplorerUnitTests/RCTDevMenuTests.m b/Examples/UIExplorer/UIExplorerUnitTests/RCTDevMenuTests.m index 6f12670d3..d86ccf31a 100644 --- a/Examples/UIExplorer/UIExplorerUnitTests/RCTDevMenuTests.m +++ b/Examples/UIExplorer/UIExplorerUnitTests/RCTDevMenuTests.m @@ -14,9 +14,22 @@ #import +#import #import #import +#define RUN_RUNLOOP_WHILE(CONDITION) \ +{ \ + NSDate *timeout = [NSDate dateWithTimeIntervalSinceNow:5]; \ + while ((CONDITION)) { \ + [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; \ + if ([timeout timeIntervalSinceNow] <= 0) { \ + XCTFail(@"Runloop timed out before condition was met"); \ + break; \ + } \ + } \ +} + typedef void(^RCTDevMenuAlertActionHandler)(UIAlertAction *action); @interface RCTDevMenu () @@ -42,6 +55,8 @@ typedef void(^RCTDevMenuAlertActionHandler)(UIAlertAction *action); _bridge = [[RCTBridge alloc] initWithBundleURL:[bundle URLForResource:@"UIExplorerUnitTestsBundle" withExtension:@"js"] moduleProvider:nil launchOptions:nil]; + + RUN_RUNLOOP_WHILE(_bridge.isLoading); } - (void)testShowCreatingActionSheet @@ -51,7 +66,6 @@ typedef void(^RCTDevMenuAlertActionHandler)(UIAlertAction *action); XCTAssertTrue([_bridge.devMenu isActionSheetShown]); } - - (void)testClosingActionSheetAfterAction { for (RCTDevMenuItem *item in _bridge.devMenu.presentedItems) { diff --git a/Examples/UIExplorer/UIExplorerUnitTests/RCTEventDispatcherTests.m b/Examples/UIExplorer/UIExplorerUnitTests/RCTEventDispatcherTests.m index fa6adf0cc..cdaf134e6 100644 --- a/Examples/UIExplorer/UIExplorerUnitTests/RCTEventDispatcherTests.m +++ b/Examples/UIExplorer/UIExplorerUnitTests/RCTEventDispatcherTests.m @@ -65,6 +65,17 @@ @end +@interface RCTDummyBridge : RCTBridge +- (void)dispatchBlock:(dispatch_block_t)block + queue:(dispatch_queue_t)queue; +@end + +@implementation RCTDummyBridge +- (void)dispatchBlock:(dispatch_block_t)block + queue:(dispatch_queue_t)queue +{} +@end + @interface RCTEventDispatcherTests : XCTestCase @end @@ -84,7 +95,7 @@ { [super setUp]; - _bridge = [OCMockObject mockForClass:[RCTBatchedBridge class]]; + _bridge = [OCMockObject mockForClass:[RCTDummyBridge class]]; _eventDispatcher = [RCTEventDispatcher new]; [_eventDispatcher setValue:_bridge forKey:@"bridge"]; diff --git a/Examples/UIExplorer/UIExplorerUnitTests/RCTModuleInitNotificationRaceTests.m b/Examples/UIExplorer/UIExplorerUnitTests/RCTModuleInitNotificationRaceTests.m index b37944da1..78d10d83b 100644 --- a/Examples/UIExplorer/UIExplorerUnitTests/RCTModuleInitNotificationRaceTests.m +++ b/Examples/UIExplorer/UIExplorerUnitTests/RCTModuleInitNotificationRaceTests.m @@ -121,9 +121,7 @@ RCT_EXPORT_MODULE() [super tearDown]; _notificationObserver = nil; - id jsExecutor = _bridge.batchedBridge.javaScriptExecutor; [_bridge invalidate]; - RUN_RUNLOOP_WHILE(jsExecutor.isValid); _bridge = nil; } diff --git a/Examples/UIExplorer/UIExplorerUnitTests/RCTModuleInitTests.m b/Examples/UIExplorer/UIExplorerUnitTests/RCTModuleInitTests.m index 20ab69800..08ca7a33e 100644 --- a/Examples/UIExplorer/UIExplorerUnitTests/RCTModuleInitTests.m +++ b/Examples/UIExplorer/UIExplorerUnitTests/RCTModuleInitTests.m @@ -179,9 +179,7 @@ RCT_EXPORT_MODULE() [[NSNotificationCenter defaultCenter] removeObserver:self name:RCTDidInitializeModuleNotification object:nil]; - id jsExecutor = _bridge.batchedBridge.javaScriptExecutor; [_bridge invalidate]; - RUN_RUNLOOP_WHILE(jsExecutor.isValid); _bridge = nil; } diff --git a/Libraries/RCTTest/RCTTestRunner.m b/Libraries/RCTTest/RCTTestRunner.m index e32af66bc..ae4009a02 100644 --- a/Libraries/RCTTest/RCTTestRunner.m +++ b/Libraries/RCTTest/RCTTestRunner.m @@ -10,7 +10,6 @@ #import "RCTTestRunner.h" #import -#import #import #import #import diff --git a/React/Executors/RCTJSCExecutor.h b/React/Executors/RCTJSCExecutor.h index afec28e44..e03868503 100644 --- a/React/Executors/RCTJSCExecutor.h +++ b/React/Executors/RCTJSCExecutor.h @@ -27,23 +27,6 @@ RCT_EXTERN NSString *const RCTJSCThreadName; */ RCT_EXTERN NSString *const RCTJavaScriptContextCreatedNotification; -/** - * A key to a reference to a JSContext class, held in the the current thread's - * dictionary. The reference would point to the JSContext class in the JS VM - * used in React (or ComponenetScript). It is recommended not to access it - * through the thread's dictionary, but rather to use the `FBJSCurrentContext()` - * accessor, which will return the current JSContext in the currently used VM. - */ -RCT_EXTERN NSString *const RCTFBJSContextClassKey; - -/** - * A key to a reference to a JSValue class, held in the the current thread's - * dictionary. The reference would point to the JSValue class in the JS VM - * used in React (or ComponenetScript). It is recommended not to access it - * through the thread's dictionary, but rather to use the `FBJSValue()` accessor. - */ -RCT_EXTERN NSString *const RCTFBJSValueClassKey; - /** * Uses a JavaScriptCore context as the execution engine. */ diff --git a/React/Executors/RCTJSCExecutor.mm b/React/Executors/RCTJSCExecutor.mm index febb80afc..b0a2c3fd0 100644 --- a/React/Executors/RCTJSCExecutor.mm +++ b/React/Executors/RCTJSCExecutor.mm @@ -38,8 +38,6 @@ NSString *const RCTJSCThreadName = @"com.facebook.react.JavaScript"; NSString *const RCTJavaScriptContextCreatedNotification = @"RCTJavaScriptContextCreatedNotification"; -RCT_EXTERN NSString *const RCTFBJSContextClassKey = @"_RCTFBJSContextClassKey"; -RCT_EXTERN NSString *const RCTFBJSValueClassKey = @"_RCTFBJSValueClassKey"; struct __attribute__((packed)) ModuleData { uint32_t offset; @@ -331,12 +329,6 @@ static NSThread *newJavaScriptThread(void) installBasicSynchronousHooksOnContext(context); } - NSMutableDictionary *threadDictionary = [[NSThread currentThread] threadDictionary]; - if (!threadDictionary[RCTFBJSContextClassKey] || !threadDictionary[RCTFBJSValueClassKey]) { - threadDictionary[RCTFBJSContextClassKey] = JSC_JSContext(contextRef); - threadDictionary[RCTFBJSValueClassKey] = JSC_JSValue(contextRef); - } - RCTFBQuickPerformanceLoggerConfigureHooks(context.JSGlobalContextRef); __weak RCTJSCExecutor *weakSelf = self;