Declare visual capabilities and dispatch explicit Presentable views
Verify Tessera GUI / verify (push) Failing after 7m41s
Verify Tessera GUI / verify (push) Failing after 7m41s
This commit is contained in:
+146
-2
@@ -20,6 +20,11 @@ pub const TYPE_NAMES: &[&str] = &[
|
||||
"Object",
|
||||
"Type",
|
||||
"Function",
|
||||
"Trait",
|
||||
"Visual",
|
||||
"EventTarget",
|
||||
"Children",
|
||||
"Presentable",
|
||||
"Block",
|
||||
"ContainerBlock",
|
||||
"TextBlock",
|
||||
@@ -42,7 +47,13 @@ pub const TYPE_NAMES: &[&str] = &[
|
||||
"DisplayList",
|
||||
"PaintCommand",
|
||||
];
|
||||
pub const QUERY_NAMES: &[&str] = &["isInstance", "isSubtype"];
|
||||
pub const QUERY_NAMES: &[&str] = &[
|
||||
"isInstance",
|
||||
"isSubtype",
|
||||
"implement",
|
||||
"implements",
|
||||
"supports",
|
||||
];
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct UiNode {
|
||||
@@ -199,6 +210,9 @@ type Shared = Arc<Mutex<Session>>;
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
enum Operation {
|
||||
IsInstance,
|
||||
Implement,
|
||||
Implements,
|
||||
Supports,
|
||||
IsSubtype,
|
||||
OpenValue,
|
||||
Mounts,
|
||||
@@ -565,6 +579,36 @@ fn show(cx: &mut NativeContext<'_>, page: ObjectRef, session: &Shared) -> Result
|
||||
show_in(cx, page, session, None)
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct PresentResult {
|
||||
open: bool,
|
||||
session: Shared,
|
||||
}
|
||||
impl NativeCallable for PresentResult {
|
||||
fn invoke(&self, cx: &mut NativeContext<'_>, args: &[Value]) -> Result<NativeResult, VmError> {
|
||||
let [Value::Object(root)] = args else {
|
||||
return Err(invalid("Presentable.present must return a Block"));
|
||||
};
|
||||
let is_page = cx.store().payload::<block::Block>(*root, "Block")?.page;
|
||||
let result = if self.open {
|
||||
let page = if is_page {
|
||||
*root
|
||||
} else {
|
||||
new_block(
|
||||
cx,
|
||||
Data::new(Kind::Page, vec![*root], 0.0, 0.0),
|
||||
&self.session,
|
||||
)?
|
||||
};
|
||||
show(cx, page, &self.session)?;
|
||||
page
|
||||
} else {
|
||||
*root
|
||||
};
|
||||
Ok(NativeResult::Return(Value::Object(result)))
|
||||
}
|
||||
}
|
||||
|
||||
fn present_value(
|
||||
cx: &mut NativeContext<'_>,
|
||||
value: &Value,
|
||||
@@ -610,7 +654,7 @@ impl NativeCallable for Function {
|
||||
fn invoke(&self, cx: &mut NativeContext<'_>, args: &[Value]) -> Result<NativeResult, VmError> {
|
||||
use Operation::*;
|
||||
let (minimum, maximum) = match self.operation {
|
||||
IsInstance | IsSubtype | Bind => (2, 2),
|
||||
IsInstance | IsSubtype | Bind | Implement | Implements | Supports => (2, 2),
|
||||
Stats | Viewport | Window | PageWindow | Mounts => (0, 0),
|
||||
State | StateSet => (1, 1),
|
||||
Increment => (0, 0),
|
||||
@@ -633,6 +677,30 @@ impl NativeCallable for Function {
|
||||
if !(minimum..=maximum).contains(&args.len()) {
|
||||
return Err(invalid("incorrect UI method argument count"));
|
||||
}
|
||||
if matches!(self.operation, Implement | Implements | Supports) {
|
||||
let capability = object(args.get(1))?;
|
||||
let value = match self.operation {
|
||||
Implement => {
|
||||
cx.implement_trait(object(args.first())?, capability)?;
|
||||
Value::Nil
|
||||
}
|
||||
Implements => Value::Bool(
|
||||
cx.store()
|
||||
.implements_trait(object(args.first())?, capability)?,
|
||||
),
|
||||
Supports => {
|
||||
// Validate the contract even for immediate scalar values.
|
||||
cx.store()
|
||||
.payload::<endor_core::EndorTraitObject>(capability, "Trait")?;
|
||||
Value::Bool(match args[0] {
|
||||
Value::Object(value) => cx.store().supports(value, capability)?,
|
||||
_ => false,
|
||||
})
|
||||
}
|
||||
_ => unreachable!(),
|
||||
};
|
||||
return Ok(NativeResult::Return(value));
|
||||
}
|
||||
if matches!(self.operation, IsInstance | IsSubtype) {
|
||||
let candidate = object(args.first())?;
|
||||
let expected = object(args.get(1))?;
|
||||
@@ -946,6 +1014,74 @@ impl NativeCallable for Function {
|
||||
self.requested_type,
|
||||
)?)));
|
||||
}
|
||||
if matches!(self.operation, OpenValue | Present)
|
||||
&& let Value::Object(value) = args[0]
|
||||
{
|
||||
let (desktop, current) = {
|
||||
let state = self
|
||||
.session
|
||||
.lock()
|
||||
.map_err(|_| invalid("UI session poisoned"))?;
|
||||
(state.master, state.desktop)
|
||||
};
|
||||
let capability = desktop_type(cx.store(), "Presentable", desktop)?;
|
||||
if !cx
|
||||
.store()
|
||||
.object(value)?
|
||||
.payload()
|
||||
.as_any()
|
||||
.is::<block::Block>()
|
||||
&& cx.store().supports(value, capability)?
|
||||
{
|
||||
let definition = cx
|
||||
.store()
|
||||
.type_of(value)?
|
||||
.ok_or(invalid("untyped Presentable"))?;
|
||||
let function = cx
|
||||
.store()
|
||||
.lookup_method(definition, "present")?
|
||||
.ok_or(invalid("missing present method"))?;
|
||||
let window = object(Some(&cx.store().get_attr(current, "window")?))?;
|
||||
let complete = cx.allocate(ContextNativeFunction::new(
|
||||
"validate presentation",
|
||||
PresentResult {
|
||||
open: matches!(self.operation, OpenValue),
|
||||
session: self.session.clone(),
|
||||
},
|
||||
vec![desktop],
|
||||
))?;
|
||||
let instructions = [
|
||||
endor_core::Instruction::new(endor_core::Opcode::LoadConst, 0),
|
||||
endor_core::Instruction::simple(endor_core::Opcode::PushNull),
|
||||
endor_core::Instruction::new(endor_core::Opcode::LoadConst, 1),
|
||||
endor_core::Instruction::simple(endor_core::Opcode::PushNull),
|
||||
endor_core::Instruction::new(endor_core::Opcode::LoadConst, 2),
|
||||
endor_core::Instruction::new(endor_core::Opcode::LoadConst, 3),
|
||||
endor_core::Instruction::new(endor_core::Opcode::Call, 2),
|
||||
endor_core::Instruction::new(endor_core::Opcode::Call, 1),
|
||||
endor_core::Instruction::simple(endor_core::Opcode::ReturnValue),
|
||||
];
|
||||
let code = endor_core::EndorCode::from_instructions(
|
||||
&instructions,
|
||||
vec![
|
||||
Value::Object(complete),
|
||||
Value::Object(function),
|
||||
Value::Object(value),
|
||||
Value::Object(window),
|
||||
],
|
||||
endor_core::CodeLayout::default(),
|
||||
)?
|
||||
.with_location("Presentable.present", "<tessera>", 1);
|
||||
let code = cx.allocate(endor_core::EndorCodeObject::new(code))?;
|
||||
let globals = cx.new_dict()?;
|
||||
let driver = cx.new_function("Presentable.present", code, globals)?;
|
||||
attach_desktop_type(cx, driver, "Function", desktop)?;
|
||||
return Ok(NativeResult::Invoke {
|
||||
function: driver,
|
||||
arguments: vec![],
|
||||
});
|
||||
}
|
||||
}
|
||||
if matches!(self.operation, OpenValue) {
|
||||
let root = present_value(cx, &args[0], &self.session)?;
|
||||
let page = if cx.store().payload::<block::Block>(root, "Block")?.page {
|
||||
@@ -1976,6 +2112,9 @@ pub fn install(vm: &mut Vm, roots: &mut Vec<ObjectRef>) -> Result<UiBridge> {
|
||||
retired_commands: Vec::new(),
|
||||
}));
|
||||
for (name, operation) in [
|
||||
("implement", Operation::Implement),
|
||||
("implements", Operation::Implements),
|
||||
("supports", Operation::Supports),
|
||||
("isInstance", Operation::IsInstance),
|
||||
("isSubtype", Operation::IsSubtype),
|
||||
("open", Operation::OpenValue),
|
||||
@@ -2015,6 +2154,7 @@ pub fn install(vm: &mut Vm, roots: &mut Vec<ObjectRef>) -> Result<UiBridge> {
|
||||
("Type", root_types.type_type),
|
||||
];
|
||||
for (name, base_name, constructor_name) in [
|
||||
("Trait", "Object", None),
|
||||
("Function", "Object", None),
|
||||
("Block", "Object", None),
|
||||
("ContainerBlock", "Block", None),
|
||||
@@ -2149,6 +2289,9 @@ pub fn install(vm: &mut Vm, roots: &mut Vec<ObjectRef>) -> Result<UiBridge> {
|
||||
"window",
|
||||
"isInstance",
|
||||
"isSubtype",
|
||||
"implement",
|
||||
"implements",
|
||||
"supports",
|
||||
] {
|
||||
let function = object(Some(&vm.get_attr(ui, name)?))?;
|
||||
vm.attach_type(function, function_type)?;
|
||||
@@ -2205,6 +2348,7 @@ pub fn install(vm: &mut Vm, roots: &mut Vec<ObjectRef>) -> Result<UiBridge> {
|
||||
let event_type = object(Some(&vm.get_attr(ui, "Event")?))?;
|
||||
let token_type = object(Some(&vm.get_attr(ui, "Subscription")?))?;
|
||||
crate::event_dispatch::install(vm, roots, event_type, token_type, function_type)?;
|
||||
crate::protocols::install(vm, roots, desktop, ui)?;
|
||||
Ok(UiBridge { ui, session })
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user