public
Description: OpenLaszlo utilities: flash bridge, ajax, etc.
Homepage:
Clone URL: git://github.com/osteele/lzosutils.git
lzosutils / test / flashbridge / log-calls.js
100644 39 lines (36 sloc) 1.154 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
function log() {
    var msg = Array.prototype.join.call(arguments, ' '),
        div = document.createElement('div');
    div.innerHTML = (msg.
                     replace(/&/g, '&').
                     replace(/</g, '&lt;').
                     replace(/>/g, '&gt;').
                     replace('"', '&quote;'));
    document.getElementById('output').appendChild(div);
}
 
function logCall(fname, args) {
    var args = Array.prototype.slice.call(args, 0);
    args.unshift(fname);
    log.apply(null, args);
}
 
function traceFunction(path) {
    var target = window,
        properties = path.split('.');
    while (properties.length > 1)
        target = target[properties.shift()];
    var name = properties[0],
        fn = target[name];
    console.info('t', target, name);
    return target[name] = function() {
        logCall(path, arguments);
        return fn.apply(this, arguments);
    }
}
 
function traceMethods(path) {
    var target = window,
        properties = path.split('.');
    while (properties.length)
        target = target[properties.shift()];
    for (var name in target)
        traceFunction(path + '.' + name);
}