From 8036a49f26a889348cd7297a4065c51ecfaff790 Mon Sep 17 00:00:00 2001 From: HalidOdat Date: Sat, 1 Aug 2020 11:39:16 +0200 Subject: [PATCH] Removed internal_slots from object (#601) --- boa/src/builtins/function/mod.rs | 1 - boa/src/builtins/object/internal_methods.rs | 30 +++++++-------------- boa/src/builtins/object/mod.rs | 18 ------------- boa/src/builtins/value/mod.rs | 23 ---------------- 4 files changed, 9 insertions(+), 63 deletions(-) diff --git a/boa/src/builtins/function/mod.rs b/boa/src/builtins/function/mod.rs index 491c2ef0b6..51d4e3763c 100644 --- a/boa/src/builtins/function/mod.rs +++ b/boa/src/builtins/function/mod.rs @@ -409,7 +409,6 @@ impl Debug for Function { pub fn create_unmapped_arguments_object(arguments_list: &[Value]) -> Value { let len = arguments_list.len(); let mut obj = Object::default(); - obj.set_internal_slot("ParameterMap", Value::undefined()); // Set length let length = Property::data_descriptor( len.into(), diff --git a/boa/src/builtins/object/internal_methods.rs b/boa/src/builtins/object/internal_methods.rs index be4269da47..c86aa6f735 100644 --- a/boa/src/builtins/object/internal_methods.rs +++ b/boa/src/builtins/object/internal_methods.rs @@ -6,7 +6,7 @@ //! [spec]: https://tc39.es/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots use crate::builtins::{ - object::{Object, PROTOTYPE}, + object::Object, property::{Attribute, Property, PropertyKey}, value::{same_value, RcString, Value}, }; @@ -311,7 +311,7 @@ impl Object { /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf pub fn set_prototype_of(&mut self, val: Value) -> bool { debug_assert!(val.is_object() || val.is_null()); - let current = self.get_internal_slot(PROTOTYPE); + let current = self.prototype.clone(); if same_value(¤t, &val) { return true; } @@ -326,10 +326,15 @@ impl Object { } else if same_value(&Value::from(self.clone()), &p) { return false; } else { - p = p.get_internal_slot(PROTOTYPE); + let prototype = p + .as_object() + .expect("prototype should be null or object") + .prototype + .clone(); + p = prototype; } } - self.set_internal_slot(PROTOTYPE, val); + self.prototype = val; true } @@ -345,23 +350,6 @@ impl Object { self.prototype.clone() } - /// Helper function to get an immutable internal slot or `Null`. - #[inline] - pub fn get_internal_slot(&self, name: &str) -> Value { - let _timer = BoaProfiler::global().start_event("Object::get_internal_slot", "object"); - - self.internal_slots() - .get(name) - .cloned() - .unwrap_or_else(Value::null) - } - - /// Helper function to set an internal slot. - #[inline] - pub fn set_internal_slot(&mut self, name: &str, val: Value) { - self.internal_slots.insert(name.to_string(), val); - } - /// Helper function for property insertion. #[inline] pub(crate) fn insert_property(&mut self, name: N, p: Property) diff --git a/boa/src/builtins/object/mod.rs b/boa/src/builtins/object/mod.rs index 027c9ad3f8..77ac66274d 100644 --- a/boa/src/builtins/object/mod.rs +++ b/boa/src/builtins/object/mod.rs @@ -52,8 +52,6 @@ pub static PROTOTYPE: &str = "prototype"; pub struct Object { /// The type of the object. pub data: ObjectData, - /// Internal Slots - internal_slots: FxHashMap, /// Properties properties: FxHashMap, /// Symbol Properties @@ -110,7 +108,6 @@ impl Default for Object { fn default() -> Self { Self { data: ObjectData::Ordinary, - internal_slots: FxHashMap::default(), properties: FxHashMap::default(), symbol_properties: FxHashMap::default(), prototype: Value::null(), @@ -132,7 +129,6 @@ impl Object { Self { data: ObjectData::Function(function), - internal_slots: FxHashMap::default(), properties: FxHashMap::default(), symbol_properties: FxHashMap::default(), prototype, @@ -158,7 +154,6 @@ impl Object { pub fn boolean(value: bool) -> Self { Self { data: ObjectData::Boolean(value), - internal_slots: FxHashMap::default(), properties: FxHashMap::default(), symbol_properties: FxHashMap::default(), prototype: Value::null(), @@ -171,7 +166,6 @@ impl Object { pub fn number(value: f64) -> Self { Self { data: ObjectData::Number(value), - internal_slots: FxHashMap::default(), properties: FxHashMap::default(), symbol_properties: FxHashMap::default(), prototype: Value::null(), @@ -187,7 +181,6 @@ impl Object { { Self { data: ObjectData::String(value.into()), - internal_slots: FxHashMap::default(), properties: FxHashMap::default(), symbol_properties: FxHashMap::default(), prototype: Value::null(), @@ -200,7 +193,6 @@ impl Object { pub fn bigint(value: RcBigInt) -> Self { Self { data: ObjectData::BigInt(value), - internal_slots: FxHashMap::default(), properties: FxHashMap::default(), symbol_properties: FxHashMap::default(), prototype: Value::null(), @@ -403,16 +395,6 @@ impl Object { matches!(self.data, ObjectData::Ordinary) } - #[inline] - pub fn internal_slots(&self) -> &FxHashMap { - &self.internal_slots - } - - #[inline] - pub fn internal_slots_mut(&mut self) -> &mut FxHashMap { - &mut self.internal_slots - } - #[inline] pub fn properties(&self) -> &FxHashMap { &self.properties diff --git a/boa/src/builtins/value/mod.rs b/boa/src/builtins/value/mod.rs index 27ebde5a7c..e78e922623 100644 --- a/boa/src/builtins/value/mod.rs +++ b/boa/src/builtins/value/mod.rs @@ -515,18 +515,6 @@ impl Value { } } - /// Resolve the property in the object. - /// - /// Returns a copy of the Property. - #[inline] - pub fn get_internal_slot(&self, field: &str) -> Value { - let _timer = BoaProfiler::global().start_event("Value::get_internal_slot", "value"); - - self.as_object() - .and_then(|x| x.internal_slots().get(field).cloned()) - .unwrap_or_else(Value::undefined) - } - /// Resolve the property in the object and get its value, or undefined if this is not an object or the field doesn't exist /// get_field recieves a Property from get_prop(). It should then return the [[Get]] result value if that's set, otherwise fall back to [[Value]] /// TODO: this function should use the get Value if its set @@ -660,17 +648,6 @@ impl Value { value } - /// Set the private field in the value - pub fn set_internal_slot(&self, field: &str, value: Value) -> Value { - let _timer = BoaProfiler::global().start_event("Value::set_internal_slot", "exec"); - if let Some(mut object) = self.as_object_mut() { - object - .internal_slots_mut() - .insert(field.to_string(), value.clone()); - } - value - } - /// Set the kind of an object. #[inline] pub fn set_data(&self, data: ObjectData) {