Browse Source

Removed internal_slots from object (#601)

pull/604/head
HalidOdat 4 years ago committed by GitHub
parent
commit
8036a49f26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      boa/src/builtins/function/mod.rs
  2. 30
      boa/src/builtins/object/internal_methods.rs
  3. 18
      boa/src/builtins/object/mod.rs
  4. 23
      boa/src/builtins/value/mod.rs

1
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(),

30
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(&current, &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<N>(&mut self, name: N, p: Property)

18
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<String, Value>,
/// Properties
properties: FxHashMap<RcString, Property>,
/// 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<String, Value> {
&self.internal_slots
}
#[inline]
pub fn internal_slots_mut(&mut self) -> &mut FxHashMap<String, Value> {
&mut self.internal_slots
}
#[inline]
pub fn properties(&self) -> &FxHashMap<RcString, Property> {
&self.properties

23
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) {

Loading…
Cancel
Save