New issue
Advanced search Search tips

Issue 732021 link

Starred by 1 user

Issue metadata

Status: Fixed
Owner:
Closed: Jul 2017
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Mac
Pri: 3
Type: Feature



Sign in to add a comment

DevTools: new Array(len) should not log as (len) [undefined x len]

Reported by hux...@gmail.com, Jun 10 2017

Issue description

UserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36

Steps to reproduce the problem:
1. open DevTool > Console
2. evaluate "new Array(2)"

What is the expected behavior?
you should see "(2) [undefined × 2]"

What went wrong?
(2) [undefined × 2] is easily confused with (2) [undefined, undefined]. 

However, according to ECMAScript Spec, It's different. There are no real "undefined"s in arrays constructed from new Array(len). For example, hasOwnProperty(0) will return false and iteration functions like map() would behave differently. 

As a comparison,
Safari log "new Array(2)" as just "[] (2)";
Firefox log "new Array(2) as "Array [ <2 empty slots> ]"; (prefered)

Did this work before? N/A 

Chrome version: 58.0.3029.110  Channel: n/a
OS Version: OS X 10.11.6
Flash Version: Shockwave Flash 25.0 r0
 
Components: -Blink Blink>JavaScript
Owner: jgruber@chromium.org
Status: Assigned (was: Unconfirmed)
Cc: jgruber@chromium.org
Owner: l...@chromium.org
The formatting takes place in devtools, not v8. Reassigning to luoe@ per git blame, please feel free to reassign as appropriate.
Components: -Blink>JavaScript Platform>DevTools>JavaScript
Labels: -Type-Bug -Pri-2 Pri-3 Type-Feature

Comment 5 by l...@chromium.org, Jun 28 2017

Summary: DevTools: new Array(len) should not log as (len) [undefined x len] (was: new Array(len) should not log as (len) [undefined x len])
Thanks for the report.  We could align closer to Firefox's formatting in this case, as the two cases are different.
Project Member

Comment 6 by bugdroid1@chromium.org, Jul 13 2017

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/072313e39845ddbd3174acddc64686b8fa12ca15

commit 072313e39845ddbd3174acddc64686b8fa12ca15
Author: luoe <luoe@chromium.org>
Date: Thu Jul 13 00:12:20 2017

DevTools: use 'empty' for array holes

Console used to format holes in an Array very similarly to Array entries that
contained the value 'undefined'. The former showed up as 'undefined x n',
(e.g. `new Array(2)` or `[,,1]`) while the latter showed up as multiple
'undefined's (e.g. `[undefined, undefined]`). The two cases are functionally
different, since `0 in Array(1)` !== `0 in [undefined]`.

This CL reduces confusion by using 'empty x n' instead of 'undefined x n'
for holes in an Array.

BUG= 732021 

Review-Url: https://codereview.chromium.org/2977463002
Cr-Commit-Position: refs/heads/master@{#486173}

[modify] https://crrev.com/072313e39845ddbd3174acddc64686b8fa12ca15/third_party/WebKit/LayoutTests/inspector/console/console-format-array-prototype-expected.txt
[modify] https://crrev.com/072313e39845ddbd3174acddc64686b8fa12ca15/third_party/WebKit/LayoutTests/inspector/console/console-format-collections-expected.txt
[modify] https://crrev.com/072313e39845ddbd3174acddc64686b8fa12ca15/third_party/WebKit/LayoutTests/inspector/console/console-log-object-with-getter-expected.txt
[modify] https://crrev.com/072313e39845ddbd3174acddc64686b8fa12ca15/third_party/WebKit/LayoutTests/inspector/console/console-object-preview-expected.txt
[modify] https://crrev.com/072313e39845ddbd3174acddc64686b8fa12ca15/third_party/WebKit/LayoutTests/inspector/sources/debugger-ui/debugger-inline-values-expected.txt
[modify] https://crrev.com/072313e39845ddbd3174acddc64686b8fa12ca15/third_party/WebKit/Source/devtools/front_end/object_ui/RemoteObjectPreviewFormatter.js

Comment 7 by l...@chromium.org, Jul 13 2017

Status: Fixed (was: Assigned)

Sign in to add a comment