Closed
Bug 1066996
Opened 10 years ago
Closed 10 years ago
Console logs incorrect values
Categories
(DevTools :: Console, defect)
DevTools
Console
Tracking
(Not tracked)
RESOLVED
DUPLICATE
of bug 754861
People
(Reporter: vporof, Unassigned)
Details
STR:
Evaluate the following in the web console (in a single line):
var x = [42]; console.log(x); x[0] = 43;
Expected output: Array [42]
Actual output: Array [43];
This is terrifying and very, very (very!) misleading.
Suppose you have some code that looks like this:
function test(obj) {
console.log(obj);
...lots of code...
...lots of code...
...lots of code...
...i can't even see the function name at this point...
...more code...
obj.foo = 43;
...even more code...
}
test({ foo: 42 });
Obviously, you'd expect your console.log call to print Object { foo: 42 }. However, even if the property is modified later (and as someone who might take a look at the code for the first time, and you don't even know that the modification is happening, especially if it's buried in the code), the output is going to be Object { foo: 43 }.
This is all sorts of wrong.
Chrome does the right thing and prints the object just like it receives it.
Comment 1•10 years ago
|
||
I doubt this is related, but when large objects are printed Firefox and Chrome show an interactive view and the same thing happens. That makes total sense though. Otherwise we'd have to deep copy the object...
var arr = [];
for(var i=0; i<1000; i++) { arr.push(i); }
console.log(arr)
arr[0] = 1000;
If you wait to expand the interactive view until after you change the value, it shows the updated value. Again that makes sense; the summarized string representation should always show the current snapshot like you want.
Comment 2•10 years ago
|
||
My last sentence is confusing. I meant to say the interactive view behavior makes sense, *however* the summmarized string repr should always show the current snapshot.
Reporter | ||
Comment 3•10 years ago
|
||
(In reply to James Long (:jlongster) from comment #2)
> My last sentence is confusing. I meant to say the interactive view behavior
> makes sense, *however* the summmarized string repr should always show the
> current snapshot.
I think this approach is the best compromise.
This should be made clear in the UI though, somehow. Making it obvious that the interactive inspection shows the live value would prevent any (potential) additional confusion.
Comment 4•10 years ago
|
||
I think this bug is a dupe of bug 754861
Comment 5•10 years ago
|
||
It is indeed.
Status: NEW → RESOLVED
Closed: 10 years ago
Resolution: --- → DUPLICATE
Updated•6 years ago
|
Product: Firefox → DevTools
You need to log in
before you can comment on or make changes to this bug.
Description
•