Permalink
Browse files

Add a default context name to RCTJSCExecutor

Reviewed By: mmmulani

Differential Revision: D4015748

fbshipit-source-id: 077287b8438aa13f2a1479d68eacb0662bf295aa
  • Loading branch information...
javache authored and Facebook Github Bot committed Oct 14, 2016
1 parent 82d6ac1 commit 8355ef91adde2a0279613193d4d8ff45d6f6db30
@@ -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 @@ - (instancetype)initWithJSContext:(JSContext *)context
{
if ((self = [super init])) {
_context = context;
+ _context.name = @"RCTJSContext";
_javaScriptThread = javaScriptThread;
/**
@@ -436,7 +437,6 @@ - (void)setUp
/** 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 @@ - (void)invalidate
_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 RandomAccessBundleStartupCode readRAMBundle(file_ptr bundle, RandomAccess
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 @@ class JSCExecutor : public JSExecutor {
virtual void handleMemoryPressureModerate() override;
virtual void handleMemoryPressureCritical() override;
virtual void destroy() override;
+ void setContextName(const std::string& name);
private:
JSGlobalContextRef m_context;

0 comments on commit 8355ef9

Please sign in to comment.