-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
LibJS+WebContent: Implement console.table #1027
LibJS+WebContent: Implement console.table #1027
Conversation
783ef6c
to
986a904
Compare
b74a281
to
d1dc9b3
Compare
Commit should be titled |
d1dc9b3
to
1ef95a8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing this! A couple of general comments besides the CSS ones:
I saw you made a PR to the console spec, that's great! Can you please include the spec steps you added as comments in this code? Put a note that links to the PR and says it's not yet in the actual spec. That'll make it easier to follow what's going on. (And help to verify that your algorithm works as intended.)
Also, the way the properties
parameter works doesn't match what I see in Firefox or Chrome:
(Ladybird on left, Firefox on right. Chrome output was the same as Firefox.)
Hello! One or more of the commit messages in this PR do not match the Ladybird code submission policy, please check the |
75ef864
to
47b8da7
Compare
@AtkinsSJ You are passing two different values between browsers: On the left screenshot, the first argument is an object while on the right screenshot, the first argument is an array that contains an object (highlighted them with orange marker): |
Ah whoops! I'm glad it's me and not your code. 😆 |
OK, I think I wasn't clear with what I meant. If you look at the other console methods, our code has the steps from the spec quoted exactly, then the code that implements them. For example, our // 1. Let map be the associated count map.
auto& map = m_counters;
// 2. If map[label] exists, set map[label] to map[label] + 1.
if (auto found = map.find(label); found != map.end()) {
map.set(label, found->value + 1);
}
// 3. Otherwise, set map[label] to 1.
else {
map.set(label, 1);
}
// ... We like doing this for a few reasons: It makes it clear that the code matches the spec; it's easier to spot errors; and if the spec changes in the future, it's easier to see what needs changing. (I think someone was working on an automated way to check this, at some point...) As an added bonus it helps us spot any problems in the spec itself. If you could do the same with your draft spec's steps, with a note at the top to say it's based on changes that aren't in the official spec yet, that would be good. Also, your commit title still says "JSLib" when it should say "LibJS". 😅 |
Makes sense. I'll add the steps in the code 😊
I'll fix that too. I thought this was about the PR title, not commit message title :D |
8e921a1
to
7662c94
Compare
@AtkinsSJ I fixed the commit message and also added steps of the algorithm, and also added "WIP" next to the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, it's a lot easier to examine the code when it's right next to the spec algorithm. (Even if it's a WIP algorithm.)
Someone else who's more familiar with LibJS will need to give this a look too, but overall this looks fine, just a few small things.
7662c94
to
42b4f48
Compare
- Expose table from console object - Add new Table log level - Create a JS object that represents table rows and columns - Print table as HTML using WebContentConsoleClient
42b4f48
to
fe399ee
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! I'm happy to merge this now, and if we do find any issues we can fix them later. Hopefully this will help demonstrate that the algorithm you wrote is correct, too. :^)
Oh, and in future, whenever you've pushed changes that resolve a review comment, click the [Resolve conversation]
button. That makes it clear to maintainers that it's ready for another review or merge.
Description
Implement
console.table
similar to how it is handled in other browsers. In this case, the Console creates a data structure and passed that structure to the Printer. In the printer side, unlike in other browsers, I decided to allow expanding arrays and objects in the table instead of just saying that the element is an array or object:Algorithm
Below is the detailed explanation of the algorithm:
There are two parts to this algorithm -- First one is about choosing the column that represents indices and the second one is assigning properties to columns.
Setting the index column:
The index column's name is represented as "(index)" (parentheses are part of the column name).
tabularData
) is a array, we iterate over the array and assign it to "(index)" column.Example:
outputs
If the first argument is an object, we iterate over all the enumerable keys and assign the key to the "(index)" column.
Example:
outputs
Assigning properties to columns:
As we iterate over each item of the object/array, we check the type of each item (array element or object property):
If the item is an array, iterate over the array, create a column that's named as the array element index and assign the value at the index to the column value.
Example:
outputs
If the item is an object, enumerate over the object propreties, create a column that's named as the property key and assign the value at the key to the the property value.
Example:
outputs
If item is neither array, nor object, assign the object to column named "Value".
Example:
outputs
When the second argument (let's call it
properties
) is passed, we show "(index)", "Value", the the columns defined in properties.Example:
outputs
Considerations:
The creation of columns based on the item type is only done one level. If there is an array or object after first level, we just print it without creating new columns.
Example:
Outputs:
The order of elements can affect the order the columns, including the "Value" column, because columns are populated as we iterate over rows.
Example:
outputs
while
outputs
"(index)" is always the first column
"(index)" and "Value" columns are NOT affected by the
properties
argumentSpec Steps
Spec PR: whatwg/console#237 (still in progress)
Changes