Skip to content

Commit c953aa7

Browse files
committed
[Executor] Make executor ID functions non-static to fix ASan
Summary: When `RCTGetExecutorID` was a static function in the header file, it would return nil when the app was running with ASan enabled even though directly calling `objc_getAssociatedObject(executor, RCTJavaScriptExecutorID)` returned the correct ID as an NSNumber. Moving this function into the .m file fixes this issue. Closes facebook#1712 Github Author: James Ide <ide@jameside.com> Test Plan: Run the UIExplorer with ASan enabled in Xcode 7. Before this diff, the app would just hang since the executor was unable to read a valid ID and so it would bail out from running JS. With this diff the executor runs the JS and the UIExplorer works fine.
1 parent 7196445 commit c953aa7

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

React/Base/RCTJavaScriptExecutor.h

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,5 @@ typedef void (^RCTJavaScriptCallback)(id json, NSError *error);
6767

6868
@end
6969

70-
static const char *RCTJavaScriptExecutorID = "RCTJavaScriptExecutorID";
71-
__used static void RCTSetExecutorID(id<RCTJavaScriptExecutor> executor)
72-
{
73-
static NSUInteger executorID = 0;
74-
if (executor) {
75-
objc_setAssociatedObject(executor, RCTJavaScriptExecutorID, @(++executorID), OBJC_ASSOCIATION_RETAIN);
76-
}
77-
}
78-
79-
__used static NSNumber *RCTGetExecutorID(id<RCTJavaScriptExecutor> executor)
80-
{
81-
return executor ? objc_getAssociatedObject(executor, RCTJavaScriptExecutorID) : @0;
82-
}
70+
void RCTSetExecutorID(id<RCTJavaScriptExecutor> executor);
71+
NSNumber *RCTGetExecutorID(id<RCTJavaScriptExecutor> executor);

React/Base/RCTJavaScriptExecutor.m

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
#import "RCTJavaScriptExecutor.h"
11+
12+
13+
static const char *RCTJavaScriptExecutorID = "RCTJavaScriptExecutorID";
14+
15+
void RCTSetExecutorID(id<RCTJavaScriptExecutor> executor)
16+
{
17+
static NSUInteger executorID = 0;
18+
if (executor) {
19+
objc_setAssociatedObject(executor, RCTJavaScriptExecutorID, @(++executorID), OBJC_ASSOCIATION_RETAIN);
20+
}
21+
}
22+
23+
NSNumber *RCTGetExecutorID(id<RCTJavaScriptExecutor> executor)
24+
{
25+
return executor ? objc_getAssociatedObject(executor, RCTJavaScriptExecutorID) : @0;
26+
}

React/React.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
58114A501AAE93D500E7D092 /* RCTAsyncLocalStorage.m in Sources */ = {isa = PBXBuildFile; fileRef = 58114A4E1AAE93D500E7D092 /* RCTAsyncLocalStorage.m */; };
6666
58C571C11AA56C1900CDF9C8 /* RCTDatePickerManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 58C571BF1AA56C1900CDF9C8 /* RCTDatePickerManager.m */; };
6767
63F014C01B02080B003B75D2 /* RCTPointAnnotation.m in Sources */ = {isa = PBXBuildFile; fileRef = 63F014BF1B02080B003B75D2 /* RCTPointAnnotation.m */; };
68+
783ABB351B38A9D3003FFD95 /* RCTJavaScriptExecutor.m in Sources */ = {isa = PBXBuildFile; fileRef = 783ABB341B38A9D3003FFD95 /* RCTJavaScriptExecutor.m */; };
6869
830A229E1A66C68A008503DA /* RCTRootView.m in Sources */ = {isa = PBXBuildFile; fileRef = 830A229D1A66C68A008503DA /* RCTRootView.m */; };
6970
830BA4551A8E3BDA00D53203 /* RCTCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 830BA4541A8E3BDA00D53203 /* RCTCache.m */; };
7071
832348161A77A5AA00B55238 /* Layout.c in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FC71A68125100A75B9A /* Layout.c */; };
@@ -216,6 +217,7 @@
216217
58C571C01AA56C1900CDF9C8 /* RCTDatePickerManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTDatePickerManager.h; sourceTree = "<group>"; };
217218
63F014BE1B02080B003B75D2 /* RCTPointAnnotation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTPointAnnotation.h; sourceTree = "<group>"; };
218219
63F014BF1B02080B003B75D2 /* RCTPointAnnotation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTPointAnnotation.m; sourceTree = "<group>"; };
220+
783ABB341B38A9D3003FFD95 /* RCTJavaScriptExecutor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTJavaScriptExecutor.m; sourceTree = "<group>"; };
219221
830213F31A654E0800B993E6 /* RCTBridgeModule.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RCTBridgeModule.h; sourceTree = "<group>"; };
220222
830A229C1A66C68A008503DA /* RCTRootView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTRootView.h; sourceTree = "<group>"; };
221223
830A229D1A66C68A008503DA /* RCTRootView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTRootView.m; sourceTree = "<group>"; };
@@ -434,6 +436,7 @@
434436
83CBBA661A601EF300E9B192 /* RCTEventDispatcher.m */,
435437
83CBBA4C1A601E3B00E9B192 /* RCTInvalidating.h */,
436438
83CBBA631A601ECA00E9B192 /* RCTJavaScriptExecutor.h */,
439+
783ABB341B38A9D3003FFD95 /* RCTJavaScriptExecutor.m */,
437440
13A1F71C1A75392D00D3D453 /* RCTKeyCommands.h */,
438441
13A1F71D1A75392D00D3D453 /* RCTKeyCommands.m */,
439442
83CBBA4D1A601E3B00E9B192 /* RCTLog.h */,
@@ -579,6 +582,7 @@
579582
134FCB3D1A6E7F0800051CC8 /* RCTContextExecutor.m in Sources */,
580583
14C2CA781B3ACB0400E6CBB2 /* RCTBatchedBridge.m in Sources */,
581584
13E067591A70F44B002CDEE1 /* UIView+React.m in Sources */,
585+
783ABB351B38A9D3003FFD95 /* RCTJavaScriptExecutor.m in Sources */,
582586
14F484561AABFCE100FDF6B9 /* RCTSliderManager.m in Sources */,
583587
14C2CA741B3AC64300E6CBB2 /* RCTModuleData.m in Sources */,
584588
142014191B32094000CC17BA /* RCTPerformanceLogger.m in Sources */,

0 commit comments

Comments
 (0)