Base class for all object private data passed to JSC

Reviewed By: amnn

Differential Revision: D5761937

fbshipit-source-id: de88cf8b959fc855c3c0786f817bb6032491c819
This commit is contained in:
Michał Gregorczyk 2017-09-18 18:35:44 -07:00 committed by Facebook Github Bot
parent 8bf8b21613
commit d6c519bc96
12 changed files with 386 additions and 12 deletions

View File

@ -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 = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
83CBBACB1A6023D300E9B192 /* RCTConvert.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTConvert.m; sourceTree = "<group>"; };
83F15A171B7CC46900F10295 /* UIView+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UIView+Private.h"; sourceTree = "<group>"; };
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 = "<group>"; };
9936F3361F5F2F480010BF04 /* PrivateDataBase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PrivateDataBase.h; path = privatedata/PrivateDataBase.h; sourceTree = "<group>"; };
A2440AA01DF8D854006E7BFC /* RCTReloadCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTReloadCommand.h; sourceTree = "<group>"; };
A2440AA11DF8D854006E7BFC /* RCTReloadCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTReloadCommand.m; sourceTree = "<group>"; };
AC70D2E81DE489E4002E6351 /* RCTJavaScriptLoader.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RCTJavaScriptLoader.mm; sourceTree = "<group>"; };
@ -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 = "<group>";
@ -2656,6 +2721,15 @@
path = Base;
sourceTree = "<group>";
};
9936F3341F5F2F360010BF04 /* privatedata */ = {
isa = PBXGroup;
children = (
9936F3351F5F2F480010BF04 /* PrivateDataBase.cpp */,
9936F3361F5F2F480010BF04 /* PrivateDataBase.h */,
);
name = privatedata;
sourceTree = "<group>";
};
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 */;

View File

@ -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)

View File

@ -44,3 +44,4 @@ $(call import-module,folly)
$(call import-module,jsc)
$(call import-module,glog)
$(call import-module,jschelpers)
$(call import-module,privatedata)

View File

@ -14,6 +14,7 @@
#include <jschelpers/JSCHelpers.h>
#include <jschelpers/JavaScriptCore.h>
#include <jschelpers/Value.h>
#include <privatedata/PrivateDataBase.h>
#ifndef RN_EXPORT
#define RN_EXPORT __attribute__((visibility("default")))
@ -50,7 +51,7 @@ struct JSCValueEncoder<folly::dynamic> {
}
};
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.

View File

@ -27,3 +27,4 @@ include $(BUILD_STATIC_LIBRARY)
$(call import-module,folly)
$(call import-module,jsc)
$(call import-module,glog)
$(call import-module,privatedata)

View File

@ -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 = [

View File

@ -14,6 +14,7 @@
#include "JavaScriptCore.h"
#include "Value.h"
#include <privatedata/PrivateDataBase.h>
#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<JSFunction*>(JSC_JSObjectGetPrivate(isCustomJSC, function));
return (*f)(ctx, thisObject, argumentCount, arguments);
auto* privateData = PrivateDataBase::cast<JSFunctionPrivateData>(
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<JSFunction*>(JSC_JSObjectGetPrivate(true, object));
delete function;
auto* privateData = PrivateDataBase::cast<JSFunctionPrivateData>(
JSC_JSObjectGetPrivate(true, object));
delete privateData;
};
} else {
definition.finalize = [](JSObjectRef object) {
auto* function = static_cast<JSFunction*>(JSC_JSObjectGetPrivate(false, object));
delete function;
auto* privateData = PrivateDataBase::cast<JSFunctionPrivateData>(
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;
}

View File

@ -11,6 +11,7 @@
#include <jschelpers/JavaScriptCore.h>
#include <jschelpers/Unicode.h>
#include <jschelpers/noncopyable.h>
#include <privatedata/PrivateDataBase.h>
#ifndef RN_EXPORT
#define RN_EXPORT __attribute__((visibility("default")))
@ -211,10 +212,10 @@ public:
template<typename ReturnType>
ReturnType* getPrivate() const {
const bool isCustomJSC = isCustomJSCPtr(m_context);
return static_cast<ReturnType*>(JSC_JSObjectGetPrivate(isCustomJSC, m_obj));
return PrivateDataBase::cast<ReturnType>(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);
}

View File

@ -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)

View File

@ -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",
],
)

View File

@ -0,0 +1,10 @@
// Copyright 2004-present Facebook. All Rights Reserved.
#include "PrivateDataBase.h"
namespace facebook {
namespace react {
PrivateDataBase::~PrivateDataBase() {}
} }

View File

@ -0,0 +1,42 @@
// Copyright 2004-present Facebook. All Rights Reserved.
#pragma once
#include <cassert>
#include <cstdlib>
#include <type_traits>
#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 <typename T>
static typename std::enable_if<std::is_base_of<PrivateDataBase, T>::value, T>::type* tryCast(void* ptr) {
return dynamic_cast<T*>(reinterpret_cast<PrivateDataBase*>(ptr));
}
// Like tryCast, but aborts on failure.
template <typename T>
static typename std::enable_if<std::is_base_of<PrivateDataBase, T>::value, T>::type* cast(void* ptr) {
auto result = tryCast<T>(ptr);
if (!result) {
assert(false && "could not cast to desired type");
abort();
}
return result;
}
};
} }