-
-
Notifications
You must be signed in to change notification settings - Fork 402
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
Implement Display for Objects #171
Implement Display for Objects #171
Conversation
This may be out of scope for your PR, but be weary of circular references. Or at least it did when I was playing with it. |
This implementation indeed does not take circular dependencies into consideration. I believe I have an idea how that can be achieved, so I will take some more time to look into it and deliver everything in one PR. |
@jasonwilliams could you take a look? |
I decided to not filter out the prototype slot, as I still have not found a scenario which causes a stack overflow. |
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.
Looks good
Do we want to somehow share this logic with |
We definitely could do that, only we need to find a way to escape code duplication for printing properties. |
@IovoslavIovchev Not sure if you're aware but the newlines aren't being parsed
|
@jasonwilliams As I have mentioned in the PR description, this is because of the If you used |
@IovoslavIovchev oh my bad. |
Looks great 😁 Do we want to make it clear the difference between properties and slots? |
Well, that really depends. In my opinion we should not, as bin.rs is used for debugging purposes anyway, and it is better to see that the output is what you actually expect. The downside obviously is that when it wraps (the way it does in your case) it gets really hard to read. |
Additionally, one slight mistake I made was I joined the properties and slots before printing and that resulted in
as you can see there is no comma after However, I have fixed it now. You can review the latest change. |
Sure, you also have a conflict |
No worries, was just curious |
…boa into feature/object-printing
You need any help with this? |
I hit a wall with |
// let mut engine = Executor::new(realm); | ||
// let init = r#" | ||
// var empty = new Array(); | ||
// var one = new Array(1); |
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.
Currently, new Array(1)
produces [1]
(an array with one element, which is 1
), when, in fact, it should produce an array with length
1 and an empty slot.
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.
We will pick this up in jasonwilliams#209
@jasonwilliams could you take a look again? |
src/lib/builtins/array.rs
Outdated
let callback = &args[0]; | ||
let this_arg = if args.len() > 1 { | ||
args[1].clone() | ||
} else { |
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.
Looks like Array.prototype.length
shouldn't have a getter according to the spec
src/lib/builtins/string.rs
Outdated
@@ -741,7 +741,9 @@ pub fn create_constructor(global: &Value) -> Value { | |||
|
|||
// Create prototype | |||
let proto = ValueData::new_obj(Some(global)); | |||
let prop = Property::default().get(to_value(get_string_length as NativeFunctionData)); | |||
let prop = Property::default() | |||
.get(to_value(get_string_length as NativeFunctionData)) |
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.
String.prototype.length
does not have a getter according to the spec https://tc39.es/ecma262/#sec-properties-of-the-string-prototype-object
NB: Due to the fact that the main binary uses the
dbg!
macro, pretty printing, while present, does not the make output, well.. pretty (e.g. new lines are rendered as\n
).