@@ -282,6 +282,140 @@ public void forEach() throws Exception {
282282 loadPageVerifyTitle2 (html );
283283 }
284284
285+ /**
286+ * @throws Exception if an error occurs
287+ */
288+ @ Test
289+ @ Alerts ({"4" , "4" ,
290+ "[object HTMLElement]/0" , "3" , "3" ,
291+ "[object HTMLElement]/1" , "2" , "2" ,
292+ "2" , "2" })
293+ public void forEachRemove () throws Exception {
294+ final String html = DOCTYPE_HTML
295+ + "<html><head>\n "
296+ + "<script>\n "
297+ + LOG_TITLE_FUNCTION
298+ + " function test() {\n "
299+ + " var nodeList = document.getElementById('myId').childNodes;\n "
300+ + " if (nodeList.forEach) {\n "
301+ + " log(document.getElementById('myId').childNodes.length);\n "
302+ + " log(nodeList.length);\n "
303+
304+ + " nodeList.forEach(myFunction);\n "
305+
306+ + " log(document.getElementById('myId').childNodes.length);\n "
307+ + " log(nodeList.length);\n "
308+ + " } else {\n "
309+ + " log('no forEach');\n "
310+ + " }\n "
311+ + " }\n "
312+
313+ + " function myFunction(value, index, list, arg) {\n "
314+ + " log(value + '/' + index);\n "
315+ + " document.getElementById('myId').removeChild(value);\n "
316+ + " log(document.getElementById('myId').childNodes.length);\n "
317+ + " log(list.length);\n "
318+ + " }\n "
319+ + "</script>\n "
320+ + "</head><body onload='test()'>\n "
321+ + " <div id='myId'><strong>a</strong>b<b>d</b>e</div>\n "
322+ + "</body></html>" ;
323+
324+ loadPageVerifyTitle2 (html );
325+ }
326+
327+ /**
328+ * @throws Exception if an error occurs
329+ */
330+ @ Test
331+ @ Alerts ({"4" , "4" ,
332+ "[object HTMLElement]/0" , "5" , "5" ,
333+ "[object Text]/1" , "6" , "6" ,
334+ "[object HTMLElement]/2" , "7" , "7" ,
335+ "[object Text]/3" , "8" , "8" ,
336+ "8" , "8" })
337+ public void forEachAppend () throws Exception {
338+ final String html = DOCTYPE_HTML
339+ + "<html><head>\n "
340+ + "<script>\n "
341+ + LOG_TITLE_FUNCTION
342+ + " function test() {\n "
343+ + " var nodeList = document.getElementById('myId').childNodes;\n "
344+ + " if (nodeList.forEach) {\n "
345+ + " log(document.getElementById('myId').childNodes.length);\n "
346+ + " log(nodeList.length);\n "
347+
348+ + " nodeList.forEach(myFunction);\n "
349+
350+ + " log(document.getElementById('myId').childNodes.length);\n "
351+ + " log(nodeList.length);\n "
352+ + " } else {\n "
353+ + " log('no forEach');\n "
354+ + " }\n "
355+ + " }\n "
356+
357+ + " function myFunction(value, index, list, arg) {\n "
358+ + " log(value + '/' + index);\n "
359+ + " if (index < 4) {\n "
360+ + " document.getElementById('myId').appendChild(document.createElement('p'));\n "
361+ + " }\n "
362+ + " log(document.getElementById('myId').childNodes.length);\n "
363+ + " log(list.length);\n "
364+ + " }\n "
365+ + "</script>\n "
366+ + "</head><body onload='test()'>\n "
367+ + " <div id='myId'><strong>a</strong>b<b>d</b>e</div>\n "
368+ + "</body></html>" ;
369+
370+ loadPageVerifyTitle2 (html );
371+ }
372+
373+ /**
374+ * @throws Exception if an error occurs
375+ */
376+ @ Test
377+ @ Alerts ({"4" , "4" ,
378+ "[object HTMLElement]/0" , "5" , "5" ,
379+ "[object HTMLElement]/1" , "6" , "6" ,
380+ "[object HTMLElement]/2" , "7" , "7" ,
381+ "[object HTMLElement]/3" , "8" , "8" ,
382+ "8" , "8" })
383+ public void forEachInsert () throws Exception {
384+ final String html = DOCTYPE_HTML
385+ + "<html><head>\n "
386+ + "<script>\n "
387+ + LOG_TITLE_FUNCTION
388+ + " function test() {\n "
389+ + " var nodeList = document.getElementById('myId').childNodes;\n "
390+ + " if (nodeList.forEach) {\n "
391+ + " log(document.getElementById('myId').childNodes.length);\n "
392+ + " log(nodeList.length);\n "
393+
394+ + " nodeList.forEach(myFunction);\n "
395+
396+ + " log(document.getElementById('myId').childNodes.length);\n "
397+ + " log(nodeList.length);\n "
398+ + " } else {\n "
399+ + " log('no forEach');\n "
400+ + " }\n "
401+ + " }\n "
402+
403+ + " function myFunction(value, index, list, arg) {\n "
404+ + " log(value + '/' + index);\n "
405+ + " if (index < 4) {\n "
406+ + " document.getElementById('myId').insertBefore(document.createElement('p'), value);\n "
407+ + " }\n "
408+ + " log(document.getElementById('myId').childNodes.length);\n "
409+ + " log(list.length);\n "
410+ + " }\n "
411+ + "</script>\n "
412+ + "</head><body onload='test()'>\n "
413+ + " <div id='myId'><strong>a</strong>b<b>d</b>e</div>\n "
414+ + "</body></html>" ;
415+
416+ loadPageVerifyTitle2 (html );
417+ }
418+
285419 /**
286420 * @throws Exception if the test fails
287421 */
0 commit comments