Skip to content

Commit

Permalink
Adjust EnumerableOwnPropertyNames to use all String type property…
Browse files Browse the repository at this point in the history
… keys (#1502)

* Adjust `EnumerableOwnPropertyNames` to use all `String` type property keys

* Change if-else to match

* Match on PropertyNameKind
  • Loading branch information
raskad authored Aug 24, 2021
1 parent 2712aaa commit 0f66054
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions boa/src/object/internal_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -902,35 +902,38 @@ impl GcObject {
// 4. For each element key of ownKeys, do
for key in own_keys {
// a. If Type(key) is String, then
if let PropertyKey::String(key_str) = &key {
let key_str = match &key {
PropertyKey::String(s) => Some(s.clone()),
PropertyKey::Index(i) => Some(i.to_string().into()),
_ => None,
};

if let Some(key_str) = key_str {
// i. Let desc be ? O.[[GetOwnProperty]](key).
let desc = self.__get_own_property__(&key);
// ii. If desc is not undefined and desc.[[Enumerable]] is true, then
if let Some(desc) = desc {
if desc.expect_enumerable() {
// 1. If kind is key, append key to properties.
if let PropertyNameKind::Key = kind {
properties.push(key_str.clone().into())
}
// 2. Else,
else {
match kind {
// 1. If kind is key, append key to properties.
PropertyNameKind::Key => properties.push(key_str.into()),
// 2. Else,
// a. Let value be ? Get(O, key).
let value = self.get(key.clone(), context)?;
// b. If kind is value, append value to properties.
if let PropertyNameKind::Value = kind {
properties.push(value)
PropertyNameKind::Value => {
properties.push(self.get(key.clone(), context)?)
}
// c. Else,
else {
// i. Assert: kind is key+value.
// ii. Let entry be ! CreateArrayFromList(« key, value »).
let key_val = key_str.clone().into();
let entry =
Array::create_array_from_list([key_val, value], context);

// iii. Append entry to properties.
properties.push(entry.into());
}
// i. Assert: kind is key+value.
// ii. Let entry be ! CreateArrayFromList(« key, value »).
// iii. Append entry to properties.
PropertyNameKind::KeyAndValue => properties.push(
Array::create_array_from_list(
[key_str.into(), self.get(key.clone(), context)?],
context,
)
.into(),
),
}
}
}
Expand Down

0 comments on commit 0f66054

Please sign in to comment.