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
Added basic console.table() implementation #29689
base: main
Are you sure you want to change the base?
Conversation
🛠 These changes could not be applied onto the latest upstream WPT. Servo's copy of the Web Platform Tests may be out of sync. |
9c4c279
to
92b34c3
Compare
92b34c3
to
ef35292
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.
Thank you for your contribution. This is a nice start. It needs a bit of work before it's ready to merge.
components/script/dom/console.rs
Outdated
tabular_data: HandleValue, | ||
properties: Option<Vec<DOMString>>, | ||
) { | ||
unsafe { |
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.
This unsafe
block is very wide. Try to move it down to exactly the problematic code and then let's see if we can eliminate it entirely.
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.
The problematic part is calling the generate_table() function, which is an unsafe function because it calls Vec::from_jsval() and is_array_like(). I'm not very experienced with the servo documentation, so there could be a way to implement generate_table() safely which I'm not aware of.
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.
At the very least here, I think you should reduce the unsafe block to enclose only the unsafe operations instead of marking the entire function as unsafe.
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.
Okay, sure! I've removed the unsafe block around generate_table() and just restricted the unsafe blocks to the unsafe operations inside the function.
components/script/dom/console.rs
Outdated
for row in table.iter() { | ||
for col in row.iter() { | ||
res.push_str(col as &str); | ||
res.push_str("\t\t"); |
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.
If we implement this, it deserves an implementation that knows how to properly align the columns of the table. Two tabs are pretty brittle, so maybe investigate if there is a more resilient way to do this based on the actual strings that we are processing.
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.
That's a good idea. I'll see if there's a good way to align the columns.
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.
I've implemented a simple way to align the columns by setting each column's width to be the maximum length of all of its rows, plus some extra space.
…ndling that supports inputting primitive arrays.
…rror handling that supports inputting primitive arrays.
components/script/dom/console.rs
Outdated
@@ -65,13 +73,76 @@ fn console_message(global: &GlobalScope, message: DOMString, level: LogLevel) { | |||
}) | |||
} | |||
|
|||
///Generates matrix of table elements, and then converts matrix into a properly formatted DOMString |
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.
When making a comment in rust you should put a space after the slashes. In this case, I don't think the rustdoc will work without the space.
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.
Oh ok sure! Thanks for the suggestion, I'm not really familiar with rustdoc so that really helps. I'll make sure to fix the comment.
Implemented a basic version of console.table() that supports arrays of primitives as input. The full functionality as described in the spec as mentioned in #27212 will also be implemented later.
./mach build -d
does not report any errors./mach test-tidy
does not report any errors