From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from out.smtp-auth.no-ip.com (out.smtp-auth.no-ip.com [8.23.224.60]) by hurricane.the-brannons.com (Postfix) with ESMTPS id B718F77DC4 for ; Sat, 28 Jan 2017 18:17:22 -0800 (PST) X-No-IP: carhart.net@noip-smtp X-Report-Spam-To: abuse@no-ip.com Received: from carhart.net (unknown [99.52.200.227]) (Authenticated sender: carhart.net@noip-smtp) by smtp-auth.no-ip.com (Postfix) with ESMTPA id 2FDC33E6 for ; Sat, 28 Jan 2017 18:18:11 -0800 (PST) Received: from carhart.net (localhost [127.0.0.1]) by carhart.net (8.13.8/8.13.8) with ESMTP id v0T2IAkL027085 for ; Sat, 28 Jan 2017 18:18:10 -0800 Received: from localhost (kevin@localhost) by carhart.net (8.13.8/8.13.8/Submit) with ESMTP id v0T2I9mi027082 for ; Sat, 28 Jan 2017 18:18:10 -0800 Date: Sat, 28 Jan 2017 18:18:09 -0800 (PST) From: Kevin Carhart To: Edbrowse-dev@lists.the-brannons.com In-Reply-To: <20170028052734.eklhad@comcast.net> Message-ID: References: <20170028052734.eklhad@comcast.net> User-Agent: Alpine 2.03 (LRH 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Subject: Re: [Edbrowse-dev] infinite loop js while() X-BeenThere: edbrowse-dev@lists.the-brannons.com X-Mailman-Version: 2.1.23 Precedence: list List-Id: Edbrowse Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 29 Jan 2017 02:17:22 -0000 This is great! Very exciting! On Sat, 28 Jan 2017, Karl Dahlke wrote: > After some detective work, here is the js that causes the infinite loop. > It creates two nodes, ft and fg, uses ft.innerHTML to put some nodes beneath ft, > then has a while loop that, I assume, moves the nodes from ft to fg. > Here's the code, then more thoughts below. > > var rid=oio.at_ei,fg=document.createDocumentFragment(),ft=document.createElement('div'); > ft.innerHTML='<'+'div class="'+oio.at_ec+'" id="'+rid+'" style="'+oio.at_es+'"> '+'<'+'/div'+'>'; > while(ft.firstChild)fg.appendChild(ft.firstChild); > document.body.insertBefore(fg,document.body.childNodes[0]); > > Ok, so the generated html looks like this. > >
 
> > Running through innerHTML, that creates a node under ft. > All good so far. > Then comes the while loop, and the only way this isn't an infinite loop is if appendChild removes the node first from wherever it is, then appends it. > I've been talking about this on the edbrowse side, in our own tree of nodes, but here it is on the js side, strictly within dom, and it's the same issue. > I think this is not just compelling evidence, but a smoking gun. > Even if it doesn't say so in the spec, appendChild and insertBefore should remove the child from wherever it is first, then put it beneath the new node. > Then the while loop above simply moves all the children from ft to fg. Zip zap. > > I'm going to think about this for a bit, cause if I just start writing code I'll screw it up, but I'm pretty sure I understand the problem now. > I just need to fix it with a small amount of code, and not breaking anything else. > I imagine if I fix it on the js side, by issuing a remove when necessary, before the append, then all those actions will carry over to the edbrowse side in our sideEffects, and I won't have to change any code over there, it will just all work. > > Karl Dahlke > -------- Kevin Carhart * 415 225 5306 * The Ten Ninety Nihilists