Skip to content

Commit

Permalink
store more property objects in vecs
Browse files Browse the repository at this point in the history
  • Loading branch information
y21 committed Nov 2, 2024
1 parent e83ce15 commit ae83fd6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
10 changes: 10 additions & 0 deletions crates/dash_middle/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,3 +308,13 @@ macro_rules! with {
$code
}};
}

#[macro_export]
macro_rules! closure {
($(clone($clone_binding:ident))*; $closure:expr) => {
{
$(let $clone_binding = $clone_binding.clone();)*
$closure
}
};
}
30 changes: 15 additions & 15 deletions crates/dash_vm/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,6 @@ mod handlers {
use dash_middle::iterator_with::{InfallibleIteratorWith, IteratorWith};
use dash_middle::parser::statement::{Asyncness, FunctionKind as ParserFunctionKind};
use handlers::extract::{extract, ForwardSequence, FrontIteratorWith};
use hashbrown::hash_map::Entry;
use if_chain::if_chain;
use smallvec::SmallVec;
use std::ops::{Add, ControlFlow, Div, Mul, Rem, Sub};
Expand All @@ -546,7 +545,8 @@ mod handlers {
use crate::value::function::generator::GeneratorFunction;
use crate::value::function::user::UserFunction;
use crate::value::function::{adjust_stack_from_flat_call, Function, FunctionKind};
use crate::value::object::{NamedObject, Object, ObjectMap, PropertyKey, PropertyValue, PropertyValueKind};
use crate::value::object::{NamedObject, Object, PropertyKey, PropertyValue, PropertyValueKind};
use crate::value::object_map::ObjectMap;
use crate::value::ops::conversions::ValueConversion;
use crate::value::ops::equality;
use crate::value::primitive::Number;
Expand Down Expand Up @@ -1499,26 +1499,26 @@ mod handlers {
let mut obj = ObjectMap::default();
while let Some(property) = iter.next(&mut cx) {
match property? {
ObjectProperty::Static { key, value } => drop(obj.insert(key, value)),
ObjectProperty::Getter { key, value } => match obj.entry(key) {
Entry::Occupied(mut entry) => match &mut entry.get_mut().kind {
PropertyValueKind::Static(_) => drop(entry.insert(PropertyValue::getter_default(value))),
ObjectProperty::Static { key, value } => obj.insert(key, value),
ObjectProperty::Getter { key, value } => obj.entry(key).modify_or_insert(
|prop| match &mut prop.kind {
PropertyValueKind::Static(_) => *prop = PropertyValue::getter_default(value),
PropertyValueKind::Trap { get, .. } => *get = Some(value),
},
Entry::Vacant(entry) => drop(entry.insert(PropertyValue::getter_default(value))),
},
ObjectProperty::Setter { key, value } => match obj.entry(key) {
Entry::Occupied(mut entry) => match &mut entry.get_mut().kind {
PropertyValueKind::Static(_) => drop(entry.insert(PropertyValue::setter_default(value))),
|| PropertyValue::getter_default(value),
),
ObjectProperty::Setter { key, value } => obj.entry(key).modify_or_insert(
|prop| match &mut prop.kind {
PropertyValueKind::Static(_) => *prop = PropertyValue::setter_default(value),
PropertyValueKind::Trap { set, .. } => *set = Some(value),
},
Entry::Vacant(entry) => drop(entry.insert(PropertyValue::setter_default(value))),
},
|| PropertyValue::setter_default(value),
),
ObjectProperty::Spread(value) => {
if let ValueKind::Object(object) = value.unpack() {
for key in object.own_keys(&mut cx.scope)? {
let key = PropertyKey::from_value(&mut cx.scope, key)?;
let value = object.get_property(&mut cx, key.clone())?.root(&mut cx.scope);
let value = object.get_property(&mut cx, key)?.root(&mut cx.scope);
obj.insert(key, PropertyValue::static_default(value));
}
}
Expand All @@ -1545,7 +1545,7 @@ mod handlers {
match property {
ObjectProperty::Static { key, value } => target.set_property(&mut cx.scope, key, value)?,
ObjectProperty::Getter { key, value } | ObjectProperty::Setter { key, value } => {
let prop = target.get_property_descriptor(&mut cx.scope, key.clone())?;
let prop = target.get_property_descriptor(&mut cx.scope, key)?;
let prop = match prop {
Some(mut prop) => {
if let PropertyValueKind::Trap { get, set } = &mut prop.kind {
Expand Down
4 changes: 2 additions & 2 deletions crates/dash_vm/src/js_std/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ pub fn assign(cx: CallContext) -> Result<Value, Value> {
let source = source.to_object(cx.scope)?;
for key in source.own_keys(cx.scope)? {
let key = PropertyKey::from_value(cx.scope, key)?;
let desc = source.get_own_property(cx.scope, key.clone()).root(cx.scope)?;
let desc = source.get_own_property(cx.scope, key).root(cx.scope)?;
to.set_property(cx.scope, key, PropertyValue::static_default(desc))?;
}
}
Expand All @@ -199,7 +199,7 @@ pub fn entries(cx: CallContext) -> Result<Value, Value> {
let obj = cx.args.first().unwrap_or_undefined().to_object(cx.scope)?;
for key in obj.own_keys(cx.scope)? {
let key = PropertyKey::from_value(cx.scope, key)?;
let value = obj.get_own_property(cx.scope, key.clone()).root(cx.scope)?;
let value = obj.get_own_property(cx.scope, key).root(cx.scope)?;
let entry = Array::from_vec(
cx.scope,
vec![
Expand Down
3 changes: 2 additions & 1 deletion crates/dash_vm/src/json/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use dash_middle::util;

use crate::localscope::LocalScope;
use crate::value::array::Array;
use crate::value::object::{NamedObject, ObjectMap, PropertyKey, PropertyValue};
use crate::value::object::{NamedObject, PropertyKey, PropertyValue};
use crate::value::object_map::ObjectMap;
use crate::value::Value;

/// An error that occurred during parsing JSON
Expand Down

0 comments on commit ae83fd6

Please sign in to comment.