The Labs \ Source Viewer \ SSCLI \ Microsoft.JScript \ NumberConstructor

  1. // ==++==
  2. //
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. //
  14. // ==--==
  15. namespace Microsoft.JScript
  16. {
  17.    
  18.     using System;
  19.     using System.Diagnostics;
  20.    
  21.     public class NumberConstructor : ScriptFunction
  22.     {
  23.         public const double MAX_VALUE = Double.MaxValue;
  24.         public const double MIN_VALUE = Double.Epsilon;
  25.         //smallest postive value
  26.         public const double NaN = Double.NaN;
  27.         public const double NEGATIVE_INFINITY = Double.NegativeInfinity;
  28.         public const double POSITIVE_INFINITY = Double.PositiveInfinity;
  29.        
  30.         static internal readonly NumberConstructor ob = new NumberConstructor();
  31.        
  32.         private NumberPrototype originalPrototype;
  33.        
  34.         internal NumberConstructor() : base(FunctionPrototype.ob, "Number", 1)
  35.         {
  36.             this.originalPrototype = NumberPrototype.ob;
  37.             NumberPrototype._constructor = this;
  38.             this.proto = NumberPrototype.ob;
  39.         }
  40.        
  41.         internal NumberConstructor(LenientFunctionPrototype parent, LenientNumberPrototype prototypeProp) : base(parent, "Number", 1)
  42.         {
  43.             this.originalPrototype = prototypeProp;
  44.             prototypeProp.constructor = this;
  45.             this.proto = prototypeProp;
  46.             this.noExpando = false;
  47.         }
  48.        
  49.         internal override object Call(object[] args, object thisob)
  50.         {
  51.             if (args.Length == 0)
  52.                 return 0;
  53.             else
  54.                 return Convert.ToNumber(args[0]);
  55.         }
  56.        
  57.         internal NumberObject Construct()
  58.         {
  59.             return new NumberObject(this.originalPrototype, 0.0, false);
  60.         }
  61.        
  62.        
  63.         internal override object Construct(object[] args)
  64.         {
  65.             return this.CreateInstance(args);
  66.         }
  67.        
  68.         internal NumberObject ConstructImplicitWrapper(object arg)
  69.         {
  70.             return new NumberObject(this.originalPrototype, arg, true);
  71.         }
  72.        
  73.         internal NumberObject ConstructWrapper(object arg)
  74.         {
  75.             return new NumberObject(this.originalPrototype, arg, false);
  76.         }
  77.        
  78.         [JSFunctionAttribute(JSFunctionAttributeEnum.HasVarArgs)]
  79.         public new NumberObject CreateInstance(params object[] args)
  80.         {
  81.             if (args.Length == 0)
  82.                 return new NumberObject(this.originalPrototype, 0.0, false);
  83.             else
  84.                 return new NumberObject(this.originalPrototype, Convert.ToNumber(args[0]), false);
  85.         }
  86.        
  87.         public double Invoke(object arg)
  88.         {
  89.             return Convert.ToNumber(arg);
  90.         }
  91.        
  92.     }
  93. }

Developer Fusion