// assert
// Asserts that the given condition is true. If the condition is false, an error
// message is display and the current script execution thread is terminated by
// throwing an exception.
function assert(condition, message)
{
    if (!condition)
    {
        var text = "";
        if (null == arguments.callee.caller)
        {
            if (null == message)
            {
                text += "Assertion failure: " + message;
            }
            else
            {
                text += "Assertion failure!";
            }
        }
        else
        {
            text += "Assertion failed in function " + arguments.callee.caller.toString().match(/function\s+(\w+)/)[1];
            if (null == message)
            {
                text += ".";
            }
            else
            {
                text += ": " + message;
            }
        }
        alert(text);
        throw text;
    }
}

