Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions React/Executors/RCTJSCExecutor.mm
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#import "RCTBridge+Private.h"
#import "RCTDefines.h"
#import "RCTDevMenu.h"
#import "RCTDevSettings.h"
#import "RCTJSCErrorHandling.h"
#import "RCTJSCProfiler.h"
#import "RCTJavaScriptLoader.h"
Expand All @@ -38,8 +39,6 @@
RCT_EXTERN NSString *const RCTFBJSContextClassKey = @"_RCTFBJSContextClassKey";
RCT_EXTERN NSString *const RCTFBJSValueClassKey = @"_RCTFBJSValueClassKey";

static NSString *const RCTJSCProfilerEnabledDefaultsKey = @"RCTJSCProfilerEnabled";

struct __attribute__((packed)) ModuleData {
uint32_t offset;
uint32_t size;
Expand Down Expand Up @@ -169,7 +168,11 @@ @implementation RCTJSCExecutor
static void RCTInstallJSCProfiler(RCTBridge *bridge, JSContextRef context)
{
if (RCTJSCProfilerIsSupported()) {
[bridge.devMenu addItem:[RCTDevMenuItem toggleItemWithKey:RCTJSCProfilerEnabledDefaultsKey title:@"Start Profiling" selectedTitle:@"Stop Profiling" handler:^(BOOL shouldStart) {
[bridge.devMenu addItem:[RCTDevMenuItem buttonItemWithTitleBlock:^NSString *{
return (bridge.devSettings.isJSCProfilingEnabled) ? @"Stop Profiling" : @"Start Profiling";
} handler:^{
BOOL shouldStart = !bridge.devSettings.isJSCProfilingEnabled;
bridge.devSettings.isJSCProfilingEnabled = shouldStart;
if (shouldStart != RCTJSCProfilerIsProfiling(context)) {
if (shouldStart) {
RCTJSCProfilerStart(context);
Expand Down Expand Up @@ -309,7 +312,7 @@ - (void)setUp
} else {
if (self->_useCustomJSCLibrary) {
JSC_configureJSCForIOS(true, RCTJSONStringify(@{
@"StartSamplingProfilerOnInit": @(self->_bridge.devMenu.startSamplingProfilerOnLaunch)
@"StartSamplingProfilerOnInit": @(self->_bridge.devSettings.startSamplingProfilerOnLaunch)
}, NULL).UTF8String);
}
contextRef = JSC_JSGlobalContextCreateInGroup(self->_useCustomJSCLibrary, nullptr, nullptr);
Expand Down Expand Up @@ -401,16 +404,7 @@ - (void)setUp
if (!strongSelf.valid || !weakContext) {
return;
}

// JSPokeSamplingProfiler() toggles the profiling process
JSGlobalContextRef ctx = weakContext.JSGlobalContextRef;
JSValueRef jsResult = JSC_JSPokeSamplingProfiler(ctx);

if (JSC_JSValueGetType(ctx, jsResult) != kJSTypeNull) {
NSString *results = [[JSC_JSValue(ctx) valueWithJSValueRef:jsResult inContext:weakContext] toObject];
JSCSamplingProfiler *profilerModule = [strongSelf->_bridge moduleForClass:[JSCSamplingProfiler class]];
[profilerModule operationCompletedWithResults:results];
}
[weakSelf.bridge.devSettings toggleJSCSamplingProfiler];
}]];

// Allow for the profiler to be poked from JS code as well
Expand Down
49 changes: 16 additions & 33 deletions React/Modules/RCTDevMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,59 +20,44 @@
@interface RCTDevMenu : NSObject

/**
* Is the menu enabled. The menu is enabled by default if RCT_DEV=1, but
* you may wish to disable it so that you can provide your own shake handler.
* Deprecated, use RCTDevSettings instead.
*/
@property (nonatomic, assign) BOOL shakeToShow;
@property (nonatomic, assign) BOOL shakeToShow DEPRECATED_ATTRIBUTE;

/**
* Enables performance profiling.
* Deprecated, use RCTDevSettings instead.
*/
@property (nonatomic, assign) BOOL profilingEnabled;
@property (nonatomic, assign) BOOL profilingEnabled DEPRECATED_ATTRIBUTE;

/**
* Enables starting of profiling sampler on launch
* Deprecated, use RCTDevSettings instead.
*/
@property (nonatomic, assign) BOOL startSamplingProfilerOnLaunch;
@property (nonatomic, assign) BOOL liveReloadEnabled DEPRECATED_ATTRIBUTE;

/**
* Enables automatic polling for JS code changes. Only applicable when
* running the app from a server.
* Deprecated, use RCTDevSettings instead.
*/
@property (nonatomic, assign) BOOL liveReloadEnabled;

/**
* Enables hot loading. Currently not supported in open source.
*/
@property (nonatomic, assign) BOOL hotLoadingEnabled;

/**
* Shows the FPS monitor for the JS and Main threads.
*/
@property (nonatomic, assign) BOOL showFPS;
@property (nonatomic, assign) BOOL hotLoadingEnabled DEPRECATED_ATTRIBUTE;

/**
* Presented items in development menu
*/
@property (nonatomic, copy, readonly) NSArray<RCTDevMenuItem *> *presentedItems;


/**
* Detect if actions sheet (development menu) is shown
*/
- (BOOL)isActionSheetShown;


/**
* Manually show the dev menu (can be called from JS).
*/
- (void)show;

/**
* Manually reload the application. Equivalent to calling [bridge reload]
* directly, but can be called from JS.
* Deprecated, use RCTDevSettings instead.
*/
- (void)reload;
- (void)reload DEPRECATED_ATTRIBUTE;

/**
* Deprecated. Use the `-addItem:` method instead.
Expand Down Expand Up @@ -101,15 +86,13 @@
handler:(void(^)(void))handler;

/**
* This creates an item with a toggle behavior. The key is used to store the
* state of the toggle. For toggle items, the handler will be called immediately
* after the item is added if the item was already selected when the module was
* last loaded.
* This creates an item with a simple push-button interface, used to trigger an
* action. getTitleForPresentation is called each time the item is about to be
* presented, and should return the item's title.
*/
+ (instancetype)toggleItemWithKey:(NSString *)key
title:(NSString *)title
selectedTitle:(NSString *)selectedTitle
handler:(void(^)(BOOL selected))handler;
+ (instancetype)buttonItemWithTitleBlock:(NSString * (^)(void))getTitleForPresentation
handler:(void(^)(void))handler;

@end

/**
Expand Down
Loading