Complete nullable page and typed lifecycle resource method contracts
This commit is contained in:
+35
-1
@@ -225,6 +225,20 @@ pub fn new_event(
|
||||
Ok(event)
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct TypedMethod {
|
||||
method: Method,
|
||||
signature: endor_core::CallSignature,
|
||||
}
|
||||
impl NativeCallable for TypedMethod {
|
||||
fn signature(&self) -> Option<endor_core::CallSignature> {
|
||||
Some(self.signature.clone())
|
||||
}
|
||||
fn invoke(&self, cx: &mut NativeContext<'_>, args: &[Value]) -> Result<NativeResult, VmError> {
|
||||
self.method.invoke(cx, args)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn install(
|
||||
vm: &mut Vm,
|
||||
roots: &mut Vec<ObjectRef>,
|
||||
@@ -244,7 +258,27 @@ pub fn install(
|
||||
(token_type, "disconnect", Method::Disconnect),
|
||||
(token_type, "isConnected", Method::Connected),
|
||||
] {
|
||||
let function = vm.allocate(ContextNativeFunction::new(name, method, vec![]))?;
|
||||
let query = matches!(method, Method::Prevented | Method::Connected);
|
||||
let function = vm.allocate(ContextNativeFunction::new(
|
||||
name,
|
||||
TypedMethod {
|
||||
method,
|
||||
signature: endor_core::CallSignature::exact(
|
||||
vec![endor_core::AnnotationType::Nominal(definition)],
|
||||
if query {
|
||||
endor_core::AnnotationType::Bool
|
||||
} else {
|
||||
endor_core::AnnotationType::Unit
|
||||
},
|
||||
if query {
|
||||
endor_core::CallEffect::ReadOnly
|
||||
} else {
|
||||
endor_core::CallEffect::Mutating
|
||||
},
|
||||
),
|
||||
},
|
||||
vec![],
|
||||
))?;
|
||||
roots.push(function);
|
||||
vm.attach_type(function, function_type)?;
|
||||
vm.define_method(definition, name, function)?;
|
||||
|
||||
Reference in New Issue
Block a user