Skip to content

Commit 8ae8bc3

Browse files
committed
NodeList.forEach() now takes care of the current state of the list
1 parent 9bec448 commit 8ae8bc3

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/main/java/org/htmlunit/javascript/host/dom/NodeList.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,14 @@ public void forEach(final Object callback) {
159159
final Function function = (Function) callback;
160160
final Scriptable scope = getParentScope();
161161

162-
final int size = getElements().size();
162+
List<DomNode> nodes = getElements();
163+
final int size = nodes.size();
163164
int i = 0;
164-
while (i < size) {
165-
function.call(cx, scope, this, new Object[] {getElements().get(i).getScriptableObject(), i, this});
165+
while (i < size && i < nodes.size()) {
166+
function.call(cx, scope, this, new Object[] {nodes.get(i).getScriptableObject(), i, this});
167+
168+
// refresh
169+
nodes = getElements();
166170
i++;
167171
}
168172

0 commit comments

Comments
 (0)