BuiltInPropertyWrapper.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using System;
  2. using Jint.Native;
  3. using Jint.Native.Function;
  4. using Jint.Native.Object;
  5. namespace Jint.Runtime.Interop
  6. {
  7. /// <summary>
  8. /// Reprensents a Property wrapper for static methods representing built-in properties.
  9. /// </summary>
  10. public sealed class BuiltInPropertyWrapper : FunctionInstance
  11. {
  12. private readonly Engine _engine;
  13. private readonly Delegate _d;
  14. public BuiltInPropertyWrapper(Engine engine, Delegate d, ObjectInstance prototype)
  15. : base(engine, prototype, null, null)
  16. {
  17. _engine = engine;
  18. _d = d;
  19. }
  20. public override object Call(object thisObject, object[] arguments)
  21. {
  22. // initialize Return flag
  23. _engine.CurrentExecutionContext.Return = Undefined.Instance;
  24. // built-in static method must have their first parameter as 'this'
  25. var allArguments = new object[arguments.Length + 1];
  26. allArguments[0] = thisObject;
  27. Array.Copy(arguments, 0, allArguments, 1, arguments.Length);
  28. return _d.DynamicInvoke(allArguments);
  29. }
  30. }
  31. }