Bug 35801

Summary: Web Inspector: generate preview for the objects dumped into the console upon logging.
Product: WebKit Reporter: mitch kramer <boards>
Component: Web Inspector (Deprecated)Assignee: Pavel Feldman <pfeldman>
Status: RESOLVED FIXED    
Severity: Normal CC: andre, ap, boards, dbrans, evan, iamrohitbanga, mathias, nschubach, paulirish, pfeldman, rc, webkit.review.bot, webkit
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Mac   
OS: OS X 10.6   
Bug Depends on: 93505, 93511, 93512    
Bug Blocks:    
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch
vsevik: review+, buildbot: commit-queue-
Assertion backtrace
none
Screenshot showing that the length of an array is inconsistent. none

mitch kramer
Reported 2010-03-05 11:37:45 PST
1) create an object literal with one or more properties 2) console.log that object but leave it closed (don't expand it in the console) 3) change one of the properties to a new value now open that console.log and you'll see it has the new value for some reason, even though it's value was different at the time it was generated.
Attachments
Patch (75.96 KB, patch)
2012-08-07 08:46 PDT, Pavel Feldman
no flags
Patch (64.50 KB, patch)
2012-08-08 06:40 PDT, Pavel Feldman
no flags
Patch (64.60 KB, patch)
2012-08-08 06:55 PDT, Pavel Feldman
no flags
Patch (64.46 KB, patch)
2012-08-08 08:37 PDT, Pavel Feldman
vsevik: review+
buildbot: commit-queue-
Assertion backtrace (2.20 KB, text/plain)
2012-08-08 11:49 PDT, Thiago Marcos P. Santos
no flags
Screenshot showing that the length of an array is inconsistent. (12.98 KB, image/png)
2012-12-01 13:36 PST, Rohit Banga
no flags
mitch kramer
Comment 1 2010-03-05 11:50:19 PST
I should point out that if you open it, it will retain the correct value if that wasn't clear.
Pavel Feldman
Comment 2 2010-03-09 06:33:36 PST
I don't think we are ever going to fix this one. We can't clone object upon dumping it into the console and we also can't listen to the object properties' changes in order to make it always actual. We should make sure existing behavior is expected though.
mitch kramer
Comment 3 2010-03-17 07:22:20 PDT
If i'm "logging it" It would seem that i would be taking a snapshot of it at that time... It seems broken to me to not have it be historical -- but if you can't do it, i guess you can't do it... just seems like it might be FAR more useful if it worked as I expected it to.
mitch kramer
Comment 4 2010-03-18 13:48:24 PDT
Thinking about this further, it's odd that the behavior is different depending on whether or not you've expanded it or not... perhaps the fix is to have it expanded by default, since that keeps the correct data then. Chances are pretty good you're going to want to see that data anyway since you're console.logging it. Or maybe just perform those same operations in the background and not update the UI...
Pavel Feldman
Comment 5 2010-03-18 13:55:51 PDT
(In reply to comment #4) > Thinking about this further, it's odd that the behavior is different depending > on whether or not you've expanded it or not... perhaps the fix is to have it > expanded by default, since that keeps the correct data then. Chances are pretty > good you're going to want to see that data anyway since you're console.logging > it. Or maybe just perform those same operations in the background and not > update the UI... What if the inspected value is on the second level? In either case, for debugging purposes one can always use toString or JSON.stringify.
mitch kramer
Comment 6 2010-03-19 14:01:41 PDT
(In reply to comment #5) > What if the inspected value is on the second level? In either case, for > debugging purposes one can always use toString or JSON.stringify. That's fair enough, this behavior in general still feels wrong to me though. But if I stand alone in that, well, then, I guess I stand alone.
André Hänsel
Comment 7 2011-05-28 19:27:19 PDT
(In reply to comment #2) > I don't think we are ever going to fix this one. We can't clone object upon dumping it into the console and we also can't listen to the object properties' changes in order to make it always actual. Why Firefox/Firebug can? What use does the functionality of dumping objects have other than seeing the object *in the state it was in when being logged*?
Quentin
Comment 8 2011-11-04 05:59:48 PDT
I agree with André. This can lead to very strange log behaviour when your are not aware of this problem, such as http://stackoverflow.com/questions/8007397/javascript-constructor-with-google-chrome-bugged
Nick S
Comment 9 2012-02-10 13:05:00 PST
Here is another example of unexpected output for console.log() http://jsfiddle.net/MeuXt/2/ You can see that toString() makes it output the correct value, but if you were to run that code without the toString(), you'd think that the array was somehow magically updated before the code was run on it.
Timothy Hatcher
Comment 10 2012-03-19 06:49:02 PDT
*** Bug 75561 has been marked as a duplicate of this bug. ***
Rohit Banga
Comment 11 2012-07-27 04:09:33 PDT
I saw a problem today which I suspect is related to this bug. eventHandler1: function(arr) { this.mainArr.push(arr); console.log(this.mainArr); // prints correct array } eventHandler2: function() { console.log(this.mainArr); // prints [undefined x 1] ... WAT!!! var arr = this.mainArr.pop(); // use and get rid of arr } eventHandler2 is invoked a few seconds after eventHandler1. Because of the pop() call the value of mainArr is printed as [undefined x 1] in eventHandler2. If I just comment the call to pop() then the value is printed correctly. It seems console.log() is resolving the reference after it has been GC'ed. I also tried to invoke eventHandler2 immediately after eventHandler1 and managed to generate [undefined x 1] for both console.log() statements. So I would vaguely describe it as a race condition between GC and console renderer. PS: Its 4 in the morning and I am too lazy to write a jsfiddle.
Paul Irish
Comment 12 2012-07-30 06:48:40 PDT
Downstream ticket: http://crbug.com/50316
Paul Irish
Comment 13 2012-08-02 07:47:01 PDT
*** Bug 49501 has been marked as a duplicate of this bug. ***
Pavel Feldman
Comment 14 2012-08-07 08:46:07 PDT
Vsevolod Vlasov
Comment 15 2012-08-08 00:37:58 PDT
Comment on attachment 156949 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=156949&action=review > Source/WebCore/inspector/InjectedScriptSource.js:714 > + /** @param {!Object} object*/ nit: Please add new lines > Source/WebCore/inspector/front-end/ConsoleMessage.js:322 > + if (isArray && name === "length") Why not skip it when creating an abbreviation? > Source/WebCore/inspector/front-end/ConsoleMessage.js:327 > + extra line > Source/WebCore/inspector/front-end/ConsoleMessage.js:329 > + if (!isArray || name != i) { !== When is this needed? > Source/WebCore/inspector/front-end/ConsoleMessage.js:345 > + span.textContent = "\"" + value.replace(/\n/g, "\u21B5") + "\""; I think trimmed string should also cause isLosslessAbbreviation = false; > Source/WebCore/inspector/front-end/ConsoleView.js:725 > return; Please revert ConsoleView changes, as they were reviewed in another bug.
Pavel Feldman
Comment 16 2012-08-08 06:40:34 PDT
Andrey Kosyakov
Comment 17 2012-08-08 06:49:30 PDT
Comment on attachment 157204 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=157204&action=review > Source/WebCore/inspector/InjectedScriptSource.js:720 > + var previewPropertyCount = 0; where is this used?
Andrey Kosyakov
Comment 18 2012-08-08 06:54:14 PDT
Comment on attachment 157204 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=157204&action=review > Source/WebCore/inspector/front-end/ConsoleMessage.js:313 > + isLosslessPreview = false; indent > Source/WebCore/inspector/front-end/ConsoleMessage.js:344 > + if (type === "object") { > + var subtype = property[3]; > + if (subtype === "node") > + span.addStyleClass("console-formatted-preview-node"); > + span.textContent = value; > + } else if (type === "string") > + span.textContent = "\"" + value.replace(/\n/g, "\u21B5") + "\""; > + else if (type === "null" || type === "undefined") > + span.textContent = type; > + else > + span.textContent = String(value); switch (type)?
Pavel Feldman
Comment 19 2012-08-08 06:55:21 PDT
Build Bot
Comment 20 2012-08-08 07:25:13 PDT
Andrey Kosyakov
Comment 21 2012-08-08 07:55:06 PDT
Comment on attachment 157208 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=157208&action=review > Source/WebCore/inspector/InjectedScriptSource.js:775 > + if (!preview.length) > + return undefined; So what happens to empty arrays? > Source/WebCore/inspector/front-end/ConsoleMessage.js:340 > + } else if (type === "string") > + span.textContent = "\"" + value.replace(/\n/g, "\u21B5") + "\""; This would turn 'a"b' into "a"b" which would looks a bit weird. I think if we're adding outer quotes, we should escape string to make it parseable.
Pavel Feldman
Comment 22 2012-08-08 08:37:59 PDT
Vsevolod Vlasov
Comment 23 2012-08-08 09:10:40 PDT
Comment on attachment 157228 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=157228&action=review > Source/WebCore/inspector/InjectedScriptSource.js:641 > + return obj.nodeType === 1 /* Node.ELEMENT_NODE */ ? "<" + obj.nodeName.toLowerCase() + ">" : obj.nodeName.toLowerCase(); doctype? > Source/WebCore/inspector/InjectedScriptSource.js:734 > + overflow = true; Please add lossless = false > Source/WebCore/inspector/InjectedScriptSource.js:753 > + const maxLength = 20; 100? > LayoutTests/inspector/console/console-format-expected.txt:58 > +[/^url\(\s*(?:(?:"(?:â¦] console-format.html:55 So regexps preview is lossy, we should add a tree view for such an object > LayoutTests/inspector/console/console-format-expected.txt:77 > +<body onload="onload()"> console-format.html:54 This change looks somewhat unexpected for me. Did you intend to change the way elements are printed? > LayoutTests/inspector/console/console-format.html:17 > + array.foo = {}; Why did this change?
Vsevolod Vlasov
Comment 24 2012-08-08 09:11:17 PDT
Comment on attachment 157228 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=157228&action=review > LayoutTests/inspector/console/console-format-expected.txt:122 > +id="x""x" I don't understand what is going on here. :(
Build Bot
Comment 25 2012-08-08 09:12:02 PDT
Pavel Feldman
Comment 26 2012-08-08 10:22:44 PDT
Thiago Marcos P. Santos
Comment 27 2012-08-08 11:49:25 PDT
Created attachment 157264 [details] Assertion backtrace The EFL Debug bot is hitting this assertion after this patch.
Pavel Feldman
Comment 28 2012-08-08 12:04:35 PDT
I'll roll it out.
WebKit Review Bot
Comment 29 2012-08-08 12:13:44 PDT
Re-opened since this is blocked by 93505
Pavel Feldman
Comment 30 2012-08-09 10:51:38 PDT
Pieter Wigboldus
Comment 31 2012-09-05 07:54:56 PDT
Please check e.g. this in your console: var s = ["hi"]; console.log(s); s[0] = "bye"; console.log(s); it show 2 times bye. can be solved with console.log(s.toString()); or console.log(s.slice()); In Firebug it show values that you expect, Chrome/Webkit show 2 times the last value.
Pavel Feldman
Comment 32 2012-09-06 02:28:16 PDT
That's what this patch fixed.
Rohit Banga
Comment 33 2012-12-01 13:36:42 PST
Created attachment 177112 [details] Screenshot showing that the length of an array is inconsistent. I have an array called tabContent. I dump it to the console and its length. The length is now 1. The object dumped is not expanded initially. Then I add another element to the array. Again print the same array. Now when I expand both the first one shows the two elements inside when at the time of printing there was only one. Also the length, preview (unexpanded array) is inconsistent with what we see in the expanded view. I am using Chrome Version 24.0.1312.27 beta.
Note You need to log in before you can comment on or make changes to this bug.