├── JSDebuggerDemo ├── Pods │ ├── Headers │ │ ├── Private │ │ │ └── JSDebugger │ │ │ │ ├── JDLog.h │ │ │ │ ├── JSDebugger.h │ │ │ │ ├── JDEngine.h │ │ │ │ ├── ffi.h │ │ │ │ ├── JDStruct.h │ │ │ │ ├── ffi_arm.h │ │ │ │ ├── JDChoose.h │ │ │ │ ├── JDEncoding.h │ │ │ │ ├── JDEnginePrivate.h │ │ │ │ ├── JDFFIContext.h │ │ │ │ ├── JDPointer.h │ │ │ │ ├── JDProperty.h │ │ │ │ ├── ffi_arm64.h │ │ │ │ ├── ffi_i386.h │ │ │ │ ├── ffitarget.h │ │ │ │ ├── ffi_common.h │ │ │ │ ├── ffi_x86_64.h │ │ │ │ ├── JDFunctionPlugin.h │ │ │ │ ├── JDIntrospect.h │ │ │ │ ├── JDJSTypeToOCType.h │ │ │ │ ├── JDMethodBridge.h │ │ │ │ ├── JDOCTypeToJSType.h │ │ │ │ ├── JDPropertyCache.h │ │ │ │ ├── ffitarget_arm.h │ │ │ │ ├── ffitarget_i386.h │ │ │ │ ├── JDClass4JS.h │ │ │ │ ├── JDFormatJSFunction.h │ │ │ │ ├── JDLocalFileObserver.h │ │ │ │ ├── JDMethod4JS.h │ │ │ │ ├── JDPointer4JS.h │ │ │ │ ├── ffitarget_arm64.h │ │ │ │ ├── ffitarget_x86_64.h │ │ │ │ ├── JDInstance4JS.h │ │ │ │ ├── JDNSStringFromJSString.h │ │ │ │ ├── NSDictionary+JSConvert.h │ │ │ │ └── NSObject+JDRuntimeIntrospection.h │ │ └── Public │ │ │ └── JSDebugger │ │ │ ├── JDEngine.h │ │ │ ├── JSDebugger.h │ │ │ └── JDLocalFileObserver.h │ ├── Target Support Files │ │ ├── JSDebugger │ │ │ ├── JSDebugger-dummy.m │ │ │ ├── JSDebugger-prefix.pch │ │ │ └── JSDebugger.xcconfig │ │ └── Pods-JSDebuggerDemo │ │ │ ├── Pods-JSDebuggerDemo-dummy.m │ │ │ ├── Pods-JSDebuggerDemo.debug.xcconfig │ │ │ ├── Pods-JSDebuggerDemo.release.xcconfig │ │ │ ├── Pods-JSDebuggerDemo-frameworks.sh │ │ │ └── Pods-JSDebuggerDemo-resources.sh │ ├── Manifest.lock │ └── Local Podspecs │ │ └── JSDebugger.podspec.json ├── Podfile ├── JSDebuggerDemo.xcodeproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata ├── JSDebuggerDemo │ ├── ViewController.h │ ├── AppDelegate.h │ ├── main.m │ ├── TestAssociateObject.h │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── TestAssociateObject.m │ ├── Info.plist │ ├── Base.lproj │ │ ├── Main.storyboard │ │ └── LaunchScreen.storyboard │ ├── AppDelegate.m │ └── ViewController.m ├── JSDebuggerDemo.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist ├── Podfile.lock └── demo.js ├── Source ├── Core │ ├── FFI │ │ ├── Vendor │ │ │ ├── libffi.a │ │ │ ├── ffitarget.h │ │ │ ├── ffi.h │ │ │ ├── ffitarget_arm64.h │ │ │ ├── ffitarget_arm.h │ │ │ ├── ffi_common.h │ │ │ ├── ffitarget_x86_64.h │ │ │ ├── ffitarget_i386.h │ │ │ ├── ffi_arm.h │ │ │ ├── ffi_x86_64.h │ │ │ ├── ffi_arm64.h │ │ │ └── ffi_i386.h │ │ └── JDFFIContext.h │ ├── Runtime │ │ ├── JSDefinition │ │ │ ├── JDClass4JS.h │ │ │ ├── JDPointer4JS.h │ │ │ ├── JDInstance4JS.h │ │ │ ├── JDMethod4JS.h │ │ │ ├── JDPointer4JS.m │ │ │ ├── JDClass4JS.m │ │ │ ├── JDMethod4JS.m │ │ │ └── JDInstance4JS.m │ │ ├── JDJSTypeToOCType.h │ │ ├── JDOCTypeToJSType.h │ │ ├── JDPropertyCache.h │ │ ├── JDStruct.h │ │ ├── JDEncoding.h │ │ ├── JDProperty.h │ │ ├── JDMethodBridge.h │ │ ├── JDPropertyCache.m │ │ ├── JDStruct.m │ │ ├── JDMethodBridge.m │ │ ├── JDOCTypeToJSType.m │ │ ├── JDJSTypeToOCType.m │ │ ├── JDEncoding.m │ │ └── JDProperty.m │ ├── Util │ │ ├── JDFormatJSFunction.h │ │ ├── JDNSStringFromJSString.h │ │ ├── JDNSStringFromJSString.m │ │ ├── NSDictionary+JSConvert.h │ │ ├── JDFormatJSFunction.m │ │ └── NSDictionary+JSConvert.m │ ├── Plugin │ │ ├── Plugin │ │ │ ├── JDChoose.h │ │ │ ├── JDIntrospect.h │ │ │ ├── JDIntrospect.mm │ │ │ └── JDChoose.mm │ │ ├── JDFunctionPlugin.h │ │ └── JDFunctionPlugin.m │ ├── Introspect │ │ ├── NSObject+JDRuntimeIntrospection.h │ │ └── NSObject+JDRuntimeIntrospection.m │ ├── JDEngine.h │ ├── JDLog.h │ ├── JDLog.mm │ └── JDEngine.m ├── JSDebugger.modulemap ├── JSDebugger.h └── FileWatcher │ ├── JDLocalFilePresenter.h │ ├── JDLocalFileObserver.h │ ├── JDLocalFilePresenter.m │ └── JDLocalFileObserver.m ├── .github └── FUNDING.yml ├── JSDebugger.podspec ├── .gitignore └── README.md /JSDebuggerDemo/Pods/Headers/Private/JSDebugger/JDLog.h: -------------------------------------------------------------------------------- 1 | ../../../../../Source/Core/JDLog.h -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Headers/Private/JSDebugger/JSDebugger.h: -------------------------------------------------------------------------------- 1 | ../../../../../Source/JSDebugger.h -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Headers/Public/JSDebugger/JDEngine.h: -------------------------------------------------------------------------------- 1 | ../../../../../Source/Core/JDEngine.h -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Headers/Public/JSDebugger/JSDebugger.h: -------------------------------------------------------------------------------- 1 | ../../../../../Source/JSDebugger.h -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Headers/Private/JSDebugger/JDEngine.h: -------------------------------------------------------------------------------- 1 | ../../../../../Source/Core/JDEngine.h -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Headers/Private/JSDebugger/ffi.h: -------------------------------------------------------------------------------- 1 | ../../../../../Source/Core/FFI/Vendor/ffi.h -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Headers/Private/JSDebugger/JDStruct.h: -------------------------------------------------------------------------------- 1 | ../../../../../Source/Core/Runtime/JDStruct.h -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Headers/Private/JSDebugger/ffi_arm.h: -------------------------------------------------------------------------------- 1 | ../../../../../Source/Core/FFI/Vendor/ffi_arm.h -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Headers/Private/JSDebugger/JDChoose.h: -------------------------------------------------------------------------------- 1 | ../../../../../Source/Core/Plugin/Plugin/JDChoose.h -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Headers/Private/JSDebugger/JDEncoding.h: -------------------------------------------------------------------------------- 1 | ../../../../../Source/Core/Runtime/JDEncoding.h -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Headers/Private/JSDebugger/JDEnginePrivate.h: -------------------------------------------------------------------------------- 1 | ../../../../../Source/Core/JDEnginePrivate.h -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Headers/Private/JSDebugger/JDFFIContext.h: -------------------------------------------------------------------------------- 1 | ../../../../../Source/Core/FFI/JDFFIContext.h -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Headers/Private/JSDebugger/JDPointer.h: -------------------------------------------------------------------------------- 1 | ../../../../../Source/Core/Runtime/JDPointer.h -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Headers/Private/JSDebugger/JDProperty.h: -------------------------------------------------------------------------------- 1 | ../../../../../Source/Core/Runtime/JDProperty.h -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Headers/Private/JSDebugger/ffi_arm64.h: -------------------------------------------------------------------------------- 1 | ../../../../../Source/Core/FFI/Vendor/ffi_arm64.h -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Headers/Private/JSDebugger/ffi_i386.h: -------------------------------------------------------------------------------- 1 | ../../../../../Source/Core/FFI/Vendor/ffi_i386.h -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Headers/Private/JSDebugger/ffitarget.h: -------------------------------------------------------------------------------- 1 | ../../../../../Source/Core/FFI/Vendor/ffitarget.h -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Headers/Private/JSDebugger/ffi_common.h: -------------------------------------------------------------------------------- 1 | ../../../../../Source/Core/FFI/Vendor/ffi_common.h -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Headers/Private/JSDebugger/ffi_x86_64.h: -------------------------------------------------------------------------------- 1 | ../../../../../Source/Core/FFI/Vendor/ffi_x86_64.h -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Headers/Private/JSDebugger/JDFunctionPlugin.h: -------------------------------------------------------------------------------- 1 | ../../../../../Source/Core/Plugin/JDFunctionPlugin.h -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Headers/Private/JSDebugger/JDIntrospect.h: -------------------------------------------------------------------------------- 1 | ../../../../../Source/Core/Plugin/Plugin/JDIntrospect.h -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Headers/Private/JSDebugger/JDJSTypeToOCType.h: -------------------------------------------------------------------------------- 1 | ../../../../../Source/Core/Runtime/JDJSTypeToOCType.h -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Headers/Private/JSDebugger/JDMethodBridge.h: -------------------------------------------------------------------------------- 1 | ../../../../../Source/Core/Runtime/JDMethodBridge.h -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Headers/Private/JSDebugger/JDOCTypeToJSType.h: -------------------------------------------------------------------------------- 1 | ../../../../../Source/Core/Runtime/JDOCTypeToJSType.h -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Headers/Private/JSDebugger/JDPropertyCache.h: -------------------------------------------------------------------------------- 1 | ../../../../../Source/Core/Runtime/JDPropertyCache.h -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Headers/Private/JSDebugger/ffitarget_arm.h: -------------------------------------------------------------------------------- 1 | ../../../../../Source/Core/FFI/Vendor/ffitarget_arm.h -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Headers/Private/JSDebugger/ffitarget_i386.h: -------------------------------------------------------------------------------- 1 | ../../../../../Source/Core/FFI/Vendor/ffitarget_i386.h -------------------------------------------------------------------------------- /Source/Core/FFI/Vendor/libffi.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SatanWoo/JSDebugger/HEAD/Source/Core/FFI/Vendor/libffi.a -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Headers/Private/JSDebugger/JDClass4JS.h: -------------------------------------------------------------------------------- 1 | ../../../../../Source/Core/Runtime/JSDefinition/JDClass4JS.h -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Headers/Private/JSDebugger/JDFormatJSFunction.h: -------------------------------------------------------------------------------- 1 | ../../../../../Source/Core/Util/JDFormatJSFunction.h -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Headers/Private/JSDebugger/JDLocalFileObserver.h: -------------------------------------------------------------------------------- 1 | ../../../../../Source/FileWatcher/JDLocalFileObserver.h -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Headers/Private/JSDebugger/JDMethod4JS.h: -------------------------------------------------------------------------------- 1 | ../../../../../Source/Core/Runtime/JSDefinition/JDMethod4JS.h -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Headers/Private/JSDebugger/JDPointer4JS.h: -------------------------------------------------------------------------------- 1 | ../../../../../Source/Core/Runtime/JSDefinition/JDPointer4JS.h -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Headers/Private/JSDebugger/ffitarget_arm64.h: -------------------------------------------------------------------------------- 1 | ../../../../../Source/Core/FFI/Vendor/ffitarget_arm64.h -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Headers/Private/JSDebugger/ffitarget_x86_64.h: -------------------------------------------------------------------------------- 1 | ../../../../../Source/Core/FFI/Vendor/ffitarget_x86_64.h -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Headers/Public/JSDebugger/JDLocalFileObserver.h: -------------------------------------------------------------------------------- 1 | ../../../../../Source/FileWatcher/JDLocalFileObserver.h -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Headers/Private/JSDebugger/JDInstance4JS.h: -------------------------------------------------------------------------------- 1 | ../../../../../Source/Core/Runtime/JSDefinition/JDInstance4JS.h -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Headers/Private/JSDebugger/JDNSStringFromJSString.h: -------------------------------------------------------------------------------- 1 | ../../../../../Source/Core/Util/JDNSStringFromJSString.h -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Headers/Private/JSDebugger/NSDictionary+JSConvert.h: -------------------------------------------------------------------------------- 1 | ../../../../../Source/Core/Util/NSDictionary+JSConvert.h -------------------------------------------------------------------------------- /JSDebuggerDemo/Podfile: -------------------------------------------------------------------------------- 1 | platform :ios, '9.0' 2 | 3 | target 'JSDebuggerDemo' do 4 | pod 'JSDebugger', :path => '../' 5 | end 6 | -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Headers/Private/JSDebugger/NSObject+JDRuntimeIntrospection.h: -------------------------------------------------------------------------------- 1 | ../../../../../Source/Core/Introspect/NSObject+JDRuntimeIntrospection.h -------------------------------------------------------------------------------- /Source/JSDebugger.modulemap: -------------------------------------------------------------------------------- 1 | framework module EasyReact { 2 | umbrella header "JSDebugger.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Target Support Files/JSDebugger/JSDebugger-dummy.m: -------------------------------------------------------------------------------- 1 | #import 2 | @interface PodsDummy_JSDebugger : NSObject 3 | @end 4 | @implementation PodsDummy_JSDebugger 5 | @end 6 | -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Target Support Files/Pods-JSDebuggerDemo/Pods-JSDebuggerDemo-dummy.m: -------------------------------------------------------------------------------- 1 | #import 2 | @interface PodsDummy_Pods_JSDebuggerDemo : NSObject 3 | @end 4 | @implementation PodsDummy_Pods_JSDebuggerDemo 5 | @end 6 | -------------------------------------------------------------------------------- /JSDebuggerDemo/JSDebuggerDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Source/Core/Runtime/JSDefinition/JDClass4JS.h: -------------------------------------------------------------------------------- 1 | // 2 | // JDClass4JS.h 3 | // JSDebugger 4 | // 5 | // Created by z on 2018/9/20. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | @import JavaScriptCore; 10 | 11 | FOUNDATION_EXTERN JSClassRef JDClass4JS(void); 12 | 13 | -------------------------------------------------------------------------------- /Source/Core/Runtime/JSDefinition/JDPointer4JS.h: -------------------------------------------------------------------------------- 1 | // 2 | // JDPointer4JS.h 3 | // JSDebugger 4 | // 5 | // Created by z on 2018/10/1. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | @import JavaScriptCore; 10 | 11 | FOUNDATION_EXTERN JSClassRef JDPointer4JS(void); 12 | -------------------------------------------------------------------------------- /Source/Core/Runtime/JSDefinition/JDInstance4JS.h: -------------------------------------------------------------------------------- 1 | // 2 | // JDInstance4JS.h 3 | // JSDebugger 4 | // 5 | // Created by z on 2018/9/20. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | @import JavaScriptCore; 10 | 11 | FOUNDATION_EXTERN JSClassRef JDInstance4JS(void); 12 | 13 | -------------------------------------------------------------------------------- /JSDebuggerDemo/JSDebuggerDemo/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // JSDebuggerDemo 4 | // 5 | // Created by z on 2018/10/3. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | @end 14 | 15 | -------------------------------------------------------------------------------- /Source/Core/Util/JDFormatJSFunction.h: -------------------------------------------------------------------------------- 1 | // 2 | // JDFormatJSFunction.h 3 | // JSDebugger 4 | // 5 | // Created by z on 2018/9/21. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | @import Foundation; 10 | 11 | FOUNDATION_EXTERN NSString *JDFormatJSFunction(NSString *JSFunctionName); 12 | 13 | -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Target Support Files/JSDebugger/JSDebugger-prefix.pch: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #else 4 | #ifndef FOUNDATION_EXPORT 5 | #if defined(__cplusplus) 6 | #define FOUNDATION_EXPORT extern "C" 7 | #else 8 | #define FOUNDATION_EXPORT extern 9 | #endif 10 | #endif 11 | #endif 12 | 13 | -------------------------------------------------------------------------------- /Source/Core/Runtime/JDJSTypeToOCType.h: -------------------------------------------------------------------------------- 1 | // 2 | // JDJSTypeToOCType.h 3 | // JSDebugger 4 | // 5 | // Created by z on 2018/9/21. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | @import JavaScriptCore; 10 | 11 | FOUNDATION_EXTERN id JDConvertJSValueToNSObject(JSContextRef ctx, JSValueRef value); 12 | -------------------------------------------------------------------------------- /JSDebuggerDemo/JSDebuggerDemo.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /JSDebuggerDemo/JSDebuggerDemo.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Source/Core/Util/JDNSStringFromJSString.h: -------------------------------------------------------------------------------- 1 | // 2 | // JDNSStringFromJSString.h 3 | // JSDebugger 4 | // 5 | // Created by z on 2018/9/21. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | @import JavaScriptCore; 10 | 11 | FOUNDATION_EXTERN NSString *JDCreateNSStringFromJSString(JSContextRef ctx, JSStringRef value); 12 | -------------------------------------------------------------------------------- /Source/Core/Runtime/JSDefinition/JDMethod4JS.h: -------------------------------------------------------------------------------- 1 | // 2 | // JDMethod4JS.h 3 | // JSDebugger 4 | // 5 | // Created by z on 2018/9/20. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | FOUNDATION_EXTERN JSClassRef JDMethod4JS(void); 13 | -------------------------------------------------------------------------------- /Source/Core/FFI/Vendor/ffitarget.h: -------------------------------------------------------------------------------- 1 | #ifdef __arm64__ 2 | 3 | #include "ffitarget_arm64.h" 4 | 5 | 6 | #endif 7 | #ifdef __i386__ 8 | 9 | #include 10 | 11 | 12 | #endif 13 | #ifdef __arm__ 14 | 15 | #include 16 | 17 | 18 | #endif 19 | #ifdef __x86_64__ 20 | 21 | #include "ffitarget_x86_64.h" 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /Source/Core/Runtime/JDOCTypeToJSType.h: -------------------------------------------------------------------------------- 1 | // 2 | // JDOCTypeToJSType.h 3 | // JSDebugger 4 | // 5 | // Created by z on 2018/9/21. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | #include 10 | 11 | FOUNDATION_EXTERN JSValueRef JDConvertNSObjectToJSValue(JSContextRef ctx, NSObject *object); 12 | 13 | 14 | -------------------------------------------------------------------------------- /Source/Core/Plugin/Plugin/JDChoose.h: -------------------------------------------------------------------------------- 1 | // 2 | // JDChoose.h 3 | // JSDebugger 4 | // 5 | // Created by z on 2018/9/20. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "JDFunctionPlugin.h" 11 | 12 | @interface JDChoose : NSObject 13 | + (NSArray *)choose:(Class)aClass; 14 | @end 15 | -------------------------------------------------------------------------------- /JSDebuggerDemo/JSDebuggerDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // JSDebuggerDemo 4 | // 5 | // Created by z on 2018/10/3. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | @end 16 | 17 | -------------------------------------------------------------------------------- /Source/Core/Plugin/Plugin/JDIntrospect.h: -------------------------------------------------------------------------------- 1 | // 2 | // JDIntrospect.h 3 | // JSDebugger 4 | // 5 | // Created by z on 2018/9/21. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "JDFunctionPlugin.h" 11 | 12 | @interface JDIntrospect : NSObject 13 | + (NSArray *)introspect:(id)_obj; 14 | @end 15 | -------------------------------------------------------------------------------- /Source/Core/Introspect/NSObject+JDRuntimeIntrospection.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSObject+JDRuntimeIntrospection.h 3 | // JSDebugger 4 | // 5 | // Created by JunyiXie on 2/10/2018. 6 | // 7 | 8 | #import 9 | 10 | NS_ASSUME_NONNULL_BEGIN 11 | 12 | @interface NSObject (JDRuntimeIntrospection) 13 | 14 | - (NSArray *)jd_logAllProperties; 15 | 16 | @end 17 | 18 | NS_ASSUME_NONNULL_END 19 | -------------------------------------------------------------------------------- /JSDebuggerDemo/JSDebuggerDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // JSDebuggerDemo 4 | // 5 | // Created by z on 2018/10/3. 6 | // Copyright © 2018年 SatanWoo. 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 | -------------------------------------------------------------------------------- /JSDebuggerDemo/JSDebuggerDemo/TestAssociateObject.h: -------------------------------------------------------------------------------- 1 | // 2 | // TestAssociateObject.h 3 | // JSDebuggerDemo 4 | // 5 | // Created by z on 2018/10/8. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface TestAssociateObject : NSObject 12 | 13 | @end 14 | 15 | @interface TestAssociateObject(Associate) 16 | @property (nonatomic) NSInteger associateInt; 17 | @end 18 | -------------------------------------------------------------------------------- /JSDebuggerDemo/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - JSDebugger (0.1.0): 3 | - JSDebugger/no-arc (= 0.1.0) 4 | - JSDebugger/no-arc (0.1.0) 5 | 6 | DEPENDENCIES: 7 | - JSDebugger (from `../`) 8 | 9 | EXTERNAL SOURCES: 10 | JSDebugger: 11 | :path: ../ 12 | 13 | SPEC CHECKSUMS: 14 | JSDebugger: bb08522a58114f014ae779817d9ff9ec5283e735 15 | 16 | PODFILE CHECKSUM: 2af29c4cf26aa230154c1a6d404fe181391e705f 17 | 18 | COCOAPODS: 1.3.1 19 | -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Manifest.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - JSDebugger (0.1.0): 3 | - JSDebugger/no-arc (= 0.1.0) 4 | - JSDebugger/no-arc (0.1.0) 5 | 6 | DEPENDENCIES: 7 | - JSDebugger (from `../`) 8 | 9 | EXTERNAL SOURCES: 10 | JSDebugger: 11 | :path: ../ 12 | 13 | SPEC CHECKSUMS: 14 | JSDebugger: bb08522a58114f014ae779817d9ff9ec5283e735 15 | 16 | PODFILE CHECKSUM: 2af29c4cf26aa230154c1a6d404fe181391e705f 17 | 18 | COCOAPODS: 1.3.1 19 | -------------------------------------------------------------------------------- /Source/Core/FFI/JDFFIContext.h: -------------------------------------------------------------------------------- 1 | // 2 | // JDFFIContext.h 3 | // JSDebugger 4 | // 5 | // Created by z on 2018/9/21. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | @import JavaScriptCore; 10 | 11 | @class JDMethodBridge; 12 | 13 | FOUNDATION_EXTERN JSValueRef JDCallFunction(JSContextRef ctx, JDMethodBridge *methodBridge, 14 | size_t argumentCount, const JSValueRef arguments[]); 15 | 16 | -------------------------------------------------------------------------------- /Source/JSDebugger.h: -------------------------------------------------------------------------------- 1 | // 2 | // JSDebugger.h 3 | // Pods 4 | // 5 | // Created by JunyiXie on 2/10/2018. 6 | // 7 | 8 | @import Foundation; 9 | 10 | //! Project version number for Expecta. 11 | FOUNDATION_EXPORT double JSDebuggerVersionNumber; 12 | 13 | //! Project version string for Expecta. 14 | FOUNDATION_EXPORT const unsigned char JSDebuggerVersionString[]; 15 | 16 | #import 17 | #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /Source/Core/Util/JDNSStringFromJSString.m: -------------------------------------------------------------------------------- 1 | // 2 | // JDNSStringFromJSString.m 3 | // JSDebugger 4 | // 5 | // Created by z on 2018/9/21. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | #import "JDNSStringFromJSString.h" 10 | 11 | NSString *JDCreateNSStringFromJSString(JSContextRef ctx, JSStringRef value) 12 | { 13 | CFStringRef ref = JSStringCopyCFString(kCFAllocatorDefault, (JSStringRef)value); 14 | NSString *string = (__bridge_transfer NSString *)ref; 15 | return string; 16 | } 17 | -------------------------------------------------------------------------------- /Source/Core/JDEngine.h: -------------------------------------------------------------------------------- 1 | // 2 | // JDEngine.h 3 | // JSDebugger 4 | // 5 | // Created by z on 2018/9/20. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | @import Foundation; 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface JDEngine : NSObject 14 | 15 | + (JDEngine *)engine; 16 | 17 | - (void)start; 18 | 19 | - (void)evaluateScript:(NSString *)scriptContent; 20 | - (void)evaluateScriptAtPath:(NSString *)path; 21 | 22 | //- (instancetype)init NS_UNAVAILABLE; 23 | 24 | @end 25 | 26 | NS_ASSUME_NONNULL_END 27 | -------------------------------------------------------------------------------- /Source/Core/Runtime/JDPropertyCache.h: -------------------------------------------------------------------------------- 1 | // 2 | // JDPropertyCache.h 3 | // JSDebugger 4 | // 5 | // Created by z on 2018/9/23. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | @import Foundation; 10 | 11 | @class JDPropertiesInClass; 12 | 13 | NS_ASSUME_NONNULL_BEGIN 14 | 15 | @interface JDPropertyCache : NSObject 16 | 17 | - (instancetype)initWithCapacity:(NSInteger)capacity; 18 | 19 | - (void)addProperty:(JDPropertiesInClass *)pic forClass:(Class)cls; 20 | - (JDPropertiesInClass *)propertiesForClass:(Class)cls; 21 | 22 | @end 23 | 24 | NS_ASSUME_NONNULL_END 25 | -------------------------------------------------------------------------------- /Source/FileWatcher/JDLocalFilePresenter.h: -------------------------------------------------------------------------------- 1 | // 2 | // JSLocalFilePresenter.h 3 | // Pods 4 | // 5 | // Created by z on 2018/11/4. 6 | // 7 | // 8 | 9 | #import 10 | 11 | @class JDLocalFilePresenter; 12 | 13 | @protocol JDLocalFilePresenterDelegate 14 | - (void)fileDidChangeAtURL:(NSURL *)URL inPresenter:(JDLocalFilePresenter *)presenter; 15 | @end 16 | 17 | @interface JDLocalFilePresenter : NSObject 18 | @property (nonatomic, weak) id delegate; 19 | - (instancetype)initWithFile:(NSString *)localJSPath; 20 | @end 21 | -------------------------------------------------------------------------------- /Source/Core/Runtime/JDStruct.h: -------------------------------------------------------------------------------- 1 | // 2 | // JDStruct.h 3 | // JSDebugger 4 | // 5 | // Created by z on 2018/9/22. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | @import JavaScriptCore; 10 | @import Foundation; 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | FOUNDATION_EXTERN NSString *JDGetStructName(const char *c); 15 | 16 | @interface JDStruct : NSObject 17 | 18 | + (void)define:(NSDictionary *)structDef name:(NSString *)structName; 19 | + (NSDictionary *)structDefintion:(NSString *)structName; 20 | 21 | + (void)setupDefaultStruct; 22 | 23 | @end 24 | 25 | NS_ASSUME_NONNULL_END 26 | -------------------------------------------------------------------------------- /Source/FileWatcher/JDLocalFileObserver.h: -------------------------------------------------------------------------------- 1 | // 2 | // WZLocalFileObserver.h 3 | // WZDB 4 | // 5 | // Created by z on 2018/1/6. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | @import Foundation; 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | typedef void (^JDFileChangeBlock)(void); 14 | 15 | @interface JDLocalFileObserver : NSObject 16 | 17 | - (instancetype)initWithFilePath:(NSString *)filePath 18 | changeBlock:(nullable JDFileChangeBlock)change NS_DESIGNATED_INITIALIZER; 19 | 20 | - (void)start; 21 | - (void)stop; 22 | 23 | - (instancetype)init NS_UNAVAILABLE; 24 | + (instancetype)new NS_UNAVAILABLE; 25 | 26 | @end 27 | 28 | NS_ASSUME_NONNULL_END 29 | -------------------------------------------------------------------------------- /Source/Core/Runtime/JSDefinition/JDPointer4JS.m: -------------------------------------------------------------------------------- 1 | // 2 | // JDPointer4JS.m 3 | // JSDebugger 4 | // 5 | // Created by z on 2018/10/1. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | #import "JDPointer4JS.h" 10 | 11 | JSClassRef JDPointer4JS(void) 12 | { 13 | static dispatch_once_t onceToken; 14 | static JSClassRef pointerRef = nil; 15 | dispatch_once(&onceToken, ^{ 16 | JSClassDefinition pointerDefinition; 17 | pointerDefinition = kJSClassDefinitionEmpty; 18 | pointerDefinition.className = "JDPointer4JS"; 19 | //pointerDefinition.callAsFunction = &JDMethodCallAsFunction; 20 | pointerRef = JSClassCreate(&pointerDefinition); 21 | }); 22 | return pointerRef; 23 | } 24 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /Source/Core/Util/NSDictionary+JSConvert.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSDictionary+GeoConvert.h 3 | // WZDB 4 | // 5 | // Created by z on 2018/3/29. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | @import Foundation; 10 | 11 | // Not Fully Supported 12 | // Only CGRect, CGPoint, CGSize are convertiable temporarily 13 | NS_ASSUME_NONNULL_BEGIN 14 | 15 | @interface NSDictionary (JSConvert) 16 | 17 | - (CGRect)jd_rectValue; 18 | - (BOOL)jd_convertToRect:(CGRect *)rect; 19 | - (BOOL)jd_canConvertToRect; 20 | 21 | - (CGPoint)jd_pointValue; 22 | - (BOOL)jd_convertToPoint:(CGPoint *)point; 23 | - (BOOL)jd_canConvertToPoint; 24 | 25 | - (CGSize)jd_sizeValue; 26 | - (BOOL)jd_convertToSize:(CGSize *)size; 27 | - (BOOL)jd_canConvertToSize; 28 | 29 | @end 30 | 31 | NS_ASSUME_NONNULL_END 32 | -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Target Support Files/Pods-JSDebuggerDemo/Pods-JSDebuggerDemo.debug.xcconfig: -------------------------------------------------------------------------------- 1 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 2 | HEADER_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/JSDebugger" 3 | LIBRARY_SEARCH_PATHS = $(inherited) "$PODS_CONFIGURATION_BUILD_DIR/JSDebugger" "${PODS_ROOT}/../../Source/Core/FFI/Vendor" 4 | OTHER_CFLAGS = $(inherited) -isystem "${PODS_ROOT}/Headers/Public" -isystem "${PODS_ROOT}/Headers/Public/JSDebugger" 5 | OTHER_LDFLAGS = $(inherited) -ObjC -l"JSDebugger" -l"c++" -l"ffi" -framework "JavaScriptCore" 6 | PODS_BUILD_DIR = $BUILD_DIR 7 | PODS_CONFIGURATION_BUILD_DIR = $PODS_BUILD_DIR/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 8 | PODS_PODFILE_DIR_PATH = ${SRCROOT}/. 9 | PODS_ROOT = ${SRCROOT}/Pods 10 | -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Target Support Files/Pods-JSDebuggerDemo/Pods-JSDebuggerDemo.release.xcconfig: -------------------------------------------------------------------------------- 1 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 2 | HEADER_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/JSDebugger" 3 | LIBRARY_SEARCH_PATHS = $(inherited) "$PODS_CONFIGURATION_BUILD_DIR/JSDebugger" "${PODS_ROOT}/../../Source/Core/FFI/Vendor" 4 | OTHER_CFLAGS = $(inherited) -isystem "${PODS_ROOT}/Headers/Public" -isystem "${PODS_ROOT}/Headers/Public/JSDebugger" 5 | OTHER_LDFLAGS = $(inherited) -ObjC -l"JSDebugger" -l"c++" -l"ffi" -framework "JavaScriptCore" 6 | PODS_BUILD_DIR = $BUILD_DIR 7 | PODS_CONFIGURATION_BUILD_DIR = $PODS_BUILD_DIR/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 8 | PODS_PODFILE_DIR_PATH = ${SRCROOT}/. 9 | PODS_ROOT = ${SRCROOT}/Pods 10 | -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Target Support Files/JSDebugger/JSDebugger.xcconfig: -------------------------------------------------------------------------------- 1 | CONFIGURATION_BUILD_DIR = $PODS_CONFIGURATION_BUILD_DIR/JSDebugger 2 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 3 | HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Private/JSDebugger" "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/JSDebugger" 4 | LIBRARY_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/../../Source/Core/FFI/Vendor" 5 | OTHER_LDFLAGS = -l"c++" -l"ffi" -framework "JavaScriptCore" 6 | PODS_BUILD_DIR = $BUILD_DIR 7 | PODS_CONFIGURATION_BUILD_DIR = $PODS_BUILD_DIR/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 8 | PODS_ROOT = ${SRCROOT} 9 | PODS_TARGET_SRCROOT = ${PODS_ROOT}/../.. 10 | PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.${PRODUCT_NAME:rfc1034identifier} 11 | SKIP_INSTALL = YES 12 | -------------------------------------------------------------------------------- /JSDebuggerDemo/JSDebuggerDemo/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 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /Source/Core/JDLog.h: -------------------------------------------------------------------------------- 1 | // 2 | // JDLog.h 3 | // JSDebugger 4 | // 5 | // Created by z on 2018/9/21. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | #ifndef JDLog_h 10 | #define JDLog_h 11 | 12 | #ifdef DEBUG 13 | #define JDLog(FORMAT, ...) fprintf(stderr,"time:%s line:%d filename:%s\tmethod:%s\n%s\n", __TIME__,__LINE__,[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String],__func__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]) 14 | #else 15 | #define JDLog(FORMAT, ...) nil 16 | #endif 17 | 18 | #endif /* JDLog_h */ 19 | 20 | #import 21 | 22 | NS_ASSUME_NONNULL_BEGIN 23 | 24 | @interface JDLog : NSObject 25 | + (JDLog *)shared; 26 | - (void)outputLog:(NSString *)logstr; 27 | /// Specify the output file 28 | @property (nonatomic, strong) NSString *filePath; 29 | @end 30 | 31 | NS_ASSUME_NONNULL_END 32 | -------------------------------------------------------------------------------- /JSDebuggerDemo/JSDebuggerDemo/TestAssociateObject.m: -------------------------------------------------------------------------------- 1 | // 2 | // TestAssociateObject.m 3 | // JSDebuggerDemo 4 | // 5 | // Created by z on 2018/10/8. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | #import "TestAssociateObject.h" 10 | #import 11 | 12 | 13 | @implementation TestAssociateObject 14 | 15 | @end 16 | 17 | @implementation TestAssociateObject(Associate) 18 | 19 | - (void)setAssociateInt:(NSInteger)associateInt 20 | { 21 | NSNumber *number = @(associateInt); 22 | objc_setAssociatedObject(self, @selector(associateInt), number, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 23 | } 24 | 25 | - (NSInteger)associateInt 26 | { 27 | NSNumber *number = objc_getAssociatedObject(self, _cmd); 28 | if (![number isKindOfClass:[NSNumber class]]) { 29 | return NSNotFound; 30 | } 31 | return [number integerValue]; 32 | } 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /Source/Core/Plugin/JDFunctionPlugin.h: -------------------------------------------------------------------------------- 1 | // 2 | // JDFunctionPlugin.h 3 | // JSDebugger 4 | // 5 | // Created by z on 2018/9/21. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #define JD_REGISTER_PLUGIN(IMP, NAME) \ 12 | FOUNDATION_EXTERN void JDRegisterPlugin(Class pluginClass); \ 13 | + (void)load {JDRegisterPlugin(self);} \ 14 | - (NSString *)key {return @NAME;} \ 15 | - (JSObjectCallAsFunctionCallback)function {return IMP;} 16 | 17 | NS_ASSUME_NONNULL_BEGIN 18 | 19 | @protocol JDFunctionPlugin 20 | 21 | @required 22 | - (JSObjectCallAsFunctionCallback)function; 23 | - (NSString *)key; 24 | 25 | @end 26 | 27 | @interface JDFunctionPluginManager : NSObject 28 | 29 | + (JDFunctionPluginManager *)pluginManager; 30 | 31 | - (void)addPlugin:(id)plugin; 32 | - (void)registerPluginsIntoContext:(JSContextRef)ctx; 33 | 34 | @end 35 | 36 | NS_ASSUME_NONNULL_END 37 | -------------------------------------------------------------------------------- /Source/Core/Util/JDFormatJSFunction.m: -------------------------------------------------------------------------------- 1 | // 2 | // JDFormatJSFunction.m 3 | // JSDebugger 4 | // 5 | // Created by z on 2018/9/21. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | #import "JDFormatJSFunction.h" 10 | 11 | NSString *JDFormatJSFunction(NSString *JSFunctionName) 12 | { 13 | NSArray *components = [JSFunctionName componentsSeparatedByString:@"_"]; 14 | 15 | NSMutableString *actualMethodName = [[NSMutableString alloc] init]; 16 | for (NSString *temp in components) { 17 | if (temp.length > 0) { 18 | [actualMethodName appendString:temp]; 19 | [actualMethodName appendString:@":"]; 20 | } 21 | } 22 | 23 | NSString *formattedName = actualMethodName.copy; 24 | if (components.count <= 1) { 25 | formattedName = [actualMethodName stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@":"]]; 26 | } 27 | 28 | return formattedName; 29 | } 30 | -------------------------------------------------------------------------------- /Source/Core/Runtime/JDEncoding.h: -------------------------------------------------------------------------------- 1 | // 2 | // JDEncoding.h 3 | // JSDebugger 4 | // 5 | // Created by z on 2018/9/21. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | @import Foundation; 10 | 11 | typedef NS_ENUM(NSUInteger) { 12 | JDEncodingVoid = 0, 13 | JDEncodingBool, 14 | JDEncodingInt8, 15 | JDEncodingUInt8, 16 | JDEncodingInt16, 17 | JDEncodingUInt16, 18 | JDEncodingInt32, 19 | JDEncodingUInt32, 20 | JDEncodingInt64, 21 | JDEncodingUInt64, 22 | JDEncodingFloat, 23 | JDEncodingDouble, 24 | JDEncodingLongDouble, 25 | JDEncodingClass, 26 | JDEncodingSEL, 27 | JDEncodingCString, 28 | JDEncodingPointer, 29 | JDEncodingCArray, 30 | JDEncodingUnion, 31 | JDEncodingStruct, 32 | JDEncodingBlock, 33 | JDEncodingObject, 34 | JDEncodingUnknown 35 | } JDEncoding; 36 | 37 | FOUNDATION_EXTERN JDEncoding JDGetEncoding(const char *c); 38 | 39 | FOUNDATION_EXTERN size_t JDSizeOfEncoding(JDEncoding encoding, NSString *structName); 40 | -------------------------------------------------------------------------------- /Source/Core/JDLog.mm: -------------------------------------------------------------------------------- 1 | // 2 | // JDFLog.m 3 | // JSDebugger 4 | // 5 | // Created by JunyiXie on 3/10/2018. 6 | // 7 | 8 | #import "JDLog.h" 9 | #import 10 | 11 | static std::ofstream _JDOut; 12 | @implementation JDLog 13 | 14 | + (JDLog *)shared 15 | { 16 | static dispatch_once_t onceToken; 17 | static JDLog *_log; 18 | dispatch_once(&onceToken, ^{ 19 | _log = [[JDLog alloc] init]; 20 | }); 21 | return _log; 22 | } 23 | 24 | - (void)dealloc 25 | { 26 | _JDOut.close(); 27 | } 28 | 29 | - (instancetype)init { 30 | if (self = [super init]) { 31 | if ([_filePath isEqualToString:@""] || _filePath == nil) { 32 | _filePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:@"JDOut.log"]; 33 | } 34 | JDLog(@"JDOut.log path: %@",_filePath); 35 | _JDOut.open(_filePath.UTF8String,std::ios::out | std::ios::ate); 36 | } 37 | return self; 38 | } 39 | 40 | #pragma mark Log 41 | - (void)outputLog:(NSString *)logstr { 42 | _JDOut << logstr.UTF8String << std::endl; 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /Source/FileWatcher/JDLocalFilePresenter.m: -------------------------------------------------------------------------------- 1 | // 2 | // JSLocalFilePresenter.m 3 | // Pods 4 | // 5 | // Created by z on 2018/11/4. 6 | // 7 | // 8 | 9 | #import "JDLocalFilePresenter.h" 10 | 11 | @interface JDLocalFilePresenter() 12 | @property (nonatomic, copy) NSString *filePath; 13 | @end 14 | 15 | @implementation JDLocalFilePresenter 16 | 17 | - (instancetype)initWithFile:(NSString *)localJSPath 18 | { 19 | self = [super init]; 20 | if (self) { 21 | _filePath = [localJSPath stringByResolvingSymlinksInPath]; 22 | } 23 | return self; 24 | } 25 | 26 | #pragma mark - NSFilePresenter 27 | - (NSURL *)presentedItemURL 28 | { 29 | return [NSURL fileURLWithPath:self.filePath]; 30 | } 31 | 32 | - (NSOperationQueue *)presentedItemOperationQueue 33 | { 34 | return [NSOperationQueue mainQueue]; 35 | } 36 | 37 | - (void)presentedItemDidChange 38 | { 39 | if (self.delegate && [self.delegate respondsToSelector:@selector(fileDidChangeAtURL:inPresenter:)]) { 40 | [self.delegate fileDidChangeAtURL:[self presentedItemURL] inPresenter:self]; 41 | } 42 | } 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /Source/Core/Runtime/JDProperty.h: -------------------------------------------------------------------------------- 1 | // 2 | // JDProperty.h 3 | // JSDebugger 4 | // 5 | // Created by z on 2018/9/23. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | @import ObjectiveC.runtime; 10 | #import "JDEncoding.h" 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | @interface JDProperty : NSObject 15 | 16 | @property (nonatomic, readonly) BOOL readonly; 17 | @property (nonatomic, readonly) JDEncoding encoding; 18 | 19 | @property (nonatomic, copy, readonly) NSString *setterName; 20 | @property (nonatomic, copy, readonly) NSString *getterName; 21 | @property (nonatomic, copy, readonly) NSString *propertyName; 22 | 23 | - (instancetype)init NS_UNAVAILABLE; 24 | + (instancetype)new NS_UNAVAILABLE; 25 | - (nullable instancetype)initWithProperty:(objc_property_t)property NS_DESIGNATED_INITIALIZER; 26 | 27 | @end 28 | 29 | @interface JDPropertiesInClass : NSObject 30 | 31 | - (instancetype)init NS_UNAVAILABLE; 32 | + (instancetype)new NS_UNAVAILABLE; 33 | - (nullable instancetype)initWithClass:(Class)cls; 34 | 35 | - (NSArray *)properties; 36 | 37 | @end 38 | 39 | NS_ASSUME_NONNULL_END 40 | -------------------------------------------------------------------------------- /Source/Core/Runtime/JDMethodBridge.h: -------------------------------------------------------------------------------- 1 | // 2 | // JDMethodBridge.h 3 | // JSDebugger 4 | // 5 | // Created by z on 2018/9/21. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | #import "JDEncoding.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface JDParameter : NSObject 14 | 15 | @property (nonatomic) JDEncoding encoding; 16 | @property (nonatomic) NSString *paramterName; 17 | 18 | @end 19 | 20 | @interface JDMethodBridge : NSObject 21 | 22 | @property (nonatomic, readonly, strong) JDParameter *returnType; 23 | @property (nonatomic, readonly, copy) NSArray *argumentsType; 24 | @property (nonatomic, readonly, weak) id instance; 25 | @property (nonatomic, readonly) SEL selector; 26 | @property (nonatomic, readonly) IMP imp; 27 | 28 | - (instancetype)init NS_UNAVAILABLE; 29 | + (instancetype)new NS_UNAVAILABLE; 30 | 31 | - (instancetype)initWithSignature:(NSMethodSignature *)signature 32 | selector:(SEL)selector 33 | instace:(id)ins 34 | imp:(IMP)imp NS_DESIGNATED_INITIALIZER; 35 | 36 | @end 37 | 38 | NS_ASSUME_NONNULL_END 39 | -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Local Podspecs/JSDebugger.podspec.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "JSDebugger", 3 | "version": "0.1.0", 4 | "summary": "JavaScript-Based Debugger For Inspecting Running State Of Your Application", 5 | "description": "JavaScript-Based Debugger For Inspecting Running State Of Your Application", 6 | "homepage": "https://github.com/SatanWoo/JSDebugger", 7 | "license": { 8 | "type": "GPL", 9 | "file": "LICENSE" 10 | }, 11 | "authors": { 12 | "SatanWoo": "xxx@xxx.com" 13 | }, 14 | "source": { 15 | "git": "https://github.com/SatanWoo/JSDebugger.git", 16 | "tag": "0.1.0" 17 | }, 18 | "platforms": { 19 | "ios": "9.0" 20 | }, 21 | "module_map": "Source/JSDebugger.modulemap", 22 | "frameworks": [ 23 | "JavaScriptCore" 24 | ], 25 | "libraries": "c++", 26 | "requires_arc": true, 27 | "exclude_files": "Source/Core/Plugin/Plugin/JDChoose.mm", 28 | "source_files": "Source/**/*", 29 | "public_header_files": [ 30 | "Source/FileWatcher/*.h", 31 | "Source/Core/JDEngine.h", 32 | "Source/JSDebugger.h" 33 | ], 34 | "vendored_libraries": "Source/Core/FFI/Vendor/libffi.a", 35 | "subspecs": [ 36 | { 37 | "name": "no-arc", 38 | "source_files": "Source/Core/Plugin/Plugin/JDChoose.mm", 39 | "requires_arc": false 40 | } 41 | ] 42 | } 43 | -------------------------------------------------------------------------------- /JSDebugger.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = 'JSDebugger' 3 | s.version = '0.1.0' 4 | s.summary = 'JavaScript-Based Debugger For Inspecting Running State Of Your Application' 5 | 6 | s.description = <<-DESC 7 | JavaScript-Based Debugger For Inspecting Running State Of Your Application 8 | DESC 9 | 10 | s.homepage = 'https://github.com/SatanWoo/JSDebugger' 11 | s.license = { :type => 'GPL', :file => 'LICENSE' } 12 | s.author = { 'SatanWoo' => 'xxx@xxx.com' } 13 | s.source = { :git => 'https://github.com/SatanWoo/JSDebugger.git', :tag => s.version.to_s } 14 | 15 | s.ios.deployment_target = '9.0' 16 | s.platform = :ios, '9.0' 17 | s.module_map = 'Source/JSDebugger.modulemap' 18 | s.frameworks = ["JavaScriptCore"] 19 | s.libraries = 'c++' 20 | 21 | s.requires_arc = true 22 | s.exclude_files = 'Source/Core/Plugin/Plugin/JDChoose.mm' 23 | 24 | s.subspec 'no-arc' do |smrc| 25 | smrc.source_files = 'Source/Core/Plugin/Plugin/JDChoose.mm' 26 | smrc.requires_arc = false 27 | end 28 | 29 | s.source_files = 'Source/**/*' 30 | s.public_header_files = ['Source/FileWatcher/*.h', 'Source/Core/JDEngine.h', 'Source/JSDebugger.h'] 31 | s.vendored_libraries = 'Source/Core/FFI/Vendor/libffi.a' 32 | 33 | end 34 | -------------------------------------------------------------------------------- /JSDebuggerDemo/JSDebuggerDemo/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 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /Source/Core/Runtime/JDPropertyCache.m: -------------------------------------------------------------------------------- 1 | // 2 | // JDPropertyCache.m 3 | // JSDebugger 4 | // 5 | // Created by z on 2018/9/23. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | #import "JDPropertyCache.h" 10 | #import "JDProperty.h" 11 | 12 | const NSUInteger JDDefaultPropertyCacheCapacity = 20; 13 | 14 | @interface JDPropertyCache() 15 | 16 | @property (nonatomic, strong) NSMapTable *clsToProperties; 17 | 18 | @end 19 | 20 | @implementation JDPropertyCache 21 | 22 | - (instancetype)init 23 | { 24 | if (self = [self initWithCapacity:JDDefaultPropertyCacheCapacity]) { 25 | 26 | } 27 | return self; 28 | } 29 | 30 | - (instancetype)initWithCapacity:(NSInteger)capacity 31 | { 32 | self = [super init]; 33 | if (self) { 34 | _clsToProperties = [[NSMapTable alloc] initWithKeyOptions:NSPointerFunctionsWeakMemory 35 | valueOptions:NSPointerFunctionsStrongMemory capacity:capacity]; 36 | } 37 | return self; 38 | } 39 | 40 | #pragma mark - Public API 41 | - (void)addProperty:(JDPropertiesInClass *)pic forClass:(Class)cls 42 | { 43 | if (!pic) { return; } 44 | [self.clsToProperties setObject:pic forKey:cls]; 45 | } 46 | 47 | - (JDPropertiesInClass *)propertiesForClass:(Class)cls 48 | { 49 | return [self.clsToProperties objectForKey:cls]; 50 | } 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /Source/FileWatcher/JDLocalFileObserver.m: -------------------------------------------------------------------------------- 1 | // 2 | // WZLocalFileObserver.m 3 | // WZDB 4 | // 5 | // Created by z on 2018/1/6. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | #import "JDLocalFileObserver.h" 10 | #import "JDLocalFilePresenter.h" 11 | 12 | @interface JDLocalFileObserver() 13 | 14 | @property (nonatomic, copy) JDFileChangeBlock changeBlock; 15 | @property (nonatomic, copy) NSString *filePath; 16 | @property (nonatomic, strong) JDLocalFilePresenter *presenter; 17 | 18 | @end 19 | 20 | @implementation JDLocalFileObserver 21 | 22 | - (instancetype)initWithFilePath:(NSString *)filePath changeBlock:(JDFileChangeBlock)change 23 | { 24 | self = [super init]; 25 | if (self) { 26 | _filePath = [filePath copy]; 27 | _changeBlock = [change copy]; 28 | 29 | _presenter = [[JDLocalFilePresenter alloc] initWithFile:_filePath]; 30 | _presenter.delegate = self; 31 | } 32 | return self; 33 | } 34 | 35 | - (void)start 36 | { 37 | [NSFileCoordinator addFilePresenter:self.presenter]; 38 | } 39 | 40 | - (void)stop 41 | { 42 | [NSFileCoordinator removeFilePresenter:self.presenter]; 43 | } 44 | 45 | #pragma mark - JDLocalFilePresenterDelegate 46 | - (void)fileDidChangeAtURL:(NSURL *)URL inPresenter:(JDLocalFilePresenter *)presenter 47 | { 48 | if (self.changeBlock) self.changeBlock(); 49 | } 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /Source/Core/Plugin/Plugin/JDIntrospect.mm: -------------------------------------------------------------------------------- 1 | // 2 | // JDIntrospect.m 3 | // JSDebugger 4 | // 5 | // Created by z on 2018/9/21. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | #import "JDIntrospect.h" 10 | 11 | #import "JDOCTypeToJSType.h" 12 | #import "JDLog.h" 13 | #import "NSObject+JDRuntimeIntrospection.h" 14 | #import 15 | #import 16 | #import "JDLog.h" 17 | 18 | static JSValueRef introspect(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) 19 | { 20 | if (argumentCount != 1) { 21 | JDLog(@"introspect() takes a class argument"); 22 | return NULL; 23 | } 24 | 25 | JSValueRef value = arguments[0]; 26 | JSObjectRef objectRef = const_cast(value); 27 | id obj = (__bridge id)(JSObjectGetPrivate(objectRef)); 28 | if (!obj) return JSObjectMakeArray(ctx, 0, NULL, exception); 29 | 30 | NSArray *result = [JDIntrospect introspect:obj]; 31 | return JDConvertNSObjectToJSValue(ctx, result); 32 | } 33 | 34 | 35 | @implementation JDIntrospect 36 | 37 | JD_REGISTER_PLUGIN(&introspect, "introspect"); 38 | 39 | + (NSArray *)introspect:(id)_obj 40 | { 41 | NSArray *result = [_obj jd_logAllProperties]; 42 | [[JDLog shared] outputLog:[NSString stringWithFormat:@"%@", result]]; 43 | 44 | return result; 45 | } 46 | 47 | @end 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /Source/Core/Runtime/JSDefinition/JDClass4JS.m: -------------------------------------------------------------------------------- 1 | // 2 | // JDClass4JS.m 3 | // JSDebugger 4 | // 5 | // Created by z on 2018/9/20. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | #import "JDClass4JS.h" 10 | #import "JDMethod4JS.h" 11 | #import "JDFormatJSFunction.h" 12 | #import "JDClass4JS.h" 13 | @import ObjectiveC.runtime; 14 | 15 | static JSValueRef JDClassGetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) { 16 | CFStringRef ref = JSStringCopyCFString(kCFAllocatorDefault, propertyName); 17 | NSString *property = (__bridge NSString *)ref; 18 | 19 | id ocClass = (__bridge Class)(JSObjectGetPrivate(object)); 20 | if (!ocClass) { 21 | CFRelease(ref); 22 | return JSValueMakeUndefined(ctx); 23 | } 24 | 25 | SEL sel = NSSelectorFromString(JDFormatJSFunction(property)); 26 | Method m = class_getClassMethod(ocClass, sel); 27 | if (!m) { 28 | CFRelease(ref); 29 | return JSValueMakeUndefined(ctx); 30 | } 31 | 32 | CFRelease(ref); 33 | return JSObjectMake(ctx, JDMethod4JS(), (void *)sel); 34 | } 35 | 36 | JSClassRef JDClass4JS() 37 | { 38 | static dispatch_once_t onceToken; 39 | static JSClassRef classRef = nil; 40 | dispatch_once(&onceToken, ^{ 41 | JSClassDefinition classDefinition; 42 | classDefinition = kJSClassDefinitionEmpty; 43 | classDefinition.className = "JDClass4JS"; 44 | classDefinition.getProperty = &JDClassGetProperty; 45 | classRef = JSClassCreate(&classDefinition); 46 | }); 47 | return classRef; 48 | } 49 | 50 | 51 | -------------------------------------------------------------------------------- /JSDebuggerDemo/demo.js: -------------------------------------------------------------------------------- 1 | 2 | // Variadic Arguments in Core Foundation Method 3 | var array = NSArray.arrayWithObjects_(72, 2, 3); 4 | 5 | // Variaidc Arugments In Your-Defined Method 6 | ViewController.test_(1, 2, 4, 7); 7 | 8 | // Custom Class Methods 9 | ViewController.printNSArray_(array); 10 | 11 | // Invalid Function Call Cause JSException And Leads To Stop Evaluating Script 12 | // ViewController.testStr_value_("wuziqi niubi", 1.0, 2.0, 7.0); 13 | 14 | // Choose 15 | var label = choose(UILabel)[0]; 16 | 17 | // Setter 18 | label.text = "WZQTQL"; 19 | 20 | // Using Method Insteat Of Getter 21 | var tex = label.text(); 22 | 23 | var vc = choose(ViewController)[0]; 24 | 25 | // Instance Method 26 | vc.printName_(tex); 27 | 28 | // Chainable Calling Method 29 | vc.view().setBackgroundColor_(UIColor.redColor()); 30 | 31 | // Struct 32 | var frame = vc.view().frame(); 33 | 34 | frame.origin.x = 100; 35 | 36 | vc.view().frame = frame; 37 | 38 | // Treat Struct As A Plain JavaScript Object 39 | label.frame = {origin:{x:0, y:10}, size:{width:200, height:100}}; 40 | 41 | // Pointer 42 | var intP = vc.allocAddressWithInt(); 43 | vc.testIntPointer_(intP); 44 | 45 | var doubleP = vc.allocAddressWithDouble(); 46 | vc.testDoublePointer_(doubleP); 47 | 48 | var charP = vc.allocAddressWithChar(); 49 | vc.testCString_(charP); 50 | 51 | // AssociateObject 52 | var aso = TestAssociateObject.alloc().init(); 53 | vc.associateObject = aso; 54 | vc.print(); 55 | 56 | aso.associateInt = 5; 57 | 58 | vc.print(); 59 | 60 | // Get AssoicateObject Directly 61 | var asovalu = aso.associateInt; 62 | 63 | vc.printNumb_(asovalu); 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xccheckout 23 | *.xcscmblueprint 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | *.ipa 28 | *.dSYM.zip 29 | *.dSYM 30 | 31 | # CocoaPods 32 | # 33 | # We recommend against adding the Pods directory to your .gitignore. However 34 | # you should judge for yourself, the pros and cons are mentioned at: 35 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 36 | # 37 | JSDebuggerDemo/Pods/ 38 | 39 | # Carthage 40 | # 41 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 42 | # Carthage/Checkouts 43 | 44 | Carthage/Build 45 | 46 | # fastlane 47 | # 48 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 49 | # screenshots whenever they are needed. 50 | # For more information about the recommended setup visit: 51 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 52 | 53 | fastlane/report.xml 54 | fastlane/Preview.html 55 | fastlane/screenshots/**/*.png 56 | fastlane/test_output 57 | 58 | # Code Injection 59 | # 60 | # After new code Injection tools there's a generated folder /iOSInjectionProject 61 | # https://github.com/johnno1962/injectionforxcode 62 | 63 | iOSInjectionProject/ 64 | -------------------------------------------------------------------------------- /JSDebuggerDemo/JSDebuggerDemo/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 | 27 | -------------------------------------------------------------------------------- /JSDebuggerDemo/JSDebuggerDemo/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 | -------------------------------------------------------------------------------- /Source/Core/FFI/Vendor/ffi.h: -------------------------------------------------------------------------------- 1 | /* -----------------------------------------------------------------*-C-*- 2 | libffi 3.2.1 - Copyright (c) 2011, 2014 Anthony Green 3 | - Copyright (c) 1996-2003, 2007, 2008 Red Hat, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person 6 | obtaining a copy of this software and associated documentation 7 | files (the ``Software''), to deal in the Software without 8 | restriction, including without limitation the rights to use, copy, 9 | modify, merge, publish, distribute, sublicense, and/or sell copies 10 | of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to 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 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 | 27 | /* ------------------------------------------------------------------- 28 | libffi-iOS is built based on libffi-3.2.1, provides universal library 29 | (i386, x86_64, armv7, arm64), both ffi_call and ffi_closure are fully 30 | tested. 31 | https://github.com/sunnyxx/libffi-iOS 32 | by sunnyxx 33 | -------------------------------------------------------------------- */ 34 | 35 | #ifdef __arm64__ 36 | #include 37 | #endif 38 | 39 | #ifdef __i386__ 40 | #include 41 | #endif 42 | 43 | #ifdef __arm__ 44 | #include 45 | #endif 46 | 47 | #ifdef __x86_64__ 48 | #include "ffi_x86_64.h" 49 | #endif 50 | -------------------------------------------------------------------------------- /Source/Core/Runtime/JDStruct.m: -------------------------------------------------------------------------------- 1 | // 2 | // JDStruct.m 3 | // JSDebugger 4 | // 5 | // Created by z on 2018/9/22. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | #import "JDStruct.h" 10 | 11 | static NSMutableDictionary *structInfo = nil; 12 | 13 | NSString *JDGetStructName(const char *c) 14 | { 15 | NSString *typeEncodeString = [NSString stringWithUTF8String:c]; 16 | 17 | NSArray *array = [typeEncodeString componentsSeparatedByString:@"="]; 18 | NSString *typeString = array[0]; 19 | int firstValidIndex = 0; 20 | for (int i = 0; i< typeString.length; i++) { 21 | char c = [typeString characterAtIndex:i]; 22 | if (c == '{' || c=='_') { 23 | firstValidIndex++; 24 | } else { 25 | break; 26 | } 27 | } 28 | return [typeString substringFromIndex:firstValidIndex]; 29 | } 30 | 31 | @implementation JDStruct 32 | 33 | + (void)initialize 34 | { 35 | if ([self class] == [JDStruct class]) { 36 | structInfo = @{}.mutableCopy; 37 | } 38 | } 39 | 40 | + (void)define:(NSDictionary *)structDef name:(NSString *)structName 41 | { 42 | if (!structDef || structName.length <= 0) { return; } 43 | [structInfo setObject:structDef forKey:structName]; 44 | } 45 | 46 | + (NSDictionary *)structDefintion:(NSString *)structName 47 | { 48 | return structInfo[structName]; 49 | } 50 | 51 | + (void)setupDefaultStruct 52 | { 53 | [self define:@{@"def":@[ 54 | @{@"type":@"{CGPoint}", @"keyword":@"origin"}, 55 | @{@"type":@"{CGSize}", @"keyword":@"size"} 56 | ]} 57 | name:@"CGRect"]; 58 | 59 | [self define:@{@"def": 60 | @[@{@"type":@"F", @"keyword":@"x"}, 61 | @{@"type":@"F", @"keyword":@"y"} 62 | ]} 63 | name:@"CGPoint"]; 64 | 65 | [self define:@{@"def": 66 | @[@{@"type":@"F", @"keyword":@"width"}, 67 | @{@"type":@"F", @"keyword":@"height"} 68 | ]} 69 | name:@"CGSize"]; 70 | } 71 | 72 | @end 73 | -------------------------------------------------------------------------------- /JSDebuggerDemo/JSDebuggerDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // JSDebuggerDemo 4 | // 5 | // Created by z on 2018/10/3. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 18 | { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application 24 | { 25 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 26 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 27 | } 28 | 29 | - (void)applicationDidEnterBackground:(UIApplication *)application 30 | { 31 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 32 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 33 | } 34 | 35 | - (void)applicationWillEnterForeground:(UIApplication *)application 36 | { 37 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 38 | } 39 | 40 | - (void)applicationDidBecomeActive:(UIApplication *)application 41 | { 42 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 43 | } 44 | 45 | - (void)applicationWillTerminate:(UIApplication *)application 46 | { 47 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 48 | } 49 | 50 | @end 51 | -------------------------------------------------------------------------------- /Source/Core/Plugin/JDFunctionPlugin.m: -------------------------------------------------------------------------------- 1 | // 2 | // JDFunctionPlugin.m 3 | // JSDebugger 4 | // 5 | // Created by z on 2018/9/21. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | #import "JDFunctionPlugin.h" 10 | 11 | void JDRegisterPlugin(Class pluginClass) 12 | { 13 | [[JDFunctionPluginManager pluginManager] addPlugin:[[pluginClass alloc] init]]; 14 | } 15 | 16 | @interface JDFunctionPluginManager() 17 | 18 | @property (nonatomic, strong) NSMutableArray *plugins; 19 | 20 | @end 21 | 22 | @implementation JDFunctionPluginManager 23 | 24 | + (JDFunctionPluginManager *)pluginManager 25 | { 26 | static dispatch_once_t onceToken; 27 | static JDFunctionPluginManager *_pluginManager; 28 | dispatch_once(&onceToken, ^{ 29 | _pluginManager = [[JDFunctionPluginManager alloc] init]; 30 | }); 31 | return _pluginManager; 32 | } 33 | 34 | - (void)addPlugin:(id)plugin 35 | { 36 | NSParameterAssert(plugin); 37 | if (!plugin) { return; } 38 | if (![plugin conformsToProtocol:NSProtocolFromString(@"JDFunctionPlugin")]) { return; } 39 | 40 | [self.plugins addObject:plugin]; 41 | } 42 | 43 | - (void)registerPluginsIntoContext:(JSContextRef)ctx 44 | { 45 | NSCParameterAssert(ctx); 46 | if (ctx == NULL) { 47 | return; 48 | } 49 | 50 | JSObjectRef global = JSContextGetGlobalObject(ctx); 51 | 52 | for (id plugin in self.plugins) { 53 | if ([plugin respondsToSelector:@selector(function)] && 54 | [plugin respondsToSelector:@selector(key)]) { 55 | 56 | JSStringRef functionJSName = JSStringCreateWithUTF8CString([plugin key].UTF8String); 57 | JSObjectSetProperty(ctx, 58 | global, 59 | functionJSName, 60 | JSObjectMakeFunctionWithCallback(ctx, functionJSName, [plugin function]), 61 | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete, NULL); 62 | JSStringRelease(functionJSName); 63 | } 64 | } 65 | } 66 | 67 | #pragma mark - Getter 68 | - (NSMutableArray *)plugins 69 | { 70 | if (!_plugins) { 71 | _plugins = @[].mutableCopy; 72 | } 73 | return _plugins; 74 | } 75 | 76 | @end 77 | -------------------------------------------------------------------------------- /Source/Core/Runtime/JDMethodBridge.m: -------------------------------------------------------------------------------- 1 | // 2 | // JDMethodBridge.m 3 | // JSDebugger 4 | // 5 | // Created by z on 2018/9/21. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | #import "JDMethodBridge.h" 10 | #import "JDEncoding.h" 11 | #import "JDStruct.h" 12 | 13 | @implementation JDParameter 14 | @end 15 | 16 | #pragma mark - JDMethodBridge 17 | 18 | @interface JDMethodBridge() 19 | 20 | @property (nonatomic, readwrite, strong) JDParameter *returnType; 21 | @property (nonatomic, readwrite, copy) NSArray *argumentsType; 22 | @property (nonatomic, readwrite, weak) id instance; 23 | @property (nonatomic, readwrite) IMP imp; 24 | @property (nonatomic, readwrite) SEL selector; 25 | 26 | @end 27 | 28 | @implementation JDMethodBridge 29 | 30 | - (instancetype)initWithSignature:(NSMethodSignature *)signature selector:(SEL)selector instace:(id)ins imp:(IMP)imp 31 | { 32 | NSParameterAssert(signature); 33 | self = [super init]; 34 | if (self) { 35 | _instance = ins; 36 | _imp = imp; 37 | _selector = selector; 38 | NSUInteger numberOfArguments = signature.numberOfArguments; 39 | NSMutableArray *argumentsList = [[NSMutableArray alloc] init]; 40 | 41 | for (NSUInteger i = 0; i < numberOfArguments; i++) { 42 | @autoreleasepool { 43 | const char *argumentType = [signature getArgumentTypeAtIndex:i]; 44 | JDEncoding encoding = JDGetEncoding(argumentType); 45 | 46 | JDParameter *p = [JDParameter new]; 47 | if (encoding == JDEncodingStruct) { 48 | NSString *structName = JDGetStructName(argumentType); 49 | p.paramterName = structName; 50 | } 51 | 52 | p.encoding = encoding; 53 | [argumentsList addObject:p]; 54 | } 55 | } 56 | 57 | _argumentsType = argumentsList.copy; 58 | 59 | const char *returnType = [signature methodReturnType]; 60 | JDEncoding returnEncoding = JDGetEncoding(returnType); 61 | JDParameter *returnP = [JDParameter new]; 62 | returnP.encoding = returnEncoding; 63 | 64 | if (returnEncoding == JDEncodingStruct) { 65 | returnP.paramterName = JDGetStructName(returnType); 66 | } 67 | 68 | _returnType = returnP; 69 | } 70 | 71 | return self; 72 | } 73 | 74 | @end 75 | -------------------------------------------------------------------------------- /Source/Core/Runtime/JSDefinition/JDMethod4JS.m: -------------------------------------------------------------------------------- 1 | // 2 | // JDMethod4JS.m 3 | // JSDebugger 4 | // 5 | // Created by z on 2018/9/20. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | #import "JDMethod4JS.h" 10 | #import "JDClass4JS.h" 11 | #import "JDInstance4JS.h" 12 | #import "JDMethodBridge.h" 13 | #import "JDFFIContext.h" 14 | @import ObjectiveC.runtime; 15 | 16 | static JSValueRef JDMethodCallAsFunction(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) 17 | { 18 | SEL sel = JSObjectGetPrivate(function); 19 | 20 | Class toSearchClass = nil; 21 | id candidate = nil; 22 | 23 | if (JSValueIsObjectOfClass(ctx, thisObject, JDClass4JS())) { 24 | Class cls = (__bridge Class)JSObjectGetPrivate(thisObject); 25 | if (!cls) { return JSValueMakeUndefined(ctx); } 26 | 27 | toSearchClass = object_getClass(cls); 28 | candidate = cls; 29 | } else if (JSValueIsObjectOfClass(ctx, thisObject, JDInstance4JS())) { 30 | id instance = (__bridge id)(JSObjectGetPrivate(thisObject)); 31 | if (!instance) { return JSValueMakeUndefined(ctx); } 32 | 33 | toSearchClass = [instance class]; 34 | candidate = instance; 35 | } 36 | 37 | if (!toSearchClass) { return JSValueMakeUndefined(ctx); } 38 | 39 | Method m = class_getInstanceMethod(toSearchClass, sel); 40 | if (!m) { return JSValueMakeUndefined(ctx); } 41 | 42 | IMP imp = method_getImplementation(m); 43 | 44 | NSMethodSignature *methodSignature = [candidate methodSignatureForSelector:sel]; 45 | JDMethodBridge *methodBridge = [[JDMethodBridge alloc] initWithSignature:methodSignature 46 | selector:sel 47 | instace:candidate 48 | imp:imp]; 49 | return JDCallFunction(ctx, methodBridge, argumentCount, arguments); 50 | } 51 | 52 | JSClassRef JDMethod4JS() 53 | { 54 | static dispatch_once_t onceToken; 55 | static JSClassRef methodRef = nil; 56 | dispatch_once(&onceToken, ^{ 57 | JSClassDefinition methodDefinition; 58 | methodDefinition = kJSClassDefinitionEmpty; 59 | methodDefinition.className = "JDClass4JS"; 60 | methodDefinition.callAsFunction = &JDMethodCallAsFunction; 61 | methodRef = JSClassCreate(&methodDefinition); 62 | }); 63 | return methodRef; 64 | } 65 | -------------------------------------------------------------------------------- /Source/Core/FFI/Vendor/ffitarget_arm64.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2009, 2010, 2011, 2012 ARM Ltd. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | ``Software''), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | #ifndef LIBFFI_TARGET_H 23 | #define LIBFFI_TARGET_H 24 | 25 | #ifndef LIBFFI_H 26 | #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead." 27 | #endif 28 | 29 | #ifndef LIBFFI_ASM 30 | #ifdef __ILP32__ 31 | #define FFI_SIZEOF_ARG 8 32 | #define FFI_SIZEOF_JAVA_RAW 4 33 | typedef unsigned long long ffi_arg; 34 | typedef signed long long ffi_sarg; 35 | #else 36 | typedef unsigned long ffi_arg; 37 | typedef signed long ffi_sarg; 38 | #endif 39 | 40 | typedef enum ffi_abi 41 | { 42 | FFI_FIRST_ABI = 0, 43 | FFI_SYSV, 44 | FFI_LAST_ABI, 45 | FFI_DEFAULT_ABI = FFI_SYSV 46 | } ffi_abi; 47 | #endif 48 | 49 | /* ---- Definitions for closures ----------------------------------------- */ 50 | 51 | #define FFI_CLOSURES 1 52 | #define FFI_NATIVE_RAW_API 0 53 | 54 | #if defined (FFI_EXEC_TRAMPOLINE_TABLE) && FFI_EXEC_TRAMPOLINE_TABLE 55 | 56 | #ifdef __MACH__ 57 | #define FFI_TRAMPOLINE_SIZE 16 58 | #define FFI_TRAMPOLINE_CLOSURE_OFFSET 16 59 | #else 60 | #error "No trampoline table implementation" 61 | #endif 62 | 63 | #else 64 | #define FFI_TRAMPOLINE_SIZE 24 65 | #define FFI_TRAMPOLINE_CLOSURE_OFFSET FFI_TRAMPOLINE_SIZE 66 | #endif 67 | 68 | /* ---- Internal ---- */ 69 | 70 | #if defined (__APPLE__) 71 | #define FFI_TARGET_SPECIFIC_VARIADIC 72 | #define FFI_EXTRA_CIF_FIELDS unsigned aarch64_nfixedargs 73 | #else 74 | /* iOS reserves x18 for the system. Disable Go closures until 75 | a new static chain is chosen. */ 76 | #define FFI_GO_CLOSURES 1 77 | #endif 78 | 79 | #define FFI_TARGET_HAS_COMPLEX_TYPE 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /Source/Core/FFI/Vendor/ffitarget_arm.h: -------------------------------------------------------------------------------- 1 | /* -----------------------------------------------------------------*-C-*- 2 | ffitarget.h - Copyright (c) 2012 Anthony Green 3 | Copyright (c) 2010 CodeSourcery 4 | Copyright (c) 1996-2003 Red Hat, Inc. 5 | 6 | Target configuration macros for ARM. 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining 9 | a copy of this software and associated documentation files (the 10 | ``Software''), to deal in the Software without restriction, including 11 | without limitation the rights to use, copy, modify, merge, publish, 12 | distribute, sublicense, and/or sell copies of the Software, and to 13 | permit persons to whom the Software is furnished to do so, subject to 14 | the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included 17 | in all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, 20 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26 | DEALINGS IN THE SOFTWARE. 27 | 28 | ----------------------------------------------------------------------- */ 29 | 30 | #ifndef LIBFFI_TARGET_H 31 | #define LIBFFI_TARGET_H 32 | 33 | #ifndef LIBFFI_H 34 | #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead." 35 | #endif 36 | 37 | #ifndef LIBFFI_ASM 38 | typedef unsigned long ffi_arg; 39 | typedef signed long ffi_sarg; 40 | 41 | typedef enum ffi_abi { 42 | FFI_FIRST_ABI = 0, 43 | FFI_SYSV, 44 | FFI_VFP, 45 | FFI_LAST_ABI, 46 | #ifdef __ARM_PCS_VFP 47 | FFI_DEFAULT_ABI = FFI_VFP, 48 | #else 49 | FFI_DEFAULT_ABI = FFI_SYSV, 50 | #endif 51 | } ffi_abi; 52 | #endif 53 | 54 | #define FFI_EXTRA_CIF_FIELDS \ 55 | int vfp_used; \ 56 | unsigned short vfp_reg_free, vfp_nargs; \ 57 | signed char vfp_args[16] \ 58 | 59 | #define FFI_TARGET_SPECIFIC_VARIADIC 60 | #define FFI_TARGET_HAS_COMPLEX_TYPE 61 | 62 | /* ---- Definitions for closures ----------------------------------------- */ 63 | 64 | #define FFI_CLOSURES 1 65 | #define FFI_GO_CLOSURES 1 66 | #define FFI_NATIVE_RAW_API 0 67 | 68 | #if defined (FFI_EXEC_TRAMPOLINE_TABLE) && FFI_EXEC_TRAMPOLINE_TABLE 69 | 70 | #ifdef __MACH__ 71 | #define FFI_TRAMPOLINE_SIZE 12 72 | #define FFI_TRAMPOLINE_CLOSURE_OFFSET 8 73 | #else 74 | #error "No trampoline table implementation" 75 | #endif 76 | 77 | #else 78 | #define FFI_TRAMPOLINE_SIZE 12 79 | #define FFI_TRAMPOLINE_CLOSURE_OFFSET FFI_TRAMPOLINE_SIZE 80 | #endif 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /Source/Core/Util/NSDictionary+JSConvert.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSDictionary+GeoConvert.m 3 | // WZDB 4 | // 5 | // Created by z on 2018/3/29. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | #import "NSDictionary+JSConvert.h" 10 | 11 | #if CGFLOAT_IS_DOUBLE 12 | 13 | #define CGFloatValue doubleValue 14 | 15 | #else 16 | 17 | #define CGFloatValue floatValue 18 | 19 | #endif 20 | 21 | @implementation NSDictionary (JSConvert) 22 | 23 | #pragma mark - CGRect 24 | 25 | - (CGRect)jd_rectValue 26 | { 27 | assert([self.allKeys containsObject:@"origin"]); 28 | assert([self.allKeys containsObject:@"size"]); 29 | 30 | CGRect rect; 31 | 32 | rect.origin.x = [self[@"origin"][@"x"] CGFloatValue]; 33 | rect.origin.y = [self[@"origin"][@"y"] CGFloatValue]; 34 | 35 | rect.size.width = [self[@"size"][@"width"] CGFloatValue]; 36 | rect.size.height = [self[@"size"][@"height"] CGFloatValue]; 37 | 38 | return rect; 39 | } 40 | 41 | - (BOOL)jd_convertToRect:(CGRect *)rect 42 | { 43 | if (rect == NULL) { return NO; } 44 | if (![self.allKeys containsObject:@"origin"]) { return NO; } 45 | if (![self.allKeys containsObject:@"size"]) { return NO; } 46 | 47 | CGRect value = [self jd_rectValue]; 48 | rect->origin = value.origin; 49 | rect->size = value.size; 50 | 51 | return YES; 52 | } 53 | 54 | - (BOOL)jd_canConvertToRect 55 | { 56 | CGRect rect; 57 | return [self jd_convertToRect:&rect]; 58 | } 59 | 60 | #pragma mark - CGPoint 61 | 62 | - (CGPoint)jd_pointValue 63 | { 64 | assert([self.allKeys containsObject:@"x"]); 65 | assert([self.allKeys containsObject:@"y"]); 66 | 67 | CGPoint p; 68 | p.x = [self[@"x"] CGFloatValue]; 69 | p.y = [self[@"y"] CGFloatValue]; 70 | 71 | return p; 72 | } 73 | 74 | - (BOOL)jd_convertToPoint:(CGPoint *)point 75 | { 76 | if (point == NULL) { return NO; } 77 | if (![self.allKeys containsObject:@"x"]) { return NO; } 78 | if (![self.allKeys containsObject:@"y"]) { return NO; } 79 | 80 | CGPoint p = [self jd_pointValue]; 81 | 82 | point->x = p.x; 83 | point->y = p.y; 84 | 85 | return YES; 86 | } 87 | 88 | - (BOOL)jd_canConvertToPoint 89 | { 90 | CGPoint point; 91 | return [self jd_convertToPoint:&point]; 92 | } 93 | 94 | #pragma mark - CGSize 95 | 96 | - (CGSize)jd_sizeValue 97 | { 98 | assert([self.allKeys containsObject:@"width"]); 99 | assert([self.allKeys containsObject:@"height"]); 100 | 101 | CGSize size; 102 | size.width = [self[@"width"] CGFloatValue]; 103 | size.height = [self[@"height"] CGFloatValue]; 104 | 105 | return size; 106 | } 107 | 108 | - (BOOL)jd_convertToSize:(CGSize *)size 109 | { 110 | if (size == NULL) return NO; 111 | if (![self.allKeys containsObject:@"width"]) { return NO; } 112 | if (![self.allKeys containsObject:@"height"]) { return NO; } 113 | 114 | size->width = [self[@"width"] CGFloatValue]; 115 | size->height = [self[@"height"] CGFloatValue]; 116 | return YES; 117 | } 118 | 119 | - (BOOL)jd_canConvertToSize 120 | { 121 | CGSize size; 122 | return [self jd_convertToSize:&size]; 123 | } 124 | 125 | @end 126 | -------------------------------------------------------------------------------- /Source/Core/Runtime/JDOCTypeToJSType.m: -------------------------------------------------------------------------------- 1 | // 2 | // JDOCTypeToJSType.m 3 | // JSDebugger 4 | // 5 | // Created by z on 2018/9/21. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | #import "JDOCTypeToJSType.h" 10 | #import "JDClass4JS.h" 11 | #import "JDInstance4JS.h" 12 | #import "JDMethod4JS.h" 13 | #import "JDPointer4JS.h" 14 | 15 | @import ObjectiveC.objc; 16 | @import ObjectiveC.runtime; 17 | 18 | static bool isBooleanClass(NSNumber *number) 19 | { 20 | if (![number isKindOfClass:[NSNumber class]]) { return false; } 21 | return [number class] == [@(YES) class]; 22 | } 23 | 24 | JSValueRef JDConvertNSObjectToJSValue(JSContextRef ctx, NSObject *object) 25 | { 26 | if (!object) { return JSValueMakeUndefined(ctx); } 27 | 28 | Class cls = object_getClass(object); 29 | 30 | Protocol *jsExportProtocol = objc_getProtocol("JSExport"); 31 | 32 | if (!class_conformsToProtocol(cls, jsExportProtocol)) { 33 | if ([object isKindOfClass:[NSArray class]]) { 34 | NSArray *array = (NSArray *)object; 35 | JSValueRef *values = (JSValueRef *)malloc(sizeof(JSValueRef) * array.count); 36 | 37 | for (NSUInteger i = 0; i < array.count; i++) { 38 | values[i] = JDConvertNSObjectToJSValue(ctx, array[i]); 39 | } 40 | 41 | JSObjectRef jsArray = JSObjectMakeArray(ctx, array.count, values, NULL); 42 | free(values); 43 | 44 | return jsArray; 45 | } else if ([object isKindOfClass:[NSDictionary class]]) { 46 | NSData *data = [NSJSONSerialization dataWithJSONObject:object options:NSJSONWritingPrettyPrinted error:nil]; 47 | NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 48 | JSStringRef stringRef = JSStringCreateWithUTF8CString(string.UTF8String); 49 | JSValueRef value = JSValueMakeFromJSONString(ctx, stringRef); 50 | JSStringRelease(stringRef); 51 | return value; 52 | 53 | } else if ([object isKindOfClass:[NSNumber class]]) { 54 | if (isBooleanClass((NSNumber *)object)) return JSValueMakeBoolean(ctx, [(NSNumber *)object boolValue]); 55 | return JSValueMakeNumber(ctx, [(NSNumber *)object doubleValue]); 56 | 57 | } else if ([object isKindOfClass:[NSString class]]) { 58 | JSStringRef string = JSStringCreateWithCFString((__bridge CFStringRef)(NSString *)object); 59 | JSValueRef js = JSValueMakeString(ctx, string); 60 | JSStringRelease(string); 61 | return js; 62 | 63 | } else if ([object isKindOfClass:[NSDate class]]) { 64 | JSValueRef argument = JSValueMakeNumber(ctx, [(NSDate *)object timeIntervalSince1970]); 65 | return JSObjectMakeDate(ctx, 1, &argument, 0); 66 | 67 | } else if ([object isKindOfClass:[NSNull class]]) { 68 | return JSValueMakeNull(ctx); 69 | } else if ([object isKindOfClass:[NSValue class]]) { 70 | NSValue *value = (NSValue *)object; 71 | SEL sel = (SEL)[value pointerValue]; 72 | 73 | BOOL isMapped = sel_isMapped(sel); 74 | if (isMapped) return JSObjectMake(ctx, JDMethod4JS(), (void *)sel); 75 | return JSObjectMake(ctx, JDPointer4JS(), [value pointerValue]); 76 | } 77 | } 78 | 79 | if (class_isMetaClass(cls)) { 80 | return JSObjectMake(ctx, JDClass4JS(), (__bridge void *)cls); 81 | } else { 82 | return JSObjectMake(ctx, JDInstance4JS(), (__bridge void *)object); 83 | } 84 | } 85 | 86 | -------------------------------------------------------------------------------- /Source/Core/Runtime/JDJSTypeToOCType.m: -------------------------------------------------------------------------------- 1 | // 2 | // JDJSTypeToOCType.m 3 | // JSDebugger 4 | // 5 | // Created by z on 2018/9/21. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | #import "JDJSTypeToOCType.h" 10 | #import "JDNSStringFromJSString.h" 11 | #import "JDClass4JS.h" 12 | #import "JDInstance4JS.h" 13 | #import "JDMethod4JS.h" 14 | 15 | id JDConvertJSValueToNSObject(JSContextRef ctx, JSValueRef value) 16 | { 17 | JSType type = JSValueGetType(ctx, value); 18 | 19 | switch(type) { 20 | case kJSTypeString:{ 21 | JSStringRef s = JSValueToStringCopy(ctx, value, NULL); 22 | NSString *str = JDCreateNSStringFromJSString(ctx, s); 23 | JSStringRelease(s); 24 | return str; 25 | } 26 | case kJSTypeBoolean: { return [NSNumber numberWithBool:JSValueToBoolean(ctx, value)]; } 27 | case kJSTypeNumber: { return [NSNumber numberWithDouble:JSValueToNumber(ctx, value, NULL)]; } 28 | case kJSTypeNull: { return [NSNull null]; } 29 | case kJSTypeUndefined: { return nil; } 30 | case kJSTypeObject: break; 31 | } 32 | 33 | if (type == kJSTypeObject) { 34 | 35 | if (JSValueIsDate(ctx, value)) { 36 | double val = JSValueToNumber(ctx, value, NULL); 37 | NSDate *date = [NSDate dateWithTimeIntervalSince1970:val / 1000.0f]; 38 | return date; 39 | 40 | } else if (JSValueIsArray(ctx, value)) { 41 | JSStringRef lengthName = JSStringCreateWithUTF8CString("length"); 42 | int count = JSValueToNumber(ctx, JSObjectGetProperty(ctx, (JSObjectRef)value, lengthName, NULL), NULL); 43 | JSStringRelease(lengthName); 44 | 45 | NSMutableArray *array = [NSMutableArray arrayWithCapacity:count]; 46 | for( int i = 0; i < count; i++ ) { 47 | NSObject *obj = JDConvertJSValueToNSObject(ctx, JSObjectGetPropertyAtIndex(ctx, (JSObjectRef)value, i, NULL)); 48 | array[i] = obj ?: [NSNull null]; 49 | } 50 | 51 | return array.copy; 52 | } 53 | 54 | else { 55 | // @SatanWoo First Check Is Self-Defined Class 56 | if (JSValueIsObjectOfClass(ctx, value, JDClass4JS())) { 57 | Class cls = (__bridge Class)JSObjectGetPrivate((JSObjectRef)value); 58 | return cls; 59 | } else if (JSValueIsObjectOfClass(ctx, value, JDInstance4JS())) { 60 | id instance = (__bridge id)JSObjectGetPrivate((JSObjectRef)value); 61 | return instance; 62 | } else if (JSValueIsObjectOfClass(ctx, value, JDMethod4JS())) { 63 | SEL sel = (SEL)JSObjectGetPrivate((JSObjectRef)value); 64 | return [NSValue valueWithPointer:sel]; 65 | } 66 | 67 | // @SatanWoo Then regard it as plain object and convert it to NSDictionary 68 | JSPropertyNameArrayRef properties = JSObjectCopyPropertyNames(ctx, (JSObjectRef)value); 69 | size_t count = JSPropertyNameArrayGetCount(properties); 70 | 71 | NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:count]; 72 | for( size_t i = 0; i < count; i++ ) { 73 | JSStringRef jsName = JSPropertyNameArrayGetNameAtIndex(properties, i); 74 | NSObject *obj = JDConvertJSValueToNSObject(ctx, JSObjectGetProperty(ctx, (JSObjectRef)value, jsName, NULL)); 75 | 76 | NSString *name = JDCreateNSStringFromJSString(ctx, jsName); 77 | dict[name] = obj ? obj : NSNull.null; 78 | } 79 | 80 | JSPropertyNameArrayRelease(properties); 81 | return dict; 82 | } 83 | } 84 | 85 | return nil; 86 | } 87 | -------------------------------------------------------------------------------- /JSDebuggerDemo/JSDebuggerDemo/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // JSDebuggerDemo 4 | // 5 | // Created by z on 2018/10/3. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "TestAssociateObject.h" 11 | #import 12 | #import 13 | 14 | @interface ViewController () 15 | { 16 | char *testStr; 17 | } 18 | 19 | @property (nonatomic, strong) UILabel *testLabel; 20 | @property (nonatomic, strong) JDLocalFileObserver *fileWatcher; 21 | @property (nonatomic, strong) TestAssociateObject *associateObject; 22 | @property (nonatomic) int testInt; 23 | @property (nonatomic) double testDouble; 24 | 25 | //- (void)test:(NSNumber *)first,...NS_REQUIRES_NIL_TERMINATION; 26 | 27 | @end 28 | 29 | @implementation ViewController 30 | 31 | - (void)viewDidLoad 32 | { 33 | [super viewDidLoad]; 34 | 35 | [[JDEngine engine] start]; 36 | 37 | self.testLabel = [[UILabel alloc] initWithFrame:CGRectMake(300, 100, 150, 50)]; 38 | self.testLabel.text = @"Try JSDebugger!"; 39 | self.testLabel.textColor = [UIColor orangeColor]; 40 | 41 | self.associateObject = [[TestAssociateObject alloc] init]; 42 | 43 | self.associateObject.associateInt = 5; 44 | 45 | //id val = objc_getAssociatedObject(self.associateObject, (void *)@"assoicateKey"); 46 | 47 | [self.view addSubview:self.testLabel]; 48 | 49 | NSString *jsFilePathOnMac = @"/Users/z/Documents/Github/JSDebugger/JSDebuggerDemo/demo.js"; // @SatanWoo: There is one copy in your project 50 | 51 | if ([[NSFileManager defaultManager] fileExistsAtPath:jsFilePathOnMac]) { 52 | self.fileWatcher = [[JDLocalFileObserver alloc] initWithFilePath:jsFilePathOnMac changeBlock:^{ 53 | NSLog(@"[mingyi]::found mac wzq.js change"); 54 | dispatch_async(dispatch_get_main_queue(), ^{ 55 | [[JDEngine engine] evaluateScriptAtPath:jsFilePathOnMac]; 56 | }); 57 | }]; 58 | [self.fileWatcher start]; 59 | } 60 | 61 | // Do any additional setup after loading the view, typically from a nib. 62 | } 63 | 64 | - (void)viewDidAppear:(BOOL)animated 65 | { 66 | [super viewDidAppear:animated]; 67 | 68 | [[JDEngine engine] evaluateScriptAtPath:[[NSBundle mainBundle] pathForResource:@"demo" ofType:@"js"]]; 69 | } 70 | 71 | 72 | + (void)test:(int)first,...NS_REQUIRES_NIL_TERMINATION 73 | { 74 | va_list list; 75 | 76 | //遍历开始 77 | 78 | va_start(list, first); 79 | 80 | NSLog(@"base address is %p and value is %d", &first, first); 81 | 82 | int arg; 83 | 84 | while ((arg = va_arg(list, int))) { 85 | NSLog(@"当前参数:%d 地址:%p" , arg, &arg); 86 | } 87 | 88 | va_end(list); 89 | } 90 | 91 | + (void)printNSArray:(NSArray *)array 92 | { 93 | NSLog(@"array is %@", array); 94 | } 95 | 96 | - (void)printName:(NSString *)name 97 | { 98 | NSLog(@"name is %@", name); 99 | } 100 | 101 | - (int *)allocAddressWithInt 102 | { 103 | self.testInt = 20; 104 | return &_testInt; 105 | } 106 | 107 | - (double *)allocAddressWithDouble 108 | { 109 | self.testDouble = 30.7; 110 | return &_testDouble; 111 | } 112 | 113 | - (char *)allocAddressWithChar 114 | { 115 | testStr = "jkjskjsd\0"; 116 | return testStr; 117 | } 118 | 119 | - (void)testDoublePointer:(double *)doubleP 120 | { 121 | NSLog(@"value is %g", *doubleP); 122 | } 123 | 124 | - (void)testIntPointer:(int *)intP 125 | { 126 | NSLog(@"value is %d", *intP); 127 | } 128 | 129 | - (void)testCString:(char *)charP 130 | { 131 | NSLog(@"value is %s", charP); 132 | } 133 | 134 | - (void)print 135 | { 136 | NSLog(@"self get assoicate int is %ld", (long)self.associateObject.associateInt); 137 | } 138 | 139 | - (void)printNumb:(NSNumber *)val 140 | { 141 | NSLog(@"val is %@", val); 142 | } 143 | 144 | @end 145 | -------------------------------------------------------------------------------- /Source/Core/Runtime/JDEncoding.m: -------------------------------------------------------------------------------- 1 | // 2 | // JDEncoding.m 3 | // JSDebugger 4 | // 5 | // Created by z on 2018/9/22. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | #import "JDEncoding.h" 10 | #import "JDStruct.h" 11 | 12 | JDEncoding JDGetEncoding(const char *c) 13 | { 14 | assert(c); 15 | 16 | unsigned long len = strlen(c); 17 | if (len == 0) return JDEncodingUnknown; 18 | 19 | switch (*c) { 20 | case 'v': return JDEncodingVoid; 21 | case 'B': return JDEncodingBool; 22 | case 'c': return JDEncodingInt8; 23 | case 'C': return JDEncodingUInt8; 24 | case 's': return JDEncodingInt16; 25 | case 'S': return JDEncodingUInt16; 26 | case 'i': return JDEncodingInt32; 27 | case 'I': return JDEncodingUInt32; 28 | case 'l': return JDEncodingInt32; 29 | case 'L': return JDEncodingUInt32; 30 | case 'q': return JDEncodingInt64; 31 | case 'Q': return JDEncodingUInt64; 32 | case 'f': return JDEncodingFloat; 33 | case 'F': 34 | #if CGFLOAT_IS_DOUBLE 35 | return JDEncodingDouble; 36 | #else 37 | return JDEncodingFloat; 38 | #endif 39 | case 'd': return JDEncodingDouble; 40 | case 'D': return JDEncodingLongDouble; 41 | case '#': return JDEncodingClass; 42 | case ':': return JDEncodingSEL; 43 | case '*': return JDEncodingCString; 44 | case '^': return JDEncodingPointer; 45 | case '[': return JDEncodingCArray; 46 | case '(': return JDEncodingUnion; 47 | case '{': return JDEncodingStruct; 48 | case '@': { 49 | if (len == 2 && *(c + 1) == '?') 50 | return JDEncodingBlock; 51 | else 52 | return JDEncodingObject; 53 | } 54 | default: return JDEncodingUnknown; 55 | } 56 | } 57 | 58 | static size_t JDSizeOfStruct(NSString *structName) 59 | { 60 | NSDictionary *definition = [JDStruct structDefintion:structName]; 61 | if (!definition) { return 0; } 62 | 63 | size_t size = 0; 64 | 65 | for (NSDictionary *info in definition[@"def"]) { 66 | NSString *type = info[@"type"]; 67 | JDEncoding encoding = JDGetEncoding(type.UTF8String); 68 | if (encoding == JDEncodingStruct) { 69 | size += JDSizeOfStruct([type stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"{}"]]); 70 | } else { 71 | size += JDSizeOfEncoding(encoding, nil); 72 | } 73 | } 74 | 75 | return size; 76 | } 77 | 78 | size_t JDSizeOfEncoding(JDEncoding encoding, NSString *structName) 79 | { 80 | #define JDSize(encoding, type) \ 81 | case encoding: \ 82 | { \ 83 | return sizeof(type);\ 84 | } 85 | 86 | switch (encoding) { 87 | JDSize(JDEncodingVoid, void); 88 | JDSize(JDEncodingInt8, int8_t); 89 | JDSize(JDEncodingUInt8, uint8_t); 90 | JDSize(JDEncodingInt16, int16_t); 91 | JDSize(JDEncodingUInt16, uint16_t); 92 | JDSize(JDEncodingInt32, int32_t); 93 | JDSize(JDEncodingUInt32, uint32_t); 94 | JDSize(JDEncodingInt64, int64_t); 95 | JDSize(JDEncodingUInt64, uint64_t); 96 | JDSize(JDEncodingBool, bool); 97 | JDSize(JDEncodingFloat, float); 98 | JDSize(JDEncodingDouble, double); 99 | JDSize(JDEncodingLongDouble, long double); 100 | JDSize(JDEncodingCString, char *); 101 | JDSize(JDEncodingPointer, void *); 102 | JDSize(JDEncodingObject, void *); 103 | JDSize(JDEncodingSEL, void *); 104 | JDSize(JDEncodingClass, void *); 105 | 106 | case JDEncodingStruct: 107 | { 108 | return JDSizeOfStruct(structName); 109 | } 110 | default: 111 | // @SatanWoo: C Struct cannot hold other types 112 | assert(false); 113 | return 0; 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /Source/Core/Runtime/JDProperty.m: -------------------------------------------------------------------------------- 1 | // 2 | // JDProperty.m 3 | // JSDebugger 4 | // 5 | // Created by z on 2018/9/23. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | #import "JDProperty.h" 10 | 11 | @interface JDProperty() 12 | 13 | @property (nonatomic, readwrite) BOOL readonly; 14 | @property (nonatomic, readwrite) JDEncoding encoding; 15 | @property (nonatomic, copy, readwrite) NSString *setterName; 16 | @property (nonatomic, copy, readwrite) NSString *getterName; 17 | @property (nonatomic, copy, readwrite) NSString *propertyName; 18 | 19 | @end 20 | 21 | @implementation JDProperty 22 | 23 | - (instancetype)initWithProperty:(objc_property_t)property 24 | { 25 | if (!property) { return nil; } 26 | const char *name = property_getName(property); 27 | 28 | if (!name) { return nil; } 29 | 30 | self = [super init]; 31 | if (self) { 32 | _propertyName = [NSString stringWithUTF8String:name]; 33 | _getterName = _propertyName.copy; 34 | _setterName = [NSString stringWithFormat:@"set%@%@:", 35 | [_propertyName substringToIndex:1].uppercaseString, 36 | [_propertyName substringFromIndex:1]]; 37 | 38 | unsigned int attrCount; 39 | objc_property_attribute_t *attrs = property_copyAttributeList(property, &attrCount); 40 | for (unsigned int i = 0; i < attrCount; i++) { 41 | switch (attrs[i].name[0]) { 42 | case 'T': { // Type encoding 43 | if (attrs[i].value) { 44 | self.encoding = JDGetEncoding(attrs[i].value); 45 | } 46 | break; 47 | } 48 | 49 | case 'R': { 50 | self.readonly = YES; 51 | break; 52 | } 53 | 54 | case 'G': { 55 | if (attrs[i].value) { 56 | self.getterName = [NSString stringWithUTF8String:attrs[i].value]; 57 | } 58 | break; 59 | } 60 | 61 | case 'S': { 62 | if (attrs[i].value) { 63 | self.setterName = [NSString stringWithUTF8String:attrs[i].value]; 64 | } 65 | break; 66 | } 67 | 68 | default: break; 69 | } 70 | } 71 | 72 | if (attrs) { 73 | free(attrs); 74 | attrs = NULL; 75 | } 76 | } 77 | return self; 78 | } 79 | 80 | - (NSString *)description 81 | { 82 | return [NSString stringWithFormat:@"%@ - %@ - %@ - %d", self.propertyName, self.setterName, self.getterName, self.readonly]; 83 | } 84 | 85 | @end 86 | 87 | #pragma mark - JDPropertiesInClass 88 | 89 | @interface JDPropertiesInClass() 90 | 91 | @property (nonatomic, strong) NSArray *properties; 92 | 93 | @end 94 | 95 | @implementation JDPropertiesInClass 96 | 97 | - (instancetype)initWithClass:(Class)cls 98 | { 99 | if (!cls) { return nil; } 100 | 101 | self = [super init]; 102 | if (self) { 103 | NSMutableArray *temp = @[].mutableCopy; 104 | 105 | unsigned int propertyCount = 0; 106 | objc_property_t *properties = class_copyPropertyList(cls, &propertyCount); 107 | if (properties) { 108 | for (unsigned int i = 0; i < propertyCount; i++) { 109 | JDProperty *property = [[JDProperty alloc] initWithProperty:properties[i]]; 110 | if (property) [temp addObject:property]; 111 | } 112 | free(properties); 113 | } 114 | _properties = temp.copy; 115 | } 116 | 117 | return self; 118 | } 119 | 120 | - (NSString *)description 121 | { 122 | NSMutableString *descr = [[NSMutableString alloc] init]; 123 | 124 | for (JDProperty *property in self.properties) { 125 | [descr appendString:[property description]]; 126 | [descr appendString:@"\n"]; 127 | } 128 | return descr.copy; 129 | } 130 | 131 | @end 132 | -------------------------------------------------------------------------------- /Source/Core/JDEngine.m: -------------------------------------------------------------------------------- 1 | // 2 | // JDEngine.m 3 | // JSDebugger 4 | // 5 | // Created by z on 2018/9/20. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | #import "JDEngine.h" 10 | #import "JDStruct.h" 11 | #import "JDClass4JS.h" 12 | #import "JDNSStringFromJSString.h" 13 | #import "JDFunctionPlugin.h" 14 | #import "JDLog.h" 15 | #import "JDJSTypeToOCType.h" 16 | 17 | static JSValueRef JDGlobalGetProperty(JSContextRef ctx, JSObjectRef object, 18 | JSStringRef propertyName, JSValueRef *exception) 19 | { 20 | NSString *className = JDCreateNSStringFromJSString(ctx, propertyName); 21 | Class cls = NSClassFromString(className); 22 | if (!cls) return NULL; // @important: to search in the super chain 23 | 24 | return JSObjectMake(ctx, JDClass4JS(), (__bridge void *)cls); 25 | } 26 | 27 | @interface JDEngine() 28 | 29 | @property (nonatomic) JSClassRef globalObject; 30 | @property (nonatomic) JSGlobalContextRef ctxRef; 31 | 32 | @end 33 | 34 | @implementation JDEngine 35 | 36 | + (JDEngine *)engine 37 | { 38 | static dispatch_once_t onceToken; 39 | static JDEngine *_engine; 40 | dispatch_once(&onceToken, ^{ 41 | _engine = [[JDEngine alloc] init]; 42 | }); 43 | return _engine; 44 | } 45 | 46 | #pragma mark - Private 47 | - (instancetype)init 48 | { 49 | self = [super init]; 50 | if (self) { 51 | JSClassDefinition globalDefinition; 52 | 53 | globalDefinition = kJSClassDefinitionEmpty; 54 | globalDefinition.className = "JDGlobal"; 55 | globalDefinition.getProperty = &JDGlobalGetProperty; 56 | 57 | _globalObject = JSClassCreate(&globalDefinition); 58 | _ctxRef = JSGlobalContextCreate(_globalObject); 59 | } 60 | return self; 61 | } 62 | 63 | - (void)dealloc 64 | { 65 | JSGlobalContextRelease(_ctxRef); 66 | _ctxRef = NULL; 67 | 68 | JSClassRelease(_globalObject); 69 | _globalObject = NULL; 70 | } 71 | 72 | - (void)start 73 | { 74 | [[JDFunctionPluginManager pluginManager] registerPluginsIntoContext:self.ctxRef]; 75 | 76 | [JDStruct setupDefaultStruct]; 77 | } 78 | 79 | #pragma mark - Private Logic 80 | 81 | - (void)outputExceptionValue:(JSValueRef)exceptionValueRef 82 | { 83 | if (exceptionValueRef != NULL) { 84 | // @SatanWoo: Exception Value is normally a 85 | id exception = JDConvertJSValueToNSObject(self.ctxRef, exceptionValueRef); 86 | 87 | JSValue *value = [JSValue valueWithJSValueRef:exceptionValueRef 88 | inContext:[JSContext contextWithJSGlobalContextRef:self.ctxRef]]; 89 | if (exception) { 90 | JDLog(@"[JSDebugger]::Evaluating JSDebugger Cause Exception Found %@ on line %@ column %@", 91 | value, 92 | exception[@"line"] ?: @"undefined", 93 | exception[@"column"] ?: @"undefined"); 94 | } 95 | } 96 | } 97 | 98 | #pragma mark - Public API 99 | - (void)evaluateScript:(NSString *)scriptContent 100 | { 101 | NSParameterAssert(scriptContent); 102 | if (scriptContent.length <= 0) { return; } 103 | 104 | JSValueRef exceptionValue = NULL; 105 | JSStringRef jsContentRef = JSStringCreateWithUTF8CString(scriptContent.UTF8String); 106 | 107 | if (!JSCheckScriptSyntax(self.ctxRef, jsContentRef, NULL, 1, &exceptionValue)) { 108 | [self outputExceptionValue:exceptionValue]; 109 | 110 | JSStringRelease(jsContentRef); 111 | return; 112 | } 113 | 114 | JSEvaluateScript(self.ctxRef, jsContentRef, JSContextGetGlobalObject(self.ctxRef), NULL, 1, &exceptionValue); 115 | JSStringRelease(jsContentRef); 116 | 117 | [self outputExceptionValue:exceptionValue]; 118 | } 119 | 120 | - (void)evaluateScriptAtPath:(NSString *)path 121 | { 122 | NSParameterAssert(path); 123 | if (path.length <= 0) { return; } 124 | 125 | BOOL isDir = NO; 126 | BOOL isExist = [[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isDir]; 127 | 128 | if (!isExist || isDir) { return; } 129 | 130 | NSString *content = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil]; 131 | [self evaluateScript:content]; 132 | } 133 | 134 | @end 135 | -------------------------------------------------------------------------------- /Source/Core/Runtime/JSDefinition/JDInstance4JS.m: -------------------------------------------------------------------------------- 1 | // 2 | // JDInstance4JS.m 3 | // JSDebugger 4 | // 5 | // Created by z on 2018/9/20. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | #import "JDInstance4JS.h" 10 | #import "JDMethod4JS.h" 11 | #import "JDFormatJSFunction.h" 12 | #import "JDProperty.h" 13 | #import "JDPropertyCache.h" 14 | #import "JDJSTypeToOCType.h" 15 | #import "JDOCTypeToJSType.h" 16 | #import "JDFFIContext.h" 17 | #import "JDNSStringFromJSString.h" 18 | #import "JDMethodBridge.h" 19 | @import ObjectiveC.runtime; 20 | 21 | #define JDCache \ 22 | cache() 23 | 24 | #define JDPrepareProperties \ 25 | JDPropertiesInClass *propertiesInClass = [JDCache propertiesForClass:[instance class]]; \ 26 | if (!propertiesInClass) { \ 27 | propertiesInClass = [[JDPropertiesInClass alloc] initWithClass:[instance class]]; \ 28 | [JDCache addProperty:propertiesInClass forClass:[instance class]]; \ 29 | } \ 30 | 31 | static JDPropertyCache *cache(void) 32 | { 33 | static JDPropertyCache *_cache = nil; 34 | if (!_cache) { 35 | _cache = [[JDPropertyCache alloc] init]; 36 | } 37 | return _cache; 38 | } 39 | 40 | static JSValueRef JDInstanceGetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) { 41 | CFStringRef ref = JSStringCopyCFString(kCFAllocatorDefault, propertyName); 42 | NSString *ocPropertyName = (__bridge_transfer NSString *)ref; 43 | 44 | // @SatanWoo: Search Property First => Method IMP 45 | id instance = (__bridge id)(JSObjectGetPrivate(object)); 46 | if (!instance) return JSValueMakeUndefined(ctx); 47 | 48 | id associateValue = objc_getAssociatedObject(instance, (void *)NSSelectorFromString(ocPropertyName)); 49 | if (associateValue) { 50 | return JDConvertNSObjectToJSValue(ctx, associateValue); 51 | } 52 | 53 | // @SatanWoo: Try regard it as property getter call directly 54 | SEL sel_data = NSSelectorFromString(JDFormatJSFunction(ocPropertyName)); 55 | 56 | // @SatanWoo: Give control back to Method4JS 57 | Method m = class_getInstanceMethod([instance class], sel_data); 58 | if (!m) return JSValueMakeUndefined(ctx); 59 | 60 | return JSObjectMake(ctx, JDMethod4JS(), (void *)sel_data); 61 | } 62 | 63 | static bool JDInstanceSetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception) 64 | { 65 | CFStringRef ref = JSStringCopyCFString(kCFAllocatorDefault, propertyName); 66 | NSString *ocPropertyName = (__bridge_transfer NSString *)ref; 67 | 68 | id instance = (__bridge id)(JSObjectGetPrivate(object)); 69 | if (!instance) { return true; } 70 | 71 | // @SatanWoo: Fall to normal setter case 72 | NSString *setterName = [NSString stringWithFormat:@"set%@%@:", 73 | [ocPropertyName substringToIndex:1].uppercaseString, 74 | [ocPropertyName substringFromIndex:1]]; 75 | 76 | SEL sel = NSSelectorFromString(setterName); 77 | IMP imp = class_getMethodImplementation([instance class], sel); 78 | NSMethodSignature *methodSignature = [instance methodSignatureForSelector:sel]; 79 | 80 | if (!methodSignature) return false; 81 | 82 | JDMethodBridge *methodBridge = [[JDMethodBridge alloc] initWithSignature:methodSignature 83 | selector:sel 84 | instace:instance 85 | imp:imp]; 86 | JSValueRef *arguments = (JSValueRef *)malloc(sizeof(JSValueRef) * 1); 87 | arguments[0] = value; 88 | JDCallFunction(ctx, methodBridge, 1, arguments); 89 | free(arguments); 90 | 91 | return false; 92 | } 93 | 94 | JSClassRef JDInstance4JS(void) 95 | { 96 | static dispatch_once_t onceToken; 97 | static JSClassRef instanceRef = nil; 98 | dispatch_once(&onceToken, ^{ 99 | JSClassDefinition instanceDefinition; 100 | instanceDefinition = kJSClassDefinitionEmpty; 101 | instanceDefinition.className = "JDInstance4JS"; 102 | instanceDefinition.getProperty = &JDInstanceGetProperty; 103 | instanceDefinition.setProperty = &JDInstanceSetProperty; 104 | instanceRef = JSClassCreate(&instanceDefinition); 105 | }); 106 | return instanceRef; 107 | } 108 | -------------------------------------------------------------------------------- /Source/Core/Introspect/NSObject+JDRuntimeIntrospection.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSObject+JDRuntimeIntrospection.m 3 | // JSDebugger 4 | // 5 | // Created by JunyiXie on 2/10/2018. 6 | // 7 | 8 | #import "NSObject+JDRuntimeIntrospection.h" 9 | #import "JDEncoding.h" 10 | @import ObjectiveC.runtime; 11 | 12 | @implementation NSObject (JDRuntimeIntrospection) 13 | 14 | - (NSArray *)jd_logAllProperties 15 | { 16 | NSMutableArray *result = @[].mutableCopy; 17 | unsigned int count; 18 | Ivar *ivars = class_copyIvarList([self class], &count); 19 | for (unsigned int i = 0; i < count; i++) { 20 | Ivar ivar = ivars[i]; 21 | 22 | const char *name = ivar_getName(ivar); 23 | const char *type = ivar_getTypeEncoding(ivar); 24 | ptrdiff_t offset = ivar_getOffset(ivar); 25 | 26 | if (strncmp(type, @encode(char), 1) == 0) { 27 | char value = *(char *)((uintptr_t)self + offset); 28 | [result addObject: [NSString stringWithFormat:@"%s = %c", name, value]]; 29 | } 30 | else if (strncmp(type, @encode(int), 1) == 0) { 31 | int value = *(int *)((uintptr_t)self + offset); 32 | [result addObject: [NSString stringWithFormat:@"%s = %d", name, value]]; 33 | } 34 | else if (strncmp(type, @encode(short), 1) == 0) { 35 | short value = *(short *)((uintptr_t)self + offset); 36 | [result addObject: [NSString stringWithFormat:@"%s = %hd", name, value]]; 37 | } 38 | else if (strncmp(type, @encode(long), 1) == 0) { 39 | long value = *(long *)((uintptr_t)self + offset); 40 | [result addObject: [NSString stringWithFormat:@"%s = %ld", name, value]]; 41 | } 42 | else if (strncmp(type, @encode(long long), 1) == 0) { 43 | long long value = *(long long *)((uintptr_t)self + offset); 44 | [result addObject: [NSString stringWithFormat:@"%s = %lld", name, value]]; 45 | } 46 | else if (strncmp(type, @encode(unsigned char), 1) == 0) { 47 | unsigned char value = *(unsigned char *)((uintptr_t)self + offset); 48 | [result addObject: [NSString stringWithFormat:@"%s = %c", name, value]]; 49 | } 50 | else if (strncmp(type, @encode(unsigned int), 1) == 0) { 51 | unsigned int value = *(unsigned int *)((uintptr_t)self + offset); 52 | [result addObject: [NSString stringWithFormat:@"%s = %u", name, value]]; 53 | } 54 | else if (strncmp(type, @encode(unsigned short), 1) == 0) { 55 | unsigned short value = *(unsigned short *)((uintptr_t)self + offset); 56 | [result addObject: [NSString stringWithFormat:@"%s = %hu", name, value]]; 57 | } 58 | else if (strncmp(type, @encode(unsigned long), 1) == 0) { 59 | unsigned long value = *(unsigned long *)((uintptr_t)self + offset); 60 | [result addObject: [NSString stringWithFormat:@"%s = %lu", name, value]]; 61 | } 62 | else if (strncmp(type, @encode(unsigned long long), 1) == 0) { 63 | unsigned long long value = *(unsigned long long *)((uintptr_t)self + offset); 64 | [result addObject: [NSString stringWithFormat:@"%s = %llu", name, value]]; 65 | } 66 | else if (strncmp(type, @encode(float), 1) == 0) { 67 | float value = *(float *)((uintptr_t)self + offset); 68 | [result addObject: [NSString stringWithFormat:@"%s = %f", name, value]]; 69 | } 70 | else if (strncmp(type, @encode(double), 1) == 0) { 71 | double value = *(double *)((uintptr_t)self + offset); 72 | [result addObject: [NSString stringWithFormat:@"%s = %e", name, value]]; 73 | } 74 | else if (strncmp(type, @encode(bool), 1) == 0) { 75 | bool value = *(bool *)((uintptr_t)self + offset); 76 | [result addObject: [NSString stringWithFormat:@"%s = %d", name, value]]; 77 | } 78 | else if (strncmp(type, @encode(char *), 1) == 0) { 79 | char * value = *(char * *)((uintptr_t)self + offset); 80 | [result addObject: [NSString stringWithFormat:@"%s = %s", name, value]]; 81 | } 82 | else if (strncmp(type, @encode(id), 1) == 0) { 83 | id value = object_getIvar(self, ivar); 84 | [result addObject: [NSString stringWithFormat:@"%s = %@", name, value]]; 85 | } 86 | else if (strncmp(type, @encode(Class), 1) == 0) { 87 | id value = object_getIvar(self, ivar); 88 | [result addObject: [NSString stringWithFormat:@"%s = %@", name, value]]; 89 | } 90 | // todo 91 | // SEL 92 | // struct 93 | // array 94 | // union 95 | // bit 96 | // field of num bits 97 | // pointer to type 98 | } 99 | free(ivars); 100 | return [result copy]; 101 | } 102 | 103 | @end 104 | 105 | 106 | 107 | -------------------------------------------------------------------------------- /Source/Core/FFI/Vendor/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 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 | 86 | #if HAVE_LONG_DOUBLE_VARIANT 87 | /* Used to adjust size/alignment of ffi types. */ 88 | void ffi_prep_types (ffi_abi abi); 89 | #endif 90 | 91 | /* Used internally, but overridden by some architectures */ 92 | ffi_status ffi_prep_cif_core(ffi_cif *cif, 93 | ffi_abi abi, 94 | unsigned int isvariadic, 95 | unsigned int nfixedargs, 96 | unsigned int ntotalargs, 97 | ffi_type *rtype, 98 | ffi_type **atypes); 99 | 100 | /* Extended cif, used in callback from assembly routine */ 101 | typedef struct 102 | { 103 | ffi_cif *cif; 104 | void *rvalue; 105 | void **avalue; 106 | } extended_cif; 107 | 108 | /* Terse sized type definitions. */ 109 | #if defined(_MSC_VER) || defined(__sgi) || defined(__SUNPRO_C) 110 | typedef unsigned char UINT8; 111 | typedef signed char SINT8; 112 | typedef unsigned short UINT16; 113 | typedef signed short SINT16; 114 | typedef unsigned int UINT32; 115 | typedef signed int SINT32; 116 | # ifdef _MSC_VER 117 | typedef unsigned __int64 UINT64; 118 | typedef signed __int64 SINT64; 119 | # else 120 | # include 121 | typedef uint64_t UINT64; 122 | typedef int64_t SINT64; 123 | # endif 124 | #else 125 | typedef unsigned int UINT8 __attribute__((__mode__(__QI__))); 126 | typedef signed int SINT8 __attribute__((__mode__(__QI__))); 127 | typedef unsigned int UINT16 __attribute__((__mode__(__HI__))); 128 | typedef signed int SINT16 __attribute__((__mode__(__HI__))); 129 | typedef unsigned int UINT32 __attribute__((__mode__(__SI__))); 130 | typedef signed int SINT32 __attribute__((__mode__(__SI__))); 131 | typedef unsigned int UINT64 __attribute__((__mode__(__DI__))); 132 | typedef signed int SINT64 __attribute__((__mode__(__DI__))); 133 | #endif 134 | 135 | typedef float FLOAT32; 136 | 137 | #ifndef __GNUC__ 138 | #define __builtin_expect(x, expected_value) (x) 139 | #endif 140 | #define LIKELY(x) __builtin_expect(!!(x),1) 141 | #define UNLIKELY(x) __builtin_expect((x)!=0,0) 142 | 143 | #ifdef __cplusplus 144 | } 145 | #endif 146 | 147 | #endif 148 | -------------------------------------------------------------------------------- /Source/Core/FFI/Vendor/ffitarget_x86_64.h: -------------------------------------------------------------------------------- 1 | /* -----------------------------------------------------------------*-C-*- 2 | ffitarget.h - Copyright (c) 2012, 2014 Anthony Green 3 | Copyright (c) 1996-2003, 2010 Red Hat, Inc. 4 | Copyright (C) 2008 Free Software Foundation, Inc. 5 | 6 | Target configuration macros for x86 and x86-64. 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining 9 | a copy of this software and associated documentation files (the 10 | ``Software''), to deal in the Software without restriction, including 11 | without limitation the rights to use, copy, modify, merge, publish, 12 | distribute, sublicense, and/or sell copies of the Software, and to 13 | permit persons to whom the Software is furnished to do so, subject to 14 | the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included 17 | in all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, 20 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26 | DEALINGS IN THE SOFTWARE. 27 | 28 | ----------------------------------------------------------------------- */ 29 | 30 | #ifndef LIBFFI_TARGET_H 31 | #define LIBFFI_TARGET_H 32 | 33 | #ifndef LIBFFI_H 34 | #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead." 35 | #endif 36 | 37 | /* ---- System specific configurations ----------------------------------- */ 38 | 39 | /* For code common to all platforms on x86 and x86_64. */ 40 | #define X86_ANY 41 | 42 | #if defined (X86_64) && defined (__i386__) 43 | #undef X86_64 44 | #define X86 45 | #endif 46 | 47 | #ifdef X86_WIN64 48 | #define FFI_SIZEOF_ARG 8 49 | #define USE_BUILTIN_FFS 0 /* not yet implemented in mingw-64 */ 50 | #endif 51 | 52 | #define FFI_TARGET_SPECIFIC_STACK_SPACE_ALLOCATION 53 | #ifndef _MSC_VER 54 | #define FFI_TARGET_HAS_COMPLEX_TYPE 55 | #endif 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 | #if defined(X86_WIN64) 82 | FFI_FIRST_ABI = 0, 83 | FFI_WIN64, 84 | FFI_LAST_ABI, 85 | FFI_DEFAULT_ABI = FFI_WIN64 86 | 87 | #elif defined(X86_64) || (defined (__x86_64__) && defined (X86_DARWIN)) 88 | FFI_FIRST_ABI = 1, 89 | FFI_UNIX64, 90 | FFI_WIN64, 91 | FFI_EFI64 = FFI_WIN64, 92 | FFI_LAST_ABI, 93 | FFI_DEFAULT_ABI = FFI_UNIX64 94 | 95 | #elif defined(X86_WIN32) 96 | FFI_FIRST_ABI = 0, 97 | FFI_SYSV = 1, 98 | FFI_STDCALL = 2, 99 | FFI_THISCALL = 3, 100 | FFI_FASTCALL = 4, 101 | FFI_MS_CDECL = 5, 102 | FFI_PASCAL = 6, 103 | FFI_REGISTER = 7, 104 | FFI_LAST_ABI, 105 | FFI_DEFAULT_ABI = FFI_MS_CDECL 106 | #else 107 | FFI_FIRST_ABI = 0, 108 | FFI_SYSV = 1, 109 | FFI_THISCALL = 3, 110 | FFI_FASTCALL = 4, 111 | FFI_STDCALL = 5, 112 | FFI_PASCAL = 6, 113 | FFI_REGISTER = 7, 114 | FFI_MS_CDECL = 8, 115 | FFI_LAST_ABI, 116 | FFI_DEFAULT_ABI = FFI_SYSV 117 | #endif 118 | } ffi_abi; 119 | #endif 120 | 121 | /* ---- Definitions for closures ----------------------------------------- */ 122 | 123 | #define FFI_CLOSURES 1 124 | #define FFI_GO_CLOSURES 1 125 | 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_WIN64) \ 132 | || (defined (__x86_64__) && defined (X86_DARWIN)) 133 | # define FFI_TRAMPOLINE_SIZE 24 134 | # define FFI_NATIVE_RAW_API 0 135 | #else 136 | # define FFI_TRAMPOLINE_SIZE 12 137 | # define FFI_NATIVE_RAW_API 1 /* x86 has native raw api support */ 138 | #endif 139 | 140 | #endif 141 | 142 | -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Target Support Files/Pods-JSDebuggerDemo/Pods-JSDebuggerDemo-frameworks.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | echo "mkdir -p ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 5 | mkdir -p "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 6 | 7 | SWIFT_STDLIB_PATH="${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}" 8 | 9 | # This protects against multiple targets copying the same framework dependency at the same time. The solution 10 | # was originally proposed here: https://lists.samba.org/archive/rsync/2008-February/020158.html 11 | RSYNC_PROTECT_TMP_FILES=(--filter "P .*.??????") 12 | 13 | install_framework() 14 | { 15 | if [ -r "${BUILT_PRODUCTS_DIR}/$1" ]; then 16 | local source="${BUILT_PRODUCTS_DIR}/$1" 17 | elif [ -r "${BUILT_PRODUCTS_DIR}/$(basename "$1")" ]; then 18 | local source="${BUILT_PRODUCTS_DIR}/$(basename "$1")" 19 | elif [ -r "$1" ]; then 20 | local source="$1" 21 | fi 22 | 23 | local destination="${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 24 | 25 | if [ -L "${source}" ]; then 26 | echo "Symlinked..." 27 | source="$(readlink "${source}")" 28 | fi 29 | 30 | # Use filter instead of exclude so missing patterns don't throw errors. 31 | echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${source}\" \"${destination}\"" 32 | rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${source}" "${destination}" 33 | 34 | local basename 35 | basename="$(basename -s .framework "$1")" 36 | binary="${destination}/${basename}.framework/${basename}" 37 | if ! [ -r "$binary" ]; then 38 | binary="${destination}/${basename}" 39 | fi 40 | 41 | # Strip invalid architectures so "fat" simulator / device frameworks work on device 42 | if [[ "$(file "$binary")" == *"dynamically linked shared library"* ]]; then 43 | strip_invalid_archs "$binary" 44 | fi 45 | 46 | # Resign the code if required by the build settings to avoid unstable apps 47 | code_sign_if_enabled "${destination}/$(basename "$1")" 48 | 49 | # Embed linked Swift runtime libraries. No longer necessary as of Xcode 7. 50 | if [ "${XCODE_VERSION_MAJOR}" -lt 7 ]; then 51 | local swift_runtime_libs 52 | swift_runtime_libs=$(xcrun otool -LX "$binary" | grep --color=never @rpath/libswift | sed -E s/@rpath\\/\(.+dylib\).*/\\1/g | uniq -u && exit ${PIPESTATUS[0]}) 53 | for lib in $swift_runtime_libs; do 54 | echo "rsync -auv \"${SWIFT_STDLIB_PATH}/${lib}\" \"${destination}\"" 55 | rsync -auv "${SWIFT_STDLIB_PATH}/${lib}" "${destination}" 56 | code_sign_if_enabled "${destination}/${lib}" 57 | done 58 | fi 59 | } 60 | 61 | # Copies the dSYM of a vendored framework 62 | install_dsym() { 63 | local source="$1" 64 | if [ -r "$source" ]; then 65 | echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${source}\" \"${DWARF_DSYM_FOLDER_PATH}\"" 66 | rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${source}" "${DWARF_DSYM_FOLDER_PATH}" 67 | fi 68 | } 69 | 70 | # Signs a framework with the provided identity 71 | code_sign_if_enabled() { 72 | if [ -n "${EXPANDED_CODE_SIGN_IDENTITY}" -a "${CODE_SIGNING_REQUIRED}" != "NO" -a "${CODE_SIGNING_ALLOWED}" != "NO" ]; then 73 | # Use the current code_sign_identitiy 74 | echo "Code Signing $1 with Identity ${EXPANDED_CODE_SIGN_IDENTITY_NAME}" 75 | local code_sign_cmd="/usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} ${OTHER_CODE_SIGN_FLAGS} --preserve-metadata=identifier,entitlements '$1'" 76 | 77 | if [ "${COCOAPODS_PARALLEL_CODE_SIGN}" == "true" ]; then 78 | code_sign_cmd="$code_sign_cmd &" 79 | fi 80 | echo "$code_sign_cmd" 81 | eval "$code_sign_cmd" 82 | fi 83 | } 84 | 85 | # Strip invalid architectures 86 | strip_invalid_archs() { 87 | binary="$1" 88 | # Get architectures for current file 89 | archs="$(lipo -info "$binary" | rev | cut -d ':' -f1 | rev)" 90 | stripped="" 91 | for arch in $archs; do 92 | if ! [[ "${ARCHS}" == *"$arch"* ]]; then 93 | # Strip non-valid architectures in-place 94 | lipo -remove "$arch" -output "$binary" "$binary" || exit 1 95 | stripped="$stripped $arch" 96 | fi 97 | done 98 | if [[ "$stripped" ]]; then 99 | echo "Stripped $binary of architectures:$stripped" 100 | fi 101 | } 102 | 103 | if [ "${COCOAPODS_PARALLEL_CODE_SIGN}" == "true" ]; then 104 | wait 105 | fi 106 | -------------------------------------------------------------------------------- /Source/Core/FFI/Vendor/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 -------------------------------------------------------------------------------- /Source/Core/Plugin/Plugin/JDChoose.mm: -------------------------------------------------------------------------------- 1 | // 2 | // JDChoose.m 3 | // JSDebugger 4 | // 5 | // Created by z on 2018/9/20. 6 | // Copyright © 2018年 SatanWoo. All rights reserved. 7 | // 8 | 9 | #import "JDChoose.h" 10 | #import "JDOCTypeToJSType.h" 11 | #import "JDLog.h" 12 | #import 13 | #import 14 | #import 15 | #import 16 | #include 17 | 18 | static JSValueRef choose(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) 19 | { 20 | if (argumentCount != 1) { 21 | JDLog(@"choose() takes a class argument"); 22 | return NULL; 23 | } 24 | 25 | JSValueRef value = arguments[0]; 26 | JSObjectRef objectRef = const_cast(value); 27 | Class ocClass = (__bridge Class)(JSObjectGetPrivate(objectRef)); 28 | if (!ocClass) return JSObjectMakeArray(ctx, 0, NULL, exception); 29 | 30 | NSArray *result = [JDChoose choose:ocClass]; 31 | return JDConvertNSObjectToJSValue(ctx, result); 32 | } 33 | 34 | struct choice { 35 | std::set query_; 36 | std::set result_; 37 | }; 38 | 39 | struct ObjectStruct { 40 | Class isa_; 41 | }; 42 | 43 | static kern_return_t read_memory(task_t task, vm_address_t address, vm_size_t size, void **data) { 44 | *data = reinterpret_cast(address); 45 | return KERN_SUCCESS; 46 | } 47 | 48 | static Class * copy_class_list(size_t &size) { 49 | size = objc_getClassList(NULL, 0); 50 | Class * data = reinterpret_cast(malloc(sizeof(Class) * size)); 51 | 52 | for (;;) { 53 | size_t writ = objc_getClassList(data, (int)size); 54 | if (writ <= size) { 55 | size = writ; 56 | return data; 57 | } 58 | 59 | Class * copy = reinterpret_cast(realloc(data, sizeof(Class) * writ)); 60 | if (copy == NULL) { 61 | free(data); 62 | return NULL; 63 | } 64 | data = copy; 65 | size = writ; 66 | } 67 | } 68 | 69 | static void choose_(task_t task, void *baton, unsigned type, vm_range_t *ranges, unsigned count) { 70 | choice * choice = reinterpret_cast(baton); 71 | for (unsigned i = 0; i < count; ++i) { 72 | vm_range_t &range = ranges[i]; 73 | void * data = reinterpret_cast(range.address); 74 | size_t size = range.size; 75 | 76 | if (size < sizeof(ObjectStruct)) 77 | continue; 78 | 79 | uintptr_t * pointers = reinterpret_cast(data); 80 | #ifdef __arm64__ 81 | Class isa = (__bridge Class)((void *)(pointers[0] & 0x1fffffff8)); 82 | #else 83 | Class isa = reinterpret_cast(pointers[0]); 84 | #endif 85 | std::set::const_iterator result(choice->query_.find(isa)); 86 | if (result == choice->query_.end()) 87 | continue; 88 | 89 | size_t needed = class_getInstanceSize(*result); 90 | size_t boundary = 496; 91 | #ifdef __LP64__ 92 | boundary *= 2; 93 | #endif 94 | if ((needed <= boundary && (needed + 15) / 16 * 16 != size) || (needed > boundary && (needed + 511) / 512 * 512 != size)) 95 | continue; 96 | choice->result_.insert((__bridge id)(data)); 97 | } 98 | } 99 | 100 | @implementation JDChoose 101 | 102 | JD_REGISTER_PLUGIN(&choose, "choose"); 103 | 104 | + (NSArray *)choose:(Class)_class 105 | { 106 | vm_address_t * zones = NULL; 107 | unsigned size = 0; 108 | kern_return_t error = malloc_get_all_zones(0, &read_memory, &zones, &size); 109 | NSAssert(error == KERN_SUCCESS, @"[JSDebugger]::Something Wrong With Choose Function"); 110 | 111 | if (error != KERN_SUCCESS) return @[]; 112 | 113 | size_t number; 114 | Class * classes = copy_class_list(number); 115 | NSAssert(classes != NULL, @"[JSDebugger]::Classes Cannot Be NULL"); 116 | if (NULL == classes) return @[]; 117 | 118 | choice choice; 119 | 120 | for (size_t i = 0; i != number; ++i) { 121 | for (Class current = classes[i]; current != Nil; current = class_getSuperclass(current)) { 122 | if (current == _class) { 123 | choice.query_.insert(classes[i]); 124 | break; 125 | } 126 | } 127 | } 128 | free(classes); 129 | 130 | for (unsigned i = 0; i != size; ++i) { 131 | const malloc_zone_t * zone = reinterpret_cast(zones[i]); 132 | if (zone == NULL || zone->introspect == NULL) 133 | continue; 134 | zone->introspect->enumerator(mach_task_self(), &choice, MALLOC_PTR_IN_USE_RANGE_TYPE, zones[i], &read_memory, &choose_); 135 | } 136 | 137 | #if __has_feature(objc_arc) 138 | NSMutableArray * result = [[NSMutableArray alloc] init]; 139 | #else 140 | NSMutableArray * result = [[[NSMutableArray alloc] init] autorelease]; 141 | #endif 142 | 143 | for (auto iter = choice.result_.begin(); iter != choice.result_.end(); iter++) { 144 | [result addObject:(id)*iter]; 145 | } 146 | return result; 147 | } 148 | 149 | @end 150 | 151 | -------------------------------------------------------------------------------- /JSDebuggerDemo/Pods/Target Support Files/Pods-JSDebuggerDemo/Pods-JSDebuggerDemo-resources.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | mkdir -p "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 5 | 6 | RESOURCES_TO_COPY=${PODS_ROOT}/resources-to-copy-${TARGETNAME}.txt 7 | > "$RESOURCES_TO_COPY" 8 | 9 | XCASSET_FILES=() 10 | 11 | # This protects against multiple targets copying the same framework dependency at the same time. The solution 12 | # was originally proposed here: https://lists.samba.org/archive/rsync/2008-February/020158.html 13 | RSYNC_PROTECT_TMP_FILES=(--filter "P .*.??????") 14 | 15 | case "${TARGETED_DEVICE_FAMILY}" in 16 | 1,2) 17 | TARGET_DEVICE_ARGS="--target-device ipad --target-device iphone" 18 | ;; 19 | 1) 20 | TARGET_DEVICE_ARGS="--target-device iphone" 21 | ;; 22 | 2) 23 | TARGET_DEVICE_ARGS="--target-device ipad" 24 | ;; 25 | 3) 26 | TARGET_DEVICE_ARGS="--target-device tv" 27 | ;; 28 | 4) 29 | TARGET_DEVICE_ARGS="--target-device watch" 30 | ;; 31 | *) 32 | TARGET_DEVICE_ARGS="--target-device mac" 33 | ;; 34 | esac 35 | 36 | install_resource() 37 | { 38 | if [[ "$1" = /* ]] ; then 39 | RESOURCE_PATH="$1" 40 | else 41 | RESOURCE_PATH="${PODS_ROOT}/$1" 42 | fi 43 | if [[ ! -e "$RESOURCE_PATH" ]] ; then 44 | cat << EOM 45 | error: Resource "$RESOURCE_PATH" not found. Run 'pod install' to update the copy resources script. 46 | EOM 47 | exit 1 48 | fi 49 | case $RESOURCE_PATH in 50 | *.storyboard) 51 | echo "ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile ${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .storyboard`.storyboardc $RESOURCE_PATH --sdk ${SDKROOT} ${TARGET_DEVICE_ARGS}" || true 52 | ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .storyboard`.storyboardc" "$RESOURCE_PATH" --sdk "${SDKROOT}" ${TARGET_DEVICE_ARGS} 53 | ;; 54 | *.xib) 55 | echo "ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile ${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .xib`.nib $RESOURCE_PATH --sdk ${SDKROOT} ${TARGET_DEVICE_ARGS}" || true 56 | ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .xib`.nib" "$RESOURCE_PATH" --sdk "${SDKROOT}" ${TARGET_DEVICE_ARGS} 57 | ;; 58 | *.framework) 59 | echo "mkdir -p ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" || true 60 | mkdir -p "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 61 | echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" $RESOURCE_PATH ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" || true 62 | rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 63 | ;; 64 | *.xcdatamodel) 65 | echo "xcrun momc \"$RESOURCE_PATH\" \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH"`.mom\"" || true 66 | xcrun momc "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcdatamodel`.mom" 67 | ;; 68 | *.xcdatamodeld) 69 | echo "xcrun momc \"$RESOURCE_PATH\" \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcdatamodeld`.momd\"" || true 70 | xcrun momc "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcdatamodeld`.momd" 71 | ;; 72 | *.xcmappingmodel) 73 | echo "xcrun mapc \"$RESOURCE_PATH\" \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcmappingmodel`.cdm\"" || true 74 | xcrun mapc "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcmappingmodel`.cdm" 75 | ;; 76 | *.xcassets) 77 | ABSOLUTE_XCASSET_FILE="$RESOURCE_PATH" 78 | XCASSET_FILES+=("$ABSOLUTE_XCASSET_FILE") 79 | ;; 80 | *) 81 | echo "$RESOURCE_PATH" || true 82 | echo "$RESOURCE_PATH" >> "$RESOURCES_TO_COPY" 83 | ;; 84 | esac 85 | } 86 | 87 | mkdir -p "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 88 | rsync -avr --copy-links --no-relative --exclude '*/.svn/*' --files-from="$RESOURCES_TO_COPY" / "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 89 | if [[ "${ACTION}" == "install" ]] && [[ "${SKIP_INSTALL}" == "NO" ]]; then 90 | mkdir -p "${INSTALL_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 91 | rsync -avr --copy-links --no-relative --exclude '*/.svn/*' --files-from="$RESOURCES_TO_COPY" / "${INSTALL_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 92 | fi 93 | rm -f "$RESOURCES_TO_COPY" 94 | 95 | if [[ -n "${WRAPPER_EXTENSION}" ]] && [ "`xcrun --find actool`" ] && [ -n "$XCASSET_FILES" ] 96 | then 97 | # Find all other xcassets (this unfortunately includes those of path pods and other targets). 98 | OTHER_XCASSETS=$(find "$PWD" -iname "*.xcassets" -type d) 99 | while read line; do 100 | if [[ $line != "${PODS_ROOT}*" ]]; then 101 | XCASSET_FILES+=("$line") 102 | fi 103 | done <<<"$OTHER_XCASSETS" 104 | 105 | printf "%s\0" "${XCASSET_FILES[@]}" | xargs -0 xcrun actool --output-format human-readable-text --notices --warnings --platform "${PLATFORM_NAME}" --minimum-deployment-target "${!DEPLOYMENT_TARGET_SETTING_NAME}" ${TARGET_DEVICE_ARGS} --compress-pngs --compile "${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 106 | fi 107 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JSDebugger 2 | 3 | **JavaScript-Based Tool For Inspecting Running State Of Your Application** 4 | 5 | > The status of this project is under rapid development and first stable version is v0.8 6 | 7 | JSDebugger is a runtime inspecting tool for you to dig into details of your applications or change application logics dynamically. 8 | 9 | **You have call any Objective-C method at anytime without manually define JSExport!** 10 | 11 | ![](https://github.com/SatanWoo/BeeHive/blob/master/jstester.gif?raw=true) 12 | 13 | ## Usage 14 | 15 | ### Calling Methods 16 | 17 | var view = UIView.alloc().init(); 18 | var k = NSMutableArray.alloc().init(); 19 | view.setBackgroundColor_(UIColor.redColor()); 20 | 21 | You may notice the method name is to some extent different from Objective-C. To illustrate it more precisely, the following two steps are executed underlying before calling an Objective-C method: 22 | 23 | - All colons are converted to underscores. 24 | - Each part of the Objective-C selector is concatenated into single string. 25 | 26 | For Example: 27 | 28 | application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 29 | 30 | will be converted into following string: 31 | 32 | application_didFinishLaunchingWithOptions_(application, launchOptions) 33 | 34 | ### Variadic Arguments 35 | 36 | **JSDebugger** Support Variadic Arguments with NIL termination 37 | 38 | For Example: 39 | 40 | var array = NSArray.arrayWithObjects_(1, 2, 3); 41 | 42 | Or you can define your own method with variadic arguments 43 | 44 | In Objective-C, you define a class method `+ (void)test:(int)first,...NS_REQUIRES_NIL_TERMINATION` in `ViewController`, 45 | 46 | then you call it with following codes: 47 | 48 | ViewController.test_(1, 2, 3, 5, 7, 9, 8); 49 | 50 | 51 | ### Getter & Setter 52 | 53 | view.backgroundColor = UIColor.redColor(); 54 | var color = view.backgroundColor(); 55 | var bounds = view.bounds(); 56 | 57 | Getter Is Not Supported. Use Method Instead Of Getter!!! 58 | 59 | For Example: 60 | 61 | view.backgroundColor; // It's Wrong 62 | 63 | view.backgroundColor(); // It's Correct 64 | 65 | 66 | ### JavaScript 67 | 68 | The running context of **JSDebugger** is totally the same as an ordinary JavaScript file. You can do whatever your want in **JSDebugger** as long as it satisfied the requirement of JavaScript: 69 | 70 | var z = 5; 71 | 72 | var k = [1, 2, 3]; 73 | 74 | var z = {name:'haha', age:15, data:k}; 75 | 76 | 77 | ## Plugin 78 | 79 | Excluded from the core functions provided with **JSDebugger**, we develop plugin mechanism for you to enhance the ability that **JSDebugger** able to cover. 80 | 81 | ### Choose 82 | 83 | `Choose` aims to provide your with the ability to access any objects on heaps. The function will search all instances that match the class name you provided **exactly** and return all found results as an array. 84 | 85 | For Example, suppose you have a class named `XXXViewController` 86 | 87 | var vc = choose(XXXViewController); 88 | 89 | Then you will make some operation on it: 90 | 91 | vc.isViewLoaded(); 92 | var view = vc.view(); 93 | view.backgroundColor = UIColor.orangeColor(); 94 | 95 | ## Playground 96 | 97 | We provide you with a mechanism to debug instantly with the help of **JSDebugger Playground** 98 | 99 | It's already integrated into **JSDebugger**. The usage of it is quite simple, suppose you have a `test.js` on your `Desktop`. 100 | 101 | Follow steps listed below, 102 | 103 | 1. include `'JDLocalFileObserver.h'` and declare a reference to it. 104 | 105 | `@property (nonatomic, strong) JDLocalFileObserver *fileWatcher;` 106 | 107 | 2. Init it with path to your `test.js` and file change callback. 108 | 109 | NSString *jsFilePath = @"PathToDesktop/test.js"; 110 | 111 | if ([[NSFileManager defaultManager] fileExistsAtPath: jsFilePath]) { 112 | self.fileWatcher = [[JDLocalFileObserver alloc] initWithFilePath: jsFilePath changeBlock:^{ 113 | NSLog(@"[JSDebugger]::found test.js change"); 114 | dispatch_async(dispatch_get_main_queue(), ^{ 115 | [[JDEngine engine] evaluateScriptAtPath: jsFilePath]; 116 | }); 117 | }]; 118 | [self.fileWatcher start]; 119 | } 120 | 121 | 3. Now, whenever you change something in your `test.js` and **save it(Command + S)**, your will find **JSDebugger** automatically reload the content of `test.js` and start to evaluate it. 122 | 123 | 4. **Do not forget to stop the local file watch whenever you don't need it** 124 | 125 | [self.fileWatch stop] 126 | 127 | If you still get confused, just checkout the code in the JSDebuggerDemo. 128 | 129 | ## Example 130 | 131 | Checkout `demo.js` in the JSDebuggerDemo, it shows great detail of what you can do with **JSDebugger**. 132 | 133 | ## Contribution 134 | 135 | Please file a new issue if you feel confused or found some bugs. 136 | 137 | ## Features: 138 | 139 | Here we list all features currently supported by **JSDebugger**: 140 | - [x] Class Methods 141 | - [x] Instance Methods 142 | - [x] Instance Property 143 | - [x] Custom Setter 144 | - [x] Playground 145 | - [x] Data Structes: `primitive types`, `object`, `class`, `struct` (Partially) 146 | - [x] Choose 147 | - [x] Introspect (Partially) 148 | - [ ] Customized Struct 149 | - [x] Getter 150 | - [x] VA_LIST 151 | - [x] Associate Object 152 | - [ ] Block 153 | - [x] C Pointer 154 | 155 | ## What's Next 156 | 157 | An IDE with live Objective-C to JavaScript convertion is under development. 158 | You can really look forward to it! 159 | 160 | ## Reference 161 | 162 | The great works listed below inspired me a lot during the development of **JSDebugger**. 163 | 164 | - Cycript 165 | - [JSPatch](https://github.com/bang590/JSPatch) @Bang 166 | - [Choose](https://github.com/BlueCocoa/choose) @BlueCocoa 167 | 168 | ## License 169 | 170 | Copyright 2018 @SatanWoo 171 | 172 | Checkout [License](https://github.com/SatanWoo/JSDebugger/blob/master/LICENSE) 173 | -------------------------------------------------------------------------------- /Source/Core/FFI/Vendor/ffi_arm.h: -------------------------------------------------------------------------------- 1 | /* -----------------------------------------------------------------*-C-*- 2 | libffi 3.99999 - Copyright (c) 2011, 2014 Anthony Green 3 | - Copyright (c) 1996-2003, 2007, 2008 Red Hat, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person 6 | obtaining a copy of this software and associated documentation 7 | files (the ``Software''), to deal in the Software without 8 | restriction, including without limitation the rights to use, copy, 9 | modify, merge, publish, distribute, sublicense, and/or sell copies 10 | of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to 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 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 | 27 | /* ------------------------------------------------------------------- 28 | Most of the API is documented in doc/libffi.texi. 29 | 30 | The raw API is designed to bypass some of the argument packing and 31 | unpacking on architectures for which it can be avoided. Routines 32 | are provided to emulate the raw API if the underlying platform 33 | doesn't allow faster implementation. 34 | 35 | More details on the raw API can be found in: 36 | 37 | http://gcc.gnu.org/ml/java/1999-q3/msg00138.html 38 | 39 | and 40 | 41 | http://gcc.gnu.org/ml/java/1999-q3/msg00174.html 42 | -------------------------------------------------------------------- */ 43 | 44 | #ifndef LIBFFI_H 45 | #define LIBFFI_H 46 | 47 | #ifdef __cplusplus 48 | extern "C" { 49 | #endif 50 | 51 | /* Specify which architecture libffi is configured for. */ 52 | #ifndef ARM 53 | #define ARM 54 | #endif 55 | 56 | /* ---- System configuration information --------------------------------- */ 57 | 58 | #include 59 | 60 | #ifndef LIBFFI_ASM 61 | 62 | #if defined(_MSC_VER) && !defined(__clang__) 63 | #define __attribute__(X) 64 | #endif 65 | 66 | #include 67 | #include 68 | 69 | /* LONG_LONG_MAX is not always defined (not if STRICT_ANSI, for example). 70 | But we can find it either under the correct ANSI name, or under GNU 71 | C's internal name. */ 72 | 73 | #define FFI_64_BIT_MAX 9223372036854775807 74 | 75 | #ifdef LONG_LONG_MAX 76 | # define FFI_LONG_LONG_MAX LONG_LONG_MAX 77 | #else 78 | # ifdef LLONG_MAX 79 | # define FFI_LONG_LONG_MAX LLONG_MAX 80 | # ifdef _AIX52 /* or newer has C99 LLONG_MAX */ 81 | # undef FFI_64_BIT_MAX 82 | # define FFI_64_BIT_MAX 9223372036854775807LL 83 | # endif /* _AIX52 or newer */ 84 | # else 85 | # ifdef __GNUC__ 86 | # define FFI_LONG_LONG_MAX __LONG_LONG_MAX__ 87 | # endif 88 | # ifdef _AIX /* AIX 5.1 and earlier have LONGLONG_MAX */ 89 | # ifndef __PPC64__ 90 | # if defined (__IBMC__) || defined (__IBMCPP__) 91 | # define FFI_LONG_LONG_MAX LONGLONG_MAX 92 | # endif 93 | # endif /* __PPC64__ */ 94 | # undef FFI_64_BIT_MAX 95 | # define FFI_64_BIT_MAX 9223372036854775807LL 96 | # endif 97 | # endif 98 | #endif 99 | 100 | /* The closure code assumes that this works on pointers, i.e. a size_t 101 | can hold a pointer. */ 102 | 103 | typedef struct _ffi_type 104 | { 105 | size_t size; 106 | unsigned short alignment; 107 | unsigned short type; 108 | struct _ffi_type **elements; 109 | } ffi_type; 110 | 111 | #ifndef LIBFFI_HIDE_BASIC_TYPES 112 | #if SCHAR_MAX == 127 113 | # define ffi_type_uchar ffi_type_uint8 114 | # define ffi_type_schar ffi_type_sint8 115 | #else 116 | #error "char size not supported" 117 | #endif 118 | 119 | #if SHRT_MAX == 32767 120 | # define ffi_type_ushort ffi_type_uint16 121 | # define ffi_type_sshort ffi_type_sint16 122 | #elif SHRT_MAX == 2147483647 123 | # define ffi_type_ushort ffi_type_uint32 124 | # define ffi_type_sshort ffi_type_sint32 125 | #else 126 | #error "short size not supported" 127 | #endif 128 | 129 | #if INT_MAX == 32767 130 | # define ffi_type_uint ffi_type_uint16 131 | # define ffi_type_sint ffi_type_sint16 132 | #elif INT_MAX == 2147483647 133 | # define ffi_type_uint ffi_type_uint32 134 | # define ffi_type_sint ffi_type_sint32 135 | #elif INT_MAX == 9223372036854775807 136 | # define ffi_type_uint ffi_type_uint64 137 | # define ffi_type_sint ffi_type_sint64 138 | #else 139 | #error "int size not supported" 140 | #endif 141 | 142 | #if LONG_MAX == 2147483647 143 | # if FFI_LONG_LONG_MAX != FFI_64_BIT_MAX 144 | #error "no 64-bit data type supported" 145 | # endif 146 | #elif LONG_MAX != FFI_64_BIT_MAX 147 | #error "long size not supported" 148 | #endif 149 | 150 | #if LONG_MAX == 2147483647 151 | # define ffi_type_ulong ffi_type_uint32 152 | # define ffi_type_slong ffi_type_sint32 153 | #elif LONG_MAX == FFI_64_BIT_MAX 154 | # define ffi_type_ulong ffi_type_uint64 155 | # define ffi_type_slong ffi_type_sint64 156 | #else 157 | #error "long size not supported" 158 | #endif 159 | 160 | /* Need minimal decorations for DLLs to works on Windows. GCC has 161 | autoimport and autoexport. Rely on Libtool to help MSVC export 162 | from a DLL, but always declare data to be imported for MSVC 163 | clients. This costs an extra indirection for MSVC clients using 164 | the static version of the library, but don't worry about that. 165 | Besides, as a workaround, they can define FFI_BUILDING if they 166 | *know* they are going to link with the static library. */ 167 | #if defined _MSC_VER && !defined FFI_BUILDING 168 | #define FFI_EXTERN extern __declspec(dllimport) 169 | #else 170 | #define FFI_EXTERN extern 171 | #endif 172 | 173 | /* These are defined in types.c. */ 174 | FFI_EXTERN ffi_type ffi_type_void; 175 | FFI_EXTERN ffi_type ffi_type_uint8; 176 | FFI_EXTERN ffi_type ffi_type_sint8; 177 | FFI_EXTERN ffi_type ffi_type_uint16; 178 | FFI_EXTERN ffi_type ffi_type_sint16; 179 | FFI_EXTERN ffi_type ffi_type_uint32; 180 | FFI_EXTERN ffi_type ffi_type_sint32; 181 | FFI_EXTERN ffi_type ffi_type_uint64; 182 | FFI_EXTERN ffi_type ffi_type_sint64; 183 | FFI_EXTERN ffi_type ffi_type_float; 184 | FFI_EXTERN ffi_type ffi_type_double; 185 | FFI_EXTERN ffi_type ffi_type_pointer; 186 | 187 | #if 0 188 | FFI_EXTERN ffi_type ffi_type_longdouble; 189 | #else 190 | #define ffi_type_longdouble ffi_type_double 191 | #endif 192 | 193 | #ifdef FFI_TARGET_HAS_COMPLEX_TYPE 194 | FFI_EXTERN ffi_type ffi_type_complex_float; 195 | FFI_EXTERN ffi_type ffi_type_complex_double; 196 | #if 0 197 | FFI_EXTERN ffi_type ffi_type_complex_longdouble; 198 | #else 199 | #define ffi_type_complex_longdouble ffi_type_complex_double 200 | #endif 201 | #endif 202 | #endif /* LIBFFI_HIDE_BASIC_TYPES */ 203 | 204 | typedef enum { 205 | FFI_OK = 0, 206 | FFI_BAD_TYPEDEF, 207 | FFI_BAD_ABI 208 | } ffi_status; 209 | 210 | typedef struct { 211 | ffi_abi abi; 212 | unsigned nargs; 213 | ffi_type **arg_types; 214 | ffi_type *rtype; 215 | unsigned bytes; 216 | unsigned flags; 217 | #ifdef FFI_EXTRA_CIF_FIELDS 218 | FFI_EXTRA_CIF_FIELDS; 219 | #endif 220 | } ffi_cif; 221 | 222 | /* ---- Definitions for the raw API -------------------------------------- */ 223 | 224 | #ifndef FFI_SIZEOF_ARG 225 | # if LONG_MAX == 2147483647 226 | # define FFI_SIZEOF_ARG 4 227 | # elif LONG_MAX == FFI_64_BIT_MAX 228 | # define FFI_SIZEOF_ARG 8 229 | # endif 230 | #endif 231 | 232 | #ifndef FFI_SIZEOF_JAVA_RAW 233 | # define FFI_SIZEOF_JAVA_RAW FFI_SIZEOF_ARG 234 | #endif 235 | 236 | typedef union { 237 | ffi_sarg sint; 238 | ffi_arg uint; 239 | float flt; 240 | char data[FFI_SIZEOF_ARG]; 241 | void* ptr; 242 | } ffi_raw; 243 | 244 | #if FFI_SIZEOF_JAVA_RAW == 4 && FFI_SIZEOF_ARG == 8 245 | /* This is a special case for mips64/n32 ABI (and perhaps others) where 246 | sizeof(void *) is 4 and FFI_SIZEOF_ARG is 8. */ 247 | typedef union { 248 | signed int sint; 249 | unsigned int uint; 250 | float flt; 251 | char data[FFI_SIZEOF_JAVA_RAW]; 252 | void* ptr; 253 | } ffi_java_raw; 254 | #else 255 | typedef ffi_raw ffi_java_raw; 256 | #endif 257 | 258 | 259 | void ffi_raw_call (ffi_cif *cif, 260 | void (*fn)(void), 261 | void *rvalue, 262 | ffi_raw *avalue); 263 | 264 | void ffi_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_raw *raw); 265 | void ffi_raw_to_ptrarray (ffi_cif *cif, ffi_raw *raw, void **args); 266 | size_t ffi_raw_size (ffi_cif *cif); 267 | 268 | /* This is analogous to the raw API, except it uses Java parameter 269 | packing, even on 64-bit machines. I.e. on 64-bit machines longs 270 | and doubles are followed by an empty 64-bit word. */ 271 | 272 | void ffi_java_raw_call (ffi_cif *cif, 273 | void (*fn)(void), 274 | void *rvalue, 275 | ffi_java_raw *avalue); 276 | 277 | void ffi_java_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_java_raw *raw); 278 | void ffi_java_raw_to_ptrarray (ffi_cif *cif, ffi_java_raw *raw, void **args); 279 | size_t ffi_java_raw_size (ffi_cif *cif); 280 | 281 | /* ---- Definitions for closures ----------------------------------------- */ 282 | 283 | #if FFI_CLOSURES 284 | 285 | #ifdef _MSC_VER 286 | __declspec(align(8)) 287 | #endif 288 | typedef struct { 289 | #if 1 290 | void *trampoline_table; 291 | void *trampoline_table_entry; 292 | #else 293 | char tramp[FFI_TRAMPOLINE_SIZE]; 294 | #endif 295 | ffi_cif *cif; 296 | void (*fun)(ffi_cif*,void*,void**,void*); 297 | void *user_data; 298 | } ffi_closure 299 | #ifdef __GNUC__ 300 | __attribute__((aligned (8))) 301 | #endif 302 | ; 303 | 304 | #ifndef __GNUC__ 305 | # ifdef __sgi 306 | # pragma pack 0 307 | # endif 308 | #endif 309 | 310 | void *ffi_closure_alloc (size_t size, void **code); 311 | void ffi_closure_free (void *); 312 | 313 | ffi_status 314 | ffi_prep_closure (ffi_closure*, 315 | ffi_cif *, 316 | void (*fun)(ffi_cif*,void*,void**,void*), 317 | void *user_data) 318 | __attribute__((deprecated ("use ffi_prep_closure_loc instead"))); 319 | 320 | ffi_status 321 | ffi_prep_closure_loc (ffi_closure*, 322 | ffi_cif *, 323 | void (*fun)(ffi_cif*,void*,void**,void*), 324 | void *user_data, 325 | void*codeloc); 326 | 327 | #ifdef __sgi 328 | # pragma pack 8 329 | #endif 330 | typedef struct { 331 | #if 1 332 | void *trampoline_table; 333 | void *trampoline_table_entry; 334 | #else 335 | char tramp[FFI_TRAMPOLINE_SIZE]; 336 | #endif 337 | ffi_cif *cif; 338 | 339 | #if !FFI_NATIVE_RAW_API 340 | 341 | /* If this is enabled, then a raw closure has the same layout 342 | as a regular closure. We use this to install an intermediate 343 | handler to do the transaltion, void** -> ffi_raw*. */ 344 | 345 | void (*translate_args)(ffi_cif*,void*,void**,void*); 346 | void *this_closure; 347 | 348 | #endif 349 | 350 | void (*fun)(ffi_cif*,void*,ffi_raw*,void*); 351 | void *user_data; 352 | 353 | } ffi_raw_closure; 354 | 355 | typedef struct { 356 | #if 1 357 | void *trampoline_table; 358 | void *trampoline_table_entry; 359 | #else 360 | char tramp[FFI_TRAMPOLINE_SIZE]; 361 | #endif 362 | 363 | ffi_cif *cif; 364 | 365 | #if !FFI_NATIVE_RAW_API 366 | 367 | /* If this is enabled, then a raw closure has the same layout 368 | as a regular closure. We use this to install an intermediate 369 | handler to do the translation, void** -> ffi_raw*. */ 370 | 371 | void (*translate_args)(ffi_cif*,void*,void**,void*); 372 | void *this_closure; 373 | 374 | #endif 375 | 376 | void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*); 377 | void *user_data; 378 | 379 | } ffi_java_raw_closure; 380 | 381 | ffi_status 382 | ffi_prep_raw_closure (ffi_raw_closure*, 383 | ffi_cif *cif, 384 | void (*fun)(ffi_cif*,void*,ffi_raw*,void*), 385 | void *user_data); 386 | 387 | ffi_status 388 | ffi_prep_raw_closure_loc (ffi_raw_closure*, 389 | ffi_cif *cif, 390 | void (*fun)(ffi_cif*,void*,ffi_raw*,void*), 391 | void *user_data, 392 | void *codeloc); 393 | 394 | ffi_status 395 | ffi_prep_java_raw_closure (ffi_java_raw_closure*, 396 | ffi_cif *cif, 397 | void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*), 398 | void *user_data); 399 | 400 | ffi_status 401 | ffi_prep_java_raw_closure_loc (ffi_java_raw_closure*, 402 | ffi_cif *cif, 403 | void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*), 404 | void *user_data, 405 | void *codeloc); 406 | 407 | #endif /* FFI_CLOSURES */ 408 | 409 | #if FFI_GO_CLOSURES 410 | 411 | typedef struct { 412 | void *tramp; 413 | ffi_cif *cif; 414 | void (*fun)(ffi_cif*,void*,void**,void*); 415 | } ffi_go_closure; 416 | 417 | ffi_status ffi_prep_go_closure (ffi_go_closure*, ffi_cif *, 418 | void (*fun)(ffi_cif*,void*,void**,void*)); 419 | 420 | void ffi_call_go (ffi_cif *cif, void (*fn)(void), void *rvalue, 421 | void **avalue, void *closure); 422 | 423 | #endif /* FFI_GO_CLOSURES */ 424 | 425 | /* ---- Public interface definition -------------------------------------- */ 426 | 427 | ffi_status ffi_prep_cif(ffi_cif *cif, 428 | ffi_abi abi, 429 | unsigned int nargs, 430 | ffi_type *rtype, 431 | ffi_type **atypes); 432 | 433 | ffi_status ffi_prep_cif_var(ffi_cif *cif, 434 | ffi_abi abi, 435 | unsigned int nfixedargs, 436 | unsigned int ntotalargs, 437 | ffi_type *rtype, 438 | ffi_type **atypes); 439 | 440 | void ffi_call(ffi_cif *cif, 441 | void (*fn)(void), 442 | void *rvalue, 443 | void **avalue); 444 | 445 | ffi_status ffi_get_struct_offsets (ffi_abi abi, ffi_type *struct_type, 446 | size_t *offsets); 447 | 448 | /* Useful for eliminating compiler warnings. */ 449 | #define FFI_FN(f) ((void (*)(void))f) 450 | 451 | /* ---- Definitions shared with assembly code ---------------------------- */ 452 | 453 | #endif 454 | 455 | /* If these change, update src/mips/ffitarget.h. */ 456 | #define FFI_TYPE_VOID 0 457 | #define FFI_TYPE_INT 1 458 | #define FFI_TYPE_FLOAT 2 459 | #define FFI_TYPE_DOUBLE 3 460 | #if 0 461 | #define FFI_TYPE_LONGDOUBLE 4 462 | #else 463 | #define FFI_TYPE_LONGDOUBLE FFI_TYPE_DOUBLE 464 | #endif 465 | #define FFI_TYPE_UINT8 5 466 | #define FFI_TYPE_SINT8 6 467 | #define FFI_TYPE_UINT16 7 468 | #define FFI_TYPE_SINT16 8 469 | #define FFI_TYPE_UINT32 9 470 | #define FFI_TYPE_SINT32 10 471 | #define FFI_TYPE_UINT64 11 472 | #define FFI_TYPE_SINT64 12 473 | #define FFI_TYPE_STRUCT 13 474 | #define FFI_TYPE_POINTER 14 475 | #define FFI_TYPE_COMPLEX 15 476 | 477 | /* This should always refer to the last type code (for sanity checks). */ 478 | #define FFI_TYPE_LAST FFI_TYPE_COMPLEX 479 | 480 | #ifdef __cplusplus 481 | } 482 | #endif 483 | 484 | #endif 485 | -------------------------------------------------------------------------------- /Source/Core/FFI/Vendor/ffi_x86_64.h: -------------------------------------------------------------------------------- 1 | /* -----------------------------------------------------------------*-C-*- 2 | libffi 3.99999 - Copyright (c) 2011, 2014 Anthony Green 3 | - Copyright (c) 1996-2003, 2007, 2008 Red Hat, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person 6 | obtaining a copy of this software and associated documentation 7 | files (the ``Software''), to deal in the Software without 8 | restriction, including without limitation the rights to use, copy, 9 | modify, merge, publish, distribute, sublicense, and/or sell copies 10 | of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to 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 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 | 27 | /* ------------------------------------------------------------------- 28 | Most of the API is documented in doc/libffi.texi. 29 | 30 | The raw API is designed to bypass some of the argument packing and 31 | unpacking on architectures for which it can be avoided. Routines 32 | are provided to emulate the raw API if the underlying platform 33 | doesn't allow faster implementation. 34 | 35 | More details on the raw API can be found in: 36 | 37 | http://gcc.gnu.org/ml/java/1999-q3/msg00138.html 38 | 39 | and 40 | 41 | http://gcc.gnu.org/ml/java/1999-q3/msg00174.html 42 | -------------------------------------------------------------------- */ 43 | 44 | #ifndef LIBFFI_H 45 | #define LIBFFI_H 46 | 47 | #ifdef __cplusplus 48 | extern "C" { 49 | #endif 50 | 51 | /* Specify which architecture libffi is configured for. */ 52 | #ifndef X86_64 53 | #define X86_64 54 | #endif 55 | 56 | /* ---- System configuration information --------------------------------- */ 57 | 58 | #include "ffitarget.h" 59 | 60 | #ifndef LIBFFI_ASM 61 | 62 | #if defined(_MSC_VER) && !defined(__clang__) 63 | #define __attribute__(X) 64 | #endif 65 | 66 | #include 67 | #include 68 | 69 | /* LONG_LONG_MAX is not always defined (not if STRICT_ANSI, for example). 70 | But we can find it either under the correct ANSI name, or under GNU 71 | C's internal name. */ 72 | 73 | #define FFI_64_BIT_MAX 9223372036854775807 74 | 75 | #ifdef LONG_LONG_MAX 76 | # define FFI_LONG_LONG_MAX LONG_LONG_MAX 77 | #else 78 | # ifdef LLONG_MAX 79 | # define FFI_LONG_LONG_MAX LLONG_MAX 80 | # ifdef _AIX52 /* or newer has C99 LLONG_MAX */ 81 | # undef FFI_64_BIT_MAX 82 | # define FFI_64_BIT_MAX 9223372036854775807LL 83 | # endif /* _AIX52 or newer */ 84 | # else 85 | # ifdef __GNUC__ 86 | # define FFI_LONG_LONG_MAX __LONG_LONG_MAX__ 87 | # endif 88 | # ifdef _AIX /* AIX 5.1 and earlier have LONGLONG_MAX */ 89 | # ifndef __PPC64__ 90 | # if defined (__IBMC__) || defined (__IBMCPP__) 91 | # define FFI_LONG_LONG_MAX LONGLONG_MAX 92 | # endif 93 | # endif /* __PPC64__ */ 94 | # undef FFI_64_BIT_MAX 95 | # define FFI_64_BIT_MAX 9223372036854775807LL 96 | # endif 97 | # endif 98 | #endif 99 | 100 | /* The closure code assumes that this works on pointers, i.e. a size_t 101 | can hold a pointer. */ 102 | 103 | typedef struct _ffi_type 104 | { 105 | size_t size; 106 | unsigned short alignment; 107 | unsigned short type; 108 | struct _ffi_type **elements; 109 | } ffi_type; 110 | 111 | #ifndef LIBFFI_HIDE_BASIC_TYPES 112 | #if SCHAR_MAX == 127 113 | # define ffi_type_uchar ffi_type_uint8 114 | # define ffi_type_schar ffi_type_sint8 115 | #else 116 | #error "char size not supported" 117 | #endif 118 | 119 | #if SHRT_MAX == 32767 120 | # define ffi_type_ushort ffi_type_uint16 121 | # define ffi_type_sshort ffi_type_sint16 122 | #elif SHRT_MAX == 2147483647 123 | # define ffi_type_ushort ffi_type_uint32 124 | # define ffi_type_sshort ffi_type_sint32 125 | #else 126 | #error "short size not supported" 127 | #endif 128 | 129 | #if INT_MAX == 32767 130 | # define ffi_type_uint ffi_type_uint16 131 | # define ffi_type_sint ffi_type_sint16 132 | #elif INT_MAX == 2147483647 133 | # define ffi_type_uint ffi_type_uint32 134 | # define ffi_type_sint ffi_type_sint32 135 | #elif INT_MAX == 9223372036854775807 136 | # define ffi_type_uint ffi_type_uint64 137 | # define ffi_type_sint ffi_type_sint64 138 | #else 139 | #error "int size not supported" 140 | #endif 141 | 142 | #if LONG_MAX == 2147483647 143 | # if FFI_LONG_LONG_MAX != FFI_64_BIT_MAX 144 | #error "no 64-bit data type supported" 145 | # endif 146 | #elif LONG_MAX != FFI_64_BIT_MAX 147 | #error "long size not supported" 148 | #endif 149 | 150 | #if LONG_MAX == 2147483647 151 | # define ffi_type_ulong ffi_type_uint32 152 | # define ffi_type_slong ffi_type_sint32 153 | #elif LONG_MAX == FFI_64_BIT_MAX 154 | # define ffi_type_ulong ffi_type_uint64 155 | # define ffi_type_slong ffi_type_sint64 156 | #else 157 | #error "long size not supported" 158 | #endif 159 | 160 | /* Need minimal decorations for DLLs to works on Windows. GCC has 161 | autoimport and autoexport. Rely on Libtool to help MSVC export 162 | from a DLL, but always declare data to be imported for MSVC 163 | clients. This costs an extra indirection for MSVC clients using 164 | the static version of the library, but don't worry about that. 165 | Besides, as a workaround, they can define FFI_BUILDING if they 166 | *know* they are going to link with the static library. */ 167 | #if defined _MSC_VER && !defined FFI_BUILDING 168 | #define FFI_EXTERN extern __declspec(dllimport) 169 | #else 170 | #define FFI_EXTERN extern 171 | #endif 172 | 173 | /* These are defined in types.c. */ 174 | FFI_EXTERN ffi_type ffi_type_void; 175 | FFI_EXTERN ffi_type ffi_type_uint8; 176 | FFI_EXTERN ffi_type ffi_type_sint8; 177 | FFI_EXTERN ffi_type ffi_type_uint16; 178 | FFI_EXTERN ffi_type ffi_type_sint16; 179 | FFI_EXTERN ffi_type ffi_type_uint32; 180 | FFI_EXTERN ffi_type ffi_type_sint32; 181 | FFI_EXTERN ffi_type ffi_type_uint64; 182 | FFI_EXTERN ffi_type ffi_type_sint64; 183 | FFI_EXTERN ffi_type ffi_type_float; 184 | FFI_EXTERN ffi_type ffi_type_double; 185 | FFI_EXTERN ffi_type ffi_type_pointer; 186 | 187 | #if 1 188 | FFI_EXTERN ffi_type ffi_type_longdouble; 189 | #else 190 | #define ffi_type_longdouble ffi_type_double 191 | #endif 192 | 193 | #ifdef FFI_TARGET_HAS_COMPLEX_TYPE 194 | FFI_EXTERN ffi_type ffi_type_complex_float; 195 | FFI_EXTERN ffi_type ffi_type_complex_double; 196 | #if 1 197 | FFI_EXTERN ffi_type ffi_type_complex_longdouble; 198 | #else 199 | #define ffi_type_complex_longdouble ffi_type_complex_double 200 | #endif 201 | #endif 202 | #endif /* LIBFFI_HIDE_BASIC_TYPES */ 203 | 204 | typedef enum { 205 | FFI_OK = 0, 206 | FFI_BAD_TYPEDEF, 207 | FFI_BAD_ABI 208 | } ffi_status; 209 | 210 | typedef struct { 211 | ffi_abi abi; 212 | unsigned nargs; 213 | ffi_type **arg_types; 214 | ffi_type *rtype; 215 | unsigned bytes; 216 | unsigned flags; 217 | #ifdef FFI_EXTRA_CIF_FIELDS 218 | FFI_EXTRA_CIF_FIELDS; 219 | #endif 220 | } ffi_cif; 221 | 222 | /* ---- Definitions for the raw API -------------------------------------- */ 223 | 224 | #ifndef FFI_SIZEOF_ARG 225 | # if LONG_MAX == 2147483647 226 | # define FFI_SIZEOF_ARG 4 227 | # elif LONG_MAX == FFI_64_BIT_MAX 228 | # define FFI_SIZEOF_ARG 8 229 | # endif 230 | #endif 231 | 232 | #ifndef FFI_SIZEOF_JAVA_RAW 233 | # define FFI_SIZEOF_JAVA_RAW FFI_SIZEOF_ARG 234 | #endif 235 | 236 | typedef union { 237 | ffi_sarg sint; 238 | ffi_arg uint; 239 | float flt; 240 | char data[FFI_SIZEOF_ARG]; 241 | void* ptr; 242 | } ffi_raw; 243 | 244 | #if FFI_SIZEOF_JAVA_RAW == 4 && FFI_SIZEOF_ARG == 8 245 | /* This is a special case for mips64/n32 ABI (and perhaps others) where 246 | sizeof(void *) is 4 and FFI_SIZEOF_ARG is 8. */ 247 | typedef union { 248 | signed int sint; 249 | unsigned int uint; 250 | float flt; 251 | char data[FFI_SIZEOF_JAVA_RAW]; 252 | void* ptr; 253 | } ffi_java_raw; 254 | #else 255 | typedef ffi_raw ffi_java_raw; 256 | #endif 257 | 258 | 259 | void ffi_raw_call (ffi_cif *cif, 260 | void (*fn)(void), 261 | void *rvalue, 262 | ffi_raw *avalue); 263 | 264 | void ffi_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_raw *raw); 265 | void ffi_raw_to_ptrarray (ffi_cif *cif, ffi_raw *raw, void **args); 266 | size_t ffi_raw_size (ffi_cif *cif); 267 | 268 | /* This is analogous to the raw API, except it uses Java parameter 269 | packing, even on 64-bit machines. I.e. on 64-bit machines longs 270 | and doubles are followed by an empty 64-bit word. */ 271 | 272 | void ffi_java_raw_call (ffi_cif *cif, 273 | void (*fn)(void), 274 | void *rvalue, 275 | ffi_java_raw *avalue); 276 | 277 | void ffi_java_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_java_raw *raw); 278 | void ffi_java_raw_to_ptrarray (ffi_cif *cif, ffi_java_raw *raw, void **args); 279 | size_t ffi_java_raw_size (ffi_cif *cif); 280 | 281 | /* ---- Definitions for closures ----------------------------------------- */ 282 | 283 | #if FFI_CLOSURES 284 | 285 | #ifdef _MSC_VER 286 | __declspec(align(8)) 287 | #endif 288 | typedef struct { 289 | #if 0 290 | void *trampoline_table; 291 | void *trampoline_table_entry; 292 | #else 293 | char tramp[FFI_TRAMPOLINE_SIZE]; 294 | #endif 295 | ffi_cif *cif; 296 | void (*fun)(ffi_cif*,void*,void**,void*); 297 | void *user_data; 298 | } ffi_closure 299 | #ifdef __GNUC__ 300 | __attribute__((aligned (8))) 301 | #endif 302 | ; 303 | 304 | #ifndef __GNUC__ 305 | # ifdef __sgi 306 | # pragma pack 0 307 | # endif 308 | #endif 309 | 310 | void *ffi_closure_alloc (size_t size, void **code); 311 | void ffi_closure_free (void *); 312 | 313 | ffi_status 314 | ffi_prep_closure (ffi_closure*, 315 | ffi_cif *, 316 | void (*fun)(ffi_cif*,void*,void**,void*), 317 | void *user_data) 318 | __attribute__((deprecated ("use ffi_prep_closure_loc instead"))); 319 | 320 | ffi_status 321 | ffi_prep_closure_loc (ffi_closure*, 322 | ffi_cif *, 323 | void (*fun)(ffi_cif*,void*,void**,void*), 324 | void *user_data, 325 | void*codeloc); 326 | 327 | #ifdef __sgi 328 | # pragma pack 8 329 | #endif 330 | typedef struct { 331 | #if 0 332 | void *trampoline_table; 333 | void *trampoline_table_entry; 334 | #else 335 | char tramp[FFI_TRAMPOLINE_SIZE]; 336 | #endif 337 | ffi_cif *cif; 338 | 339 | #if !FFI_NATIVE_RAW_API 340 | 341 | /* If this is enabled, then a raw closure has the same layout 342 | as a regular closure. We use this to install an intermediate 343 | handler to do the transaltion, void** -> ffi_raw*. */ 344 | 345 | void (*translate_args)(ffi_cif*,void*,void**,void*); 346 | void *this_closure; 347 | 348 | #endif 349 | 350 | void (*fun)(ffi_cif*,void*,ffi_raw*,void*); 351 | void *user_data; 352 | 353 | } ffi_raw_closure; 354 | 355 | typedef struct { 356 | #if 0 357 | void *trampoline_table; 358 | void *trampoline_table_entry; 359 | #else 360 | char tramp[FFI_TRAMPOLINE_SIZE]; 361 | #endif 362 | 363 | ffi_cif *cif; 364 | 365 | #if !FFI_NATIVE_RAW_API 366 | 367 | /* If this is enabled, then a raw closure has the same layout 368 | as a regular closure. We use this to install an intermediate 369 | handler to do the translation, void** -> ffi_raw*. */ 370 | 371 | void (*translate_args)(ffi_cif*,void*,void**,void*); 372 | void *this_closure; 373 | 374 | #endif 375 | 376 | void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*); 377 | void *user_data; 378 | 379 | } ffi_java_raw_closure; 380 | 381 | ffi_status 382 | ffi_prep_raw_closure (ffi_raw_closure*, 383 | ffi_cif *cif, 384 | void (*fun)(ffi_cif*,void*,ffi_raw*,void*), 385 | void *user_data); 386 | 387 | ffi_status 388 | ffi_prep_raw_closure_loc (ffi_raw_closure*, 389 | ffi_cif *cif, 390 | void (*fun)(ffi_cif*,void*,ffi_raw*,void*), 391 | void *user_data, 392 | void *codeloc); 393 | 394 | ffi_status 395 | ffi_prep_java_raw_closure (ffi_java_raw_closure*, 396 | ffi_cif *cif, 397 | void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*), 398 | void *user_data); 399 | 400 | ffi_status 401 | ffi_prep_java_raw_closure_loc (ffi_java_raw_closure*, 402 | ffi_cif *cif, 403 | void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*), 404 | void *user_data, 405 | void *codeloc); 406 | 407 | #endif /* FFI_CLOSURES */ 408 | 409 | #if FFI_GO_CLOSURES 410 | 411 | typedef struct { 412 | void *tramp; 413 | ffi_cif *cif; 414 | void (*fun)(ffi_cif*,void*,void**,void*); 415 | } ffi_go_closure; 416 | 417 | ffi_status ffi_prep_go_closure (ffi_go_closure*, ffi_cif *, 418 | void (*fun)(ffi_cif*,void*,void**,void*)); 419 | 420 | void ffi_call_go (ffi_cif *cif, void (*fn)(void), void *rvalue, 421 | void **avalue, void *closure); 422 | 423 | #endif /* FFI_GO_CLOSURES */ 424 | 425 | /* ---- Public interface definition -------------------------------------- */ 426 | 427 | ffi_status ffi_prep_cif(ffi_cif *cif, 428 | ffi_abi abi, 429 | unsigned int nargs, 430 | ffi_type *rtype, 431 | ffi_type **atypes); 432 | 433 | ffi_status ffi_prep_cif_var(ffi_cif *cif, 434 | ffi_abi abi, 435 | unsigned int nfixedargs, 436 | unsigned int ntotalargs, 437 | ffi_type *rtype, 438 | ffi_type **atypes); 439 | 440 | void ffi_call(ffi_cif *cif, 441 | void (*fn)(void), 442 | void *rvalue, 443 | void **avalue); 444 | 445 | ffi_status ffi_get_struct_offsets (ffi_abi abi, ffi_type *struct_type, 446 | size_t *offsets); 447 | 448 | /* Useful for eliminating compiler warnings. */ 449 | #define FFI_FN(f) ((void (*)(void))f) 450 | 451 | /* ---- Definitions shared with assembly code ---------------------------- */ 452 | 453 | #endif 454 | 455 | /* If these change, update src/mips/ffitarget.h. */ 456 | #define FFI_TYPE_VOID 0 457 | #define FFI_TYPE_INT 1 458 | #define FFI_TYPE_FLOAT 2 459 | #define FFI_TYPE_DOUBLE 3 460 | #if 1 461 | #define FFI_TYPE_LONGDOUBLE 4 462 | #else 463 | #define FFI_TYPE_LONGDOUBLE FFI_TYPE_DOUBLE 464 | #endif 465 | #define FFI_TYPE_UINT8 5 466 | #define FFI_TYPE_SINT8 6 467 | #define FFI_TYPE_UINT16 7 468 | #define FFI_TYPE_SINT16 8 469 | #define FFI_TYPE_UINT32 9 470 | #define FFI_TYPE_SINT32 10 471 | #define FFI_TYPE_UINT64 11 472 | #define FFI_TYPE_SINT64 12 473 | #define FFI_TYPE_STRUCT 13 474 | #define FFI_TYPE_POINTER 14 475 | #define FFI_TYPE_COMPLEX 15 476 | 477 | /* This should always refer to the last type code (for sanity checks). */ 478 | #define FFI_TYPE_LAST FFI_TYPE_COMPLEX 479 | 480 | #ifdef __cplusplus 481 | } 482 | #endif 483 | 484 | #endif 485 | -------------------------------------------------------------------------------- /Source/Core/FFI/Vendor/ffi_arm64.h: -------------------------------------------------------------------------------- 1 | /* -----------------------------------------------------------------*-C-*- 2 | libffi 3.99999 - Copyright (c) 2011, 2014 Anthony Green 3 | - Copyright (c) 1996-2003, 2007, 2008 Red Hat, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person 6 | obtaining a copy of this software and associated documentation 7 | files (the ``Software''), to deal in the Software without 8 | restriction, including without limitation the rights to use, copy, 9 | modify, merge, publish, distribute, sublicense, and/or sell copies 10 | of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to 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 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 | 27 | /* ------------------------------------------------------------------- 28 | Most of the API is documented in doc/libffi.texi. 29 | 30 | The raw API is designed to bypass some of the argument packing and 31 | unpacking on architectures for which it can be avoided. Routines 32 | are provided to emulate the raw API if the underlying platform 33 | doesn't allow faster implementation. 34 | 35 | More details on the raw API can be found in: 36 | 37 | http://gcc.gnu.org/ml/java/1999-q3/msg00138.html 38 | 39 | and 40 | 41 | http://gcc.gnu.org/ml/java/1999-q3/msg00174.html 42 | -------------------------------------------------------------------- */ 43 | 44 | #ifndef LIBFFI_H 45 | #define LIBFFI_H 46 | 47 | #ifdef __cplusplus 48 | extern "C" { 49 | #endif 50 | 51 | /* Specify which architecture libffi is configured for. */ 52 | #ifndef AARCH64 53 | #define AARCH64 54 | #endif 55 | 56 | /* ---- System configuration information --------------------------------- */ 57 | 58 | #include "ffitarget.h" 59 | 60 | #ifndef LIBFFI_ASM 61 | 62 | #if defined(_MSC_VER) && !defined(__clang__) 63 | #define __attribute__(X) 64 | #endif 65 | 66 | #include 67 | #include 68 | 69 | /* LONG_LONG_MAX is not always defined (not if STRICT_ANSI, for example). 70 | But we can find it either under the correct ANSI name, or under GNU 71 | C's internal name. */ 72 | 73 | #define FFI_64_BIT_MAX 9223372036854775807 74 | 75 | #ifdef LONG_LONG_MAX 76 | # define FFI_LONG_LONG_MAX LONG_LONG_MAX 77 | #else 78 | # ifdef LLONG_MAX 79 | # define FFI_LONG_LONG_MAX LLONG_MAX 80 | # ifdef _AIX52 /* or newer has C99 LLONG_MAX */ 81 | # undef FFI_64_BIT_MAX 82 | # define FFI_64_BIT_MAX 9223372036854775807LL 83 | # endif /* _AIX52 or newer */ 84 | # else 85 | # ifdef __GNUC__ 86 | # define FFI_LONG_LONG_MAX __LONG_LONG_MAX__ 87 | # endif 88 | # ifdef _AIX /* AIX 5.1 and earlier have LONGLONG_MAX */ 89 | # ifndef __PPC64__ 90 | # if defined (__IBMC__) || defined (__IBMCPP__) 91 | # define FFI_LONG_LONG_MAX LONGLONG_MAX 92 | # endif 93 | # endif /* __PPC64__ */ 94 | # undef FFI_64_BIT_MAX 95 | # define FFI_64_BIT_MAX 9223372036854775807LL 96 | # endif 97 | # endif 98 | #endif 99 | 100 | /* The closure code assumes that this works on pointers, i.e. a size_t 101 | can hold a pointer. */ 102 | 103 | typedef struct _ffi_type 104 | { 105 | size_t size; 106 | unsigned short alignment; 107 | unsigned short type; 108 | struct _ffi_type **elements; 109 | } ffi_type; 110 | 111 | #ifndef LIBFFI_HIDE_BASIC_TYPES 112 | #if SCHAR_MAX == 127 113 | # define ffi_type_uchar ffi_type_uint8 114 | # define ffi_type_schar ffi_type_sint8 115 | #else 116 | #error "char size not supported" 117 | #endif 118 | 119 | #if SHRT_MAX == 32767 120 | # define ffi_type_ushort ffi_type_uint16 121 | # define ffi_type_sshort ffi_type_sint16 122 | #elif SHRT_MAX == 2147483647 123 | # define ffi_type_ushort ffi_type_uint32 124 | # define ffi_type_sshort ffi_type_sint32 125 | #else 126 | #error "short size not supported" 127 | #endif 128 | 129 | #if INT_MAX == 32767 130 | # define ffi_type_uint ffi_type_uint16 131 | # define ffi_type_sint ffi_type_sint16 132 | #elif INT_MAX == 2147483647 133 | # define ffi_type_uint ffi_type_uint32 134 | # define ffi_type_sint ffi_type_sint32 135 | #elif INT_MAX == 9223372036854775807 136 | # define ffi_type_uint ffi_type_uint64 137 | # define ffi_type_sint ffi_type_sint64 138 | #else 139 | #error "int size not supported" 140 | #endif 141 | 142 | #if LONG_MAX == 2147483647 143 | # if FFI_LONG_LONG_MAX != FFI_64_BIT_MAX 144 | #error "no 64-bit data type supported" 145 | # endif 146 | #elif LONG_MAX != FFI_64_BIT_MAX 147 | #error "long size not supported" 148 | #endif 149 | 150 | #if LONG_MAX == 2147483647 151 | # define ffi_type_ulong ffi_type_uint32 152 | # define ffi_type_slong ffi_type_sint32 153 | #elif LONG_MAX == FFI_64_BIT_MAX 154 | # define ffi_type_ulong ffi_type_uint64 155 | # define ffi_type_slong ffi_type_sint64 156 | #else 157 | #error "long size not supported" 158 | #endif 159 | 160 | /* Need minimal decorations for DLLs to works on Windows. GCC has 161 | autoimport and autoexport. Rely on Libtool to help MSVC export 162 | from a DLL, but always declare data to be imported for MSVC 163 | clients. This costs an extra indirection for MSVC clients using 164 | the static version of the library, but don't worry about that. 165 | Besides, as a workaround, they can define FFI_BUILDING if they 166 | *know* they are going to link with the static library. */ 167 | #if defined _MSC_VER && !defined FFI_BUILDING 168 | #define FFI_EXTERN extern __declspec(dllimport) 169 | #else 170 | #define FFI_EXTERN extern 171 | #endif 172 | 173 | /* These are defined in types.c. */ 174 | FFI_EXTERN ffi_type ffi_type_void; 175 | FFI_EXTERN ffi_type ffi_type_uint8; 176 | FFI_EXTERN ffi_type ffi_type_sint8; 177 | FFI_EXTERN ffi_type ffi_type_uint16; 178 | FFI_EXTERN ffi_type ffi_type_sint16; 179 | FFI_EXTERN ffi_type ffi_type_uint32; 180 | FFI_EXTERN ffi_type ffi_type_sint32; 181 | FFI_EXTERN ffi_type ffi_type_uint64; 182 | FFI_EXTERN ffi_type ffi_type_sint64; 183 | FFI_EXTERN ffi_type ffi_type_float; 184 | FFI_EXTERN ffi_type ffi_type_double; 185 | FFI_EXTERN ffi_type ffi_type_pointer; 186 | 187 | #if 0 188 | FFI_EXTERN ffi_type ffi_type_longdouble; 189 | #else 190 | #define ffi_type_longdouble ffi_type_double 191 | #endif 192 | 193 | #ifdef FFI_TARGET_HAS_COMPLEX_TYPE 194 | FFI_EXTERN ffi_type ffi_type_complex_float; 195 | FFI_EXTERN ffi_type ffi_type_complex_double; 196 | #if 0 197 | FFI_EXTERN ffi_type ffi_type_complex_longdouble; 198 | #else 199 | #define ffi_type_complex_longdouble ffi_type_complex_double 200 | #endif 201 | #endif 202 | #endif /* LIBFFI_HIDE_BASIC_TYPES */ 203 | 204 | typedef enum { 205 | FFI_OK = 0, 206 | FFI_BAD_TYPEDEF, 207 | FFI_BAD_ABI 208 | } ffi_status; 209 | 210 | typedef struct { 211 | ffi_abi abi; 212 | unsigned nargs; 213 | ffi_type **arg_types; 214 | ffi_type *rtype; 215 | unsigned bytes; 216 | unsigned flags; 217 | #ifdef FFI_EXTRA_CIF_FIELDS 218 | FFI_EXTRA_CIF_FIELDS; 219 | #endif 220 | } ffi_cif; 221 | 222 | /* ---- Definitions for the raw API -------------------------------------- */ 223 | 224 | #ifndef FFI_SIZEOF_ARG 225 | # if LONG_MAX == 2147483647 226 | # define FFI_SIZEOF_ARG 4 227 | # elif LONG_MAX == FFI_64_BIT_MAX 228 | # define FFI_SIZEOF_ARG 8 229 | # endif 230 | #endif 231 | 232 | #ifndef FFI_SIZEOF_JAVA_RAW 233 | # define FFI_SIZEOF_JAVA_RAW FFI_SIZEOF_ARG 234 | #endif 235 | 236 | typedef union { 237 | ffi_sarg sint; 238 | ffi_arg uint; 239 | float flt; 240 | char data[FFI_SIZEOF_ARG]; 241 | void* ptr; 242 | } ffi_raw; 243 | 244 | #if FFI_SIZEOF_JAVA_RAW == 4 && FFI_SIZEOF_ARG == 8 245 | /* This is a special case for mips64/n32 ABI (and perhaps others) where 246 | sizeof(void *) is 4 and FFI_SIZEOF_ARG is 8. */ 247 | typedef union { 248 | signed int sint; 249 | unsigned int uint; 250 | float flt; 251 | char data[FFI_SIZEOF_JAVA_RAW]; 252 | void* ptr; 253 | } ffi_java_raw; 254 | #else 255 | typedef ffi_raw ffi_java_raw; 256 | #endif 257 | 258 | 259 | void ffi_raw_call (ffi_cif *cif, 260 | void (*fn)(void), 261 | void *rvalue, 262 | ffi_raw *avalue); 263 | 264 | void ffi_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_raw *raw); 265 | void ffi_raw_to_ptrarray (ffi_cif *cif, ffi_raw *raw, void **args); 266 | size_t ffi_raw_size (ffi_cif *cif); 267 | 268 | /* This is analogous to the raw API, except it uses Java parameter 269 | packing, even on 64-bit machines. I.e. on 64-bit machines longs 270 | and doubles are followed by an empty 64-bit word. */ 271 | 272 | void ffi_java_raw_call (ffi_cif *cif, 273 | void (*fn)(void), 274 | void *rvalue, 275 | ffi_java_raw *avalue); 276 | 277 | void ffi_java_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_java_raw *raw); 278 | void ffi_java_raw_to_ptrarray (ffi_cif *cif, ffi_java_raw *raw, void **args); 279 | size_t ffi_java_raw_size (ffi_cif *cif); 280 | 281 | /* ---- Definitions for closures ----------------------------------------- */ 282 | 283 | #if FFI_CLOSURES 284 | 285 | #ifdef _MSC_VER 286 | __declspec(align(8)) 287 | #endif 288 | typedef struct { 289 | #if 1 290 | void *trampoline_table; 291 | void *trampoline_table_entry; 292 | #else 293 | char tramp[FFI_TRAMPOLINE_SIZE]; 294 | #endif 295 | ffi_cif *cif; 296 | void (*fun)(ffi_cif*,void*,void**,void*); 297 | void *user_data; 298 | } ffi_closure 299 | #ifdef __GNUC__ 300 | __attribute__((aligned (8))) 301 | #endif 302 | ; 303 | 304 | #ifndef __GNUC__ 305 | # ifdef __sgi 306 | # pragma pack 0 307 | # endif 308 | #endif 309 | 310 | void *ffi_closure_alloc (size_t size, void **code); 311 | void ffi_closure_free (void *); 312 | 313 | ffi_status 314 | ffi_prep_closure (ffi_closure*, 315 | ffi_cif *, 316 | void (*fun)(ffi_cif*,void*,void**,void*), 317 | void *user_data) 318 | __attribute__((deprecated ("use ffi_prep_closure_loc instead"))); 319 | 320 | ffi_status 321 | ffi_prep_closure_loc (ffi_closure*, 322 | ffi_cif *, 323 | void (*fun)(ffi_cif*,void*,void**,void*), 324 | void *user_data, 325 | void*codeloc); 326 | 327 | #ifdef __sgi 328 | # pragma pack 8 329 | #endif 330 | typedef struct { 331 | #if 1 332 | void *trampoline_table; 333 | void *trampoline_table_entry; 334 | #else 335 | char tramp[FFI_TRAMPOLINE_SIZE]; 336 | #endif 337 | ffi_cif *cif; 338 | 339 | #if !FFI_NATIVE_RAW_API 340 | 341 | /* If this is enabled, then a raw closure has the same layout 342 | as a regular closure. We use this to install an intermediate 343 | handler to do the transaltion, void** -> ffi_raw*. */ 344 | 345 | void (*translate_args)(ffi_cif*,void*,void**,void*); 346 | void *this_closure; 347 | 348 | #endif 349 | 350 | void (*fun)(ffi_cif*,void*,ffi_raw*,void*); 351 | void *user_data; 352 | 353 | } ffi_raw_closure; 354 | 355 | typedef struct { 356 | #if 1 357 | void *trampoline_table; 358 | void *trampoline_table_entry; 359 | #else 360 | char tramp[FFI_TRAMPOLINE_SIZE]; 361 | #endif 362 | 363 | ffi_cif *cif; 364 | 365 | #if !FFI_NATIVE_RAW_API 366 | 367 | /* If this is enabled, then a raw closure has the same layout 368 | as a regular closure. We use this to install an intermediate 369 | handler to do the translation, void** -> ffi_raw*. */ 370 | 371 | void (*translate_args)(ffi_cif*,void*,void**,void*); 372 | void *this_closure; 373 | 374 | #endif 375 | 376 | void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*); 377 | void *user_data; 378 | 379 | } ffi_java_raw_closure; 380 | 381 | ffi_status 382 | ffi_prep_raw_closure (ffi_raw_closure*, 383 | ffi_cif *cif, 384 | void (*fun)(ffi_cif*,void*,ffi_raw*,void*), 385 | void *user_data); 386 | 387 | ffi_status 388 | ffi_prep_raw_closure_loc (ffi_raw_closure*, 389 | ffi_cif *cif, 390 | void (*fun)(ffi_cif*,void*,ffi_raw*,void*), 391 | void *user_data, 392 | void *codeloc); 393 | 394 | ffi_status 395 | ffi_prep_java_raw_closure (ffi_java_raw_closure*, 396 | ffi_cif *cif, 397 | void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*), 398 | void *user_data); 399 | 400 | ffi_status 401 | ffi_prep_java_raw_closure_loc (ffi_java_raw_closure*, 402 | ffi_cif *cif, 403 | void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*), 404 | void *user_data, 405 | void *codeloc); 406 | 407 | #endif /* FFI_CLOSURES */ 408 | 409 | #if FFI_GO_CLOSURES 410 | 411 | typedef struct { 412 | void *tramp; 413 | ffi_cif *cif; 414 | void (*fun)(ffi_cif*,void*,void**,void*); 415 | } ffi_go_closure; 416 | 417 | ffi_status ffi_prep_go_closure (ffi_go_closure*, ffi_cif *, 418 | void (*fun)(ffi_cif*,void*,void**,void*)); 419 | 420 | void ffi_call_go (ffi_cif *cif, void (*fn)(void), void *rvalue, 421 | void **avalue, void *closure); 422 | 423 | #endif /* FFI_GO_CLOSURES */ 424 | 425 | /* ---- Public interface definition -------------------------------------- */ 426 | 427 | ffi_status ffi_prep_cif(ffi_cif *cif, 428 | ffi_abi abi, 429 | unsigned int nargs, 430 | ffi_type *rtype, 431 | ffi_type **atypes); 432 | 433 | ffi_status ffi_prep_cif_var(ffi_cif *cif, 434 | ffi_abi abi, 435 | unsigned int nfixedargs, 436 | unsigned int ntotalargs, 437 | ffi_type *rtype, 438 | ffi_type **atypes); 439 | 440 | void ffi_call(ffi_cif *cif, 441 | void (*fn)(void), 442 | void *rvalue, 443 | void **avalue); 444 | 445 | ffi_status ffi_get_struct_offsets (ffi_abi abi, ffi_type *struct_type, 446 | size_t *offsets); 447 | 448 | /* Useful for eliminating compiler warnings. */ 449 | #define FFI_FN(f) ((void (*)(void))f) 450 | 451 | /* ---- Definitions shared with assembly code ---------------------------- */ 452 | 453 | #endif 454 | 455 | /* If these change, update src/mips/ffitarget.h. */ 456 | #define FFI_TYPE_VOID 0 457 | #define FFI_TYPE_INT 1 458 | #define FFI_TYPE_FLOAT 2 459 | #define FFI_TYPE_DOUBLE 3 460 | #if 0 461 | #define FFI_TYPE_LONGDOUBLE 4 462 | #else 463 | #define FFI_TYPE_LONGDOUBLE FFI_TYPE_DOUBLE 464 | #endif 465 | #define FFI_TYPE_UINT8 5 466 | #define FFI_TYPE_SINT8 6 467 | #define FFI_TYPE_UINT16 7 468 | #define FFI_TYPE_SINT16 8 469 | #define FFI_TYPE_UINT32 9 470 | #define FFI_TYPE_SINT32 10 471 | #define FFI_TYPE_UINT64 11 472 | #define FFI_TYPE_SINT64 12 473 | #define FFI_TYPE_STRUCT 13 474 | #define FFI_TYPE_POINTER 14 475 | #define FFI_TYPE_COMPLEX 15 476 | 477 | /* This should always refer to the last type code (for sanity checks). */ 478 | #define FFI_TYPE_LAST FFI_TYPE_COMPLEX 479 | 480 | #ifdef __cplusplus 481 | } 482 | #endif 483 | 484 | #endif 485 | -------------------------------------------------------------------------------- /Source/Core/FFI/Vendor/ffi_i386.h: -------------------------------------------------------------------------------- 1 | #ifdef __i386__ 2 | 3 | /* -----------------------------------------------------------------*-C-*- 4 | libffi 3.2.1 - Copyright (c) 2011, 2014 Anthony Green 5 | - Copyright (c) 1996-2003, 2007, 2008 Red Hat, Inc. 6 | 7 | Permission is hereby granted, free of charge, to any person 8 | obtaining a copy of this software and associated documentation 9 | files (the ``Software''), to deal in the Software without 10 | restriction, including without limitation the rights to use, copy, 11 | modify, merge, publish, distribute, sublicense, and/or sell copies 12 | of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be 16 | included in all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, 19 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 22 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | DEALINGS IN THE SOFTWARE. 26 | 27 | ----------------------------------------------------------------------- */ 28 | 29 | /* ------------------------------------------------------------------- 30 | The basic API is described in the README file. 31 | 32 | The raw API is designed to bypass some of the argument packing 33 | and unpacking on architectures for which it can be avoided. 34 | 35 | The closure API allows interpreted functions to be packaged up 36 | inside a C function pointer, so that they can be called as C functions, 37 | with no understanding on the client side that they are interpreted. 38 | It can also be used in other cases in which it is necessary to package 39 | up a user specified parameter and a function pointer as a single 40 | function pointer. 41 | 42 | The closure API must be implemented in order to get its functionality, 43 | e.g. for use by gij. Routines are provided to emulate the raw API 44 | if the underlying platform doesn't allow faster implementation. 45 | 46 | More details on the raw and cloure API can be found in: 47 | 48 | http://gcc.gnu.org/ml/java/1999-q3/msg00138.html 49 | 50 | and 51 | 52 | http://gcc.gnu.org/ml/java/1999-q3/msg00174.html 53 | -------------------------------------------------------------------- */ 54 | 55 | #ifndef LIBFFI_H 56 | #define LIBFFI_H 57 | 58 | #ifdef __cplusplus 59 | extern "C" { 60 | #endif 61 | 62 | /* Specify which architecture libffi is configured for. */ 63 | #ifndef X86_DARWIN 64 | #define X86_DARWIN 65 | #endif 66 | 67 | /* ---- System configuration information --------------------------------- */ 68 | 69 | #include 70 | 71 | #ifndef LIBFFI_ASM 72 | 73 | #if defined(_MSC_VER) && !defined(__clang__) 74 | #define __attribute__(X) 75 | #endif 76 | 77 | #include 78 | #include 79 | 80 | /* LONG_LONG_MAX is not always defined (not if STRICT_ANSI, for example). 81 | But we can find it either under the correct ANSI name, or under GNU 82 | C's internal name. */ 83 | 84 | #define FFI_64_BIT_MAX 9223372036854775807 85 | 86 | #ifdef LONG_LONG_MAX 87 | # define FFI_LONG_LONG_MAX LONG_LONG_MAX 88 | #else 89 | # ifdef LLONG_MAX 90 | # define FFI_LONG_LONG_MAX LLONG_MAX 91 | # ifdef _AIX52 /* or newer has C99 LLONG_MAX */ 92 | # undef FFI_64_BIT_MAX 93 | # define FFI_64_BIT_MAX 9223372036854775807LL 94 | # endif /* _AIX52 or newer */ 95 | # else 96 | # ifdef __GNUC__ 97 | # define FFI_LONG_LONG_MAX __LONG_LONG_MAX__ 98 | # endif 99 | # ifdef _AIX /* AIX 5.1 and earlier have LONGLONG_MAX */ 100 | # ifndef __PPC64__ 101 | # if defined (__IBMC__) || defined (__IBMCPP__) 102 | # define FFI_LONG_LONG_MAX LONGLONG_MAX 103 | # endif 104 | # endif /* __PPC64__ */ 105 | # undef FFI_64_BIT_MAX 106 | # define FFI_64_BIT_MAX 9223372036854775807LL 107 | # endif 108 | # endif 109 | #endif 110 | 111 | /* The closure code assumes that this works on pointers, i.e. a size_t */ 112 | /* can hold a pointer. */ 113 | 114 | typedef struct _ffi_type 115 | { 116 | size_t size; 117 | unsigned short alignment; 118 | unsigned short type; 119 | struct _ffi_type **elements; 120 | } ffi_type; 121 | 122 | #ifndef LIBFFI_HIDE_BASIC_TYPES 123 | #if SCHAR_MAX == 127 124 | # define ffi_type_uchar ffi_type_uint8 125 | # define ffi_type_schar ffi_type_sint8 126 | #else 127 | #error "char size not supported" 128 | #endif 129 | 130 | #if SHRT_MAX == 32767 131 | # define ffi_type_ushort ffi_type_uint16 132 | # define ffi_type_sshort ffi_type_sint16 133 | #elif SHRT_MAX == 2147483647 134 | # define ffi_type_ushort ffi_type_uint32 135 | # define ffi_type_sshort ffi_type_sint32 136 | #else 137 | #error "short size not supported" 138 | #endif 139 | 140 | #if INT_MAX == 32767 141 | # define ffi_type_uint ffi_type_uint16 142 | # define ffi_type_sint ffi_type_sint16 143 | #elif INT_MAX == 2147483647 144 | # define ffi_type_uint ffi_type_uint32 145 | # define ffi_type_sint ffi_type_sint32 146 | #elif INT_MAX == 9223372036854775807 147 | # define ffi_type_uint ffi_type_uint64 148 | # define ffi_type_sint ffi_type_sint64 149 | #else 150 | #error "int size not supported" 151 | #endif 152 | 153 | #if LONG_MAX == 2147483647 154 | # if FFI_LONG_LONG_MAX != FFI_64_BIT_MAX 155 | #error "no 64-bit data type supported" 156 | # endif 157 | #elif LONG_MAX != FFI_64_BIT_MAX 158 | #error "long size not supported" 159 | #endif 160 | 161 | #if LONG_MAX == 2147483647 162 | # define ffi_type_ulong ffi_type_uint32 163 | # define ffi_type_slong ffi_type_sint32 164 | #elif LONG_MAX == FFI_64_BIT_MAX 165 | # define ffi_type_ulong ffi_type_uint64 166 | # define ffi_type_slong ffi_type_sint64 167 | #else 168 | #error "long size not supported" 169 | #endif 170 | 171 | /* Need minimal decorations for DLLs to works on Windows. */ 172 | /* GCC has autoimport and autoexport. Rely on Libtool to */ 173 | /* help MSVC export from a DLL, but always declare data */ 174 | /* to be imported for MSVC clients. This costs an extra */ 175 | /* indirection for MSVC clients using the static version */ 176 | /* of the library, but don't worry about that. Besides, */ 177 | /* as a workaround, they can define FFI_BUILDING if they */ 178 | /* *know* they are going to link with the static library. */ 179 | #if defined _MSC_VER && !defined FFI_BUILDING 180 | #define FFI_EXTERN extern __declspec(dllimport) 181 | #else 182 | #define FFI_EXTERN extern 183 | #endif 184 | 185 | /* These are defined in types.c */ 186 | FFI_EXTERN ffi_type ffi_type_void; 187 | FFI_EXTERN ffi_type ffi_type_uint8; 188 | FFI_EXTERN ffi_type ffi_type_sint8; 189 | FFI_EXTERN ffi_type ffi_type_uint16; 190 | FFI_EXTERN ffi_type ffi_type_sint16; 191 | FFI_EXTERN ffi_type ffi_type_uint32; 192 | FFI_EXTERN ffi_type ffi_type_sint32; 193 | FFI_EXTERN ffi_type ffi_type_uint64; 194 | FFI_EXTERN ffi_type ffi_type_sint64; 195 | FFI_EXTERN ffi_type ffi_type_float; 196 | FFI_EXTERN ffi_type ffi_type_double; 197 | FFI_EXTERN ffi_type ffi_type_pointer; 198 | 199 | #if 1 200 | FFI_EXTERN ffi_type ffi_type_longdouble; 201 | #else 202 | #define ffi_type_longdouble ffi_type_double 203 | #endif 204 | 205 | #ifdef FFI_TARGET_HAS_COMPLEX_TYPE 206 | FFI_EXTERN ffi_type ffi_type_complex_float; 207 | FFI_EXTERN ffi_type ffi_type_complex_double; 208 | #if 1 209 | FFI_EXTERN ffi_type ffi_type_complex_longdouble; 210 | #else 211 | #define ffi_type_complex_longdouble ffi_type_complex_double 212 | #endif 213 | #endif 214 | #endif /* LIBFFI_HIDE_BASIC_TYPES */ 215 | 216 | typedef enum { 217 | FFI_OK = 0, 218 | FFI_BAD_TYPEDEF, 219 | FFI_BAD_ABI 220 | } ffi_status; 221 | 222 | typedef unsigned FFI_TYPE; 223 | 224 | typedef struct { 225 | ffi_abi abi; 226 | unsigned nargs; 227 | ffi_type **arg_types; 228 | ffi_type *rtype; 229 | unsigned bytes; 230 | unsigned flags; 231 | #ifdef FFI_EXTRA_CIF_FIELDS 232 | FFI_EXTRA_CIF_FIELDS; 233 | #endif 234 | } ffi_cif; 235 | 236 | #if 0 237 | /* Used to adjust size/alignment of ffi types. */ 238 | void ffi_prep_types (ffi_abi abi); 239 | #endif 240 | 241 | /* Used internally, but overridden by some architectures */ 242 | ffi_status ffi_prep_cif_core(ffi_cif *cif, 243 | ffi_abi abi, 244 | unsigned int isvariadic, 245 | unsigned int nfixedargs, 246 | unsigned int ntotalargs, 247 | ffi_type *rtype, 248 | ffi_type **atypes); 249 | 250 | /* ---- Definitions for the raw API -------------------------------------- */ 251 | 252 | #ifndef FFI_SIZEOF_ARG 253 | # if LONG_MAX == 2147483647 254 | # define FFI_SIZEOF_ARG 4 255 | # elif LONG_MAX == FFI_64_BIT_MAX 256 | # define FFI_SIZEOF_ARG 8 257 | # endif 258 | #endif 259 | 260 | #ifndef FFI_SIZEOF_JAVA_RAW 261 | # define FFI_SIZEOF_JAVA_RAW FFI_SIZEOF_ARG 262 | #endif 263 | 264 | typedef union { 265 | ffi_sarg sint; 266 | ffi_arg uint; 267 | float flt; 268 | char data[FFI_SIZEOF_ARG]; 269 | void* ptr; 270 | } ffi_raw; 271 | 272 | #if FFI_SIZEOF_JAVA_RAW == 4 && FFI_SIZEOF_ARG == 8 273 | /* This is a special case for mips64/n32 ABI (and perhaps others) where 274 | sizeof(void *) is 4 and FFI_SIZEOF_ARG is 8. */ 275 | typedef union { 276 | signed int sint; 277 | unsigned int uint; 278 | float flt; 279 | char data[FFI_SIZEOF_JAVA_RAW]; 280 | void* ptr; 281 | } ffi_java_raw; 282 | #else 283 | typedef ffi_raw ffi_java_raw; 284 | #endif 285 | 286 | 287 | void ffi_raw_call (ffi_cif *cif, 288 | void (*fn)(void), 289 | void *rvalue, 290 | ffi_raw *avalue); 291 | 292 | void ffi_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_raw *raw); 293 | void ffi_raw_to_ptrarray (ffi_cif *cif, ffi_raw *raw, void **args); 294 | size_t ffi_raw_size (ffi_cif *cif); 295 | 296 | /* This is analogous to the raw API, except it uses Java parameter */ 297 | /* packing, even on 64-bit machines. I.e. on 64-bit machines */ 298 | /* longs and doubles are followed by an empty 64-bit word. */ 299 | 300 | void ffi_java_raw_call (ffi_cif *cif, 301 | void (*fn)(void), 302 | void *rvalue, 303 | ffi_java_raw *avalue); 304 | 305 | void ffi_java_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_java_raw *raw); 306 | void ffi_java_raw_to_ptrarray (ffi_cif *cif, ffi_java_raw *raw, void **args); 307 | size_t ffi_java_raw_size (ffi_cif *cif); 308 | 309 | /* ---- Definitions for closures ----------------------------------------- */ 310 | 311 | #if FFI_CLOSURES 312 | 313 | #ifdef _MSC_VER 314 | __declspec(align(8)) 315 | #endif 316 | typedef struct { 317 | #if 0 318 | void *trampoline_table; 319 | void *trampoline_table_entry; 320 | #else 321 | char tramp[FFI_TRAMPOLINE_SIZE]; 322 | #endif 323 | ffi_cif *cif; 324 | void (*fun)(ffi_cif*,void*,void**,void*); 325 | void *user_data; 326 | #ifdef __GNUC__ 327 | } ffi_closure __attribute__((aligned (8))); 328 | #else 329 | } ffi_closure; 330 | # ifdef __sgi 331 | # pragma pack 0 332 | # endif 333 | #endif 334 | 335 | void *ffi_closure_alloc (size_t size, void **code); 336 | void ffi_closure_free (void *); 337 | 338 | ffi_status 339 | ffi_prep_closure (ffi_closure*, 340 | ffi_cif *, 341 | void (*fun)(ffi_cif*,void*,void**,void*), 342 | void *user_data); 343 | 344 | ffi_status 345 | ffi_prep_closure_loc (ffi_closure*, 346 | ffi_cif *, 347 | void (*fun)(ffi_cif*,void*,void**,void*), 348 | void *user_data, 349 | void*codeloc); 350 | 351 | #ifdef __sgi 352 | # pragma pack 8 353 | #endif 354 | typedef struct { 355 | #if 0 356 | void *trampoline_table; 357 | void *trampoline_table_entry; 358 | #else 359 | char tramp[FFI_TRAMPOLINE_SIZE]; 360 | #endif 361 | ffi_cif *cif; 362 | 363 | #if !FFI_NATIVE_RAW_API 364 | 365 | /* if this is enabled, then a raw closure has the same layout 366 | as a regular closure. We use this to install an intermediate 367 | handler to do the transaltion, void** -> ffi_raw*. */ 368 | 369 | void (*translate_args)(ffi_cif*,void*,void**,void*); 370 | void *this_closure; 371 | 372 | #endif 373 | 374 | void (*fun)(ffi_cif*,void*,ffi_raw*,void*); 375 | void *user_data; 376 | 377 | } ffi_raw_closure; 378 | 379 | typedef struct { 380 | #if 0 381 | void *trampoline_table; 382 | void *trampoline_table_entry; 383 | #else 384 | char tramp[FFI_TRAMPOLINE_SIZE]; 385 | #endif 386 | 387 | ffi_cif *cif; 388 | 389 | #if !FFI_NATIVE_RAW_API 390 | 391 | /* if this is enabled, then a raw closure has the same layout 392 | as a regular closure. We use this to install an intermediate 393 | handler to do the transaltion, void** -> ffi_raw*. */ 394 | 395 | void (*translate_args)(ffi_cif*,void*,void**,void*); 396 | void *this_closure; 397 | 398 | #endif 399 | 400 | void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*); 401 | void *user_data; 402 | 403 | } ffi_java_raw_closure; 404 | 405 | ffi_status 406 | ffi_prep_raw_closure (ffi_raw_closure*, 407 | ffi_cif *cif, 408 | void (*fun)(ffi_cif*,void*,ffi_raw*,void*), 409 | void *user_data); 410 | 411 | ffi_status 412 | ffi_prep_raw_closure_loc (ffi_raw_closure*, 413 | ffi_cif *cif, 414 | void (*fun)(ffi_cif*,void*,ffi_raw*,void*), 415 | void *user_data, 416 | void *codeloc); 417 | 418 | ffi_status 419 | ffi_prep_java_raw_closure (ffi_java_raw_closure*, 420 | ffi_cif *cif, 421 | void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*), 422 | void *user_data); 423 | 424 | ffi_status 425 | ffi_prep_java_raw_closure_loc (ffi_java_raw_closure*, 426 | ffi_cif *cif, 427 | void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*), 428 | void *user_data, 429 | void *codeloc); 430 | 431 | #endif /* FFI_CLOSURES */ 432 | 433 | /* ---- Public interface definition -------------------------------------- */ 434 | 435 | ffi_status ffi_prep_cif(ffi_cif *cif, 436 | ffi_abi abi, 437 | unsigned int nargs, 438 | ffi_type *rtype, 439 | ffi_type **atypes); 440 | 441 | ffi_status ffi_prep_cif_var(ffi_cif *cif, 442 | ffi_abi abi, 443 | unsigned int nfixedargs, 444 | unsigned int ntotalargs, 445 | ffi_type *rtype, 446 | ffi_type **atypes); 447 | 448 | void ffi_call(ffi_cif *cif, 449 | void (*fn)(void), 450 | void *rvalue, 451 | void **avalue); 452 | 453 | /* Useful for eliminating compiler warnings */ 454 | #define FFI_FN(f) ((void (*)(void))f) 455 | 456 | /* ---- Definitions shared with assembly code ---------------------------- */ 457 | 458 | #endif 459 | 460 | /* If these change, update src/mips/ffitarget.h. */ 461 | #define FFI_TYPE_VOID 0 462 | #define FFI_TYPE_INT 1 463 | #define FFI_TYPE_FLOAT 2 464 | #define FFI_TYPE_DOUBLE 3 465 | #if 1 466 | #define FFI_TYPE_LONGDOUBLE 4 467 | #else 468 | #define FFI_TYPE_LONGDOUBLE FFI_TYPE_DOUBLE 469 | #endif 470 | #define FFI_TYPE_UINT8 5 471 | #define FFI_TYPE_SINT8 6 472 | #define FFI_TYPE_UINT16 7 473 | #define FFI_TYPE_SINT16 8 474 | #define FFI_TYPE_UINT32 9 475 | #define FFI_TYPE_SINT32 10 476 | #define FFI_TYPE_UINT64 11 477 | #define FFI_TYPE_SINT64 12 478 | #define FFI_TYPE_STRUCT 13 479 | #define FFI_TYPE_POINTER 14 480 | #define FFI_TYPE_COMPLEX 15 481 | 482 | /* This should always refer to the last type code (for sanity checks) */ 483 | #define FFI_TYPE_LAST FFI_TYPE_COMPLEX 484 | 485 | #ifdef __cplusplus 486 | } 487 | #endif 488 | 489 | #endif 490 | 491 | 492 | #endif --------------------------------------------------------------------------------