-
-
Notifications
You must be signed in to change notification settings - Fork 414
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
Setting array length does not delete elements. #557
Comments
Hey I'm new to this codebase and decided to take a look at this. Please correct me if I'm wrong. Object properties are separate from ObjectData and the function responsible for setting properties directly mutates the dictionary (properties field of struct Object) regardless of ObjectData. I think here's where the problem lies. We might need more information while setting properties or perhaps delegate this action to the data (ObjectData) field of struct Object. This would require perhaps a new trait which constraits objects (array, etc.) to have get/set properties (among others). The default impl of the set property could be the one that exists here. For special cases, this can be overridden. Could you highlight the problems with this? Thanks. |
Hi @54k1
This is a problem with Internal Object Methods , they currently are only set for ordinary objects, but not for array, string etc. Every object in the spec gets these internal methods an example is
We are trying to solve an inheritance problem, rust does not have a way to describe a base class where we have base class (with the the properties) and all the object ( I was going to do this after #577 which is another architectural problem that needs to be fixed, before the internal object methods. A hacky way of fixing this would be to check in |
@HalidOdat I was wondering how you were going to go about overriding internal object methods for exotic objects in general, since at the moment doing something like There might already be a solution offered in the codebase somewhere that I missed, so please let me know. Perhaps a new issue should be made for the handling of exotic objects. |
This is how I intended to do it, we have the internal method for example impl Object {
fn ordinary_set(&self /* , ... other parameters */) -> bool {
// implementation
}
fn set(&mut self /* , ... other parameters */ ) -> bool {
match self.data {
ObjectData::Array => {
// Arrays [[set]]
}
ObjectData::String(string) => {
// Strings [[set]]
}
// This is for ordinay objects and for objects
// that don't define a special implementation of [[set]]
_ => self.ordinary_set(/* , ... args*/)
}
}
} This way of implementing allows the compiler to do some optimization that can't be done in dynamic dispatch. If you have a better solution, or a way to improve it feel free to say so :)
I was going to create it after #577 |
@benjaminflin. I created the issue we can discuss it there #591. |
This issue has been fixed in #1042. |
Describe the bug
According to the spec, shortening
array.length
should delete elements in the array. Currently, array elements that are accessed beyond the array length are not necessarilyundefined
.To Reproduce
Expected behavior
arr[4]
should beundefined
but instead is5
.Build environment
Found in #555
The text was updated successfully, but these errors were encountered: