Add a default context name to RCTJSCExecutor
Reviewed By: mmmulani Differential Revision: D4015748 fbshipit-source-id: 077287b8438aa13f2a1479d68eacb0662bf295aa
This commit is contained in:
parent
82d6ac1a51
commit
8355ef91ad
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<JSStringRef>(jsName));
|
||||
}
|
||||
|
||||
void JSCExecutor::initOnJSVMThread() throw(JSException) {
|
||||
SystraceSection s("JSCExecutor.initOnJSVMThread");
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue