-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
256 lines (199 loc) · 9.25 KB
/
Copy pathindex.js
File metadata and controls
256 lines (199 loc) · 9.25 KB
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
Ext.Loader.setConfig({ enabled : false });
App = {
/**
* @cfg url1 Set the url to first Ext JS version
*/
url1 : 'http://lh/ext-5.0.0.736/build/ext-all-debug.js',
/**
* @cfg url2 Set the url to second Ext JS version
*/
url2 : 'http://lh/extjs-4.2.2/ext-all-debug.js',
frame1 : null,
frame2 : null,
ExtNew : null,
ExtOld : null,
// Skip some static stuff we don't care about
staticIgnoreRe : (function () {
var keys = Object.keys(Ext.Base).map(function (k) {
return Ext.String.escapeRegex(k)
});
return new RegExp(keys.concat(['alternateClassName', 'superclass', 'hasListeners', 'HasListeners']).join('|'));
})(),
// Skip some prototype stuff we don't care about
ignoreRe : (function () {
var keys = Object.keys(Ext.Base.prototype).map(function (k) {
return Ext.String.escapeRegex(k)
});
return new RegExp(keys.concat(['id', 'alternateClassName', 'superclass']).join('|'));
})(),
init : function () {
var me = this;
this.frame1 = Ext.core.DomHelper.append(Ext.getBody(), {
tag : "iframe",
style : 'display:none'
}, false);
this.frame2 = Ext.core.DomHelper.append(Ext.getBody(), {
tag : "iframe",
style : 'display:none'
}, false);
var win1 = this.frame1.contentWindow;
win1.document.open();
win1.document.write(
'<html><head><script type="text/javascript" src="' + this.url1 + '"></script></head><body></body></html>'
);
win1.document.close();
var win2 = this.frame2.contentWindow;
win2.document.open();
win2.document.write(
'<html><head><script type="text/javascript" src="' + this.url2 + '"></script></head><body></body></html>'
);
win2.document.close();
var int = setInterval(function () {
if (win1.Ext && win2.Ext) {
win1.onerror = win2.Ext.Loader.loadScript = function() { return true };
win2.onerror = win1.Ext.Loader.loadScript = function() { return true };
Ext.fly('version1').update(win1.Ext.versions.extjs.toString());
Ext.fly('version2').update(win2.Ext.versions.extjs.toString());
clearInterval(int);
me.scan(me.visualize);
}
}, 200)
},
visualize : function(data) {
var versionString = this.ExtNew.versions.extjs.toString();
var newTpl = new Ext.XTemplate('<div class="addedClasses"><tpl for="."><div>{.}</div></tpl>')
var removedTpl = new Ext.XTemplate('<div class="removedClasses"><tpl for="."><div>{.}</div></tpl>')
var changedStaticTpl = new Ext.XTemplate('<ul class="changedStaticProperties"><tpl foreach="."><li class="clsName">{$}<ul><tpl for="."><li class="{type}"><span class="type">[{type}]</span> {prop} {[values.old ? "(old: " + values.old + ", new: " + values.new + ")" : ""]}</li></tpl></ul></li></tpl></table>')
var changedPrototypeTpl = new Ext.XTemplate('<ul class="changedPrototypeProperties"><tpl foreach="."><li class="clsName">{$}<ul><tpl for="."><li class="{type}"><span class="type">[{type}]</span> {prop} {[values.old ? "(old: " + values.old + ", new: " + values.new + ")": ""]}</li></tpl></ul></li></tpl></table>')
newTpl.append("one", data.added.sort());
removedTpl.append("two", data.removed.sort());
changedStaticTpl.append("three", data.staticChanged);
changedPrototypeTpl.append("four", data.prototypeChanged);
},
// Try to get a readable type
getType : function (obj) {
if (obj === null) return 'null';
if (obj && obj.$className) return obj.$className;
if (Ext.isArray(obj)) return 'Array';
if (Ext.isDate(obj)) return 'Date';
return typeof obj;
},
getObjectDiff : function (newObj, oldObj, clsName, static) {
var diff = []
for (var p in oldObj) {
if ((static ? this.staticIgnoreRe : this.ignoreRe).test(p)) continue;
try {
if ((oldObj.hasOwnProperty(p)) || (!isNaN(Number(oldObj.$className)) && oldObj.superclass.hasOwnProperty(p))) {
// Check if the object exists on the clean window and also do a string comparison
// in case a builtin method has been overridden
if (!newObj.hasOwnProperty(p) && typeof newObj[p] == 'undefined') {
diff.push({
prop : p,
type : 'removed',
static : static
});
}
// Check for property type change
else if (this.getType(oldObj[p]) !== this.getType(newObj[p])) {
diff.push({
prop : p,
type : 'type_changed',
old : this.getType(oldObj[p]),
new : this.getType(newObj[p]),
static : static
});
}
// Check for property value change
else if (Ext.isPrimitive(oldObj[p]) && oldObj[p].toString() !== newObj[p].toString()) {
diff.push({
prop : p,
type : 'value_changed',
old : oldObj[p].toString(),
new : newObj[p].toString(),
static : static
});
}
}
} catch (e) {
// Just continue
}
}
return diff.sort(function(a, b) { return a.prop < b.prop ? -1 : 1; });
},
scan : function (callback) {
var me = this;
var ExtNew = this.frame1.contentWindow.Ext;
var ExtOld = this.frame2.contentWindow.Ext;
var staticChanged = {};
var protChanged = {};
var removed = [];
var added = [];
var i = 1;
var processed = {};
ExtNew = ExtNew.versions.extjs.isGreaterThan(ExtOld.versions.extjs.version) ? ExtNew : ExtOld;
this.ExtOld = ExtOld;
this.ExtNew = ExtNew;
var newClasses = Object.keys(ExtNew.ClassManager.classes);
var oldClasses = Object.keys(ExtOld.ClassManager.classes);
oldClasses.forEach(function (cls) {
if (processed[cls]) return;
var clsNew = ExtNew.ClassManager.get(cls);
var clsOld = ExtOld.ClassManager.get(cls);
if (!clsNew) {
removed.push(cls);
} else {
var diff = me.getObjectDiff(clsNew, clsOld, clsOld.$className, true);
if (diff.length > 0) {
staticChanged[clsOld.$className] = diff;
}
var singletonChanged = (clsOld.singleton !== clsNew.singleton);
if (singletonChanged) {
staticChanged[clsOld.$className] = {
prop : 'singleton',
type : 'singleton_changed',
old : String(!!clsOld.singleton),
new : String(!!clsNew.singleton),
static : true
};
}
// Prototype properties
else if (clsOld.prototype) {
// Make subclasses to provoke additional properties being created in onClassExtended (Ext.data.Model etc)
var oldSubClass = ExtOld.define(i.toString(), { extend : clsOld.$className });
var newSubClass = ExtNew.define(i.toString(), { extend : clsOld.$className });
var oldIns, newIns;
// If we're lucky, we can instantiate the class too without args, and find more properties added in the constructor
try
{
oldIns = new oldSubClass();
newIns = new newSubClass();
} catch(e) {
oldIns = newIns = null;
}
diff = me.getObjectDiff(newIns || newSubClass.prototype, oldIns || oldSubClass.prototype, clsOld.$className);
if (diff.length > 0) {
protChanged[clsOld.$className] = diff;
}
i++;
}
}
// Mark it as processed along with any class aliases
if (clsOld.alternateClassName) {
(Ext.isArray(clsOld.alternateClassName) ? clsOld.alternateClassName : [clsOld.alternateClassName]).forEach(function(name) { processed[name] = 1; });
}
});
newClasses.forEach(function (cls) {
var clsOld = ExtOld.ClassManager.get(cls);
if (!clsOld) {
added.push(cls);
}
});
callback.call(this, {
prototypeChanged : protChanged,
staticChanged : staticChanged,
added : added,
removed : removed
});
}
};
Ext.onReady(App.init, App);