Complete nullable page and typed lifecycle resource method contracts

This commit is contained in:
2026-10-22 14:01:01 +08:00
parent 543c909d53
commit d9fd3f2f65
10 changed files with 193 additions and 24 deletions
+35 -1
View File
@@ -192,10 +192,14 @@ pub fn cancel_owner(cx: &mut NativeContext<'_>, owner: ObjectRef) -> Result<(),
#[derive(Debug)]
struct After {
signature: endor_core::CallSignature,
index: Index,
desktop: ObjectRef,
}
impl NativeCallable for After {
fn signature(&self) -> Option<endor_core::CallSignature> {
Some(self.signature.clone())
}
fn arity(&self) -> Option<endor_core::CallArity> {
Some(endor_core::CallArity::exact(4))
}
@@ -324,10 +328,14 @@ enum Query {
}
#[derive(Debug)]
struct Method {
signature: endor_core::CallSignature,
query: Query,
desktop: ObjectRef,
}
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(1))
}
@@ -551,6 +559,16 @@ pub fn install(
let after = vm.allocate(ContextNativeFunction::new(
"after",
After {
signature: endor_core::CallSignature::exact(
vec![
endor_core::AnnotationType::Any,
endor_core::AnnotationType::String,
endor_core::AnnotationType::Number,
endor_core::AnnotationType::Function,
],
endor_core::AnnotationType::Nominal(definition),
endor_core::CallEffect::Mutating,
),
index: index.clone(),
desktop,
},
@@ -565,7 +583,23 @@ pub fn install(
] {
let method = vm.allocate(ContextNativeFunction::new(
name,
Method { query, desktop },
Method {
query,
desktop,
signature: endor_core::CallSignature::exact(
vec![endor_core::AnnotationType::Nominal(definition)],
if matches!(query, Query::Status) {
endor_core::AnnotationType::String
} else {
endor_core::AnnotationType::Bool
},
if matches!(query, Query::Cancel) {
endor_core::CallEffect::Mutating
} else {
endor_core::CallEffect::ReadOnly
},
),
},
vec![desktop],
))?;
roots.push(method);