forked from parmanoir/jscocoa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path38 class walker.js
150 lines (102 loc) · 3.72 KB
/
38 class walker.js
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
//
// Exploring the runtime !
//
//log('class walker 1')
//
// Class list
//
// All classes defined in the runtime. Right now this returns class names, not classes themselves
// log('rootClasses=' + JSCocoa.rootclasses)
// All root classes (NSObject, NSProxy)
// log('classes=' + JSCocoa.classes)
//
// Derivation information
//
// Returns an array containing all superclasses and this class : NSObject, NSResponder, NSView, NSControl, NSButton
// log('NSButton derivation path=' + NSButton.__derivationPath)
// Returns the size of derivation path -1 (Root classes have level 0)
// log('NSButton derivation level=' + NSButton.__derivationLevel)
//
// Which frameworks defines the class ?
//
// Path to framework defining the class
// log('framework defining NSView=' + NSView.__classImage)
//
// Methods
//
// Own methods : returns an array containing the methods defined by this class level
// name
// encoding
// type (instance|class)
// class
// framework (path to lib defining the method implementation)
// log('NSView.ownMethods=' + NSView.__ownMethods)
// Methods : returns an array containing all methods defined in this class
// log('NSView.methods=' + NSView.__methods)
// log('CALayer.methods=' + CALayer.__methods)
// log('CALayer.subclassTree=\n' + CALayer.__subclassTree)
// log('NSBlock.subclassTree=\n' + NSBlock.__subclassTree)
// log('NSBlock.ownMethods=' + NSBlock.__ownMethods)
// log('__NSGlobalBlock__.ownMethods=' + __NSGlobalBlock__.__ownMethods)
// log('NSMutableArray.ownMethods=' + NSMutableArray.__ownMethods)
// All methods from all classes
// var m = JSCocoa.methods
// log('all methods=' + m)
//var i = 0;
// Too slow !
// May be a split call problem. Activity Monitor sampling shows isMaybeSplitCall, trySplitCall
// log('all instance methods starting with set=' + m.filter(function (method) { i++; if (i%100==0) log(i + '/' + m.length); return method.type == 'instance' && method.name.match(/^set/) }))
//
// Subclasses
//
// log('NSView.subclasses=' + NSView.__subclasses)
// Display subclasses as a tree
// log('NSView.subclassTree=\n' + NSView.__subclassTree)
// log('NSButton.subclassTree=\n' + NSButton.__subclassTree)
// log('NSObject.subclassTree=\n' + NSObject.__subclassTree)
// log(NSString.__subclasses)
//
// ivars
// Just like methods, use
// ivars to get ALL ivars in the class, including ivars from all superclasses
// ownIvars to get ivars from this class only
//
// log('NSView.ivars=' + NSView.__ivars)
// log('NSResponder.ivars=' + NSResponder.__ivars)
//
// Properties
//
// log('CALayer.properties=' + CALayer.__properties)
// log('CATextLayer.properties=' + CATextLayer.__properties)
//
// Protocols
//
// log('protocols=' + JSCocoa.protocols)
// log('NSObject.protocols=' + NSObject.__protocols);
// log('NSView.protocols=' + NSView.__protocols);
//
// Image names (loaded frameworks)
// returns { name : imageName, classNames : [className, className, ...] }
//
// log('image names=' + JSCocoa.imageNames)
//
// Runtime description
//
// log('runtime description=' + JSCocoa.runtimeReport)
// Find all array methods starting with 'init'
// log(NSArray.__methods.filter(function (method) { return method.name.match(/^init/) }))
// Only method names
// log(NSArray.__methods.filter(function (method) { return method.name.match(/^init/) }).map(function(o){return o.name}))
// log(NSObject.__methods.filter(function (method) { return method.framework.match(/AppKit/) } ))
//log('class walker 2')
//
// Method encoding explainer
//
/*
var methods = NSView.__ownMethods
for (var i=0; i<methods.length; i++)
{
var method = methods[i]
log(method.name + ' explained=' + JSCocoa.explainMethodEncoding(method.encoding))
}
*/