feat: protect existing objects during read-only calls and track reads

This commit is contained in:
2026-10-21 14:17:38 +08:00
parent 44a02c9fd6
commit ff49f266a2
11 changed files with 249 additions and 6 deletions
+15
View File
@@ -48,6 +48,21 @@ impl Vm {
self.call_with_limits(function, arguments, ExecutionLimits::default())
}
/// Allow result allocation while rejecting mutations of objects that were
/// already alive on entry. All reads share the call's normal frame budget.
/// Returned read handles are borrowed dependency identities, not owned roots.
pub fn call_read_only_with_limits(
&mut self,
function: ObjectRef,
arguments: &[Value],
limits: ExecutionLimits,
) -> Result<(Value, Vec<ObjectRef>), VmError> {
let scope = self.objects.begin_read_only();
let result = self.call_with_limits(function, arguments, limits);
let reads = self.objects.end_read_only(scope)?;
result.map(|value| (value, reads))
}
pub fn call_with_limits(
&mut self,
function: ObjectRef,