Author: ptw
Date: 2007-07-02 11:05:55 -0700 (Mon, 02 Jul 2007)
New Revision: 5579

Modified:
   openlaszlo/branches/legals/WEB-INF/lps/lfc/debugger/platform/dhtml/LzDebug.js
Log:
?\239?\187?\191Change 20070702-ptw-D by [EMAIL PROTECTED] on 2007-07-02 
09:05:57 EDT
    in /Users/ptw/OpenLaszlo/legals
    for http://svn.openlaszlo.org/openlaszlo/branches/legals

Summary: Preserve Debug.printLength when overriding

Bugs Fixed:
LPP-4234 'DHTML Debug.inspect clobbers printLength'

Technical Reviewer: ben (Message-Id: <[EMAIL PROTECTED]>)
QA Reviewer: frisco (pending)

Details:
    Guard with a try/catch.  Also, move length computation out of
    object test so length will be displayed for strings.

Tests:
    ant lztest, smokecheck

    lzx> Debug.printLength = 24
    24
    lzx> "A long string that will be abbreviated"
    ?\194?\171string(38)| 'A l...?\194?\187
    lzx> Debug.inspect('A long string that will be abbreviated')
    'A long string that will be abbreviated'
    ?\194?\171string(38)| 'A l...?\194?\187
    lzx> Debug.printLength
    24
    lzx> 



Modified: 
openlaszlo/branches/legals/WEB-INF/lps/lfc/debugger/platform/dhtml/LzDebug.js
===================================================================
--- 
openlaszlo/branches/legals/WEB-INF/lps/lfc/debugger/platform/dhtml/LzDebug.js   
    2007-07-02 13:24:19 UTC (rev 5578)
+++ 
openlaszlo/branches/legals/WEB-INF/lps/lfc/debugger/platform/dhtml/LzDebug.js   
    2007-07-02 18:05:55 UTC (rev 5579)
@@ -7,8 +7,8 @@
 Debug.objectClassPattern = new RegExp('^\\[object\\s+(\\w+)\\]$');
 Debug.nativeClassPattern = new RegExp('^\\[(\\w+)\\]$');
 /**
-  * @access private
-  */
+ * @access private
+ */
 Debug.__typeof = function (thing) {
   try {
     // default type
@@ -66,14 +66,13 @@
           n = '\u00bf' + n + '?';
         }
       }
-
-      // Show dimensions, if applicable
-      try {
-        if (typeof(thing.length) == 'number') {
-          n += '(' + thing.length + ')';
-        }
-      } catch (e) {};
     }
+    // Show dimensions, if applicable
+    try {
+      if (thing && typeof(thing.length) == 'number') {
+        n += '(' + thing.length + ')';
+      }
+    } catch (e) {};
   }
   catch (e) {
     try {
@@ -85,14 +84,14 @@
   }
 
   return n;
-}
+};
 
 
 Debug.functionNamePattern = new RegExp('function\\s+([^\\s(]+)[\\s(]');
 
 /**
-  * @access private
-  */
+ * @access private
+ */
 Debug.functionName = function (fn, mustBeUnique) {
   if (fn && (fn instanceof Function)) {
     // tip o' the pin to osteele.com
@@ -110,20 +109,20 @@
     }
   }
   return null;
-}
+};
 
 /**
-  * @access private
-  */
-  Debug.__String = function (thing, pretty, limit, unique) {
+ * @access private
+ */
+Debug.__String = function (thing, pretty, limit, unique) {
   try {
     switch (arguments.length) {
       case 1:
-        pretty = this.printPretty;
+      pretty = this.printPretty;
       case 2:
-        limit = this.printLength;
+      limit = this.printLength;
       case 3:
-        unique = !pretty;
+      unique = !pretty;
     }
     // Evade infinite recursion
     if (limit <= 0) return '';
@@ -170,7 +169,7 @@
         catch (e) {}
       } else if (thing['_dbg_name'] &&
                  (typeof(thing._dbg_name) == 'string'
-                 || (debug_name instanceof String))) {
+                  || (debug_name instanceof String))) {
         debug_name = thing._dbg_name;
       }
       this.printLength = opl;
@@ -290,20 +289,20 @@
         }
         var ellip = true;
         var tl = thing.length
