chiark / gitweb /
dep-ui.js: Add some debugging machinery.
authorMark Wooding <mdw@distorted.org.uk>
Sat, 13 Apr 2013 23:15:50 +0000 (00:15 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 13 Apr 2013 23:15:50 +0000 (00:15 +0100)
The `DEP_UI.debug' function writes a trace message to the `trace'
element, if there is one.  Add a `trace' element.

dep-ui.js
rolling.html

index 29f5d6bb7bea435041563d486ca6c9ce451d7b34..22f2e60ee564f72ce17ab8b818da1c2ae772fa4e 100644 (file)
--- a/dep-ui.js
+++ b/dep-ui.js
@@ -25,6 +25,22 @@ var DEP_UI = {}; (function () { with (DEP_UI) {
 
 /*----- Utility functions and classes -------------------------------------*/
 
+DEP_UI.debug = function(msg) {
+  /* Write the string MSG to the `trace' element, if there is one. */
+
+  var e = elt('trace');
+  if (e !== null) e.textContent += msg;
+}
+
+  DEP_UI.trap = function(what, func) {
+  try {
+    func();
+  } catch (e) {
+    debug('caught exception in ' + what + ': ' + e);
+    throw e;
+  }
+}
+
 DEP_UI.elt = function (id) {
   /* Find and return the element with the given ID. */
   return document.getElementById(id);
index 3ac355525424910c63e92cda55bf39b285b0114c..b4656a28124efc534103a5301df5372f88b07170 100644 (file)
@@ -12,6 +12,7 @@
 
 <h1>Rolling wire-strip calculator</h1>
 
+<div id=trace style="white-space: pre"></div>
 <script type="text/javascript"><!--
 --></script>