Support the bytecode cache for FBReactKit
Reviewed By: javache Differential Revision: D3174040 fb-gh-sync-id: 8d1c43a55ec8764e5b51f13663613b0f7a4a581e fbshipit-source-id: 8d1c43a55ec8764e5b51f13663613b0f7a4a581e
This commit is contained in:
parent
2b69ec2589
commit
033e7c80bf
|
@ -11,6 +11,11 @@
|
|||
|
||||
#import <pthread.h>
|
||||
|
||||
#ifdef WITH_FB_JSC_TUNING
|
||||
#include <string>
|
||||
#include <fbjsc/jsc_config_ios.h>
|
||||
#endif
|
||||
|
||||
#import <JavaScriptCore/JavaScriptCore.h>
|
||||
#import <UIKit/UIDevice.h>
|
||||
|
||||
|
@ -280,12 +285,29 @@ static void RCTInstallJSCProfiler(RCTBridge *bridge, JSContextRef context)
|
|||
- (void)setUp
|
||||
{
|
||||
__weak RCTJSCExecutor *weakSelf = self;
|
||||
|
||||
#ifdef WITH_FB_JSC_TUNING
|
||||
[self executeBlockOnJavaScriptQueue:^{
|
||||
RCTJSCExecutor *strongSelf = weakSelf;
|
||||
if (!strongSelf.valid) {
|
||||
return;
|
||||
}
|
||||
|
||||
NSString *cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject];
|
||||
RCTAssert(cachesPath != nil, @"cachesPath should not be nil");
|
||||
if (cachesPath) {
|
||||
std::string path = std::string([cachesPath UTF8String]);
|
||||
configureJSContextForIOS(strongSelf.context.ctx, path);
|
||||
}
|
||||
}];
|
||||
#endif
|
||||
|
||||
[self addSynchronousHookWithName:@"noop" usingBlock:^{}];
|
||||
|
||||
[self addSynchronousHookWithName:@"nativeLoggingHook" usingBlock:^(NSString *message, NSNumber *logLevel) {
|
||||
RCTLogLevel level = RCTLogLevelInfo;
|
||||
if (logLevel) {
|
||||
level = MAX(level, logLevel.integerValue);
|
||||
level = MAX(level, (RCTLogLevel)logLevel.integerValue);
|
||||
}
|
||||
|
||||
_RCTLogJavaScriptInternal(level, message);
|
||||
|
@ -620,7 +642,7 @@ static void RCTInstallJSCProfiler(RCTBridge *bridge, JSContextRef context)
|
|||
RCTPerformanceLoggerStart(RCTPLScriptExecution);
|
||||
|
||||
JSValueRef jsError = NULL;
|
||||
JSStringRef execJSString = JSStringCreateWithUTF8CString(script.bytes);
|
||||
JSStringRef execJSString = JSStringCreateWithUTF8CString((const char *)script.bytes);
|
||||
JSValueRef result = JSEvaluateScript(strongSelf->_context.ctx, execJSString, NULL, _bundleURL, 0, &jsError);
|
||||
JSStringRelease(execJSString);
|
||||
RCTPerformanceLoggerEnd(RCTPLScriptExecution);
|
||||
|
@ -702,7 +724,8 @@ static void freeModule(__unused CFAllocatorRef allocator, void *ptr)
|
|||
free(ptr);
|
||||
}
|
||||
|
||||
static uint32_t readUint32(const void **ptr) {
|
||||
static uint32_t readUint32(const char **ptr)
|
||||
{
|
||||
uint32_t data;
|
||||
memcpy(&data, *ptr, sizeof(uint32_t));
|
||||
data = NSSwapLittleIntToHost(data);
|
||||
|
@ -710,7 +733,8 @@ static uint32_t readUint32(const void **ptr) {
|
|||
return data;
|
||||
}
|
||||
|
||||
static int readBundle(FILE *fd, size_t offset, size_t length, void *ptr) {
|
||||
static int readBundle(FILE *fd, size_t offset, size_t length, void *ptr)
|
||||
{
|
||||
if (fseek(fd, offset, SEEK_SET) != 0) {
|
||||
return 1;
|
||||
}
|
||||
|
@ -808,12 +832,12 @@ static int readBundle(FILE *fd, size_t offset, size_t length, void *ptr) {
|
|||
return nil;
|
||||
}
|
||||
|
||||
void *tableCursor = tableStart;
|
||||
void *endOfTable = tableCursor + tableLength;
|
||||
char *tableCursor = tableStart;
|
||||
char *endOfTable = tableCursor + tableLength;
|
||||
|
||||
while (tableCursor < endOfTable) {
|
||||
uint32_t nameLength = strlen((const char *)tableCursor);
|
||||
char *name = malloc(nameLength + 1);
|
||||
char *name = (char *)malloc(nameLength + 1);
|
||||
|
||||
if (!name) {
|
||||
if (error) {
|
||||
|
@ -825,13 +849,13 @@ static int readBundle(FILE *fd, size_t offset, size_t length, void *ptr) {
|
|||
strcpy(name, tableCursor);
|
||||
|
||||
// the space allocated for each module's metada gets freed when the module is injected into JSC on `nativeRequire`
|
||||
ModuleData *moduleData = malloc(sizeof(ModuleData));
|
||||
ModuleData *moduleData = (ModuleData *)malloc(sizeof(ModuleData));
|
||||
|
||||
tableCursor += nameLength + 1; // null byte terminator
|
||||
|
||||
moduleData->offset = baseOffset + readUint32((const void **)&tableCursor);
|
||||
moduleData->length = readUint32((const void **)&tableCursor);
|
||||
moduleData->lineNo = readUint32((const void **)&tableCursor);
|
||||
moduleData->offset = baseOffset + readUint32((const char **)&tableCursor);
|
||||
moduleData->length = readUint32((const char **)&tableCursor);
|
||||
moduleData->lineNo = readUint32((const char **)&tableCursor);
|
||||
|
||||
CFDictionarySetValue(_jsModules, name, moduleData);
|
||||
}
|
|
@ -13,7 +13,7 @@
|
|||
133CAE8E1B8E5CFD00F6AD92 /* RCTDatePicker.m in Sources */ = {isa = PBXBuildFile; fileRef = 133CAE8D1B8E5CFD00F6AD92 /* RCTDatePicker.m */; };
|
||||
13456E931ADAD2DE009F94A7 /* RCTConvert+CoreLocation.m in Sources */ = {isa = PBXBuildFile; fileRef = 13456E921ADAD2DE009F94A7 /* RCTConvert+CoreLocation.m */; };
|
||||
13456E961ADAD482009F94A7 /* RCTConvert+MapKit.m in Sources */ = {isa = PBXBuildFile; fileRef = 13456E951ADAD482009F94A7 /* RCTConvert+MapKit.m */; };
|
||||
134FCB3D1A6E7F0800051CC8 /* RCTJSCExecutor.m in Sources */ = {isa = PBXBuildFile; fileRef = 134FCB3A1A6E7F0800051CC8 /* RCTJSCExecutor.m */; };
|
||||
134FCB3D1A6E7F0800051CC8 /* RCTJSCExecutor.mm in Sources */ = {isa = PBXBuildFile; fileRef = 134FCB3A1A6E7F0800051CC8 /* RCTJSCExecutor.mm */; };
|
||||
13513F3C1B1F43F400FCE529 /* RCTProgressViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 13513F3B1B1F43F400FCE529 /* RCTProgressViewManager.m */; };
|
||||
13723B501A82FD3C00F88898 /* RCTStatusBarManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 13723B4F1A82FD3C00F88898 /* RCTStatusBarManager.m */; };
|
||||
1372B70A1AB030C200659ED6 /* RCTAppState.m in Sources */ = {isa = PBXBuildFile; fileRef = 1372B7091AB030C200659ED6 /* RCTAppState.m */; };
|
||||
|
@ -127,7 +127,7 @@
|
|||
1345A83A1B265A0E00583190 /* RCTURLRequestDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTURLRequestDelegate.h; sourceTree = "<group>"; };
|
||||
1345A83B1B265A0E00583190 /* RCTURLRequestHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTURLRequestHandler.h; sourceTree = "<group>"; };
|
||||
134FCB391A6E7F0800051CC8 /* RCTJSCExecutor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTJSCExecutor.h; sourceTree = "<group>"; };
|
||||
134FCB3A1A6E7F0800051CC8 /* RCTJSCExecutor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTJSCExecutor.m; sourceTree = "<group>"; };
|
||||
134FCB3A1A6E7F0800051CC8 /* RCTJSCExecutor.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RCTJSCExecutor.mm; sourceTree = "<group>"; };
|
||||
13513F3A1B1F43F400FCE529 /* RCTProgressViewManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTProgressViewManager.h; sourceTree = "<group>"; };
|
||||
13513F3B1B1F43F400FCE529 /* RCTProgressViewManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTProgressViewManager.m; sourceTree = "<group>"; };
|
||||
13723B4E1A82FD3C00F88898 /* RCTStatusBarManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTStatusBarManager.h; sourceTree = "<group>"; };
|
||||
|
@ -318,7 +318,7 @@
|
|||
isa = PBXGroup;
|
||||
children = (
|
||||
134FCB391A6E7F0800051CC8 /* RCTJSCExecutor.h */,
|
||||
134FCB3A1A6E7F0800051CC8 /* RCTJSCExecutor.m */,
|
||||
134FCB3A1A6E7F0800051CC8 /* RCTJSCExecutor.mm */,
|
||||
);
|
||||
path = Executors;
|
||||
sourceTree = "<group>";
|
||||
|
@ -710,7 +710,7 @@
|
|||
13A0C2891B74F71200B29F6F /* RCTDevLoadingView.m in Sources */,
|
||||
13B07FF21A69327A00A75B9A /* RCTTiming.m in Sources */,
|
||||
1372B70A1AB030C200659ED6 /* RCTAppState.m in Sources */,
|
||||
134FCB3D1A6E7F0800051CC8 /* RCTJSCExecutor.m in Sources */,
|
||||
134FCB3D1A6E7F0800051CC8 /* RCTJSCExecutor.mm in Sources */,
|
||||
14C2CA781B3ACB0400E6CBB2 /* RCTBatchedBridge.m in Sources */,
|
||||
13E067591A70F44B002CDEE1 /* UIView+React.m in Sources */,
|
||||
14F484561AABFCE100FDF6B9 /* RCTSliderManager.m in Sources */,
|
||||
|
|
Loading…
Reference in New Issue