diff --git a/api/sixtyfps-node/native/lib.rs b/api/sixtyfps-node/native/lib.rs index 776946811..b4d847773 100644 --- a/api/sixtyfps-node/native/lib.rs +++ b/api/sixtyfps-node/native/lib.rs @@ -263,7 +263,7 @@ fn to_js_value<'cx>( Value::Struct(o) => { let js_object = JsObject::new(cx); for (k, e) in o.iter() { - let v = to_js_value(e, cx)?; + let v = to_js_value(e.clone(), cx)?; js_object.set(cx, k, v)?; } js_object.as_value(cx) diff --git a/sixtyfps_runtime/interpreter/api.rs b/sixtyfps_runtime/interpreter/api.rs index c3fbecc63..83a39b493 100644 --- a/sixtyfps_runtime/interpreter/api.rs +++ b/sixtyfps_runtime/interpreter/api.rs @@ -152,7 +152,7 @@ macro_rules! declare_value_struct_conversion { impl From<$name> for Value { fn from($name { $($field),* }: $name) -> Self { let mut struct_ = Struct::default(); - $(struct_.set_property(stringify!($field).into(), $field.into());)* + $(struct_.set_field(stringify!($field).into(), $field.into());)* Value::Struct(struct_) } } @@ -163,7 +163,7 @@ macro_rules! declare_value_struct_conversion { Self::Struct(x) => { type Ty = $name; Ok(Ty { - $($field: x.get_property(stringify!($field)).ok_or(())?.clone().try_into().map_err(|_|())?),* + $($field: x.get_field(stringify!($field)).ok_or(())?.clone().try_into().map_err(|_|())?),* }) } _ => Err(()), @@ -289,25 +289,23 @@ impl TryInto for Value { /// /// // get the properties of a `{ foo: 45, bar: true }` /// let s : Struct = value.try_into().unwrap(); -/// assert_eq!(s.get_property("foo").unwrap().try_into(), Ok(45u32)); +/// assert_eq!(s.get_field("foo").unwrap().try_into(), Ok(45u32)); /// ``` -/// FIXME: the documentation of langref.md uses "Object" and we probably should make that uniform. -/// also, is "property" the right term here? #[derive(Clone, PartialEq, Debug, Default)] pub struct Struct(HashMap); impl Struct { - /// Get the value for a given struct property - pub fn get_property(&self, name: &str) -> Option { + /// Get the value for a given struct field + pub fn get_field(&self, name: &str) -> Option { self.0.get(name).cloned() } - /// Set the value of a given struct property - pub fn set_property(&mut self, name: String, value: Value) { + /// Set the value of a given struct field + pub fn set_field(&mut self, name: String, value: Value) { self.0.insert(name, value); } - /// Iterate over all the property in this struct - pub fn iter(&self) -> impl Iterator { - self.0.iter().map(|(a, b)| (a.as_str(), b.clone())) + /// Iterate over all the fields in this struct + pub fn iter(&self) -> impl Iterator { + self.0.iter().map(|(a, b)| (a.as_str(), b)) } } diff --git a/sixtyfps_runtime/interpreter/eval.rs b/sixtyfps_runtime/interpreter/eval.rs index ffc9d1d59..131e244fd 100644 --- a/sixtyfps_runtime/interpreter/eval.rs +++ b/sixtyfps_runtime/interpreter/eval.rs @@ -173,7 +173,7 @@ pub fn eval_expression(e: &Expression, local_context: &mut EvalLocalContext) -> } Expression::StructFieldAccess { base, name } => { if let Value::Struct(o) = eval_expression(base, local_context) { - o.get_property(name).unwrap_or(Value::Void) + o.get_field(name).unwrap_or(Value::Void) } else { Value::Void } @@ -580,9 +580,9 @@ fn eval_assignement(lhs: &Expression, op: char, rhs: Value, local_context: &mut } Expression::StructFieldAccess { base, name } => { if let Value::Struct(mut o) = eval_expression(base, local_context) { - let mut r = o.get_property(name).unwrap(); + let mut r = o.get_field(name).unwrap(); r = if op == '=' { rhs } else { eval(std::mem::take(&mut r)) }; - o.set_property(name.to_owned(), r); + o.set_field(name.to_owned(), r); eval_assignement(base, '=', Value::Struct(o), local_context) } }