evaluate static method

dynamic evaluate(
  1. String code,
  2. Map<String, dynamic> context, {
  3. int timeoutMs = 5000,
})

Evaluates JavaScript code with the given context.

code - JavaScript code to execute context - Variables to expose to JavaScript timeoutMs - Maximum execution time in milliseconds (default: 5000)

Returns the result of the JavaScript evaluation, or null on error.

Example:

final result = JavaScriptEvaluator.evaluate(
  "input === 'magic'",
  {'input': 'magic'},
);
print(result); // true

Implementation

static dynamic evaluate(
  String code,
  Map<String, dynamic> context, {
  int timeoutMs = 5000,
}) {
  return evaluateJS(code, context, timeoutMs: timeoutMs);
}