Complete nullable page and typed lifecycle resource method contracts
This commit is contained in:
@@ -65,12 +65,16 @@ enum Query {
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Method {
|
||||
signature: endor_core::CallSignature,
|
||||
owner: ObjectRef,
|
||||
desktop: WeakObjectRef,
|
||||
query: Query,
|
||||
}
|
||||
|
||||
impl NativeCallable for Method {
|
||||
fn signature(&self) -> Option<endor_core::CallSignature> {
|
||||
Some(self.signature.clone())
|
||||
}
|
||||
fn arity(&self) -> Option<endor_core::CallArity> {
|
||||
Some(endor_core::CallArity::exact(
|
||||
if matches!(
|
||||
@@ -158,6 +162,12 @@ impl NativeCallable for Method {
|
||||
]
|
||||
};
|
||||
let bounds = cx.new_object()?;
|
||||
let endor_core::CallType::Single(endor_core::AnnotationType::Nominal(definition)) =
|
||||
&self.signature.returns
|
||||
else {
|
||||
return Err(VmError::InvalidArgument("invalid Mount bounds signature"));
|
||||
};
|
||||
cx.attach_type(bounds, *definition)?;
|
||||
for (name, value) in [
|
||||
("x", geometry[0]),
|
||||
("y", geometry[1]),
|
||||
@@ -234,6 +244,41 @@ impl NativeCallable for Method {
|
||||
}
|
||||
}
|
||||
|
||||
fn mount_signature(
|
||||
store: &endor_core::ObjectStore,
|
||||
desktop: ObjectRef,
|
||||
query: Query,
|
||||
) -> Result<endor_core::CallSignature, VmError> {
|
||||
use endor_core::{AnnotationType as T, CallEffect, CallSignature, CallType};
|
||||
let nominal = |name| crate::ui_bridge::desktop_type(store, name, desktop).map(T::Nominal);
|
||||
let returns = match query {
|
||||
Query::Bounds => nominal("Bounds")?.into(),
|
||||
Query::Parent | Query::FirstChild | Query::NextSibling => {
|
||||
CallType::nullable(nominal("Mount")?)
|
||||
}
|
||||
Query::Page => CallType::nullable(nominal("Page")?),
|
||||
Query::HitTest => T::Bool.into(),
|
||||
Query::ScrollPosition => T::Any.into(),
|
||||
_ => T::Unit.into(),
|
||||
};
|
||||
let effect = if matches!(
|
||||
query,
|
||||
Query::ScrollTo | Query::ScrollBy | Query::ScrollIntoView | Query::Focus
|
||||
) {
|
||||
CallEffect::Mutating
|
||||
} else {
|
||||
CallEffect::ReadOnly
|
||||
};
|
||||
let parameters = if matches!(query, Query::HitTest | Query::ScrollTo | Query::ScrollBy) {
|
||||
vec![T::Number, T::Number]
|
||||
} else {
|
||||
vec![]
|
||||
};
|
||||
let mut signature = CallSignature::exact(parameters, T::Any, effect);
|
||||
signature.returns = returns;
|
||||
Ok(signature)
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct MountTable {
|
||||
pub active: HashMap<u64, WeakObjectRef>,
|
||||
@@ -365,6 +410,7 @@ impl NativeCallable for Sync {
|
||||
let function = cx.allocate(ContextNativeFunction::new(
|
||||
name,
|
||||
Method {
|
||||
signature: mount_signature(cx.store(), self.desktop, query)?,
|
||||
owner: object,
|
||||
desktop: cx.store().downgrade(self.desktop)?,
|
||||
query,
|
||||
|
||||
Reference in New Issue
Block a user