Skip to content
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

Closed
wants to merge 6 commits into from
Closed

Fix global objects attributes #624

wants to merge 6 commits into from

Conversation

54k1
Copy link
Contributor

@54k1 54k1 commented Aug 11, 2020

This Pull Request fixes/closes #606 .

It changes the following:

  1. Rename insert_property to insert.
  2. Remove insert_field.
  3. Add new insert method which takes Value, Attribute and inserts a property.

1. Rename insert_property to insert.
2. Remove insert_field.
3. Add new insert method which takes Value, Attribute and inserts a property.
@codecov
Copy link

codecov bot commented Aug 11, 2020

Codecov Report

Merging #624 into master will decrease coverage by 0.25%.
The diff coverage is 70.18%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
boa/src/builtins/array/mod.rs 76.13% <50.00%> (-0.32%) ⬇️
boa/src/builtins/bigint/mod.rs 67.74% <50.00%> (-2.26%) ⬇️
boa/src/builtins/boolean/mod.rs 34.37% <50.00%> (-2.30%) ⬇️
boa/src/builtins/console/mod.rs 29.05% <50.00%> (-0.33%) ⬇️
boa/src/builtins/date/mod.rs 56.13% <50.00%> (-0.22%) ⬇️
boa/src/builtins/error/mod.rs 29.62% <50.00%> (-2.38%) ⬇️
boa/src/builtins/error/range.rs 70.83% <50.00%> (-6.44%) ⬇️
boa/src/builtins/error/reference.rs 70.83% <50.00%> (-6.44%) ⬇️
boa/src/builtins/error/syntax.rs 33.33% <50.00%> (-3.04%) ⬇️
boa/src/builtins/error/type.rs 70.83% <50.00%> (-6.44%) ⬇️
... and 17 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 14d7791...df2dd48. Read the comment docs.

boa/src/builtins/function/mod.rs Outdated Show resolved Hide resolved
boa/src/builtins/function/mod.rs Outdated Show resolved Hide resolved
boa/src/builtins/math/mod.rs Show resolved Hide resolved
boa/src/builtins/object/internal_methods.rs Outdated Show resolved Hide resolved
boa/src/builtins/object/internal_methods.rs Outdated Show resolved Hide resolved
@54k1 54k1 marked this pull request as ready for review August 11, 2020 15:12
boa/src/builtins/mod.rs Outdated Show resolved Hide resolved
@HalidOdat HalidOdat added bug Something isn't working builtins PRs and Issues related to builtins/intrinsics execution Issues or PRs related to code execution labels Aug 16, 2020
@HalidOdat HalidOdat added this to the v0.10.0 milestone Aug 16, 2020
boa/src/builtins/array/mod.rs Outdated Show resolved Hide resolved
boa/src/builtins/nan/mod.rs Outdated Show resolved Hide resolved
boa/src/builtins/infinity/mod.rs Outdated Show resolved Hide resolved
Copy link
Member

@HalidOdat HalidOdat left a 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 :)

@54k1 54k1 requested a review from HalidOdat August 22, 2020 06:35
@Lan2u
Copy link

Lan2u commented Aug 22, 2020

Are there any tests demonstrating the new behaviour?

@HalidOdat HalidOdat changed the title Alter property insert API Fix global objects attributes Aug 28, 2020
Copy link
Member

@HalidOdat HalidOdat left a 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
Copy link
Member

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?

Comment on lines +339 to 354
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);
}
}
}
Copy link
Member

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>

Comment on lines +371 to 391
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)
}
}
}
Copy link
Member

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.

@jasonwilliams jasonwilliams modified the milestones: v0.10.0, v0.11.0 Sep 28, 2020
@HalidOdat
Copy link
Member

Closing this in favor of #722

@HalidOdat HalidOdat closed this Oct 1, 2020
@HalidOdat HalidOdat removed this from the v0.11.0 milestone Oct 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working builtins PRs and Issues related to builtins/intrinsics execution Issues or PRs related to code execution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Altering vital properties of builtins
4 participants