Chrome 69, bug in console.log when displaying same object multiple times

99 views
Skip to first unread message

Merouane Nadir

unread,
Sep 17, 2018, 1:14:58 PM9/17/18
to Chromium-dev
Hello,

I have writen a javascript function to push object into an array. In my loop I do a console.log(myArray); to display the content of the array at each loop.

The problem is that in the console the data lengh is correct but not the content of the data. When I click on the arrow to expend the array and see the values, it show me all the values from the finished loop at each iteration instead of the current array content in those loops. 

That's totally wrong and is not helpfull at all... 

Here is a copy/paste of what i see in the console:

  1. (17) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, __ob__: Ct]
    1. length: 21

As you can see, there should be 17 elements but it shows 20...  not logic at all ... 

Malay Keshav

unread,
Sep 17, 2018, 2:05:59 PM9/17/18
to nadirm...@gmail.com, chromium-dev
Hello,

I think this is working as expected. The console.log() does not create a copy of the object instead only points to the object. For it to work as you are expecting, it would have to create a copy of the array for each console.log, which is not efficient.
Try using console.log(myArray.toString()) instead.

--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/f44f53f3-835a-4aeb-9ac3-142e0aa0fc50%40chromium.org.

Merouane Nadir

unread,
Sep 17, 2018, 5:35:40 PM9/17/18
to malay...@chromium.org, chromi...@chromium.org
Not at all, as you can see in the log the content of the array is 17 when displaying the obejct, so the object is not "displayed by reference", but when clicking on the Arrow to expand the object in the console, the length changes to 21. This is a specific bug of Chrome 69 that does not exist in any other browser.  I have tested it live on Firefox, Chrome 69, Edge, Safari and Galeon. I cannot provide the URL to test it because it was on a admin interface for our customers. 

It is a simple array with a loop to push objects Inside the array with a console.log in the loop to show its content evolving. Very easy to reproduce. 

Malay Keshav

unread,
Sep 17, 2018, 5:47:09 PM9/17/18
to Merouane Nadir, chromium-dev
On Mon, Sep 17, 2018 at 2:34 PM Merouane Nadir <nadirm...@gmail.com> wrote:
Not at all, as you can see in the log the content of the array is 17 when displaying the obejct, so the object is not "displayed by reference", but when clicking on the Arrow to expand the object in the console, the length changes to 21.
I may be wrong, but if you are referring to the '17' at the beginning of the log statement, then that might just be a string generated by console.log() for the array at that point of time in execution. The object that you expand to see the contents is still displayed by reference.
 
This is a specific bug of Chrome 69 that does not exist in any other browser.  I have tested it live on Firefox, Chrome 69, Edge, Safari and Galeon. I cannot provide the URL to test it because it was on a admin interface for our customers. 
If you feel that this is a bug introduced in M69, and was working as expected in earlier versions, you should file bug at https://bugs.chromium.org/p/chromium/issues/entry Make sure to assign the right component for it. (Platform>DevTools>JavaScript)

Torne (Richard Coles)

unread,
Sep 17, 2018, 5:47:25 PM9/17/18
to nadirm...@gmail.com, malay...@chromium.org, chromi...@chromium.org
That is actually how it works. When you console.log something, the part that is actually displayed by default in devtools (e.g. the count, and the abbreviated contents) is rendered immediately and added to the console, *and* the actual object is saved as a reference in order to support expanding the object later. The expanded form is rendered lazily only when you actually click, so it's rendered based on the value of the object at that later point in time.

It would have to calculate the full expanded rendering in advance to do what you expect, or copy the object - both of these would be very expensive for an object that might be very deep and have many otehr things nested inside it.

Merouane Nadir

unread,
Sep 17, 2018, 6:12:10 PM9/17/18
to Malay Keshav, chromium-dev
Already reported it via chrome bug report. Also to go further when opening an item of the array and then any object of it every fields where replaced by dots. I had to click on each dots one by one to see the values... With an object of more than 50 fields... Very funny. I finally finished the debug in edge to not loose time and my mind. 

PhistucK

unread,
Sep 17, 2018, 6:34:30 PM9/17/18
to nadirm...@gmail.com, malay...@chromium.org, Chromium-dev
Three dots usually mean a field has a getter/setter and not a simple value.

PhistucK


To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAMmMKSri9tgEjKgC2cDjNVxa3P38gNL-2Zcaoe177r8Erm8XWA%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages