diff --git a/README.md b/README.md index 5df65ab..6d11723 100644 --- a/README.md +++ b/README.md @@ -481,3 +481,9 @@ Typed capability methods cannot be shadowed by instance attributes. Aster checks Aster `ObjectStore::call_effect` queries known native or conservatively proved source effects, including bound methods, without executing the function. Proved source ReadOnly methods constrain known native overrides. Shared local assignment, unresolved dynamic calls and other unproved instructions remain unknown; the runtime read-only barrier still follows actual calls and delegation. This does not establish a full source call graph or prove trusted host I/O safe. Known source call graphs can now be proved ReadOnly using current globals/builtins, closure Cells and resolved receivers. Analysis follows control-flow joins and recursive call graphs with explicit queues, executes no function body and retains no cross-query cache. Rebinding triggers fresh analysis. Unresolved targets/results, shared assignments and calls outside the ReadOnly proof remain unknown; actual runtime barriers and native target checks still apply. + +Native layout/paint fast paths and the default event classification inspect the actual ContextNativeFunction implementation and operation. They do not use the current mutable Block method table as an intrinsic baseline. Replacing a base method or a function payload therefore takes the new implementation path. Visual snapshots depend on each protocol function's version and include it in the protocol key, so payload changes at a stable function identity invalidate cached visuals and interactivity. + +Block.click returns the generated Event and Block.dispatch returns the delivered Event, preserving the event object from the dispatch pipeline. Native return signatures match these actual results, including GUI activation. + +Event dispatch/click and lifecycle entry points publish External as their allowed effect bound: handlers may mutate application state or use host I/O APIs. The built-in no-op bodies do not make the overridable handler contract ReadOnly. These entry points still reject invocation inside read-only rendering. diff --git a/src/README.md b/src/README.md index ce26fcf..73673a8 100644 --- a/src/README.md +++ b/src/README.md @@ -7,10 +7,10 @@ | 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, compiled source/call-graph effect query and rebinding coverage, 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/override checks with deferred typed public/native constructor signatures and split option/field preflight plus shared native arity intervals plus resolved types/unions/effects on methods, tab registry, stable-slot insertion, source-dispatched tab reorder/drop and callback registration checks, Page lifecycle/navigation and immutable frame extraction | +| 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/override checks with deferred typed public/native constructor signatures and split option/field preflight plus shared native arity intervals plus resolved types/unions/effects on methods, tab registry, stable-slot insertion, source-dispatched tab reorder/drop and callback registration checks, Page lifecycle/navigation, Event returns/effect bounds, intrinsic handler recognition 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, typed method attribute validity dependencies, reverse parent links and cached immutable visual derivation | +| snapshot.rs | Property and visual-method identity dependencies across shared field-storage paths, typed method attribute validity and protocol function payload-version dependencies, reverse parent links and cached immutable visual derivation | | mount.rs | Typed per-occurrence methods and nominal Bounds results, managed contexts, weak reverse links, ordered mount/unmount hooks, geometry and focus queries | | events.rs | Bounded native input transport with kind-specific tab-drop/desktop-position metadata to the owning VM | | event_dispatch.rs | Typed Event factory and managed Event/Subscription methods, weak Subscription tokens, Block-owned connections and occurrence-specific capture/target/bubble through a budgeted VM driver | @@ -20,10 +20,10 @@ | tabs.rs | Immutable tab chrome, shared draw/hit geometry, overflow navigation, drag gaps/anchors/insertion markers and opaque published Page identities | | window.rs | Typed native Window queries/effects, construction/close, context ownership, ordered Page roots, read-only guards, Page reordering, physical desktop placement and coalesced GUI projections | | vm_sequence.rs | Shared validated call-sequence builder and EXTENDED_ARG-aware same-frame repetition for layout, event and lifecycle work | -| source_layout.rs | Read-only source layout, repeated constraint/geometry solving with cycle detection, per-Mount measurement caches with subcall dependencies, viewport constraints, typed/slot validation and occurrence geometry | +| source_layout.rs | Read-only source layout, repeated constraint/geometry solving with cycle detection, per-Mount measurement caches with subcall dependencies, viewport constraints, typed/slot validation, concrete intrinsic recognition and occurrence geometry | | source_hit.rs | Read-only source/native pointer target selectors, reverse paint order, strict Bool results and matching press/release targets | -| source_paint.rs | Read-only source paint dispatch, shared VM budget, paired text-wrap bounds and checked command conversion and versioned object dependencies | -| native_visual.rs | Managed native visual protocol queries with resolved type/read-only signatures, occurrence validation, value conversion and bounded results | +| source_paint.rs | Read-only source paint dispatch with concrete intrinsic recognition, shared VM budget, paired text-wrap bounds and checked command conversion and versioned object dependencies | +| native_visual.rs | Managed native visual protocol queries with resolved type/read-only signatures, occurrence validation, concrete implementation/operation identity, value conversion and bounded results | | object_list.rs | Typed factory envelopes, read-only indexed access and traced results shared by Mount queries and visual protocol results | | layout.rs | Shared native geometry/paint functions, iterative measurement/arrangement, stable occurrence IDs, measurement cache, solve-pass counters, geometry budgets and width-sensitive native text measurement | | document.rs | Published source/AST/UI snapshot, revisions, invalidation, frame validation, single-line fault banner (full cause retained in Frame), validated optional text-wrap bounds and display commands | diff --git a/src/api.rs b/src/api.rs index 4658330..106c78c 100644 --- a/src/api.rs +++ b/src/api.rs @@ -1103,9 +1103,9 @@ Declared fields are checked at construction and set_attr writes through the same 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 complete native signature coverage remain separate gaps. See examples/native-signatures.endor. -Native CallSignature checks resolved parameter/return types for visual measure/arrange/paint/hitTest, Point queries, Window/Block/Container/Page/Mount/Task/Event/Subscription methods and ObjectList.at. Signature definitions are traced managed edges. Parameters fail before dispatch; final results delegated to source/native functions must satisfy all pending native return contracts, with rooted definitions and the same frame/instruction budgets. Wrong returns release scoped results but do not undo earlier writes. CallEffect ReadOnly allows result allocation; Delegated allows a read-only native wrapper while delegated targets keep the same VM read-only/budget scope (ui.present); Mutating/External calls are rejected before invocation during read-only execution. Existing heap barriers still apply, and this does not sandbox trusted native I/O. CallType unions preserve every branch definition. Page.open accepts Window or nil; page.window returns Window or nil; Block.on accepts Bool or String for its optional phase, while phase names retain domain validation. Mount relation queries are nullable, and bounds() is a real Bounds object usable by Point.inside. Native union metadata does not add Endor union syntax. Source method overrides now enforce parameter contravariance, return covariance and accepted-count preservation at class creation/method replacement, with call-time rechecks for dynamic annotation names. Ancestor replacement checks overriding descendants atomically. Unknown forward names may defer until invocation; known incompatibilities reject before effects. Native effects may only shrink; source effects remain unknown and runtime read-only barriers still apply. See examples/method-contracts.endor. Public ui functions, captured state methods and native factories publish signatures after the registry exists. Factories check the Type receiver/general result/effect and split native options from requested-class fields before validating both; omitted Rect/Text options and Row/Column variable children cannot absorb subclass fields. Event/ObjectList keep dedicated member/field checks. Generic Type reflection still has no single fixed constructor signature. See examples/constructor-contracts.endor. Source/Delegated transitive effects remain unknown; static inference remains pending. Unknown legacy metadata remains unknown. See examples/visual-protocols.endor and examples/layout-negotiation.endor. +Native CallSignature checks resolved parameter/return types for visual measure/arrange/paint/hitTest, Point queries, Window/Block/Container/Page/Mount/Task/Event/Subscription methods and ObjectList.at. Signature definitions are traced managed edges. Parameters fail before dispatch; final results delegated to source/native functions must satisfy all pending native return contracts, with rooted definitions and the same frame/instruction budgets. Wrong returns release scoped results but do not undo earlier writes. CallEffect ReadOnly allows result allocation; Delegated allows a read-only native wrapper while delegated targets keep the same VM read-only/budget scope (ui.present); Mutating/External calls are rejected before invocation during read-only execution. Block.click returns its generated Event; Block.dispatch returns the delivered Event. Dispatch/click and lifecycle handler contracts permit External effects; the default no-op does not constrain native overrides to ReadOnly. Existing heap barriers still apply, and this does not sandbox trusted native I/O. CallType unions preserve every branch definition. Page.open accepts Window or nil; page.window returns Window or nil; Block.on accepts Bool or String for its optional phase, while phase names retain domain validation. Mount relation queries are nullable, and bounds() is a real Bounds object usable by Point.inside. Native union metadata does not add Endor union syntax. Source method overrides now enforce parameter contravariance, return covariance and accepted-count preservation at class creation/method replacement, with call-time rechecks for dynamic annotation names. Ancestor replacement checks overriding descendants atomically. Unknown forward names may defer until invocation; known incompatibilities reject before effects. Known effects may only shrink; conservative source/call-graph ReadOnly proofs supplement runtime barriers. See examples/method-contracts.endor. Public ui functions, captured state methods and native factories publish signatures after the registry exists. Factories check the Type receiver/general result/effect and split native options from requested-class fields before validating both; omitted Rect/Text options and Row/Column variable children cannot absorb subclass fields. Event/ObjectList keep dedicated member/field checks. Generic Type reflection still has no single fixed constructor signature. See examples/constructor-contracts.endor. Current global/builtins/closure/receiver call graphs may prove ReadOnly without execution; unresolved targets/results, shared writes and Delegated targets remain unknown. Unknown legacy metadata remains unknown. See examples/visual-protocols.endor and examples/layout-negotiation.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/type/known-native-effect 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. These capabilities use typed signatures: registration checks parameter contravariance, return covariance and known native effects. Actual calls recheck dynamic names and final results across delegation, with rooted return definitions. Explicit typed method annotations remain checked even if a different host disables global source checks; concrete implementations keep wider inputs and optional convenience forms. Source static effects and formal trait syntax remain pending. EventTarget requires canonical on/dispatch/onEvent arities 3/2/1 after self; native optional convenience forms remain. +Trait definitions Visual, EventTarget, Children and Presentable are managed nominal capabilities. ui.implement(type,capability) explicitly declares an implementation after required-method/positional-arity/type/known-native-effect 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. These capabilities use typed signatures: registration checks parameter contravariance, return covariance and known native effects. Actual calls recheck dynamic names and final results across delegation, with rooted return definitions. Explicit typed method annotations remain checked even if a different host disables global source checks; concrete implementations keep wider inputs and optional convenience forms. General source effects 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. diff --git a/src/endor_host.rs b/src/endor_host.rs index 8e6b062..afa4af8 100644 --- a/src/endor_host.rs +++ b/src/endor_host.rs @@ -3938,6 +3938,256 @@ page.render(block) ); } + #[test] + fn click_and_dispatch_return_the_actual_delivered_event() { + let mut session = ReplSession::new(237).unwrap(); + session + .execute( + r#"button = Button("event") +clicked = button.click() +dispatched = Event("click") +returned = button.dispatch(dispatched)"#, + "app.main", + ) + .unwrap(); + assert_eq!( + session + .execute("ui.isInstance(clicked, Event)", "app.main") + .unwrap() + .value, + "true" + ); + assert_eq!( + session.execute("clicked.kind", "app.main").unwrap().value, + "\"click\"" + ); + let globals = session.candidate.globals.unwrap(); + assert_eq!( + session + .candidate + .vm + .dict_get(globals, &Value::Text("returned".into())) + .unwrap(), + session + .candidate + .vm + .dict_get(globals, &Value::Text("dispatched".into())) + .unwrap() + ); + } + + #[derive(Debug)] + struct VisualRedirect { + target: ObjectRef, + signature: endor_core::CallSignature, + } + impl endor_core::NativeCallable for VisualRedirect { + fn signature(&self) -> Option { + Some(self.signature.clone()) + } + fn invoke( + &self, + _: &mut endor_core::NativeContext<'_>, + arguments: &[Value], + ) -> std::result::Result { + Ok(endor_core::NativeResult::Invoke { + function: self.target, + arguments: arguments.to_vec(), + }) + } + } + + #[test] + fn native_visual_identity_accepts_shared_window_registries_only() { + let mut session = ReplSession::new(238).unwrap(); + session.execute("second = Window()", "app.main").unwrap(); + let globals = session.candidate.globals.unwrap(); + let Value::Object(window) = session + .candidate + .vm + .dict_get(globals, &Value::Text("second".into())) + .unwrap() + .unwrap() + else { + panic!("window") + }; + let vm = &mut session.candidate.vm; + let desktop = vm + .payload::(window, "Window") + .unwrap() + .desktop; + let block = crate::ui_bridge::desktop_type(vm.object_store(), "Block", desktop).unwrap(); + let function = vm + .object_store() + .lookup_method(block, "measure") + .unwrap() + .unwrap(); + assert!( + crate::native_visual::is_intrinsic(vm.object_store(), function, "measure", desktop) + .unwrap() + ); + assert!( + !crate::native_visual::is_intrinsic(vm.object_store(), function, "paint", desktop) + .unwrap() + ); + let foreign = vm.new_object().unwrap(); + let registry = vm.new_dict().unwrap(); + vm.set_attr(foreign, "types", Value::Object(registry)) + .unwrap(); + assert!( + !crate::native_visual::is_intrinsic(vm.object_store(), function, "measure", foreign) + .unwrap() + ); + vm.release(foreign).unwrap(); + vm.release(registry).unwrap(); + } + + #[test] + fn replacing_base_visual_methods_changes_layout_and_same_identity_paint() { + let (mut session, _) = ReplSession::load(r#" + class Hooks { + function measure(self: Object, mount: Mount, constraints: Constraints): MeasureResult { return MeasureResult(140, 70) } + function paint(self: Object, mount: Mount, geometry: Bounds): DisplayList { return DisplayList(ObjectList()) } + } + base = Block + rect = RectBlock(20, 10) + page = Page() + page.render(rect) + "#, "app.main", 235, 1).unwrap(); + let globals = session.candidate.globals.unwrap(); + let get = |name: &str| match session + .candidate + .vm + .dict_get(globals, &Value::Text(name.into())) + .unwrap() + .unwrap() + { + Value::Object(value) => value, + _ => panic!("object"), + }; + let base = get("base"); + let hooks = get("Hooks"); + let Value::Object(measure) = session.candidate.vm.get_attr(hooks, "measure").unwrap() + else { + panic!("measure") + }; + let Value::Object(paint) = session.candidate.vm.get_attr(hooks, "paint").unwrap() else { + panic!("paint") + }; + session + .candidate + .vm + .define_method(base, "measure", measure) + .unwrap(); + session.refresh_document().unwrap().unwrap(); + assert_eq!( + session + .execute("rect.mounts().at(0).bounds().width", "app.main") + .unwrap() + .value, + "140" + ); + let original = session + .candidate + .vm + .object_store() + .lookup_method(base, "paint") + .unwrap() + .unwrap(); + let signature = session + .candidate + .vm + .object_store() + .native_signature(original) + .unwrap() + .unwrap(); + session + .candidate + .vm + .replace_payload( + original, + endor_core::ContextNativeFunction::new( + "redirect paint", + VisualRedirect { + target: paint, + signature, + }, + vec![paint], + ), + ) + .unwrap(); + let updated = session.refresh_document().unwrap().unwrap(); + assert!(updated.frame.commands.is_empty()); + } + + #[test] + fn same_identity_event_payload_changes_invalidate_interactivity_cache() { + let mut session = ReplSession::new(236).unwrap(); + session + .execute( + r#" + class Hooks { function onEvent(self: Object, event: Event): Unit {} } + base = Block + rect = RectBlock(20, 10) + "#, + "app.main", + ) + .unwrap(); + let globals = session.candidate.globals.unwrap(); + let get = |name: &str| match session + .candidate + .vm + .dict_get(globals, &Value::Text(name.into())) + .unwrap() + .unwrap() + { + Value::Object(value) => value, + _ => panic!("object"), + }; + let base = get("base"); + let hooks = get("Hooks"); + let rect = get("rect"); + let Value::Object(target) = session.candidate.vm.get_attr(hooks, "onEvent").unwrap() else { + panic!("onEvent") + }; + let vm = &mut session.candidate.vm; + let function = vm + .object_store() + .lookup_method(base, "onEvent") + .unwrap() + .unwrap(); + let mut signature = vm + .object_store() + .native_signature(function) + .unwrap() + .unwrap(); + signature.effect = endor_core::CallEffect::Mutating; + let mut cache = crate::snapshot::RenderCache::default(); + let initial = cache.snapshot(vm.object_store(), rect).unwrap(); + assert!(!initial.interactive); + vm.take_changes(); + vm.replace_payload( + function, + endor_core::ContextNativeFunction::new( + "redirect event", + VisualRedirect { target, signature }, + vec![target], + ), + ) + .unwrap(); + cache.invalidate(vm.take_changes()); + let updated = cache.snapshot(vm.object_store(), rect).unwrap(); + assert!(updated.interactive); + assert_ne!(initial.protocol_key, updated.protocol_key); + assert_eq!( + session + .execute("ui.implements(base, EventTarget)", "app.main") + .unwrap() + .value, + "true" + ); + } + #[test] fn source_effect_queries_use_compiled_instructions_without_running_functions() { let mut session = ReplSession::new(234).unwrap(); @@ -4040,7 +4290,7 @@ page.render(block) let mut session = ReplSession::new(233).unwrap(); session .execute( - "rect = RectBlock(40, 20) root = ColumnBlock(0, 0, rect)", + "rect = RectBlock(40, 20)\nroot = ColumnBlock(0, 0, rect)", "app.main", ) .unwrap(); diff --git a/src/native_visual.rs b/src/native_visual.rs index d6417b8..4f0b2b0 100644 --- a/src/native_visual.rs +++ b/src/native_visual.rs @@ -9,7 +9,7 @@ use crate::{ }; use endor_core::{ AnnotationType, CallEffect, CallSignature, ContextNativeFunction, NativeCallable, - NativeContext, NativeResult, ObjectRef, Value, Vm, VmError, + NativeContext, NativeResult, ObjectRef, ObjectStore, Value, Vm, VmError, }; fn invalid(message: &'static str) -> VmError { @@ -87,6 +87,40 @@ struct Method { desktop: ObjectRef, signature: CallSignature, } +/// Only this actual implementation can use the matching intrinsic fast path. +pub(crate) fn is_intrinsic( + store: &ObjectStore, + function: ObjectRef, + name: &str, + desktop: ObjectRef, +) -> Result { + let Some(function) = store + .object(function)? + .payload() + .as_any() + .downcast_ref::() + else { + return Ok(false); + }; + let Some(method) = function.implementation::() else { + return Ok(false); + }; + // Per-window desktops share the same nominal registry and intrinsic bodies. + let same_registry = method.desktop == desktop + || matches!( + (store.get_attr(method.desktop, "types")?, store.get_attr(desktop, "types")?), + (Value::Object(left), Value::Object(right)) if left == right + ); + Ok(same_registry + && matches!( + (name, method.query), + ("measure", Query::Measure) + | ("arrange", Query::Arrange) + | ("paint", Query::Paint) + | ("hitTest", Query::HitTest) + )) +} + impl NativeCallable for Method { fn signature(&self) -> Option { Some(self.signature.clone()) diff --git a/src/snapshot.rs b/src/snapshot.rs index 28646b6..fed10f1 100644 --- a/src/snapshot.rs +++ b/src/snapshot.rs @@ -168,11 +168,15 @@ impl RenderCache { protocol_key.push_str(&definition.to_string()); for name in ["measure", "arrange", "paint", "hitTest", "onEvent"] { if let Some(method) = store.lookup_method(definition, name)? { - protocol_key.push_str(&format!("/{method}")); + let version = store.change_version(method)?; + protocol_key.push_str(&format!("/{method}:{version}")); + dependencies.push(Dependency { + object: method, + property: None, + }); } } let event = store.lookup_method(definition, "onEvent")?; - let mut native_event = None; let mut current = Some(definition); while let Some(definition) = current { dependencies.push(Dependency { @@ -180,18 +184,14 @@ impl RenderCache { property: None, }); let item = store.payload::(definition, "Type")?; - if item.name() == "Block" - && item.base().is_some_and(|base| { - store - .payload::(base, "Type") - .is_ok_and(|base| base.base().is_none()) - }) - { - native_event = store.lookup_method(definition, "onEvent")?; - } current = item.base(); } - custom_event = event.is_some() && event != native_event; + custom_event = event + .map(|function| { + crate::ui_bridge::is_intrinsic_event(store, function).map(|native| !native) + }) + .transpose()? + .unwrap_or(false); } let mut click_connection = false; for connection in &data.subscriptions { diff --git a/src/source_layout.rs b/src/source_layout.rs index fdade96..e3dd816 100644 --- a/src/source_layout.rs +++ b/src/source_layout.rs @@ -119,13 +119,12 @@ impl NativeCallable for Step { .store() .lookup_method(definition, self.phase.method())? .ok_or(invalid("missing layout method"))?; - let native = cx - .store() - .lookup_method( - desktop_type(cx.store(), "Block", self.desktop)?, - self.phase.method(), - )? - .ok_or(invalid("missing native layout method"))?; + let intrinsic = crate::native_visual::is_intrinsic( + cx.store(), + method, + self.phase.method(), + self.desktop, + )?; let (node, children, bounds, native_size) = { let mut plan = self .plan @@ -142,9 +141,9 @@ impl NativeCallable for Step { None }; if matches!(self.phase, Phase::Measure) { - plan.custom_measure[self.index] = method != native; + plan.custom_measure[self.index] = !intrinsic; } - let native_size = if matches!(self.phase, Phase::Measure) && method == native { + let native_size = if matches!(self.phase, Phase::Measure) && intrinsic { let constraints = plan.constraints[self.index]; Some( plan.runtime @@ -152,7 +151,7 @@ impl NativeCallable for Step { .map_err(|_| invalid("native measurement exceeds layout limits"))?, ) } else { - if method != native { + if !intrinsic { plan.custom = true; } if matches!(self.phase, Phase::Measure) { @@ -194,7 +193,7 @@ impl NativeCallable for Step { }; if matches!(self.phase, Phase::Arrange) { plan.runtime.arranged += 1; - plan.custom_arrange[self.index] = method != native; + plan.custom_arrange[self.index] = !intrinsic; } (node, children, bounds, native_size) }; diff --git a/src/source_paint.rs b/src/source_paint.rs index 5baab44..dfe7276 100644 --- a/src/source_paint.rs +++ b/src/source_paint.rs @@ -189,11 +189,6 @@ impl NativeCallable for Prepare { } fn invoke(&self, cx: &mut NativeContext<'_>, _: &[Value]) -> Result { - let block_type = named_type(cx.store(), self.desktop, "Block")?; - let native = cx - .store() - .lookup_method(block_type, "paint")? - .ok_or(invalid("missing native paint"))?; let mut constants = Vec::new(); let mut instructions = Vec::new(); for (id, weak) in &self.mounts { @@ -212,7 +207,7 @@ impl NativeCallable for Prepare { .store() .lookup_method(definition, "paint")? .ok_or(invalid("missing paint method"))?; - if function == native { + if crate::native_visual::is_intrinsic(cx.store(), function, "paint", self.desktop)? { continue; } let bounds = cx.new_object()?; diff --git a/src/ui_bridge.rs b/src/ui_bridge.rs index 8959c34..8a4256b 100644 --- a/src/ui_bridge.rs +++ b/src/ui_bridge.rs @@ -351,13 +351,17 @@ fn method_signature( Move => (vec![Number, Number], Unit, CallEffect::Mutating), Render | Navigate => (vec![nominal("Block")?], Unit, CallEffect::Mutating), OnClick => (vec![Function], Nominal(receiver), CallEffect::Mutating), - OnEvent => (vec![nominal("Event")?], Unit, CallEffect::ReadOnly), - OnMount | OnUnmount => (vec![nominal("Mount")?], Unit, CallEffect::ReadOnly), - Click => (vec![nominal("Mount")?], Unit, CallEffect::Mutating), + OnEvent => (vec![nominal("Event")?], Unit, CallEffect::External), + OnMount | OnUnmount => (vec![nominal("Mount")?], Unit, CallEffect::External), + Click => ( + vec![nominal("Mount")?], + nominal("Event")?, + CallEffect::External, + ), Dispatch => ( vec![nominal("Event")?, nominal("Mount")?], - Unit, - CallEffect::Mutating, + nominal("Event")?, + CallEffect::External, ), MoveWindow => ( vec![nominal("Window")?], @@ -496,6 +500,23 @@ struct TypeMethod { session: Shared, } +pub(crate) fn is_intrinsic_event( + store: &endor_core::ObjectStore, + function: ObjectRef, +) -> Result { + let Some(function) = store + .object(function)? + .payload() + .as_any() + .downcast_ref::() + else { + return Ok(false); + }; + Ok(function + .implementation::() + .is_some_and(|method| matches!(method.operation, Operation::OnEvent))) +} + impl NativeCallable for TypeMethod { fn signature(&self) -> Option { Some(self.signature.clone()) diff --git a/vendor/aster b/vendor/aster index ae821ae..e511e39 160000 --- a/vendor/aster +++ b/vendor/aster @@ -1 +1 @@ -Subproject commit ae821aea2e48544b58cce15e8abd9b2baa567403 +Subproject commit e511e393d98a5d87015dc8c42cfa59a82d48a422