/
JPEngine.h
107 lines (84 loc) · 2.73 KB
/
JPEngine.h
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//
// JPEngine.h
// JSPatch
//
// Created by bang on 15/4/30.
// Copyright (c) 2015 bang. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <JavaScriptCore/JavaScriptCore.h>
@interface JPEngine : NSObject
/*!
@method
@discussion start the JSPatch engine, execute only once.
!Deprecated! will be call automatically before evaluate script
*/
+ (void)startEngine;
/*!
@method
@description Evaluate Javascript code from a file Path. Call it after +startEngine.
@param filePath: The filePath of the Javascript code.
@result The last value generated by the script.
*/
+ (JSValue *)evaluateScriptWithPath:(NSString *)filePath;
/*!
@method
@description Evaluate a string of JavaScript code. Call it after +startEngine.
The method will generate a default resouceURL named "main.js" to the Safari debugger.
@param script: A string containing the JavaScript code to evaluate.
@result The last value generated by the script.
*/
+ (JSValue *)evaluateScript:(NSString *)script;
/*!
@method
@description Return the JSPatch JavaScript execution environment.
*/
+ (JSContext *)context;
/*!
@method
@description Add JPExtension.
@param extensions: An array containing class name string.
*/
+ (void)addExtensions:(NSArray *)extensions;
/*!
@method
@description add new struct type supporting to JS
@param defineDict: the definition of struct, for Example:
@{
@"name": @"CGAffineTransform", //struct name
@"types": @"ffffff", //struct types
@"keys": @[@"a", @"b", @"c", @"d", @"tx", @"ty"] //struct keys in JS
}
*/
+ (void)defineStruct:(NSDictionary *)defineDict;
+ (void)handleException:(void (^)(NSString *msg))exceptionBlock;
@end
@interface JPExtension : NSObject
+ (void)main:(JSContext *)context;
+ (void *)formatPointerJSToOC:(JSValue *)val;
+ (id)formatRetainedCFTypeOCToJS:(CFTypeRef)CF_CONSUMED type;
+ (id)formatPointerOCToJS:(void *)pointer;
+ (id)formatJSToOC:(JSValue *)val;
+ (id)formatOCToJS:(id)obj;
+ (int)sizeOfStructTypes:(NSString *)structTypes;
+ (void)getStructDataWidthDict:(void *)structData dict:(NSDictionary *)dict structDefine:(NSDictionary *)structDefine;
+ (NSDictionary *)getDictOfStruct:(void *)structData structDefine:(NSDictionary *)structDefine;
/*!
@method
@description Return the registered struct definition in JSPatch,
the key of dictionary is the struct name.
*/
+ (NSMutableDictionary *)registeredStruct;
+ (NSDictionary *)overideMethods;
+ (NSMutableSet *)includedScriptPaths;
@end
@interface JPBoxing : NSObject
@property (nonatomic) id obj;
@property (nonatomic) void *pointer;
@property (nonatomic) Class cls;
@property (nonatomic, weak) id weakObj;
@property (nonatomic, assign) id assignObj;
- (id)unbox;
- (void *)unboxPointer;
- (Class)unboxClass;
@end