FunctionInstance.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using Jint.Native.Object;
  2. using Jint.Parser.Ast;
  3. using Jint.Runtime.Descriptors;
  4. using Jint.Runtime.Environments;
  5. using System.Collections.Generic;
  6. namespace Jint.Native.Function
  7. {
  8. public abstract class FunctionInstance : ObjectInstance
  9. {
  10. protected FunctionInstance(ObjectInstance prototype, Identifier[] parameters, LexicalEnvironment scope) : base(prototype)
  11. {
  12. Parameters = parameters;
  13. Scope = scope;
  14. }
  15. /// <summary>
  16. /// Executed when a function object is used as a function
  17. /// </summary>
  18. /// <param name="interpreter"></param>
  19. /// <param name="state"></param>
  20. /// <param name="arguments"></param>
  21. /// <returns></returns>
  22. public abstract dynamic Call(Engine interpreter, object thisObject, dynamic[] arguments);
  23. public LexicalEnvironment Scope { get; private set; }
  24. public Identifier[] Parameters { get; private set; }
  25. public bool HasInstance(object instance)
  26. {
  27. var v = instance as ObjectInstance;
  28. if (v == null)
  29. {
  30. return false;
  31. }
  32. while (true)
  33. {
  34. v = v.Prototype;
  35. if (v == null)
  36. {
  37. return false;
  38. }
  39. if (v == this.Prototype)
  40. {
  41. return true;
  42. }
  43. }
  44. return false;
  45. }
  46. public override string Class
  47. {
  48. get
  49. {
  50. return "Function";
  51. }
  52. }
  53. }
  54. }