/*
 * Example class using the stacktrace by Kalle Alm, 2006-03-15.
 */

// will, after body-load, point to the pre element where we'll print out... stuff.
var dbgptr = null;

// pointer to our goodly stacktrace
var stack = new stacktrace();

// the debug-printer routine
var dbgprint = function(s)
{
    dbgptr.innerHTML += s + "\n";
};

var testClass = function() {
    dbgprint("constructing testClass");

    // Tell the stacktrace class what we're called -- which is testClass
    stack.id(this, "testClass");
    dbgprint("stacktrace now knows who we are");
};

// Let's add a few functions now. To keep things simple, we'll stick to one class but several functions.
// First though, we need to set the regtarget to testClass.
__regtarget(testClass);

// Now we're ready to register functions.
__reg("firstFunction", function (somearg) {
    dbgprint("firstFunction called with " + somearg + "; now gonna call secondFunction.");
    that.secondFunction(); // note the usage of 'that' here; we cannot use 'this' if we register via the stacktrace.
    dbgprint("left secondFunction; trace = \n" + stack.trace());
});

__reg("secondFunction", function () {
    dbgprint("secondFunction; this is what the stack trace output looks like:\n" + stack.trace());
    dbgprint("now I'm calling thirdFunction");
    that.thirdFunction();
    dbgprint("left thirdFunction; trace = \n" + stack.trace());
});

__reg("thirdFunction", function () {
    dbgprint("thirdFunction; this is the stack trace:\n" + stack.trace());
});

// Now all we gotta do is create the body-load function.

// the body-load function
var pageinit = function()
{
    dbgptr = document.getElementById('debugpane'); // we need a pre with the id "debugpane", thus.
    dbgprint("debugger initialized...");
    var test = new testClass();
    dbgprint("created test, instance of testClass");
    test.firstFunction("This is a test!");
    dbgprint("called test.firstFunction('This is a test!')");
};


