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

  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.Reflection.Emit;
  21.    
  22.     internal class ConstructorCall : AST
  23.     {
  24.         internal bool isOK;
  25.         internal bool isSuperConstructorCall;
  26.         internal ASTList arguments;
  27.        
  28.         internal ConstructorCall(Context context, ASTList arguments, bool isSuperConstructorCall) : base(context)
  29.         {
  30.             this.isOK = false;
  31.             this.isSuperConstructorCall = isSuperConstructorCall;
  32.             if (arguments == null)
  33.                 this.arguments = new ASTList(context);
  34.             else
  35.                 this.arguments = arguments;
  36.         }
  37.        
  38.         internal override object Evaluate()
  39.         {
  40.             return new Completion();
  41.             //do nothing. The enclosing function will call the constructor
  42.         }
  43.        
  44.         internal override AST PartiallyEvaluate()
  45.         {
  46.             if (!this.isOK) {
  47.                 this.context.HandleError(JSError.NotOKToCallSuper);
  48.                 return this;
  49.             }
  50.             for (int i = 0int n = this.arguments.count; i < n; i++) {
  51.                 this.arguments[i] = this.arguments[i].PartiallyEvaluate();
  52.                 this.arguments[i].CheckIfOKToUseInSuperConstructorCall();
  53.             }
  54.             ScriptObject scope = Globals.ScopeStack.Peek();
  55.             if (!(scope is FunctionScope)) {
  56.                 this.context.HandleError(JSError.NotOKToCallSuper);
  57.                 return this;
  58.             }
  59.             if (!((FunctionScope)scope).owner.isConstructor)
  60.                 this.context.HandleError(JSError.NotOKToCallSuper);
  61.             ((FunctionScope)scope).owner.superConstructorCall = this;
  62.             return this;
  63.         }
  64.        
  65.         internal override AST PartiallyEvaluateAsReference()
  66.         {
  67.             throw new JScriptException(JSError.InternalError);
  68.         }
  69.        
  70.         internal override void TranslateToIL(ILGenerator il, Type rtype)
  71.         {
  72.             //do nothing. The enclosing function will emit the call to the constructor
  73.         }
  74.        
  75.         internal override void TranslateToILInitializer(ILGenerator il)
  76.         {
  77.             //do nothing. The enclosing function will emit the code to initialize
  78.         }
  79.        
  80.     }
  81. }

Developer Fusion