Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Base class for all object private data passed to JSC
Reviewed By: amnn Differential Revision: D5761937 fbshipit-source-id: de88cf8b959fc855c3c0786f817bb6032491c819
- Loading branch information
1 parent
8bf8b21
commit d6c519b
Showing
12 changed files
with
386 additions
and
12 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright 2004-present Facebook. All Rights Reserved. | ||
|
||
#include "PrivateDataBase.h" | ||
|
||
namespace facebook { | ||
namespace react { | ||
|
||
PrivateDataBase::~PrivateDataBase() {} | ||
|
||
} } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
}; | ||
|
||
} } |