Add more functions to RCTJSCWrapper + make it a public header

Reviewed By: javache

Differential Revision: D4133936

fbshipit-source-id: 04951965099598f7058cb0005267712c276582b9
This commit is contained in:
Indragie Karunaratne 2016-11-14 08:59:20 -08:00 committed by Facebook Github Bot
parent 3a9a4fd33a
commit 13aba82a2b
2 changed files with 33 additions and 1 deletions

View File

@ -9,22 +9,30 @@
#import <JavaScriptCore/JavaScriptCore.h> #import <JavaScriptCore/JavaScriptCore.h>
#import "RCTDefines.h" #import <FBReactKit/RCTDefines.h>
typedef void (*voidWithNoParamsFuncType)(); typedef void (*voidWithNoParamsFuncType)();
typedef JSStringRef (*JSStringCreateWithCFStringFuncType)(CFStringRef); typedef JSStringRef (*JSStringCreateWithCFStringFuncType)(CFStringRef);
typedef JSStringRef (*JSStringCreateWithUTF8CStringFuncType)(const char *); typedef JSStringRef (*JSStringCreateWithUTF8CStringFuncType)(const char *);
typedef CFStringRef (*JSStringCopyCFStringFuncType)(CFAllocatorRef, JSStringRef);
typedef void (*JSStringReleaseFuncType)(JSStringRef); typedef void (*JSStringReleaseFuncType)(JSStringRef);
typedef void (*JSGlobalContextSetNameFuncType)(JSGlobalContextRef, JSStringRef); typedef void (*JSGlobalContextSetNameFuncType)(JSGlobalContextRef, JSStringRef);
typedef void (*JSObjectSetPropertyFuncType)(JSContextRef, JSObjectRef, JSStringRef, JSValueRef, JSPropertyAttributes, JSValueRef *); typedef void (*JSObjectSetPropertyFuncType)(JSContextRef, JSObjectRef, JSStringRef, JSValueRef, JSPropertyAttributes, JSValueRef *);
typedef JSObjectRef (*JSContextGetGlobalObjectFuncType)(JSContextRef); typedef JSObjectRef (*JSContextGetGlobalObjectFuncType)(JSContextRef);
typedef JSValueRef (*JSObjectGetPropertyFuncType)(JSContextRef, JSObjectRef, JSStringRef, JSValueRef *); typedef JSValueRef (*JSObjectGetPropertyFuncType)(JSContextRef, JSObjectRef, JSStringRef, JSValueRef *);
typedef bool (*JSObjectIsFunctionFuncType)(JSContextRef, JSObjectRef);
typedef bool (*JSObjectIsConstructorFuncType)(JSContextRef, JSObjectRef);
typedef JSPropertyNameArrayRef (*JSObjectCopyPropertyNamesFuncType)(JSContextRef, JSObjectRef);
typedef size_t (*JSPropertyNameArrayGetCountFuncType)(JSPropertyNameArrayRef);
typedef JSStringRef (*JSPropertyNameArrayGetNameAtIndexFuncType)(JSPropertyNameArrayRef, size_t);
typedef void (*JSPropertyNameArrayReleaseFuncType)(JSPropertyNameArrayRef);
typedef JSValueRef (*JSValueMakeFromJSONStringFuncType)(JSContextRef, JSStringRef); typedef JSValueRef (*JSValueMakeFromJSONStringFuncType)(JSContextRef, JSStringRef);
typedef JSValueRef (*JSObjectCallAsFunctionFuncType)(JSContextRef, JSObjectRef, JSObjectRef, size_t, const JSValueRef *, JSValueRef *); typedef JSValueRef (*JSObjectCallAsFunctionFuncType)(JSContextRef, JSObjectRef, JSObjectRef, size_t, const JSValueRef *, JSValueRef *);
typedef JSValueRef (*JSValueMakeNullFuncType)(JSContextRef); typedef JSValueRef (*JSValueMakeNullFuncType)(JSContextRef);
typedef JSStringRef (*JSValueCreateJSONStringFuncType)(JSContextRef, JSValueRef, unsigned, JSValueRef *); typedef JSStringRef (*JSValueCreateJSONStringFuncType)(JSContextRef, JSValueRef, unsigned, JSValueRef *);
typedef bool (*JSValueIsUndefinedFuncType)(JSContextRef, JSValueRef); typedef bool (*JSValueIsUndefinedFuncType)(JSContextRef, JSValueRef);
typedef bool (*JSValueIsNullFuncType)(JSContextRef, JSValueRef); typedef bool (*JSValueIsNullFuncType)(JSContextRef, JSValueRef);
typedef JSObjectRef (*JSValueToObjectFuncType)(JSContextRef, JSValueRef, JSValueRef *);
typedef JSValueRef (*JSEvaluateScriptFuncType)(JSContextRef, JSStringRef, JSObjectRef, JSStringRef, int, JSValueRef *); typedef JSValueRef (*JSEvaluateScriptFuncType)(JSContextRef, JSStringRef, JSObjectRef, JSStringRef, int, JSValueRef *);
typedef JSValueRef (*JSEvaluateBytecodeBundleFuncType)(JSContextRef, JSObjectRef, int, JSStringRef, JSValueRef *); typedef JSValueRef (*JSEvaluateBytecodeBundleFuncType)(JSContextRef, JSObjectRef, int, JSStringRef, JSValueRef *);
@ -38,17 +46,25 @@ extern const int32_t JSNoBytecodeFileFormatVersion;
typedef struct RCTJSCWrapper { typedef struct RCTJSCWrapper {
JSStringCreateWithCFStringFuncType JSStringCreateWithCFString; JSStringCreateWithCFStringFuncType JSStringCreateWithCFString;
JSStringCreateWithUTF8CStringFuncType JSStringCreateWithUTF8CString; JSStringCreateWithUTF8CStringFuncType JSStringCreateWithUTF8CString;
JSStringCopyCFStringFuncType JSStringCopyCFString;
JSStringReleaseFuncType JSStringRelease; JSStringReleaseFuncType JSStringRelease;
JSGlobalContextSetNameFuncType JSGlobalContextSetName; JSGlobalContextSetNameFuncType JSGlobalContextSetName;
JSObjectSetPropertyFuncType JSObjectSetProperty; JSObjectSetPropertyFuncType JSObjectSetProperty;
JSContextGetGlobalObjectFuncType JSContextGetGlobalObject; JSContextGetGlobalObjectFuncType JSContextGetGlobalObject;
JSObjectGetPropertyFuncType JSObjectGetProperty; JSObjectGetPropertyFuncType JSObjectGetProperty;
JSObjectIsFunctionFuncType JSObjectIsFunction;
JSObjectIsConstructorFuncType JSObjectIsConstructor;
JSObjectCopyPropertyNamesFuncType JSObjectCopyPropertyNames;
JSPropertyNameArrayGetCountFuncType JSPropertyNameArrayGetCount;
JSPropertyNameArrayGetNameAtIndexFuncType JSPropertyNameArrayGetNameAtIndex;
JSPropertyNameArrayReleaseFuncType JSPropertyNameArrayRelease;
JSValueMakeFromJSONStringFuncType JSValueMakeFromJSONString; JSValueMakeFromJSONStringFuncType JSValueMakeFromJSONString;
JSObjectCallAsFunctionFuncType JSObjectCallAsFunction; JSObjectCallAsFunctionFuncType JSObjectCallAsFunction;
JSValueMakeNullFuncType JSValueMakeNull; JSValueMakeNullFuncType JSValueMakeNull;
JSValueCreateJSONStringFuncType JSValueCreateJSONString; JSValueCreateJSONStringFuncType JSValueCreateJSONString;
JSValueIsUndefinedFuncType JSValueIsUndefined; JSValueIsUndefinedFuncType JSValueIsUndefined;
JSValueIsNullFuncType JSValueIsNull; JSValueIsNullFuncType JSValueIsNull;
JSValueToObjectFuncType JSValueToObject;
JSEvaluateScriptFuncType JSEvaluateScript; JSEvaluateScriptFuncType JSEvaluateScript;
JSEvaluateBytecodeBundleFuncType JSEvaluateBytecodeBundle; JSEvaluateBytecodeBundleFuncType JSEvaluateBytecodeBundle;
voidWithNoParamsFuncType configureJSCForIOS; voidWithNoParamsFuncType configureJSCForIOS;

View File

@ -62,17 +62,25 @@ static RCTJSCWrapper *RCTSetUpSystemLibraryPointers()
return new RCTJSCWrapper { return new RCTJSCWrapper {
.JSStringCreateWithCFString = JSStringCreateWithCFString, .JSStringCreateWithCFString = JSStringCreateWithCFString,
.JSStringCreateWithUTF8CString = JSStringCreateWithUTF8CString, .JSStringCreateWithUTF8CString = JSStringCreateWithUTF8CString,
.JSStringCopyCFString = JSStringCopyCFString,
.JSStringRelease = JSStringRelease, .JSStringRelease = JSStringRelease,
.JSGlobalContextSetName = JSGlobalContextSetName, .JSGlobalContextSetName = JSGlobalContextSetName,
.JSObjectSetProperty = JSObjectSetProperty, .JSObjectSetProperty = JSObjectSetProperty,
.JSContextGetGlobalObject = JSContextGetGlobalObject, .JSContextGetGlobalObject = JSContextGetGlobalObject,
.JSObjectGetProperty = JSObjectGetProperty, .JSObjectGetProperty = JSObjectGetProperty,
.JSObjectIsFunction = JSObjectIsFunction,
.JSObjectIsConstructor = JSObjectIsConstructor,
.JSObjectCopyPropertyNames = JSObjectCopyPropertyNames,
.JSPropertyNameArrayGetCount = JSPropertyNameArrayGetCount,
.JSPropertyNameArrayGetNameAtIndex = JSPropertyNameArrayGetNameAtIndex,
.JSPropertyNameArrayRelease = JSPropertyNameArrayRelease,
.JSValueMakeFromJSONString = JSValueMakeFromJSONString, .JSValueMakeFromJSONString = JSValueMakeFromJSONString,
.JSObjectCallAsFunction = JSObjectCallAsFunction, .JSObjectCallAsFunction = JSObjectCallAsFunction,
.JSValueMakeNull = JSValueMakeNull, .JSValueMakeNull = JSValueMakeNull,
.JSValueCreateJSONString = JSValueCreateJSONString, .JSValueCreateJSONString = JSValueCreateJSONString,
.JSValueIsUndefined = JSValueIsUndefined, .JSValueIsUndefined = JSValueIsUndefined,
.JSValueIsNull = JSValueIsNull, .JSValueIsNull = JSValueIsNull,
.JSValueToObject = JSValueToObject,
.JSEvaluateScript = JSEvaluateScript, .JSEvaluateScript = JSEvaluateScript,
.JSBytecodeFileFormatVersion = JSNoBytecodeFileFormatVersion, .JSBytecodeFileFormatVersion = JSNoBytecodeFileFormatVersion,
.JSEvaluateBytecodeBundle = (JSEvaluateBytecodeBundleFuncType)UnimplementedJSEvaluateBytecodeBundle, .JSEvaluateBytecodeBundle = (JSEvaluateBytecodeBundleFuncType)UnimplementedJSEvaluateBytecodeBundle,
@ -92,17 +100,25 @@ static RCTJSCWrapper *RCTSetUpCustomLibraryPointers()
auto wrapper = new RCTJSCWrapper { auto wrapper = new RCTJSCWrapper {
.JSStringCreateWithCFString = (JSStringCreateWithCFStringFuncType)dlsym(libraryHandle, "JSStringCreateWithCFString"), .JSStringCreateWithCFString = (JSStringCreateWithCFStringFuncType)dlsym(libraryHandle, "JSStringCreateWithCFString"),
.JSStringCreateWithUTF8CString = (JSStringCreateWithUTF8CStringFuncType)dlsym(libraryHandle, "JSStringCreateWithUTF8CString"), .JSStringCreateWithUTF8CString = (JSStringCreateWithUTF8CStringFuncType)dlsym(libraryHandle, "JSStringCreateWithUTF8CString"),
.JSStringCopyCFString = (JSStringCopyCFStringFuncType)dlsym(libraryHandle, "JSStringCopyCFString"),
.JSStringRelease = (JSStringReleaseFuncType)dlsym(libraryHandle, "JSStringRelease"), .JSStringRelease = (JSStringReleaseFuncType)dlsym(libraryHandle, "JSStringRelease"),
.JSGlobalContextSetName = (JSGlobalContextSetNameFuncType)dlsym(libraryHandle, "JSGlobalContextSetName"), .JSGlobalContextSetName = (JSGlobalContextSetNameFuncType)dlsym(libraryHandle, "JSGlobalContextSetName"),
.JSObjectSetProperty = (JSObjectSetPropertyFuncType)dlsym(libraryHandle, "JSObjectSetProperty"), .JSObjectSetProperty = (JSObjectSetPropertyFuncType)dlsym(libraryHandle, "JSObjectSetProperty"),
.JSContextGetGlobalObject = (JSContextGetGlobalObjectFuncType)dlsym(libraryHandle, "JSContextGetGlobalObject"), .JSContextGetGlobalObject = (JSContextGetGlobalObjectFuncType)dlsym(libraryHandle, "JSContextGetGlobalObject"),
.JSObjectGetProperty = (JSObjectGetPropertyFuncType)dlsym(libraryHandle, "JSObjectGetProperty"), .JSObjectGetProperty = (JSObjectGetPropertyFuncType)dlsym(libraryHandle, "JSObjectGetProperty"),
.JSObjectIsFunction = (JSObjectIsFunctionFuncType)dlsym(libraryHandle, "JSObjectIsFunction"),
.JSObjectIsConstructor = (JSObjectIsConstructorFuncType)dlsym(libraryHandle, "JSObjectIsConstructor"),
.JSObjectCopyPropertyNames = (JSObjectCopyPropertyNamesFuncType)dlsym(libraryHandle, "JSObjectCopyPropertyNames"),
.JSPropertyNameArrayGetCount = (JSPropertyNameArrayGetCountFuncType)dlsym(libraryHandle, "JSPropertyNameArrayGetCount"),
.JSPropertyNameArrayGetNameAtIndex = (JSPropertyNameArrayGetNameAtIndexFuncType)dlsym(libraryHandle, "JSPropertyNameArrayGetNameAtIndex"),
.JSPropertyNameArrayRelease = (JSPropertyNameArrayReleaseFuncType)dlsym(libraryHandle, "JSPropertyNameArrayRelease"),
.JSValueMakeFromJSONString = (JSValueMakeFromJSONStringFuncType)dlsym(libraryHandle, "JSValueMakeFromJSONString"), .JSValueMakeFromJSONString = (JSValueMakeFromJSONStringFuncType)dlsym(libraryHandle, "JSValueMakeFromJSONString"),
.JSObjectCallAsFunction = (JSObjectCallAsFunctionFuncType)dlsym(libraryHandle, "JSObjectCallAsFunction"), .JSObjectCallAsFunction = (JSObjectCallAsFunctionFuncType)dlsym(libraryHandle, "JSObjectCallAsFunction"),
.JSValueMakeNull = (JSValueMakeNullFuncType)dlsym(libraryHandle, "JSValueMakeNull"), .JSValueMakeNull = (JSValueMakeNullFuncType)dlsym(libraryHandle, "JSValueMakeNull"),
.JSValueCreateJSONString = (JSValueCreateJSONStringFuncType)dlsym(libraryHandle, "JSValueCreateJSONString"), .JSValueCreateJSONString = (JSValueCreateJSONStringFuncType)dlsym(libraryHandle, "JSValueCreateJSONString"),
.JSValueIsUndefined = (JSValueIsUndefinedFuncType)dlsym(libraryHandle, "JSValueIsUndefined"), .JSValueIsUndefined = (JSValueIsUndefinedFuncType)dlsym(libraryHandle, "JSValueIsUndefined"),
.JSValueIsNull = (JSValueIsNullFuncType)dlsym(libraryHandle, "JSValueIsNull"), .JSValueIsNull = (JSValueIsNullFuncType)dlsym(libraryHandle, "JSValueIsNull"),
.JSValueToObject = (JSValueToObjectFuncType)dlsym(libraryHandle, "JSValueToObject"),
.JSEvaluateScript = (JSEvaluateScriptFuncType)dlsym(libraryHandle, "JSEvaluateScript"), .JSEvaluateScript = (JSEvaluateScriptFuncType)dlsym(libraryHandle, "JSEvaluateScript"),
.JSEvaluateBytecodeBundle = (JSEvaluateBytecodeBundleFuncType)dlsym(libraryHandle, "JSEvaluateBytecodeBundle"), .JSEvaluateBytecodeBundle = (JSEvaluateBytecodeBundleFuncType)dlsym(libraryHandle, "JSEvaluateBytecodeBundle"),
.configureJSCForIOS = (voidWithNoParamsFuncType)dlsym(libraryHandle, "configureJSCForIOS"), .configureJSCForIOS = (voidWithNoParamsFuncType)dlsym(libraryHandle, "configureJSCForIOS"),