feat: construct native visual subclasses from Endor source
Verify Tessera GUI / verify (push) Successful in 9m53s

This commit is contained in:
2026-10-21 02:06:25 +08:00
parent 0d5e4b318d
commit 6c42e5dde4
9 changed files with 259 additions and 22 deletions
+24 -1
View File
@@ -41,6 +41,23 @@ pub struct Block {
}
impl ObjectPayload for Block {
fn attribute_target(&self, store: &ObjectStore) -> Result<Option<ObjectRef>, VmError> {
let Value::Object(value) = store.cell_get(self.state)? else {
return Err(VmError::InvalidArgument("Block state is not an object"));
};
if store.object(value)?.payload().as_any().is::<Block>() {
Ok(Some(value))
} else {
store
.payload::<Data>(value, "Block data")?
.properties
.map(Some)
.ok_or(VmError::InvalidArgument(
"Block has no managed property storage",
))
}
}
fn type_target(&self, store: &ObjectStore) -> Result<Option<ObjectRef>, VmError> {
let Value::Object(value) = store.cell_get(self.state)? else {
return Err(VmError::InvalidArgument("Block state is not an object"));
@@ -94,6 +111,7 @@ pub struct Data {
pub history_index: usize,
pub text_binding: Option<(ObjectRef, String)>,
pub click: Option<ObjectRef>,
pub properties: Option<ObjectRef>,
}
impl Data {
@@ -116,6 +134,7 @@ impl Data {
history_index: 0,
text_binding: None,
click: None,
properties: None,
}
}
pub fn is_container(&self) -> bool {
@@ -134,6 +153,9 @@ impl ObjectPayload for Data {
"tessera-block-data"
}
fn trace(&self, visit: &mut dyn FnMut(ObjectRef)) {
if let Some(properties) = self.properties {
visit(properties);
}
for child in &self.children {
visit(child.block);
}
@@ -149,11 +171,12 @@ impl ObjectPayload for Data {
}
}
pub fn allocate(cx: &mut NativeContext<'_>, data: Data) -> Result<ObjectRef, VmError> {
pub fn allocate(cx: &mut NativeContext<'_>, mut data: Data) -> Result<ObjectRef, VmError> {
let page = matches!(data.kind, Kind::Page);
for child in &data.children {
validate(cx.store(), child.block, None)?;
}
data.properties = Some(cx.new_object()?);
let data = cx.allocate(data)?;
let state = cx.new_cell(Some(Value::Object(data)))?;
cx.allocate(Block { state, page })