EvalFunctionInstance.cs 834 B

123456789101112131415161718192021222324252627
  1. using Jint.Native.Object;
  2. using Jint.Parser;
  3. using Jint.Parser.Ast;
  4. using Jint.Runtime;
  5. using Jint.Runtime.Environments;
  6. namespace Jint.Native.Function
  7. {
  8. public class EvalFunctionInstance: FunctionInstance
  9. {
  10. private readonly Engine _engine;
  11. public EvalFunctionInstance(Engine engine, ObjectInstance prototype, string[] parameters, LexicalEnvironment scope, bool strict) : base(engine, parameters, scope, strict)
  12. {
  13. _engine = engine;
  14. }
  15. public override object Call(object thisObject, object[] arguments)
  16. {
  17. var code = TypeConverter.ToString(arguments[0]);
  18. var parser = new JavaScriptParser();
  19. var program = parser.Parse(code);
  20. return _engine.ExecuteStatement(program).Value ?? Undefined.Instance;
  21. }
  22. }
  23. }