dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.26k stars 1.58k forks source link

Problem with compiling forEach() on FrozenElementList with frog #1026

Closed munificent closed 9 years ago

munificent commented 12 years ago

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.

jmesserly commented 12 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.

vsmenon commented 12 years ago

Removed Area-UI label. Added Area-DOM label.

vsmenon commented 12 years ago

This pattern appears to work today (queryAll(...).forEach(...)) in dart2js.


Added AssumedStale label.