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

  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 sealed class BooleanConstructor : ScriptFunction
  22.     {
  23.         static internal readonly BooleanConstructor ob = new BooleanConstructor();
  24.        
  25.         private BooleanPrototype originalPrototype;
  26.        
  27.         internal BooleanConstructor() : base(FunctionPrototype.ob, "Boolean", 1)
  28.         {
  29.             this.originalPrototype = BooleanPrototype.ob;
  30.             BooleanPrototype._constructor = this;
  31.             this.proto = BooleanPrototype.ob;
  32.         }
  33.        
  34.         internal BooleanConstructor(LenientFunctionPrototype parent, LenientBooleanPrototype prototypeProp) : base(parent, "Boolean", 1)
  35.         {
  36.             this.originalPrototype = prototypeProp;
  37.             prototypeProp.constructor = this;
  38.             this.proto = prototypeProp;
  39.             this.noExpando = false;
  40.         }
  41.        
  42.         internal override object Call(object[] args, object thisob)
  43.         {
  44.             if (args.Length == 0)
  45.                 return false;
  46.             else
  47.                 return Convert.ToBoolean(args[0]);
  48.         }
  49.        
  50.         internal BooleanObject Construct()
  51.         {
  52.             return new BooleanObject(originalPrototype, false, false);
  53.         }
  54.        
  55.         internal override object Construct(object[] args)
  56.         {
  57.             return this.CreateInstance(args);
  58.         }
  59.        
  60.         internal BooleanObject ConstructImplicitWrapper(bool arg)
  61.         {
  62.             return new BooleanObject(originalPrototype, arg, true);
  63.         }
  64.        
  65.         internal BooleanObject ConstructWrapper(bool arg)
  66.         {
  67.             return new BooleanObject(originalPrototype, arg, false);
  68.         }
  69.        
  70.         [JSFunctionAttribute(JSFunctionAttributeEnum.HasVarArgs)]
  71.         public new BooleanObject CreateInstance(params object[] args)
  72.         {
  73.             return new BooleanObject(originalPrototype, args.Length == 0 ? false : Convert.ToBoolean(args[0]), false);
  74.         }
  75.        
  76.         public bool Invoke(object arg)
  77.         {
  78.             return Convert.ToBoolean(arg);
  79.         }
  80.     }
  81. }

Developer Fusion