Browse Source

Make `Object.getOwnPropertyDescriptors` spec compliant (#1876)

It changes the following:
- Fix `Object.getOwnPropertyDescriptors()` to comply to spec
pull/1877/head
Halid Odat 3 years ago
parent
commit
73bcd42640
  1. 36
      boa_engine/src/builtins/object/mod.rs

36
boa_engine/src/builtins/object/mod.rs

@ -198,28 +198,34 @@ impl Object {
args: &[JsValue], args: &[JsValue],
context: &mut Context, context: &mut Context,
) -> JsResult<JsValue> { ) -> JsResult<JsValue> {
let object = args.get_or_undefined(0).to_object(context)?; // 1. Let obj be ? ToObject(O).
let obj = args.get_or_undefined(0).to_object(context)?;
// 2. Let ownKeys be ? obj.[[OwnPropertyKeys]]().
let own_keys = obj.__own_property_keys__(context)?;
// 3. Let descriptors be OrdinaryObjectCreate(%Object.prototype%).
let descriptors = context.construct_object(); let descriptors = context.construct_object();
for key in object.borrow().properties().keys() { // 4. For each element key of ownKeys, do
let descriptor = { for key in own_keys {
let desc = object.__get_own_property__(&key, context)?; // a. Let desc be ? obj.[[GetOwnProperty]](key).
Self::from_property_descriptor(desc, context) let desc = obj.__get_own_property__(&key, context)?;
};
// b. Let descriptor be FromPropertyDescriptor(desc).
let descriptor = Self::from_property_descriptor(desc, context);
// c. If descriptor is not undefined,
// perform ! CreateDataPropertyOrThrow(descriptors, key, descriptor).
if !descriptor.is_undefined() { if !descriptor.is_undefined() {
descriptors.borrow_mut().insert( descriptors
key, .create_data_property_or_throw(key, descriptor, context)
PropertyDescriptor::builder() .expect("should not fail according to spec");
.value(descriptor)
.writable(true)
.enumerable(true)
.configurable(true),
);
} }
} }
Ok(JsValue::Object(descriptors)) // 5. Return descriptors.
Ok(descriptors.into())
} }
/// The abstract operation `FromPropertyDescriptor`. /// The abstract operation `FromPropertyDescriptor`.

Loading…
Cancel
Save