From d6c519bc9669221025cfedeeca08de1c795d6aa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Gregorczyk?= Date: Mon, 18 Sep 2017 18:35:44 -0700 Subject: [PATCH] Base class for all object private data passed to JSC Reviewed By: amnn Differential Revision: D5761937 fbshipit-source-id: de88cf8b959fc855c3c0786f817bb6032491c819 --- React/React.xcodeproj/project.pbxproj | 253 ++++++++++++++++++ .../src/main/jni/react/jni/Android.mk | 3 +- ReactCommon/cxxreact/Android.mk | 1 + ReactCommon/cxxreact/JSCExecutor.h | 3 +- ReactCommon/jschelpers/Android.mk | 1 + ReactCommon/jschelpers/BUCK | 4 + ReactCommon/jschelpers/JSCHelpers.cpp | 32 ++- ReactCommon/jschelpers/Value.h | 5 +- ReactCommon/privatedata/Android.mk | 21 ++ ReactCommon/privatedata/BUCK | 23 ++ ReactCommon/privatedata/PrivateDataBase.cpp | 10 + ReactCommon/privatedata/PrivateDataBase.h | 42 +++ 12 files changed, 386 insertions(+), 12 deletions(-) create mode 100644 ReactCommon/privatedata/Android.mk create mode 100644 ReactCommon/privatedata/BUCK create mode 100644 ReactCommon/privatedata/PrivateDataBase.cpp create mode 100644 ReactCommon/privatedata/PrivateDataBase.h diff --git a/React/React.xcodeproj/project.pbxproj b/React/React.xcodeproj/project.pbxproj index 3e8faf15a..e7e8723ed 100644 --- a/React/React.xcodeproj/project.pbxproj +++ b/React/React.xcodeproj/project.pbxproj @@ -1071,6 +1071,14 @@ 83CBBA691A601EF300E9B192 /* RCTEventDispatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = 83CBBA661A601EF300E9B192 /* RCTEventDispatcher.m */; }; 83CBBA981A6020BB00E9B192 /* RCTTouchHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 83CBBA971A6020BB00E9B192 /* RCTTouchHandler.m */; }; 83CBBACC1A6023D300E9B192 /* RCTConvert.m in Sources */ = {isa = PBXBuildFile; fileRef = 83CBBACB1A6023D300E9B192 /* RCTConvert.m */; }; + 9936F3371F5F2F480010BF04 /* PrivateDataBase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9936F3351F5F2F480010BF04 /* PrivateDataBase.cpp */; }; + 9936F3381F5F2F480010BF04 /* PrivateDataBase.h in Headers */ = {isa = PBXBuildFile; fileRef = 9936F3361F5F2F480010BF04 /* PrivateDataBase.h */; }; + 9936F3391F5F2F5C0010BF04 /* PrivateDataBase.h in Headers */ = {isa = PBXBuildFile; fileRef = 9936F3361F5F2F480010BF04 /* PrivateDataBase.h */; }; + 9936F33A1F5F2F7C0010BF04 /* PrivateDataBase.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 9936F3361F5F2F480010BF04 /* PrivateDataBase.h */; }; + 9936F33B1F5F2F9D0010BF04 /* PrivateDataBase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9936F3351F5F2F480010BF04 /* PrivateDataBase.cpp */; }; + 9936F33C1F5F2FE70010BF04 /* PrivateDataBase.h in Headers */ = {isa = PBXBuildFile; fileRef = 9936F3361F5F2F480010BF04 /* PrivateDataBase.h */; }; + 9936F33D1F5F2FF40010BF04 /* PrivateDataBase.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 9936F3361F5F2F480010BF04 /* PrivateDataBase.h */; }; + 9936F33E1F5F2FFC0010BF04 /* PrivateDataBase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9936F3351F5F2F480010BF04 /* PrivateDataBase.cpp */; }; A2440AA21DF8D854006E7BFC /* RCTReloadCommand.h in Headers */ = {isa = PBXBuildFile; fileRef = A2440AA01DF8D854006E7BFC /* RCTReloadCommand.h */; }; A2440AA31DF8D854006E7BFC /* RCTReloadCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = A2440AA11DF8D854006E7BFC /* RCTReloadCommand.m */; }; A2440AA41DF8D865006E7BFC /* RCTReloadCommand.h in Headers */ = {isa = PBXBuildFile; fileRef = A2440AA01DF8D854006E7BFC /* RCTReloadCommand.h */; }; @@ -1175,6 +1183,34 @@ remoteGlobalIDString = 3D3CD90C1DE5FBD800167DC4; remoteInfo = "jschelpers-tvOS"; }; + 9936F33F1F5F305D0010BF04 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 83CBB9F71A601CBA00E9B192 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 9936F2F81F5F2E4B0010BF04; + remoteInfo = privatedata; + }; + 9936F3411F5F30640010BF04 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 83CBB9F71A601CBA00E9B192 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 9936F3141F5F2E5B0010BF04; + remoteInfo = "privatedata-tvOS"; + }; + 9936F3431F5F30780010BF04 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 83CBB9F71A601CBA00E9B192 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 9936F2F81F5F2E4B0010BF04; + remoteInfo = privatedata; + }; + 9936F3451F5F30830010BF04 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 83CBB9F71A601CBA00E9B192 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 9936F3141F5F2E5B0010BF04; + remoteInfo = "privatedata-tvOS"; + }; /* End PBXContainerItemProxy section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -1616,6 +1652,28 @@ name = "Copy Headers"; runOnlyForDeploymentPostprocessing = 0; }; + 9936F3021F5F2E4B0010BF04 /* Copy Headers */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = include/privatedata; + dstSubfolderSpec = 16; + files = ( + 9936F33D1F5F2FF40010BF04 /* PrivateDataBase.h in Copy Headers */, + ); + name = "Copy Headers"; + runOnlyForDeploymentPostprocessing = 0; + }; + 9936F31E1F5F2E5B0010BF04 /* Copy Headers */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = include/privatedata; + dstSubfolderSpec = 16; + files = ( + 9936F33A1F5F2F7C0010BF04 /* PrivateDataBase.h in Copy Headers */, + ); + name = "Copy Headers"; + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ @@ -2014,6 +2072,10 @@ 83CBBACA1A6023D300E9B192 /* RCTConvert.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = RCTConvert.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; 83CBBACB1A6023D300E9B192 /* RCTConvert.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTConvert.m; sourceTree = ""; }; 83F15A171B7CC46900F10295 /* UIView+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UIView+Private.h"; sourceTree = ""; }; + 9936F3131F5F2E4B0010BF04 /* libprivatedata.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libprivatedata.a; sourceTree = BUILT_PRODUCTS_DIR; }; + 9936F32F1F5F2E5B0010BF04 /* libprivatedata-tvOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libprivatedata-tvOS.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + 9936F3351F5F2F480010BF04 /* PrivateDataBase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = PrivateDataBase.cpp; path = privatedata/PrivateDataBase.cpp; sourceTree = ""; }; + 9936F3361F5F2F480010BF04 /* PrivateDataBase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PrivateDataBase.h; path = privatedata/PrivateDataBase.h; sourceTree = ""; }; A2440AA01DF8D854006E7BFC /* RCTReloadCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTReloadCommand.h; sourceTree = ""; }; A2440AA11DF8D854006E7BFC /* RCTReloadCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTReloadCommand.m; sourceTree = ""; }; AC70D2E81DE489E4002E6351 /* RCTJavaScriptLoader.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RCTJavaScriptLoader.mm; sourceTree = ""; }; @@ -2392,6 +2454,7 @@ 3D10A3C71DDF3CED004A0F9D /* ReactCommon */ = { isa = PBXGroup; children = ( + 9936F3341F5F2F360010BF04 /* privatedata */, 130A77021DF767AF001F9587 /* yoga */, AC70D2EA1DE489FC002E6351 /* cxxreact */, 3D4A621D1DDD3985001F41B4 /* jschelpers */, @@ -2554,6 +2617,8 @@ 139D7ECE1E25DB7D00323FB7 /* libthird-party.a */, 3D383D3C1EBD27B6005632C8 /* libthird-party.a */, 3D383D621EBD27B9005632C8 /* libdouble-conversion.a */, + 9936F3131F5F2E4B0010BF04 /* libprivatedata.a */, + 9936F32F1F5F2E5B0010BF04 /* libprivatedata-tvOS.a */, ); name = Products; sourceTree = ""; @@ -2656,6 +2721,15 @@ path = Base; sourceTree = ""; }; + 9936F3341F5F2F360010BF04 /* privatedata */ = { + isa = PBXGroup; + children = ( + 9936F3351F5F2F480010BF04 /* PrivateDataBase.cpp */, + 9936F3361F5F2F480010BF04 /* PrivateDataBase.h */, + ); + name = privatedata; + sourceTree = ""; + }; AC70D2EA1DE489FC002E6351 /* cxxreact */ = { isa = PBXGroup; children = ( @@ -3062,6 +3136,7 @@ 3D80DA2E1DF820620028D040 /* RCTImageSource.h in Headers */, 3D80DA2F1DF820620028D040 /* RCTInvalidating.h in Headers */, 3D7BFD251EA8E351008DFB7A /* RCTSamplingProfilerPackagerMethod.h in Headers */, + 9936F3381F5F2F480010BF04 /* PrivateDataBase.h in Headers */, 3D80DA301DF820620028D040 /* RCTJavaScriptExecutor.h in Headers */, 135A9BFF1E7B0EE600587AEB /* RCTJSCHelpers.h in Headers */, 3D80DA311DF820620028D040 /* RCTJavaScriptLoader.h in Headers */, @@ -3187,6 +3262,22 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 9936F2FB1F5F2E4B0010BF04 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + 9936F33C1F5F2FE70010BF04 /* PrivateDataBase.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 9936F3171F5F2E5B0010BF04 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + 9936F3391F5F2F5C0010BF04 /* PrivateDataBase.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXHeadersBuildPhase section */ /* Begin PBXNativeTarget section */ @@ -3325,6 +3416,7 @@ buildRules = ( ); dependencies = ( + 9936F3441F5F30780010BF04 /* PBXTargetDependency */, 1320081B1E283DC300F0C457 /* PBXTargetDependency */, ); name = jschelpers; @@ -3343,6 +3435,7 @@ buildRules = ( ); dependencies = ( + 9936F3461F5F30830010BF04 /* PBXTargetDependency */, 3D383D641EBD27CE005632C8 /* PBXTargetDependency */, ); name = "jschelpers-tvOS"; @@ -3361,6 +3454,7 @@ buildRules = ( ); dependencies = ( + 9936F3401F5F305D0010BF04 /* PBXTargetDependency */, 3D3CD9501DE5FDB900167DC4 /* PBXTargetDependency */, ); name = cxxreact; @@ -3379,6 +3473,7 @@ buildRules = ( ); dependencies = ( + 9936F3421F5F30640010BF04 /* PBXTargetDependency */, 3DC159E81E83E2A0007B1282 /* PBXTargetDependency */, ); name = "cxxreact-tvOS"; @@ -3408,6 +3503,40 @@ productReference = 83CBBA2E1A601D0E00E9B192 /* libReact.a */; productType = "com.apple.product-type.library.static"; }; + 9936F2F81F5F2E4B0010BF04 /* privatedata */ = { + isa = PBXNativeTarget; + buildConfigurationList = 9936F3101F5F2E4B0010BF04 /* Build configuration list for PBXNativeTarget "privatedata" */; + buildPhases = ( + 9936F2FB1F5F2E4B0010BF04 /* Headers */, + 9936F3021F5F2E4B0010BF04 /* Copy Headers */, + 9936F30A1F5F2E4B0010BF04 /* Sources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = privatedata; + productName = React; + productReference = 9936F3131F5F2E4B0010BF04 /* libprivatedata.a */; + productType = "com.apple.product-type.library.static"; + }; + 9936F3141F5F2E5B0010BF04 /* privatedata-tvOS */ = { + isa = PBXNativeTarget; + buildConfigurationList = 9936F32C1F5F2E5B0010BF04 /* Build configuration list for PBXNativeTarget "privatedata-tvOS" */; + buildPhases = ( + 9936F3171F5F2E5B0010BF04 /* Headers */, + 9936F31E1F5F2E5B0010BF04 /* Copy Headers */, + 9936F3261F5F2E5B0010BF04 /* Sources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "privatedata-tvOS"; + productName = "React-tvOS"; + productReference = 9936F32F1F5F2E5B0010BF04 /* libprivatedata-tvOS.a */; + productType = "com.apple.product-type.library.static"; + }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ @@ -3467,6 +3596,8 @@ 3D383D211EBD27B6005632C8 /* third-party-tvOS */, 139D7E871E25C6D100323FB7 /* double-conversion */, 3D383D3D1EBD27B9005632C8 /* double-conversion-tvOS */, + 9936F2F81F5F2E4B0010BF04 /* privatedata */, + 9936F3141F5F2E5B0010BF04 /* privatedata-tvOS */, ); }; /* End PBXProject section */ @@ -3960,6 +4091,7 @@ 137327E81AA5CF210034F82E /* RCTTabBarItem.m in Sources */, 83A1FE8C1B62640A00BE0E65 /* RCTModalHostView.m in Sources */, 13E067551A70F44B002CDEE1 /* RCTShadowView.m in Sources */, + 9936F3371F5F2F480010BF04 /* PrivateDataBase.cpp in Sources */, 1450FF871BCFF28A00208362 /* RCTProfileTrampoline-arm.S in Sources */, 131B6AF51AF1093D00FFC3E0 /* RCTSegmentedControlManager.m in Sources */, 58114A171AAE854800E7D092 /* RCTPickerManager.m in Sources */, @@ -3987,6 +4119,22 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 9936F30A1F5F2E4B0010BF04 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 9936F33E1F5F2FFC0010BF04 /* PrivateDataBase.cpp in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 9936F3261F5F2E5B0010BF04 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 9936F33B1F5F2F9D0010BF04 /* PrivateDataBase.cpp in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ @@ -4040,6 +4188,26 @@ target = 3D3CD90C1DE5FBD800167DC4 /* jschelpers-tvOS */; targetProxy = 3DC159E71E83E2A0007B1282 /* PBXContainerItemProxy */; }; + 9936F3401F5F305D0010BF04 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 9936F2F81F5F2E4B0010BF04 /* privatedata */; + targetProxy = 9936F33F1F5F305D0010BF04 /* PBXContainerItemProxy */; + }; + 9936F3421F5F30640010BF04 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 9936F3141F5F2E5B0010BF04 /* privatedata-tvOS */; + targetProxy = 9936F3411F5F30640010BF04 /* PBXContainerItemProxy */; + }; + 9936F3441F5F30780010BF04 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 9936F2F81F5F2E4B0010BF04 /* privatedata */; + targetProxy = 9936F3431F5F30780010BF04 /* PBXContainerItemProxy */; + }; + 9936F3461F5F30830010BF04 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 9936F3141F5F2E5B0010BF04 /* privatedata-tvOS */; + targetProxy = 9936F3451F5F30830010BF04 /* PBXContainerItemProxy */; + }; /* End PBXTargetDependency section */ /* Begin XCBuildConfiguration section */ @@ -4555,6 +4723,73 @@ }; name = Release; }; + 9936F3111F5F2E4B0010BF04 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 3D788F841EBD2D240063D616 /* third-party.xcconfig */; + buildSettings = { + CLANG_CXX_LANGUAGE_STANDARD = "c++14"; + CLANG_STATIC_ANALYZER_MODE = deep; + GCC_WARN_ABOUT_MISSING_NEWLINE = YES; + OTHER_LDFLAGS = "-ObjC"; + PRODUCT_NAME = "$(TARGET_NAME)"; + PUBLIC_HEADERS_FOLDER_PATH = /usr/local/include/privatedata; + RUN_CLANG_STATIC_ANALYZER = YES; + }; + name = Debug; + }; + 9936F3121F5F2E4B0010BF04 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 3D788F841EBD2D240063D616 /* third-party.xcconfig */; + buildSettings = { + CLANG_CXX_LANGUAGE_STANDARD = "c++14"; + CLANG_STATIC_ANALYZER_MODE = deep; + GCC_PREPROCESSOR_DEFINITIONS = "$(inherited)"; + GCC_WARN_ABOUT_MISSING_NEWLINE = YES; + OTHER_LDFLAGS = "-ObjC"; + PRODUCT_NAME = "$(TARGET_NAME)"; + PUBLIC_HEADERS_FOLDER_PATH = /usr/local/include/privatedata; + RUN_CLANG_STATIC_ANALYZER = NO; + }; + name = Release; + }; + 9936F32D1F5F2E5B0010BF04 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 3D788F841EBD2D240063D616 /* third-party.xcconfig */; + buildSettings = { + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "c++14"; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_SUSPICIOUS_MOVES = YES; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_TESTABILITY = YES; + GCC_NO_COMMON_BLOCKS = YES; + OTHER_LDFLAGS = "-ObjC"; + PRODUCT_NAME = "$(TARGET_NAME)"; + PUBLIC_HEADERS_FOLDER_PATH = /usr/local/include/privatedata; + SDKROOT = appletvos; + }; + name = Debug; + }; + 9936F32E1F5F2E5B0010BF04 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 3D788F841EBD2D240063D616 /* third-party.xcconfig */; + buildSettings = { + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "c++14"; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_SUSPICIOUS_MOVES = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + GCC_NO_COMMON_BLOCKS = YES; + OTHER_LDFLAGS = "-ObjC"; + PRODUCT_NAME = "$(TARGET_NAME)"; + PUBLIC_HEADERS_FOLDER_PATH = /usr/local/include/privatedata; + SDKROOT = appletvos; + }; + name = Release; + }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ @@ -4675,6 +4910,24 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + 9936F3101F5F2E4B0010BF04 /* Build configuration list for PBXNativeTarget "privatedata" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 9936F3111F5F2E4B0010BF04 /* Debug */, + 9936F3121F5F2E4B0010BF04 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 9936F32C1F5F2E5B0010BF04 /* Build configuration list for PBXNativeTarget "privatedata-tvOS" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 9936F32D1F5F2E5B0010BF04 /* Debug */, + 9936F32E1F5F2E5B0010BF04 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; /* End XCConfigurationList section */ }; rootObject = 83CBB9F71A601CBA00E9B192 /* Project object */; diff --git a/ReactAndroid/src/main/jni/react/jni/Android.mk b/ReactAndroid/src/main/jni/react/jni/Android.mk index f792554e0..b132a41ff 100644 --- a/ReactAndroid/src/main/jni/react/jni/Android.mk +++ b/ReactAndroid/src/main/jni/react/jni/Android.mk @@ -35,12 +35,13 @@ LOCAL_CFLAGS += $(CXX11_FLAGS) LOCAL_EXPORT_CPPFLAGS := $(CXX11_FLAGS) LOCAL_LDLIBS += -landroid -LOCAL_SHARED_LIBRARIES := libfolly_json libfbjni libjsc libglog_init libyoga +LOCAL_SHARED_LIBRARIES := libfolly_json libfbjni libjsc libglog_init libyoga libprivatedata LOCAL_STATIC_LIBRARIES := libreactnative include $(BUILD_SHARED_LIBRARY) $(call import-module,cxxreact) +$(call import-module,privatedata) $(call import-module,fb) $(call import-module,fbgloginit) $(call import-module,folly) diff --git a/ReactCommon/cxxreact/Android.mk b/ReactCommon/cxxreact/Android.mk index 98713b086..c29e7d1e3 100644 --- a/ReactCommon/cxxreact/Android.mk +++ b/ReactCommon/cxxreact/Android.mk @@ -44,3 +44,4 @@ $(call import-module,folly) $(call import-module,jsc) $(call import-module,glog) $(call import-module,jschelpers) +$(call import-module,privatedata) diff --git a/ReactCommon/cxxreact/JSCExecutor.h b/ReactCommon/cxxreact/JSCExecutor.h index 9fbd52337..82e2b30f8 100644 --- a/ReactCommon/cxxreact/JSCExecutor.h +++ b/ReactCommon/cxxreact/JSCExecutor.h @@ -14,6 +14,7 @@ #include #include #include +#include #ifndef RN_EXPORT #define RN_EXPORT __attribute__((visibility("default"))) @@ -50,7 +51,7 @@ struct JSCValueEncoder { } }; -class RN_EXPORT JSCExecutor : public JSExecutor { +class RN_EXPORT JSCExecutor : public JSExecutor, public PrivateDataBase { public: /** * Must be invoked from thread this Executor will run on. diff --git a/ReactCommon/jschelpers/Android.mk b/ReactCommon/jschelpers/Android.mk index 3de80a9d5..920227863 100644 --- a/ReactCommon/jschelpers/Android.mk +++ b/ReactCommon/jschelpers/Android.mk @@ -27,3 +27,4 @@ include $(BUILD_STATIC_LIBRARY) $(call import-module,folly) $(call import-module,jsc) $(call import-module,glog) +$(call import-module,privatedata) diff --git a/ReactCommon/jschelpers/BUCK b/ReactCommon/jschelpers/BUCK index c7b1b06fd..d1c4b8a0e 100644 --- a/ReactCommon/jschelpers/BUCK +++ b/ReactCommon/jschelpers/BUCK @@ -31,9 +31,13 @@ rn_xplat_cxx_library( compiler_flags = [ "-Wall", "-fexceptions", + "-frtti", "-fvisibility=hidden", "-std=c++1y", ], + exported_deps = [ + react_native_xplat_target("privatedata:privatedata"), + ], fbobjc_inherited_buck_flags = STATIC_LIBRARY_IOS_FLAGS, force_static = True, visibility = [ diff --git a/ReactCommon/jschelpers/JSCHelpers.cpp b/ReactCommon/jschelpers/JSCHelpers.cpp index 540122e7e..2f7331d41 100644 --- a/ReactCommon/jschelpers/JSCHelpers.cpp +++ b/ReactCommon/jschelpers/JSCHelpers.cpp @@ -14,6 +14,7 @@ #include "JavaScriptCore.h" #include "Value.h" +#include #if WITH_FBJSCEXTENSIONS #undef ASSERT @@ -31,6 +32,18 @@ namespace react { namespace { +class JSFunctionPrivateData : public PrivateDataBase { + public: + explicit JSFunctionPrivateData(JSFunction&& function) : jsFunction_{std::move(function)} {} + + JSFunction& getJSFunction() { + return jsFunction_; + } + +private: + JSFunction jsFunction_; +}; + JSValueRef functionCaller( JSContextRef ctx, JSObjectRef function, @@ -39,8 +52,9 @@ JSValueRef functionCaller( const JSValueRef arguments[], JSValueRef* exception) { const bool isCustomJSC = isCustomJSCPtr(ctx); - auto* f = static_cast(JSC_JSObjectGetPrivate(isCustomJSC, function)); - return (*f)(ctx, thisObject, argumentCount, arguments); + auto* privateData = PrivateDataBase::cast( + JSC_JSObjectGetPrivate(isCustomJSC, function)); + return (privateData->getJSFunction())(ctx, thisObject, argumentCount, arguments); } JSClassRef createFuncClass(JSContextRef ctx) { @@ -52,13 +66,15 @@ JSClassRef createFuncClass(JSContextRef ctx) { const bool isCustomJSC = isCustomJSCPtr(ctx); if (isCustomJSC) { definition.finalize = [](JSObjectRef object) { - auto* function = static_cast(JSC_JSObjectGetPrivate(true, object)); - delete function; + auto* privateData = PrivateDataBase::cast( + JSC_JSObjectGetPrivate(true, object)); + delete privateData; }; } else { definition.finalize = [](JSObjectRef object) { - auto* function = static_cast(JSC_JSObjectGetPrivate(false, object)); - delete function; + auto* privateData = PrivateDataBase::cast( + JSC_JSObjectGetPrivate(false, object)); + delete privateData; }; } definition.callAsFunction = exceptionWrapMethod<&functionCaller>(); @@ -77,8 +93,8 @@ JSObjectRef makeFunction( } // dealloc in kClassDef.finalize - JSFunction *functionPtr = new JSFunction(std::move(function)); - auto functionObject = Object(ctx, JSC_JSObjectMake(ctx, *classRef, functionPtr)); + JSFunctionPrivateData *functionDataPtr = new JSFunctionPrivateData(std::move(function)); + auto functionObject = Object(ctx, JSC_JSObjectMake(ctx, *classRef, functionDataPtr)); functionObject.setProperty("name", Value(ctx, name)); return functionObject; } diff --git a/ReactCommon/jschelpers/Value.h b/ReactCommon/jschelpers/Value.h index c11489efe..13674817a 100644 --- a/ReactCommon/jschelpers/Value.h +++ b/ReactCommon/jschelpers/Value.h @@ -11,6 +11,7 @@ #include #include #include +#include #ifndef RN_EXPORT #define RN_EXPORT __attribute__((visibility("default"))) @@ -211,10 +212,10 @@ public: template ReturnType* getPrivate() const { const bool isCustomJSC = isCustomJSCPtr(m_context); - return static_cast(JSC_JSObjectGetPrivate(isCustomJSC, m_obj)); + return PrivateDataBase::cast(JSC_JSObjectGetPrivate(isCustomJSC, m_obj)); } - void setPrivate(void* data) const { + void setPrivate(PrivateDataBase* data) const { const bool isCustomJSC = isCustomJSCPtr(m_context); JSC_JSObjectSetPrivate(isCustomJSC, m_obj, data); } diff --git a/ReactCommon/privatedata/Android.mk b/ReactCommon/privatedata/Android.mk new file mode 100644 index 000000000..d46770615 --- /dev/null +++ b/ReactCommon/privatedata/Android.mk @@ -0,0 +1,21 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_MODULE := privatedata + +LOCAL_SRC_FILES := \ + PrivateDataBase.cpp \ + +LOCAL_C_INCLUDES := $(LOCAL_PATH)/.. +LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES) + +LOCAL_CFLAGS := \ + -DLOG_TAG=\"ReactNative\" + +LOCAL_CFLAGS += -Wall -Werror -fexceptions -frtti +CXX11_FLAGS := -std=c++11 +LOCAL_CFLAGS += $(CXX11_FLAGS) +LOCAL_EXPORT_CPPFLAGS := $(CXX11_FLAGS) + +include $(BUILD_SHARED_LIBRARY) diff --git a/ReactCommon/privatedata/BUCK b/ReactCommon/privatedata/BUCK new file mode 100644 index 000000000..a22a1eaab --- /dev/null +++ b/ReactCommon/privatedata/BUCK @@ -0,0 +1,23 @@ +include_defs("//ReactCommon/DEFS") + +rn_xplat_cxx_library( + name = "privatedata", + srcs = glob(["**/*.cpp"]), + header_namespace = "", + exported_headers = subdir_glob( + [ + ("", "**/*.h"), + ], + prefix = "privatedata", + ), + compiler_flags = [ + "-Wall", + "-fexceptions", + "-frtti", + "-fvisibility=hidden", + "-std=c++1y", + ], + visibility = [ + "PUBLIC", + ], +) diff --git a/ReactCommon/privatedata/PrivateDataBase.cpp b/ReactCommon/privatedata/PrivateDataBase.cpp new file mode 100644 index 000000000..133f526e6 --- /dev/null +++ b/ReactCommon/privatedata/PrivateDataBase.cpp @@ -0,0 +1,10 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +#include "PrivateDataBase.h" + +namespace facebook { +namespace react { + +PrivateDataBase::~PrivateDataBase() {} + +} } diff --git a/ReactCommon/privatedata/PrivateDataBase.h b/ReactCommon/privatedata/PrivateDataBase.h new file mode 100644 index 000000000..599660c9f --- /dev/null +++ b/ReactCommon/privatedata/PrivateDataBase.h @@ -0,0 +1,42 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +#pragma once + +#include +#include +#include + +#ifndef RN_EXPORT +#define RN_EXPORT __attribute__((visibility("default"))) +#endif + +namespace facebook { +namespace react { + +// Base class for private data used to implement hybrid JS-native objects. A common root class, +// rtti and dynamic_cast allow us to do some runtime type checking that makes it possible +// for multiple hybrid object implementations to co-exist. +class RN_EXPORT PrivateDataBase { + public: + virtual ~PrivateDataBase(); + + // Casts given void* to PrivateDataBase and performs dynamic_cast to desired type. Returns null on + // failure. + template + static typename std::enable_if::value, T>::type* tryCast(void* ptr) { + return dynamic_cast(reinterpret_cast(ptr)); + } + + // Like tryCast, but aborts on failure. + template + static typename std::enable_if::value, T>::type* cast(void* ptr) { + auto result = tryCast(ptr); + if (!result) { + assert(false && "could not cast to desired type"); + abort(); + } + return result; + } +}; + +} }