feat: expose native visual protocols and explicit invalidation
Verify Tessera GUI / verify (push) Failing after 7m23s

This commit is contained in:
2026-10-21 02:42:16 +08:00
parent d2f167e71f
commit dc61f5e33c
13 changed files with 691 additions and 140 deletions
+65
View File
@@ -0,0 +1,65 @@
//! Managed indexed host results; values and the at method are traced edges.
use endor_core::{
ContextNativeFunction, NativeCallable, NativeContext, NativeResult, ObjectPayload, ObjectRef,
Value, VmError,
};
#[derive(Debug)]
struct ObjectList(Vec<ObjectRef>);
impl ObjectPayload for ObjectList {
fn as_any(&self) -> &dyn std::any::Any {
self
}
fn kind_name(&self) -> &'static str {
"tessera-object-list"
}
fn allows_attributes(&self) -> bool {
true
}
fn trace(&self, visit: &mut dyn FnMut(ObjectRef)) {
for mount in &self.0 {
visit(*mount);
}
}
}
#[derive(Debug)]
struct At(ObjectRef);
impl NativeCallable for At {
fn invoke(&self, cx: &mut NativeContext<'_>, args: &[Value]) -> Result<NativeResult, VmError> {
let [Value::Number(index)] = args else {
return Err(VmError::InvalidArgument("object list at expects an index"));
};
let index = index
.as_i64()
.and_then(|v| usize::try_from(v).ok())
.ok_or(VmError::InvalidArgument("invalid list index"))?;
let mount = *cx
.store()
.payload::<ObjectList>(self.0, "Object list")?
.0
.get(index)
.ok_or(VmError::InvalidArgument("list index out of range"))?;
Ok(NativeResult::Return(Value::Object(mount)))
}
}
pub fn collection(
cx: &mut NativeContext<'_>,
mounts: Vec<ObjectRef>,
desktop: ObjectRef,
) -> Result<ObjectRef, VmError> {
let first = mounts
.first()
.copied()
.map(Value::Object)
.unwrap_or(Value::Nil);
let count = mounts.len();
let set = cx.allocate(ObjectList(mounts))?;
crate::ui_bridge::attach_desktop_type(cx, set, "ObjectList", desktop)?;
cx.set_attr(set, "first", first)?;
cx.set_attr(set, "count", Value::Number((count as i64).into()))?;
let at = cx.allocate(ContextNativeFunction::new("at", At(set), vec![set]))?;
crate::ui_bridge::attach_desktop_type(cx, at, "Function", desktop)?;
cx.set_attr(set, "at", Value::Object(at))?;
Ok(set)
}