-
-
Notifications
You must be signed in to change notification settings - Fork 411
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
Fix global objects attributes #624
Conversation
1. Rename insert_property to insert. 2. Remove insert_field. 3. Add new insert method which takes Value, Attribute and inserts a property.
Codecov Report
@@ Coverage Diff @@
## master #624 +/- ##
==========================================
- Coverage 72.50% 72.24% -0.26%
==========================================
Files 179 179
Lines 13376 13411 +35
==========================================
- Hits 9698 9689 -9
- Misses 3678 3722 +44
Continue to review full report at Codecov.
|
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 looks ready to merge, just needs a rebase :)
Are there any tests demonstrating the new behaviour? |
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 looks almost ready :) Check my comments on how to improve it
Also as @Lan2u said having some test to prove that it the object attributes are set would be nice, something like:
Infinity = 3;
and asserting that Infinity did not change (this tests that its readonly), another test is to do:
delete Infinity;
And asserting its sill there (tests that it is permanent)
globalThis.propertyIsEnumerable("Infinity")
and asserting that it is false (tests that it is non_enumerable)
@@ -486,7 +486,8 @@ impl Value { | |||
let _timer = BoaProfiler::global().start_event("Value::update_property", "value"); | |||
|
|||
if let Some(ref mut object) = self.as_object_mut() { | |||
object.insert_property(field, new_property); | |||
// FIXME overwrite the property |
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.
Could you explain this comment? doesn't insert overwrite it?
pub(crate) fn insert<K>(&mut self, key: K, property: Property) | ||
where | ||
K: Into<PropertyKey>, | ||
{ | ||
match key.into() { | ||
PropertyKey::Index(index) => self.indexed_properties.insert(index, property), | ||
PropertyKey::Index(index) => { | ||
self.indexed_properties.insert(index, property); | ||
} | ||
PropertyKey::String(ref string) => { | ||
self.string_properties.insert(string.clone(), property) | ||
self.string_properties.insert(string.clone(), property); | ||
} | ||
PropertyKey::Symbol(ref symbol) => { | ||
self.symbol_properties.insert(symbol.clone(), property) | ||
self.symbol_properties.insert(symbol.clone(), property); | ||
} | ||
} | ||
} |
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.
it would be better if .insert
returned an Option<Property>
pub(crate) fn insert_property<K, V>( | ||
&mut self, | ||
key: K, | ||
value: V, | ||
attribute: Attribute, | ||
) -> Option<Property> | ||
where | ||
K: Into<PropertyKey>, | ||
V: Into<Value>, | ||
{ | ||
self.insert_property( | ||
key.into(), | ||
Property::data_descriptor( | ||
value, | ||
Attribute::WRITABLE | Attribute::ENUMERABLE | Attribute::CONFIGURABLE, | ||
), | ||
) | ||
let property = Property::data_descriptor(value.into(), attribute); | ||
match key.into() { | ||
PropertyKey::Index(index) => self.indexed_properties.insert(index, property), | ||
PropertyKey::String(ref string) => { | ||
self.string_properties.insert(string.clone(), property) | ||
} | ||
PropertyKey::Symbol(ref symbol) => { | ||
self.symbol_properties.insert(symbol.clone(), property) | ||
} | ||
} | ||
} |
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 insert retruns an Option<Property>
we could do:
let property = Property::data_descriptor(value.into(), attribute);
self.insert(key.into(), property)
This would eliminate some code duplication.
Closing this in favor of #722 |
This Pull Request fixes/closes #606 .
It changes the following: