public static void PushStackFrameForMethod(object thisob, JSLocalField[] fields, VsaEngine engine)
        {
            Globals           globals = engine.Globals;
            IActivationObject obj2    = (IActivationObject)globals.ScopeStack.Peek();
            string            name    = thisob.GetType().Namespace;
            WithObject        parent  = null;

            if ((name != null) && (name.Length > 0))
            {
                parent = new WithObject(obj2.GetGlobalScope(), new WrappedNamespace(name, engine))
                {
                    isKnownAtCompileTime = true
                };
                parent = new WithObject(parent, thisob);
            }
            else
            {
                parent = new WithObject(obj2.GetGlobalScope(), thisob);
            }
            parent.isKnownAtCompileTime = true;
            Microsoft.JScript.StackFrame item = new Microsoft.JScript.StackFrame(parent, fields, new object[fields.Length], thisob)
            {
                closureInstance = thisob
            };
            globals.ScopeStack.GuardedPush(item);
        }
예제 #2
0
 internal Closure(FunctionObject func, object declaringObject) : base(func.GetParent(), func.name, func.GetNumberOfFormalParameters())
 {
     this.func            = func;
     base.engine          = func.engine;
     base.proto           = new JSPrototypeObject(((ScriptObject)func.proto).GetParent(), this);
     this.enclosing_scope = base.engine.ScriptObjectStackTop();
     this.arguments       = DBNull.Value;
     this.caller          = DBNull.Value;
     this.declaringObject = declaringObject;
     base.noExpando       = func.noExpando;
     if (func.isExpandoMethod)
     {
         Microsoft.JScript.StackFrame frame = new Microsoft.JScript.StackFrame(new WithObject(this.enclosing_scope, declaringObject), new JSLocalField[0], new object[0], null);
         this.enclosing_scope  = frame;
         frame.closureInstance = declaringObject;
     }
 }
 internal Closure(FunctionObject func, object declaringObject) : base(func.GetParent(), func.name, func.GetNumberOfFormalParameters())
 {
     this.func = func;
     base.engine = func.engine;
     base.proto = new JSPrototypeObject(((ScriptObject) func.proto).GetParent(), this);
     this.enclosing_scope = base.engine.ScriptObjectStackTop();
     this.arguments = DBNull.Value;
     this.caller = DBNull.Value;
     this.declaringObject = declaringObject;
     base.noExpando = func.noExpando;
     if (func.isExpandoMethod)
     {
         Microsoft.JScript.StackFrame frame = new Microsoft.JScript.StackFrame(new WithObject(this.enclosing_scope, declaringObject), new JSLocalField[0], new object[0], null);
         this.enclosing_scope = frame;
         frame.closureInstance = declaringObject;
     }
 }
 private object CallASTFunc(object[] args, object thisob, ScriptObject enclosing_scope, Closure calleeClosure, Binder binder, CultureInfo culture)
 {
     object obj7;
     object caller = calleeClosure.caller;
     calleeClosure.caller = this.globals.caller;
     this.globals.caller = calleeClosure;
     object arguments = calleeClosure.arguments;
     ScriptObject obj4 = this.globals.ScopeStack.Peek();
     ArgumentsObject obj5 = (obj4 is Microsoft.JScript.StackFrame) ? ((Microsoft.JScript.StackFrame) obj4).caller_arguments : null;
     Microsoft.JScript.StackFrame item = new Microsoft.JScript.StackFrame(enclosing_scope, this.fields, new object[this.fields.Length], thisob);
     if (this.isMethod && !this.isStatic)
     {
         item.closureInstance = thisob;
     }
     this.globals.ScopeStack.GuardedPush(item);
     try
     {
         this.own_scope.CloseNestedFunctions(item);
         ArgumentsObject obj6 = null;
         if (this.hasArgumentsObject)
         {
             obj6 = new ArgumentsObject(this.globals.globalObject.originalObjectPrototype, args, this, calleeClosure, item, obj5);
             item.localVars[this.argumentsSlotNumber] = obj6;
         }
         item.caller_arguments = obj6;
         calleeClosure.arguments = obj6;
         this.ConvertArguments(args, item.localVars, 0, args.Length, this.formal_parameters.Length, binder, culture);
         Completion completion = (Completion) this.body.Evaluate();
         if (completion.Return)
         {
             return completion.value;
         }
         obj7 = null;
     }
     finally
     {
         this.globals.ScopeStack.Pop();
         calleeClosure.arguments = arguments;
         this.globals.caller = calleeClosure.caller;
         calleeClosure.caller = caller;
     }
     return obj7;
 }
 internal override object Call(object[] args, object thisob, ScriptObject enclosing_scope, Closure calleeClosure, Binder binder, CultureInfo culture)
 {
     object obj7;
     if (this.body != null)
     {
         return this.CallASTFunc(args, thisob, enclosing_scope, calleeClosure, binder, culture);
     }
     object caller = calleeClosure.caller;
     calleeClosure.caller = this.globals.caller;
     this.globals.caller = calleeClosure;
     object arguments = calleeClosure.arguments;
     ScriptObject obj4 = this.globals.ScopeStack.Peek();
     ArgumentsObject obj5 = (obj4 is Microsoft.JScript.StackFrame) ? ((Microsoft.JScript.StackFrame) obj4).caller_arguments : null;
     Microsoft.JScript.StackFrame item = new Microsoft.JScript.StackFrame(enclosing_scope, this.fields, this.must_save_stack_locals ? new object[this.fields.Length] : null, thisob);
     this.globals.ScopeStack.GuardedPush(item);
     ArgumentsObject obj6 = new ArgumentsObject(this.globals.globalObject.originalObjectPrototype, args, this, calleeClosure, item, obj5);
     item.caller_arguments = obj6;
     calleeClosure.arguments = obj6;
     try
     {
         int length = this.formal_parameters.Length;
         int num2 = args.Length;
         if (this.hasArgumentsObject)
         {
             object[] objArray = new object[length + 3];
             objArray[0] = thisob;
             objArray[1] = base.engine;
             objArray[2] = obj6;
             this.ConvertArguments(args, objArray, 3, num2, length, binder, culture);
             return this.method.Invoke(thisob, BindingFlags.SuppressChangeType, null, objArray, null);
         }
         if (!this.isMethod)
         {
             object[] objArray2 = new object[length + 2];
             objArray2[0] = thisob;
             objArray2[1] = base.engine;
             this.ConvertArguments(args, objArray2, 2, num2, length, binder, culture);
             return this.method.Invoke(thisob, BindingFlags.SuppressChangeType, null, objArray2, null);
         }
         if (length == num2)
         {
             this.ConvertArguments(args, args, 0, num2, length, binder, culture);
             return this.method.Invoke(thisob, BindingFlags.SuppressChangeType, null, args, null);
         }
         object[] newargs = new object[length];
         this.ConvertArguments(args, newargs, 0, num2, length, binder, culture);
         obj7 = this.method.Invoke(thisob, BindingFlags.SuppressChangeType, null, newargs, null);
     }
     catch (TargetInvocationException exception)
     {
         throw exception.InnerException;
     }
     finally
     {
         this.globals.ScopeStack.Pop();
         calleeClosure.arguments = arguments;
         this.globals.caller = calleeClosure.caller;
         calleeClosure.caller = caller;
     }
     return obj7;
 }
 internal override object Call(object[] args, object thisob, Binder binder, CultureInfo culture)
 {
     object obj2;
     if (this.body == null)
     {
         return this.Call(args, thisob, this.enclosing_scope, new Closure(this), binder, culture);
     }
     Microsoft.JScript.StackFrame item = new Microsoft.JScript.StackFrame((thisob is JSObject) ? ((JSObject) thisob) : this.enclosing_scope, this.fields, new object[this.fields.Length], thisob);
     if (this.isConstructor)
     {
         item.closureInstance = thisob;
         if (this.superConstructor != null)
         {
             if (this.superConstructorCall == null)
             {
                 if (this.superConstructor is JSConstructor)
                 {
                     this.superConstructor.Invoke(thisob, new object[0]);
                 }
             }
             else
             {
                 ASTList arguments = this.superConstructorCall.arguments;
                 int count = arguments.count;
                 object[] parameters = new object[count];
                 for (int i = 0; i < count; i++)
                 {
                     parameters[i] = arguments[i].Evaluate();
                 }
                 this.superConstructor.Invoke(thisob, BindingFlags.Default, binder, parameters, culture);
             }
         }
         this.globals.ScopeStack.GuardedPush((thisob is JSObject) ? ((JSObject) thisob) : this.enclosing_scope);
         try
         {
             ((ClassScope) this.enclosing_scope).owner.body.EvaluateInstanceVariableInitializers();
         }
         finally
         {
             this.globals.ScopeStack.Pop();
         }
     }
     else if (this.isMethod && !this.isStatic)
     {
         if (!((ClassScope) this.enclosing_scope).HasInstance(thisob))
         {
             throw new JScriptException(JSError.TypeMismatch);
         }
         item.closureInstance = thisob;
     }
     this.globals.ScopeStack.GuardedPush(item);
     try
     {
         this.own_scope.CloseNestedFunctions(item);
         this.ConvertArguments(args, item.localVars, 0, args.Length, this.formal_parameters.Length, binder, culture);
         Completion completion = (Completion) this.body.Evaluate();
         if (completion.Return)
         {
             return completion.value;
         }
         obj2 = null;
     }
     finally
     {
         this.globals.ScopeStack.Pop();
     }
     return obj2;
 }
 public static void PushStackFrameForMethod(object thisob, JSLocalField[] fields, VsaEngine engine)
 {
     Globals globals = engine.Globals;
     IActivationObject obj2 = (IActivationObject) globals.ScopeStack.Peek();
     string name = thisob.GetType().Namespace;
     WithObject parent = null;
     if ((name != null) && (name.Length > 0))
     {
         parent = new WithObject(obj2.GetGlobalScope(), new WrappedNamespace(name, engine)) {
             isKnownAtCompileTime = true
         };
         parent = new WithObject(parent, thisob);
     }
     else
     {
         parent = new WithObject(obj2.GetGlobalScope(), thisob);
     }
     parent.isKnownAtCompileTime = true;
     Microsoft.JScript.StackFrame item = new Microsoft.JScript.StackFrame(parent, fields, new object[fields.Length], thisob) {
         closureInstance = thisob
     };
     globals.ScopeStack.GuardedPush(item);
 }