diff --git a/React/Executors/RCTJSCExecutor.h b/React/Executors/RCTJSCExecutor.h index 8a5567a27f..3a7ae96f30 100644 --- a/React/Executors/RCTJSCExecutor.h +++ b/React/Executors/RCTJSCExecutor.h @@ -72,6 +72,12 @@ RCT_EXTERN NSString *const RCTFBJSValueClassKey; */ @property (nonatomic, readonly, assign) BOOL useCustomJSCLibrary; +/** + * Specify a name for the JSContext used, which will be visible in debugging tools + * @default is "RCTJSContext" + */ +@property (nonatomic, copy) NSString *contextName; + /** * Inits a new executor instance with given flag that's used * to initialize RCTJSCWrapper. diff --git a/React/Executors/RCTJSCExecutor.mm b/React/Executors/RCTJSCExecutor.mm index db5cea01d0..296474b4b9 100644 --- a/React/Executors/RCTJSCExecutor.mm +++ b/React/Executors/RCTJSCExecutor.mm @@ -108,6 +108,7 @@ struct RCTJSContextData { { if ((self = [super init])) { _context = context; + _context.name = @"RCTJSContext"; _javaScriptThread = javaScriptThread; /** @@ -436,7 +437,6 @@ static NSThread *newJavaScriptThread(void) /** Installs synchronous hooks that don't require a weak reference back to the RCTJSCExecutor. */ static void installBasicSynchronousHooksOnContext(JSContext *context) { - context[@"noop"] = ^{}; context[@"nativeLoggingHook"] = ^(NSString *message, NSNumber *logLevel) { RCTLogLevel level = RCTLogLevelInfo; if (logLevel) { @@ -500,11 +500,21 @@ static void installBasicSynchronousHooksOnContext(JSContext *context) _valid = NO; -#if RCT_DEV +#if RCT_PROFILE [[NSNotificationCenter defaultCenter] removeObserver:self]; #endif } +- (NSString *)contextName +{ + return [_context.context name]; +} + +RCT_EXPORT_METHOD(setContextName:(nonnull NSString *)contextName) +{ + [_context.context setName:contextName]; +} + - (void)dealloc { [self invalidate]; @@ -917,15 +927,6 @@ static NSData *loadRAMBundle(NSURL *sourceURL, NSError **error, RandomAccessBund return [NSData dataWithBytesNoCopy:startupCode.code.release() length:startupCode.size freeWhenDone:YES]; } -RCT_EXPORT_METHOD(setContextName:(nonnull NSString *)name) -{ - if (_jscWrapper->JSGlobalContextSetName != NULL) { - JSStringRef JSName = _jscWrapper->JSStringCreateWithCFString((__bridge CFStringRef)name); - _jscWrapper->JSGlobalContextSetName(_context.context.JSGlobalContextRef, JSName); - _jscWrapper->JSStringRelease(JSName); - } -} - @end @implementation RCTJSContextProvider diff --git a/ReactCommon/cxxreact/JSCExecutor.cpp b/ReactCommon/cxxreact/JSCExecutor.cpp index 210ee64e8c..15e073b7df 100644 --- a/ReactCommon/cxxreact/JSCExecutor.cpp +++ b/ReactCommon/cxxreact/JSCExecutor.cpp @@ -200,6 +200,11 @@ void JSCExecutor::destroy() { }); } +void JSCExecutor::setContextName(const std::string& name) { + String jsName = String(name.c_str()); + JSGlobalContextSetName(m_context, static_cast(jsName)); +} + void JSCExecutor::initOnJSVMThread() throw(JSException) { SystraceSection s("JSCExecutor.initOnJSVMThread"); diff --git a/ReactCommon/cxxreact/JSCExecutor.h b/ReactCommon/cxxreact/JSCExecutor.h index ce7d4992f6..0462abc712 100644 --- a/ReactCommon/cxxreact/JSCExecutor.h +++ b/ReactCommon/cxxreact/JSCExecutor.h @@ -92,6 +92,7 @@ public: virtual void handleMemoryPressureModerate() override; virtual void handleMemoryPressureCritical() override; virtual void destroy() override; + void setContextName(const std::string& name); private: JSGlobalContextRef m_context;