-
Notifications
You must be signed in to change notification settings - Fork 2
/
server-modification.js
97 lines (77 loc) · 2.88 KB
/
server-modification.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
var fs = require('fs');
var path = require('path');
var esinstrument = require('./server-instrument');
//var __to_set = require('./log/server-logger').to_set;
//var __to_callback = require('./log/server-logger').to_callback;
exports.instrument = function (dir) {
var appFiles = fs.readdirSync(dir);
appFiles.forEach(function (fileName) {
var fileExt = path.extname(fileName);
if ('.html' == fileExt || '.htm' == fileExt) {
// console.log('------- html');
}
else if ('.js' == fileExt) {
// console.log('js');
var filePath = dir + '/' + fileName;
var script = fs.readFileSync(filePath, 'utf8');
var instrumentedAst = esinstrument.instrumentAst(script);
var instrumentedScript = esinstrument.generateScript(instrumentedAst);
console.log(instrumentedScript);
}
});
};
/*
exports.modifyTimeouts = function () {
// __setTimeout = window.setTimeout;
}
*/
/*
// Keep the current setTimeout function
__setTimeout = setTimeout;
// Redefine setTimeout
setTimeout = function(func, delay, params) {
var wrapperFunc = new Object();
//var timeoutArgs = Array.prototype.slice.call(arguments, 2);
var timeoutArgs = null;
if (typeof func == 'function') {
wrapperFunc._original = func;
// wrapperFunc.name = func; // TODO TODO GET NAME
// TODO SET ID
func = wrapperFunc;
}
// if (Object.prototype.toString.apply(func) === '[object String]') {
// wrapperFunc._original = func;
// wrapperFunc.name = func;
// func = wrapperFunc;
// }
// Log the creation of the timeout
__to_set(func, delay, timeoutArgs);
// Call the original timeout after logging
__setTimeout(function() { // params ) {
try {
console.log('timeout');
// logger.logTimeoutCallback(func); // TODO LOG
// console.log('CALLBACK TO: ', func);
__to_callback(func);
if (typeof func._original == 'function')
func._original.apply(null);
else if (typeof func._original == 'object')
eval(func._original);
else
console.log('INVALID timeout callback');
// if (Object.prototype.toString.apply(func) === '[object Function]') {
// func.apply(null);
// } else if (Object.prototype.toString.apply(func) === '[object String]') {
// // eval(func);
// } else if (Object.prototype.toString.apply(func) === '[object Object]' && func._original) {
// eval(func._original);
// } else {
// console.log('Invalid timeout callback, must be Function or String.');
// }
} catch (exception) {
// alert("Timeout exception");
}
}, delay);
};
//setTimeout(function() {console.log('to cb');}, 500);
*/