MathInstance.cs 926 B

12345678910111213141516171819202122232425262728293031323334353637
  1. using Jint.Native.Object;
  2. using Jint.Runtime;
  3. using Jint.Runtime.Descriptors.Specialized;
  4. namespace Jint.Native.Math
  5. {
  6. public sealed class MathInstance : ObjectInstance
  7. {
  8. public MathInstance(ObjectInstance prototype)
  9. : base(prototype)
  10. {
  11. }
  12. public override string Class
  13. {
  14. get
  15. {
  16. return "Math";
  17. }
  18. }
  19. public static MathInstance CreateMathObject(Engine engine, ObjectInstance prototype)
  20. {
  21. var math = new MathInstance(prototype);
  22. math.DefineOwnProperty("abs", new ClrDataDescriptor<MathInstance, double>(engine, Abs), false);
  23. return math;
  24. }
  25. private static double Abs(MathInstance thisObject, object[] arguments)
  26. {
  27. var x = TypeConverter.ToNumber(arguments[0]);
  28. return System.Math.Abs(x);
  29. }
  30. }
  31. }