-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add algorithm for console table #237
base: main
Are you sure you want to change the base?
Add algorithm for console table #237
Conversation
Does the algorithm match Chrome or Firefox, or neither? cc @nchevobbe |
1f2faf9
to
dc65c23
Compare
dc65c23
to
a0adbc4
Compare
@zcorpan It matches both Chromium and Firefox. I did not see any difference between them for the cases that I tested. |
There's one difference I'm aware of (see https://bugzilla.mozilla.org/show_bug.cgi?id=1744441) With var client=[];
client["a"]=[1];
client["b"]=[2];
console.table(client); Firefox and Safari don't print a table, Chrome and Node do.
and https://infra.spec.whatwg.org/#lists :
https://infra.spec.whatwg.org/#the-exclusive-range
I guess non integer indices shouldn't be included, which is what Safari and Firefox are doing |
I did not check the use case of setting non integer indices to an array. Personally, my preference is that arrays only handle integer indices which is aligned with what Safari and Firefox (and LadyBird once my PR is ready to be merged :D) are doing. But it is just a personal preference and I do not have a strong opinion either way. Let me know how you want to proceed with this. |
This is now live in Ladybird (LadybirdBrowser/ladybird#1027) if anyone wants to experiment with it. |
@bmeurer can this be changed in Chromium/V8? See #237 (comment) above. |
We can definitely update Chromium accordingly, but I wonder if that wouldn't be considered a regression. Being able to print objects (with non-indexed properties) as tables could be useful for some users. Is there some data that we can base the decision to stick to just indexed properties on? |
I think the idea is that a JS object (that is not an array) would still work (step 4). Hmm, the spec algorithm here operates on Infra value types (list vs map), but the IDL type for JS arrays and JS objects are both "object" if I understand https://webidl.spec.whatwg.org/#js-any correctly. ( https://webidl.spec.whatwg.org/#js-union can map to an IDL sequence, step 11.1.) I'm not sure what the JS - IDL - Infra mapping is for an IDL |
@zcorpan I am new to writing a spec and this is something I was not aware of. Just want to understand this for this use-case and as a future reference as well:
|
The spec written here is not clear enough one way or another. tabularData is specified as You need to either:
The former would be better but I'm unsure how compatible it is with current implementations. |
Ah, I misread the example. If it's only about excluding non-indexed properties for arrays (or array-like objects), we can definitely do that in Chromium. |
@domenic I think the second option is closer to what browsers do today. Gecko uses let o = {}; Object.defineProperty(o, "x", { get() { throw "y" } }); console.table(o); |
Define algorithm for
console.table
tabularData
andproperties
argumentsDescription
I have tried to figure out and define the algorithm for
console.table
based on how Chromium and Firefox do it. This is my first PR; so, please let me know of any concerns and comments.Checklist
(See WHATWG Working Mode: Changes for more details.)
Preview | Diff