Closed Bug 794990 Opened 12 years ago Closed 12 years ago

An object that extends NodeList does not satisfy instanceof

Categories

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

10 Branch
x86
macOS
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla18

People

(Reporter: m.prestifilippo, Unassigned)

References

Details

(Keywords: regression)

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1 Steps to reproduce: I extended NodeList (my subclass is called ElementList). But an instance of ElementList does not satisfy instanceof NodeList. The following code will illustrate this. var ElementList = function() {} ElementList.prototype = document.querySelectorAll('doesntexist') var a = new ElementList console.log(a instanceof NodeList) Actual results: a instanceof NodeList should return true Expected results: a instanceof NodeList should returned false
Got it backwards... Actual results: a instanceof NodeList returns false Expected results: a instanceof NodeList should be true
Just ran the following code in Nightly, still returns false.
Mozregression range: m-c good=2011-10-10 bad=2011-10-11 http://hg.mozilla.org/mozilla-central/pushloghtml?fromchange=e9c620a5c85f&tochange=ccea01542d0b m-i good=2011-10-10 bad=2011-10-11 http://hg.mozilla.org/integration/mozilla-inbound/pushloghtml?fromchange=e1927273c6c9&tochange=568821b5cdca Suspected bug: Bug 648801 - Prototype a proxy-based NodeList implementation
Blocks: 648801
Status: UNCONFIRMED → NEW
Component: Untriaged → DOM
Ever confirmed: true
Keywords: regression
Product: Firefox → Core
Version: 15 Branch → 10 Branch
Yep, NodeList has a somewhat magic [HasInstance] hook... Peter, is this changing with the WebIDL bindings? Mathhew, note that there isn't all that much you can do with the resulting object, per spec... (e.g. getting .length on it should throw).
I agree it's hard to work with. If I do the following, I can see what I added to the ElementList l = new ElementList; l[0] = document.createElement('div'); l[1] = document.createElement('a'); for(var i in l) console.log(l[i]); I don't have to subclass to get this functionality. I'm not even sure this is supposed to be legal. Please don't remove the functionality though! haha
> for(var i in l) console.log(l[i]); Per spec this should work for 0 and 1, then throw for i == "length".
The spec says the length property is readonly. Why would it throw an error if I read the length property?
Because the "this" object for the getter is not an actual NodeList object. Please see http://dev.w3.org/2006/webapi/WebIDL/#es-operations third bullet point step 2.
Fixed in WebIDL bindings.
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla18
Depends on: 791774
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.