Publish native arity and validate callback contracts before registration
Verify Tessera GUI / verify (push) Failing after 7m44s

This commit is contained in:
2026-10-22 12:03:24 +08:00
parent 50422f801a
commit 25275b515c
17 changed files with 297 additions and 35 deletions
+56 -22
View File
@@ -291,6 +291,35 @@ enum Operation {
Present,
}
impl Operation {
fn arity(self) -> endor_core::CallArity {
use Operation::*;
let (minimum, maximum) = match self {
IsInstance | IsSubtype | Bind | Implement | Implements | Supports => (2, 2),
Stats | Viewport | Window | PageWindow | Mounts => (0, 0),
State | StateSet => (1, 1),
Increment => (0, 0),
TextOf => (2, 4),
Scroll => (3, 3),
Text => (1, 3),
Rect => (2, 4),
MoveTab | MoveWindow | OpenValue | Spacer | SetText | SetColor | Append | Remove
| Render | Navigate | OnClick | Present => (1, 1),
Row | Column => (2, MAX_UI_NODES + 2),
Button => (1, 1),
Insert | Replace | Move => (2, 2),
Page | Unmount | Close | Activate | Back | Forward | Children | NewWindow
| CloseWindow | Detach => (0, 0),
Open => (0, 1),
Click | Invalidate => (0, 1),
On => (2, 3),
Dispatch => (1, 2),
OnEvent | OnMount | OnUnmount => (1, 1),
};
endor_core::CallArity::range(minimum, maximum)
}
}
#[derive(Debug)]
struct Function {
operation: Operation,
@@ -309,6 +338,14 @@ struct TypeMethod {
}
impl NativeCallable for TypeMethod {
fn arity(&self) -> Option<endor_core::CallArity> {
let arity = self.operation.arity();
Some(endor_core::CallArity::range(
arity.required + 1,
arity.maximum + 1,
))
}
fn invoke(&self, cx: &mut NativeContext<'_>, args: &[Value]) -> Result<NativeResult, VmError> {
let owner = object(args.first())?;
if !cx.store().is_instance(owner, self.expected)? {
@@ -333,6 +370,13 @@ struct NativeFactory {
}
impl NativeCallable for NativeFactory {
fn arity(&self) -> Option<endor_core::CallArity> {
Some(endor_core::CallArity::range(
self.operation.arity().required + 1,
usize::MAX,
))
}
fn invoke(&self, cx: &mut NativeContext<'_>, args: &[Value]) -> Result<NativeResult, VmError> {
let requested = object(args.first())?;
let fields = cx
@@ -617,6 +661,10 @@ struct PresentResult {
session: Shared,
}
impl NativeCallable for PresentResult {
fn arity(&self) -> Option<endor_core::CallArity> {
Some(endor_core::CallArity::exact(1))
}
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"));
@@ -683,30 +731,14 @@ fn present_value(
}
impl NativeCallable for Function {
fn arity(&self) -> Option<endor_core::CallArity> {
Some(self.operation.arity())
}
fn invoke(&self, cx: &mut NativeContext<'_>, args: &[Value]) -> Result<NativeResult, VmError> {
use Operation::*;
let (minimum, maximum) = match self.operation {
IsInstance | IsSubtype | Bind | Implement | Implements | Supports => (2, 2),
Stats | Viewport | Window | PageWindow | Mounts => (0, 0),
State | StateSet => (1, 1),
Increment => (0, 0),
TextOf => (2, 4),
Scroll => (3, 3),
Text => (1, 3),
Rect => (2, 4),
MoveTab | MoveWindow | OpenValue | Spacer | SetText | SetColor | Append | Remove
| Render | Navigate | OnClick | Present => (1, 1),
Row | Column => (2, MAX_UI_NODES + 2),
Button => (1, 1),
Insert | Replace | Move => (2, 2),
Page | Unmount | Close | Activate | Back | Forward | Children | NewWindow
| CloseWindow | Detach => (0, 0),
Open => (0, 1),
Click | Invalidate => (0, 1),
On => (2, 3),
Dispatch => (1, 2),
OnEvent | OnMount | OnUnmount => (1, 1),
};
let arity = self.operation.arity();
let (minimum, maximum) = (arity.required, arity.maximum);
if !(minimum..=maximum).contains(&args.len()) {
return Err(invalid("incorrect UI method argument count"));
}
@@ -1381,6 +1413,7 @@ impl NativeCallable for Function {
}
OnClick => {
let handler = object(args.first())?;
crate::event_dispatch::validate_handler(cx.store(), handler)?;
data.click = Some(handler);
result = Value::Object(owner);
}
@@ -1390,6 +1423,7 @@ impl NativeCallable for Function {
return Err(invalid("invalid event kind"));
}
let handler = object(args.get(1))?;
crate::event_dispatch::validate_handler(cx.store(), handler)?;
let capture = match args.get(2) {
None | Some(Value::Bool(false)) => false,
Some(Value::Bool(true)) => true,