Skip to main content

run_js_calculations

Function run_js_calculations 

Source
pub fn run_js_calculations(
    form: &mut FormTree,
    scripts: &[(FormNodeId, &str)],
    runtime: &mut XfaJsRuntime,
    cancel: Arc<AtomicBool>,
) -> Result<ScriptResult, ScriptError>
Expand description

Execute JavaScript calculate scripts on specific form fields.

This is the application/x-javascript dispatch path. Callers provide an explicit list of (target_field_id, js_script_body) pairs — the language detection happens at a higher layer (the template parser / XFA merger) which knows the contentType of each <script> element.

For each pair the function:

  1. Snapshots all field raw-values into a FieldValues store.
  2. Executes the JS script body via the sandboxed XfaJsRuntime.
  3. Flushes any rawValue mutations back into the FormTree.

Errors from individual scripts are swallowed (best-effort, matching Adobe behaviour). Use the returned ScriptResult to inspect which fields were updated.