Truly independent web browser
LibJS: Tell whether an object has internal slots of its own
Shannon Booth0b0b97af950a
diff --git a/Libraries/LibJS/Rust/src/runtime/map_prototype.rs b/Libraries/LibJS/Rust/src/runtime/map_prototype.rsindex fbf0c004b49..7f1e64d5f1d 100644--- a/Libraries/LibJS/Rust/src/runtime/map_prototype.rs+++ b/Libraries/LibJS/Rust/src/runtime/map_prototype.rs@@ -50,6 +50,8 @@ pub struct MapPrototype {define_object_class!(MapPrototype, extends: [Object], methods: {initialize: MapPrototype::initialize,+ // NB: The field of the prototype only caches its entries function.+ has_internal_slots: Some(false),..ORDINARY_OBJECT_METHODS});diff --git a/Libraries/LibJS/Rust/src/runtime/object.rs b/Libraries/LibJS/Rust/src/runtime/object.rsindex 71fa990f373..a8dd4a2b6c6 100644--- a/Libraries/LibJS/Rust/src/runtime/object.rs+++ b/Libraries/LibJS/Rust/src/runtime/object.rs@@ -277,6 +277,10 @@ pub struct ObjectMethods {pub as_builtin_iterator_if_next_is_not_redefined: fn(&Object, Value) -> Option<BuiltinIteratorNext>,/// The [[ErrorData]] internal slot, which Error objects have.pub error_data: fn(&Object) -> Option<&ErrorData>,+ /// Whether the objects of this class have internal slots other than [[Prototype]], [[Extensible]] and+ /// [[PrivateElements]], for a class whose fields do not tell: one whose fields only cache, or one with a slot that+ /// holds nothing. None leaves it to the fields, which Object::has_internal_slots() reads.+ pub has_internal_slots: Option<bool>,}/// [[GetPrototypeOf]].@@ -311,6 +315,7 @@ pub static ORDINARY_OBJECT_METHODS: ObjectMethods = ObjectMethods {eligible_for_own_property_enumeration_fast_path: |_| true,as_builtin_iterator_if_next_is_not_redefined: |_, _| None,error_data: error_data_of_error,+ has_internal_slots: None,};define_cell!(@@ -1009,6 +1014,15 @@ impl Object {self.internal_has_property(vm, property_key)}+ /// Whether this object has internal slots other than [[Prototype]], [[Extensible]] and [[PrivateElements]]. Its+ /// class keeps the internal slots of its objects in fields of its own, so a class the size of Object has none,+ /// unless its internal methods say otherwise, or its shape holds a [[ParameterMap]].+ pub fn has_internal_slots(&self) -> bool {+ self.methods().has_internal_slots.unwrap_or_else(|| {+ self.class().type_info.cell_size != Self::CLASS.type_info.cell_size || self.has_parameter_map()+ })+ }+/// Whether [[GetPrototypeOf]] and [[Get]] of this object are the ordinary ones, and [[GetOwnProperty]] is the/// ordinary one for properties named by symbols and by strings that are not array indices, so that its storage and/// its prototype alone decide what looking those properties up finds.diff --git a/Libraries/LibJS/Rust/src/runtime/raw_json_object.rs b/Libraries/LibJS/Rust/src/runtime/raw_json_object.rsindex 5ee66f60b57..70b1674d09d 100644--- a/Libraries/LibJS/Rust/src/runtime/raw_json_object.rs+++ b/Libraries/LibJS/Rust/src/runtime/raw_json_object.rs@@ -21,6 +21,8 @@ pub struct RawJSONObject {}define_object_class!(RawJSONObject, extends: [Object], methods: {+ // NB: The [[IsRawJSON]] internal slot holds nothing, so the object has no field for it.+ has_internal_slots: Some(true),..ORDINARY_OBJECT_METHODS});diff --git a/Libraries/LibJS/Rust/src/runtime/set_prototype.rs b/Libraries/LibJS/Rust/src/runtime/set_prototype.rsindex d673afc97fe..29d3a4f8895 100644--- a/Libraries/LibJS/Rust/src/runtime/set_prototype.rs+++ b/Libraries/LibJS/Rust/src/runtime/set_prototype.rs@@ -47,6 +47,8 @@ pub struct SetPrototype {define_object_class!(SetPrototype, extends: [Object], methods: {initialize: SetPrototype::initialize,+ // NB: The field of the prototype only caches its values function.+ has_internal_slots: Some(false),..ORDINARY_OBJECT_METHODS});