Permalink
Browse files

Make RCTSamplingProfilerPackagerMethod not depend on RCTBridge

Reviewed By: javache

Differential Revision: D5245899

fbshipit-source-id: a99de4cbf0ddd9c8ee98cbbf438f8930a57e917c
  • Loading branch information...
fromcelticpark authored and facebook-github-bot committed Jun 15, 2017
1 parent d27ff20 commit c143313a20eab73e224fbb495e3d139ce8e507a0
@@ -11,7 +11,6 @@
#import <XCTest/XCTest.h>
#import <RCTTest/RCTTestRunner.h>
#import <React/RCTBridge+JavaScriptCore.h>
#import <React/RCTBridge.h>
#import <React/RCTDevMenu.h>
View
@@ -12,9 +12,9 @@
#import <objc/runtime.h>
#import "RCTBridge+JavaScriptCore.h"
#import "RCTConvert.h"
#import "RCTEventDispatcher.h"
#import "RCTJSEnvironment.h"
#import "RCTLog.h"
#import "RCTModuleData.h"
#import "RCTPerformanceLogger.h"
@@ -11,16 +11,19 @@
#import <React/RCTBridge.h>
@interface RCTBridge (JavaScriptCore)
@protocol RCTJSEnvironment <NSObject>
/**
* The JSContext used by the bridge.
*/
@property (nonatomic, readonly, strong) JSContext *jsContext;
/**
* The raw JSGlobalContextRef used by the bridge.
*/
@property (nonatomic, readonly, assign) JSGlobalContextRef jsContextRef;
@end
@interface RCTBridge (RCTJSEnvironment) <RCTJSEnvironment>
@end
@@ -11,6 +11,7 @@
#import <React/RCTBridge.h>
#import "RCTJSEnvironment.h"
#import "RCTReloadPackagerMethod.h"
#import "RCTSamplingProfilerPackagerMethod.h"
@@ -48,7 +49,7 @@ - (NSURL *)packagerURL
{
return @{
@"reload": [[RCTReloadPackagerMethod alloc] initWithBridge:_bridge],
@"pokeSamplingProfiler": [[RCTSamplingProfilerPackagerMethod alloc] initWithBridge:_bridge]
@"pokeSamplingProfiler": [[RCTSamplingProfilerPackagerMethod alloc] initWithJSEnvironment:_bridge]
};
}
@@ -9,13 +9,13 @@
#import <React/RCTPackagerClient.h>
@class RCTBridge;
@protocol RCTJSEnvironment;
#if RCT_DEV // Only supported in dev mode
@interface RCTSamplingProfilerPackagerMethod : NSObject <RCTPackagerClientMethod>
- (instancetype)initWithBridge:(RCTBridge *)bridge;
- (instancetype)initWithJSEnvironment:(id<RCTJSEnvironment>)jsEnvironment;
@end
@@ -11,29 +11,28 @@
#import <JavaScriptCore/JavaScriptCore.h>
#import <React/RCTBridge+JavaScriptCore.h>
#import <jschelpers/JavaScriptCore.h>
#import "RCTBridge.h"
#import "RCTJSEnvironment.h"
#import "RCTLog.h"
#if RCT_DEV // Only supported in dev mode
@implementation RCTSamplingProfilerPackagerMethod {
__weak RCTBridge *_bridge;
__weak id<RCTJSEnvironment> _jsEnvironment;
}
- (instancetype)initWithBridge:(RCTBridge *)bridge
- (instancetype)initWithJSEnvironment:(id<RCTJSEnvironment>)jsEnvironment
{
if (self = [super init]) {
_bridge = bridge;
_jsEnvironment = jsEnvironment;
}
return self;
}
- (void)handleRequest:(__unused id)params withResponder:(RCTPackagerClientResponder *)responder
{
JSGlobalContextRef globalContext = [_bridge jsContextRef];
JSGlobalContextRef globalContext = _jsEnvironment.jsContextRef;
if (!JSC_JSSamplingProfilerEnabled(globalContext)) {
[responder respondWithError:@"The JSSamplingProfiler is disabled. See 'iOS specific setup' section here https://fburl.com/u4lw7xeq for some help"];
return;
@@ -44,7 +43,7 @@ - (void)handleRequest:(__unused id)params withResponder:(RCTPackagerClientRespon
if (JSC_JSValueGetType(globalContext, jsResult) == kJSTypeNull) {
[responder respondWithResult:@"started"];
} else {
JSContext *context = [_bridge jsContext];
JSContext *context = _jsEnvironment.jsContext;
NSString *results = [[JSC_JSValue(globalContext) valueWithJSValueRef:jsResult inContext:context] toObject];
[responder respondWithResult:results];
}
@@ -15,12 +15,12 @@
#import <jschelpers/JavaScriptCore.h>
#import "RCTBridge+JavaScriptCore.h"
#import "RCTBridge+Private.h"
#import "RCTBridgeModule.h"
#import "RCTEventDispatcher.h"
#import "RCTInspectorDevServerHelper.h"
#import "RCTJSCSamplingProfiler.h"
#import "RCTJSEnvironment.h"
#import "RCTLog.h"
#import "RCTProfile.h"
#import "RCTUtils.h"
@@ -342,10 +342,6 @@
369123E11DDC75850095B341 /* RCTJSCSamplingProfiler.m in Sources */ = {isa = PBXBuildFile; fileRef = 369123E01DDC75850095B341 /* RCTJSCSamplingProfiler.m */; };
391E86A41C623EC800009732 /* RCTTouchEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 391E86A21C623EC800009732 /* RCTTouchEvent.m */; };
3D05745A1DE5FFF500184BB4 /* RCTJavaScriptLoader.mm in Sources */ = {isa = PBXBuildFile; fileRef = AC70D2E81DE489E4002E6351 /* RCTJavaScriptLoader.mm */; };
3D0976D51E9739ED00B9C6DD /* RCTBridge+JavaScriptCore.h in Headers */ = {isa = PBXBuildFile; fileRef = 3D0976D41E9739ED00B9C6DD /* RCTBridge+JavaScriptCore.h */; };
3D0976D61E9739F000B9C6DD /* RCTBridge+JavaScriptCore.h in Headers */ = {isa = PBXBuildFile; fileRef = 3D0976D41E9739ED00B9C6DD /* RCTBridge+JavaScriptCore.h */; };
3D0976D71E9739FB00B9C6DD /* RCTBridge+JavaScriptCore.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 3D0976D41E9739ED00B9C6DD /* RCTBridge+JavaScriptCore.h */; };
3D0976D81E973A0200B9C6DD /* RCTBridge+JavaScriptCore.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 3D0976D41E9739ED00B9C6DD /* RCTBridge+JavaScriptCore.h */; };
3D0B84221EC0B3F600B2BD8E /* RCTResizeMode.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 3D1FA0851DE4F3A000E03CC6 /* RCTResizeMode.h */; };
3D0B84231EC0B40D00B2BD8E /* RCTImageLoader.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 3D1FA0831DE4F3A000E03CC6 /* RCTImageLoader.h */; };
3D0B84241EC0B40D00B2BD8E /* RCTImageStoreManager.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 3D1FA0841DE4F3A000E03CC6 /* RCTImageStoreManager.h */; };
@@ -1065,6 +1061,10 @@
C6194AAF1EF156280034D062 /* RCTPackagerConnectionBridgeConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = C6194AAA1EF156280034D062 /* RCTPackagerConnectionBridgeConfig.m */; };
C6194AB01EF156280034D062 /* RCTPackagerConnectionConfig.h in Headers */ = {isa = PBXBuildFile; fileRef = C6194AAB1EF156280034D062 /* RCTPackagerConnectionConfig.h */; };
C6194AB11EF156280034D062 /* RCTPackagerConnectionConfig.h in Headers */ = {isa = PBXBuildFile; fileRef = C6194AAB1EF156280034D062 /* RCTPackagerConnectionConfig.h */; };
C6827DF61EF17CCC00D66BEF /* RCTJSEnvironment.h in Headers */ = {isa = PBXBuildFile; fileRef = C6827DF51EF17CCC00D66BEF /* RCTJSEnvironment.h */; };
C6827DF71EF17CCC00D66BEF /* RCTJSEnvironment.h in Headers */ = {isa = PBXBuildFile; fileRef = C6827DF51EF17CCC00D66BEF /* RCTJSEnvironment.h */; };
C6827DFB1EF1800E00D66BEF /* RCTJSEnvironment.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = C6827DF51EF17CCC00D66BEF /* RCTJSEnvironment.h */; };
C6827DFC1EF1801B00D66BEF /* RCTJSEnvironment.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = C6827DF51EF17CCC00D66BEF /* RCTJSEnvironment.h */; };
CF2731C01E7B8DE40044CA4F /* RCTDeviceInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = CF2731BE1E7B8DE40044CA4F /* RCTDeviceInfo.h */; };
CF2731C11E7B8DE40044CA4F /* RCTDeviceInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = CF2731BF1E7B8DE40044CA4F /* RCTDeviceInfo.m */; };
CF2731C21E7B8DEF0044CA4F /* RCTDeviceInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = CF2731BE1E7B8DE40044CA4F /* RCTDeviceInfo.h */; };
@@ -1171,6 +1171,7 @@
dstPath = include/React;
dstSubfolderSpec = 16;
files = (
C6827DFC1EF1801B00D66BEF /* RCTJSEnvironment.h in Copy Headers */,
59EB6DC01EBD70130072A5E7 /* RCTUIManagerObserverCoordinator.h in Copy Headers */,
59B1EBCA1EBD47520047B19B /* RCTShadowView+Layout.h in Copy Headers */,
3D0B84271EC0B45400B2BD8E /* RCTLinkingManager.h in Copy Headers */,
@@ -1182,7 +1183,6 @@
3D383D201EBD27AF005632C8 /* RCTBridge+Private.h in Copy Headers */,
3D7BFD351EA8E43F008DFB7A /* RCTDevSettings.h in Copy Headers */,
3D7BFD331EA8E433008DFB7A /* RCTPackagerClient.h in Copy Headers */,
3D0976D71E9739FB00B9C6DD /* RCTBridge+JavaScriptCore.h in Copy Headers */,
3DA981E91E5B0F7F004F2374 /* RCTJSCSamplingProfiler.h in Copy Headers */,
3DA981EA1E5B0F7F004F2374 /* RCTAccessibilityManager.h in Copy Headers */,
3DA981EB1E5B0F7F004F2374 /* RCTAlertManager.h in Copy Headers */,
@@ -1391,12 +1391,12 @@
dstPath = include/React;
dstSubfolderSpec = 16;
files = (
C6827DFB1EF1800E00D66BEF /* RCTJSEnvironment.h in Copy Headers */,
59EB6DBF1EBD6FFC0072A5E7 /* RCTUIManagerObserverCoordinator.h in Copy Headers */,
59B1EBC91EBD46250047B19B /* RCTShadowView+Layout.h in Copy Headers */,
3D383D1F1EBD27A8005632C8 /* RCTBridge+Private.h in Copy Headers */,
3D7BFD311EA8E41F008DFB7A /* RCTPackagerClient.h in Copy Headers */,
3D7BFD291EA8E37B008DFB7A /* RCTDevSettings.h in Copy Headers */,
3D0976D81E973A0200B9C6DD /* RCTBridge+JavaScriptCore.h in Copy Headers */,
3D80D91F1DF6FA890028D040 /* RCTImageLoader.h in Copy Headers */,
3D80D9201DF6FA890028D040 /* RCTImageStoreManager.h in Copy Headers */,
3D80D9211DF6FA890028D040 /* RCTResizeMode.h in Copy Headers */,
@@ -1819,7 +1819,6 @@
369123E01DDC75850095B341 /* RCTJSCSamplingProfiler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTJSCSamplingProfiler.m; sourceTree = "<group>"; };
391E86A21C623EC800009732 /* RCTTouchEvent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTTouchEvent.m; sourceTree = "<group>"; };
391E86A31C623EC800009732 /* RCTTouchEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTTouchEvent.h; sourceTree = "<group>"; };
3D0976D41E9739ED00B9C6DD /* RCTBridge+JavaScriptCore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "RCTBridge+JavaScriptCore.h"; sourceTree = "<group>"; };
3D0B84281EC0B49400B2BD8E /* RCTTVRemoteHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTTVRemoteHandler.h; sourceTree = "<group>"; };
3D0B84291EC0B49400B2BD8E /* RCTTVRemoteHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTTVRemoteHandler.m; sourceTree = "<group>"; };
3D0B842D1EC0B51200B2BD8E /* RCTTVNavigationEventEmitter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTTVNavigationEventEmitter.h; sourceTree = "<group>"; };
@@ -1985,6 +1984,7 @@
C6194AA91EF156280034D062 /* RCTPackagerConnectionBridgeConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTPackagerConnectionBridgeConfig.h; sourceTree = "<group>"; };
C6194AAA1EF156280034D062 /* RCTPackagerConnectionBridgeConfig.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTPackagerConnectionBridgeConfig.m; sourceTree = "<group>"; };
C6194AAB1EF156280034D062 /* RCTPackagerConnectionConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTPackagerConnectionConfig.h; sourceTree = "<group>"; };
C6827DF51EF17CCC00D66BEF /* RCTJSEnvironment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTJSEnvironment.h; sourceTree = "<group>"; };
CF2731BE1E7B8DE40044CA4F /* RCTDeviceInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTDeviceInfo.h; sourceTree = "<group>"; };
CF2731BF1E7B8DE40044CA4F /* RCTDeviceInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTDeviceInfo.m; sourceTree = "<group>"; };
E3BBC8EB1ADE6F47001BBD81 /* RCTTextDecorationLineType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RCTTextDecorationLineType.h; sourceTree = "<group>"; };
@@ -2522,7 +2522,6 @@
83CBBA4B1A601E3B00E9B192 /* RCTAssert.m */,
83CBBA5E1A601EAA00E9B192 /* RCTBridge.h */,
83CBBA5F1A601EAA00E9B192 /* RCTBridge.m */,
3D0976D41E9739ED00B9C6DD /* RCTBridge+JavaScriptCore.h */,
14A43DB81C1F849600794BC8 /* RCTBridge+Private.h */,
1482F9E61B55B927000ADFF3 /* RCTBridgeDelegate.h */,
13AFBCA11C07287B00BBAEAA /* RCTBridgeMethod.h */,
@@ -2549,6 +2548,7 @@
AC70D2E81DE489E4002E6351 /* RCTJavaScriptLoader.mm */,
135A9BF91E7B0EAE00587AEB /* RCTJSCErrorHandling.h */,
135A9BFA1E7B0EAE00587AEB /* RCTJSCErrorHandling.mm */,
C6827DF51EF17CCC00D66BEF /* RCTJSEnvironment.h */,
008341F51D1DB34400876D9A /* RCTJSStackFrame.h */,
008341F41D1DB34400876D9A /* RCTJSStackFrame.m */,
13A1F71C1A75392D00D3D453 /* RCTKeyCommands.h */,
@@ -2688,6 +2688,7 @@
3D302F261DF828F800D6DDAE /* RCTResizeMode.h in Headers */,
3D302F271DF828F800D6DDAE /* RCTLinkingManager.h in Headers */,
3D7BFD161EA8E351008DFB7A /* RCTPackagerClient.h in Headers */,
C6827DF71EF17CCC00D66BEF /* RCTJSEnvironment.h in Headers */,
3D302F281DF828F800D6DDAE /* RCTNetworking.h in Headers */,
3D302F291DF828F800D6DDAE /* RCTNetworkTask.h in Headers */,
3D7BFD2E1EA8E3FA008DFB7A /* RCTReconnectingWebSocket.h in Headers */,
@@ -2755,7 +2756,6 @@
3D302F621DF828F800D6DDAE /* RCTSourceCode.h in Headers */,
3D302F631DF828F800D6DDAE /* RCTStatusBarManager.h in Headers */,
3D302F641DF828F800D6DDAE /* RCTTiming.h in Headers */,
3D0976D61E9739F000B9C6DD /* RCTBridge+JavaScriptCore.h in Headers */,
3D302F651DF828F800D6DDAE /* RCTUIManager.h in Headers */,
3D302F661DF828F800D6DDAE /* RCTFPSGraph.h in Headers */,
3D302F681DF828F800D6DDAE /* RCTMacros.h in Headers */,
@@ -3061,7 +3061,6 @@
3D80DA721DF820620028D040 /* RCTModalHostViewManager.h in Headers */,
13134C9C1E296B2A00B9F3CB /* RCTCxxModule.h in Headers */,
3D80DA731DF820620028D040 /* RCTNavigator.h in Headers */,
3D0976D51E9739ED00B9C6DD /* RCTBridge+JavaScriptCore.h in Headers */,
3D80DA741DF820620028D040 /* RCTNavigatorManager.h in Headers */,
3D80DA751DF820620028D040 /* RCTNavItem.h in Headers */,
3D80DA761DF820620028D040 /* RCTNavItemManager.h in Headers */,
@@ -3079,6 +3078,7 @@
3D80DA7F1DF820620028D040 /* RCTScrollView.h in Headers */,
3D80DA801DF820620028D040 /* RCTScrollViewManager.h in Headers */,
3D80DA811DF820620028D040 /* RCTSegmentedControl.h in Headers */,
C6827DF61EF17CCC00D66BEF /* RCTJSEnvironment.h in Headers */,
3D80DA821DF820620028D040 /* RCTSegmentedControlManager.h in Headers */,
3D80DA831DF820620028D040 /* RCTShadowView.h in Headers */,
3D80DA841DF820620028D040 /* RCTSlider.h in Headers */,
Oops, something went wrong.

1 comment on commit c143313

@gre

This comment has been minimized.

Show comment
Hide comment
@gre

gre Aug 5, 2017

Contributor

this commit breaks third party doing #import <React/RCTBridge+JavaScriptCore.h> – ctx gre/gl-react#146 (comment) (I need bridge.jsContextRef to instrument some JSC c++ code that implement webgl)

Contributor

gre commented on c143313 Aug 5, 2017

this commit breaks third party doing #import <React/RCTBridge+JavaScriptCore.h> – ctx gre/gl-react#146 (comment) (I need bridge.jsContextRef to instrument some JSC c++ code that implement webgl)

Please sign in to comment.