Use api::Struct in Value::Struct, replacing Value::Object

This commit is contained in:
Simon Hausmann 2021-03-15 12:55:39 +01:00
parent f1a7847820
commit a4c196df60
3 changed files with 31 additions and 29 deletions

View file

@ -210,18 +210,18 @@ fn to_eval_value<'cx>(
Type::Bool => Ok(Value::Bool(val.downcast_or_throw::<JsBoolean, _>(cx)?.value())),
Type::Object { fields, .. } => {
let obj = val.downcast_or_throw::<JsObject, _>(cx)?;
Ok(Value::Object(
Ok(Value::Struct(
fields
.iter()
.map(|(pro_name, pro_ty)| {
Ok((
pro_name.clone(),
to_eval_value(
sixtyfps_interpreter::api::Value(to_eval_value(
obj.get(cx, pro_name.as_str())?,
pro_ty.clone(),
cx,
persistent_context,
)?,
)?),
))
})
.collect::<Result<_, _>>()?,
@ -268,11 +268,11 @@ fn to_js_value<'cx>(
}
js_array.as_value(cx)
}
Value::Object(o) => {
Value::Struct(o) => {
let js_object = JsObject::new(cx);
for (k, e) in o.into_iter() {
let v = to_js_value(e, cx)?;
js_object.set(cx, k.as_str(), v)?;
for (k, e) in o.iter() {
let v = to_js_value(e.0, cx)?;
js_object.set(cx, k, v)?;
}
js_object.as_value(cx)
}