EvalFunctionInstance.cs 997 B

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