-          // Don't accumulate beyond limit
-          for (var e = 0; (e < tl) && (s.length < limit); e++) {
-            // skip non-existent elements
-            if ((typeof(thing[e]) == 'undefined')) {
-              if (ellip) {
-                s += '..., ';
-                ellip = false;
-              }
-            } else {
-              ellip = true;
-              // TODO: [2005-06-22 ptw] Use __String in case element is huge
-              s += String(thing[e]) + ', ';
+        // Don't accumulate beyond limit
+        for (var e = 0; (e < tl) && (s.length < limit); e++) {
+          // skip non-existent elements
+          if ((typeof(thing[e]) == 'undefined')) {
+            if (ellip) {
+              s += '..., ';
+              ellip = false;
             }
+          } else {
+            ellip = true;
+            // TODO: [2005-06-22 ptw] Use __String in case element is huge
+            s += String(thing[e]) + ', ';
           }
+        }
         if (s != '')
           s = s.substring(0, s.length - 2);
         s = '[' + s + ']';
@@ -394,11 +393,11 @@
   }
   r += '\u00BB'; // >>
   return r;
-}
+};
 
 /**
-  * @access private
-  */
+ * @access private
+ */
 Debug.makeObjectLink = function (rep, id, attrs) {
   var type = 'INSPECT';
   switch (arguments.length) {
@@ -417,117 +416,118 @@
     return '<a class="' + type + '" title="' + tip + '" 
href="javascript:window.parent.$modules.lz.Debug.displayObj(' + id + ')">' + 
rep +"</a>";
   }
   return rep;
-}
+};
 
 /**
-  * @access private
-  */
+ * @access private
+ */
 Debug.inspectInternal = function (obj, showInternalProperties) {
   var si = (typeof(showInternalProperties) != 
'undefined')?showInternalProperties: this.showInternalProperties;
   var hasProto = obj && obj.hasOwnProperty;
   var opl = this.printLength;
-
-  // TODO: [2003-09-12 ptw] either bind or pass as option
-  // Disable printLength for printing the name of a non-object in case
-  // it was abbreviated, otherwise set it short
-  if (! ((typeof(obj) == 'object') || (obj instanceof Object))) {
-    this.printLength = Infinity;
-  } else {
+  try {
+    // TODO: [2003-09-12 ptw] either bind or pass as option
+    // Disable printLength for printing the name of a non-object in case
+    // it was abbreviated, otherwise set it short
+    if (! ((typeof(obj) == 'object') || (obj instanceof Object))) {
+      this.printLength = Infinity;
+    } else {
+      this.printLength = this.inspect.printLength;
+    }
+    // Turn off pretty for name
+    var name = this.xmlEscape(this.__String(obj, false));
+    if (! (obj instanceof Object)) {
+      return name;
+    }
+    // Print properties with abbreviated length
     this.printLength = this.inspect.printLength;
-  }
-  // Turn off pretty for name
-  var name = this.xmlEscape(this.__String(obj, false));
-  if (! (obj instanceof Object)) {
-    return name;
-  }
-  // Print properties with abbreviated length
-  this.printLength = this.inspect.printLength;
 
-  var keys = [];
-  var arraylen = typeof(obj.length) == 'number' ? obj.length : null;
-  if (si) {
-    // print unenumerable properties of ECMA objects
-    // TODO: [2006-04-11 ptw] enumerate Global/Number/Math/Regexp
-    // object properties
-    for (var p in {callee: true, length: true, constructor: true, prototype: 
true}) {
+    var keys = [];
+    var arraylen = typeof(obj.length) == 'number' ? obj.length : null;
+    if (si) {
+      // print unenumerable properties of ECMA objects
+      // TODO: [2006-04-11 ptw] enumerate Global/Number/Math/Regexp
+      // object properties
+      for (var p in {callee: true, length: true, constructor: true, prototype: 
true}) {
+        try {
+          if (hasProto && obj.hasOwnProperty(p)) {
+            keys.push(p);
+          }
+        } catch (e) {};
+      }
+    }
+    for (var key in obj) {
+      // Print only local slots
       try {
-        if (hasProto && obj.hasOwnProperty(p)) {
-          keys.push(p);
+        if ((! hasProto) ||
+            obj.hasOwnProperty(key) ||
+            // or getter slots (this is a heuristic -- there is no way to
+            // ask if a property is a getter)
+            (function () { try { return obj[key] } catch (e) {} })() !== 
+            (function () { try { return obj.constructor.prototype[key] } catch 
(e) {} })()
+            ) {
+          // Print array slots later, in order
+          if (arraylen && (key >= 0) && (key < arraylen)) {
+          } else if (si ||
+                     ((! this.internalProperty(key)) &&
+                      // Only show slots with internal type if showing
+                      // internals
+                      (! this.internalProperty(this.__typeof(obj[key]))))) {
+            keys.push(key);
+          }
         }
       } catch (e) {};
     }
-  }
-  for (var key in obj) {
-    // Print only local slots
-    try {
-      if ((! hasProto) ||
-          obj.hasOwnProperty(key) ||
-          // or getter slots (this is a heuristic -- there is no way to
-          // ask if a property is a getter)
-          (function () { try { return obj[key] } catch (e) {} })() !== 
-          (function () { try { return obj.constructor.prototype[key] } catch 
(e) {} })()
-          ) {
-        // Print array slots later, in order
-        if (arraylen && (key >= 0) && (key < arraylen)) {
-        } else if (si ||
-                   ((! this.internalProperty(key)) &&
-                    // Only show slots with internal type if showing
-                    // internals
-                    (! this.internalProperty(this.__typeof(obj[key]))))) {
-          keys.push(key);
-        }
+
+    keys.sort(function (a, b) {
+        var al = a.toLowerCase();
+        var bl = b.toLowerCase();
+        return (al > bl) - (al < bl);
+      });
+    var description = "";
+    var kl = keys.length;
+    var val;
+    var wid = 0;
+    // Align all keys if annotating 'weight'
+    if (this.markGeneration > 0) {
+      for (var i = 0; i < kl; i++) {
+        var kil = keys[i].length;
+        if (kil > wid) { wid = kil; }
       }
-    } catch (e) {};
-  }
-
-  keys.sort(function (a, b) {
-    var al = a.toLowerCase();
-    var bl = b.toLowerCase();
-    return (al > bl) - (al < bl);
-  });
-  var description = "";
-  var kl = keys.length;
-  var val;
-  var wid = 0;
-  // Align all keys if annotating 'weight'
-  if (this.markGeneration > 0) {
-    for (var i = 0; i < kl; i++) {
-      var kil = keys[i].length;
+    }
+    if (arraylen) {
+      var kil = ('' + arraylen).length;
       if (kil > wid) { wid = kil; }
     }
-  }
-  if (arraylen) {
-    var kil = ('' + arraylen).length;
-    if (kil > wid) { wid = kil; }
-  }
-  var last;
-  for (var i = 0; i < kl; i++) {
-    var key = keys[i];
-    // Some runtimes duplicate inherited slots
-    if (key != last) {
-      last = key;
-      val = obj[key];
-      description += '  ' + this.computeSlotDescription(obj, key, val, wid) + 
'\n';
+    var last;
+    for (var i = 0; i < kl; i++) {
+      var key = keys[i];
+      // Some runtimes duplicate inherited slots
+      if (key != last) {
+        last = key;
+        val = obj[key];
+        description += '  ' + this.computeSlotDescription(obj, key, val, wid) 
+ '\n';
+      }
     }
-  }
 
-  if (arraylen &&
-      // Don't print the characters of a string
-      (! ((typeof obj == 'string') || (obj instanceof String)))) {
-    for (var key = 0; key < arraylen; key++) {
-      // Skip non-existent elements, but don't bother with ellipses,
-      // since we are displaying the key here
-      if ((! hasProto) ||
-          obj.hasOwnProperty(key)) {
-        val = obj[key];
-        if(typeof(val) != 'undefined') {
-          description += '  ' + this.computeSlotDescription(obj, key, val, 
wid) + '\n';
+    if (arraylen &&
+        // Don't print the characters of a string
+        (! ((typeof obj == 'string') || (obj instanceof String)))) {
+      for (var key = 0; key < arraylen; key++) {
+        // Skip non-existent elements, but don't bother with ellipses,
+        // since we are displaying the key here
+        if ((! hasProto) ||
+            obj.hasOwnProperty(key)) {
+          val = obj[key];
+          if(typeof(val) != 'undefined') {
+            description += '  ' + this.computeSlotDescription(obj, key, val, 
wid) + '\n';
+          }
         }
       }
     }
+  } finally {
+    this.printLength = opl;
   }
-
-  this.printLength = opl;
   // Annotate 'weight' if available
   if (this.markGeneration > 0) {
     var leaked = this.annotation.leaked;
@@ -542,12 +542,12 @@
   }
   if (description != "") { description = ' {\n' + description + '}'; }
   return name + description;
-}
+};
 
 /**
-  * Compute slot description
-  * @access private
-  */
+ * Compute slot description
+ * @access private
+ */
 Debug.computeSlotDescription = function (obj, key, val, wid) {
   var r = key + ':';
   try {
@@ -586,7 +586,7 @@
     }
   }
   return r;
-}
+};
 
 //* A_LZ_COPYRIGHT_BEGIN ******************************************************
 //* Copyright 2001-2007 Laszlo Systems, Inc.  All Rights Reserved.            *


_______________________________________________
Laszlo-checkins mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-checkins

Reply via email to