Publish native arity and validate callback contracts before registration
Verify Tessera GUI / verify (push) Failing after 7m44s
Verify Tessera GUI / verify (push) Failing after 7m44s
This commit is contained in:
+5
-3
@@ -7,8 +7,8 @@
|
||||
| activity.rs | Bounded in-memory HTTP exchanges with marked previews and allowlisted request headers |
|
||||
| endor_host.rs | Aster compilation, fresh PUT candidates retained after successful publication, shared Console/program VM, asynchronous completion/fault boundaries, bounded execution, root cleanup and AST developer tree for function/class/member assignment nodes |
|
||||
| endor_script.rs | Batch complete inputs for Aster's Interactive parser/compiler, retain Module entry, and rebase Aster spans to the original snapshot |
|
||||
| ui_bridge.rs | Inheritable native nominal constructors with source fields, shared type method tables and bound receiver dispatch, configured unified Function classification and source/field annotation checks with native constructor preflight, tab registry, stable-slot insertion, source-dispatched tab reorder/drop, Page lifecycle/navigation and immutable frame extraction |
|
||||
| binding.rs | Target-owned managed property bindings, weak Subscription tokens, read-only compute and borrowed dependency/output caches |
|
||||
| ui_bridge.rs | Inheritable native nominal constructors with source fields, shared type method tables and bound receiver dispatch, configured unified Function classification and source/field annotation checks with native constructor preflight and shared native arity intervals, tab registry, stable-slot insertion, source-dispatched tab reorder/drop and callback registration checks, Page lifecycle/navigation and immutable frame extraction |
|
||||
| binding.rs | Target-owned managed property bindings, weak Subscription tokens, zero-argument callback preflight, read-only compute and borrowed dependency/output caches |
|
||||
| block.rs | Aster-managed Block/Cell/data graph, stable child slots, content-owned field storage, shared assignment, cycle validation and explicit text bindings |
|
||||
| snapshot.rs | Property and visual-method identity dependencies across shared field-storage paths, reverse parent links and cached immutable visual derivation |
|
||||
| mount.rs | Managed per-occurrence contexts, weak reverse links, ordered mount/unmount hooks, geometry and focus queries |
|
||||
@@ -58,7 +58,7 @@ contain only immutable native data.
|
||||
Tests in api.rs execute real HTTP CRUD, persistent Console/reset/PUT isolation and a controlled queued-PUT/DELETE race
|
||||
without opening a window. Tests in endor_host.rs cover lifecycle, direct script and
|
||||
module entry, page methods, stable-slot insertion and tab drop/override/stale-target behavior, multiline inputs, original source ranges, malformed input,
|
||||
owner/task cancellation, hidden-object delivery, stale request and callback failure, entry checks, source function/declared-field annotation checks, constructor side-effect prevention, shared field forwarding/function identity and REPL class redefinition, budgets, failure preservation, live object identity, explicit rendering,
|
||||
owner/task cancellation, hidden-object delivery, stale request and callback failure, entry checks, source function/declared-field annotation checks, constructor side-effect prevention, native callback signature/pre-registration validation, shared field forwarding/function identity and REPL class redefinition, budgets, failure preservation, live object identity, explicit rendering,
|
||||
compile-before-execute behavior and stale-result invalidation. They
|
||||
run only in remote CI. Font tests in text.rs and software_renderer.rs cover real
|
||||
advances, multiline height, fractional scaling, CJK fallback, grapheme-safe fitting,
|
||||
@@ -129,3 +129,5 @@ Mount.scrollBy method without changing guest focus. Mount requests mark a
|
||||
per-window projection refresh; snapshots/caches never own business objects.
|
||||
|
||||
Tab drops validate source and destination window/session/layout plus the actual VM Page order before callbacks. The bridge invokes managed Page methods, respecting source overrides that decline or redirect a window move. Reordering within a window retains Mounts; moving windows retains Page identity and replaces Mounts. Native drag feedback is host state, with no additional managed roots. Desktop placement is an asynchronous physical outer-origin request, protected by the existing session/commit boundary. Regression sources cover the HTTP event allowlist, stale frame reuse, stable insertion, source overrides and signed positions; these were compiled, not locally executed.
|
||||
|
||||
NativeCallable implementations publish positional metadata, including internal layout/paint/hit/event continuations. The VM validates it before entering Rust. Event delivery uses the same source/native/bound arity query; binding and Task registration reject incompatible or unknown metadata before changing ownership. Native parameter/return types and effects remain checked by existing host boundaries rather than this count-only metadata.
|
||||
|
||||
+3
-1
@@ -1097,7 +1097,9 @@ Source function parameter annotations are checked before the body and return ann
|
||||
|
||||
Declared fields are checked at construction and set_attr writes through the same enabled type-check switch. Native subclass fields are validated before native allocation/opening effects. Failure preserves the field; declared deletion is rejected. Inherited fields use their declaring definition/environment, the declaring class name keeps its actual identity after REPL redefinition, and other names resolve dynamically in declaration globals/builtins. Shared Block forwarding selects the current content type/storage. This does not scan old objects or revalidate all referring fields after shared-reference changes; trusted payload/storage/attach operations and complete initialization remain host responsibilities. Static/effect typing, override variance and local/captured type annotations remain pending. See examples/field-contracts.endor.
|
||||
|
||||
Trait definitions Visual, EventTarget, Children and Presentable are managed nominal capabilities. ui.implement(type,capability) explicitly declares an implementation after required-method/positional-arity checks; ui.implements(type,capability) and ui.supports(value,capability) query it. Block declares Visual/EventTarget; ContainerBlock declares Children, inherited by Page. Same-name methods alone never declare an implementation. Source subclass construction and host method replacement validate inherited/affected descendant contracts. Native callable signatures are trusted; source parameter/return annotations are checked at invocation. Native signature metadata, effect checks and formal trait syntax remain pending. EventTarget requires canonical on/dispatch/onEvent arities 3/2/1 after self; native optional convenience forms remain.
|
||||
Native methods now publish positional CallArity intervals, checked by the VM before invocation. Source defaults and bound receivers participate in the same query. Traits validate acceptance of their canonical count including self and reject native methods without metadata. Event listeners/onClick require Function metadata accepting zero arguments or one Event, preferring Event if both work. Binding computes and Task callbacks require zero-argument acceptance before registration/replacement. Generic Type constructor reflection and native parameter/return type/effect metadata remain separate gaps. See examples/native-signatures.endor.
|
||||
|
||||
Trait definitions Visual, EventTarget, Children and Presentable are managed nominal capabilities. ui.implement(type,capability) explicitly declares an implementation after required-method/positional-arity checks; ui.implements(type,capability) and ui.supports(value,capability) query it. Block declares Visual/EventTarget; ContainerBlock declares Children, inherited by Page. Same-name methods alone never declare an implementation. Source subclass construction and host method replacement validate inherited/affected descendant contracts. Source/native positional intervals are checked, and missing native arity metadata prevents a capability declaration; source parameter/return annotations are checked at invocation. Native parameter/return type metadata, effect checks and formal trait syntax remain pending. EventTarget requires canonical on/dispatch/onEvent arities 3/2/1 after self; native optional convenience forms remain.
|
||||
|
||||
For a plain object explicitly implementing Presentable, present(self, window: Window): Block is invoked by ui.present(value) or ui.open(value), using the current managed Window and the same VM budget. The result must be an actual Block. Blocks pass through directly; unregistered values retain the summary fallback. Source views retain their business object via managed fields/callbacks/bindings, as in examples/presentable.endor. Viewing function definitions does not itself execute them. Rendering methods still run read-only with nominal result checks.
|
||||
|
||||
|
||||
+17
-1
@@ -58,7 +58,23 @@ pub fn connect(
|
||||
.properties
|
||||
.ok_or(VmError::InvalidArgument("missing property storage"))?;
|
||||
cx.store().get_attr(properties, field)?;
|
||||
cx.store().object(compute)?;
|
||||
if !cx.store().object(compute)?.payload().is_function() {
|
||||
return Err(VmError::InvalidArgument(
|
||||
"binding compute must be a Function",
|
||||
));
|
||||
}
|
||||
if !cx
|
||||
.store()
|
||||
.call_arity(compute)?
|
||||
.ok_or(VmError::InvalidArgument(
|
||||
"binding compute requires positional metadata",
|
||||
))?
|
||||
.accepts(0)
|
||||
{
|
||||
return Err(VmError::InvalidArgument(
|
||||
"binding compute requires zero unbound parameters",
|
||||
));
|
||||
}
|
||||
let mut retained = vec![];
|
||||
for connection in &data.bindings {
|
||||
let mut binding = cx
|
||||
|
||||
@@ -993,6 +993,70 @@ mod tests {
|
||||
const EXAMPLE: &str = include_str!("../examples/hello.endor");
|
||||
const PAGE: &str = include_str!("../examples/page.endor");
|
||||
|
||||
#[test]
|
||||
fn native_signatures_validate_registration_and_deliver_the_event_argument() {
|
||||
let (mut session, _) = ReplSession::load(
|
||||
include_str!("../examples/native-signatures.endor"),
|
||||
"app.main",
|
||||
1,
|
||||
220,
|
||||
)
|
||||
.unwrap();
|
||||
for invalid in [
|
||||
r#"withEvent.on("click", ui.textOf)"#,
|
||||
r#"withEvent.on("click", Page)"#,
|
||||
r#"label.bind("text", received.set)"#,
|
||||
r#"ui.after(ui,"bad",60000,received.set)"#,
|
||||
"count.increment(1)",
|
||||
] {
|
||||
assert!(session.execute(invalid, "app.main").is_err(), "{invalid}");
|
||||
assert!(
|
||||
session.documents[&crate::window::MAIN_WINDOW]
|
||||
.frame
|
||||
.fault
|
||||
.is_none()
|
||||
);
|
||||
}
|
||||
let document = session
|
||||
.execute("withEvent.click()", "app.main")
|
||||
.unwrap()
|
||||
.document
|
||||
.unwrap();
|
||||
assert!(document.frame.commands.iter().any(
|
||||
|command| matches!(command, RenderCommand::Text { value, .. } if value == "click")
|
||||
));
|
||||
assert_eq!(
|
||||
session
|
||||
.execute("received.value.kind", "app.main")
|
||||
.unwrap()
|
||||
.value,
|
||||
r#""click""#
|
||||
);
|
||||
session.execute("withoutEvent.click()", "app.main").unwrap();
|
||||
assert_eq!(
|
||||
session.execute("count.value", "app.main").unwrap().value,
|
||||
"1"
|
||||
);
|
||||
assert!(session.poll_tasks().unwrap().is_none());
|
||||
let globals = session.candidate.globals.unwrap();
|
||||
let Value::Object(received) = session
|
||||
.candidate
|
||||
.vm
|
||||
.dict_get(globals, &Value::Text("received".into()))
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
else {
|
||||
panic!("state")
|
||||
};
|
||||
let Value::Object(set) = session.candidate.vm.get_attr(received, "set").unwrap() else {
|
||||
panic!("set")
|
||||
};
|
||||
assert_eq!(
|
||||
session.candidate.vm.call_arity(set).unwrap(),
|
||||
Some(endor_core::CallArity::exact(1))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn checked_fields_reject_native_constructor_side_effects_and_preserve_live_values() {
|
||||
let (mut session, _) = ReplSession::load(
|
||||
|
||||
+38
-2
@@ -11,6 +11,24 @@ fn invalid(message: &'static str) -> VmError {
|
||||
VmError::InvalidArgument(message)
|
||||
}
|
||||
|
||||
pub fn validate_handler(
|
||||
store: &endor_core::ObjectStore,
|
||||
function: ObjectRef,
|
||||
) -> Result<(), VmError> {
|
||||
if !store.object(function)?.payload().is_function() {
|
||||
return Err(invalid("event handler must be a Function"));
|
||||
}
|
||||
let arity = store
|
||||
.call_arity(function)?
|
||||
.ok_or(invalid("event handler requires positional metadata"))?;
|
||||
if !arity.accepts(0) && !arity.accepts(1) {
|
||||
return Err(invalid(
|
||||
"event handler must accept zero arguments or one Event",
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct Event {
|
||||
dispatch: Option<WeakObjectRef>,
|
||||
@@ -84,6 +102,10 @@ enum Method {
|
||||
Connected,
|
||||
}
|
||||
impl NativeCallable for Method {
|
||||
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(owner)] = args else {
|
||||
return Err(invalid("event method receiver"));
|
||||
@@ -159,6 +181,10 @@ impl NativeCallable for Method {
|
||||
#[derive(Debug)]
|
||||
pub struct Constructor;
|
||||
impl NativeCallable for Constructor {
|
||||
fn arity(&self) -> Option<endor_core::CallArity> {
|
||||
Some(endor_core::CallArity::range(2, usize::MAX))
|
||||
}
|
||||
|
||||
fn invoke(&self, cx: &mut NativeContext<'_>, args: &[Value]) -> Result<NativeResult, VmError> {
|
||||
let [Value::Object(definition), Value::Text(kind), values @ ..] = args else {
|
||||
return Err(invalid("Event requires an event kind"));
|
||||
@@ -171,6 +197,8 @@ impl NativeCallable for Constructor {
|
||||
if fields.len() != values.len() {
|
||||
return Err(invalid("incorrect Event field arguments"));
|
||||
}
|
||||
cx.store()
|
||||
.check_class_field_arguments(*definition, values)?;
|
||||
let event = new_event(cx, *definition, kind)?;
|
||||
for (field, value) in fields.iter().zip(values) {
|
||||
cx.set_attr(event, &field.name, value.clone())?;
|
||||
@@ -240,6 +268,10 @@ struct Delivery {
|
||||
handler: Handler,
|
||||
}
|
||||
impl NativeCallable for Delivery {
|
||||
fn arity(&self) -> Option<endor_core::CallArity> {
|
||||
Some(endor_core::CallArity::exact(0))
|
||||
}
|
||||
|
||||
fn invoke(&self, cx: &mut NativeContext<'_>, _: &[Value]) -> Result<NativeResult, VmError> {
|
||||
let mut event = cx.store().payload::<Event>(self.event, "Event")?.clone();
|
||||
if event.immediate || event.stopped_at.is_some_and(|group| group != self.group) {
|
||||
@@ -280,8 +312,8 @@ impl NativeCallable for Delivery {
|
||||
if matches!(self.handler, Handler::ObjectMethod)
|
||||
|| cx
|
||||
.store()
|
||||
.positional_parameter_count(function)?
|
||||
.is_some_and(|count| count > 0)
|
||||
.call_arity(function)?
|
||||
.is_some_and(|arity| arity.accepts(1))
|
||||
{
|
||||
arguments.push(Value::Object(self.event));
|
||||
}
|
||||
@@ -294,6 +326,10 @@ impl NativeCallable for Delivery {
|
||||
#[derive(Debug)]
|
||||
struct Finish(ObjectRef);
|
||||
impl NativeCallable for Finish {
|
||||
fn arity(&self) -> Option<endor_core::CallArity> {
|
||||
Some(endor_core::CallArity::exact(0))
|
||||
}
|
||||
|
||||
fn invoke(&self, cx: &mut NativeContext<'_>, _: &[Value]) -> Result<NativeResult, VmError> {
|
||||
let mut event = cx.store().payload::<Event>(self.0, "Event")?.clone();
|
||||
event.dispatch = None;
|
||||
|
||||
@@ -71,6 +71,19 @@ struct Method {
|
||||
}
|
||||
|
||||
impl NativeCallable for Method {
|
||||
fn arity(&self) -> Option<endor_core::CallArity> {
|
||||
Some(endor_core::CallArity::exact(
|
||||
if matches!(
|
||||
self.query,
|
||||
Query::HitTest | Query::ScrollTo | Query::ScrollBy
|
||||
) {
|
||||
2
|
||||
} else {
|
||||
0
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
fn invoke(&self, cx: &mut NativeContext<'_>, args: &[Value]) -> Result<NativeResult, VmError> {
|
||||
let mount = cx.store().payload::<Mount>(self.owner, "Mount")?.clone();
|
||||
if !mount.mounted
|
||||
@@ -246,6 +259,10 @@ struct LifecycleCall {
|
||||
mount: ObjectRef,
|
||||
}
|
||||
impl NativeCallable for LifecycleCall {
|
||||
fn arity(&self) -> Option<endor_core::CallArity> {
|
||||
Some(endor_core::CallArity::exact(0))
|
||||
}
|
||||
|
||||
fn invoke(&self, _: &mut NativeContext<'_>, _: &[Value]) -> Result<NativeResult, VmError> {
|
||||
Ok(NativeResult::Invoke {
|
||||
function: self.function,
|
||||
@@ -280,6 +297,10 @@ fn lifecycle_call(
|
||||
}
|
||||
|
||||
impl NativeCallable for Sync {
|
||||
fn arity(&self) -> Option<endor_core::CallArity> {
|
||||
Some(endor_core::CallArity::exact(0))
|
||||
}
|
||||
|
||||
fn invoke(&self, cx: &mut NativeContext<'_>, _args: &[Value]) -> Result<NativeResult, VmError> {
|
||||
let mut blocks = HashMap::new();
|
||||
for weak in &self.nodes {
|
||||
|
||||
@@ -81,6 +81,10 @@ struct Method {
|
||||
desktop: ObjectRef,
|
||||
}
|
||||
impl NativeCallable for Method {
|
||||
fn arity(&self) -> Option<endor_core::CallArity> {
|
||||
Some(endor_core::CallArity::exact(3))
|
||||
}
|
||||
|
||||
fn invoke(&self, cx: &mut NativeContext<'_>, args: &[Value]) -> Result<NativeResult, VmError> {
|
||||
let [owner, context, input] = args else {
|
||||
return Err(invalid("visual method expects a Mount and an input value"));
|
||||
@@ -257,6 +261,14 @@ struct PointMethod {
|
||||
circle: bool,
|
||||
}
|
||||
impl NativeCallable for PointMethod {
|
||||
fn arity(&self) -> Option<endor_core::CallArity> {
|
||||
Some(endor_core::CallArity::exact(if self.circle {
|
||||
4
|
||||
} else {
|
||||
2
|
||||
}))
|
||||
}
|
||||
|
||||
fn invoke(&self, cx: &mut NativeContext<'_>, args: &[Value]) -> Result<NativeResult, VmError> {
|
||||
let Some(Value::Object(point)) = args.first() else {
|
||||
return Err(invalid("Point method requires a Point"));
|
||||
|
||||
@@ -28,6 +28,10 @@ impl ObjectPayload for ObjectList {
|
||||
#[derive(Debug)]
|
||||
struct At(ObjectRef);
|
||||
impl NativeCallable for At {
|
||||
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::Number(index)] = args else {
|
||||
return Err(VmError::InvalidArgument("object list at expects an index"));
|
||||
@@ -94,6 +98,10 @@ pub struct Constructor {
|
||||
pub desktop: ObjectRef,
|
||||
}
|
||||
impl NativeCallable for Constructor {
|
||||
fn arity(&self) -> Option<endor_core::CallArity> {
|
||||
Some(endor_core::CallArity::range(1, usize::MAX))
|
||||
}
|
||||
|
||||
fn invoke(&self, cx: &mut NativeContext<'_>, args: &[Value]) -> Result<NativeResult, VmError> {
|
||||
let [Value::Object(definition), values @ ..] = args else {
|
||||
return Err(VmError::InvalidArgument("ObjectList type argument"));
|
||||
@@ -115,6 +123,8 @@ impl NativeCallable for Constructor {
|
||||
.ok_or(VmError::InvalidArgument(
|
||||
"missing ObjectList subclass fields",
|
||||
))?;
|
||||
cx.store()
|
||||
.check_class_field_arguments(*definition, &values[count..])?;
|
||||
let members = values[..count]
|
||||
.iter()
|
||||
.map(|value| {
|
||||
|
||||
@@ -9,6 +9,10 @@ use endor_core::{
|
||||
#[derive(Debug)]
|
||||
struct Boolean;
|
||||
impl NativeCallable for Boolean {
|
||||
fn arity(&self) -> Option<endor_core::CallArity> {
|
||||
Some(endor_core::CallArity::exact(1))
|
||||
}
|
||||
|
||||
fn invoke(&self, _: &mut NativeContext<'_>, args: &[Value]) -> Result<NativeResult, VmError> {
|
||||
let [Value::Bool(value)] = args else {
|
||||
return Err(VmError::InvalidArgument("hitTest must return Bool"));
|
||||
@@ -19,6 +23,10 @@ impl NativeCallable for Boolean {
|
||||
#[derive(Debug)]
|
||||
struct SameTarget;
|
||||
impl NativeCallable for SameTarget {
|
||||
fn arity(&self) -> Option<endor_core::CallArity> {
|
||||
Some(endor_core::CallArity::exact(2))
|
||||
}
|
||||
|
||||
fn invoke(&self, _: &mut NativeContext<'_>, args: &[Value]) -> Result<NativeResult, VmError> {
|
||||
let value = match args {
|
||||
[Value::Object(first), Value::Object(second)] if first == second => {
|
||||
@@ -132,6 +140,10 @@ struct Prepare {
|
||||
desktop: ObjectRef,
|
||||
}
|
||||
impl NativeCallable for Prepare {
|
||||
fn arity(&self) -> Option<endor_core::CallArity> {
|
||||
Some(endor_core::CallArity::exact(0))
|
||||
}
|
||||
|
||||
fn invoke(&self, cx: &mut NativeContext<'_>, _: &[Value]) -> Result<NativeResult, VmError> {
|
||||
let down = selector(cx, &self.candidates, self.press, self.desktop)?;
|
||||
let up = selector(cx, &self.candidates, self.release, self.desktop)?;
|
||||
|
||||
@@ -98,6 +98,10 @@ struct Step {
|
||||
desktop: ObjectRef,
|
||||
}
|
||||
impl NativeCallable for Step {
|
||||
fn arity(&self) -> Option<endor_core::CallArity> {
|
||||
Some(endor_core::CallArity::exact(0))
|
||||
}
|
||||
|
||||
fn invoke(&self, cx: &mut NativeContext<'_>, _: &[Value]) -> Result<NativeResult, VmError> {
|
||||
let mount = cx.store().payload::<Mount>(self.mount, "Mount")?.clone();
|
||||
let definition = cx
|
||||
@@ -258,6 +262,10 @@ struct Collect {
|
||||
desktop: ObjectRef,
|
||||
}
|
||||
impl NativeCallable for Collect {
|
||||
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 pending = if matches!(self.phase, Phase::Measure) {
|
||||
self.plan
|
||||
@@ -403,6 +411,10 @@ struct Prepare {
|
||||
desktop: ObjectRef,
|
||||
}
|
||||
impl NativeCallable for Prepare {
|
||||
fn arity(&self) -> Option<endor_core::CallArity> {
|
||||
Some(endor_core::CallArity::exact(0))
|
||||
}
|
||||
|
||||
fn invoke(&self, cx: &mut NativeContext<'_>, _: &[Value]) -> Result<NativeResult, VmError> {
|
||||
let mut instructions = Vec::new();
|
||||
let mut constants = Vec::new();
|
||||
|
||||
@@ -133,6 +133,10 @@ struct Collect {
|
||||
output: Output,
|
||||
}
|
||||
impl NativeCallable for Collect {
|
||||
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(result)] = args else {
|
||||
return Err(invalid("paint must return a DisplayList"));
|
||||
@@ -168,6 +172,10 @@ struct Prepare {
|
||||
output: Output,
|
||||
}
|
||||
impl NativeCallable for Prepare {
|
||||
fn arity(&self) -> Option<endor_core::CallArity> {
|
||||
Some(endor_core::CallArity::exact(0))
|
||||
}
|
||||
|
||||
fn invoke(&self, cx: &mut NativeContext<'_>, _: &[Value]) -> Result<NativeResult, VmError> {
|
||||
let block_type = named_type(cx.store(), self.desktop, "Block")?;
|
||||
let native = cx
|
||||
|
||||
+12
-3
@@ -196,6 +196,10 @@ struct After {
|
||||
desktop: ObjectRef,
|
||||
}
|
||||
impl NativeCallable for After {
|
||||
fn arity(&self) -> Option<endor_core::CallArity> {
|
||||
Some(endor_core::CallArity::exact(4))
|
||||
}
|
||||
|
||||
fn invoke(&self, cx: &mut NativeContext<'_>, args: &[Value]) -> Result<NativeResult, VmError> {
|
||||
if cx.store().is_read_only() {
|
||||
return Err(invalid(
|
||||
@@ -212,10 +216,11 @@ impl NativeCallable for After {
|
||||
if !cx.store().object(callback)?.payload().is_function() {
|
||||
return Err(invalid("task callback must be a Function"));
|
||||
}
|
||||
if cx
|
||||
if !cx
|
||||
.store()
|
||||
.positional_parameter_count(callback)?
|
||||
.is_some_and(|count| count != 0)
|
||||
.call_arity(callback)?
|
||||
.ok_or(invalid("task callback requires positional metadata"))?
|
||||
.accepts(0)
|
||||
{
|
||||
return Err(invalid("task callback requires zero unbound parameters"));
|
||||
}
|
||||
@@ -323,6 +328,10 @@ struct Method {
|
||||
desktop: ObjectRef,
|
||||
}
|
||||
impl NativeCallable for Method {
|
||||
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] = args else {
|
||||
return Err(invalid("Task methods accept no arguments"));
|
||||
|
||||
+56
-22
@@ -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,
|
||||
|
||||
@@ -113,6 +113,14 @@ struct Method {
|
||||
desktop: ObjectRef,
|
||||
}
|
||||
impl NativeCallable for Method {
|
||||
fn arity(&self) -> Option<endor_core::CallArity> {
|
||||
Some(endor_core::CallArity::exact(match self.operation {
|
||||
Operation::Resize | Operation::MoveTo => 3,
|
||||
Operation::SetTitle => 2,
|
||||
_ => 1,
|
||||
}))
|
||||
}
|
||||
|
||||
fn invoke(&self, cx: &mut NativeContext<'_>, args: &[Value]) -> Result<NativeResult, VmError> {
|
||||
let Some(Value::Object(owner)) = args.first() else {
|
||||
return Err(invalid("Window method requires a Window"));
|
||||
|
||||
Reference in New Issue
Block a user