Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed internal_slots from object #601

Merged
merged 1 commit into from
Aug 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion boa/src/builtins/function/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
30 changes: 9 additions & 21 deletions boa/src/builtins/object/internal_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand Down Expand Up @@ -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;
}
Expand All @@ -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
}

Expand All @@ -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)
Expand Down
18 changes: 0 additions & 18 deletions boa/src/builtins/object/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand All @@ -132,7 +129,6 @@ impl Object {

Self {
data: ObjectData::Function(function),
internal_slots: FxHashMap::default(),
properties: FxHashMap::default(),
symbol_properties: FxHashMap::default(),
prototype,
Expand All @@ -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(),
Expand All @@ -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(),
Expand All @@ -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(),
Expand All @@ -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(),
Expand Down Expand Up @@ -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
Expand Down
23 changes: 0 additions & 23 deletions boa/src/builtins/value/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down