GlobalObject.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using Jint.Native.Object;
  2. using Jint.Runtime;
  3. using Jint.Runtime.Descriptors;
  4. using Jint.Runtime.Descriptors.Specialized;
  5. namespace Jint.Native.Global
  6. {
  7. public sealed class GlobalObject : ObjectInstance
  8. {
  9. private GlobalObject(ObjectInstance prototype)
  10. : base(prototype)
  11. {
  12. }
  13. public static GlobalObject CreateGlobalObject(Engine engine, ObjectInstance prototype)
  14. {
  15. var global = new GlobalObject(prototype);
  16. // Global object properties
  17. global.DefineOwnProperty("NaN", new DataDescriptor(double.NaN), false);
  18. global.DefineOwnProperty("Infinity", new DataDescriptor(double.PositiveInfinity), false);
  19. global.DefineOwnProperty("undefined", new DataDescriptor(Undefined.Instance), false);
  20. // Global object functions
  21. global.DefineOwnProperty("isNaN", new ClrDataDescriptor<object, bool>(engine, IsNaN), false);
  22. return global;
  23. }
  24. private static bool IsNaN(object thisObject, object[] arguments)
  25. {
  26. var x = TypeConverter.ToNumber(arguments[0]);
  27. return double.IsNaN(x);
  28. }
  29. }
  30. }