Javascript Runtime breakpoints
var TrimPath; if (TrimPath == null) TrimPath = new Object(); /** * TrimPath.breakpoint usage: * * In the middle of your code somewhere, add a line of code like... * * breakpoint(function(expr) { return eval(expr); }); * * You can also pass a message, like... * * breakpoint(function(expr) { return eval(expr); }, "breakpoint #2 in datetime validation"); * * You can also pass in an initial expression as the 3rd parameter, like... * * breakpoint(function(expr) { return eval(expr); }, "breakpoint #2 in datetime validation", "dateStr"); * * Then, you can enter expressions in the prompt dialog to inspect variables and objects * in the breakpoint's scope. Click Cancel in the prompt dialog to continue processing. */ var breakpoint = TrimPath.breakpoint = function(evalFunc, msg, initialExprStr) { // TrimPath.breakpoint currently works only in DOM/browser environment. if (msg == null) msg = ""; var result = initialExprStr || "1+2"; while (true) { var expr = prompt("BREAKPOINT: " + msg + "\nEnter an expression to evaluate, or Cancel to continue.", result); if (expr == null || expr == "") return; try { result = evalFunc(expr); } catch (e) { result = e; } } }
Then, at runtime, when the breakpoint line is reached, execution will stop and a prompt dialog will open where you can enter JavaScript expressions in order to...
* Inspect variables and objects in the breakpoint's scope. For example, "document.getElementById('foo').style.width"
* Set and modify variable values, too. For example, "currCounter = 0"
* Additionally, you can also call alert() from the breakpoint prompt dialog, such as when you want to inspect something with a large output value. For example, "alert(myHiddenTextarea.value)"