Open Bug 1327726 Opened 8 years ago Updated 2 years ago

Errors in console refer to modified arrays instead of original ones

Categories

(DevTools :: Console, defect, P4)

defect

Tracking

(Not tracked)

People

(Reporter: arni2033, Unassigned)

Details

>>>   My Info:   Win7_64, Nightly 49, 32bit, ID 20160526082509
1. Execute in console one of the following expressions w/o quotes
  "[1,2,3].shift().shift()"     or
  "[1,2,3].pop().pop()"         or
  "[1,2,3].push(4).push(5)"     


AR:  Console says
  TypeError: [2, 3].shift(...).shift is not a function
  TypeError: [1, 2].pop(...).pop is not a function
  TypeError: [1, 2, 3, 4].push(...).push is not a function

ER:  Either X or Y or Z
 X) Console should say (note that there're no whitespaces between 1,2,3 in the errors I expect to see)
  TypeError: [1,2,3].shift(...).shift is not a function
  TypeError: [1,2,3].pop(...).pop is not a function
  TypeError: [1,2,3].push(...).push is not a function
 Y) Console should say
  TypeError: [...].shift(...).shift is not a function
  TypeError: [...].pop(...).pop is not a function
  TypeError: [...].push(...).push is not a function
 Z) At developers' choice (probably wontfix, I don't know what's best here)
No longer blocks: 1277113
Component: Untriaged → Developer Tools: Console
Product: Firefox → DevTools
Priority: -- → P4

This is actually more serious than it is treated currently.

If one uses console.error() for checking e.g. the content of an array before and after some given operation (that is paramount in order to get a trace so that one may put a breakpoint up the stack somewhere), later, when expanding the collapsed values, both logged instances are the same.

I think it is due to the error not creating a copy of the object and instead using the live instance to be printed.
I checked however and neither console.log() nor console.warn() has the same problem (i.e. they both use a copy presumably); it is only console.error() that produces this issue.

I suspect there is some obscure reason behind the same logic not being used for errors; could anyone please shed some light on it?

Hello Victor,

I'm not sure your comment is related to this issue.
This bug is about exceptions not representing the array correctly.

But it's not about using console.error.
Also, console.error shouldn't act differently as console.log or console.warn, so if you have a reduced test case I could check, that would be great

Flags: needinfo?(vcsiky)

It most likely is, as I suggest the inbuilt error/exception reporting uses the same means to log stuff to console, regardless of it is a "TypeError" or a "user error" logged with console.error() (even from an exception handler). I may be wrong here, though.

As for the test, please use the one-liner:

var asd = asd || []; asd = [ "one", "two", "three", "four", "five" ]; console.error(asd); asd[2] = "nought"; asd[4] = "nought"; console.error(asd);

At face value, it appears that it is OK; but when you _expand the collapsed view (with the second chevron/whatnot, the first being for the stack trace), both values show "nought" at indices 2 and 4.

Also, console.error shouldn't act differently asconsole.log or console.warn

I beg your pardon; you are quite right on this one.
It seems that I have mixed up; I added cloning into my debugging code, and only then swapped out error for warn and then log, and as such, surely enough, they worked.

So yes, all three console logging facilities have this issue; even so, I am still insisting on fixing this would also fix the original issue here.

Flags: needinfo?(vcsiky)

So yes, this is a different issue, which is covered in Bug 1505304. (for what it's worth, other devtools suffer from similar issue, but they make it clearer that when expanding, it retrieve data from the "live" object, not a copied version)

Thanks, I subscribed to that one as well.

Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.