Closed munificent closed 9 years ago
Looks like a DOM/HTML issue. dart:html assumes that dart:dom's NoteList is Iterable, but it's not marked that way.
Tracing this through the call stack: ElementList queryAll(String selectors) { // TODO(jacobr): scope fix. return new FrozenElementList._wrap(_ptr.querySelectorAll(selectors)); }
forEach looks like:
class FrozenElementList implements ElementList { final _ptr;
FrozenElementList._wrap(this._ptr); ... void forEach(void f(Element element)) { for (var element in _ptr) { f(LevelDom.wrapElement(element)); } } ...
dart:dom's NodeList looks like:
class NodeList native "*NodeList" {
int length;
Node operator[](int index) native;
void operator[]=(int index, Node value) { throw new UnsupportedOperationException("Cannot assign element of immutable List."); }
Node item(int index) native;
var dartObjectLocalStorage;
String get typeName() native; }
Set owner to @rakudrama. Removed Area-Frog label. Added Area-UI label.
This pattern appears to work today (queryAll(...).forEach(...)) in dart2js.
Added AssumedStale label.
Reported by Marcin:
var els = document.queryAll('a.add-event-handler');
els.forEach((el) { el.classes.remove('add-event-handler'); el.on.click.add(onAnchorClick); });
This works great in Dartium, but after compiling via frogc it complains with:
Uncaught NoSuchMethodException - receiver: '[object NodeList]' function name: 'iterator' arguments: []] $throw Object.noSuchMethod Object.iterator$0 FrozenElementList.forEach FrozenElementList.forEach$1
Given that it works in Dartium (and dartc as later reported) I'm guessing this is a frog bug.