Closed Bug 11115 Opened 25 years ago Closed 24 years ago

DOM Collection JS classes should delegate to Array.prototype

Categories

(Core :: DOM: Core & HTML, defect, P3)

defect

Tracking

()

VERIFIED WONTFIX

People

(Reporter: brendan, Assigned: brendan)

Details

Vidur kindly said file a bug on him, but I figured I could do this with his
advice and consent, so I'm filing it on me!

/be
Status: NEW → ASSIGNED
Target Milestone: M10
Assignee: brendan → brendan
Status: ASSIGNED → NEW
I should keep my bugs assigned to brendan@netscape.com, not to my @mozilla.org
alter ego.

/be
QA Contact: gerardok → ckritzer
Status: NEW → ASSIGNED
Target Milestone: M10 → M15
Why update on this one?
I meant "any update on this one?" Ups!
Any testcase?
What about something like this:
<SCRIPT>
for (a in document.getElementsByTagName("*")) {
  document.writeln(a + "<BR>");
}
</SCRIPT>
Target Milestone: M15 → M16
Henrik: the advantage of making DOM collection classes delegate to
Array.prototype is that one could then use slice(), concat(), join(), and all
the other Array methods on collection instances.

/be
Moving out.

jst, vidur: is this kind of extension (it gives all DOM collections methods such 
as sort and slice/splice) allowed by the standard?

/be
Target Milestone: M16 → M18
jst@netscape.com wrote:
> I say WONTFIX. One reason for this is that there are a number of different
> array type interfaces in the DOM but not all of those can support things like
> soring, take the attributes list (NamedNodeMap) in all nodes for instance,
> attributes is a completetly unorderd list. The attribute nodes in that list
> are accessible by index, but there's no way to insert an attribute node into
> that list at a particular index. If we do choose to support things like sort
> in all our array like interfaces we'd need a way for the JS engine to tell
> the native (C++) implementation to either do the sorting or the native
> implementations would need to expose the neccessary methods (through internal
> interfaces) for the JS engine to do the sorting, right?

Right.  Array.prototype.sort is generic, it uses only OBJ_GET_PROPERTY (which 
for native objects will call the JSClass.getProperty hook) to put array values 
in a vector, sort them, and then reinitialize the this parameter as a new array 
object with the sorted vector as its content (that re-initialization uses 
OBJ_DEFINE_PROPERTY, which for native objects will call through the addProperty 
JSClass hook).

So the DOM classes would have to have non-permanent (deleteable) properties, and 
they would have to "do the right thing" given addProperty calls that replace 
existing indexed properties with new ones having different (sorted) values. 

I'll WONTFIX this bug, thanks. 

/be 
Status: ASSIGNED → RESOLVED
Closed: 24 years ago
Resolution: --- → WONTFIX
Just so I understand:
for (a in document.getElementsByTagName("*")) {
  document.writeln(a + "<BR>");
}
will never be possible?
Henrik: your for..in loop example has nothing to do with this bug.  If it does
not work as you expect, please file another bug saying that indexed elements of
DOM collections are not enumerable (lack JSPROP_ENUMERATE in their JS property
attributes).  If it works, then where's the beef?

/be
Mass update of qa contact
QA Contact: ckritzer → janc
verified
Status: RESOLVED → VERIFIED
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.