validateCode method

  1. @override
void validateCode(
  1. String code
)
override

Validates that the JavaScript code is safe to execute.

Should check for potentially dangerous operations like:

  • eval()
  • Function constructor
  • Global object access
  • File system operations

Throws JsEvaluationException if code is deemed unsafe.

Implementation

@override
void validateCode(String code) {
  final dangerous = [
    'eval(',
    'Function(',
    'setTimeout(',
    'setInterval(',
    'import(',
    'require(',
  ];

  for (final keyword in dangerous) {
    if (code.contains(keyword)) {
      throw JsEvaluationException('Dangerous code pattern detected: $keyword');
    }
  }
}