Arguments.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System.Runtime.CompilerServices;
  2. using Jint.Native;
  3. namespace Jint.Runtime;
  4. public static class Arguments
  5. {
  6. public static JsCallArguments Empty => [];
  7. public static JsValue[] From(params JsValue[] o)
  8. {
  9. return o;
  10. }
  11. /// <summary>
  12. /// Returns the arguments at the provided position or Undefined if not present
  13. /// </summary>
  14. /// <param name="args"></param>
  15. /// <param name="index">The index of the parameter to return</param>
  16. /// <param name="undefinedValue">The value to return is the parameter is not provided</param>
  17. /// <returns></returns>
  18. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  19. public static JsValue At(this JsValue[] args, int index, JsValue undefinedValue)
  20. {
  21. return (uint) index < (uint) args.Length ? args[index] : undefinedValue;
  22. }
  23. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  24. public static JsValue At(this JsValue[] args, int index)
  25. {
  26. return At(args, index, JsValue.Undefined);
  27. }
  28. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  29. public static JsCallArguments Skip(this JsValue[] args, int count)
  30. {
  31. var newLength = args.Length - count;
  32. if (newLength <= 0)
  33. {
  34. return [];
  35. }
  36. var array = new JsValue[newLength];
  37. Array.Copy(args, count, array, 0, newLength);
  38. return array;
  39. }
  40. }