Make custom jsc initialization a link-time replacable function.

Reviewed By: bnham

Differential Revision: D3880106

fbshipit-source-id: 2a3c3c8ff120ecc66b31325700c187cbd957f361
This commit is contained in:
Yiding Jia 2016-09-20 16:48:15 -07:00 committed by Facebook Github Bot
parent fe84362a90
commit bb933c8ad4
2 changed files with 14 additions and 12 deletions

View File

@ -49,3 +49,13 @@ typedef struct RCTJSCWrapper {
RCT_EXTERN RCTJSCWrapper *RCTJSCWrapperCreate(BOOL useCustomJSC);
RCT_EXTERN void RCTJSCWrapperRelease(RCTJSCWrapper *wrapper);
/**
* Link time overridable initialization function to execute custom
* initialization code when loading custom JSC.
*
* By default it does nothing.
*
* @param handle to the dlopen'd JSC library.
*/
void __attribute__((visibility("hidden"))) RCTCustomJSCInit(void *handle);

View File

@ -16,11 +16,10 @@
#include <dlfcn.h>
#if HAS_FBGLOG
#import <FBGLog/FBGLogSink.h>
typedef void (*configureJSCLoggingForIOSFuncType)(int32_t, std::unique_ptr<google::LogSink>, void (*)());
#endif
void __attribute__((visibility("hidden"),weak)) RCTCustomJSCInit(void *handle) {
return;
}
static void *RCTCustomLibraryHandler(void)
{
@ -89,17 +88,10 @@ static void RCTSetUpCustomLibraryPointers(RCTJSCWrapper *wrapper)
wrapper->JSValue = (__bridge Class)dlsym(libraryHandle, "OBJC_CLASS_$_JSValue");
wrapper->configureJSContextForIOS = (configureJSContextForIOSFuncType)dlsym(libraryHandle, "configureJSContextForIOS");
#if HAS_FBGLOG
static dispatch_once_t once;
dispatch_once(&once, ^{
void *handle = dlsym(libraryHandle, "configureJSCLoggingForIOS");
if (handle) {
configureJSCLoggingForIOSFuncType logConfigFunc = (configureJSCLoggingForIOSFuncType)handle;
logConfigFunc(google::GLOG_INFO, FBGLogSink(), FBGLogFailureFunction);
}
RCTCustomJSCInit(libraryHandle);
});
#endif
}
RCTJSCWrapper *RCTJSCWrapperCreate(BOOL useCustomJSC)