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

  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.    
  20.     public class ErrorPrototype : JSObject
  21.     {
  22.         public readonly string name;
  23.        
  24.         static internal readonly ErrorPrototype ob = new ErrorPrototype(ObjectPrototype.ob, "Error");
  25.         internal ErrorConstructor _constructor;
  26.        
  27.         internal ErrorPrototype(ScriptObject parent, string name) : base(parent)
  28.         {
  29.             this.name = name;
  30.             //this.constructor is given a value by the constructor class
  31.         }
  32.        
  33.         public ErrorConstructor constructor {
  34.             get { return this._constructor; }
  35.         }
  36.        
  37.         [JSFunctionAttribute(JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Error_toString)]
  38.         public static string toString(object thisob)
  39.         {
  40.             if (thisob is ErrorObject) {
  41.                 string message = ((ErrorObject)thisob).Message;
  42.                 if (message.Length == 0)
  43.                     return LateBinding.GetMemberValue(thisob, "name").ToString();
  44.                 else
  45.                     return LateBinding.GetMemberValue(thisob, "name").ToString() + ": " + message;
  46.             }
  47.             return thisob.ToString();
  48.         }
  49.        
  50.     }
  51. }

Developer Fusion