├── JPPlaygroundTool ├── JPPlayground.h ├── JPPlayground.m ├── JPPlaygroundModule │ ├── JPKeyCommands.h │ ├── JPKeyCommands.m │ ├── SGDirWatchdog.h │ └── SGDirWatchdog.m └── JPPlaygroundView │ ├── JPDevErrorView.h │ ├── JPDevErrorView.m │ ├── JPDevMenu.h │ ├── JPDevMenu.m │ ├── JPDevTipView.h │ └── JPDevTipView.m ├── JSPatchPlaygroundDemo ├── Extensions │ ├── JPCFunction │ │ ├── JPCFunction.h │ │ ├── JPCFunction.m │ │ ├── JPMemory.h │ │ ├── JPMemory.m │ │ ├── JPStructPointer.h │ │ ├── JPStructPointer.m │ │ └── libffi │ │ │ ├── headers │ │ │ ├── ffi.h │ │ │ ├── ffi_arm64.h │ │ │ ├── ffi_armv7.h │ │ │ ├── ffi_common.h │ │ │ ├── ffi_i386.h │ │ │ ├── ffi_x86_64.h │ │ │ ├── fficonfig.h │ │ │ ├── fficonfig_arm64.h │ │ │ ├── fficonfig_armv7.h │ │ │ ├── fficonfig_i386.h │ │ │ ├── fficonfig_x86_64.h │ │ │ ├── ffitarget.h │ │ │ ├── ffitarget_arm64.h │ │ │ ├── ffitarget_armv7.h │ │ │ ├── ffitarget_i386.h │ │ │ └── ffitarget_x86_64.h │ │ │ └── src │ │ │ ├── aarch64 │ │ │ ├── ffi_arm64.c │ │ │ └── sysv_arm64.S │ │ │ ├── arm │ │ │ ├── ffi_armv7.c │ │ │ ├── sysv_armv7.S │ │ │ └── trampoline_armv7.S │ │ │ ├── common │ │ │ ├── prep_cif.c │ │ │ ├── raw_api.c │ │ │ └── types.c │ │ │ └── x86 │ │ │ ├── darwin64_x86_64.S │ │ │ ├── darwin_i386.S │ │ │ ├── ffi64_x86_64.c │ │ │ ├── ffi_i386.c │ │ │ └── win32_i386.S │ ├── JPCFunctionBinder │ │ ├── CoreGraphics │ │ │ ├── JPCGBitmapContext.h │ │ │ ├── JPCGBitmapContext.m │ │ │ ├── JPCGColor.h │ │ │ ├── JPCGColor.m │ │ │ ├── JPCGContext.h │ │ │ ├── JPCGContext.m │ │ │ ├── JPCGGeometry.h │ │ │ ├── JPCGGeometry.m │ │ │ ├── JPCGImage.h │ │ │ ├── JPCGImage.m │ │ │ ├── JPCGPath.h │ │ │ ├── JPCGPath.m │ │ │ ├── JPCGTransform.h │ │ │ ├── JPCGTransform.m │ │ │ ├── JPCoreGraphics.h │ │ │ └── JPCoreGraphics.m │ │ └── UIKit │ │ │ ├── JPUIGeometry.h │ │ │ ├── JPUIGeometry.m │ │ │ ├── JPUIGraphics.h │ │ │ ├── JPUIGraphics.m │ │ │ ├── JPUIImage.h │ │ │ ├── JPUIImage.m │ │ │ ├── JPUIKit.h │ │ │ └── JPUIKit.m │ ├── JPCleaner.h │ ├── JPCleaner.m │ ├── JPLocker.h │ ├── JPLocker.m │ ├── JPSpecialInit.h │ └── JPSpecialInit.m ├── JSPatch │ ├── JPEngine.h │ ├── JPEngine.m │ └── JSPatch.js ├── JSPatchPlaygroundDemo.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── JSPatchPlaygroundDemo.xcscmblueprint │ │ └── xcuserdata │ │ │ └── Awhisper.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── Awhisper.xcuserdatad │ │ └── xcschemes │ │ ├── JSPatchPlaygroundDemo.xcscheme │ │ └── xcschememanagement.plist └── JSPatchPlaygroundDemo │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── Contents.json │ └── apple.imageset │ │ ├── Contents.json │ │ └── apple.png │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ ├── JPRootViewController.h │ ├── JPRootViewController.m │ ├── js │ ├── demo.js │ └── demo2.js │ └── main.m ├── README.md └── Screenshot.gif /JPPlaygroundTool/JPPlayground.h: -------------------------------------------------------------------------------- 1 | // 2 | // JPPlayground.h 3 | // JSPatchPlaygroundDemo 4 | // 5 | // Created by Awhisper on 16/8/7. 6 | // Copyright © 2016年 baidu. All rights reserved. 7 | // 8 | #import 9 | 10 | @interface JPPlayground : NSObject 11 | 12 | +(void)startPlaygroundWithJSPath:(NSString *)path; 13 | 14 | +(void)setReloadCompleteHandler:(void(^)())complete; 15 | 16 | +(void)reload; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /JPPlaygroundTool/JPPlayground.m: -------------------------------------------------------------------------------- 1 | // 2 | // JPPlayground.m 3 | // JSPatchPlaygroundDemo 4 | // 5 | // Created by Awhisper on 16/8/7. 6 | // Copyright © 2016年 baidu. All rights reserved. 7 | // 8 | 9 | #import "JPPlayground.h" 10 | #import "JPKeyCommands.h" 11 | #import "JPDevErrorView.h" 12 | #import "JPDevMenu.h" 13 | #import "JPDevTipView.h" 14 | #import "SGDirWatchdog.h" 15 | 16 | @interface JPPlayground () 17 | 18 | @property (nonatomic,strong) NSString *rootPath; 19 | 20 | @property (nonatomic,strong) JPKeyCommands *keyManager; 21 | 22 | @property (nonatomic,strong) UIView *errorView; 23 | 24 | @property (nonatomic,strong) JPDevMenu *devMenu; 25 | 26 | @property (nonatomic,assign) BOOL isAutoReloading; 27 | 28 | @property (nonatomic,strong) NSMutableArray *watchDogs; 29 | 30 | @end 31 | 32 | static void (^_reloadCompleteHandler)(void) = ^void(void) { 33 | 34 | }; 35 | 36 | @implementation JPPlayground 37 | 38 | #pragma clang diagnostic push 39 | #pragma clang diagnostic ignored "-Wundeclared-selector" 40 | 41 | + (instancetype)sharedInstance 42 | { 43 | #if TARGET_IPHONE_SIMULATOR 44 | static JPPlayground *sharedInstance; 45 | static dispatch_once_t onceToken; 46 | dispatch_once(&onceToken, ^{ 47 | sharedInstance = [self new]; 48 | }); 49 | 50 | return sharedInstance; 51 | #else 52 | return nil; 53 | #endif 54 | } 55 | 56 | - (instancetype)init 57 | { 58 | if ((self = [super init])) { 59 | #if TARGET_IPHONE_SIMULATOR 60 | _keyManager = [JPKeyCommands sharedInstance]; 61 | _devMenu = [[JPDevMenu alloc]init]; 62 | _devMenu.delegate = self; 63 | _isAutoReloading = NO; 64 | _watchDogs = [[NSMutableArray alloc] init]; 65 | #endif 66 | } 67 | return self; 68 | } 69 | 70 | +(void)setReloadCompleteHandler:(void (^)())complete 71 | { 72 | _reloadCompleteHandler = [complete copy]; 73 | } 74 | 75 | +(void)startPlaygroundWithJSPath:(NSString *)path 76 | { 77 | [[JPPlayground sharedInstance] startPlaygroundWithJSPath:path]; 78 | } 79 | 80 | -(void)startPlaygroundWithJSPath:(NSString *)mainScriptPath 81 | { 82 | #if TARGET_IPHONE_SIMULATOR 83 | self.rootPath = mainScriptPath; 84 | 85 | NSString *scriptRootPath = [mainScriptPath stringByDeletingLastPathComponent]; 86 | 87 | NSArray *contentOfFolder = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:scriptRootPath error:NULL]; 88 | [self watchFolder:scriptRootPath mainScriptPath:mainScriptPath]; 89 | 90 | if ([scriptRootPath rangeOfString:@".app"].location != NSNotFound) { 91 | NSString *apphomepath = [scriptRootPath stringByDeletingLastPathComponent]; 92 | [self watchFolder:apphomepath mainScriptPath:mainScriptPath]; 93 | } 94 | 95 | for (NSString *aPath in contentOfFolder) { 96 | NSString * fullPath = [scriptRootPath stringByAppendingPathComponent:aPath]; 97 | BOOL isDir; 98 | if ([[NSFileManager defaultManager] fileExistsAtPath:fullPath isDirectory:&isDir] && isDir) { 99 | [self watchFolder:fullPath mainScriptPath:mainScriptPath]; 100 | } 101 | } 102 | void(^exceptionhandler)(NSString *msg) = ^(NSString *msg){ 103 | JPDevErrorView *errV = [[JPDevErrorView alloc]initError:msg]; 104 | [[UIApplication sharedApplication].keyWindow addSubview:errV]; 105 | self.errorView = errV; 106 | [self.devMenu toggle]; 107 | }; 108 | id JPEngineClass = (id)NSClassFromString(@"JPEngine"); 109 | if (JPEngineClass && [JPEngineClass respondsToSelector:@selector(handleException:)]) { 110 | [JPEngineClass performSelector:@selector(handleException:) withObject:exceptionhandler]; 111 | }else{ 112 | NSCAssert(NO, @"can't find JPEngine handleException: Method"); 113 | } 114 | 115 | [self.keyManager registerKeyCommandWithInput:@"x" modifierFlags:UIKeyModifierCommand action:^(UIKeyCommand *command) { 116 | [self.devMenu toggle]; 117 | }]; 118 | 119 | [self.keyManager registerKeyCommandWithInput:@"r" modifierFlags:UIKeyModifierCommand action:^(UIKeyCommand *command) { 120 | [self reload]; 121 | }]; 122 | 123 | [self reload]; 124 | #endif 125 | } 126 | 127 | +(void)reload 128 | { 129 | [[JPPlayground sharedInstance]reload]; 130 | } 131 | 132 | -(void)reload 133 | { 134 | #if TARGET_IPHONE_SIMULATOR 135 | [JPDevTipView showJPDevTip:@"JSPatch Reloading ..."]; 136 | [self hideErrorView]; 137 | id JPCleanerClass = (id)NSClassFromString(@"JPCleaner"); 138 | if (JPCleanerClass && [JPCleanerClass respondsToSelector:@selector(cleanAll)]) { 139 | [JPCleanerClass performSelector:@selector(cleanAll)]; 140 | }else{ 141 | NSCAssert(NO, @"can't find JPCleaner cleanAll Method"); 142 | } 143 | 144 | NSString *script = [NSString stringWithContentsOfFile:self.rootPath encoding:NSUTF8StringEncoding error:nil]; 145 | 146 | id JPEngineClass = (id)NSClassFromString(@"JPEngine"); 147 | if (JPEngineClass && [JPEngineClass respondsToSelector:@selector(evaluateScript:)]) { 148 | [JPEngineClass performSelector:@selector(evaluateScript:) withObject:script]; 149 | }else{ 150 | NSCAssert(NO, @"can't find JPEngine evaluateScript: Method"); 151 | } 152 | 153 | _reloadCompleteHandler(); 154 | #endif 155 | } 156 | 157 | -(void)openInFinder 158 | { 159 | #if TARGET_IPHONE_SIMULATOR 160 | NSLog(@"%@\n",self.rootPath); 161 | 162 | NSLog(@"请打开以上路径的文件,事实编辑JS,事实刷新"); 163 | 164 | NSString *msg = [NSString stringWithFormat:@"JS文件路径:%@\n 编辑JS文件后保存,按Command+R刷新就可以看到最新的代码效果",self.rootPath]; 165 | 166 | #pragma clang diagnostic push 167 | #pragma clang diagnostic ignored "-Wdeprecated-declarations" 168 | UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Edit JS File and Reload" message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; 169 | [alert show]; 170 | [UIPasteboard generalPasteboard].string = self.rootPath; 171 | #pragma clang diagnostic pop 172 | 173 | #endif 174 | } 175 | 176 | -(void)watchJSFile:(BOOL)watch 177 | { 178 | #if TARGET_IPHONE_SIMULATOR 179 | for (SGDirWatchdog *dog in self.watchDogs) { 180 | if (watch) { 181 | [dog start]; 182 | }else{ 183 | [dog stop]; 184 | } 185 | } 186 | #endif 187 | } 188 | 189 | - (void)watchFolder:(NSString *)folderPath mainScriptPath:(NSString *)mainScriptPath 190 | { 191 | #if TARGET_IPHONE_SIMULATOR 192 | SGDirWatchdog *watchDog = [[SGDirWatchdog alloc] initWithPath:folderPath update:^{ 193 | [self reload]; 194 | }]; 195 | [self.watchDogs addObject:watchDog]; 196 | #endif 197 | } 198 | 199 | -(void)hideErrorView 200 | { 201 | #if TARGET_IPHONE_SIMULATOR 202 | [self.errorView removeFromSuperview]; 203 | self.errorView = nil; 204 | #endif 205 | } 206 | 207 | 208 | -(void)devMenuDidAction:(JPDevMenuAction)action withValue:(id)value 209 | { 210 | #if TARGET_IPHONE_SIMULATOR 211 | switch (action) { 212 | case JPDevMenuActionReload:{ 213 | [self reload]; 214 | break; 215 | } 216 | case JPDevMenuActionAutoReload:{ 217 | BOOL select = [value boolValue]; 218 | [self watchJSFile:select]; 219 | break; 220 | } 221 | case JPDevMenuActionOpenJS:{ 222 | [self openInFinder]; 223 | break; 224 | } 225 | case JPDevMenuActionCancel:{ 226 | [self hideErrorView]; 227 | break; 228 | } 229 | 230 | 231 | default: 232 | break; 233 | } 234 | #endif 235 | } 236 | 237 | #pragma clang diagnostic pop 238 | @end 239 | -------------------------------------------------------------------------------- /JPPlaygroundTool/JPPlaygroundModule/JPKeyCommands.h: -------------------------------------------------------------------------------- 1 | // 2 | // JPKeyCommands.h 3 | // JSPatchPlaygroundDemo 4 | // 5 | // Created by Awhisper on 16/8/7. 6 | // Copyright © 2016年 baidu. All rights reserved. 7 | // 8 | 9 | 10 | #import 11 | 12 | @interface JPKeyCommands : NSObject 13 | 14 | + (instancetype)sharedInstance; 15 | 16 | - (void)registerKeyCommandWithInput:(NSString *)input 17 | modifierFlags:(UIKeyModifierFlags)flags 18 | action:(void (^)(UIKeyCommand *))block; 19 | 20 | - (void)unregisterKeyCommandWithInput:(NSString *)input 21 | modifierFlags:(UIKeyModifierFlags)flags; 22 | 23 | - (BOOL)isKeyCommandRegisteredForInput:(NSString *)input 24 | modifierFlags:(UIKeyModifierFlags)flags; 25 | @end 26 | -------------------------------------------------------------------------------- /JPPlaygroundTool/JPPlaygroundModule/JPKeyCommands.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #import "JPKeyCommands.h" 11 | 12 | #import 13 | #import 14 | 15 | static BOOL JPIsIOS8OrEarlier() 16 | { 17 | return [UIDevice currentDevice].systemVersion.floatValue < 9; 18 | } 19 | 20 | 21 | void JPSwapInstanceMethods(Class cls, SEL original, SEL replacement) 22 | { 23 | Method originalMethod = class_getInstanceMethod(cls, original); 24 | IMP originalImplementation = method_getImplementation(originalMethod); 25 | const char *originalArgTypes = method_getTypeEncoding(originalMethod); 26 | 27 | Method replacementMethod = class_getInstanceMethod(cls, replacement); 28 | IMP replacementImplementation = method_getImplementation(replacementMethod); 29 | const char *replacementArgTypes = method_getTypeEncoding(replacementMethod); 30 | 31 | if (class_addMethod(cls, original, replacementImplementation, replacementArgTypes)) { 32 | class_replaceMethod(cls, replacement, originalImplementation, originalArgTypes); 33 | } else { 34 | method_exchangeImplementations(originalMethod, replacementMethod); 35 | } 36 | } 37 | 38 | 39 | #if TARGET_IPHONE_SIMULATOR 40 | 41 | @interface JPKeyCommand : NSObject 42 | 43 | @property (nonatomic, strong) UIKeyCommand *keyCommand; 44 | @property (nonatomic, copy) void (^block)(UIKeyCommand *); 45 | 46 | @end 47 | 48 | @implementation JPKeyCommand 49 | 50 | - (instancetype)initWithKeyCommand:(UIKeyCommand *)keyCommand 51 | block:(void (^)(UIKeyCommand *))block 52 | { 53 | if ((self = [super init])) { 54 | _keyCommand = keyCommand; 55 | _block = block; 56 | } 57 | return self; 58 | } 59 | 60 | 61 | - (id)copyWithZone:(__unused NSZone *)zone 62 | { 63 | return self; 64 | } 65 | 66 | - (NSUInteger)hash 67 | { 68 | return _keyCommand.input.hash ^ _keyCommand.modifierFlags; 69 | } 70 | 71 | - (BOOL)isEqual:(JPKeyCommand *)object 72 | { 73 | if (![object isKindOfClass:[JPKeyCommand class]]) { 74 | return NO; 75 | } 76 | return [self matchesInput:object.keyCommand.input 77 | flags:object.keyCommand.modifierFlags]; 78 | } 79 | 80 | - (BOOL)matchesInput:(NSString *)input flags:(UIKeyModifierFlags)flags 81 | { 82 | return [_keyCommand.input isEqual:input] && _keyCommand.modifierFlags == flags; 83 | } 84 | 85 | - (NSString *)description 86 | { 87 | return [NSString stringWithFormat:@"<%@:%p input=\"%@\" flags=%zd hasBlock=%@>", 88 | [self class], self, _keyCommand.input, _keyCommand.modifierFlags, 89 | _block ? @"YES" : @"NO"]; 90 | } 91 | 92 | @end 93 | 94 | @interface JPKeyCommands () 95 | 96 | @property (nonatomic, strong) NSMutableSet *commands; 97 | 98 | @end 99 | 100 | @implementation UIResponder (RCTKeyCommands) 101 | 102 | - (NSArray *)JP_keyCommands 103 | { 104 | NSSet *commands = [JPKeyCommands sharedInstance].commands; 105 | return [[commands valueForKeyPath:@"keyCommand"] allObjects]; 106 | } 107 | 108 | 109 | - (void)JP_handleKeyCommand:(UIKeyCommand *)key 110 | { 111 | // NOTE: throttle the key handler because on iOS 9 the handleKeyCommand: 112 | // method gets called repeatedly if the command key is held down. 113 | 114 | static NSTimeInterval lastCommand = 0; 115 | if (JPIsIOS8OrEarlier() || CACurrentMediaTime() - lastCommand > 0.5) { 116 | for (JPKeyCommand *command in [JPKeyCommands sharedInstance].commands) { 117 | if ([command.keyCommand.input isEqualToString:key.input] && 118 | command.keyCommand.modifierFlags == key.modifierFlags) { 119 | if (command.block) { 120 | command.block(key); 121 | lastCommand = CACurrentMediaTime(); 122 | } 123 | } 124 | } 125 | } 126 | } 127 | 128 | @end 129 | 130 | @implementation UIApplication (JPKeyCommands) 131 | 132 | // Required for iOS 8.x 133 | - (BOOL)JP_sendAction:(SEL)action to:(id)target from:(id)sender forEvent:(UIEvent *)event 134 | { 135 | if (action == @selector(JP_handleKeyCommand:)) { 136 | [self JP_handleKeyCommand:sender]; 137 | return YES; 138 | } 139 | return [self JP_sendAction:action to:target from:sender forEvent:event]; 140 | } 141 | 142 | @end 143 | 144 | @implementation JPKeyCommands 145 | 146 | + (void)initialize 147 | { 148 | if (JPIsIOS8OrEarlier()) { 149 | 150 | //swizzle UIApplication 151 | JPSwapInstanceMethods([UIApplication class], 152 | @selector(keyCommands), 153 | @selector(JP_keyCommands)); 154 | 155 | JPSwapInstanceMethods([UIApplication class], 156 | @selector(sendAction:to:from:forEvent:), 157 | @selector(JP_sendAction:to:from:forEvent:)); 158 | } else { 159 | 160 | //swizzle UIResponder 161 | JPSwapInstanceMethods([UIResponder class], 162 | @selector(keyCommands), 163 | @selector(JP_keyCommands)); 164 | } 165 | } 166 | 167 | + (instancetype)sharedInstance 168 | { 169 | static JPKeyCommands *sharedInstance; 170 | static dispatch_once_t onceToken; 171 | dispatch_once(&onceToken, ^{ 172 | sharedInstance = [self new]; 173 | }); 174 | 175 | return sharedInstance; 176 | } 177 | 178 | - (instancetype)init 179 | { 180 | if ((self = [super init])) { 181 | _commands = [NSMutableSet new]; 182 | } 183 | return self; 184 | } 185 | 186 | - (void)registerKeyCommandWithInput:(NSString *)input 187 | modifierFlags:(UIKeyModifierFlags)flags 188 | action:(void (^)(UIKeyCommand *))block 189 | { 190 | 191 | if (input.length && flags && JPIsIOS8OrEarlier()) { 192 | 193 | // Workaround around the first cmd not working: http://openradar.appspot.com/19613391 194 | // You can register just the cmd key and do nothing. This ensures that 195 | // command-key modified commands will work first time. Fixed in iOS 9. 196 | 197 | [self registerKeyCommandWithInput:@"" 198 | modifierFlags:flags 199 | action:nil]; 200 | } 201 | 202 | UIKeyCommand *command = [UIKeyCommand keyCommandWithInput:input 203 | modifierFlags:flags 204 | action:@selector(JP_handleKeyCommand:)]; 205 | 206 | JPKeyCommand *keyCommand = [[JPKeyCommand alloc] initWithKeyCommand:command block:block]; 207 | [_commands removeObject:keyCommand]; 208 | [_commands addObject:keyCommand]; 209 | } 210 | 211 | - (void)unregisterKeyCommandWithInput:(NSString *)input 212 | modifierFlags:(UIKeyModifierFlags)flags 213 | { 214 | 215 | for (JPKeyCommand *command in _commands.allObjects) { 216 | if ([command matchesInput:input flags:flags]) { 217 | [_commands removeObject:command]; 218 | break; 219 | } 220 | } 221 | } 222 | 223 | - (BOOL)isKeyCommandRegisteredForInput:(NSString *)input 224 | modifierFlags:(UIKeyModifierFlags)flags 225 | { 226 | 227 | for (JPKeyCommand *command in _commands) { 228 | if ([command matchesInput:input flags:flags]) { 229 | return YES; 230 | } 231 | } 232 | return NO; 233 | } 234 | 235 | @end 236 | 237 | #else 238 | 239 | @implementation JPKeyCommands 240 | 241 | + (instancetype)sharedInstance 242 | { 243 | return nil; 244 | } 245 | 246 | - (void)registerKeyCommandWithInput:(NSString *)input 247 | modifierFlags:(UIKeyModifierFlags)flags 248 | action:(void (^)(UIKeyCommand *))block { 249 | 250 | }; 251 | 252 | - (void)unregisterKeyCommandWithInput:(NSString *)input 253 | modifierFlags:(UIKeyModifierFlags)flags { 254 | 255 | }; 256 | 257 | - (BOOL)isKeyCommandRegisteredForInput:(NSString *)input 258 | modifierFlags:(UIKeyModifierFlags)flags 259 | { 260 | return NO; 261 | } 262 | 263 | @end 264 | 265 | #endif 266 | 267 | -------------------------------------------------------------------------------- /JPPlaygroundTool/JPPlaygroundModule/SGDirWatchdog.h: -------------------------------------------------------------------------------- 1 | // 2 | // SGDirObserver.h 3 | // DirectoryObserver 4 | // 5 | // Copyright (c) 2011 Simon Grätzer. 6 | // 7 | 8 | #import 9 | 10 | @interface SGDirWatchdog : NSObject 11 | 12 | @property (readonly, nonatomic) NSString *path; 13 | @property (copy, nonatomic) void (^update)(void); 14 | 15 | + (NSString *)documentsPath; 16 | + (id)watchtdogOnDocumentsDir:(void (^)(void))update; 17 | 18 | - (id)initWithPath:(NSString *)path update:(void (^)(void))update; 19 | 20 | - (void)start; 21 | - (void)stop; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /JPPlaygroundTool/JPPlaygroundModule/SGDirWatchdog.m: -------------------------------------------------------------------------------- 1 | // 2 | // SGDirObserver.m 3 | // DirectoryObserver 4 | // 5 | // Copyright (c) 2011 Simon Grätzer. 6 | // 7 | 8 | #import "SGDirWatchdog.h" 9 | #import 10 | #import 11 | #import 12 | 13 | @interface SGDirWatchdog () 14 | @property (nonatomic, readonly) CFFileDescriptorRef kqRef; 15 | - (void)kqueueFired; 16 | @end 17 | 18 | 19 | static void KQCallback(CFFileDescriptorRef kqRef, CFOptionFlags callBackTypes, void *info) { 20 | // Pick up the object passed in the "info" member of the CFFileDescriptorContext passed to CFFileDescriptorCreate 21 | SGDirWatchdog* obj = (__bridge SGDirWatchdog*) info; 22 | 23 | if ([obj isKindOfClass:[SGDirWatchdog class]] && // If we can call back to the proper sort of object ... 24 | (kqRef == obj.kqRef) && // and the FD that issued the CB is the expected one ... 25 | (callBackTypes == kCFFileDescriptorReadCallBack) ) // and we're processing the proper sort of CB ... 26 | { 27 | [obj kqueueFired]; // Invoke the instance's CB handler 28 | } 29 | } 30 | 31 | @implementation SGDirWatchdog { 32 | int _dirFD; 33 | CFFileDescriptorRef _kqRef; 34 | } 35 | 36 | + (NSString *)documentsPath { 37 | NSArray *documentsPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 38 | 39 | return documentsPaths[0]; // Path to the application's "Documents" directory 40 | } 41 | 42 | + (id)watchtdogOnDocumentsDir:(void (^)(void))update; { 43 | return [[SGDirWatchdog alloc]initWithPath:[self documentsPath] update:update]; 44 | } 45 | 46 | 47 | - (id)initWithPath:(NSString *)path update:(void (^)(void))update; { 48 | if ((self = [super init])) { 49 | _path = path; 50 | _update = [update copy]; 51 | } 52 | return self; 53 | } 54 | 55 | - (void)dealloc { 56 | [self stop]; 57 | 58 | 59 | } 60 | 61 | #pragma mark - 62 | #pragma mark Extension methods 63 | 64 | - (void)kqueueFired { 65 | // Pull the native FD around which the CFFileDescriptor was wrapped 66 | int kq = CFFileDescriptorGetNativeDescriptor(_kqRef); 67 | if (kq < 0) return; 68 | 69 | // If we pull a single available event out of the queue, assume the directory was updated 70 | struct kevent event; 71 | struct timespec timeout = {0, 0}; 72 | if (kevent(kq, NULL, 0, &event, 1, &timeout) == 1 && _update) { 73 | _update(); 74 | } 75 | 76 | // (Re-)Enable a one-shot (the only kind) callback 77 | CFFileDescriptorEnableCallBacks(_kqRef, kCFFileDescriptorReadCallBack); 78 | } 79 | 80 | 81 | - (void)start { 82 | // One ping only 83 | if (_kqRef != NULL) return; 84 | 85 | // Fetch pathname of the directory to monitor 86 | NSString* docPath = self.path; 87 | if (!docPath) return; 88 | 89 | // Open an event-only file descriptor associated with the directory 90 | int dirFD = open([docPath fileSystemRepresentation], O_EVTONLY); 91 | if (dirFD < 0) return; 92 | 93 | // Create a new kernel event queue 94 | int kq = kqueue(); 95 | if (kq < 0) 96 | { 97 | close(dirFD); 98 | return; 99 | } 100 | 101 | // Set up a kevent to monitor 102 | struct kevent eventToAdd; // Register an (ident, filter) pair with the kqueue 103 | eventToAdd.ident = dirFD; // The object to watch (the directory FD) 104 | eventToAdd.filter = EVFILT_VNODE; // Watch for certain events on the VNODE spec'd by ident 105 | eventToAdd.flags = EV_ADD | EV_CLEAR; // Add a resetting kevent 106 | eventToAdd.fflags = NOTE_WRITE; // The events to watch for on the VNODE spec'd by ident (writes) 107 | eventToAdd.data = 0; // No filter-specific data 108 | eventToAdd.udata = NULL; // No user data 109 | 110 | // Add a kevent to monitor 111 | if (kevent(kq, &eventToAdd, 1, NULL, 0, NULL)) { 112 | close(kq); 113 | close(dirFD); 114 | return; 115 | } 116 | 117 | // Wrap a CFFileDescriptor around a native FD 118 | CFFileDescriptorContext context = {0, (__bridge void *)(self), NULL, NULL, NULL}; 119 | _kqRef = CFFileDescriptorCreate(NULL, // Use the default allocator 120 | kq, // Wrap the kqueue 121 | true, // Close the CFFileDescriptor if kq is invalidated 122 | KQCallback, // Fxn to call on activity 123 | &context); // Supply a context to set the callback's "info" argument 124 | if (_kqRef == NULL) { 125 | close(kq); 126 | close(dirFD); 127 | return; 128 | } 129 | 130 | // Spin out a pluggable run loop source from the CFFileDescriptorRef 131 | // Add it to the current run loop, then release it 132 | CFRunLoopSourceRef rls = CFFileDescriptorCreateRunLoopSource(NULL, _kqRef, 0); 133 | if (rls == NULL) { 134 | CFRelease(_kqRef); _kqRef = NULL; 135 | close(kq); 136 | close(dirFD); 137 | return; 138 | } 139 | CFRunLoopAddSource(CFRunLoopGetCurrent(), rls, kCFRunLoopDefaultMode); 140 | CFRelease(rls); 141 | 142 | // Store the directory FD for later closing 143 | _dirFD = dirFD; 144 | 145 | // Enable a one-shot (the only kind) callback 146 | CFFileDescriptorEnableCallBacks(_kqRef, kCFFileDescriptorReadCallBack); 147 | } 148 | 149 | - (void)stop { 150 | if (_kqRef) { 151 | close(_dirFD); 152 | CFFileDescriptorInvalidate(_kqRef); 153 | CFRelease(_kqRef); 154 | _kqRef = NULL; 155 | } 156 | } 157 | 158 | @end 159 | -------------------------------------------------------------------------------- /JPPlaygroundTool/JPPlaygroundView/JPDevErrorView.h: -------------------------------------------------------------------------------- 1 | // 2 | // JPErrorView.h 3 | // JSPatchPlaygroundDemo 4 | // 5 | // Created by Awhisper on 16/8/7. 6 | // Copyright © 2016年 baidu. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface JPDevErrorView : UIView 12 | 13 | - (instancetype)initError:(NSString *)errMsg; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /JPPlaygroundTool/JPPlaygroundView/JPDevErrorView.m: -------------------------------------------------------------------------------- 1 | // 2 | // JPErrorView.m 3 | // JSPatchPlaygroundDemo 4 | // 5 | // Created by Awhisper on 16/8/7. 6 | // Copyright © 2016年 baidu. All rights reserved. 7 | // 8 | 9 | #import "JPDevErrorView.h" 10 | 11 | 12 | 13 | @implementation JPDevErrorView 14 | 15 | - (instancetype)initError:(NSString *)errMsg 16 | { 17 | self = [super initWithFrame:[UIScreen mainScreen].bounds]; 18 | if (self) { 19 | self.backgroundColor = [UIColor redColor]; 20 | 21 | UITextView *text = [[UITextView alloc]initWithFrame:CGRectMake(0, 20, self.bounds.size.width, self.bounds.size.height-20)]; 22 | text.backgroundColor = [UIColor redColor]; 23 | text.textColor = [UIColor whiteColor]; 24 | text.font = [UIFont systemFontOfSize:20]; 25 | text.userInteractionEnabled = NO; 26 | 27 | text.text = errMsg; 28 | 29 | [self addSubview:text]; 30 | 31 | } 32 | return self; 33 | } 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /JPPlaygroundTool/JPPlaygroundView/JPDevMenu.h: -------------------------------------------------------------------------------- 1 | // 2 | // JPPlaygroundMenu.h 3 | // JSPatchPlaygroundDemo 4 | // 5 | // Created by Awhisper on 16/8/7. 6 | // Copyright © 2016年 baidu. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef enum : NSUInteger { 12 | JPDevMenuActionReload = 0, 13 | JPDevMenuActionAutoReload, 14 | JPDevMenuActionOpenJS, 15 | JPDevMenuActionCancel 16 | } JPDevMenuAction; 17 | 18 | @protocol JPDevMenuDelegate 19 | 20 | -(void)devMenuDidAction:(JPDevMenuAction)action withValue:(id)value; 21 | 22 | @end 23 | 24 | @interface JPDevMenu : NSObject 25 | 26 | @property (nonatomic,weak) id delegate; 27 | - (void)toggle; 28 | @end 29 | -------------------------------------------------------------------------------- /JPPlaygroundTool/JPPlaygroundView/JPDevMenu.m: -------------------------------------------------------------------------------- 1 | // 2 | // JPPlaygroundMenu.m 3 | // JSPatchPlaygroundDemo 4 | // 5 | // Created by Awhisper on 16/8/7. 6 | // Copyright © 2016年 baidu. All rights reserved. 7 | // 8 | 9 | #import "JPDevMenu.h" 10 | #import 11 | 12 | @interface JPDevMenuItem : NSObject 13 | 14 | /** 15 | * This creates an item with a simple push-button interface, used to trigger an 16 | * action. 17 | */ 18 | + (instancetype)buttonItemWithTitle:(NSString *)title 19 | handler:(void(^)(void))handler; 20 | 21 | /** 22 | * This creates an item with a toggle behavior. The key is used to store the 23 | * state of the toggle. For toggle items, the handler will be called immediately 24 | * after the item is added if the item was already selected when the module was 25 | * last loaded. 26 | */ 27 | + (instancetype)toggleItemWithKey:(NSString *)key 28 | title:(NSString *)title 29 | selectedTitle:(NSString *)selectedTitle 30 | handler:(void(^)(BOOL selected))handler; 31 | @end 32 | 33 | typedef NS_ENUM(NSInteger, JPDevMenuType) { 34 | JPDevMenuTypeButton, 35 | JPDevMenuTypeToggle 36 | }; 37 | 38 | @interface JPDevMenuItem () 39 | 40 | @property (nonatomic, assign, readonly) JPDevMenuType type; 41 | @property (nonatomic, copy, readonly) NSString *key; 42 | @property (nonatomic, copy, readonly) NSString *title; 43 | @property (nonatomic, copy, readonly) NSString *selectedTitle; 44 | @property (nonatomic, copy) id value; 45 | 46 | @end 47 | 48 | @implementation JPDevMenuItem 49 | { 50 | id _handler; // block 51 | } 52 | 53 | #pragma clang diagnostic push 54 | #pragma clang diagnostic ignored "-Wdeprecated-declarations" 55 | 56 | - (instancetype)initWithType:(JPDevMenuType)type 57 | key:(NSString *)key 58 | title:(NSString *)title 59 | selectedTitle:(NSString *)selectedTitle 60 | handler:(id /* block */)handler 61 | { 62 | if ((self = [super init])) { 63 | _type = type; 64 | _key = [key copy]; 65 | _title = [title copy]; 66 | _selectedTitle = [selectedTitle copy]; 67 | _handler = [handler copy]; 68 | _value = nil; 69 | } 70 | return self; 71 | } 72 | 73 | + (instancetype)buttonItemWithTitle:(NSString *)title 74 | handler:(void (^)(void))handler 75 | { 76 | return [[self alloc] initWithType:JPDevMenuTypeButton 77 | key:nil 78 | title:title 79 | selectedTitle:nil 80 | handler:handler]; 81 | } 82 | 83 | + (instancetype)toggleItemWithKey:(NSString *)key 84 | title:(NSString *)title 85 | selectedTitle:(NSString *)selectedTitle 86 | handler:(void (^)(BOOL selected))handler 87 | { 88 | return [[self alloc] initWithType:JPDevMenuTypeToggle 89 | key:key 90 | title:title 91 | selectedTitle:selectedTitle 92 | handler:handler]; 93 | } 94 | 95 | - (void)callHandler 96 | { 97 | switch (_type) { 98 | case JPDevMenuTypeButton: { 99 | if (_handler) { 100 | ((void(^)())_handler)(); 101 | } 102 | break; 103 | } 104 | case JPDevMenuTypeToggle: { 105 | if (_handler) { 106 | ((void(^)(BOOL selected))_handler)([_value boolValue]); 107 | } 108 | break; 109 | } 110 | } 111 | } 112 | 113 | @end 114 | 115 | @interface JPDevMenu () 116 | 117 | @property (nonatomic,strong) UIActionSheet * actionSheet; 118 | @property (nonatomic,strong) NSMutableDictionary *settings; 119 | @property (nonatomic,strong) NSArray *presentedItems; 120 | 121 | @end 122 | 123 | @implementation JPDevMenu 124 | 125 | -(instancetype)init 126 | { 127 | self = [super init]; 128 | if (self) { 129 | _settings = [[NSMutableDictionary alloc]init]; 130 | } 131 | return self; 132 | } 133 | 134 | 135 | - (NSArray *)menuItems 136 | { 137 | NSMutableArray *items = [NSMutableArray new]; 138 | 139 | // Add built-in items 140 | 141 | 142 | [items addObject:[JPDevMenuItem buttonItemWithTitle:@"Reload JS (Command+R)" handler:^{ 143 | if (self.delegate && [self.delegate respondsToSelector:@selector(devMenuDidAction:withValue:)]) { 144 | [self.delegate devMenuDidAction:JPDevMenuActionReload withValue:nil]; 145 | } 146 | }]]; 147 | 148 | JPDevMenuItem *toggle = [JPDevMenuItem toggleItemWithKey:@"autoReloadJS" title:@"open Auto Reload JS" selectedTitle:@"Auto Reload JS Is Open" handler:^(BOOL selected) { 149 | if (self.delegate && [self.delegate respondsToSelector:@selector(devMenuDidAction:withValue:)]) { 150 | [self.delegate devMenuDidAction:JPDevMenuActionAutoReload withValue:@(selected)]; 151 | } 152 | 153 | }]; 154 | toggle.value = _settings[@"autoReloadJS"]; 155 | [items addObject:toggle]; 156 | 157 | 158 | [items addObject:[JPDevMenuItem buttonItemWithTitle:@"Help" handler:^{ 159 | if (self.delegate && [self.delegate respondsToSelector:@selector(devMenuDidAction:withValue:)]) { 160 | [self.delegate devMenuDidAction:JPDevMenuActionOpenJS withValue:nil]; 161 | } 162 | }]]; 163 | 164 | 165 | return items; 166 | } 167 | 168 | 169 | - (void)toggle 170 | { 171 | if (_actionSheet) { 172 | [_actionSheet dismissWithClickedButtonIndex:_actionSheet.cancelButtonIndex animated:YES]; 173 | _actionSheet = nil; 174 | } else { 175 | [self show]; 176 | } 177 | 178 | } 179 | 180 | -(void)show 181 | { 182 | UIActionSheet *actionSheet = [UIActionSheet new]; 183 | actionSheet.title = @"JPatch Playgournd : Command + X"; 184 | actionSheet.delegate = self; 185 | 186 | NSArray *items = [self menuItems]; 187 | for (JPDevMenuItem *item in items) { 188 | switch (item.type) { 189 | case JPDevMenuTypeButton: { 190 | [actionSheet addButtonWithTitle:item.title]; 191 | break; 192 | } 193 | case JPDevMenuTypeToggle: { 194 | BOOL selected = [item.value boolValue]; 195 | [actionSheet addButtonWithTitle:selected? item.selectedTitle : item.title]; 196 | break; 197 | } 198 | } 199 | } 200 | 201 | [actionSheet addButtonWithTitle:@"Cancel"]; 202 | actionSheet.cancelButtonIndex = actionSheet.numberOfButtons - 1; 203 | 204 | [actionSheet showInView:[UIApplication sharedApplication].keyWindow.rootViewController.view]; 205 | _actionSheet = actionSheet; 206 | _presentedItems = items; 207 | } 208 | 209 | 210 | - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex 211 | { 212 | _actionSheet = nil; 213 | if (buttonIndex == actionSheet.cancelButtonIndex) { 214 | return; 215 | } 216 | 217 | JPDevMenuItem *item = _presentedItems[buttonIndex]; 218 | switch (item.type) { 219 | case JPDevMenuTypeButton: { 220 | [item callHandler]; 221 | break; 222 | } 223 | case JPDevMenuTypeToggle: { 224 | BOOL value = [_settings[item.key] boolValue]; 225 | [self updateSetting:item.key value:@(!value)]; // will call handler 226 | break; 227 | } 228 | } 229 | return; 230 | } 231 | 232 | - (void)updateSetting:(NSString *)name value:(id)value 233 | { 234 | // Fire handler for item whose values has changed 235 | for (JPDevMenuItem *item in _presentedItems) { 236 | if ([item.key isEqualToString:name]) { 237 | if (value != item.value && ![value isEqual:item.value]) { 238 | item.value = value; 239 | [item callHandler]; 240 | } 241 | break; 242 | } 243 | } 244 | 245 | // Save the setting 246 | id currentValue = _settings[name]; 247 | if (currentValue == value || [currentValue isEqual:value]) { 248 | return; 249 | } 250 | if (value) { 251 | _settings[name] = value; 252 | } else { 253 | [_settings removeObjectForKey:name]; 254 | } 255 | } 256 | 257 | 258 | 259 | -(void)actionSheetCancel:(UIActionSheet *)actionSheet 260 | { 261 | if (self.delegate && [self.delegate respondsToSelector:@selector(devMenuDidAction:withValue:)]) { 262 | [self.delegate devMenuDidAction:JPDevMenuActionCancel withValue:nil]; 263 | } 264 | } 265 | 266 | -(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex 267 | { 268 | if (self.delegate && [self.delegate respondsToSelector:@selector(devMenuDidAction:withValue:)]) { 269 | [self.delegate devMenuDidAction:JPDevMenuActionCancel withValue:nil]; 270 | } 271 | } 272 | 273 | #pragma clang diagnostic pop 274 | 275 | @end 276 | -------------------------------------------------------------------------------- /JPPlaygroundTool/JPPlaygroundView/JPDevTipView.h: -------------------------------------------------------------------------------- 1 | // 2 | // JPTipView.h 3 | // JSPatchPlaygroundDemo 4 | // 5 | // Created by Awhisper on 16/8/7. 6 | // Copyright © 2016年 baidu. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface JPDevTipView : UIView 12 | 13 | +(void)showJPDevTip:(NSString *)msg; 14 | 15 | -(instancetype)initWithMsg:(NSString*)msg; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /JPPlaygroundTool/JPPlaygroundView/JPDevTipView.m: -------------------------------------------------------------------------------- 1 | // 2 | // JPTipView.m 3 | // JSPatchPlaygroundDemo 4 | // 5 | // Created by Awhisper on 16/8/7. 6 | // Copyright © 2016年 baidu. All rights reserved. 7 | // 8 | 9 | #import "JPDevTipView.h" 10 | 11 | @implementation JPDevTipView 12 | 13 | -(instancetype)initWithMsg:(NSString*)msg{ 14 | BOOL statusBarShow = [UIApplication sharedApplication].isStatusBarHidden; 15 | 16 | 17 | self = [super initWithFrame:CGRectMake(0,0,[UIScreen mainScreen].bounds.size.width,statusBarShow?20:40)]; 18 | if (self) { 19 | self.backgroundColor = [UIColor redColor]; 20 | 21 | UILabel *tip = [[UILabel alloc]initWithFrame:CGRectMake(0, statusBarShow?0:20, self.bounds.size.width, 20)]; 22 | tip.textColor = [UIColor whiteColor]; 23 | tip.font = [UIFont systemFontOfSize:18]; 24 | tip.textAlignment = NSTextAlignmentCenter; 25 | tip.text = msg; 26 | [self addSubview:tip]; 27 | } 28 | return self; 29 | } 30 | 31 | 32 | +(void)showJPDevTip:(NSString *)msg 33 | { 34 | JPDevTipView *tip = [[JPDevTipView alloc]initWithMsg:msg]; 35 | UIView *window = [UIApplication sharedApplication].keyWindow; 36 | 37 | [window addSubview:tip]; 38 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ 39 | [UIView animateWithDuration:1 animations:^{ 40 | tip.alpha = 0; 41 | } completion:^(BOOL finished) { 42 | [tip removeFromSuperview]; 43 | }]; 44 | }); 45 | } 46 | /* 47 | // Only override drawRect: if you perform custom drawing. 48 | // An empty implementation adversely affects performance during animation. 49 | - (void)drawRect:(CGRect)rect { 50 | // Drawing code 51 | } 52 | */ 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunction/JPCFunction.h: -------------------------------------------------------------------------------- 1 | // 2 | // JPCFunction.h 3 | // JSPatchDemo 4 | // 5 | // Created by bang on 5/30/16. 6 | // Copyright © 2016 bang. All rights reserved. 7 | // 8 | 9 | #import "JPEngine.h" 10 | 11 | @interface JPCFunction : JPExtension 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunction/JPMemory.h: -------------------------------------------------------------------------------- 1 | // 2 | // JPMemory.h 3 | // JSPatchDemo 4 | // 5 | // Created by Albert438 on 15/7/6. 6 | // Copyright (c) 2015年 bang. All rights reserved. 7 | // 8 | 9 | #import "JPEngine.h" 10 | 11 | @interface JPMemory : JPExtension 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunction/JPMemory.m: -------------------------------------------------------------------------------- 1 | // 2 | // JPMemory.m 3 | // JSPatchDemo 4 | // 5 | // Created by Albert438 on 15/7/6. 6 | // Copyright (c) 2015年 bang. All rights reserved. 7 | // 8 | 9 | #import "JPMemory.h" 10 | 11 | @implementation JPMemory 12 | 13 | + (void)main:(JSContext *)context 14 | { 15 | context[@"memset"] = ^void(JSValue *jsVal, int ch,size_t n) { 16 | memset([self formatPointerJSToOC:jsVal], ch, n); 17 | }; 18 | 19 | context[@"memmove"] = ^id(JSValue *des, JSValue *src, size_t n) { 20 | void *ret = memmove([self formatPointerJSToOC:des], [self formatPointerJSToOC:src], n); 21 | return [self formatPointerOCToJS:ret]; 22 | }; 23 | 24 | context[@"memcpy"] = ^id(JSValue *des, JSValue *src, size_t n) { 25 | void *ret = memcpy([self formatPointerJSToOC:des], [self formatPointerJSToOC:src], n); 26 | return [self formatPointerOCToJS:ret]; 27 | }; 28 | 29 | context[@"malloc"] = ^id(size_t size) { 30 | void *m = malloc(size); 31 | return [self formatPointerOCToJS:m]; 32 | }; 33 | 34 | context[@"free"] = ^void(JSValue *jsVal) { 35 | void *m = [self formatPointerJSToOC:jsVal]; 36 | free(m); 37 | }; 38 | 39 | context[@"pval"] = ^id(JSValue *jsVal) { 40 | void *m = [self formatPointerJSToOC:jsVal]; 41 | id obj = *((__unsafe_unretained id *)m); 42 | return [self formatOCToJS:obj]; 43 | }; 44 | 45 | context[@"getPointer"] = ^id(JSValue *jsVal) { 46 | void **p = malloc(sizeof(void *)); 47 | void *pointer = [self formatPointerJSToOC:jsVal]; 48 | if (pointer != NULL) { 49 | *p = pointer; 50 | } else { 51 | id obj = [self formatJSToOC:jsVal]; 52 | *p = (__bridge void*)obj; 53 | } 54 | return [self formatPointerOCToJS:p]; 55 | }; 56 | 57 | context[@"pvalBool"] = ^id(JSValue *jsVal) { 58 | void *m = [self formatPointerJSToOC:jsVal]; 59 | BOOL b = *((BOOL *)m); 60 | return [self formatOCToJS:[NSNumber numberWithBool:b]]; 61 | }; 62 | 63 | __weak JSContext *weakCtx = context; 64 | context[@"sizeof"] = ^size_t(JSValue *jsVal) { 65 | NSString *typeName = [jsVal toString]; 66 | 67 | if ([typeName isEqualToString:@"id"]) return sizeof(id); 68 | if ([typeName isEqualToString:@"CGRect"]) return sizeof(CGRect); 69 | if ([typeName isEqualToString:@"CGPoint"]) return sizeof(CGPoint); 70 | if ([typeName isEqualToString:@"CGSize"]) return sizeof(CGSize); 71 | if ([typeName isEqualToString:@"NSRange"]) return sizeof(NSRange); 72 | 73 | @synchronized (weakCtx) { 74 | NSDictionary *structDefine = [JPExtension registeredStruct][typeName]; 75 | if (structDefine) { 76 | return [self sizeOfStructTypes:structDefine[@"types"]]; 77 | } 78 | } 79 | return 0; 80 | }; 81 | 82 | context[@"__bridge_id"] = ^id(JSValue *jsVal) { 83 | void *p = [self formatPointerJSToOC:jsVal]; 84 | id obj = (__bridge id)p; 85 | return [self formatOCToJS:obj]; 86 | }; 87 | 88 | context[@"CFRelease"] = ^void(JSValue *jsVal) { 89 | CFRelease([self formatPointerJSToOC:jsVal]); 90 | }; 91 | 92 | context[@"CFRetain"] = ^void(JSValue *jsVal) { 93 | CFRetain([self formatPointerJSToOC:jsVal]); 94 | }; 95 | 96 | context[@"assignPointer"] = ^void(JSValue *jsVal, JSValue *value) { 97 | void *m = [self formatPointerJSToOC:jsVal]; 98 | id obj = [self formatJSToOC:value]; 99 | *((__unsafe_unretained id *)m) = obj; 100 | }; 101 | 102 | context[@"autoreleasepool"] = ^void(JSValue *cb) { 103 | @autoreleasepool { 104 | [cb callWithArguments:nil]; 105 | } 106 | }; 107 | } 108 | 109 | 110 | 111 | @end 112 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunction/JPStructPointer.h: -------------------------------------------------------------------------------- 1 | // 2 | // JPStructPointer.h 3 | // JSPatchDemo 4 | // 5 | // Created by bang on 15/8/13. 6 | // Copyright (c) 2015年 bang. All rights reserved. 7 | // 8 | 9 | #import "JPEngine.h" 10 | 11 | @interface JPStructPointer : JPExtension 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunction/JPStructPointer.m: -------------------------------------------------------------------------------- 1 | // 2 | // JPStructPointer.m 3 | // JSPatchDemo 4 | // 5 | // Created by bang on 15/8/13. 6 | // Copyright (c) 2015年 bang. All rights reserved. 7 | // 8 | 9 | #import "JPStructPointer.h" 10 | 11 | @implementation JPStructPointer 12 | + (void)main:(JSContext *)context 13 | { 14 | __weak JSContext *weakCtx = context; 15 | context[@"newStruct"] = ^id(NSString *structName, JSValue *structDict) { 16 | #define JP_NEW_STRUCT(_type, _method) \ 17 | if ([structName isEqualToString:@#_type]) { \ 18 | void *ret = malloc(sizeof(_type)); \ 19 | _type rect = [structDict _method]; \ 20 | ret = memcpy(ret, &rect, sizeof(_type)); \ 21 | return [self formatPointerOCToJS:ret]; \ 22 | } 23 | JP_NEW_STRUCT(CGRect, toRect) 24 | JP_NEW_STRUCT(CGPoint, toPoint) 25 | JP_NEW_STRUCT(CGSize, toSize) 26 | JP_NEW_STRUCT(NSRange, toRange) 27 | 28 | @synchronized (weakCtx) { 29 | NSDictionary *structDefine = [JPExtension registeredStruct][structName]; 30 | if (structDefine) { 31 | int size = [self sizeOfStructTypes:structDefine[@"types"]]; 32 | void *ret = malloc(size); 33 | memset(ret, 0, size); 34 | [self getStructDataWidthDict:ret dict:[structDict toObject] structDefine:structDefine]; 35 | return [self formatPointerOCToJS:ret]; 36 | } 37 | } 38 | return nil; 39 | }; 40 | 41 | context[@"pvalStruct"] = ^id(NSString *structName, JSValue *structPointer) { 42 | if ([structName isEqualToString:@"CGRect"]) { 43 | CGRect *rect = [self formatPointerJSToOC:structPointer]; 44 | return @{@"x": @(rect->origin.x), @"y": @(rect->origin.y), @"width": @(rect->size.width), @"height": @(rect->size.height)}; 45 | } 46 | if ([structName isEqualToString:@"CGPoint"]) { 47 | CGPoint *point = [self formatPointerJSToOC:structPointer]; 48 | return @{@"x": @(point->x), @"y": @(point->y)}; 49 | } 50 | if ([structName isEqualToString:@"CGSize"]) { 51 | CGSize *size = [self formatPointerJSToOC:structPointer]; 52 | return @{@"width": @(size->width), @"height": @(size->height)}; 53 | } 54 | if ([structName isEqualToString:@"NSRange"]) { 55 | NSRange *range = [self formatPointerJSToOC:structPointer]; 56 | return @{@"location": @(range->location), @"length": @(range->length)}; 57 | } 58 | @synchronized (weakCtx) { 59 | 60 | JSContext *context = [JPEngine context]; 61 | @synchronized (context) { 62 | NSDictionary *structDefine = [JPExtension registeredStruct][structName]; 63 | if (structDefine) { 64 | return [self getDictOfStruct:[self formatPointerJSToOC:structPointer] structDefine:structDefine]; 65 | } 66 | } 67 | } 68 | return nil; 69 | }; 70 | } 71 | @end 72 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunction/libffi/headers/ffi.h: -------------------------------------------------------------------------------- 1 | #ifdef __arm64__ 2 | 3 | #include "ffi_arm64.h" 4 | 5 | 6 | #endif 7 | #ifdef __i386__ 8 | 9 | #include "ffi_i386.h" 10 | 11 | 12 | #endif 13 | #ifdef __arm__ 14 | 15 | #include "ffi_armv7.h" 16 | 17 | 18 | #endif 19 | #ifdef __x86_64__ 20 | 21 | #include "ffi_x86_64.h" 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunction/libffi/headers/ffi_common.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- 2 | ffi_common.h - Copyright (C) 2011, 2012, 2013 Anthony Green 3 | Copyright (C) 2007 Free Software Foundation, Inc 4 | Copyright (c) 1996 Red Hat, Inc. 5 | 6 | Common internal definitions and macros. Only necessary for building 7 | libffi. 8 | ----------------------------------------------------------------------- */ 9 | 10 | #ifndef FFI_COMMON_H 11 | #define FFI_COMMON_H 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | #include "fficonfig.h" 18 | 19 | /* Do not move this. Some versions of AIX are very picky about where 20 | this is positioned. */ 21 | #ifdef __GNUC__ 22 | # if HAVE_ALLOCA_H 23 | # include 24 | # else 25 | /* mingw64 defines this already in malloc.h. */ 26 | # ifndef alloca 27 | # define alloca __builtin_alloca 28 | # endif 29 | # endif 30 | # define MAYBE_UNUSED __attribute__((__unused__)) 31 | #else 32 | # define MAYBE_UNUSED 33 | # if HAVE_ALLOCA_H 34 | # include 35 | # else 36 | # ifdef _AIX 37 | # pragma alloca 38 | # else 39 | # ifndef alloca /* predefined by HP cc +Olibcalls */ 40 | # ifdef _MSC_VER 41 | # define alloca _alloca 42 | # else 43 | char *alloca (); 44 | # endif 45 | # endif 46 | # endif 47 | # endif 48 | #endif 49 | 50 | /* Check for the existence of memcpy. */ 51 | #if STDC_HEADERS 52 | # include 53 | #else 54 | # ifndef HAVE_MEMCPY 55 | # define memcpy(d, s, n) bcopy ((s), (d), (n)) 56 | # endif 57 | #endif 58 | 59 | #if defined(FFI_DEBUG) 60 | #include 61 | #endif 62 | 63 | #ifdef FFI_DEBUG 64 | void ffi_assert(char *expr, char *file, int line); 65 | void ffi_stop_here(void); 66 | void ffi_type_test(ffi_type *a, char *file, int line); 67 | 68 | #define FFI_ASSERT(x) ((x) ? (void)0 : ffi_assert(#x, __FILE__,__LINE__)) 69 | #define FFI_ASSERT_AT(x, f, l) ((x) ? 0 : ffi_assert(#x, (f), (l))) 70 | #define FFI_ASSERT_VALID_TYPE(x) ffi_type_test (x, __FILE__, __LINE__) 71 | #else 72 | #define FFI_ASSERT(x) 73 | #define FFI_ASSERT_AT(x, f, l) 74 | #define FFI_ASSERT_VALID_TYPE(x) 75 | #endif 76 | 77 | #define ALIGN(v, a) (((((size_t) (v))-1) | ((a)-1))+1) 78 | #define ALIGN_DOWN(v, a) (((size_t) (v)) & -a) 79 | 80 | /* Perform machine dependent cif processing */ 81 | ffi_status ffi_prep_cif_machdep(ffi_cif *cif); 82 | ffi_status ffi_prep_cif_machdep_var(ffi_cif *cif, 83 | unsigned int nfixedargs, unsigned int ntotalargs); 84 | 85 | /* Extended cif, used in callback from assembly routine */ 86 | typedef struct 87 | { 88 | ffi_cif *cif; 89 | void *rvalue; 90 | void **avalue; 91 | } extended_cif; 92 | 93 | /* Terse sized type definitions. */ 94 | #if defined(_MSC_VER) || defined(__sgi) || defined(__SUNPRO_C) 95 | typedef unsigned char UINT8; 96 | typedef signed char SINT8; 97 | typedef unsigned short UINT16; 98 | typedef signed short SINT16; 99 | typedef unsigned int UINT32; 100 | typedef signed int SINT32; 101 | # ifdef _MSC_VER 102 | typedef unsigned __int64 UINT64; 103 | typedef signed __int64 SINT64; 104 | # else 105 | # include 106 | typedef uint64_t UINT64; 107 | typedef int64_t SINT64; 108 | # endif 109 | #else 110 | typedef unsigned int UINT8 __attribute__((__mode__(__QI__))); 111 | typedef signed int SINT8 __attribute__((__mode__(__QI__))); 112 | typedef unsigned int UINT16 __attribute__((__mode__(__HI__))); 113 | typedef signed int SINT16 __attribute__((__mode__(__HI__))); 114 | typedef unsigned int UINT32 __attribute__((__mode__(__SI__))); 115 | typedef signed int SINT32 __attribute__((__mode__(__SI__))); 116 | typedef unsigned int UINT64 __attribute__((__mode__(__DI__))); 117 | typedef signed int SINT64 __attribute__((__mode__(__DI__))); 118 | #endif 119 | 120 | typedef float FLOAT32; 121 | 122 | #ifndef __GNUC__ 123 | #define __builtin_expect(x, expected_value) (x) 124 | #endif 125 | #define LIKELY(x) __builtin_expect(!!(x),1) 126 | #define UNLIKELY(x) __builtin_expect((x)!=0,0) 127 | 128 | #ifdef __cplusplus 129 | } 130 | #endif 131 | 132 | #endif 133 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunction/libffi/headers/fficonfig.h: -------------------------------------------------------------------------------- 1 | #ifdef __arm64__ 2 | 3 | #include "fficonfig_arm64.h" 4 | 5 | 6 | #endif 7 | #ifdef __i386__ 8 | 9 | #include "fficonfig_i386.h" 10 | 11 | 12 | #endif 13 | #ifdef __arm__ 14 | 15 | #include "fficonfig_armv7.h" 16 | 17 | 18 | #endif 19 | #ifdef __x86_64__ 20 | 21 | #include "fficonfig_x86_64.h" 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunction/libffi/headers/fficonfig_arm64.h: -------------------------------------------------------------------------------- 1 | #ifdef __arm64__ 2 | 3 | /* fficonfig.h. Generated from fficonfig.h.in by configure. */ 4 | /* fficonfig.h.in. Generated from configure.ac by autoheader. */ 5 | 6 | /* Define if building universal (internal helper macro) */ 7 | /* #undef AC_APPLE_UNIVERSAL_BUILD */ 8 | 9 | /* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP 10 | systems. This function is required for `alloca.c' support on those systems. 11 | */ 12 | /* #undef CRAY_STACKSEG_END */ 13 | 14 | /* Define to 1 if using `alloca.c'. */ 15 | /* #undef C_ALLOCA */ 16 | 17 | /* Define to the flags needed for the .section .eh_frame directive. */ 18 | #define EH_FRAME_FLAGS "aw" 19 | 20 | /* Define this if you want extra debugging. */ 21 | /* #undef FFI_DEBUG */ 22 | 23 | /* Cannot use PROT_EXEC on this target, so, we revert to alternative means */ 24 | /* #undef FFI_EXEC_TRAMPOLINE_TABLE */ 25 | 26 | /* Define this if you want to enable pax emulated trampolines */ 27 | /* #undef FFI_MMAP_EXEC_EMUTRAMP_PAX */ 28 | 29 | /* Cannot use malloc on this target, so, we revert to alternative means */ 30 | #define FFI_MMAP_EXEC_WRIT 1 31 | 32 | /* Define this if you do not want support for the raw API. */ 33 | /* #undef FFI_NO_RAW_API */ 34 | 35 | /* Define this if you do not want support for aggregate types. */ 36 | /* #undef FFI_NO_STRUCTS */ 37 | 38 | /* Define to 1 if you have `alloca', as a function or macro. */ 39 | #define HAVE_ALLOCA 1 40 | 41 | /* Define to 1 if you have and it should be used (not on Ultrix). 42 | */ 43 | #define HAVE_ALLOCA_H 1 44 | 45 | /* Define if your assembler supports .ascii. */ 46 | /* #undef HAVE_AS_ASCII_PSEUDO_OP */ 47 | 48 | /* Define if your assembler supports .cfi_* directives. */ 49 | #define HAVE_AS_CFI_PSEUDO_OP 1 50 | 51 | /* Define if your assembler supports .register. */ 52 | /* #undef HAVE_AS_REGISTER_PSEUDO_OP */ 53 | 54 | /* Define if your assembler and linker support unaligned PC relative relocs. 55 | */ 56 | /* #undef HAVE_AS_SPARC_UA_PCREL */ 57 | 58 | /* Define if your assembler supports .string. */ 59 | /* #undef HAVE_AS_STRING_PSEUDO_OP */ 60 | 61 | /* Define if your assembler supports unwind section type. */ 62 | /* #undef HAVE_AS_X86_64_UNWIND_SECTION_TYPE */ 63 | 64 | /* Define if your assembler supports PC relative relocs. */ 65 | /* #undef HAVE_AS_X86_PCREL */ 66 | 67 | /* Define to 1 if you have the header file. */ 68 | #define HAVE_DLFCN_H 1 69 | 70 | /* Define if __attribute__((visibility("hidden"))) is supported. */ 71 | /* #undef HAVE_HIDDEN_VISIBILITY_ATTRIBUTE */ 72 | 73 | /* Define to 1 if you have the header file. */ 74 | #define HAVE_INTTYPES_H 1 75 | 76 | /* Define if you have the long double type and it is bigger than a double */ 77 | /* #undef HAVE_LONG_DOUBLE */ 78 | 79 | /* Define if you support more than one size of the long double type */ 80 | /* #undef HAVE_LONG_DOUBLE_VARIANT */ 81 | 82 | /* Define to 1 if you have the `memcpy' function. */ 83 | #define HAVE_MEMCPY 1 84 | 85 | /* Define to 1 if you have the header file. */ 86 | #define HAVE_MEMORY_H 1 87 | 88 | /* Define to 1 if you have the `mkostemp' function. */ 89 | /* #undef HAVE_MKOSTEMP */ 90 | 91 | /* Define to 1 if you have the `mmap' function. */ 92 | #define HAVE_MMAP 1 93 | 94 | /* Define if mmap with MAP_ANON(YMOUS) works. */ 95 | #define HAVE_MMAP_ANON 1 96 | 97 | /* Define if mmap of /dev/zero works. */ 98 | /* #undef HAVE_MMAP_DEV_ZERO */ 99 | 100 | /* Define if read-only mmap of a plain file works. */ 101 | #define HAVE_MMAP_FILE 1 102 | 103 | /* Define if .eh_frame sections should be read-only. */ 104 | /* #undef HAVE_RO_EH_FRAME */ 105 | 106 | /* Define to 1 if you have the header file. */ 107 | #define HAVE_STDINT_H 1 108 | 109 | /* Define to 1 if you have the header file. */ 110 | #define HAVE_STDLIB_H 1 111 | 112 | /* Define to 1 if you have the header file. */ 113 | #define HAVE_STRINGS_H 1 114 | 115 | /* Define to 1 if you have the header file. */ 116 | #define HAVE_STRING_H 1 117 | 118 | /* Define to 1 if you have the header file. */ 119 | #define HAVE_SYS_MMAN_H 1 120 | 121 | /* Define to 1 if you have the header file. */ 122 | #define HAVE_SYS_STAT_H 1 123 | 124 | /* Define to 1 if you have the header file. */ 125 | #define HAVE_SYS_TYPES_H 1 126 | 127 | /* Define to 1 if you have the header file. */ 128 | #define HAVE_UNISTD_H 1 129 | 130 | /* Define to the sub-directory in which libtool stores uninstalled libraries. 131 | */ 132 | #define LT_OBJDIR ".libs/" 133 | 134 | /* Name of package */ 135 | #define PACKAGE "libffi" 136 | 137 | /* Define to the address where bug reports for this package should be sent. */ 138 | #define PACKAGE_BUGREPORT "http://github.com/atgreen/libffi/issues" 139 | 140 | /* Define to the full name of this package. */ 141 | #define PACKAGE_NAME "libffi" 142 | 143 | /* Define to the full name and version of this package. */ 144 | #define PACKAGE_STRING "libffi 3.2.1" 145 | 146 | /* Define to the one symbol short name of this package. */ 147 | #define PACKAGE_TARNAME "libffi" 148 | 149 | /* Define to the home page for this package. */ 150 | #define PACKAGE_URL "" 151 | 152 | /* Define to the version of this package. */ 153 | #define PACKAGE_VERSION "3.2.1" 154 | 155 | /* The size of `double', as computed by sizeof. */ 156 | #define SIZEOF_DOUBLE 8 157 | 158 | /* The size of `long double', as computed by sizeof. */ 159 | #define SIZEOF_LONG_DOUBLE 8 160 | 161 | /* The size of `size_t', as computed by sizeof. */ 162 | #define SIZEOF_SIZE_T 8 163 | 164 | /* If using the C implementation of alloca, define if you know the 165 | direction of stack growth for your system; otherwise it will be 166 | automatically deduced at runtime. 167 | STACK_DIRECTION > 0 => grows toward higher addresses 168 | STACK_DIRECTION < 0 => grows toward lower addresses 169 | STACK_DIRECTION = 0 => direction of growth unknown */ 170 | /* #undef STACK_DIRECTION */ 171 | 172 | /* Define to 1 if you have the ANSI C header files. */ 173 | #define STDC_HEADERS 1 174 | 175 | /* Define if symbols are underscored. */ 176 | #define SYMBOL_UNDERSCORE 1 177 | 178 | /* Define this if you are using Purify and want to suppress spurious messages. 179 | */ 180 | /* #undef USING_PURIFY */ 181 | 182 | /* Version number of package */ 183 | #define VERSION "3.2.1" 184 | 185 | /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most 186 | significant byte first (like Motorola and SPARC, unlike Intel). */ 187 | #if defined AC_APPLE_UNIVERSAL_BUILD 188 | # if defined __BIG_ENDIAN__ 189 | # define WORDS_BIGENDIAN 1 190 | # endif 191 | #else 192 | # ifndef WORDS_BIGENDIAN 193 | /* # undef WORDS_BIGENDIAN */ 194 | # endif 195 | #endif 196 | 197 | /* Define to `unsigned int' if does not define. */ 198 | /* #undef size_t */ 199 | 200 | 201 | #ifdef HAVE_HIDDEN_VISIBILITY_ATTRIBUTE 202 | #ifdef LIBFFI_ASM 203 | #define FFI_HIDDEN(name) .hidden name 204 | #else 205 | #define FFI_HIDDEN __attribute__ ((visibility ("hidden"))) 206 | #endif 207 | #else 208 | #ifdef LIBFFI_ASM 209 | #define FFI_HIDDEN(name) 210 | #else 211 | #define FFI_HIDDEN 212 | #endif 213 | #endif 214 | 215 | 216 | 217 | #endif -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunction/libffi/headers/fficonfig_armv7.h: -------------------------------------------------------------------------------- 1 | #ifdef __arm__ 2 | 3 | /* fficonfig.h. Generated from fficonfig.h.in by configure. */ 4 | /* fficonfig.h.in. Generated from configure.ac by autoheader. */ 5 | 6 | /* Define if building universal (internal helper macro) */ 7 | /* #undef AC_APPLE_UNIVERSAL_BUILD */ 8 | 9 | /* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP 10 | systems. This function is required for `alloca.c' support on those systems. 11 | */ 12 | /* #undef CRAY_STACKSEG_END */ 13 | 14 | /* Define to 1 if using `alloca.c'. */ 15 | /* #undef C_ALLOCA */ 16 | 17 | /* Define to the flags needed for the .section .eh_frame directive. */ 18 | #define EH_FRAME_FLAGS "aw" 19 | 20 | /* Define this if you want extra debugging. */ 21 | /* #undef FFI_DEBUG */ 22 | 23 | /* Cannot use PROT_EXEC on this target, so, we revert to alternative means */ 24 | #define FFI_EXEC_TRAMPOLINE_TABLE 1 25 | 26 | /* Define this if you want to enable pax emulated trampolines */ 27 | /* #undef FFI_MMAP_EXEC_EMUTRAMP_PAX */ 28 | 29 | /* Cannot use malloc on this target, so, we revert to alternative means */ 30 | /* #undef FFI_MMAP_EXEC_WRIT */ 31 | 32 | /* Define this if you do not want support for the raw API. */ 33 | /* #undef FFI_NO_RAW_API */ 34 | 35 | /* Define this if you do not want support for aggregate types. */ 36 | /* #undef FFI_NO_STRUCTS */ 37 | 38 | /* Define to 1 if you have `alloca', as a function or macro. */ 39 | #define HAVE_ALLOCA 1 40 | 41 | /* Define to 1 if you have and it should be used (not on Ultrix). 42 | */ 43 | #define HAVE_ALLOCA_H 1 44 | 45 | /* Define if your assembler supports .ascii. */ 46 | /* #undef HAVE_AS_ASCII_PSEUDO_OP */ 47 | 48 | /* Define if your assembler supports .cfi_* directives. */ 49 | #define HAVE_AS_CFI_PSEUDO_OP 1 50 | 51 | /* Define if your assembler supports .register. */ 52 | /* #undef HAVE_AS_REGISTER_PSEUDO_OP */ 53 | 54 | /* Define if your assembler and linker support unaligned PC relative relocs. 55 | */ 56 | /* #undef HAVE_AS_SPARC_UA_PCREL */ 57 | 58 | /* Define if your assembler supports .string. */ 59 | /* #undef HAVE_AS_STRING_PSEUDO_OP */ 60 | 61 | /* Define if your assembler supports unwind section type. */ 62 | /* #undef HAVE_AS_X86_64_UNWIND_SECTION_TYPE */ 63 | 64 | /* Define if your assembler supports PC relative relocs. */ 65 | /* #undef HAVE_AS_X86_PCREL */ 66 | 67 | /* Define to 1 if you have the header file. */ 68 | #define HAVE_DLFCN_H 1 69 | 70 | /* Define if __attribute__((visibility("hidden"))) is supported. */ 71 | /* #undef HAVE_HIDDEN_VISIBILITY_ATTRIBUTE */ 72 | 73 | /* Define to 1 if you have the header file. */ 74 | #define HAVE_INTTYPES_H 1 75 | 76 | /* Define if you have the long double type and it is bigger than a double */ 77 | /* #undef HAVE_LONG_DOUBLE */ 78 | 79 | /* Define if you support more than one size of the long double type */ 80 | /* #undef HAVE_LONG_DOUBLE_VARIANT */ 81 | 82 | /* Define to 1 if you have the `memcpy' function. */ 83 | #define HAVE_MEMCPY 1 84 | 85 | /* Define to 1 if you have the header file. */ 86 | #define HAVE_MEMORY_H 1 87 | 88 | /* Define to 1 if you have the `mkostemp' function. */ 89 | /* #undef HAVE_MKOSTEMP */ 90 | 91 | /* Define to 1 if you have the `mmap' function. */ 92 | #define HAVE_MMAP 1 93 | 94 | /* Define if mmap with MAP_ANON(YMOUS) works. */ 95 | #define HAVE_MMAP_ANON 1 96 | 97 | /* Define if mmap of /dev/zero works. */ 98 | /* #undef HAVE_MMAP_DEV_ZERO */ 99 | 100 | /* Define if read-only mmap of a plain file works. */ 101 | #define HAVE_MMAP_FILE 1 102 | 103 | /* Define if .eh_frame sections should be read-only. */ 104 | /* #undef HAVE_RO_EH_FRAME */ 105 | 106 | /* Define to 1 if you have the header file. */ 107 | #define HAVE_STDINT_H 1 108 | 109 | /* Define to 1 if you have the header file. */ 110 | #define HAVE_STDLIB_H 1 111 | 112 | /* Define to 1 if you have the header file. */ 113 | #define HAVE_STRINGS_H 1 114 | 115 | /* Define to 1 if you have the header file. */ 116 | #define HAVE_STRING_H 1 117 | 118 | /* Define to 1 if you have the header file. */ 119 | #define HAVE_SYS_MMAN_H 1 120 | 121 | /* Define to 1 if you have the header file. */ 122 | #define HAVE_SYS_STAT_H 1 123 | 124 | /* Define to 1 if you have the header file. */ 125 | #define HAVE_SYS_TYPES_H 1 126 | 127 | /* Define to 1 if you have the header file. */ 128 | #define HAVE_UNISTD_H 1 129 | 130 | /* Define to the sub-directory in which libtool stores uninstalled libraries. 131 | */ 132 | #define LT_OBJDIR ".libs/" 133 | 134 | /* Name of package */ 135 | #define PACKAGE "libffi" 136 | 137 | /* Define to the address where bug reports for this package should be sent. */ 138 | #define PACKAGE_BUGREPORT "http://github.com/atgreen/libffi/issues" 139 | 140 | /* Define to the full name of this package. */ 141 | #define PACKAGE_NAME "libffi" 142 | 143 | /* Define to the full name and version of this package. */ 144 | #define PACKAGE_STRING "libffi 3.2.1" 145 | 146 | /* Define to the one symbol short name of this package. */ 147 | #define PACKAGE_TARNAME "libffi" 148 | 149 | /* Define to the home page for this package. */ 150 | #define PACKAGE_URL "" 151 | 152 | /* Define to the version of this package. */ 153 | #define PACKAGE_VERSION "3.2.1" 154 | 155 | /* The size of `double', as computed by sizeof. */ 156 | #define SIZEOF_DOUBLE 8 157 | 158 | /* The size of `long double', as computed by sizeof. */ 159 | #define SIZEOF_LONG_DOUBLE 8 160 | 161 | /* The size of `size_t', as computed by sizeof. */ 162 | #define SIZEOF_SIZE_T 4 163 | 164 | /* If using the C implementation of alloca, define if you know the 165 | direction of stack growth for your system; otherwise it will be 166 | automatically deduced at runtime. 167 | STACK_DIRECTION > 0 => grows toward higher addresses 168 | STACK_DIRECTION < 0 => grows toward lower addresses 169 | STACK_DIRECTION = 0 => direction of growth unknown */ 170 | /* #undef STACK_DIRECTION */ 171 | 172 | /* Define to 1 if you have the ANSI C header files. */ 173 | #define STDC_HEADERS 1 174 | 175 | /* Define if symbols are underscored. */ 176 | #define SYMBOL_UNDERSCORE 1 177 | 178 | /* Define this if you are using Purify and want to suppress spurious messages. 179 | */ 180 | /* #undef USING_PURIFY */ 181 | 182 | /* Version number of package */ 183 | #define VERSION "3.2.1" 184 | 185 | /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most 186 | significant byte first (like Motorola and SPARC, unlike Intel). */ 187 | #if defined AC_APPLE_UNIVERSAL_BUILD 188 | # if defined __BIG_ENDIAN__ 189 | # define WORDS_BIGENDIAN 1 190 | # endif 191 | #else 192 | # ifndef WORDS_BIGENDIAN 193 | /* # undef WORDS_BIGENDIAN */ 194 | # endif 195 | #endif 196 | 197 | /* Define to `unsigned int' if does not define. */ 198 | /* #undef size_t */ 199 | 200 | 201 | #ifdef HAVE_HIDDEN_VISIBILITY_ATTRIBUTE 202 | #ifdef LIBFFI_ASM 203 | #define FFI_HIDDEN(name) .hidden name 204 | #else 205 | #define FFI_HIDDEN __attribute__ ((visibility ("hidden"))) 206 | #endif 207 | #else 208 | #ifdef LIBFFI_ASM 209 | #define FFI_HIDDEN(name) 210 | #else 211 | #define FFI_HIDDEN 212 | #endif 213 | #endif 214 | 215 | 216 | 217 | #endif -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunction/libffi/headers/fficonfig_i386.h: -------------------------------------------------------------------------------- 1 | #ifdef __i386__ 2 | 3 | /* fficonfig.h. Generated from fficonfig.h.in by configure. */ 4 | /* fficonfig.h.in. Generated from configure.ac by autoheader. */ 5 | 6 | /* Define if building universal (internal helper macro) */ 7 | /* #undef AC_APPLE_UNIVERSAL_BUILD */ 8 | 9 | /* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP 10 | systems. This function is required for `alloca.c' support on those systems. 11 | */ 12 | /* #undef CRAY_STACKSEG_END */ 13 | 14 | /* Define to 1 if using `alloca.c'. */ 15 | /* #undef C_ALLOCA */ 16 | 17 | /* Define to the flags needed for the .section .eh_frame directive. */ 18 | #define EH_FRAME_FLAGS "aw" 19 | 20 | /* Define this if you want extra debugging. */ 21 | /* #undef FFI_DEBUG */ 22 | 23 | /* Cannot use PROT_EXEC on this target, so, we revert to alternative means */ 24 | /* #undef FFI_EXEC_TRAMPOLINE_TABLE */ 25 | 26 | /* Define this if you want to enable pax emulated trampolines */ 27 | /* #undef FFI_MMAP_EXEC_EMUTRAMP_PAX */ 28 | 29 | /* Cannot use malloc on this target, so, we revert to alternative means */ 30 | #define FFI_MMAP_EXEC_WRIT 1 31 | 32 | /* Define this if you do not want support for the raw API. */ 33 | /* #undef FFI_NO_RAW_API */ 34 | 35 | /* Define this if you do not want support for aggregate types. */ 36 | /* #undef FFI_NO_STRUCTS */ 37 | 38 | /* Define to 1 if you have `alloca', as a function or macro. */ 39 | #define HAVE_ALLOCA 1 40 | 41 | /* Define to 1 if you have and it should be used (not on Ultrix). 42 | */ 43 | #define HAVE_ALLOCA_H 1 44 | 45 | /* Define if your assembler supports .ascii. */ 46 | /* #undef HAVE_AS_ASCII_PSEUDO_OP */ 47 | 48 | /* Define if your assembler supports .cfi_* directives. */ 49 | #define HAVE_AS_CFI_PSEUDO_OP 1 50 | 51 | /* Define if your assembler supports .register. */ 52 | /* #undef HAVE_AS_REGISTER_PSEUDO_OP */ 53 | 54 | /* Define if your assembler and linker support unaligned PC relative relocs. 55 | */ 56 | /* #undef HAVE_AS_SPARC_UA_PCREL */ 57 | 58 | /* Define if your assembler supports .string. */ 59 | /* #undef HAVE_AS_STRING_PSEUDO_OP */ 60 | 61 | /* Define if your assembler supports unwind section type. */ 62 | /* #undef HAVE_AS_X86_64_UNWIND_SECTION_TYPE */ 63 | 64 | /* Define if your assembler supports PC relative relocs. */ 65 | /* #undef HAVE_AS_X86_PCREL */ 66 | 67 | /* Define to 1 if you have the header file. */ 68 | #define HAVE_DLFCN_H 1 69 | 70 | /* Define if __attribute__((visibility("hidden"))) is supported. */ 71 | /* #undef HAVE_HIDDEN_VISIBILITY_ATTRIBUTE */ 72 | 73 | /* Define to 1 if you have the header file. */ 74 | #define HAVE_INTTYPES_H 1 75 | 76 | /* Define if you have the long double type and it is bigger than a double */ 77 | #define HAVE_LONG_DOUBLE 1 78 | 79 | /* Define if you support more than one size of the long double type */ 80 | /* #undef HAVE_LONG_DOUBLE_VARIANT */ 81 | 82 | /* Define to 1 if you have the `memcpy' function. */ 83 | #define HAVE_MEMCPY 1 84 | 85 | /* Define to 1 if you have the header file. */ 86 | #define HAVE_MEMORY_H 1 87 | 88 | /* Define to 1 if you have the `mkostemp' function. */ 89 | /* #undef HAVE_MKOSTEMP */ 90 | 91 | /* Define to 1 if you have the `mmap' function. */ 92 | #define HAVE_MMAP 1 93 | 94 | /* Define if mmap with MAP_ANON(YMOUS) works. */ 95 | #define HAVE_MMAP_ANON 1 96 | 97 | /* Define if mmap of /dev/zero works. */ 98 | /* #undef HAVE_MMAP_DEV_ZERO */ 99 | 100 | /* Define if read-only mmap of a plain file works. */ 101 | #define HAVE_MMAP_FILE 1 102 | 103 | /* Define if .eh_frame sections should be read-only. */ 104 | /* #undef HAVE_RO_EH_FRAME */ 105 | 106 | /* Define to 1 if you have the header file. */ 107 | #define HAVE_STDINT_H 1 108 | 109 | /* Define to 1 if you have the header file. */ 110 | #define HAVE_STDLIB_H 1 111 | 112 | /* Define to 1 if you have the header file. */ 113 | #define HAVE_STRINGS_H 1 114 | 115 | /* Define to 1 if you have the header file. */ 116 | #define HAVE_STRING_H 1 117 | 118 | /* Define to 1 if you have the header file. */ 119 | #define HAVE_SYS_MMAN_H 1 120 | 121 | /* Define to 1 if you have the header file. */ 122 | #define HAVE_SYS_STAT_H 1 123 | 124 | /* Define to 1 if you have the header file. */ 125 | #define HAVE_SYS_TYPES_H 1 126 | 127 | /* Define to 1 if you have the header file. */ 128 | #define HAVE_UNISTD_H 1 129 | 130 | /* Define to the sub-directory in which libtool stores uninstalled libraries. 131 | */ 132 | #define LT_OBJDIR ".libs/" 133 | 134 | /* Name of package */ 135 | #define PACKAGE "libffi" 136 | 137 | /* Define to the address where bug reports for this package should be sent. */ 138 | #define PACKAGE_BUGREPORT "http://github.com/atgreen/libffi/issues" 139 | 140 | /* Define to the full name of this package. */ 141 | #define PACKAGE_NAME "libffi" 142 | 143 | /* Define to the full name and version of this package. */ 144 | #define PACKAGE_STRING "libffi 3.2.1" 145 | 146 | /* Define to the one symbol short name of this package. */ 147 | #define PACKAGE_TARNAME "libffi" 148 | 149 | /* Define to the home page for this package. */ 150 | #define PACKAGE_URL "" 151 | 152 | /* Define to the version of this package. */ 153 | #define PACKAGE_VERSION "3.2.1" 154 | 155 | /* The size of `double', as computed by sizeof. */ 156 | #define SIZEOF_DOUBLE 8 157 | 158 | /* The size of `long double', as computed by sizeof. */ 159 | #define SIZEOF_LONG_DOUBLE 16 160 | 161 | /* The size of `size_t', as computed by sizeof. */ 162 | #define SIZEOF_SIZE_T 4 163 | 164 | /* If using the C implementation of alloca, define if you know the 165 | direction of stack growth for your system; otherwise it will be 166 | automatically deduced at runtime. 167 | STACK_DIRECTION > 0 => grows toward higher addresses 168 | STACK_DIRECTION < 0 => grows toward lower addresses 169 | STACK_DIRECTION = 0 => direction of growth unknown */ 170 | /* #undef STACK_DIRECTION */ 171 | 172 | /* Define to 1 if you have the ANSI C header files. */ 173 | #define STDC_HEADERS 1 174 | 175 | /* Define if symbols are underscored. */ 176 | #define SYMBOL_UNDERSCORE 1 177 | 178 | /* Define this if you are using Purify and want to suppress spurious messages. 179 | */ 180 | /* #undef USING_PURIFY */ 181 | 182 | /* Version number of package */ 183 | #define VERSION "3.2.1" 184 | 185 | /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most 186 | significant byte first (like Motorola and SPARC, unlike Intel). */ 187 | #if defined AC_APPLE_UNIVERSAL_BUILD 188 | # if defined __BIG_ENDIAN__ 189 | # define WORDS_BIGENDIAN 1 190 | # endif 191 | #else 192 | # ifndef WORDS_BIGENDIAN 193 | /* # undef WORDS_BIGENDIAN */ 194 | # endif 195 | #endif 196 | 197 | /* Define to `unsigned int' if does not define. */ 198 | /* #undef size_t */ 199 | 200 | 201 | #ifdef HAVE_HIDDEN_VISIBILITY_ATTRIBUTE 202 | #ifdef LIBFFI_ASM 203 | #define FFI_HIDDEN(name) .hidden name 204 | #else 205 | #define FFI_HIDDEN __attribute__ ((visibility ("hidden"))) 206 | #endif 207 | #else 208 | #ifdef LIBFFI_ASM 209 | #define FFI_HIDDEN(name) 210 | #else 211 | #define FFI_HIDDEN 212 | #endif 213 | #endif 214 | 215 | 216 | 217 | #endif -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunction/libffi/headers/fficonfig_x86_64.h: -------------------------------------------------------------------------------- 1 | #ifdef __x86_64__ 2 | 3 | /* fficonfig.h. Generated from fficonfig.h.in by configure. */ 4 | /* fficonfig.h.in. Generated from configure.ac by autoheader. */ 5 | 6 | /* Define if building universal (internal helper macro) */ 7 | /* #undef AC_APPLE_UNIVERSAL_BUILD */ 8 | 9 | /* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP 10 | systems. This function is required for `alloca.c' support on those systems. 11 | */ 12 | /* #undef CRAY_STACKSEG_END */ 13 | 14 | /* Define to 1 if using `alloca.c'. */ 15 | /* #undef C_ALLOCA */ 16 | 17 | /* Define to the flags needed for the .section .eh_frame directive. */ 18 | #define EH_FRAME_FLAGS "aw" 19 | 20 | /* Define this if you want extra debugging. */ 21 | /* #undef FFI_DEBUG */ 22 | 23 | /* Cannot use PROT_EXEC on this target, so, we revert to alternative means */ 24 | /* #undef FFI_EXEC_TRAMPOLINE_TABLE */ 25 | 26 | /* Define this if you want to enable pax emulated trampolines */ 27 | /* #undef FFI_MMAP_EXEC_EMUTRAMP_PAX */ 28 | 29 | /* Cannot use malloc on this target, so, we revert to alternative means */ 30 | #define FFI_MMAP_EXEC_WRIT 1 31 | 32 | /* Define this if you do not want support for the raw API. */ 33 | /* #undef FFI_NO_RAW_API */ 34 | 35 | /* Define this if you do not want support for aggregate types. */ 36 | /* #undef FFI_NO_STRUCTS */ 37 | 38 | /* Define to 1 if you have `alloca', as a function or macro. */ 39 | #define HAVE_ALLOCA 1 40 | 41 | /* Define to 1 if you have and it should be used (not on Ultrix). 42 | */ 43 | #define HAVE_ALLOCA_H 1 44 | 45 | /* Define if your assembler supports .ascii. */ 46 | /* #undef HAVE_AS_ASCII_PSEUDO_OP */ 47 | 48 | /* Define if your assembler supports .cfi_* directives. */ 49 | #define HAVE_AS_CFI_PSEUDO_OP 1 50 | 51 | /* Define if your assembler supports .register. */ 52 | /* #undef HAVE_AS_REGISTER_PSEUDO_OP */ 53 | 54 | /* Define if your assembler and linker support unaligned PC relative relocs. 55 | */ 56 | /* #undef HAVE_AS_SPARC_UA_PCREL */ 57 | 58 | /* Define if your assembler supports .string. */ 59 | /* #undef HAVE_AS_STRING_PSEUDO_OP */ 60 | 61 | /* Define if your assembler supports unwind section type. */ 62 | /* #undef HAVE_AS_X86_64_UNWIND_SECTION_TYPE */ 63 | 64 | /* Define if your assembler supports PC relative relocs. */ 65 | /* #undef HAVE_AS_X86_PCREL */ 66 | 67 | /* Define to 1 if you have the header file. */ 68 | #define HAVE_DLFCN_H 1 69 | 70 | /* Define if __attribute__((visibility("hidden"))) is supported. */ 71 | /* #undef HAVE_HIDDEN_VISIBILITY_ATTRIBUTE */ 72 | 73 | /* Define to 1 if you have the header file. */ 74 | #define HAVE_INTTYPES_H 1 75 | 76 | /* Define if you have the long double type and it is bigger than a double */ 77 | #define HAVE_LONG_DOUBLE 1 78 | 79 | /* Define if you support more than one size of the long double type */ 80 | /* #undef HAVE_LONG_DOUBLE_VARIANT */ 81 | 82 | /* Define to 1 if you have the `memcpy' function. */ 83 | #define HAVE_MEMCPY 1 84 | 85 | /* Define to 1 if you have the header file. */ 86 | #define HAVE_MEMORY_H 1 87 | 88 | /* Define to 1 if you have the `mkostemp' function. */ 89 | /* #undef HAVE_MKOSTEMP */ 90 | 91 | /* Define to 1 if you have the `mmap' function. */ 92 | #define HAVE_MMAP 1 93 | 94 | /* Define if mmap with MAP_ANON(YMOUS) works. */ 95 | #define HAVE_MMAP_ANON 1 96 | 97 | /* Define if mmap of /dev/zero works. */ 98 | /* #undef HAVE_MMAP_DEV_ZERO */ 99 | 100 | /* Define if read-only mmap of a plain file works. */ 101 | #define HAVE_MMAP_FILE 1 102 | 103 | /* Define if .eh_frame sections should be read-only. */ 104 | /* #undef HAVE_RO_EH_FRAME */ 105 | 106 | /* Define to 1 if you have the header file. */ 107 | #define HAVE_STDINT_H 1 108 | 109 | /* Define to 1 if you have the header file. */ 110 | #define HAVE_STDLIB_H 1 111 | 112 | /* Define to 1 if you have the header file. */ 113 | #define HAVE_STRINGS_H 1 114 | 115 | /* Define to 1 if you have the header file. */ 116 | #define HAVE_STRING_H 1 117 | 118 | /* Define to 1 if you have the header file. */ 119 | #define HAVE_SYS_MMAN_H 1 120 | 121 | /* Define to 1 if you have the header file. */ 122 | #define HAVE_SYS_STAT_H 1 123 | 124 | /* Define to 1 if you have the header file. */ 125 | #define HAVE_SYS_TYPES_H 1 126 | 127 | /* Define to 1 if you have the header file. */ 128 | #define HAVE_UNISTD_H 1 129 | 130 | /* Define to the sub-directory in which libtool stores uninstalled libraries. 131 | */ 132 | #define LT_OBJDIR ".libs/" 133 | 134 | /* Name of package */ 135 | #define PACKAGE "libffi" 136 | 137 | /* Define to the address where bug reports for this package should be sent. */ 138 | #define PACKAGE_BUGREPORT "http://github.com/atgreen/libffi/issues" 139 | 140 | /* Define to the full name of this package. */ 141 | #define PACKAGE_NAME "libffi" 142 | 143 | /* Define to the full name and version of this package. */ 144 | #define PACKAGE_STRING "libffi 3.2.1" 145 | 146 | /* Define to the one symbol short name of this package. */ 147 | #define PACKAGE_TARNAME "libffi" 148 | 149 | /* Define to the home page for this package. */ 150 | #define PACKAGE_URL "" 151 | 152 | /* Define to the version of this package. */ 153 | #define PACKAGE_VERSION "3.2.1" 154 | 155 | /* The size of `double', as computed by sizeof. */ 156 | #define SIZEOF_DOUBLE 8 157 | 158 | /* The size of `long double', as computed by sizeof. */ 159 | #define SIZEOF_LONG_DOUBLE 16 160 | 161 | /* The size of `size_t', as computed by sizeof. */ 162 | #define SIZEOF_SIZE_T 8 163 | 164 | /* If using the C implementation of alloca, define if you know the 165 | direction of stack growth for your system; otherwise it will be 166 | automatically deduced at runtime. 167 | STACK_DIRECTION > 0 => grows toward higher addresses 168 | STACK_DIRECTION < 0 => grows toward lower addresses 169 | STACK_DIRECTION = 0 => direction of growth unknown */ 170 | /* #undef STACK_DIRECTION */ 171 | 172 | /* Define to 1 if you have the ANSI C header files. */ 173 | #define STDC_HEADERS 1 174 | 175 | /* Define if symbols are underscored. */ 176 | #define SYMBOL_UNDERSCORE 1 177 | 178 | /* Define this if you are using Purify and want to suppress spurious messages. 179 | */ 180 | /* #undef USING_PURIFY */ 181 | 182 | /* Version number of package */ 183 | #define VERSION "3.2.1" 184 | 185 | /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most 186 | significant byte first (like Motorola and SPARC, unlike Intel). */ 187 | #if defined AC_APPLE_UNIVERSAL_BUILD 188 | # if defined __BIG_ENDIAN__ 189 | # define WORDS_BIGENDIAN 1 190 | # endif 191 | #else 192 | # ifndef WORDS_BIGENDIAN 193 | /* # undef WORDS_BIGENDIAN */ 194 | # endif 195 | #endif 196 | 197 | /* Define to `unsigned int' if does not define. */ 198 | /* #undef size_t */ 199 | 200 | 201 | #ifdef HAVE_HIDDEN_VISIBILITY_ATTRIBUTE 202 | #ifdef LIBFFI_ASM 203 | #define FFI_HIDDEN(name) .hidden name 204 | #else 205 | #define FFI_HIDDEN __attribute__ ((visibility ("hidden"))) 206 | #endif 207 | #else 208 | #ifdef LIBFFI_ASM 209 | #define FFI_HIDDEN(name) 210 | #else 211 | #define FFI_HIDDEN 212 | #endif 213 | #endif 214 | 215 | 216 | 217 | #endif -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunction/libffi/headers/ffitarget.h: -------------------------------------------------------------------------------- 1 | #ifdef __arm64__ 2 | 3 | #include "ffitarget_arm64.h" 4 | 5 | 6 | #endif 7 | #ifdef __i386__ 8 | 9 | #include "ffitarget_i386.h" 10 | 11 | 12 | #endif 13 | #ifdef __arm__ 14 | 15 | #include "ffitarget_armv7.h" 16 | 17 | 18 | #endif 19 | #ifdef __x86_64__ 20 | 21 | #include "ffitarget_x86_64.h" 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunction/libffi/headers/ffitarget_arm64.h: -------------------------------------------------------------------------------- 1 | #ifdef __arm64__ 2 | 3 | /* Copyright (c) 2009, 2010, 2011, 2012 ARM Ltd. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | ``Software''), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 23 | 24 | #ifndef LIBFFI_TARGET_H 25 | #define LIBFFI_TARGET_H 26 | 27 | #ifndef LIBFFI_H 28 | #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead." 29 | #endif 30 | 31 | #ifndef LIBFFI_ASM 32 | typedef unsigned long ffi_arg; 33 | typedef signed long ffi_sarg; 34 | 35 | typedef enum ffi_abi 36 | { 37 | FFI_FIRST_ABI = 0, 38 | FFI_SYSV, 39 | FFI_LAST_ABI, 40 | FFI_DEFAULT_ABI = FFI_SYSV 41 | } ffi_abi; 42 | #endif 43 | 44 | /* ---- Definitions for closures ----------------------------------------- */ 45 | 46 | #define FFI_CLOSURES 1 47 | #define FFI_TRAMPOLINE_SIZE 36 48 | #define FFI_NATIVE_RAW_API 0 49 | 50 | /* ---- Internal ---- */ 51 | 52 | #if defined (__APPLE__) 53 | #define FFI_TARGET_SPECIFIC_VARIADIC 54 | #define FFI_EXTRA_CIF_FIELDS unsigned aarch64_flags; unsigned aarch64_nfixedargs 55 | #else 56 | #define FFI_EXTRA_CIF_FIELDS unsigned aarch64_flags 57 | #endif 58 | 59 | #define AARCH64_FFI_WITH_V_BIT 0 60 | 61 | #define AARCH64_N_XREG 32 62 | #define AARCH64_N_VREG 32 63 | #define AARCH64_CALL_CONTEXT_SIZE (AARCH64_N_XREG * 8 + AARCH64_N_VREG * 16) 64 | 65 | #endif 66 | 67 | 68 | #endif -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunction/libffi/headers/ffitarget_armv7.h: -------------------------------------------------------------------------------- 1 | #ifdef __arm__ 2 | 3 | /* -----------------------------------------------------------------*-C-*- 4 | ffitarget.h - Copyright (c) 2012 Anthony Green 5 | Copyright (c) 2010 CodeSourcery 6 | Copyright (c) 1996-2003 Red Hat, Inc. 7 | 8 | Target configuration macros for ARM. 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining 11 | a copy of this software and associated documentation files (the 12 | ``Software''), to deal in the Software without restriction, including 13 | without limitation the rights to use, copy, modify, merge, publish, 14 | distribute, sublicense, and/or sell copies of the Software, and to 15 | permit persons to whom the Software is furnished to do so, subject to 16 | the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included 19 | in all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, 22 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 24 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 25 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 26 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 27 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 28 | DEALINGS IN THE SOFTWARE. 29 | 30 | ----------------------------------------------------------------------- */ 31 | 32 | #ifndef LIBFFI_TARGET_H 33 | #define LIBFFI_TARGET_H 34 | 35 | #ifndef LIBFFI_H 36 | #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead." 37 | #endif 38 | 39 | #ifndef LIBFFI_ASM 40 | typedef unsigned long ffi_arg; 41 | typedef signed long ffi_sarg; 42 | 43 | typedef enum ffi_abi { 44 | FFI_FIRST_ABI = 0, 45 | FFI_SYSV, 46 | FFI_VFP, 47 | FFI_LAST_ABI, 48 | #ifdef __ARM_PCS_VFP 49 | FFI_DEFAULT_ABI = FFI_VFP, 50 | #else 51 | FFI_DEFAULT_ABI = FFI_SYSV, 52 | #endif 53 | } ffi_abi; 54 | #endif 55 | 56 | #define FFI_EXTRA_CIF_FIELDS \ 57 | int vfp_used; \ 58 | short vfp_reg_free, vfp_nargs; \ 59 | signed char vfp_args[16] \ 60 | 61 | /* Internally used. */ 62 | #define FFI_TYPE_STRUCT_VFP_FLOAT (FFI_TYPE_LAST + 1) 63 | #define FFI_TYPE_STRUCT_VFP_DOUBLE (FFI_TYPE_LAST + 2) 64 | 65 | #define FFI_TARGET_SPECIFIC_VARIADIC 66 | 67 | /* ---- Definitions for closures ----------------------------------------- */ 68 | 69 | #define FFI_CLOSURES 1 70 | #define FFI_TRAMPOLINE_SIZE 20 71 | #define FFI_NATIVE_RAW_API 0 72 | 73 | #endif 74 | 75 | 76 | #endif -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunction/libffi/headers/ffitarget_i386.h: -------------------------------------------------------------------------------- 1 | #ifdef __i386__ 2 | 3 | /* -----------------------------------------------------------------*-C-*- 4 | ffitarget.h - Copyright (c) 2012, 2014 Anthony Green 5 | Copyright (c) 1996-2003, 2010 Red Hat, Inc. 6 | Copyright (C) 2008 Free Software Foundation, Inc. 7 | 8 | Target configuration macros for x86 and x86-64. 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining 11 | a copy of this software and associated documentation files (the 12 | ``Software''), to deal in the Software without restriction, including 13 | without limitation the rights to use, copy, modify, merge, publish, 14 | distribute, sublicense, and/or sell copies of the Software, and to 15 | permit persons to whom the Software is furnished to do so, subject to 16 | the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included 19 | in all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, 22 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 24 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 25 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 26 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 27 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 28 | DEALINGS IN THE SOFTWARE. 29 | 30 | ----------------------------------------------------------------------- */ 31 | 32 | #ifndef LIBFFI_TARGET_H 33 | #define LIBFFI_TARGET_H 34 | 35 | #ifndef LIBFFI_H 36 | #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead." 37 | #endif 38 | 39 | /* ---- System specific configurations ----------------------------------- */ 40 | 41 | /* For code common to all platforms on x86 and x86_64. */ 42 | #define X86_ANY 43 | 44 | #if defined (X86_64) && defined (__i386__) 45 | #undef X86_64 46 | #define X86 47 | #endif 48 | 49 | #ifdef X86_WIN64 50 | #define FFI_SIZEOF_ARG 8 51 | #define USE_BUILTIN_FFS 0 /* not yet implemented in mingw-64 */ 52 | #endif 53 | 54 | #define FFI_TARGET_SPECIFIC_STACK_SPACE_ALLOCATION 55 | #define FFI_TARGET_HAS_COMPLEX_TYPE 56 | 57 | /* ---- Generic type definitions ----------------------------------------- */ 58 | 59 | #ifndef LIBFFI_ASM 60 | #ifdef X86_WIN64 61 | #ifdef _MSC_VER 62 | typedef unsigned __int64 ffi_arg; 63 | typedef __int64 ffi_sarg; 64 | #else 65 | typedef unsigned long long ffi_arg; 66 | typedef long long ffi_sarg; 67 | #endif 68 | #else 69 | #if defined __x86_64__ && defined __ILP32__ 70 | #define FFI_SIZEOF_ARG 8 71 | #define FFI_SIZEOF_JAVA_RAW 4 72 | typedef unsigned long long ffi_arg; 73 | typedef long long ffi_sarg; 74 | #else 75 | typedef unsigned long ffi_arg; 76 | typedef signed long ffi_sarg; 77 | #endif 78 | #endif 79 | 80 | typedef enum ffi_abi { 81 | FFI_FIRST_ABI = 0, 82 | 83 | /* ---- Intel x86 Win32 ---------- */ 84 | #ifdef X86_WIN32 85 | FFI_SYSV, 86 | FFI_STDCALL, 87 | FFI_THISCALL, 88 | FFI_FASTCALL, 89 | FFI_MS_CDECL, 90 | FFI_PASCAL, 91 | FFI_REGISTER, 92 | FFI_LAST_ABI, 93 | #ifdef _MSC_VER 94 | FFI_DEFAULT_ABI = FFI_MS_CDECL 95 | #else 96 | FFI_DEFAULT_ABI = FFI_SYSV 97 | #endif 98 | 99 | #elif defined(X86_WIN64) 100 | FFI_WIN64, 101 | FFI_LAST_ABI, 102 | FFI_DEFAULT_ABI = FFI_WIN64 103 | 104 | #else 105 | /* ---- Intel x86 and AMD x86-64 - */ 106 | FFI_SYSV, 107 | FFI_UNIX64, /* Unix variants all use the same ABI for x86-64 */ 108 | FFI_THISCALL, 109 | FFI_FASTCALL, 110 | FFI_STDCALL, 111 | FFI_PASCAL, 112 | FFI_REGISTER, 113 | FFI_LAST_ABI, 114 | #if defined(__i386__) || defined(__i386) 115 | FFI_DEFAULT_ABI = FFI_SYSV 116 | #else 117 | FFI_DEFAULT_ABI = FFI_UNIX64 118 | #endif 119 | #endif 120 | } ffi_abi; 121 | #endif 122 | 123 | /* ---- Definitions for closures ----------------------------------------- */ 124 | 125 | #define FFI_CLOSURES 1 126 | #define FFI_TYPE_SMALL_STRUCT_1B (FFI_TYPE_LAST + 1) 127 | #define FFI_TYPE_SMALL_STRUCT_2B (FFI_TYPE_LAST + 2) 128 | #define FFI_TYPE_SMALL_STRUCT_4B (FFI_TYPE_LAST + 3) 129 | #define FFI_TYPE_MS_STRUCT (FFI_TYPE_LAST + 4) 130 | 131 | #if defined (X86_64) || (defined (__x86_64__) && defined (X86_DARWIN)) 132 | #define FFI_TRAMPOLINE_SIZE 24 133 | #define FFI_NATIVE_RAW_API 0 134 | #else 135 | #ifdef X86_WIN32 136 | #define FFI_TRAMPOLINE_SIZE 52 137 | #else 138 | #ifdef X86_WIN64 139 | #define FFI_TRAMPOLINE_SIZE 29 140 | #define FFI_NATIVE_RAW_API 0 141 | #define FFI_NO_RAW_API 1 142 | #else 143 | #define FFI_TRAMPOLINE_SIZE 10 144 | #endif 145 | #endif 146 | #ifndef X86_WIN64 147 | #define FFI_NATIVE_RAW_API 1 /* x86 has native raw api support */ 148 | #endif 149 | #endif 150 | 151 | #endif 152 | 153 | 154 | 155 | #endif -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunction/libffi/headers/ffitarget_x86_64.h: -------------------------------------------------------------------------------- 1 | #ifdef __x86_64__ 2 | 3 | /* -----------------------------------------------------------------*-C-*- 4 | ffitarget.h - Copyright (c) 2012, 2014 Anthony Green 5 | Copyright (c) 1996-2003, 2010 Red Hat, Inc. 6 | Copyright (C) 2008 Free Software Foundation, Inc. 7 | 8 | Target configuration macros for x86 and x86-64. 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining 11 | a copy of this software and associated documentation files (the 12 | ``Software''), to deal in the Software without restriction, including 13 | without limitation the rights to use, copy, modify, merge, publish, 14 | distribute, sublicense, and/or sell copies of the Software, and to 15 | permit persons to whom the Software is furnished to do so, subject to 16 | the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included 19 | in all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, 22 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 24 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 25 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 26 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 27 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 28 | DEALINGS IN THE SOFTWARE. 29 | 30 | ----------------------------------------------------------------------- */ 31 | 32 | #ifndef LIBFFI_TARGET_H 33 | #define LIBFFI_TARGET_H 34 | 35 | #ifndef LIBFFI_H 36 | #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead." 37 | #endif 38 | 39 | /* ---- System specific configurations ----------------------------------- */ 40 | 41 | /* For code common to all platforms on x86 and x86_64. */ 42 | #define X86_ANY 43 | 44 | #if defined (X86_64) && defined (__i386__) 45 | #undef X86_64 46 | #define X86 47 | #endif 48 | 49 | #ifdef X86_WIN64 50 | #define FFI_SIZEOF_ARG 8 51 | #define USE_BUILTIN_FFS 0 /* not yet implemented in mingw-64 */ 52 | #endif 53 | 54 | #define FFI_TARGET_SPECIFIC_STACK_SPACE_ALLOCATION 55 | #define FFI_TARGET_HAS_COMPLEX_TYPE 56 | 57 | /* ---- Generic type definitions ----------------------------------------- */ 58 | 59 | #ifndef LIBFFI_ASM 60 | #ifdef X86_WIN64 61 | #ifdef _MSC_VER 62 | typedef unsigned __int64 ffi_arg; 63 | typedef __int64 ffi_sarg; 64 | #else 65 | typedef unsigned long long ffi_arg; 66 | typedef long long ffi_sarg; 67 | #endif 68 | #else 69 | #if defined __x86_64__ && defined __ILP32__ 70 | #define FFI_SIZEOF_ARG 8 71 | #define FFI_SIZEOF_JAVA_RAW 4 72 | typedef unsigned long long ffi_arg; 73 | typedef long long ffi_sarg; 74 | #else 75 | typedef unsigned long ffi_arg; 76 | typedef signed long ffi_sarg; 77 | #endif 78 | #endif 79 | 80 | typedef enum ffi_abi { 81 | FFI_FIRST_ABI = 0, 82 | 83 | /* ---- Intel x86 Win32 ---------- */ 84 | #ifdef X86_WIN32 85 | FFI_SYSV, 86 | FFI_STDCALL, 87 | FFI_THISCALL, 88 | FFI_FASTCALL, 89 | FFI_MS_CDECL, 90 | FFI_PASCAL, 91 | FFI_REGISTER, 92 | FFI_LAST_ABI, 93 | #ifdef _MSC_VER 94 | FFI_DEFAULT_ABI = FFI_MS_CDECL 95 | #else 96 | FFI_DEFAULT_ABI = FFI_SYSV 97 | #endif 98 | 99 | #elif defined(X86_WIN64) 100 | FFI_WIN64, 101 | FFI_LAST_ABI, 102 | FFI_DEFAULT_ABI = FFI_WIN64 103 | 104 | #else 105 | /* ---- Intel x86 and AMD x86-64 - */ 106 | FFI_SYSV, 107 | FFI_UNIX64, /* Unix variants all use the same ABI for x86-64 */ 108 | FFI_THISCALL, 109 | FFI_FASTCALL, 110 | FFI_STDCALL, 111 | FFI_PASCAL, 112 | FFI_REGISTER, 113 | FFI_LAST_ABI, 114 | #if defined(__i386__) || defined(__i386) 115 | FFI_DEFAULT_ABI = FFI_SYSV 116 | #else 117 | FFI_DEFAULT_ABI = FFI_UNIX64 118 | #endif 119 | #endif 120 | } ffi_abi; 121 | #endif 122 | 123 | /* ---- Definitions for closures ----------------------------------------- */ 124 | 125 | #define FFI_CLOSURES 1 126 | #define FFI_TYPE_SMALL_STRUCT_1B (FFI_TYPE_LAST + 1) 127 | #define FFI_TYPE_SMALL_STRUCT_2B (FFI_TYPE_LAST + 2) 128 | #define FFI_TYPE_SMALL_STRUCT_4B (FFI_TYPE_LAST + 3) 129 | #define FFI_TYPE_MS_STRUCT (FFI_TYPE_LAST + 4) 130 | 131 | #if defined (X86_64) || (defined (__x86_64__) && defined (X86_DARWIN)) 132 | #define FFI_TRAMPOLINE_SIZE 24 133 | #define FFI_NATIVE_RAW_API 0 134 | #else 135 | #ifdef X86_WIN32 136 | #define FFI_TRAMPOLINE_SIZE 52 137 | #else 138 | #ifdef X86_WIN64 139 | #define FFI_TRAMPOLINE_SIZE 29 140 | #define FFI_NATIVE_RAW_API 0 141 | #define FFI_NO_RAW_API 1 142 | #else 143 | #define FFI_TRAMPOLINE_SIZE 10 144 | #endif 145 | #endif 146 | #ifndef X86_WIN64 147 | #define FFI_NATIVE_RAW_API 1 /* x86 has native raw api support */ 148 | #endif 149 | #endif 150 | 151 | #endif 152 | 153 | 154 | 155 | #endif -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunction/libffi/src/aarch64/sysv_arm64.S: -------------------------------------------------------------------------------- 1 | #ifdef __arm64__ 2 | 3 | /* Copyright (c) 2009, 2010, 2011, 2012 ARM Ltd. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | ``Software''), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 23 | 24 | #define LIBFFI_ASM 25 | #include "fficonfig.h" 26 | #include "ffi.h" 27 | 28 | #ifdef HAVE_MACHINE_ASM_H 29 | #include 30 | #else 31 | #ifdef __USER_LABEL_PREFIX__ 32 | #define CONCAT1(a, b) CONCAT2(a, b) 33 | #define CONCAT2(a, b) a ## b 34 | 35 | /* Use the right prefix for global labels. */ 36 | #define CNAME(x) CONCAT1 (__USER_LABEL_PREFIX__, x) 37 | #else 38 | #define CNAME(x) x 39 | #endif 40 | #endif 41 | 42 | #define cfi_adjust_cfa_offset(off) .cfi_adjust_cfa_offset off 43 | #define cfi_rel_offset(reg, off) .cfi_rel_offset reg, off 44 | #define cfi_restore(reg) .cfi_restore reg 45 | #define cfi_def_cfa_register(reg) .cfi_def_cfa_register reg 46 | 47 | .text 48 | .globl CNAME(ffi_call_SYSV) 49 | #ifdef __ELF__ 50 | .type CNAME(ffi_call_SYSV), #function 51 | #endif 52 | #ifdef __APPLE__ 53 | .align 2 54 | #endif 55 | 56 | /* ffi_call_SYSV() 57 | 58 | Create a stack frame, setup an argument context, call the callee 59 | and extract the result. 60 | 61 | The maximum required argument stack size is provided, 62 | ffi_call_SYSV() allocates that stack space then calls the 63 | prepare_fn to populate register context and stack. The 64 | argument passing registers are loaded from the register 65 | context and the callee called, on return the register passing 66 | register are saved back to the context. Our caller will 67 | extract the return value from the final state of the saved 68 | register context. 69 | 70 | Prototype: 71 | 72 | extern unsigned 73 | ffi_call_SYSV (void (*)(struct call_context *context, unsigned char *, 74 | extended_cif *), 75 | struct call_context *context, 76 | extended_cif *, 77 | size_t required_stack_size, 78 | void (*fn)(void)); 79 | 80 | Therefore on entry we have: 81 | 82 | x0 prepare_fn 83 | x1 &context 84 | x2 &ecif 85 | x3 bytes 86 | x4 fn 87 | 88 | This function uses the following stack frame layout: 89 | 90 | == 91 | saved x30(lr) 92 | x29(fp)-> saved x29(fp) 93 | saved x24 94 | saved x23 95 | saved x22 96 | sp' -> saved x21 97 | ... 98 | sp -> (constructed callee stack arguments) 99 | == 100 | 101 | Voila! */ 102 | 103 | #define ffi_call_SYSV_FS (8 * 4) 104 | 105 | .cfi_startproc 106 | CNAME(ffi_call_SYSV): 107 | stp x29, x30, [sp, #-16]! 108 | cfi_adjust_cfa_offset (16) 109 | cfi_rel_offset (x29, 0) 110 | cfi_rel_offset (x30, 8) 111 | 112 | mov x29, sp 113 | cfi_def_cfa_register (x29) 114 | sub sp, sp, #ffi_call_SYSV_FS 115 | 116 | stp x21, x22, [sp, #0] 117 | cfi_rel_offset (x21, 0 - ffi_call_SYSV_FS) 118 | cfi_rel_offset (x22, 8 - ffi_call_SYSV_FS) 119 | 120 | stp x23, x24, [sp, #16] 121 | cfi_rel_offset (x23, 16 - ffi_call_SYSV_FS) 122 | cfi_rel_offset (x24, 24 - ffi_call_SYSV_FS) 123 | 124 | mov x21, x1 125 | mov x22, x2 126 | mov x24, x4 127 | 128 | /* Allocate the stack space for the actual arguments, many 129 | arguments will be passed in registers, but we assume 130 | worst case and allocate sufficient stack for ALL of 131 | the arguments. */ 132 | sub sp, sp, x3 133 | 134 | /* unsigned (*prepare_fn) (struct call_context *context, 135 | unsigned char *stack, extended_cif *ecif); 136 | */ 137 | mov x23, x0 138 | mov x0, x1 139 | mov x1, sp 140 | /* x2 already in place */ 141 | blr x23 142 | 143 | /* Preserve the flags returned. */ 144 | mov x23, x0 145 | 146 | /* Figure out if we should touch the vector registers. */ 147 | tbz x23, #AARCH64_FFI_WITH_V_BIT, 1f 148 | 149 | /* Load the vector argument passing registers. */ 150 | ldp q0, q1, [x21, #8*32 + 0] 151 | ldp q2, q3, [x21, #8*32 + 32] 152 | ldp q4, q5, [x21, #8*32 + 64] 153 | ldp q6, q7, [x21, #8*32 + 96] 154 | 1: 155 | /* Load the core argument passing registers. */ 156 | ldp x0, x1, [x21, #0] 157 | ldp x2, x3, [x21, #16] 158 | ldp x4, x5, [x21, #32] 159 | ldp x6, x7, [x21, #48] 160 | 161 | /* Don't forget x8 which may be holding the address of a return buffer. 162 | */ 163 | ldr x8, [x21, #8*8] 164 | 165 | blr x24 166 | 167 | /* Save the core argument passing registers. */ 168 | stp x0, x1, [x21, #0] 169 | stp x2, x3, [x21, #16] 170 | stp x4, x5, [x21, #32] 171 | stp x6, x7, [x21, #48] 172 | 173 | /* Note nothing useful ever comes back in x8! */ 174 | 175 | /* Figure out if we should touch the vector registers. */ 176 | tbz x23, #AARCH64_FFI_WITH_V_BIT, 1f 177 | 178 | /* Save the vector argument passing registers. */ 179 | stp q0, q1, [x21, #8*32 + 0] 180 | stp q2, q3, [x21, #8*32 + 32] 181 | stp q4, q5, [x21, #8*32 + 64] 182 | stp q6, q7, [x21, #8*32 + 96] 183 | 1: 184 | /* All done, unwind our stack frame. */ 185 | ldp x21, x22, [x29, # - ffi_call_SYSV_FS] 186 | cfi_restore (x21) 187 | cfi_restore (x22) 188 | 189 | ldp x23, x24, [x29, # - ffi_call_SYSV_FS + 16] 190 | cfi_restore (x23) 191 | cfi_restore (x24) 192 | 193 | mov sp, x29 194 | cfi_def_cfa_register (sp) 195 | 196 | ldp x29, x30, [sp], #16 197 | cfi_adjust_cfa_offset (-16) 198 | cfi_restore (x29) 199 | cfi_restore (x30) 200 | 201 | ret 202 | 203 | .cfi_endproc 204 | #ifdef __ELF__ 205 | .size CNAME(ffi_call_SYSV), .-CNAME(ffi_call_SYSV) 206 | #endif 207 | 208 | #define ffi_closure_SYSV_FS (8 * 2 + AARCH64_CALL_CONTEXT_SIZE) 209 | 210 | /* ffi_closure_SYSV 211 | 212 | Closure invocation glue. This is the low level code invoked directly by 213 | the closure trampoline to setup and call a closure. 214 | 215 | On entry x17 points to a struct trampoline_data, x16 has been clobbered 216 | all other registers are preserved. 217 | 218 | We allocate a call context and save the argument passing registers, 219 | then invoked the generic C ffi_closure_SYSV_inner() function to do all 220 | the real work, on return we load the result passing registers back from 221 | the call context. 222 | 223 | On entry 224 | 225 | extern void 226 | ffi_closure_SYSV (struct trampoline_data *); 227 | 228 | struct trampoline_data 229 | { 230 | UINT64 *ffi_closure; 231 | UINT64 flags; 232 | }; 233 | 234 | This function uses the following stack frame layout: 235 | 236 | == 237 | saved x30(lr) 238 | x29(fp)-> saved x29(fp) 239 | saved x22 240 | saved x21 241 | ... 242 | sp -> call_context 243 | == 244 | 245 | Voila! */ 246 | 247 | .text 248 | .globl CNAME(ffi_closure_SYSV) 249 | #ifdef __APPLE__ 250 | .align 2 251 | #endif 252 | .cfi_startproc 253 | CNAME(ffi_closure_SYSV): 254 | stp x29, x30, [sp, #-16]! 255 | cfi_adjust_cfa_offset (16) 256 | cfi_rel_offset (x29, 0) 257 | cfi_rel_offset (x30, 8) 258 | 259 | mov x29, sp 260 | cfi_def_cfa_register (x29) 261 | 262 | sub sp, sp, #ffi_closure_SYSV_FS 263 | 264 | stp x21, x22, [x29, #-16] 265 | cfi_rel_offset (x21, -16) 266 | cfi_rel_offset (x22, -8) 267 | 268 | /* Load x21 with &call_context. */ 269 | mov x21, sp 270 | /* Preserve our struct trampoline_data * */ 271 | mov x22, x17 272 | 273 | /* Save the rest of the argument passing registers. */ 274 | stp x0, x1, [x21, #0] 275 | stp x2, x3, [x21, #16] 276 | stp x4, x5, [x21, #32] 277 | stp x6, x7, [x21, #48] 278 | /* Don't forget we may have been given a result scratch pad address. 279 | */ 280 | str x8, [x21, #64] 281 | 282 | /* Figure out if we should touch the vector registers. */ 283 | ldr x0, [x22, #8] 284 | tbz x0, #AARCH64_FFI_WITH_V_BIT, 1f 285 | 286 | /* Save the argument passing vector registers. */ 287 | stp q0, q1, [x21, #8*32 + 0] 288 | stp q2, q3, [x21, #8*32 + 32] 289 | stp q4, q5, [x21, #8*32 + 64] 290 | stp q6, q7, [x21, #8*32 + 96] 291 | 1: 292 | /* Load &ffi_closure.. */ 293 | ldr x0, [x22, #0] 294 | mov x1, x21 295 | /* Compute the location of the stack at the point that the 296 | trampoline was called. */ 297 | add x2, x29, #16 298 | 299 | bl CNAME(ffi_closure_SYSV_inner) 300 | 301 | /* Figure out if we should touch the vector registers. */ 302 | ldr x0, [x22, #8] 303 | tbz x0, #AARCH64_FFI_WITH_V_BIT, 1f 304 | 305 | /* Load the result passing vector registers. */ 306 | ldp q0, q1, [x21, #8*32 + 0] 307 | ldp q2, q3, [x21, #8*32 + 32] 308 | ldp q4, q5, [x21, #8*32 + 64] 309 | ldp q6, q7, [x21, #8*32 + 96] 310 | 1: 311 | /* Load the result passing core registers. */ 312 | ldp x0, x1, [x21, #0] 313 | ldp x2, x3, [x21, #16] 314 | ldp x4, x5, [x21, #32] 315 | ldp x6, x7, [x21, #48] 316 | /* Note nothing useful is returned in x8. */ 317 | 318 | /* We are done, unwind our frame. */ 319 | ldp x21, x22, [x29, #-16] 320 | cfi_restore (x21) 321 | cfi_restore (x22) 322 | 323 | mov sp, x29 324 | cfi_def_cfa_register (sp) 325 | 326 | ldp x29, x30, [sp], #16 327 | cfi_adjust_cfa_offset (-16) 328 | cfi_restore (x29) 329 | cfi_restore (x30) 330 | 331 | ret 332 | .cfi_endproc 333 | #ifdef __ELF__ 334 | .size CNAME(ffi_closure_SYSV), .-CNAME(ffi_closure_SYSV) 335 | #endif 336 | 337 | 338 | #endif -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunction/libffi/src/common/prep_cif.c: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- 2 | prep_cif.c - Copyright (c) 2011, 2012 Anthony Green 3 | Copyright (c) 1996, 1998, 2007 Red Hat, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | ``Software''), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included 14 | in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | DEALINGS IN THE SOFTWARE. 24 | ----------------------------------------------------------------------- */ 25 | 26 | #include "ffi.h" 27 | #include "ffi_common.h" 28 | #include 29 | 30 | /* Round up to FFI_SIZEOF_ARG. */ 31 | 32 | #define STACK_ARG_SIZE(x) ALIGN(x, FFI_SIZEOF_ARG) 33 | 34 | /* Perform machine independent initialization of aggregate type 35 | specifications. */ 36 | 37 | static ffi_status initialize_aggregate(ffi_type *arg) 38 | { 39 | ffi_type **ptr; 40 | 41 | if (UNLIKELY(arg == NULL || arg->elements == NULL)) 42 | return FFI_BAD_TYPEDEF; 43 | 44 | arg->size = 0; 45 | arg->alignment = 0; 46 | 47 | ptr = &(arg->elements[0]); 48 | 49 | if (UNLIKELY(ptr == 0)) 50 | return FFI_BAD_TYPEDEF; 51 | 52 | while ((*ptr) != NULL) 53 | { 54 | if (UNLIKELY(((*ptr)->size == 0) 55 | && (initialize_aggregate((*ptr)) != FFI_OK))) 56 | return FFI_BAD_TYPEDEF; 57 | 58 | /* Perform a sanity check on the argument type */ 59 | FFI_ASSERT_VALID_TYPE(*ptr); 60 | 61 | arg->size = ALIGN(arg->size, (*ptr)->alignment); 62 | arg->size += (*ptr)->size; 63 | 64 | arg->alignment = (arg->alignment > (*ptr)->alignment) ? 65 | arg->alignment : (*ptr)->alignment; 66 | 67 | ptr++; 68 | } 69 | 70 | /* Structure size includes tail padding. This is important for 71 | structures that fit in one register on ABIs like the PowerPC64 72 | Linux ABI that right justify small structs in a register. 73 | It's also needed for nested structure layout, for example 74 | struct A { long a; char b; }; struct B { struct A x; char y; }; 75 | should find y at an offset of 2*sizeof(long) and result in a 76 | total size of 3*sizeof(long). */ 77 | arg->size = ALIGN (arg->size, arg->alignment); 78 | 79 | /* On some targets, the ABI defines that structures have an additional 80 | alignment beyond the "natural" one based on their elements. */ 81 | #ifdef FFI_AGGREGATE_ALIGNMENT 82 | if (FFI_AGGREGATE_ALIGNMENT > arg->alignment) 83 | arg->alignment = FFI_AGGREGATE_ALIGNMENT; 84 | #endif 85 | 86 | if (arg->size == 0) 87 | return FFI_BAD_TYPEDEF; 88 | else 89 | return FFI_OK; 90 | } 91 | 92 | #ifndef __CRIS__ 93 | /* The CRIS ABI specifies structure elements to have byte 94 | alignment only, so it completely overrides this functions, 95 | which assumes "natural" alignment and padding. */ 96 | 97 | /* Perform machine independent ffi_cif preparation, then call 98 | machine dependent routine. */ 99 | 100 | /* For non variadic functions isvariadic should be 0 and 101 | nfixedargs==ntotalargs. 102 | 103 | For variadic calls, isvariadic should be 1 and nfixedargs 104 | and ntotalargs set as appropriate. nfixedargs must always be >=1 */ 105 | 106 | 107 | ffi_status FFI_HIDDEN ffi_prep_cif_core(ffi_cif *cif, ffi_abi abi, 108 | unsigned int isvariadic, 109 | unsigned int nfixedargs, 110 | unsigned int ntotalargs, 111 | ffi_type *rtype, ffi_type **atypes) 112 | { 113 | unsigned bytes = 0; 114 | unsigned int i; 115 | ffi_type **ptr; 116 | 117 | FFI_ASSERT(cif != NULL); 118 | FFI_ASSERT((!isvariadic) || (nfixedargs >= 1)); 119 | FFI_ASSERT(nfixedargs <= ntotalargs); 120 | 121 | if (! (abi > FFI_FIRST_ABI && abi < FFI_LAST_ABI)) 122 | return FFI_BAD_ABI; 123 | 124 | cif->abi = abi; 125 | cif->arg_types = atypes; 126 | cif->nargs = ntotalargs; 127 | cif->rtype = rtype; 128 | 129 | cif->flags = 0; 130 | 131 | #if HAVE_LONG_DOUBLE_VARIANT 132 | ffi_prep_types (abi); 133 | #endif 134 | 135 | /* Initialize the return type if necessary */ 136 | if ((cif->rtype->size == 0) && (initialize_aggregate(cif->rtype) != FFI_OK)) 137 | return FFI_BAD_TYPEDEF; 138 | 139 | #ifndef FFI_TARGET_HAS_COMPLEX_TYPE 140 | if (rtype->type == FFI_TYPE_COMPLEX) 141 | abort(); 142 | #endif 143 | /* Perform a sanity check on the return type */ 144 | FFI_ASSERT_VALID_TYPE(cif->rtype); 145 | 146 | /* x86, x86-64 and s390 stack space allocation is handled in prep_machdep. */ 147 | #if !defined FFI_TARGET_SPECIFIC_STACK_SPACE_ALLOCATION 148 | /* Make space for the return structure pointer */ 149 | if (cif->rtype->type == FFI_TYPE_STRUCT 150 | #ifdef SPARC 151 | && (cif->abi != FFI_V9 || cif->rtype->size > 32) 152 | #endif 153 | #ifdef TILE 154 | && (cif->rtype->size > 10 * FFI_SIZEOF_ARG) 155 | #endif 156 | #ifdef XTENSA 157 | && (cif->rtype->size > 16) 158 | #endif 159 | #ifdef NIOS2 160 | && (cif->rtype->size > 8) 161 | #endif 162 | ) 163 | bytes = STACK_ARG_SIZE(sizeof(void*)); 164 | #endif 165 | 166 | for (ptr = cif->arg_types, i = cif->nargs; i > 0; i--, ptr++) 167 | { 168 | 169 | /* Initialize any uninitialized aggregate type definitions */ 170 | if (((*ptr)->size == 0) && (initialize_aggregate((*ptr)) != FFI_OK)) 171 | return FFI_BAD_TYPEDEF; 172 | 173 | #ifndef FFI_TARGET_HAS_COMPLEX_TYPE 174 | if ((*ptr)->type == FFI_TYPE_COMPLEX) 175 | abort(); 176 | #endif 177 | /* Perform a sanity check on the argument type, do this 178 | check after the initialization. */ 179 | FFI_ASSERT_VALID_TYPE(*ptr); 180 | 181 | #if !defined FFI_TARGET_SPECIFIC_STACK_SPACE_ALLOCATION 182 | #ifdef SPARC 183 | if (((*ptr)->type == FFI_TYPE_STRUCT 184 | && ((*ptr)->size > 16 || cif->abi != FFI_V9)) 185 | || ((*ptr)->type == FFI_TYPE_LONGDOUBLE 186 | && cif->abi != FFI_V9)) 187 | bytes += sizeof(void*); 188 | else 189 | #endif 190 | { 191 | /* Add any padding if necessary */ 192 | if (((*ptr)->alignment - 1) & bytes) 193 | bytes = (unsigned)ALIGN(bytes, (*ptr)->alignment); 194 | 195 | #ifdef TILE 196 | if (bytes < 10 * FFI_SIZEOF_ARG && 197 | bytes + STACK_ARG_SIZE((*ptr)->size) > 10 * FFI_SIZEOF_ARG) 198 | { 199 | /* An argument is never split between the 10 parameter 200 | registers and the stack. */ 201 | bytes = 10 * FFI_SIZEOF_ARG; 202 | } 203 | #endif 204 | #ifdef XTENSA 205 | if (bytes <= 6*4 && bytes + STACK_ARG_SIZE((*ptr)->size) > 6*4) 206 | bytes = 6*4; 207 | #endif 208 | 209 | bytes += STACK_ARG_SIZE((*ptr)->size); 210 | } 211 | #endif 212 | } 213 | 214 | cif->bytes = bytes; 215 | 216 | /* Perform machine dependent cif processing */ 217 | #ifdef FFI_TARGET_SPECIFIC_VARIADIC 218 | if (isvariadic) 219 | return ffi_prep_cif_machdep_var(cif, nfixedargs, ntotalargs); 220 | #endif 221 | 222 | return ffi_prep_cif_machdep(cif); 223 | } 224 | #endif /* not __CRIS__ */ 225 | 226 | ffi_status ffi_prep_cif(ffi_cif *cif, ffi_abi abi, unsigned int nargs, 227 | ffi_type *rtype, ffi_type **atypes) 228 | { 229 | return ffi_prep_cif_core(cif, abi, 0, nargs, nargs, rtype, atypes); 230 | } 231 | 232 | ffi_status ffi_prep_cif_var(ffi_cif *cif, 233 | ffi_abi abi, 234 | unsigned int nfixedargs, 235 | unsigned int ntotalargs, 236 | ffi_type *rtype, 237 | ffi_type **atypes) 238 | { 239 | return ffi_prep_cif_core(cif, abi, 1, nfixedargs, ntotalargs, rtype, atypes); 240 | } 241 | 242 | #if FFI_CLOSURES 243 | 244 | ffi_status 245 | ffi_prep_closure (ffi_closure* closure, 246 | ffi_cif* cif, 247 | void (*fun)(ffi_cif*,void*,void**,void*), 248 | void *user_data) 249 | { 250 | return ffi_prep_closure_loc (closure, cif, fun, user_data, closure); 251 | } 252 | 253 | #endif 254 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunction/libffi/src/common/raw_api.c: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- 2 | raw_api.c - Copyright (c) 1999, 2008 Red Hat, Inc. 3 | 4 | Author: Kresten Krab Thorup 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining 7 | a copy of this software and associated documentation files (the 8 | ``Software''), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, 18 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 24 | DEALINGS IN THE SOFTWARE. 25 | ----------------------------------------------------------------------- */ 26 | 27 | /* This file defines generic functions for use with the raw api. */ 28 | 29 | #include "ffi.h" 30 | #include "ffi_common.h" 31 | 32 | #if !FFI_NO_RAW_API 33 | 34 | size_t 35 | ffi_raw_size (ffi_cif *cif) 36 | { 37 | size_t result = 0; 38 | int i; 39 | 40 | ffi_type **at = cif->arg_types; 41 | 42 | for (i = cif->nargs-1; i >= 0; i--, at++) 43 | { 44 | #if !FFI_NO_STRUCTS 45 | if ((*at)->type == FFI_TYPE_STRUCT) 46 | result += ALIGN (sizeof (void*), FFI_SIZEOF_ARG); 47 | else 48 | #endif 49 | result += ALIGN ((*at)->size, FFI_SIZEOF_ARG); 50 | } 51 | 52 | return result; 53 | } 54 | 55 | 56 | void 57 | ffi_raw_to_ptrarray (ffi_cif *cif, ffi_raw *raw, void **args) 58 | { 59 | unsigned i; 60 | ffi_type **tp = cif->arg_types; 61 | 62 | #if WORDS_BIGENDIAN 63 | 64 | for (i = 0; i < cif->nargs; i++, tp++, args++) 65 | { 66 | switch ((*tp)->type) 67 | { 68 | case FFI_TYPE_UINT8: 69 | case FFI_TYPE_SINT8: 70 | *args = (void*) ((char*)(raw++) + FFI_SIZEOF_ARG - 1); 71 | break; 72 | 73 | case FFI_TYPE_UINT16: 74 | case FFI_TYPE_SINT16: 75 | *args = (void*) ((char*)(raw++) + FFI_SIZEOF_ARG - 2); 76 | break; 77 | 78 | #if FFI_SIZEOF_ARG >= 4 79 | case FFI_TYPE_UINT32: 80 | case FFI_TYPE_SINT32: 81 | *args = (void*) ((char*)(raw++) + FFI_SIZEOF_ARG - 4); 82 | break; 83 | #endif 84 | 85 | #if !FFI_NO_STRUCTS 86 | case FFI_TYPE_STRUCT: 87 | *args = (raw++)->ptr; 88 | break; 89 | #endif 90 | 91 | case FFI_TYPE_COMPLEX: 92 | *args = (raw++)->ptr; 93 | break; 94 | 95 | case FFI_TYPE_POINTER: 96 | *args = (void*) &(raw++)->ptr; 97 | break; 98 | 99 | default: 100 | *args = raw; 101 | raw += ALIGN ((*tp)->size, FFI_SIZEOF_ARG) / FFI_SIZEOF_ARG; 102 | } 103 | } 104 | 105 | #else /* WORDS_BIGENDIAN */ 106 | 107 | #if !PDP 108 | 109 | /* then assume little endian */ 110 | for (i = 0; i < cif->nargs; i++, tp++, args++) 111 | { 112 | #if !FFI_NO_STRUCTS 113 | if ((*tp)->type == FFI_TYPE_STRUCT) 114 | { 115 | *args = (raw++)->ptr; 116 | } 117 | else 118 | #endif 119 | if ((*tp)->type == FFI_TYPE_COMPLEX) 120 | { 121 | *args = (raw++)->ptr; 122 | } 123 | else 124 | { 125 | *args = (void*) raw; 126 | raw += ALIGN ((*tp)->size, sizeof (void*)) / sizeof (void*); 127 | } 128 | } 129 | 130 | #else 131 | #error "pdp endian not supported" 132 | #endif /* ! PDP */ 133 | 134 | #endif /* WORDS_BIGENDIAN */ 135 | } 136 | 137 | void 138 | ffi_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_raw *raw) 139 | { 140 | unsigned i; 141 | ffi_type **tp = cif->arg_types; 142 | 143 | for (i = 0; i < cif->nargs; i++, tp++, args++) 144 | { 145 | switch ((*tp)->type) 146 | { 147 | case FFI_TYPE_UINT8: 148 | (raw++)->uint = *(UINT8*) (*args); 149 | break; 150 | 151 | case FFI_TYPE_SINT8: 152 | (raw++)->sint = *(SINT8*) (*args); 153 | break; 154 | 155 | case FFI_TYPE_UINT16: 156 | (raw++)->uint = *(UINT16*) (*args); 157 | break; 158 | 159 | case FFI_TYPE_SINT16: 160 | (raw++)->sint = *(SINT16*) (*args); 161 | break; 162 | 163 | #if FFI_SIZEOF_ARG >= 4 164 | case FFI_TYPE_UINT32: 165 | (raw++)->uint = *(UINT32*) (*args); 166 | break; 167 | 168 | case FFI_TYPE_SINT32: 169 | (raw++)->sint = *(SINT32*) (*args); 170 | break; 171 | #endif 172 | 173 | #if !FFI_NO_STRUCTS 174 | case FFI_TYPE_STRUCT: 175 | (raw++)->ptr = *args; 176 | break; 177 | #endif 178 | 179 | case FFI_TYPE_COMPLEX: 180 | (raw++)->ptr = *args; 181 | break; 182 | 183 | case FFI_TYPE_POINTER: 184 | (raw++)->ptr = **(void***) args; 185 | break; 186 | 187 | default: 188 | memcpy ((void*) raw->data, (void*)*args, (*tp)->size); 189 | raw += ALIGN ((*tp)->size, FFI_SIZEOF_ARG) / FFI_SIZEOF_ARG; 190 | } 191 | } 192 | } 193 | 194 | #if !FFI_NATIVE_RAW_API 195 | 196 | 197 | /* This is a generic definition of ffi_raw_call, to be used if the 198 | * native system does not provide a machine-specific implementation. 199 | * Having this, allows code to be written for the raw API, without 200 | * the need for system-specific code to handle input in that format; 201 | * these following couple of functions will handle the translation forth 202 | * and back automatically. */ 203 | 204 | void ffi_raw_call (ffi_cif *cif, void (*fn)(void), void *rvalue, ffi_raw *raw) 205 | { 206 | void **avalue = (void**) alloca (cif->nargs * sizeof (void*)); 207 | ffi_raw_to_ptrarray (cif, raw, avalue); 208 | ffi_call (cif, fn, rvalue, avalue); 209 | } 210 | 211 | #if FFI_CLOSURES /* base system provides closures */ 212 | 213 | static void 214 | ffi_translate_args (ffi_cif *cif, void *rvalue, 215 | void **avalue, void *user_data) 216 | { 217 | ffi_raw *raw = (ffi_raw*)alloca (ffi_raw_size (cif)); 218 | ffi_raw_closure *cl = (ffi_raw_closure*)user_data; 219 | 220 | ffi_ptrarray_to_raw (cif, avalue, raw); 221 | (*cl->fun) (cif, rvalue, raw, cl->user_data); 222 | } 223 | 224 | ffi_status 225 | ffi_prep_raw_closure_loc (ffi_raw_closure* cl, 226 | ffi_cif *cif, 227 | void (*fun)(ffi_cif*,void*,ffi_raw*,void*), 228 | void *user_data, 229 | void *codeloc) 230 | { 231 | ffi_status status; 232 | 233 | status = ffi_prep_closure_loc ((ffi_closure*) cl, 234 | cif, 235 | &ffi_translate_args, 236 | codeloc, 237 | codeloc); 238 | if (status == FFI_OK) 239 | { 240 | cl->fun = fun; 241 | cl->user_data = user_data; 242 | } 243 | 244 | return status; 245 | } 246 | 247 | #endif /* FFI_CLOSURES */ 248 | #endif /* !FFI_NATIVE_RAW_API */ 249 | 250 | #if FFI_CLOSURES 251 | 252 | /* Again, here is the generic version of ffi_prep_raw_closure, which 253 | * will install an intermediate "hub" for translation of arguments from 254 | * the pointer-array format, to the raw format */ 255 | 256 | ffi_status 257 | ffi_prep_raw_closure (ffi_raw_closure* cl, 258 | ffi_cif *cif, 259 | void (*fun)(ffi_cif*,void*,ffi_raw*,void*), 260 | void *user_data) 261 | { 262 | return ffi_prep_raw_closure_loc (cl, cif, fun, user_data, cl); 263 | } 264 | 265 | #endif /* FFI_CLOSURES */ 266 | 267 | #endif /* !FFI_NO_RAW_API */ 268 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunction/libffi/src/common/types.c: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- 2 | types.c - Copyright (c) 1996, 1998 Red Hat, Inc. 3 | 4 | Predefined ffi_types needed by libffi. 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining 7 | a copy of this software and associated documentation files (the 8 | ``Software''), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, 18 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 24 | DEALINGS IN THE SOFTWARE. 25 | ----------------------------------------------------------------------- */ 26 | 27 | /* Hide the basic type definitions from the header file, so that we 28 | can redefine them here as "const". */ 29 | #define LIBFFI_HIDE_BASIC_TYPES 30 | 31 | #include "ffi.h" 32 | #include "ffi_common.h" 33 | 34 | /* Type definitions */ 35 | 36 | #define FFI_TYPEDEF(name, type, id, maybe_const)\ 37 | struct struct_align_##name { \ 38 | char c; \ 39 | type x; \ 40 | }; \ 41 | maybe_const ffi_type ffi_type_##name = { \ 42 | sizeof(type), \ 43 | offsetof(struct struct_align_##name, x), \ 44 | id, NULL \ 45 | } 46 | 47 | #define FFI_COMPLEX_TYPEDEF(name, type, maybe_const) \ 48 | static ffi_type *ffi_elements_complex_##name [2] = { \ 49 | (ffi_type *)(&ffi_type_##name), NULL \ 50 | }; \ 51 | struct struct_align_complex_##name { \ 52 | char c; \ 53 | _Complex type x; \ 54 | }; \ 55 | maybe_const ffi_type ffi_type_complex_##name = { \ 56 | sizeof(_Complex type), \ 57 | offsetof(struct struct_align_complex_##name, x), \ 58 | FFI_TYPE_COMPLEX, \ 59 | (ffi_type **)ffi_elements_complex_##name \ 60 | } 61 | 62 | /* Size and alignment are fake here. They must not be 0. */ 63 | const ffi_type ffi_type_void = { 64 | 1, 1, FFI_TYPE_VOID, NULL 65 | }; 66 | 67 | FFI_TYPEDEF(uint8, UINT8, FFI_TYPE_UINT8, const); 68 | FFI_TYPEDEF(sint8, SINT8, FFI_TYPE_SINT8, const); 69 | FFI_TYPEDEF(uint16, UINT16, FFI_TYPE_UINT16, const); 70 | FFI_TYPEDEF(sint16, SINT16, FFI_TYPE_SINT16, const); 71 | FFI_TYPEDEF(uint32, UINT32, FFI_TYPE_UINT32, const); 72 | FFI_TYPEDEF(sint32, SINT32, FFI_TYPE_SINT32, const); 73 | FFI_TYPEDEF(uint64, UINT64, FFI_TYPE_UINT64, const); 74 | FFI_TYPEDEF(sint64, SINT64, FFI_TYPE_SINT64, const); 75 | 76 | FFI_TYPEDEF(pointer, void*, FFI_TYPE_POINTER, const); 77 | 78 | FFI_TYPEDEF(float, float, FFI_TYPE_FLOAT, const); 79 | FFI_TYPEDEF(double, double, FFI_TYPE_DOUBLE, const); 80 | 81 | #if !defined HAVE_LONG_DOUBLE_VARIANT || defined __alpha__ 82 | #define FFI_LDBL_CONST const 83 | #else 84 | #define FFI_LDBL_CONST 85 | #endif 86 | 87 | #ifdef __alpha__ 88 | /* Even if we're not configured to default to 128-bit long double, 89 | maintain binary compatibility, as -mlong-double-128 can be used 90 | at any time. */ 91 | /* Validate the hard-coded number below. */ 92 | # if defined(__LONG_DOUBLE_128__) && FFI_TYPE_LONGDOUBLE != 4 93 | # error FFI_TYPE_LONGDOUBLE out of date 94 | # endif 95 | const ffi_type ffi_type_longdouble = { 16, 16, 4, NULL }; 96 | #elif FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE 97 | FFI_TYPEDEF(longdouble, long double, FFI_TYPE_LONGDOUBLE, FFI_LDBL_CONST); 98 | #endif 99 | 100 | #ifdef FFI_TARGET_HAS_COMPLEX_TYPE 101 | FFI_COMPLEX_TYPEDEF(float, float, const); 102 | FFI_COMPLEX_TYPEDEF(double, double, const); 103 | #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE 104 | FFI_COMPLEX_TYPEDEF(longdouble, long double, FFI_LDBL_CONST); 105 | #endif 106 | #endif 107 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunction/libffi/src/x86/darwin_i386.S: -------------------------------------------------------------------------------- 1 | #ifdef __i386__ 2 | 3 | /* ----------------------------------------------------------------------- 4 | darwin.S - Copyright (c) 1996, 1998, 2001, 2002, 2003, 2005 Red Hat, Inc. 5 | Copyright (C) 2008 Free Software Foundation, Inc. 6 | 7 | X86 Foreign Function Interface 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining 10 | a copy of this software and associated documentation files (the 11 | ``Software''), to deal in the Software without restriction, including 12 | without limitation the rights to use, copy, modify, merge, publish, 13 | distribute, sublicense, and/or sell copies of the Software, and to 14 | permit persons to whom the Software is furnished to do so, subject to 15 | the following conditions: 16 | 17 | The above copyright notice and this permission notice shall be included 18 | in all copies or substantial portions of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, 21 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | DEALINGS IN THE SOFTWARE. 28 | ----------------------------------------------------------------------- 29 | */ 30 | 31 | #ifndef __x86_64__ 32 | 33 | #define LIBFFI_ASM 34 | #include "fficonfig.h" 35 | #include "ffi.h" 36 | 37 | .text 38 | 39 | .globl _ffi_prep_args 40 | 41 | .align 4 42 | .globl _ffi_call_SYSV 43 | 44 | _ffi_call_SYSV: 45 | .LFB1: 46 | pushl %ebp 47 | .LCFI0: 48 | movl %esp,%ebp 49 | .LCFI1: 50 | subl $8,%esp 51 | /* Make room for all of the new args. */ 52 | movl 16(%ebp),%ecx 53 | subl %ecx,%esp 54 | 55 | movl %esp,%eax 56 | 57 | /* Place all of the ffi_prep_args in position */ 58 | subl $8,%esp 59 | pushl 12(%ebp) 60 | pushl %eax 61 | call *8(%ebp) 62 | 63 | /* Return stack to previous state and call the function */ 64 | addl $16,%esp 65 | 66 | call *28(%ebp) 67 | 68 | /* Load %ecx with the return type code */ 69 | movl 20(%ebp),%ecx 70 | 71 | /* Protect %esi. We're going to pop it in the epilogue. */ 72 | pushl %esi 73 | 74 | /* If the return value pointer is NULL, assume no return value. */ 75 | cmpl $0,24(%ebp) 76 | jne 0f 77 | 78 | /* Even if there is no space for the return value, we are 79 | obliged to handle floating-point values. */ 80 | cmpl $FFI_TYPE_FLOAT,%ecx 81 | jne noretval 82 | fstp %st(0) 83 | 84 | jmp epilogue 85 | 0: 86 | .align 4 87 | call 1f 88 | .Lstore_table: 89 | .long noretval-.Lstore_table /* FFI_TYPE_VOID */ 90 | .long retint-.Lstore_table /* FFI_TYPE_INT */ 91 | .long retfloat-.Lstore_table /* FFI_TYPE_FLOAT */ 92 | .long retdouble-.Lstore_table /* FFI_TYPE_DOUBLE */ 93 | .long retlongdouble-.Lstore_table /* FFI_TYPE_LONGDOUBLE */ 94 | .long retuint8-.Lstore_table /* FFI_TYPE_UINT8 */ 95 | .long retsint8-.Lstore_table /* FFI_TYPE_SINT8 */ 96 | .long retuint16-.Lstore_table /* FFI_TYPE_UINT16 */ 97 | .long retsint16-.Lstore_table /* FFI_TYPE_SINT16 */ 98 | .long retint-.Lstore_table /* FFI_TYPE_UINT32 */ 99 | .long retint-.Lstore_table /* FFI_TYPE_SINT32 */ 100 | .long retint64-.Lstore_table /* FFI_TYPE_UINT64 */ 101 | .long retint64-.Lstore_table /* FFI_TYPE_SINT64 */ 102 | .long retstruct-.Lstore_table /* FFI_TYPE_STRUCT */ 103 | .long retint-.Lstore_table /* FFI_TYPE_POINTER */ 104 | .long retstruct1b-.Lstore_table /* FFI_TYPE_SMALL_STRUCT_1B */ 105 | .long retstruct2b-.Lstore_table /* FFI_TYPE_SMALL_STRUCT_2B */ 106 | 1: 107 | pop %esi 108 | add (%esi, %ecx, 4), %esi 109 | jmp *%esi 110 | 111 | /* Sign/zero extend as appropriate. */ 112 | retsint8: 113 | movsbl %al, %eax 114 | jmp retint 115 | 116 | retsint16: 117 | movswl %ax, %eax 118 | jmp retint 119 | 120 | retuint8: 121 | movzbl %al, %eax 122 | jmp retint 123 | 124 | retuint16: 125 | movzwl %ax, %eax 126 | jmp retint 127 | 128 | retfloat: 129 | /* Load %ecx with the pointer to storage for the return value */ 130 | movl 24(%ebp),%ecx 131 | fstps (%ecx) 132 | jmp epilogue 133 | 134 | retdouble: 135 | /* Load %ecx with the pointer to storage for the return value */ 136 | movl 24(%ebp),%ecx 137 | fstpl (%ecx) 138 | jmp epilogue 139 | 140 | retlongdouble: 141 | /* Load %ecx with the pointer to storage for the return value */ 142 | movl 24(%ebp),%ecx 143 | fstpt (%ecx) 144 | jmp epilogue 145 | 146 | retint64: 147 | /* Load %ecx with the pointer to storage for the return value */ 148 | movl 24(%ebp),%ecx 149 | movl %eax,0(%ecx) 150 | movl %edx,4(%ecx) 151 | jmp epilogue 152 | 153 | retstruct1b: 154 | /* Load %ecx with the pointer to storage for the return value */ 155 | movl 24(%ebp),%ecx 156 | movb %al,0(%ecx) 157 | jmp epilogue 158 | 159 | retstruct2b: 160 | /* Load %ecx with the pointer to storage for the return value */ 161 | movl 24(%ebp),%ecx 162 | movw %ax,0(%ecx) 163 | jmp epilogue 164 | 165 | retint: 166 | /* Load %ecx with the pointer to storage for the return value */ 167 | movl 24(%ebp),%ecx 168 | movl %eax,0(%ecx) 169 | 170 | retstruct: 171 | /* Nothing to do! */ 172 | 173 | noretval: 174 | epilogue: 175 | popl %esi 176 | movl %ebp,%esp 177 | popl %ebp 178 | ret 179 | 180 | .LFE1: 181 | .ffi_call_SYSV_end: 182 | 183 | .align 4 184 | FFI_HIDDEN (ffi_closure_SYSV) 185 | .globl _ffi_closure_SYSV 186 | 187 | _ffi_closure_SYSV: 188 | .LFB2: 189 | pushl %ebp 190 | .LCFI2: 191 | movl %esp, %ebp 192 | .LCFI3: 193 | subl $40, %esp 194 | leal -24(%ebp), %edx 195 | movl %edx, -12(%ebp) /* resp */ 196 | leal 8(%ebp), %edx 197 | movl %edx, 4(%esp) /* args = __builtin_dwarf_cfa () */ 198 | leal -12(%ebp), %edx 199 | movl %edx, (%esp) /* &resp */ 200 | movl %ebx, 8(%esp) 201 | .LCFI7: 202 | call L_ffi_closure_SYSV_inner$stub 203 | movl 8(%esp), %ebx 204 | movl -12(%ebp), %ecx 205 | cmpl $FFI_TYPE_INT, %eax 206 | je .Lcls_retint 207 | 208 | /* Handle FFI_TYPE_UINT8, FFI_TYPE_SINT8, FFI_TYPE_UINT16, 209 | FFI_TYPE_SINT16, FFI_TYPE_UINT32, FFI_TYPE_SINT32. */ 210 | cmpl $FFI_TYPE_UINT64, %eax 211 | jge 0f 212 | cmpl $FFI_TYPE_UINT8, %eax 213 | jge .Lcls_retint 214 | 215 | 0: cmpl $FFI_TYPE_FLOAT, %eax 216 | je .Lcls_retfloat 217 | cmpl $FFI_TYPE_DOUBLE, %eax 218 | je .Lcls_retdouble 219 | cmpl $FFI_TYPE_LONGDOUBLE, %eax 220 | je .Lcls_retldouble 221 | cmpl $FFI_TYPE_SINT64, %eax 222 | je .Lcls_retllong 223 | cmpl $FFI_TYPE_SMALL_STRUCT_1B, %eax 224 | je .Lcls_retstruct1b 225 | cmpl $FFI_TYPE_SMALL_STRUCT_2B, %eax 226 | je .Lcls_retstruct2b 227 | cmpl $FFI_TYPE_STRUCT, %eax 228 | je .Lcls_retstruct 229 | .Lcls_epilogue: 230 | movl %ebp, %esp 231 | popl %ebp 232 | ret 233 | .Lcls_retint: 234 | movl (%ecx), %eax 235 | jmp .Lcls_epilogue 236 | .Lcls_retfloat: 237 | flds (%ecx) 238 | jmp .Lcls_epilogue 239 | .Lcls_retdouble: 240 | fldl (%ecx) 241 | jmp .Lcls_epilogue 242 | .Lcls_retldouble: 243 | fldt (%ecx) 244 | jmp .Lcls_epilogue 245 | .Lcls_retllong: 246 | movl (%ecx), %eax 247 | movl 4(%ecx), %edx 248 | jmp .Lcls_epilogue 249 | .Lcls_retstruct1b: 250 | movsbl (%ecx), %eax 251 | jmp .Lcls_epilogue 252 | .Lcls_retstruct2b: 253 | movswl (%ecx), %eax 254 | jmp .Lcls_epilogue 255 | .Lcls_retstruct: 256 | lea -8(%ebp),%esp 257 | movl %ebp, %esp 258 | popl %ebp 259 | ret $4 260 | .LFE2: 261 | 262 | #if !FFI_NO_RAW_API 263 | 264 | #define RAW_CLOSURE_CIF_OFFSET ((FFI_TRAMPOLINE_SIZE + 3) & ~3) 265 | #define RAW_CLOSURE_FUN_OFFSET (RAW_CLOSURE_CIF_OFFSET + 4) 266 | #define RAW_CLOSURE_USER_DATA_OFFSET (RAW_CLOSURE_FUN_OFFSET + 4) 267 | #define CIF_FLAGS_OFFSET 20 268 | 269 | .align 4 270 | FFI_HIDDEN (ffi_closure_raw_SYSV) 271 | .globl _ffi_closure_raw_SYSV 272 | 273 | _ffi_closure_raw_SYSV: 274 | .LFB3: 275 | pushl %ebp 276 | .LCFI4: 277 | movl %esp, %ebp 278 | .LCFI5: 279 | pushl %esi 280 | .LCFI6: 281 | subl $36, %esp 282 | movl RAW_CLOSURE_CIF_OFFSET(%eax), %esi /* closure->cif */ 283 | movl RAW_CLOSURE_USER_DATA_OFFSET(%eax), %edx /* closure->user_data */ 284 | movl %edx, 12(%esp) /* user_data */ 285 | leal 8(%ebp), %edx /* __builtin_dwarf_cfa () */ 286 | movl %edx, 8(%esp) /* raw_args */ 287 | leal -24(%ebp), %edx 288 | movl %edx, 4(%esp) /* &res */ 289 | movl %esi, (%esp) /* cif */ 290 | call *RAW_CLOSURE_FUN_OFFSET(%eax) /* closure->fun */ 291 | movl CIF_FLAGS_OFFSET(%esi), %eax /* rtype */ 292 | cmpl $FFI_TYPE_INT, %eax 293 | je .Lrcls_retint 294 | 295 | /* Handle FFI_TYPE_UINT8, FFI_TYPE_SINT8, FFI_TYPE_UINT16, 296 | FFI_TYPE_SINT16, FFI_TYPE_UINT32, FFI_TYPE_SINT32. */ 297 | cmpl $FFI_TYPE_UINT64, %eax 298 | jge 0f 299 | cmpl $FFI_TYPE_UINT8, %eax 300 | jge .Lrcls_retint 301 | 0: 302 | cmpl $FFI_TYPE_FLOAT, %eax 303 | je .Lrcls_retfloat 304 | cmpl $FFI_TYPE_DOUBLE, %eax 305 | je .Lrcls_retdouble 306 | cmpl $FFI_TYPE_LONGDOUBLE, %eax 307 | je .Lrcls_retldouble 308 | cmpl $FFI_TYPE_SINT64, %eax 309 | je .Lrcls_retllong 310 | .Lrcls_epilogue: 311 | addl $36, %esp 312 | popl %esi 313 | popl %ebp 314 | ret 315 | .Lrcls_retint: 316 | movl -24(%ebp), %eax 317 | jmp .Lrcls_epilogue 318 | .Lrcls_retfloat: 319 | flds -24(%ebp) 320 | jmp .Lrcls_epilogue 321 | .Lrcls_retdouble: 322 | fldl -24(%ebp) 323 | jmp .Lrcls_epilogue 324 | .Lrcls_retldouble: 325 | fldt -24(%ebp) 326 | jmp .Lrcls_epilogue 327 | .Lrcls_retllong: 328 | movl -24(%ebp), %eax 329 | movl -20(%ebp), %edx 330 | jmp .Lrcls_epilogue 331 | .LFE3: 332 | #endif 333 | 334 | .section __IMPORT,__jump_table,symbol_stubs,self_modifying_code+pure_instructions,5 335 | L_ffi_closure_SYSV_inner$stub: 336 | .indirect_symbol _ffi_closure_SYSV_inner 337 | hlt ; hlt ; hlt ; hlt ; hlt 338 | 339 | 340 | .section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support 341 | EH_frame1: 342 | .set L$set$0,LECIE1-LSCIE1 343 | .long L$set$0 344 | LSCIE1: 345 | .long 0x0 346 | .byte 0x1 347 | .ascii "zR\0" 348 | .byte 0x1 349 | .byte 0x7c 350 | .byte 0x8 351 | .byte 0x1 352 | .byte 0x10 353 | .byte 0xc 354 | .byte 0x5 355 | .byte 0x4 356 | .byte 0x88 357 | .byte 0x1 358 | .align 2 359 | LECIE1: 360 | .globl _ffi_call_SYSV.eh 361 | _ffi_call_SYSV.eh: 362 | LSFDE1: 363 | .set L$set$1,LEFDE1-LASFDE1 364 | .long L$set$1 365 | LASFDE1: 366 | .long LASFDE1-EH_frame1 367 | .long .LFB1-. 368 | .set L$set$2,.LFE1-.LFB1 369 | .long L$set$2 370 | .byte 0x0 371 | .byte 0x4 372 | .set L$set$3,.LCFI0-.LFB1 373 | .long L$set$3 374 | .byte 0xe 375 | .byte 0x8 376 | .byte 0x84 377 | .byte 0x2 378 | .byte 0x4 379 | .set L$set$4,.LCFI1-.LCFI0 380 | .long L$set$4 381 | .byte 0xd 382 | .byte 0x4 383 | .align 2 384 | LEFDE1: 385 | .globl _ffi_closure_SYSV.eh 386 | _ffi_closure_SYSV.eh: 387 | LSFDE2: 388 | .set L$set$5,LEFDE2-LASFDE2 389 | .long L$set$5 390 | LASFDE2: 391 | .long LASFDE2-EH_frame1 392 | .long .LFB2-. 393 | .set L$set$6,.LFE2-.LFB2 394 | .long L$set$6 395 | .byte 0x0 396 | .byte 0x4 397 | .set L$set$7,.LCFI2-.LFB2 398 | .long L$set$7 399 | .byte 0xe 400 | .byte 0x8 401 | .byte 0x84 402 | .byte 0x2 403 | .byte 0x4 404 | .set L$set$8,.LCFI3-.LCFI2 405 | .long L$set$8 406 | .byte 0xd 407 | .byte 0x4 408 | .align 2 409 | LEFDE2: 410 | 411 | #if !FFI_NO_RAW_API 412 | 413 | .globl _ffi_closure_raw_SYSV.eh 414 | _ffi_closure_raw_SYSV.eh: 415 | LSFDE3: 416 | .set L$set$10,LEFDE3-LASFDE3 417 | .long L$set$10 418 | LASFDE3: 419 | .long LASFDE3-EH_frame1 420 | .long .LFB3-. 421 | .set L$set$11,.LFE3-.LFB3 422 | .long L$set$11 423 | .byte 0x0 424 | .byte 0x4 425 | .set L$set$12,.LCFI4-.LFB3 426 | .long L$set$12 427 | .byte 0xe 428 | .byte 0x8 429 | .byte 0x84 430 | .byte 0x2 431 | .byte 0x4 432 | .set L$set$13,.LCFI5-.LCFI4 433 | .long L$set$13 434 | .byte 0xd 435 | .byte 0x4 436 | .byte 0x4 437 | .set L$set$14,.LCFI6-.LCFI5 438 | .long L$set$14 439 | .byte 0x85 440 | .byte 0x3 441 | .align 2 442 | LEFDE3: 443 | 444 | #endif 445 | 446 | #endif /* ifndef __x86_64__ */ 447 | 448 | 449 | #endif -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunctionBinder/CoreGraphics/JPCGBitmapContext.h: -------------------------------------------------------------------------------- 1 | // 2 | // JPCGBitmapContext.h 3 | // JSPatchDemo 4 | // 5 | // Created by Albert438 on 15/7/3. 6 | // Copyright (c) 2015年 bang. All rights reserved. 7 | // 8 | 9 | #import "JPEngine.h" 10 | 11 | @interface JPCGBitmapContext : JPExtension 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunctionBinder/CoreGraphics/JPCGBitmapContext.m: -------------------------------------------------------------------------------- 1 | // 2 | // JPCGBitmapContext.m 3 | // JSPatchDemo 4 | // 5 | // Created by Albert438 on 15/7/3. 6 | // Copyright (c) 2015年 bang. All rights reserved. 7 | // 8 | 9 | #import "JPCGBitmapContext.h" 10 | #import 11 | 12 | @implementation JPCGBitmapContext 13 | 14 | + (void)main:(JSContext *)context 15 | { 16 | context[@"CGBitmapContextCreate"] = ^id(JSValue *data, size_t width, 17 | size_t height, size_t bitsPerComponent, size_t bytesPerRow, 18 | JSValue *space, uint32_t bitmapInfo) { 19 | CGContextRef bitmapContext = CGBitmapContextCreate([self formatPointerJSToOC:data], width, height, bitsPerComponent, bytesPerRow, [self formatPointerJSToOC:space], bitmapInfo); 20 | return [self formatRetainedCFTypeOCToJS:bitmapContext]; 21 | }; 22 | 23 | context[@"CGBitmapContextCreateImage"] = ^id(JSValue *c) { 24 | CGImageRef image = CGBitmapContextCreateImage([self formatPointerJSToOC:c]); 25 | return [self formatRetainedCFTypeOCToJS:image]; 26 | }; 27 | 28 | context[@"CGBitmapContextGetBytesPerRow"] = ^size_t(JSValue *c) { 29 | return CGBitmapContextGetBytesPerRow([self formatPointerJSToOC:c]); 30 | }; 31 | 32 | context[@"CGBitmapContextGetData"] = ^id(JSValue *c) { 33 | return [self formatPointerJSToOC:CGBitmapContextGetData([self formatPointerJSToOC:c])]; 34 | }; 35 | 36 | context[@"CGBitmapContextGetHeight"] = ^size_t(JSValue *c) { 37 | return CGBitmapContextGetHeight([self formatPointerJSToOC:c]); 38 | }; 39 | 40 | context[@"CGBitmapContextGetWidth"] = ^size_t(JSValue *c) { 41 | return CGBitmapContextGetWidth([self formatPointerJSToOC:c]); 42 | }; 43 | 44 | context[@"CGImageRelease"] = ^void(JSValue *image) { 45 | CGImageRelease([self formatPointerJSToOC:image]); 46 | }; 47 | } 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunctionBinder/CoreGraphics/JPCGColor.h: -------------------------------------------------------------------------------- 1 | // 2 | // JPCGColor.h 3 | // JSPatchDemo 4 | // 5 | // Created by Albert438 on 15/7/3. 6 | // Copyright (c) 2015年 bang. All rights reserved. 7 | // 8 | 9 | #import "JPEngine.h" 10 | 11 | @interface JPCGColor : JPExtension 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunctionBinder/CoreGraphics/JPCGColor.m: -------------------------------------------------------------------------------- 1 | // 2 | // JPCGColor.m 3 | // JSPatchDemo 4 | // 5 | // Created by Albert438 on 15/7/3. 6 | // Copyright (c) 2015年 bang. All rights reserved. 7 | // 8 | 9 | #import "JPCGColor.h" 10 | #import 11 | 12 | @implementation JPCGColor 13 | 14 | + (void)main:(JSContext *)context 15 | { 16 | context[@"CGColorCreate"] = ^id(JSValue *space, 17 | NSArray *componentsArray) { 18 | CGFloat *components = malloc(componentsArray.count * sizeof(CGFloat)); 19 | for (int i = 0; i < componentsArray.count; i++) { 20 | components[i] = [componentsArray[i] doubleValue]; 21 | } 22 | CGColorRef color = CGColorCreate([self formatPointerJSToOC:space], components); 23 | free(components); 24 | return [self formatRetainedCFTypeOCToJS:color]; 25 | }; 26 | 27 | context[@"CGColorEqualToColor"] = ^BOOL(JSValue *color1, JSValue *color2) { 28 | return CGColorEqualToColor([self formatPointerJSToOC:color1], [self formatPointerJSToOC:color2]); 29 | }; 30 | 31 | context[@"CGColorGetColorSpace"] = ^id(JSValue *color) { 32 | CGColorSpaceRef space = CGColorGetColorSpace([self formatPointerJSToOC:color]); 33 | return [self formatPointerOCToJS:space]; 34 | }; 35 | 36 | context[@"CGColorGetComponents"] = ^NSArray *(JSValue *color) { 37 | size_t numberOfComponents = CGColorGetNumberOfComponents([self formatPointerJSToOC:color]); 38 | const CGFloat *componets = CGColorGetComponents([self formatPointerJSToOC:color]); 39 | NSMutableArray *componentsArray = [NSMutableArray array]; 40 | for (int i = 0 ; i < numberOfComponents ; i++) { 41 | [componentsArray addObject:[NSNumber numberWithDouble:componets[i]]]; 42 | } 43 | return componentsArray; 44 | }; 45 | 46 | context[@"CGColorGetNumberOfComponents"] = ^size_t(JSValue *color) { 47 | return CGColorGetNumberOfComponents([self formatPointerJSToOC:color]); 48 | }; 49 | 50 | context[@"CGColorRelease"] = ^void(JSValue *color){ 51 | CGColorRelease([self formatPointerJSToOC:color]); 52 | }; 53 | 54 | context[@"CGColorSpaceCreateDeviceGray"] = ^id() { 55 | return [self formatRetainedCFTypeOCToJS:CGColorSpaceCreateDeviceGray()]; 56 | }; 57 | 58 | context[@"CGColorSpaceCreateDeviceRGB"] = ^id() { 59 | return [self formatRetainedCFTypeOCToJS:CGColorSpaceCreateDeviceRGB()]; 60 | }; 61 | 62 | context[@"CGColorSpaceCreateDeviceCMYK"] = ^id() { 63 | return [self formatRetainedCFTypeOCToJS:CGColorSpaceCreateDeviceCMYK()]; 64 | }; 65 | 66 | context[@"CGColorSpaceCreatePattern"] = ^id(JSValue *baseSpace) { 67 | return [self formatRetainedCFTypeOCToJS:CGColorSpaceCreatePattern([self formatPointerJSToOC:baseSpace])]; 68 | }; 69 | 70 | context[@"CGColorSpaceGetModel"] = ^NSInteger(JSValue *space) { 71 | NSInteger model = CGColorSpaceGetModel([self formatPointerJSToOC:space]); 72 | return model; 73 | }; 74 | 75 | context[@"CGColorSpaceRelease"] = ^void(JSValue *space) { 76 | CGColorSpaceRelease([self formatPointerJSToOC:space]); 77 | }; 78 | } 79 | 80 | @end 81 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunctionBinder/CoreGraphics/JPCGContext.h: -------------------------------------------------------------------------------- 1 | // 2 | // JPCGContext.h 3 | // 4 | // 5 | // Created by Albert438 on 15/7/2. 6 | // Copyright © 2015年 bang. All rights reserved. 7 | // 8 | 9 | #import "JPEngine.h" 10 | 11 | @interface JPCGContext : JPExtension 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunctionBinder/CoreGraphics/JPCGGeometry.h: -------------------------------------------------------------------------------- 1 | // 2 | // JPCGGeometryHelper.h 3 | // JSPatchDemo 4 | // 5 | // Created by Albert438 on 15/7/2. 6 | // Copyright © 2015年 bang. All rights reserved. 7 | // 8 | 9 | #import "JPEngine.h" 10 | 11 | @interface JPCGGeometry : JPExtension 12 | 13 | + (void)rectStruct:(CGRect *)rect ofDict:(NSDictionary *)dict; 14 | 15 | + (void)pointStruct:(CGPoint *)point ofDict:(NSDictionary *)dict; 16 | 17 | + (void)sizeStruct:(CGSize *)size ofDict:(NSDictionary *)dict; 18 | 19 | + (void)vectorStruct:(CGVector *)vector ofDict:(NSDictionary *)dict; 20 | 21 | + (NSDictionary *)rectDictOfStruct:(CGRect *)rect; 22 | 23 | + (NSDictionary *)sizeDictOfStruct:(CGSize *)size; 24 | 25 | + (NSDictionary *)pointDictOfStruct:(CGPoint *)point; 26 | 27 | + (NSDictionary *)vectorDictOfStruct:(CGVector *)vector; 28 | @end 29 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunctionBinder/CoreGraphics/JPCGGeometry.m: -------------------------------------------------------------------------------- 1 | // 2 | // JPCGGeometryHelper.m 3 | // JSPatchDemo 4 | // 5 | // Created by Albert438 on 15/7/2. 6 | // Copyright © 2015年 bang. All rights reserved. 7 | // 8 | 9 | #import "JPCGGeometry.h" 10 | #import 11 | 12 | @implementation JPCGGeometry 13 | 14 | + (void)main:(JSContext *)context 15 | { 16 | [JPEngine defineStruct:@{ 17 | @"name": @"CGVector", 18 | @"types": @"FF", 19 | @"keys": @[@"dx", @"dy"] 20 | }]; 21 | 22 | [JPEngine defineStruct:@{ 23 | @"name": @"CGAffineTransform", 24 | @"types": @"FFFFFF", 25 | @"keys": @[@"a", @"b", @"c", @"d", @"tx", @"ty"] 26 | }]; 27 | 28 | context[@"CGRectContainsPoint"] = ^BOOL(NSDictionary *rectDict, NSDictionary *pointDict) { 29 | CGRect rect; 30 | CGPoint point; 31 | [JPCGGeometry rectStruct:&rect ofDict:rectDict]; 32 | [JPCGGeometry pointStruct:&point ofDict:pointDict]; 33 | return CGRectContainsPoint(rect, point); 34 | }; 35 | 36 | context[@"CGRectEqualToRect"] = ^BOOL(NSDictionary *rectDict1, NSDictionary *rectDict2) { 37 | CGRect rect1,rect2; 38 | [JPCGGeometry rectStruct:&rect1 ofDict:rectDict1]; 39 | [JPCGGeometry rectStruct:&rect2 ofDict:rectDict2]; 40 | return CGRectEqualToRect(rect1, rect2); 41 | }; 42 | 43 | context[@"CGRectGetMaxX"] = ^CGFloat(NSDictionary *rectDict) { 44 | CGRect rect; 45 | [JPCGGeometry rectStruct:&rect ofDict:rectDict]; 46 | return CGRectGetMaxX(rect); 47 | }; 48 | 49 | context[@"CGRectGetMaxY"] = ^CGFloat(NSDictionary *rectDict) { 50 | CGRect rect; 51 | [JPCGGeometry rectStruct:&rect ofDict:rectDict]; 52 | return CGRectGetMaxY(rect); 53 | }; 54 | 55 | context[@"CGRectGetMidX"] = ^CGFloat(NSDictionary *rectDict) { 56 | CGRect rect; 57 | [JPCGGeometry rectStruct:&rect ofDict:rectDict]; 58 | return CGRectGetMidX(rect); 59 | }; 60 | 61 | context[@"CGRectGetMidY"] = ^CGFloat(NSDictionary *rectDict) { 62 | CGRect rect; 63 | [JPCGGeometry rectStruct:&rect ofDict:rectDict]; 64 | return CGRectGetMidY(rect); 65 | }; 66 | 67 | context[@"CGRectGetMinX"] = ^CGFloat(NSDictionary *rectDict) { 68 | CGRect rect; 69 | [JPCGGeometry rectStruct:&rect ofDict:rectDict]; 70 | return CGRectGetMinX(rect); 71 | }; 72 | 73 | context[@"CGRectGetMinY"] = ^CGFloat(NSDictionary *rectDict) { 74 | CGRect rect; 75 | [JPCGGeometry rectStruct:&rect ofDict:rectDict]; 76 | return CGRectGetMinY(rect); 77 | }; 78 | 79 | context[@"CGRectInset"] = ^CGRect(NSDictionary *rectDict, CGFloat dx, CGFloat dy) { 80 | CGRect rect; 81 | [JPCGGeometry rectStruct:&rect ofDict:rectDict]; 82 | CGRect rectInset = CGRectInset(rect, dx, dy); 83 | return rectInset; 84 | }; 85 | 86 | context[@"CGRectIntegral"] = ^CGRect(NSDictionary *rectDict) { 87 | CGRect rect; 88 | [JPCGGeometry rectStruct:&rect ofDict:rectDict]; 89 | CGRect rectIntegral = CGRectIntegral(rect); 90 | return rectIntegral; 91 | }; 92 | 93 | context[@"CGRectIntersection"] = ^CGRect(NSDictionary *rectDict1, NSDictionary *rectDict2) { 94 | CGRect rect1,rect2; 95 | [JPCGGeometry rectStruct:&rect1 ofDict:rectDict1]; 96 | [JPCGGeometry rectStruct:&rect2 ofDict:rectDict2]; 97 | 98 | CGRect rectIntersection = CGRectIntersection(rect1, rect2); 99 | return rectIntersection; 100 | }; 101 | 102 | context[@"CGRectOffset"] = ^CGRect(NSDictionary *rectDict, CGFloat dx, CGFloat dy) { 103 | CGRect rect; 104 | [JPCGGeometry rectStruct:&rect ofDict:rectDict]; 105 | CGRect rectOffset = CGRectOffset(rect, dx, dy); 106 | return rectOffset; 107 | }; 108 | 109 | context[@"CGRectIntersectsRect"] = ^BOOL(NSDictionary *rectDict1, NSDictionary *rectDict2) { 110 | CGRect rect1,rect2; 111 | [JPCGGeometry rectStruct:&rect1 ofDict:rectDict1]; 112 | [JPCGGeometry rectStruct:&rect2 ofDict:rectDict2]; 113 | return CGRectIntersectsRect(rect1, rect2); 114 | }; 115 | } 116 | 117 | #if CGFLOAT_IS_DOUBLE 118 | #define CGFloatValue doubleValue 119 | #else 120 | #define CGFloatValue floatValue 121 | #endif 122 | 123 | + (void)rectStruct:(CGRect *)rect ofDict:(NSDictionary *)dict 124 | { 125 | CGPoint point; 126 | CGSize size; 127 | point.x = [dict[@"x"] CGFloatValue]; 128 | point.y = [dict[@"y"] CGFloatValue]; 129 | size.width = [dict[@"width"] CGFloatValue]; 130 | size.height = [dict[@"height"] CGFloatValue]; 131 | rect->origin = point; 132 | rect->size = size; 133 | 134 | } 135 | 136 | + (void)pointStruct:(CGPoint *)point ofDict:(NSDictionary *)dict 137 | { 138 | point->x = [dict[@"x"] CGFloatValue]; 139 | point->y = [dict[@"y"] CGFloatValue]; 140 | } 141 | 142 | + (void)sizeStruct:(CGSize *)size ofDict:(NSDictionary *)dict 143 | { 144 | size->width = [dict[@"width"] CGFloatValue]; 145 | size->height = [dict[@"height"] CGFloatValue]; 146 | } 147 | 148 | + (void)vectorStruct:(CGVector *)vector ofDict:(NSDictionary *)dict 149 | { 150 | vector->dx = [dict[@"dx"] CGFloatValue]; 151 | vector->dy = [dict[@"dy"] CGFloatValue]; 152 | } 153 | 154 | #undef CGFloatValue 155 | 156 | + (NSDictionary *)rectDictOfStruct:(CGRect *)rect 157 | { 158 | return @{@"x": @(rect->origin.x), @"y": @(rect->origin.y), @"width": @(rect->size.width), @"height": @(rect->size.height)}; 159 | } 160 | 161 | + (NSDictionary *)sizeDictOfStruct:(CGSize *)size 162 | { 163 | return @{@"width": @(size->width), @"height": @(size->height)}; 164 | } 165 | 166 | + (NSDictionary *)pointDictOfStruct:(CGPoint *)point 167 | { 168 | return @{@"x": @(point->x), @"y": @(point->y)}; 169 | } 170 | 171 | + (NSDictionary *)vectorDictOfStruct:(CGVector *)vector 172 | { 173 | return @{@"dx": @(vector->dx), @"dy": @(vector->dy)}; 174 | } 175 | @end 176 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunctionBinder/CoreGraphics/JPCGImage.h: -------------------------------------------------------------------------------- 1 | // 2 | // JPCGImage.h 3 | // JSPatchDemo 4 | // 5 | // Created by Albert438 on 15/7/3. 6 | // Copyright (c) 2015年 bang. All rights reserved. 7 | // 8 | 9 | #import "JPEngine.h" 10 | 11 | @interface JPCGImage : JPExtension 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunctionBinder/CoreGraphics/JPCGImage.m: -------------------------------------------------------------------------------- 1 | // 2 | // JPCGImage.m 3 | // JSPatchDemo 4 | // 5 | // Created by Albert438 on 15/7/3. 6 | // Copyright (c) 2015年 bang. All rights reserved. 7 | // 8 | 9 | #import "JPCGImage.h" 10 | #import 11 | #import "JPCGGeometry.h" 12 | 13 | @implementation JPCGImage 14 | 15 | + (void)main:(JSContext *)context 16 | { 17 | context[@"CGImageCreate"] = ^id(size_t width, size_t height, 18 | size_t bitsPerComponent, size_t bitsPerPixel, size_t bytesPerRow, 19 | JSValue *space, int bitmapInfo, JSValue *provider, 20 | NSArray *decodeArray, bool shouldInterpolate, 21 | int intent) { 22 | if (decodeArray == nil) { 23 | CGImageRef createdImage = CGImageCreate(width, height, bitsPerComponent, bitsPerPixel,bytesPerRow, [self formatPointerJSToOC:space], bitmapInfo, [self formatPointerJSToOC:provider], NULL, shouldInterpolate, intent); 24 | return [self formatRetainedCFTypeOCToJS:createdImage]; 25 | }else { 26 | CGFloat *decode = malloc(decodeArray.count * sizeof(CGFloat)); 27 | for (int i = 0; i < decodeArray.count; i++) { 28 | decode[i] = [decodeArray[i] doubleValue]; 29 | } 30 | CGImageRef createdImage = CGImageCreate(width, height, bitsPerComponent, bitsPerPixel,bytesPerRow, [self formatPointerJSToOC:space], bitmapInfo, [self formatPointerJSToOC:provider], decode, shouldInterpolate, intent); 31 | free(decode); 32 | return [self formatRetainedCFTypeOCToJS:createdImage]; 33 | } 34 | }; 35 | 36 | context[@"CGImageCreateWithImageInRect"] = ^id(JSValue *image, NSDictionary *rectDict) { 37 | CGRect rect; 38 | [JPCGGeometry rectStruct:&rect ofDict:rectDict]; 39 | CGImageRef retImage = CGImageCreateWithImageInRect([self formatPointerJSToOC:image], rect); 40 | return [self formatRetainedCFTypeOCToJS:retImage]; 41 | }; 42 | 43 | context[@"CGImageCreateWithMask"] = ^id(JSValue *image, JSValue *mask) { 44 | CGImageRef createdImage = CGImageCreateWithMask([self formatPointerJSToOC:image], [self formatPointerJSToOC:mask]); 45 | return [self formatRetainedCFTypeOCToJS:createdImage]; 46 | }; 47 | 48 | context[@"CGImageGetAlphaInfo"] = ^CGImageAlphaInfo(JSValue *image) { 49 | return CGImageGetAlphaInfo([self formatPointerJSToOC:image]); 50 | }; 51 | 52 | context[@"CGImageGetBitmapInfo"] = ^CGBitmapInfo(JSValue *image) { 53 | CGBitmapInfo ret = CGImageGetBitmapInfo([self formatPointerJSToOC:image]); 54 | return ret; 55 | }; 56 | 57 | context[@"CGImageGetBitsPerComponent"] = ^size_t(JSValue *image) { 58 | return CGImageGetBitsPerComponent([self formatPointerJSToOC:image]); 59 | }; 60 | 61 | context[@"CGImageGetColorSpace"] = ^id(JSValue *image) { 62 | CGColorSpaceRef space = CGImageGetColorSpace([self formatPointerJSToOC:image]); 63 | return [self formatPointerOCToJS:space]; 64 | }; 65 | 66 | context[@"CGImageGetDataProvider"] = ^id(JSValue *image) { 67 | CGDataProviderRef provider = CGImageGetDataProvider([self formatPointerJSToOC:image]); 68 | return [self formatPointerOCToJS:provider]; 69 | }; 70 | 71 | context[@"CGImageGetHeight"] = ^size_t(JSValue *image) { 72 | return CGImageGetHeight([self formatPointerJSToOC:image]); 73 | }; 74 | 75 | context[@"CGImageGetWidth"] = ^size_t(JSValue *image) { 76 | return CGImageGetWidth([self formatPointerJSToOC:image]); 77 | }; 78 | 79 | context[@"CGImageRelease"] = ^void(JSValue *image) { 80 | CGImageRelease([self formatPointerJSToOC:image]); 81 | }; 82 | } 83 | 84 | 85 | @end 86 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunctionBinder/CoreGraphics/JPCGPath.h: -------------------------------------------------------------------------------- 1 | // 2 | // JPCGPath.h 3 | // JSPatchDemo 4 | // 5 | // Created by Albert438 on 15/7/6. 6 | // Copyright (c) 2015年 bang. All rights reserved. 7 | // 8 | 9 | #import "JPEngine.h" 10 | 11 | @interface JPCGPath : JPExtension 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunctionBinder/CoreGraphics/JPCGPath.m: -------------------------------------------------------------------------------- 1 | // 2 | // JPCGPath.m 3 | // JSPatchDemo 4 | // 5 | // Created by Albert438 on 15/7/6. 6 | // Copyright (c) 2015年 bang. All rights reserved. 7 | // 8 | 9 | #import "JPCGPath.h" 10 | #import "JPCGTransform.h" 11 | #import "JPCGGeometry.h" 12 | #import 13 | 14 | @implementation JPCGPath 15 | 16 | + (void)main:(JSContext *)context 17 | { 18 | context[@"CGPathAddArc"] = ^void(JSValue *path, NSDictionary *m, 19 | CGFloat x, CGFloat y, CGFloat radius, CGFloat startAngle, CGFloat endAngle, 20 | bool clockwise) { 21 | CGAffineTransform transform; 22 | [JPCGTransform transStruct:&transform ofDict:m]; 23 | CGPathAddArc([self formatPointerJSToOC:path], &transform, x, y, radius, startAngle, endAngle, clockwise); 24 | }; 25 | 26 | context[@"CGPathAddArcToPoint"] = ^void(JSValue *path, 27 | NSDictionary *m, CGFloat x1, CGFloat y1, CGFloat x2, CGFloat y2, 28 | CGFloat radius) { 29 | CGAffineTransform transform; 30 | [JPCGTransform transStruct:&transform ofDict:m]; 31 | CGPathAddArcToPoint([self formatPointerJSToOC:path], &transform, x1, y1, x2, y2, radius); 32 | }; 33 | context[@"CGPathAddCurveToPoint"] = ^void(JSValue *path, 34 | NSDictionary *m, CGFloat cp1x, CGFloat cp1y, 35 | CGFloat cp2x, CGFloat cp2y, CGFloat x, CGFloat y) { 36 | CGAffineTransform transform; 37 | [JPCGTransform transStruct:&transform ofDict:m]; 38 | CGPathAddCurveToPoint([self formatPointerJSToOC:path], &transform, cp1x, cp1y, cp2x, cp2y, x, y); 39 | }; 40 | 41 | context[@"CGPathAddEllipseInRect"] = ^void(JSValue *path, 42 | NSDictionary *m, NSDictionary *rectDict) { 43 | CGAffineTransform transform; 44 | [JPCGTransform transStruct:&transform ofDict:m]; 45 | CGRect rect; 46 | [JPCGGeometry rectStruct:&rect ofDict:rectDict]; 47 | CGPathAddEllipseInRect([self formatPointerJSToOC:path], &transform, rect); 48 | }; 49 | 50 | context[@"CGPathAddLineToPoint"] = ^void(JSValue *path, 51 | NSDictionary *m, CGFloat x, CGFloat y) { 52 | CGAffineTransform transform; 53 | [JPCGTransform transStruct:&transform ofDict:m]; 54 | CGPathAddLineToPoint([self formatPointerJSToOC:path], &transform, x, y); 55 | }; 56 | 57 | 58 | context[@"CGPathAddLines"] = ^void(JSValue *path, 59 | NSDictionary *m, NSArray *pointsArray, size_t count) { 60 | CGPoint *points = malloc(sizeof(CGPoint) * count); 61 | for (int i = 0; i < count; i++) { 62 | CGPoint point; 63 | [JPCGGeometry pointStruct:&point ofDict:pointsArray[i]]; 64 | points[i] = point; 65 | } 66 | CGAffineTransform transform; 67 | [JPCGTransform transStruct:&transform ofDict:m]; 68 | CGPathAddLines([self formatPointerJSToOC:path], &transform, points, count); 69 | free(points); 70 | }; 71 | 72 | context[@"CGPathAddRect"] = ^void(JSValue *path, NSDictionary *m, 73 | NSDictionary *rectDict) { 74 | CGRect rect; 75 | CGAffineTransform transform; 76 | [JPCGGeometry rectStruct:&rect ofDict:rectDict]; 77 | [JPCGTransform transStruct:&transform ofDict:m]; 78 | CGPathAddRect([self formatPointerJSToOC:path], &transform, rect); 79 | }; 80 | 81 | context[@"CGPathCreateMutable"] = ^id() { 82 | CGMutablePathRef path = CGPathCreateMutable(); 83 | return [self formatRetainedCFTypeOCToJS:path]; 84 | }; 85 | 86 | context[@"CGPathMoveToPoint"] = ^void(JSValue *path, 87 | NSDictionary *m, CGFloat x, CGFloat y) { 88 | CGAffineTransform transform; 89 | [JPCGTransform transStruct:&transform ofDict:m]; 90 | CGPathMoveToPoint([self formatPointerJSToOC:path], &transform, x, y); 91 | }; 92 | 93 | context[@"CGPathCloseSubpath"] = ^void(JSValue *path) { 94 | CGPathCloseSubpath([self formatPointerJSToOC:path]); 95 | }; 96 | 97 | context[@"CGPathContainsPoint"] = ^BOOL(JSValue *path, 98 | NSDictionary *m, NSDictionary *pointDict, bool eoFill) { 99 | CGAffineTransform transform; 100 | [JPCGTransform transStruct:&transform ofDict:m]; 101 | CGPoint point; 102 | [JPCGGeometry pointDictOfStruct:&point]; 103 | return CGPathContainsPoint([self formatPointerJSToOC:path], &transform, point, eoFill); 104 | }; 105 | 106 | context[@"CGPathCreateWithEllipseInRect"] = ^id(NSDictionary *rectDict, 107 | NSDictionary *transformDict) { 108 | CGRect rect; 109 | CGAffineTransform transform; 110 | [JPCGGeometry rectStruct:&rect ofDict:rectDict]; 111 | [JPCGTransform transStruct:&transform ofDict:transformDict]; 112 | CGPathRef path = CGPathCreateWithEllipseInRect(rect, &transform); 113 | return [self formatRetainedCFTypeOCToJS:(void *)path]; 114 | }; 115 | 116 | context[@"CGPathGetPathBoundingBox"] = ^NSDictionary *(JSValue *path) { 117 | CGRect rect = CGPathGetPathBoundingBox([self formatPointerJSToOC:path]); 118 | return [JPCGGeometry rectDictOfStruct:&rect]; 119 | }; 120 | 121 | context[@"CGPathRelease"] = ^void(JSValue *path) { 122 | CGPathRelease([self formatPointerJSToOC:path]); 123 | }; 124 | } 125 | 126 | 127 | @end 128 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunctionBinder/CoreGraphics/JPCGTransform.h: -------------------------------------------------------------------------------- 1 | // 2 | // JPCGTransform.h 3 | // JSPatchDemo 4 | // 5 | // Created by bang on 15/6/30. 6 | // Copyright (c) 2015 bang. All rights reserved. 7 | // 8 | 9 | #import "JPEngine.h" 10 | #import 11 | 12 | @interface JPCGTransform : JPExtension 13 | 14 | + (NSDictionary *)transDictOfStruct:(CGAffineTransform *)trans; 15 | + (void)transStruct:(CGAffineTransform *)trans ofDict:(NSDictionary *)dict; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunctionBinder/CoreGraphics/JPCGTransform.m: -------------------------------------------------------------------------------- 1 | // 2 | // JPCGTransform.m 3 | // JSPatchDemo 4 | // 5 | // Created by bang on 15/6/30. 6 | // Copyright (c) 2015 bang. All rights reserved. 7 | // 8 | 9 | #import "JPCGTransform.h" 10 | #import "JPCGGeometry.h" 11 | 12 | #define TRANSFORM_DEFINE @{ \ 13 | @"name": @"CGAffineTransform", \ 14 | @"types": @"FFFFFF", \ 15 | @"keys": @[@"a", @"b", @"c", @"d", @"tx", @"ty"] \ 16 | } 17 | 18 | @implementation JPCGTransform 19 | static NSDictionary *transformStructDefine; 20 | + (void)main:(JSContext *)context 21 | { 22 | transformStructDefine = TRANSFORM_DEFINE; 23 | [JPEngine defineStruct:transformStructDefine]; 24 | 25 | context[@"CGAffineTransformMakeTranslation"] = ^id(CGFloat tx, CGFloat ty) { 26 | CGAffineTransform trans = CGAffineTransformMakeTranslation(tx, ty); 27 | return [self getDictOfStruct:&trans structDefine:transformStructDefine]; 28 | }; 29 | 30 | context[@"CGAffineTransformMakeRotation"] = ^id(CGFloat angle) { 31 | CGAffineTransform trans = CGAffineTransformMakeRotation(angle); 32 | return [self getDictOfStruct:&trans structDefine:transformStructDefine]; 33 | }; 34 | 35 | context[@"CGAffineTransformMakeScale"] = ^id(CGFloat sx, CGFloat sy) { 36 | CGAffineTransform trans = CGAffineTransformMakeScale(sx, sy); 37 | return [self getDictOfStruct:&trans structDefine:transformStructDefine]; 38 | }; 39 | 40 | context[@"CGAffineTransformTranslate"] = ^id(NSDictionary *transformDict, CGFloat tx, CGFloat ty) { 41 | CGAffineTransform trans; 42 | [self getStructDataWidthDict:&trans dict:transformDict structDefine:transformStructDefine]; 43 | CGAffineTransform translatedTransform = CGAffineTransformTranslate(trans, tx, ty); 44 | return [self getDictOfStruct:&translatedTransform structDefine:transformStructDefine]; 45 | }; 46 | 47 | context[@"CGAffineTransformScale"] = ^id(NSDictionary *transformDict, CGFloat sx, CGFloat sy) { 48 | CGAffineTransform trans; 49 | [self getStructDataWidthDict:&trans dict:transformDict structDefine:transformStructDefine]; 50 | CGAffineTransform translatedTransform = CGAffineTransformScale(trans, sx, sy); 51 | return [self getDictOfStruct:&translatedTransform structDefine:transformStructDefine]; 52 | }; 53 | 54 | context[@"CGAffineTransformRotate"] = ^id(NSDictionary *transformDict, CGFloat angle) { 55 | CGAffineTransform trans; 56 | [self getStructDataWidthDict:&trans dict:transformDict structDefine:transformStructDefine]; 57 | CGAffineTransform translatedTransform = CGAffineTransformRotate(trans, angle); 58 | return [self getDictOfStruct:&translatedTransform structDefine:transformStructDefine]; 59 | }; 60 | 61 | context[@"CGRectApplyAffineTransform"] = ^NSDictionary *(NSDictionary *rectDict, NSDictionary *transformDict) { 62 | CGRect rect; 63 | CGAffineTransform transform; 64 | [self getStructDataWidthDict:&transform dict:transformDict structDefine:transformStructDefine]; 65 | [JPCGGeometry rectStruct:&rect ofDict:rectDict]; 66 | CGRect retRect = CGRectApplyAffineTransform(rect, transform); 67 | return [JPCGGeometry rectDictOfStruct:&retRect]; 68 | }; 69 | } 70 | 71 | + (NSDictionary *)transDictOfStruct:(CGAffineTransform *)trans 72 | { 73 | return [self getDictOfStruct:trans structDefine:transformStructDefine ? transformStructDefine : TRANSFORM_DEFINE]; 74 | } 75 | + (void)transStruct:(CGAffineTransform *)trans ofDict:(NSDictionary *)dict 76 | { 77 | [self getStructDataWidthDict:trans dict:dict structDefine:transformStructDefine ? transformStructDefine : TRANSFORM_DEFINE]; 78 | } 79 | 80 | @end 81 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunctionBinder/CoreGraphics/JPCoreGraphics.h: -------------------------------------------------------------------------------- 1 | // 2 | // JPCoreGraphics.h 3 | // JSPatchDemo 4 | // 5 | // Created by Albert438 on 15/7/3. 6 | // Copyright © 2015年 bang. All rights reserved. 7 | // 8 | 9 | #import "JPEngine.h" 10 | 11 | @interface JPCoreGraphics : JPExtension 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunctionBinder/CoreGraphics/JPCoreGraphics.m: -------------------------------------------------------------------------------- 1 | // 2 | // JPCoreGraphics.m 3 | // JSPatchDemo 4 | // 5 | // Created by Albert438 on 15/7/3. 6 | // Copyright © 2015年 bang. All rights reserved. 7 | // 8 | 9 | #import "JPCoreGraphics.h" 10 | #import "JPEngine.h" 11 | 12 | 13 | @implementation JPCoreGraphics 14 | 15 | + (void)main:(JSContext *)context 16 | { 17 | NSArray *extensionArray = @[@"JPCGTransform", @"JPCGContext", @"JPCGGeometry", @"JPCGBitmapContext", 18 | @"JPCGColor", @"JPCGImage", @"JPCGPath"]; 19 | [JPEngine addExtensions:extensionArray]; 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunctionBinder/UIKit/JPUIGeometry.h: -------------------------------------------------------------------------------- 1 | // 2 | // JPUIGeometry.h 3 | // JSPatchDemo 4 | // 5 | // Created by Albert438 on 15/7/6. 6 | // Copyright (c) 2015年 bang. All rights reserved. 7 | // 8 | 9 | #import "JPEngine.h" 10 | 11 | @interface JPUIGeometry : JPExtension 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunctionBinder/UIKit/JPUIGeometry.m: -------------------------------------------------------------------------------- 1 | // 2 | // JPUIGeometry.m 3 | // JSPatchDemo 4 | // 5 | // Created by Albert438 on 15/7/6. 6 | // Copyright (c) 2015年 bang. All rights reserved. 7 | // 8 | 9 | #import "JPUIGeometry.h" 10 | #import "JPCGGeometry.h" 11 | #import 12 | 13 | 14 | @implementation JPUIGeometry 15 | 16 | + (void)main:(JSContext *)context 17 | { 18 | [JPEngine defineStruct:@{@"name": @"UIEdgeInsets", 19 | @"types": @"FFFF", 20 | @"keys": @[@"top", @"left", @"bottom", @"right"] 21 | }]; 22 | 23 | [JPEngine defineStruct:@{@"name": @"UIOffset", 24 | @"types": @"FF", 25 | @"keys": @[@"horizontal", @"vertical"] 26 | }]; 27 | 28 | context[@"CGRectFromString"] = ^NSDictionary *(NSString *string) { 29 | CGRect rect = CGRectFromString(string); 30 | return [JPCGGeometry rectDictOfStruct:&rect]; 31 | }; 32 | 33 | context[@"CGSizeFromString"] = ^NSDictionary *(NSString *string) { 34 | CGSize size = CGSizeFromString(string); 35 | return [JPCGGeometry sizeDictOfStruct:&size]; 36 | }; 37 | 38 | context[@"CGPointFromString"] = ^NSDictionary *(NSString *string) { 39 | CGPoint point = CGPointFromString(string); 40 | return [JPCGGeometry pointDictOfStruct:&point]; 41 | }; 42 | 43 | context[@"CGVectorFromString"] = ^NSDictionary *(NSString *string) { 44 | CGVector vector = CGVectorFromString(string); 45 | return [JPCGGeometry vectorDictOfStruct:&vector]; 46 | }; 47 | } 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunctionBinder/UIKit/JPUIGraphics.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIGraphics.h 3 | // JSPatchDemo 4 | // 5 | // Created by Albert438 on 15/7/6. 6 | // Copyright (c) 2015年 bang. All rights reserved. 7 | // 8 | 9 | #import "JPEngine.h" 10 | 11 | @interface JPUIGraphics : JPExtension 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunctionBinder/UIKit/JPUIGraphics.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIGraphics.m 3 | // JSPatchDemo 4 | // 5 | // Created by Albert438 on 15/7/6. 6 | // Copyright (c) 2015年 bang. All rights reserved. 7 | // 8 | 9 | 10 | #import "JPUIGraphics.h" 11 | #import "JPCGGeometry.h" 12 | #import 13 | 14 | @implementation JPUIGraphics 15 | 16 | + (void)main:(JSContext *)context 17 | { 18 | context[@"UIGraphicsGetCurrentContext"] = ^id() { 19 | CGContextRef c = UIGraphicsGetCurrentContext(); 20 | return [self formatPointerOCToJS:c]; 21 | }; 22 | 23 | context[@"UIGraphicsBeginImageContext"] = ^void(NSDictionary *sizeDict) { 24 | CGSize size; 25 | [JPCGGeometry sizeStruct:&size ofDict:sizeDict]; 26 | UIGraphicsBeginImageContext(size); 27 | }; 28 | 29 | context[@"UIGraphicsBeginImageContextWithOptions"] = ^void(NSDictionary *sizeDict, BOOL opaque, CGFloat scale) { 30 | CGSize size; 31 | [JPCGGeometry sizeStruct:&size ofDict:sizeDict]; 32 | UIGraphicsBeginImageContextWithOptions(size, opaque, scale); 33 | }; 34 | 35 | context[@"UIGraphicsGetImageFromCurrentImageContext"] = ^id() { 36 | UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 37 | return [self formatOCToJS:image]; 38 | }; 39 | 40 | context[@"UIGraphicsEndImageContext"] = ^void() { 41 | UIGraphicsEndImageContext(); 42 | }; 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunctionBinder/UIKit/JPUIImage.h: -------------------------------------------------------------------------------- 1 | // 2 | // JPUIImage.h 3 | // JSPatchDemo 4 | // 5 | // Created by Albert438 on 15/7/6. 6 | // Copyright (c) 2015年 bang. All rights reserved. 7 | // 8 | 9 | #import "JPEngine.h" 10 | 11 | @interface JPUIImage : JPExtension 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunctionBinder/UIKit/JPUIImage.m: -------------------------------------------------------------------------------- 1 | // 2 | // JPUIImage.m 3 | // JSPatchDemo 4 | // 5 | // Created by Albert438 on 15/7/6. 6 | // Copyright (c) 2015年 bang. All rights reserved. 7 | // 8 | 9 | #import "JPUIImage.h" 10 | #import 11 | 12 | @implementation JPUIImage 13 | 14 | + (void)main:(JSContext *)context 15 | { 16 | context[@"UIImageJPEGRepresentation"] = ^id(JSValue *jsVal, CGFloat compressionQuality) { 17 | UIImage *image = [self formatJSToOC:jsVal]; 18 | NSData *data = UIImageJPEGRepresentation(image, compressionQuality); 19 | return [self formatOCToJS:data]; 20 | }; 21 | 22 | context[@"UIImagePNGRepresentation"] = ^id(JSValue *jsVal) { 23 | UIImage *image = [self formatJSToOC:jsVal]; 24 | NSData *data = UIImagePNGRepresentation(image); 25 | return [self formatOCToJS:data]; 26 | }; 27 | 28 | } 29 | 30 | @end 31 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunctionBinder/UIKit/JPUIKit.h: -------------------------------------------------------------------------------- 1 | // 2 | // JPUIKit.h 3 | // JSPatchDemo 4 | // 5 | // Created by Albert438 on 15/7/6. 6 | // Copyright (c) 2015年 bang. All rights reserved. 7 | // 8 | 9 | #import "JPEngine.h" 10 | 11 | @interface JPUIKit : JPExtension 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCFunctionBinder/UIKit/JPUIKit.m: -------------------------------------------------------------------------------- 1 | // 2 | // JPUIKit.m 3 | // JSPatchDemo 4 | // 5 | // Created by Albert438 on 15/7/6. 6 | // Copyright (c) 2015年 bang. All rights reserved. 7 | // 8 | 9 | #import "JPUIKit.h" 10 | 11 | @implementation JPUIKit 12 | 13 | + (void)main:(JSContext *)context 14 | { 15 | NSArray *extensionArray = @[@"JPUIGraphics", @"JPUIGeometry", @"JPUIImage"]; 16 | [JPEngine addExtensions:extensionArray]; 17 | } 18 | 19 | @end -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCleaner.h: -------------------------------------------------------------------------------- 1 | // 2 | // JPReverter.h 3 | // JSPatchDemo 4 | // 5 | // Created by bang on 2/4/16. 6 | // Copyright © 2016 bang. All rights reserved. 7 | // 8 | 9 | #import "JPEngine.h" 10 | 11 | @interface JPCleaner : JPExtension 12 | + (void)cleanAll; 13 | + (void)cleanClass:(NSString *)className; 14 | @end 15 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPCleaner.m: -------------------------------------------------------------------------------- 1 | // 2 | // JPReverter.m 3 | // JSPatchDemo 4 | // 5 | // Created by bang on 2/4/16. 6 | // Copyright © 2016 bang. All rights reserved. 7 | // 8 | 9 | #import "JPCleaner.h" 10 | #import 11 | 12 | @implementation JPCleaner 13 | #pragma clang diagnostic push 14 | #pragma clang diagnostic ignored "-Wundeclared-selector" 15 | 16 | + (void)cleanAll 17 | { 18 | [self cleanClass:nil]; 19 | [[self includedScriptPaths] removeAllObjects]; 20 | } 21 | 22 | + (void)cleanClass:(NSString *)className 23 | { 24 | NSDictionary *methodsDict = [JPExtension overideMethods]; 25 | for (Class cls in methodsDict.allKeys) { 26 | if (className && ![className isEqualToString:NSStringFromClass(cls)]) { 27 | continue; 28 | } 29 | for (NSString *jpSelectorName in [methodsDict[cls] allKeys]) { 30 | NSString *selectorName = [jpSelectorName substringFromIndex:3]; 31 | NSString *originalSelectorName = [NSString stringWithFormat:@"ORIG%@", selectorName]; 32 | 33 | SEL selector = NSSelectorFromString(selectorName); 34 | SEL originalSelector = NSSelectorFromString(originalSelectorName); 35 | IMP originalImp = class_respondsToSelector(cls, originalSelector) ? class_getMethodImplementation(cls, originalSelector) : NULL; 36 | 37 | Method method = class_getInstanceMethod(cls, originalSelector); 38 | char *typeDescription = (char *)method_getTypeEncoding(method); 39 | 40 | class_replaceMethod(cls, selector, originalImp, typeDescription); 41 | } 42 | 43 | char *typeDescription = (char *)method_getTypeEncoding(class_getInstanceMethod(cls, @selector(forwardInvocation:))); 44 | IMP forwardInvocationIMP = class_getMethodImplementation(cls, @selector(ORIGforwardInvocation:)); 45 | class_replaceMethod(cls, @selector(forwardInvocation:), forwardInvocationIMP, typeDescription); 46 | } 47 | } 48 | 49 | #pragma clang diagnostic pop 50 | @end 51 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPLocker.h: -------------------------------------------------------------------------------- 1 | // 2 | // JPLocker.h 3 | // JSPatchDemo 4 | // 5 | // Created by bang on 3/22/16. 6 | // Copyright © 2016 bang. All rights reserved. 7 | // 8 | 9 | #import "JPEngine.h" 10 | 11 | @interface JPLocker : JPExtension 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPLocker.m: -------------------------------------------------------------------------------- 1 | // 2 | // JPLocker.m 3 | // JSPatchDemo 4 | // 5 | // Created by bang on 3/22/16. 6 | // Copyright © 2016 bang. All rights reserved. 7 | // 8 | 9 | #import "JPLocker.h" 10 | 11 | @implementation JPLocker 12 | + (void)main:(JSContext *)context 13 | { 14 | context[@"synchronized"] = ^void(JSValue *jsVal, JSValue *cb) { 15 | @synchronized([self formatJSToOC:jsVal]) { 16 | [cb callWithArguments:nil]; 17 | } 18 | }; 19 | } 20 | @end 21 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPSpecialInit.h: -------------------------------------------------------------------------------- 1 | // 2 | // JPSpecialInit.h 3 | // SwiftDemo 4 | // 5 | // Created by KouArlen on 16/2/25. 6 | // Copyright © 2016年 Arlen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | /** 13 | handle the Init of some Special Class 14 | https://github.com/bang590/JSPatch/issues/248 15 | 16 | */ 17 | 18 | @interface JPSpecialInit : NSObject 19 | 20 | + (NSCalendar *)calendarWithCalendarIdentifier:(NSString *)iden; 21 | 22 | #if TARGET_OS_IOS 23 | + (UIWebView *)newWebView; 24 | #endif 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/Extensions/JPSpecialInit.m: -------------------------------------------------------------------------------- 1 | // 2 | // JPSpecialInit.m 3 | // SwiftDemo 4 | // 5 | // Created by KouArlen on 16/2/25. 6 | // Copyright © 2016年 Arlen. All rights reserved. 7 | // 8 | 9 | #import "JPSpecialInit.h" 10 | 11 | @implementation JPSpecialInit 12 | 13 | + (NSCalendar *)calendarWithCalendarIdentifier:(NSString *)iden 14 | { 15 | return [[NSCalendar alloc] initWithCalendarIdentifier:iden]; 16 | } 17 | 18 | #if TARGET_OS_IOS 19 | + (UIWebView *)newWebView 20 | { 21 | return [[UIWebView alloc] init]; 22 | } 23 | #endif 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/JSPatch/JPEngine.h: -------------------------------------------------------------------------------- 1 | // 2 | // JPEngine.h 3 | // JSPatch 4 | // 5 | // Created by bang on 15/4/30. 6 | // Copyright (c) 2015 bang. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | 13 | @interface JPEngine : NSObject 14 | 15 | /*! 16 | @method 17 | @discussion start the JSPatch engine, execute only once. 18 | !Deprecated! will be call automatically before evaluate script 19 | */ 20 | + (void)startEngine; 21 | 22 | /*! 23 | @method 24 | @description Evaluate Javascript code from a file Path. Call it after +startEngine. 25 | @param filePath: The filePath of the Javascript code. 26 | @result The last value generated by the script. 27 | */ 28 | + (JSValue *)evaluateScriptWithPath:(NSString *)filePath; 29 | 30 | /*! 31 | @method 32 | @description Evaluate a string of JavaScript code. Call it after +startEngine. 33 | The method will generate a default resouceURL named "main.js" to the Safari debugger. 34 | @param script: A string containing the JavaScript code to evaluate. 35 | @result The last value generated by the script. 36 | */ 37 | + (JSValue *)evaluateScript:(NSString *)script; 38 | 39 | /*! 40 | @method 41 | @description Return the JSPatch JavaScript execution environment. 42 | */ 43 | + (JSContext *)context; 44 | 45 | 46 | 47 | /*! 48 | @method 49 | @description Add JPExtension. 50 | @param extensions: An array containing class name string. 51 | */ 52 | + (void)addExtensions:(NSArray *)extensions; 53 | 54 | /*! 55 | @method 56 | @description add new struct type supporting to JS 57 | @param defineDict: the definition of struct, for Example: 58 | @{ 59 | @"name": @"CGAffineTransform", //struct name 60 | @"types": @"ffffff", //struct types 61 | @"keys": @[@"a", @"b", @"c", @"d", @"tx", @"ty"] //struct keys in JS 62 | } 63 | */ 64 | + (void)defineStruct:(NSDictionary *)defineDict; 65 | 66 | + (void)handleException:(void (^)(NSString *msg))exceptionBlock; 67 | @end 68 | 69 | 70 | 71 | @interface JPExtension : NSObject 72 | + (void)main:(JSContext *)context; 73 | 74 | + (void *)formatPointerJSToOC:(JSValue *)val; 75 | + (id)formatRetainedCFTypeOCToJS:(CFTypeRef)CF_CONSUMED type; 76 | + (id)formatPointerOCToJS:(void *)pointer; 77 | + (id)formatJSToOC:(JSValue *)val; 78 | + (id)formatOCToJS:(id)obj; 79 | 80 | + (int)sizeOfStructTypes:(NSString *)structTypes; 81 | + (void)getStructDataWidthDict:(void *)structData dict:(NSDictionary *)dict structDefine:(NSDictionary *)structDefine; 82 | + (NSDictionary *)getDictOfStruct:(void *)structData structDefine:(NSDictionary *)structDefine; 83 | 84 | /*! 85 | @method 86 | @description Return the registered struct definition in JSPatch, 87 | the key of dictionary is the struct name. 88 | */ 89 | + (NSMutableDictionary *)registeredStruct; 90 | 91 | + (NSDictionary *)overideMethods; 92 | + (NSMutableSet *)includedScriptPaths; 93 | @end 94 | 95 | 96 | 97 | @interface JPBoxing : NSObject 98 | @property (nonatomic) id obj; 99 | @property (nonatomic) void *pointer; 100 | @property (nonatomic) Class cls; 101 | @property (nonatomic, weak) id weakObj; 102 | @property (nonatomic, assign) id assignObj; 103 | - (id)unbox; 104 | - (void *)unboxPointer; 105 | - (Class)unboxClass; 106 | @end 107 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/JSPatch/JSPatch.js: -------------------------------------------------------------------------------- 1 | var global = this 2 | 3 | ;(function() { 4 | 5 | var _ocCls = {}; 6 | var _jsCls = {}; 7 | 8 | var _formatOCToJS = function(obj) { 9 | if (obj === undefined || obj === null) return false 10 | if (typeof obj == "object") { 11 | if (obj.__obj) return obj 12 | if (obj.__isNil) return false 13 | } 14 | if (obj instanceof Array) { 15 | var ret = [] 16 | obj.forEach(function(o) { 17 | ret.push(_formatOCToJS(o)) 18 | }) 19 | return ret 20 | } 21 | if (obj instanceof Function) { 22 | return function() { 23 | var args = Array.prototype.slice.call(arguments) 24 | var formatedArgs = _OC_formatJSToOC(args) 25 | for (var i = 0; i < args.length; i++) { 26 | if (args[i] === null || args[i] === undefined || args[i] === false) { 27 | formatedArgs.splice(i, 1, undefined) 28 | } else if (args[i] == nsnull) { 29 | formatedArgs.splice(i, 1, null) 30 | } 31 | } 32 | return _OC_formatOCToJS(obj.apply(obj, formatedArgs)) 33 | } 34 | } 35 | if (obj instanceof Object) { 36 | var ret = {} 37 | for (var key in obj) { 38 | ret[key] = _formatOCToJS(obj[key]) 39 | } 40 | return ret 41 | } 42 | return obj 43 | } 44 | 45 | var _methodFunc = function(instance, clsName, methodName, args, isSuper, isPerformSelector) { 46 | var selectorName = methodName 47 | if (!isPerformSelector) { 48 | methodName = methodName.replace(/__/g, "-") 49 | selectorName = methodName.replace(/_/g, ":").replace(/-/g, "_") 50 | var marchArr = selectorName.match(/:/g) 51 | var numOfArgs = marchArr ? marchArr.length : 0 52 | if (args.length > numOfArgs) { 53 | selectorName += ":" 54 | } 55 | } 56 | var ret = instance ? _OC_callI(instance, selectorName, args, isSuper): 57 | _OC_callC(clsName, selectorName, args) 58 | return _formatOCToJS(ret) 59 | } 60 | 61 | var _customMethods = { 62 | __c: function(methodName) { 63 | var slf = this 64 | 65 | if (slf instanceof Boolean) { 66 | return function() { 67 | return false 68 | } 69 | } 70 | if (slf[methodName]) { 71 | return slf[methodName].bind(slf); 72 | } 73 | 74 | if (!slf.__obj && !slf.__clsName) { 75 | throw new Error(slf + '.' + methodName + ' is undefined') 76 | } 77 | if (slf.__isSuper && slf.__clsName) { 78 | slf.__clsName = _OC_superClsName(slf.__obj.__realClsName ? slf.__obj.__realClsName: slf.__clsName); 79 | } 80 | var clsName = slf.__clsName 81 | if (clsName && _ocCls[clsName]) { 82 | var methodType = slf.__obj ? 'instMethods': 'clsMethods' 83 | if (_ocCls[clsName][methodType][methodName]) { 84 | slf.__isSuper = 0; 85 | return _ocCls[clsName][methodType][methodName].bind(slf) 86 | } 87 | 88 | if (slf.__obj && _ocCls[clsName]['props'][methodName]) { 89 | if (!slf.__ocProps) { 90 | var props = _OC_getCustomProps(slf.__obj) 91 | if (!props) { 92 | props = {} 93 | _OC_setCustomProps(slf.__obj, props) 94 | } 95 | slf.__ocProps = props; 96 | } 97 | var c = methodName.charCodeAt(3); 98 | if (methodName.length > 3 && methodName.substr(0,3) == 'set' && c >= 65 && c <= 90) { 99 | return function(val) { 100 | var propName = methodName[3].toLowerCase() + methodName.substr(4) 101 | if(val === undefined || val === null) { 102 | val = false; 103 | } 104 | slf.__ocProps[propName] = val 105 | } 106 | } else { 107 | return function(){ 108 | return slf.__ocProps[methodName] 109 | } 110 | } 111 | } 112 | } 113 | 114 | return function(){ 115 | var args = Array.prototype.slice.call(arguments) 116 | return _methodFunc(slf.__obj, slf.__clsName, methodName, args, slf.__isSuper) 117 | } 118 | }, 119 | 120 | super: function() { 121 | var slf = this 122 | if (slf.__obj) { 123 | slf.__obj.__realClsName = slf.__realClsName; 124 | } 125 | return {__obj: slf.__obj, __clsName: slf.__clsName, __isSuper: 1} 126 | }, 127 | 128 | performSelectorInOC: function() { 129 | var slf = this 130 | var args = Array.prototype.slice.call(arguments) 131 | return {__isPerformInOC:1, obj:slf.__obj, clsName:slf.__clsName, sel: args[0], args: args[1], cb: args[2]} 132 | }, 133 | 134 | performSelector: function() { 135 | var slf = this 136 | var args = Array.prototype.slice.call(arguments) 137 | return _methodFunc(slf.__obj, slf.__clsName, args[0], args.splice(1), slf.__isSuper, true) 138 | } 139 | } 140 | 141 | for (var method in _customMethods) { 142 | if (_customMethods.hasOwnProperty(method)) { 143 | Object.defineProperty(Object.prototype, method, {value: _customMethods[method], configurable:false, enumerable: false}) 144 | } 145 | } 146 | 147 | var _require = function(clsName) { 148 | if (!global[clsName]) { 149 | global[clsName] = { 150 | __clsName: clsName 151 | } 152 | } 153 | return global[clsName] 154 | } 155 | 156 | global.require = function(clsNames) { 157 | var lastRequire 158 | clsNames.split(',').forEach(function(clsName) { 159 | lastRequire = _require(clsName.trim()) 160 | }) 161 | return lastRequire 162 | } 163 | 164 | var _formatDefineMethods = function(methods, newMethods, realClsName) { 165 | for (var methodName in methods) { 166 | if (!(methods[methodName] instanceof Function)) return; 167 | (function(){ 168 | var originMethod = methods[methodName] 169 | newMethods[methodName] = [originMethod.length, function() { 170 | try { 171 | var args = _formatOCToJS(Array.prototype.slice.call(arguments)) 172 | var lastSelf = global.self 173 | global.self = args[0] 174 | if (global.self) global.self.__realClsName = realClsName 175 | args.splice(0,1) 176 | var ret = originMethod.apply(originMethod, args) 177 | global.self = lastSelf 178 | return ret 179 | } catch(e) { 180 | _OC_catch(e.message, e.stack) 181 | } 182 | }] 183 | })() 184 | } 185 | } 186 | 187 | var _wrapLocalMethod = function(methodName, func, realClsName) { 188 | return function() { 189 | var lastSelf = global.self 190 | global.self = this 191 | this.__realClsName = realClsName 192 | var ret = func.apply(this, arguments) 193 | global.self = lastSelf 194 | return ret 195 | } 196 | } 197 | 198 | var _setupJSMethod = function(className, methods, isInst, realClsName) { 199 | for (var name in methods) { 200 | var key = isInst ? 'instMethods': 'clsMethods', 201 | func = methods[name] 202 | _ocCls[className][key][name] = _wrapLocalMethod(name, func, realClsName) 203 | } 204 | } 205 | 206 | global.defineClass = function(declaration, properties, instMethods, clsMethods) { 207 | var newInstMethods = {}, newClsMethods = {} 208 | if (!(properties instanceof Array)) { 209 | clsMethods = instMethods 210 | instMethods = properties 211 | properties = null 212 | } 213 | 214 | var realClsName = declaration.split(':')[0].trim() 215 | 216 | _formatDefineMethods(instMethods, newInstMethods, realClsName) 217 | _formatDefineMethods(clsMethods, newClsMethods, realClsName) 218 | 219 | var ret = _OC_defineClass(declaration, newInstMethods, newClsMethods) 220 | var className = ret['cls'] 221 | var superCls = ret['superCls'] 222 | 223 | _ocCls[className] = { 224 | instMethods: {}, 225 | clsMethods: {}, 226 | props: {} 227 | } 228 | 229 | if (superCls.length && _ocCls[superCls]) { 230 | for (var funcName in _ocCls[superCls]['instMethods']) { 231 | _ocCls[className]['instMethods'][funcName] = _ocCls[superCls]['instMethods'][funcName] 232 | } 233 | for (var funcName in _ocCls[superCls]['clsMethods']) { 234 | _ocCls[className]['clsMethods'][funcName] = _ocCls[superCls]['clsMethods'][funcName] 235 | } 236 | if (_ocCls[superCls]['props']) { 237 | _ocCls[className]['props'] = JSON.parse(JSON.stringify(_ocCls[superCls]['props'])); 238 | } 239 | } 240 | 241 | _setupJSMethod(className, instMethods, 1, realClsName) 242 | _setupJSMethod(className, clsMethods, 0, realClsName) 243 | 244 | if (properties) { 245 | properties.forEach(function(o){ 246 | _ocCls[className]['props'][o] = 1 247 | _ocCls[className]['props']['set' + o.substr(0,1).toUpperCase() + o.substr(1)] = 1 248 | }) 249 | } 250 | return require(className) 251 | } 252 | 253 | global.defineProtocol = function(declaration, instProtos , clsProtos) { 254 | var ret = _OC_defineProtocol(declaration, instProtos,clsProtos); 255 | return ret 256 | } 257 | 258 | global.block = function(args, cb) { 259 | var slf = this 260 | if (args instanceof Function) { 261 | cb = args 262 | args = '' 263 | } 264 | var callback = function() { 265 | var args = Array.prototype.slice.call(arguments) 266 | return cb.apply(slf, _formatOCToJS(args)) 267 | } 268 | return {args: args, cb: callback, __isBlock: 1} 269 | } 270 | 271 | if (global.console) { 272 | var jsLogger = console.log; 273 | global.console.log = function() { 274 | global._OC_log.apply(global, arguments); 275 | if (jsLogger) { 276 | jsLogger.apply(global.console, arguments); 277 | } 278 | } 279 | } else { 280 | global.console = { 281 | log: global._OC_log 282 | } 283 | } 284 | 285 | global.defineJSClass = function(declaration, instMethods, clsMethods) { 286 | var o = function() {}, 287 | a = declaration.split(':'), 288 | clsName = a[0].trim(), 289 | superClsName = a[1] ? a[1].trim() : null 290 | o.prototype = { 291 | init: function() { 292 | if (this.super()) this.super().init() 293 | return this; 294 | }, 295 | super: function() { 296 | return superClsName ? _jsCls[superClsName].prototype : null 297 | } 298 | } 299 | var cls = { 300 | alloc: function() { 301 | return new o; 302 | } 303 | } 304 | for (var methodName in instMethods) { 305 | o.prototype[methodName] = instMethods[methodName]; 306 | } 307 | for (var methodName in clsMethods) { 308 | cls[methodName] = clsMethods[methodName]; 309 | } 310 | global[clsName] = cls 311 | _jsCls[clsName] = o 312 | } 313 | 314 | global.YES = 1 315 | global.NO = 0 316 | global.nsnull = _OC_null 317 | global._formatOCToJS = _formatOCToJS 318 | 319 | })() -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/JSPatchPlaygroundDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/JSPatchPlaygroundDemo.xcodeproj/project.xcworkspace/xcshareddata/JSPatchPlaygroundDemo.xcscmblueprint: -------------------------------------------------------------------------------- 1 | { 2 | "DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey" : "6EA45720F22E1F1990AF2F8AF937D269A4CC7998", 3 | "DVTSourceControlWorkspaceBlueprintWorkingCopyRepositoryLocationsKey" : { 4 | 5 | }, 6 | "DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : { 7 | "6EA45720F22E1F1990AF2F8AF937D269A4CC7998" : 0, 8 | "0104904A6E66B3737E89F93E333177FA001D0B29" : 0 9 | }, 10 | "DVTSourceControlWorkspaceBlueprintIdentifierKey" : "B07DAEBB-7249-497D-84EF-E9083290E269", 11 | "DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : { 12 | "6EA45720F22E1F1990AF2F8AF937D269A4CC7998" : "JSPatchPlaygroundTool\/", 13 | "0104904A6E66B3737E89F93E333177FA001D0B29" : "JSPatch\/" 14 | }, 15 | "DVTSourceControlWorkspaceBlueprintNameKey" : "JSPatchPlaygroundDemo", 16 | "DVTSourceControlWorkspaceBlueprintVersion" : 204, 17 | "DVTSourceControlWorkspaceBlueprintRelativePathToProjectKey" : "JSPatchPlaygroundDemo\/JSPatchPlaygroundDemo.xcodeproj", 18 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoriesKey" : [ 19 | { 20 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/Awhisper\/JSPatch", 21 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 22 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "0104904A6E66B3737E89F93E333177FA001D0B29" 23 | }, 24 | { 25 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/Awhisper\/JSPatchPlaygroundTool", 26 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 27 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "6EA45720F22E1F1990AF2F8AF937D269A4CC7998" 28 | } 29 | ] 30 | } -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/JSPatchPlaygroundDemo.xcodeproj/project.xcworkspace/xcuserdata/Awhisper.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Awhisper/JSPatchPlaygroundTool/66ae16c16d5c6c25fdba899590e5f21bd0dccfbf/JSPatchPlaygroundDemo/JSPatchPlaygroundDemo.xcodeproj/project.xcworkspace/xcuserdata/Awhisper.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/JSPatchPlaygroundDemo.xcodeproj/xcuserdata/Awhisper.xcuserdatad/xcschemes/JSPatchPlaygroundDemo.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/JSPatchPlaygroundDemo.xcodeproj/xcuserdata/Awhisper.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | JSPatchPlaygroundDemo.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 6C5D37A71D56F58600B78CD9 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/JSPatchPlaygroundDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // JSPatch 4 | // 5 | // Created by bang on 15/4/30. 6 | // Copyright (c) 2015年 bang. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | @end 16 | 17 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/JSPatchPlaygroundDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // JSPatch 4 | // 5 | // Created by bang on 15/4/30. 6 | // Copyright (c) 2015年 bang. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | #import "JPEngine.h" 11 | #import "JPRootViewController.h" 12 | @implementation AppDelegate 13 | 14 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 15 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 16 | JPRootViewController *rootViewController = [[JPRootViewController alloc] init]; 17 | UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController]; 18 | self.window.rootViewController = navigationController; 19 | [self.window makeKeyAndVisible]; 20 | return YES; 21 | } 22 | @end 23 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/JSPatchPlaygroundDemo/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "83.5x83.5", 66 | "scale" : "2x" 67 | } 68 | ], 69 | "info" : { 70 | "version" : 1, 71 | "author" : "xcode" 72 | } 73 | } -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/JSPatchPlaygroundDemo/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/JSPatchPlaygroundDemo/Assets.xcassets/apple.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "apple.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/JSPatchPlaygroundDemo/Assets.xcassets/apple.imageset/apple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Awhisper/JSPatchPlaygroundTool/66ae16c16d5c6c25fdba899590e5f21bd0dccfbf/JSPatchPlaygroundDemo/JSPatchPlaygroundDemo/Assets.xcassets/apple.imageset/apple.png -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/JSPatchPlaygroundDemo/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/JSPatchPlaygroundDemo/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/JSPatchPlaygroundDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | projectPath 47 | $(SRCROOT)/$(TARGET_NAME) 48 | 49 | 50 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/JSPatchPlaygroundDemo/JPRootViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // JSPatchPlayground 4 | // 5 | // Created by bang on 5/14/16. 6 | // Copyright © 2016 bang. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface JPRootViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/JSPatchPlaygroundDemo/JPRootViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // JSPatchPlayground 4 | // 5 | // Created by bang on 5/14/16. 6 | // Copyright © 2016 bang. All rights reserved. 7 | // 8 | 9 | #import "JPRootViewController.h" 10 | #import "JPEngine.h" 11 | #import "JPPlayground.h" 12 | 13 | 14 | 15 | @interface JPRootViewController () 16 | 17 | @end 18 | 19 | @implementation JPRootViewController 20 | 21 | - (void)viewDidLoad { 22 | [super viewDidLoad]; 23 | self.view.backgroundColor = [UIColor whiteColor]; 24 | 25 | 26 | [JPEngine startEngine]; 27 | 28 | 29 | #if TARGET_IPHONE_SIMULATOR 30 | //playground调试 31 | //JS测试包的本地绝对路径 32 | NSString *rootPath = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"projectPath"];; 33 | 34 | NSString *scriptPath = [NSString stringWithFormat:@"%@/js/%@", rootPath, @"/demo.js"]; 35 | [JPPlayground setReloadCompleteHandler:^{ 36 | [self showController]; 37 | }]; 38 | [JPPlayground startPlaygroundWithJSPath:scriptPath]; 39 | 40 | #else 41 | //正常执行JSPatch 42 | NSString *rootPath = [[NSBundle mainBundle] bundlePath]; 43 | NSString *scriptPath = [rootPath stringByAppendingPathComponent:@"demo.js"]; 44 | [JPEngine evaluateScriptWithPath:scriptPath]; 45 | #endif 46 | 47 | 48 | 49 | UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 100, [UIScreen mainScreen].bounds.size.width, 50)]; 50 | [btn setTitle:@"Push Playground" forState:UIControlStateNormal]; 51 | [btn addTarget:self action:@selector(showController) forControlEvents:UIControlEventTouchUpInside]; 52 | [btn setBackgroundColor:[UIColor grayColor]]; 53 | [self.view addSubview:btn]; 54 | } 55 | 56 | 57 | - (void)showController 58 | { 59 | Class clz = NSClassFromString(@"JPDemoController"); 60 | if (clz) { 61 | id vc = [[clz alloc]init]; 62 | [self.navigationController popViewControllerAnimated:NO]; 63 | [self.navigationController pushViewController:vc animated:NO]; 64 | } 65 | } 66 | 67 | 68 | @end 69 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/JSPatchPlaygroundDemo/js/demo.js: -------------------------------------------------------------------------------- 1 | require('UILabel, UIColor, UIFont, UIScreen, UIImageView, UIImage') 2 | 3 | var screenWidth = UIScreen.mainScreen().bounds().width; 4 | var screenHeight = UIScreen.mainScreen().bounds().height; 5 | 6 | defineClass('JPDemoController: UIViewController', { 7 | viewDidLoad: function() { 8 | self.super().viewDidLoad(); 9 | self.view().setBackgroundColor(UIColor.whiteColor()); 10 | var size = 120; 11 | var imgView = UIImageView.alloc().initWithFrame({x: (screenWidth - size)/2, y: 150, width: size, height: size}); 12 | imgView.setImage(UIImage.imageNamed('apple')) 13 | 14 | self.view().addSubview(imgView); 15 | 16 | var label = UILabel.alloc().initWithFrame({x: 0, y: 310, width: screenWidth, height: 30}); 17 | label.setText("JSPatch"); 18 | label.setTextAlignment(1); 19 | label.setFont(UIFont.systemFontOfSize(25)); 20 | self.view().addSubview(label); 21 | }, 22 | }) 23 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/JSPatchPlaygroundDemo/js/demo2.js: -------------------------------------------------------------------------------- 1 | require('UILabel, UIColor, UIFont, UIScreen, UIImageView, UIImage') 2 | 3 | var screenWidtha = UIScreen.mainScreen().bounds().width; 4 | var screenHeighta = UIScreen.mainScreen().bounds().height; 5 | 6 | -------------------------------------------------------------------------------- /JSPatchPlaygroundDemo/JSPatchPlaygroundDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // JSPatchPlaygroundDemo 4 | // 5 | // Created by Awhisper on 16/8/7. 6 | // Copyright © 2016年 baidu. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JSPatchPlaygroundTool 2 | 3 | JSPatch天然能实现playground黑科技一样的效果,什么样的黑科技呢?我们改的每一行代码,每一个语句,完全无需重新运行app,直接能立刻看到效果。 4 | 5 | 并且bang哥已经给出了如何操作和说明 6 | 7 | # JSPatch Playground 8 | 9 | [JSPatch Playground Github](https://github.com/bang590/JSPatch/tree/master/Demo/iOSPlayground) 10 | 11 | 12 | ![Screenshot](https://raw.github.com/bang590/JSPatch/master/Demo/iOSPlayground/Screenshot.gif) 13 | 14 | ## 介绍 15 | 16 | JSPatch Playground 可以让你快速看到 JSPatch 代码执行效果,APP在模拟器运行后,每次修改脚本保存模拟器都会自动刷新,无需重启模拟器,即时看到效果。 17 | 18 | 你也可以仿照 JSPatch Playground 在你的项目里添加 JSPatch 脚本即时刷新功能,帮助你快速使用 JSPatch 开发功能模块。 19 | 20 | Tips: 如果运行过程中脚本执行错误,会在状态栏里显示错误原因,点击状态栏可以看到更详细的错误提示。 21 | 22 | 23 | 24 | # JSPatchPlaygroundTool 25 | 26 | bang哥的Playground工程下面,可以看到想要配置这样一个如此酷炫的黑科技,[JSPatch Playground Github](https://github.com/bang590/JSPatch/tree/master/Demo/iOSPlayground) 项目下的`JPRootViewController.m`文件里面的代码还是挺多的 27 | 28 | 由于前些日子搞了一阵子ReactNative,发现ReactNative下面的Debug,Reload工具很是方便,心想也给JSPatch弄一套,于是就有了这个`JSPatchPlaygroundTool` 29 | 30 | 初衷是,把一整套playground的思路以及环境代码配置,封装成工具,以简洁的API就能轻松运行。 31 | 32 | 33 | 34 | ## JSPatchPlaygroundTool的使用 35 | 36 | 这段代码分成两部分,上半部分就是配置`JSPatchPlaygroundTool`,让JSPatch以Playground的模式进行工作。下半部分则是正常代码,正常的按既有方案加载JSPatch 37 | 38 | ```objectivec 39 | #if TARGET_IPHONE_SIMULATOR 40 | //playground调试 41 | //JS测试包的本地绝对路径 42 | NSString *rootPath = @"/Users/Awhisper/Desktop/Github/JSPatchPlaygroundTool/JSPatchPlaygroundDemo/JSPatchPlaygroundDemo"; 43 | 44 | NSString *scriptRootPath = [rootPath stringByAppendingPathComponent:@"js"]; 45 | NSString *mainScriptPath = [NSString stringWithFormat:@"%@/%@", scriptRootPath, @"demo.js"]; 46 | [JPPlayground setReloadCompleteHandler:^{ 47 | [self showController]; 48 | }]; 49 | [JPPlayground startPlaygroundWithJSPath:mainScriptPath]; 50 | 51 | #else 52 | //正常执行JSPatch 53 | //JS测试包的本地绝对路径 54 | NSString *rootPath = [[NSBundle mainBundle] bundlePath]; 55 | 56 | NSString *scriptPath = [rootPath stringByAppendingPathComponent:@"demo.js"]; 57 | NSString *script = [NSString stringWithContentsOfFile:scriptPath encoding:NSUTF8StringEncoding error:nil]; 58 | [JPEngine evaluateScript:script]; 59 | #endif 60 | 61 | ``` 62 | 63 | 这里只讲解上半部分的API,`rootPath`此处切记输入Mac电脑的mainJS文件所在的路径,我的目录里在工程文件`JSPatchPlaygroundDemo`下专门放了个名字为JS的文件夹,里面放着核心的JS代码逻辑,所以我又补充了`\js\demo.js`作为后缀 64 | 65 | - [JPPlayground setReloadCompleteHandler:block] 66 | 67 | 这个API的意义在于,每次重新刷新JS后,如果有一些额外的想要操作的东西就可以在此时执行,如果没有,这个API完全可以不使用 68 | 69 | - [JPPlayground startPlaygroundWithJSPath:path] 70 | 71 | 72 | 这个API是核心API,输入mainJS的路径后,整个JSPatch将会以playground的模式进行运行 73 | 74 | ## JSPatchPlaygroundTool的效果 75 | 76 | __command + X__:可以打开操作菜单 77 | 78 | ![menu](http://ww2.sinaimg.cn/mw690/678c3e91jw1f6lkzh8zwdj208n0fyaam.jpg) 79 | 80 | 81 | __command + R__:可以ReloadJS 82 | 83 | 当APP在保持运行的时候,我们可以任意修改main.js文件然后进行保存,然后按command+R的组合键,就可以立刻刷新 84 | 85 | __JS Error__:当JS文件有错误,app并不会崩溃,保持持续运行,并且弹出红色界面,详细描述错误信息,当把js文件修改正确后,重新reload,自然就会顺利运行。 86 | 87 | ![error](http://ww2.sinaimg.cn/mw690/678c3e91jw1f6lkzglfruj208n0fyq3t.jpg) 88 | 89 | __AutoReload JS__:Tool可以开启监听JS文件的变化,当你把menu中的这个开关打开,每一次修改js文件进行保存,都会自动触发reload。再次点击这个按钮,会关闭监听,(AutoReload默认不开启) 90 | 91 | __Todo List__:我还想尝试在菜单里面多做2个功能,但并未能找到办法 92 | 93 | - 自动打开Finder,打开JS文件所在的目录,从而能快速找到要修改的JS文件,轻轻松松的开始畅快的JS代码之旅,从此告别编译,运行,重启app的烦躁过程 94 | 95 | - 自动打开Safari的开发者模式,打开正在run的JSContext,从而能对js代码进行断点调试,就好像ReactNative能自动打开chrome一样 96 | 97 | 我没有找到很好的办法,能在iOS框架里面,在模拟器里面,打开Mac上的Mac app,太多的方法都是OSX开发才能使用的库,比如`NSWorkSpace`,这玩意没法在iOS项目里用。发愁 98 | 99 | ## JSPatchPlaygroundTool的目标 100 | 101 | 当使用JSPatch进行一整个功能模块的开发,而不仅仅是只用来修改bug,能像ReactNative一样,run起app后,告别反锁的编译,运行,写出来的代码立刻就生效,代码出错也立刻报出来,丝毫不影响运行,重新修改好后,自然完美运作。 102 | 103 | # JSPatchPlayground的原理 104 | 105 | 之前提到过JSPatch是天然支持这种playground的黑科技玩法的~ 106 | 107 | 原因就在于JSPatch的一个Extension`JPCleaner`,他可以让所有被JSPatch的hook的函数都恢复原样,这样将修改过最新的JS,重新执行以下,就实现了Reload的效果 -------------------------------------------------------------------------------- /Screenshot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Awhisper/JSPatchPlaygroundTool/66ae16c16d5c6c25fdba899590e5f21bd0dccfbf/Screenshot.gif --------------------------------------------------------------------------------