List Info

Thread: bug in MochiKit.DOM.appendChildNodes?




bug in MochiKit.DOM.appendChildNodes?
user name
2006-02-25 13:46:21
Hi,

I think I spotted a bug (this time  in
MochiKit.DOM.appendChildNodes.
The problem is that when an iterable is found in the node
stack, its
content is flattened at the end of the stack rather than
"in-place".
I see no reason why the current code would ever want to do
this.
Here are an example that exposes the bug and a patch for it.

Eric.

--------------------------------------------
--- DOM.js.orig Sat Feb 25 14:29:17 2006
+++ DOM.js      Sat Feb 25 14:29:40 2006
 -439,7
+439,6 
             elem
         )
     ];
-    var iextend = MochiKit.Iter.iextend;
     while (nodeStack.length) {
         var n = nodeStack.shift();
         if (typeof(n) == 'undefined' || n == null) {
 -447,7
+446,7 
         } else if (typeof(n.nodeType) == 'number') {
             elem.appendChild(n);
         } else {
-            iextend(nodeStack, n);
+           nodeStack = MochiKit.Base.extend(list(n),
nodeStack);
         }
     }
     return elem;
---------------------------------------------
<!DOCTYPE html
  PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/x
html">
  <head>
    <title>Test</title>
    <script src="MochiKit.js"
type="text/javascript"></script>
  </head>
  <body>
   <div id="foo"/>
  </body>
  <script type="text/javascript">

/* Uncomment to enable the fix.

MochiKit.DOM.appendChildNodes = function (node) {
    var elem = node;
    var self = MochiKit.DOM;
    if (typeof(node) == 'string') {
        elem = self.getElement(node);
    }
    var nodeStack = [
        self.coerceToDOM(
            MochiKit.Base.extend(null, arguments, 1),
            elem
        )
    ];
    while (nodeStack.length) {
        var n = nodeStack.shift();
        if (typeof(n) == 'undefined' || n == null) {
            // pass
        } else if (typeof(n.nodeType) == 'number') {
            elem.appendChild(n);
        } else {
	    nodeStack = MochiKit.Base.extend(list(n), nodeStack);
        }
    }
    return elem;
};
*/

makeLine = function(item) {
  return  TR(null, TD(null, "item ", item))
};

makeLines = function(items) {
  return [ TR(null, TD(null, "items ",
repr(items))),
           map(makeLine, items) ];
};

lines = [
  [ 1, 2, 3 ],
  [ 4, 5, 6 ],
  [ 7, 8, 9 ] ];

swapDOM("foo", TABLE(null, TR(null, TH(null,
"Things")),
                           TBODY(null,
				 map(makeLines, lines))));

  </script>
</html>


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "MochiKit" group.
To post to this group, send email to mochikitgooglegroups.com
To unsubscribe from this group, send email to
mochikit-unsubscribegooglegroups.com
For more options, visit this group at http://groups
.google.com/group/mochikit
-~----------~----~----~----~------~----~------~--~---

bug in MochiKit.DOM.appendChildNodes?
user name
2006-02-25 14:01:20

On Feb 25, 2006, at 7:46 AM, Eric Faurot wrote:

> I think I spotted a bug (this time  in  
> MochiKit.DOM.appendChildNodes.
> The problem is that when an iterable is found in the
node stack, its
> content is flattened at the end of the stack rather
than "in-place".
> I see no reason why the current code would ever want to
do this.
> Here are an example that exposes the bug and a patch
for it.

Yes, that was a bug in MochiKit up to 1.2... but you're a
few weeks  
late.  It was found and fixed a few weeks ago.

	http://trac.mochik
it.com/ticket/52
	http://trac.mo
chikit.com/changeset/612

* MochiKit.DOM.appendChildNodes and associated functions now
append  
iterables in the correct order.

-bob


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "MochiKit" group.
To post to this group, send email to mochikitgooglegroups.com
To unsubscribe from this group, send email to
mochikit-unsubscribegooglegroups.com
For more options, visit this group at http://groups
.google.com/group/mochikit
-~----------~----~----~----~------~----~------~--~---

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )