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

  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.Reflection;
  20.     using System.Globalization;
  21.    
  22.     internal sealed class JSClosureMethod : JSMethod
  23.     {
  24.         internal MethodInfo method;
  25.        
  26.         internal JSClosureMethod(MethodInfo method) : base(null)
  27.         {
  28.             this.method = method;
  29.         }
  30.        
  31.         internal override object Construct(object[] args)
  32.         {
  33.             throw new JScriptException(JSError.InternalError);
  34.             //should never happen at compile time.
  35.         }
  36.        
  37.         public override MethodAttributes Attributes {
  38.                 //Fool the analysis code to OK calls to this method from static code
  39.             get { return this.method.Attributes & (~MethodAttributes.Virtual) | MethodAttributes.Static; }
  40.         }
  41.        
  42.         public override Type DeclaringType {
  43.             get { return this.method.DeclaringType; }
  44.         }
  45.        
  46.         public override ParameterInfo[] GetParameters()
  47.         {
  48.             return this.method.GetParameters();
  49.         }
  50.        
  51.         internal override MethodInfo GetMethodInfo(CompilerGlobals compilerGlobals)
  52.         {
  53.             if (this.method is JSMethod)
  54.                 return ((JSMethod)this.method).GetMethodInfo(compilerGlobals);
  55.             else
  56.                 return this.method;
  57.         }
  58.        
  59.         internal override object Invoke(object obj, object thisob, BindingFlags options, Binder binder, object[] parameters, CultureInfo culture)
  60.         {
  61.             if (obj is StackFrame)
  62.                 return this.method.Invoke(((StackFrame)((StackFrame)obj).engine.ScriptObjectStackTop()).closureInstance, options, binder, parameters, culture);
  63.             throw new JScriptException(JSError.InternalError);
  64.             //should never happen at compile time.
  65.         }
  66.        
  67.         public override string Name {
  68.             get { return this.method.Name; }
  69.         }
  70.        
  71.         public override Type ReturnType {
  72.             get { return this.method.ReturnType; }
  73.         }
  74.     }
  75.    
  76.    
  77. }

Developer Fusion