Skip to content

NodeList.filter and NodeList.getRange does not work as advertised #5369

@jmesserly

Description

@jmesserly

NodeList.filter returns a NodeList, but it doesn't behave like a normal NodeList. If you mutate this list, the node is not added to the document. Also, no error is reported. Contrast with .elements, which returns a frozen list.
http://api.dartlang.org/docs/continuous/dart_html/NodeList.html

one of these solutions would be better:

  • declare return type as List<Node>, and return mutable list. Essentially like it does now, but the type better aligns with user expectations.
  • return immutable NodeList, like Element.elements does

here's a way to reproduce this:

<!doctype html>
<html>
<head></head>
<body>
<div class="awesome">Hello there</div>
<script type="application/dart">

import('dart:html');

main() {
  // Yeah, you could do this other ways, like with a query :)
  var nodes = document.body.nodes;
  // This won't be added and won't produce an error
  nodes.filter((n) => true).add(new DivElement()..text = ' this no worky!');
  nodes.add(new DivElement()..text = ' but this does!');
}
</script>
<script type="text/javascript">navigator.webkitStartDart();</script>
</body>
</html>

Metadata

Metadata

Assignees

Labels

web-librariesIssues impacting dart:html, etc., libraries

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions