Closed
Bug 371711
Opened 18 years ago
Closed 9 years ago
Assigning into the HTMLCollection returned by document.getElementsByTagName should throw
Categories
(Core :: DOM: Core & HTML, enhancement)
Tracking
()
RESOLVED
WORKSFORME
People
(Reporter: jruderman, Unassigned)
Details
(Keywords: testcase)
Attachments
(2 files)
I think the following code should cause an exception to be thrown:
document.getElementsByTagName('button')[0] = 'wtf';
I don't think this would break web sites, since it crashed for a while (bug 367589) and I was the first to notice.
Updated•15 years ago
|
Assignee: general → nobody
QA Contact: ian → general
Reporter | ||
Comment 1•15 years ago
|
||
Strangely, Safari and Opera have the same behavior: it doesn't throw.
Reporter | ||
Comment 2•15 years ago
|
||
WebIDL + DOM Core probably mandates one behavior or another here.
Comment 3•14 years ago
|
||
Until DOM Core NodeLists are rewritten in Web IDL (probably as part of Web DOM Core) no particular behaviour is mandated at the moment. But if it were, I think the behaviour should be not to throw, unless in strict mode. (Because the "0" property that would exist due to the index getter would be [[Writable]]:false.)
Comment 4•13 years ago
|
||
AFAICT from WebIDL, the assignments in this test should throw, but nobody does that. Cameron, could you have a look?
Comment 5•13 years ago
|
||
Yes, with that test, the first assignment should throw a TypeError (the [[DefineOwnProperty]] algorithm in http://dev.w3.org/2006/webapi/WebIDL/#defineownproperty says to Reject (= throw when in strict mode) if the object supports indexed properties but doesn't have a setter or creator defined on the interface.
The two last w() calls should then write out "[object HTMLButtonElement]" and "undefined".
Note that this is a slightly different case from throwing due to being in strict mode and assigning to a property that exists and is a currently supported property index (*mouthful*). If everyone just ignores the assignment, I'm open to changing the spec to require that instead of throwing, if people think it's a good idea. I think it's more consistent with the aims of strict mode to throw in this case, though.
Updated•9 years ago
|
Attachment #571338 -
Attachment mime type: text/plain → text/html
Comment 6•9 years ago
|
||
Worksforme in strict mode, as expected.
Status: NEW → RESOLVED
Closed: 9 years ago
Resolution: --- → WORKSFORME
Assignee | ||
Updated•6 years ago
|
Component: DOM → DOM: Core & HTML
You need to log in
before you can comment on or make changes to this bug.
Description
•