Closed
Bug 794990
Opened 13 years ago
Closed 13 years ago
An object that extends NodeList does not satisfy instanceof
Categories
(Core :: DOM: Core & HTML, defect)
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
| Reporter | ||
Comment 1•13 years ago
|
||
Got it backwards...
Actual results:
a instanceof NodeList returns false
Expected results:
a instanceof NodeList should be true
Comment 2•13 years ago
|
||
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
Comment 4•13 years ago
|
||
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).
| Reporter | ||
Comment 5•13 years ago
|
||
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
Comment 6•13 years ago
|
||
> for(var i in l) console.log(l[i]);
Per spec this should work for 0 and 1, then throw for i == "length".
| Reporter | ||
Comment 7•13 years ago
|
||
The spec says the length property is readonly. Why would it throw an error if I read the length property?
Comment 8•13 years ago
|
||
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.
Comment 9•13 years ago
|
||
Fixed in WebIDL bindings.
Status: NEW → RESOLVED
Closed: 13 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla18
| Assignee | ||
Updated•7 years ago
|
Component: DOM → DOM: Core & HTML
You need to log in
before you can comment on or make changes to this bug.
Description
•