THPDFQuickJS.Eval

Unit: HPDFQuickJS

Declaration

function Eval(const Script: string): THPDFQuickJSResult; overload;
function Eval(const Script: string; TimeoutMs: Cardinal;
  MaxInterruptChecks: NativeUInt): THPDFQuickJSResult; overload;

Behaviour

Executes JavaScript in the engine context and returns success, value, error text and status

The original overload uses the constructor limits; the additional overload supplies per-evaluation timeout and interrupt bounds while retaining memory, stack and script-size limits

A zero timeout or interrupt limit disables that corresponding evaluation bound; callers enforcing a transaction deadline pass the remaining time instead of restarting a full timeout

The XFA session uses this overload to share one elapsed budget across replay and current execution

The same original timeout and interrupt bounds remain active through final completion-value conversion. If a returned object's toString exceeds a bound or catches the resulting exception, Eval returns qjsTimeLimit or qjsInterruptLimit rather than a successful value; EvalCached applies the same rule without restarting either budget for conversion, including custom Error toString execution while reporting a compile exception

A limit failure discards any partial value and error output before returning the canonical limit diagnostic. Cleanup leaves the engine reusable for a later evaluation with fresh limits

Delphi results and diagnostics use Unicode strings; Free Pascal preserves the bridge UTF-8 bytes and tags the managed string as UTF-8, avoiding conversion through the system ANSI code page

JavaScript arithmetic follows IEEE behaviour for NaN, Infinity, overflow and underflow even when the calling application enables native floating-point traps

The engine temporarily masks floating-point exceptions during initialisation and evaluation, clears flags produced by the engine, and restores the calling thread's original exception mask before returning or propagating an exception; application callbacks invoked after XFA request suspension run with the restored native mask

Native replay fetch failures

When an optional replay provider is installed, infrastructure failures in that new fetch path are latched until the top-level evaluation finishes. A JS catch cannot produce success after host I/O, copied-length disagreement, fetched-script size rejection, allocation failure or an expired fetch deadline

The guard is checked after completion-value conversion as well as script execution, so a returned object's toString cannot swallow a fetch failure. EvalCached applies the same guard; resource failures report qjsResourceError and fetch deadline failures report qjsTimeLimit, with no successful output

The fetch-specific snapshot retains its original deadline through result conversion, while the general evaluation limits independently enforce ordinary nonfetch conversion failures. Replay infrastructure latches retain their dedicated diagnostics and precedence

An unavailable raw field returns undefined, and invalid native getter arguments throw without coercion. Those caller outcomes do not set the infrastructure latch; a Session helper's ordinary unavailable-entry error remains catchable

Related APIs

TXFAJavaScriptSession, HPDFXFAExecuteJavaScriptEvent and Interactive Dynamic XFA Widget Runtime