WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED DUPLICATE of
bug 35801
49501
console.log(document.getElementsByTagName(..)) outputs wrong value when DOM is later modified
https://bugs.webkit.org/show_bug.cgi?id=49501
Summary
console.log(document.getElementsByTagName(..)) outputs wrong value when DOM i...
Evan Martin
Reported
2010-11-13 15:38:25 PST
See attached test case. Basically, getElementsByTagName() returns a value like you've already executed the code that *follows* it. If you remove the later code, the earlier code behaves as expected. Google Chrome 9.0.576.0 (Official Build 65344) dev WebKit 534.12 V8 2.5.4 Works in Firefox 3.6.12.
Attachments
html file showing problem
(487 bytes, text/html)
2010-11-13 15:38 PST
,
Evan Martin
no flags
Details
better demo
(585 bytes, text/html)
2010-11-13 15:49 PST
,
Evan Martin
no flags
Details
View All
Add attachment
proposed patch, testcase, etc.
Evan Martin
Comment 1
2010-11-13 15:38:48 PST
Created
attachment 73834
[details]
html file showing problem
Evan Martin
Comment 2
2010-11-13 15:39:35 PST
(Note that this only dumps to the JS console, so you need Firebug installed on Firefox to test it.)
Evan Martin
Comment 3
2010-11-13 15:49:00 PST
Created
attachment 73836
[details]
better demo Here's a better example, where we flip a coin to decide whether to remove the node or not. Load this, bring up the console, repeatedly hit f5 and boggle at the first line of output changing. I guess something is printing the actual value of getElementsByTagName too late -- we always seem to successfully get the first node, whether or not the console.log thinks it exists.
Adam Barth
Comment 4
2010-11-13 16:10:58 PST
I think getElementsByTagName is returning a live node list. You're then modifying the node list. The question is when we read the value of the node list to print. With the inspector using an async API, I can see why this might occur after later than you expect.
Sam Weinig
Comment 5
2010-11-14 11:57:37 PST
This seems like an inspector bug and not a DOM bug. If you log document.getElementsByTagName('ul').length instead of just document.getElementsByTagName('ul'), you will see that the first log has two elements and the second log as one element. Changing component to Web Inspector.
Evan Martin
Comment 6
2010-11-15 10:35:52 PST
With another day's perspective on my code. console.log(document.getElementsByTagName('ul')); => prints the list with only the second one var x = document.getElementsByTagName('ul')[0]; => x successfully is the first (missing) item. So it's clear that document.getElementsByTagName is returning the right thing, and it's just the console.log that is confusing. I'll retitle the bug to something less mysterious.
Paul Irish
Comment 7
2012-08-02 07:47:01 PDT
A bit later, but thanks for the great repro Evan. (and folks for the help) Duping here. Also downstream ticket is at
http://crbug.com/50316
*** This bug has been marked as a duplicate of
bug 35801
***
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug