Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ All benchmarks run the full pipeline: parse → compile → execute. No caching,
| Promise.then (single) | **5.6 µs** | — | — |
| Promise.then chain (×3) | **9.9 µs** | — | — |
| Promise.all (3 promises) | **7.4 µs** | — | — |
| Async `.map()` (3 elements) | **11.6 µs** | — | — |
| Loop (100 iterations) | **77.8 µs** | — | — |
| Fibonacci (n=10, 177 calls) | **138.4 µs** | — | — |
| Snapshot size (typical agent) | **< 2 KB** | N/A | N/A |
Expand Down Expand Up @@ -519,12 +520,13 @@ For detailed logging of generated code, tool calls, and output, see the debug-tr
- Call from Rust, Node.js, Python, or WebAssembly
- Track and limit resources — memory, allocations, stack depth, and wall-clock time
- 30+ string methods, 25+ array methods, plus Math, JSON, Object, and Promise builtins
- Async callbacks in `.map()` and `.forEach()` — each `await` suspends and resumes the VM sequentially

**Cannot do:**

- Run arbitrary npm packages or the full Node.js standard library
- Execute regular expressions (parsing supported, execution is a no-op)
- Provide full `Promise` semantics (`.then()` chains, `Promise.race`, etc.)
- Provide full `Promise` semantics (`Promise.race`, etc.) — `.then()`, `.catch()`, `.finally()`, and `Promise.all` are supported
- Run code that requires `this` in non-class contexts

These are intentional constraints, not bugs. Zapcode targets one use case: **running code written by AI agents** inside a secure, embeddable sandbox.
Expand All @@ -549,6 +551,7 @@ These are intentional constraints, not bugs. Zapcode targets one use case: **run
| Type annotations, interfaces, type aliases | Stripped at parse time |
| String methods (30+) | Supported |
| Array methods (25+, including `map`, `filter`, `reduce`) | Supported |
| Async callbacks in `.map()`, `.forEach()` | Supported |
| Math, JSON, Object, Promise | Supported |
| `import` / `require` / `eval` | Blocked (sandbox) |
| Regular expressions | Parsed, not executed |
Expand Down
14 changes: 14 additions & 0 deletions crates/zapcode-core/benches/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,17 @@ fn promise_all_3() -> zapcode_core::Value {
eval_ts("await Promise.all([Promise.resolve(1), Promise.resolve(2), Promise.resolve(3)])")
.unwrap()
}

#[divan::bench]
fn async_map_3() -> zapcode_core::Value {
eval_ts(
r#"
const items = [1, 2, 3];
items.map(async (x) => {
const doubled = await Promise.resolve(x * 2);
return doubled;
})
"#,
)
.unwrap()
}
5 changes: 4 additions & 1 deletion crates/zapcode-core/src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::compiler::CompiledProgram;
use crate::error::{Result, ZapcodeError};
use crate::sandbox::ResourceLimits;
use crate::value::Value;
use crate::vm::{CallFrame, TryInfo, Vm, VmState};
use crate::vm::{CallFrame, Continuation, TryInfo, Vm, VmState};

/// Internal serializable representation of VM state at a suspension point.
#[derive(Debug, Clone, Serialize, Deserialize)]
Expand All @@ -17,6 +17,7 @@ struct VmSnapshot {
/// User-defined globals only — builtins are re-registered on resume.
globals: Vec<(String, Value)>,
try_stack: Vec<TryInfo>,
continuations: Vec<Continuation>,
stdout: String,
limits: ResourceLimits,
external_functions: Vec<String>,
Expand Down Expand Up @@ -47,6 +48,7 @@ impl ZapcodeSnapshot {
frames: vm.frames.clone(),
globals: user_globals,
try_stack: vm.try_stack.clone(),
continuations: vm.continuations.clone(),
stdout: vm.stdout.clone(),
limits: vm.limits.clone(),
external_functions: vm.external_functions.iter().cloned().collect(),
Expand Down Expand Up @@ -85,6 +87,7 @@ impl ZapcodeSnapshot {
vm_snap.frames,
user_globals,
vm_snap.try_stack,
vm_snap.continuations,
vm_snap.stdout,
vm_snap.limits,
ext_set,
Expand Down
Loading
Loading