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

  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 FunctionPrototype : ScriptFunction
  21.     {
  22.         static internal readonly FunctionPrototype ob = new FunctionPrototype(ObjectPrototype.CommonInstance());
  23.         static internal FunctionConstructor _constructor;
  24.        
  25.         internal FunctionPrototype(ScriptObject parent) : base(parent)
  26.         {
  27.             //this.constructor is given a value by the constructor class
  28.         }
  29.        
  30.         internal override object Call(object[] args, object thisob)
  31.         {
  32.             return null;
  33.         }
  34.        
  35.         [JSFunctionAttribute(JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Function_apply)]
  36.         public static object apply(object thisob, object thisarg, object argArray)
  37.         {
  38.             if (!(thisob is ScriptFunction))
  39.                 throw new JScriptException(JSError.FunctionExpected);
  40.             if (thisarg is Missing)
  41.                 thisarg = ((IActivationObject)((ScriptFunction)thisob).engine.ScriptObjectStackTop()).GetDefaultThisObject();
  42.             if (argArray is Missing)
  43.                 return ((ScriptFunction)thisob).Call(new object[0], thisarg);
  44.             if (argArray is ArgumentsObject)
  45.                 return ((ScriptFunction)thisob).Call(((ArgumentsObject)argArray).ToArray(), thisarg);
  46.             if (argArray is ArrayObject)
  47.                 return ((ScriptFunction)thisob).Call(((ArrayObject)argArray).ToArray(), thisarg);
  48.             throw new JScriptException(JSError.InvalidCall);
  49.         }
  50.        
  51.         [JSFunctionAttribute(JSFunctionAttributeEnum.HasThisObject | JSFunctionAttributeEnum.HasVarArgs, JSBuiltin.Function_call)]
  52.         public static object call(object thisob, object thisarg, params object[] args)
  53.         {
  54.             if (!(thisob is ScriptFunction))
  55.                 throw new JScriptException(JSError.FunctionExpected);
  56.             if (thisarg is Missing)
  57.                 thisarg = ((IActivationObject)((ScriptFunction)thisob).engine.ScriptObjectStackTop()).GetDefaultThisObject();
  58.             return ((ScriptFunction)thisob).Call(args, thisarg);
  59.         }
  60.        
  61.         public static FunctionConstructor constructor {
  62.             get { return FunctionPrototype._constructor; }
  63.         }
  64.        
  65.         [JSFunctionAttribute(JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Function_toString)]
  66.         public static string toString(object thisob)
  67.         {
  68.             if (thisob is ScriptFunction)
  69.                 return thisob.ToString();
  70.             else {
  71.                 throw new JScriptException(JSError.FunctionExpected);
  72.             }
  73.         }
  74.     }
  75. }

Developer Fusion