ScriptObjectStackTop() public method

public ScriptObjectStackTop ( ) : ScriptObject
return Microsoft.JScript.ScriptObject
 internal ScriptFunction Construct(object[] args, VsaEngine engine)
 {
     ScriptFunction function;
     StringBuilder builder = new StringBuilder("function anonymous(");
     int index = 0;
     int num2 = args.Length - 2;
     while (index < num2)
     {
         builder.Append(Microsoft.JScript.Convert.ToString(args[index]));
         builder.Append(", ");
         index++;
     }
     if (args.Length > 1)
     {
         builder.Append(Microsoft.JScript.Convert.ToString(args[args.Length - 2]));
     }
     builder.Append(") {\n");
     if (args.Length > 0)
     {
         builder.Append(Microsoft.JScript.Convert.ToString(args[args.Length - 1]));
     }
     builder.Append("\n}");
     Context context = new Context(new DocumentContext("anonymous", engine), builder.ToString());
     JSParser parser = new JSParser(context);
     engine.PushScriptObject(((IActivationObject) engine.ScriptObjectStackTop()).GetGlobalScope());
     try
     {
         function = (ScriptFunction) parser.ParseFunctionExpression().PartiallyEvaluate().Evaluate();
     }
     finally
     {
         engine.PopScriptObject();
     }
     return function;
 }
 public static void JScriptPackage(string rootName, VsaEngine engine)
 {
     GlobalScope globalScope = ((IActivationObject) engine.ScriptObjectStackTop()).GetGlobalScope();
     if (globalScope.GetLocalField(rootName) == null)
     {
         FieldInfo info = globalScope.AddNewField(rootName, Namespace.GetNamespace(rootName, engine), FieldAttributes.Literal | FieldAttributes.Public);
     }
 }
Exemplo n.º 3
0
 public static void JScriptImport(String name, VsaEngine engine){
   int dotPos = name.IndexOf('.');
   String rootName = dotPos > 0 ? name.Substring(0, dotPos) : name;
   GlobalScope scope = ((IActivationObject)engine.ScriptObjectStackTop()).GetGlobalScope();
   FieldInfo field = scope.GetLocalField(rootName);
   if (field == null)
     field = scope.AddNewField(rootName, Namespace.GetNamespace(rootName, engine), FieldAttributes.Public|FieldAttributes.Literal);
   engine.SetEnclosingContext(new WrappedNamespace(name, engine, false));
 }
 public static void JScriptImport(string name, VsaEngine engine)
 {
     int index = name.IndexOf('.');
     string str = (index > 0) ? name.Substring(0, index) : name;
     GlobalScope globalScope = ((IActivationObject) engine.ScriptObjectStackTop()).GetGlobalScope();
     if (globalScope.GetLocalField(str) == null)
     {
         FieldInfo info = globalScope.AddNewField(str, Namespace.GetNamespace(str, engine), FieldAttributes.Literal | FieldAttributes.Public);
     }
     engine.SetEnclosingContext(new WrappedNamespace(name, engine, false));
 }
Exemplo n.º 5
0
		public static FunctionObject JScriptFunctionExpression (RuntimeTypeHandle handle, string name,
									string methodName, string [] formalParams,
									JSLocalField [] fields, bool mustSaveStackLocals, 
									bool hasArgumentsObject, string text,
									VsaEngine engine)
		{
			MethodInfo method = engine.ScriptObjectStackTop ().GetType ().GetMethod (methodName);
			FunctionObject fun = new FunctionObject (method);
			fun.source = text;
			fun.vsa_engine = engine;
			return fun;
		}
 public static object GetClosureInstance(VsaEngine engine)
 {
     if (engine != null)
     {
         StackFrame frame = engine.ScriptObjectStackTop() as StackFrame;
         if (frame != null)
         {
             return frame.closureInstance;
         }
     }
     return null;
 }
Exemplo n.º 7
0
		public static Closure JScriptFunctionDeclaration (RuntimeTypeHandle handle, string name, 
								  string methodName, string [] formalParameters,
								  JSLocalField [] fields, bool mustSaveStackLocals,
								  bool hasArgumentsObjects, string text, 
								  Object declaringObject, VsaEngine engine)
		{
			FunctionObject f = new FunctionObject (name, null, null, null, null);
			f.source = text;
			MethodInfo method = engine.ScriptObjectStackTop ().GetType ().GetMethod (methodName);
			f.method = method;
			f.vsa_engine = engine;
			return new Closure (f);
		}
Exemplo n.º 8
0
	// Push into a "with" scope and return the converted object.
	public static Object JScriptWith(Object withOb, VsaEngine engine)
			{
				withOb = Convert.ToObject(withOb, engine);
				if(withOb != null)
				{
					engine.PushScriptObjectChecked
						(new WithScope(engine.ScriptObjectStackTop(), withOb));
					return withOb;
				}
				else
				{
					throw new JScriptException(JSError.ObjectExpected);
				}
			}
Exemplo n.º 9
0
 public static Object JScriptEvaluate(Object source, VsaEngine engine){
   if (Convert.GetTypeCode(source) != TypeCode.String)
     return source;
   if (engine.doFast)
     engine.PushScriptObject(new BlockScope(engine.ScriptObjectStackTop()));
   try{
     Context context = new Context(new DocumentContext("eval code", engine), ((IConvertible)source).ToString());
     JSParser p = new JSParser(context);
     return ((Completion)p.ParseEvalBody().PartiallyEvaluate().Evaluate()).value;
   }finally{
     if (engine.doFast)
       engine.PopScriptObject();
   }
 }
 internal ScriptFunction Construct(Object[] args, VsaEngine engine){
   StringBuilder func_string = new StringBuilder("function anonymous(");
   for (int i = 0, n = args.Length-2; i < n; i++){
     func_string.Append(Convert.ToString(args[i]));
     func_string.Append(", ");
   }
   if (args.Length > 1)
     func_string.Append(Convert.ToString(args[args.Length-2]));
   func_string.Append(") {\n");
   if (args.Length > 0)
     func_string.Append(Convert.ToString(args[args.Length-1]));
   func_string.Append("\n}");
   Context context = new Context(new DocumentContext("anonymous", engine), func_string.ToString());
   JSParser p = new JSParser(context);
   engine.PushScriptObject(((IActivationObject)engine.ScriptObjectStackTop()).GetGlobalScope());
   try{
     return (ScriptFunction)p.ParseFunctionExpression().PartiallyEvaluate().Evaluate();
   }finally{
     engine.PopScriptObject();
   }
 }
 private static object DoEvaluate(object source, VsaEngine engine, bool isUnsafe)
 {
     object obj2;
     if (engine.doFast)
     {
         engine.PushScriptObject(new BlockScope(engine.ScriptObjectStackTop()));
     }
     try
     {
         Context context = new Context(new DocumentContext("eval code", engine), ((IConvertible) source).ToString());
         JSParser parser = new JSParser(context);
         obj2 = ((Completion) parser.ParseEvalBody().PartiallyEvaluate().Evaluate()).value;
     }
     finally
     {
         if (engine.doFast)
         {
             engine.PopScriptObject();
         }
     }
     return obj2;
 }
Exemplo n.º 12
0
 public static void PushHandlerScope(VsaEngine engine, String id, int scopeId){
   engine.PushScriptObject(new BlockScope(engine.ScriptObjectStackTop(), id, scopeId));
 }
Exemplo n.º 13
0
	public override Object Eval(VsaEngine engine)
#line 322 "./Nodes/JNode.tc"
	{
		// Get the scope to declare the function within.
		ScriptObject scope = engine.ScriptObjectStackTop();
	
		// Create a function object to wrap up this function.
		FunctionObject obj = new FunctionObject
			(EngineInstance.GetEngineInstance(engine).GetFunctionPrototype(),
			 this, scope);
		
		// javascript allows for anonymous functions
		if(name != null)
		{
			// Add the function to the scope.
			if(scope is IVariableAccess)
			{
				((IVariableAccess)scope).SetVariable(name, obj);
			}
			else
			{
				scope.Put(name, obj);
			}
		}
	
		// Return compiled function object
		return obj;
	}
Exemplo n.º 14
0
	// Evaluate a JScript expression in the context of a specific engine.
	public static Object JScriptEvaluate(Object source, VsaEngine engine)
			{
				Object value = null;

				// Bail out if we weren't supplied a string.
				if(!(source is String))
				{
					return source;
				}

				// Parse the "eval" statement.
				Context context = new Context((String)source);
				context.codebase = new CodeBase("eval code", null);
				JSParser parser = new JSParser(context);
				JNode node = parser.ParseSource(true);

				// Push a scope for use during evaluation.
				engine.PushScriptObject
					(new BlockScope(engine.ScriptObjectStackTop(),
									new JSObject (null, engine)));

				// Evaluate the statement.
				try
				{
					value = node.Eval(engine);
					if(value == Empty.Value)
					{
						value = null;
					}
				}
				catch(JScriptException e)
				{
					// Attach the context information to low-level exceptions.
					if(e.context == null)
					{
						e.context = context;
					}
					throw;
				}
				catch(BreakJumpOut brk)
				{
					// "break" used incorrectly.
					throw new JScriptException(JSError.BadBreak, brk.context);
				}
				catch(ContinueJumpOut cont)
				{
					// "continue" used incorrectly.
					throw new JScriptException(JSError.BadContinue,
											   cont.context);
				}
				catch(ReturnJumpOut ret)
				{
					// "return" used incorrectly.
					throw new JScriptException(JSError.BadReturn, ret.context);
				}
				finally
				{
					// Pop the script scope.
					engine.PopScriptObject();
				}

				// Return the result of the evaluation to the caller.
				return value;
			}
Exemplo n.º 15
0
	public override Object GetAndPrepare(VsaEngine engine, ref Object data1, ref Object data2)
#line 130 "./Nodes/JExpr.tc"
	{
		IVariableAccess scope = (engine.ScriptObjectStackTop() as IVariableAccess);
		while(scope != null)
		{
			if(scope.HasVariable(name))
			{
				data1 = scope;
				return scope.GetVariable(name);
			}
			scope = scope.GetParentScope();
		}
		scope = (IVariableAccess)(engine.GetMainScope());
		data1 = scope;
		return scope.GetVariable(name);
	}
Exemplo n.º 16
0
	public override Object Eval(VsaEngine engine)
#line 97 "./Nodes/JExpr.tc"
	{
		IVariableAccess scope = (engine.ScriptObjectStackTop() as IVariableAccess);
		while(scope != null)
		{
			if(scope.HasVariable(name))
			{
				return scope.GetVariable(name);
			}
			scope = scope.GetParentScope();
		}
		return ((IVariableAccess)(engine.GetMainScope())).GetVariable(name);
	}
Exemplo n.º 17
0
	public override Object Eval(VsaEngine engine)
#line 82 "./Nodes/JExpr.tc"
	{
		IActivationObject act =
			(engine.ScriptObjectStackTop() as IActivationObject);
		if(act != null)
		{
			return act.GetDefaultThisObject();
		}
		else
		{
			return DBNull.Value;
		}
	}
Exemplo n.º 18
0
	public override Object Eval(VsaEngine engine)
#line 476 "./Nodes/JStmt.tc"
	{
		// Get the current variable definition scope.
		IActivationObject scope =
			(IActivationObject)(engine.ScriptObjectStackTop());
	
		// We can take a short-cut if the scope implements "IVariableAccess".
		// This avoids creating unnecessary "FieldInfo" objects.
		IVariableAccess varAccess = (scope as IVariableAccess);
		if(varAccess != null)
		{
			if(initializer != null)
			{
				varAccess.SetVariable(name, initializer.Eval(engine));
			}
			else
			{
				varAccess.DeclareVariable(name);
			}
			return name;
		}
	
		// Get the field reference for the variable.
		FieldInfo field = scope.GetLocalField(name);
		if(field == null)
		{
			// Create a new field within the activation object with this name.
			// TODO
		}
		if(initializer != null)
		{
			// Set the variable to the specified initializer value.
			// TODO
		}
	
		// Return the name of the variable as the node's final value.
		return name;
	}
Exemplo n.º 19
0
 public static void JScriptPackage(String rootName, VsaEngine engine){
   GlobalScope scope = ((IActivationObject)engine.ScriptObjectStackTop()).GetGlobalScope();
   FieldInfo field = scope.GetLocalField(rootName);
   if (field == null)
     field = scope.AddNewField(rootName, Namespace.GetNamespace(rootName, engine), FieldAttributes.Public|FieldAttributes.Literal);
 }
 public object Call(object[] arguments, bool construct, bool brackets, VsaEngine engine)
 {
     object obj2;
     try
     {
         if (this.name == null)
         {
             return CallValue(this.obj, arguments, construct, brackets, engine, ((IActivationObject) engine.ScriptObjectStackTop()).GetDefaultThisObject(), JSBinder.ob, null, null);
         }
         obj2 = this.Call(JSBinder.ob, arguments, null, null, null, construct, brackets, engine);
     }
     catch (TargetInvocationException exception)
     {
         throw exception.InnerException;
     }
     return obj2;
 }
Exemplo n.º 21
0
      private static Object DoEvaluate(Object source, VsaEngine engine, bool isUnsafe){
        if (engine.doFast)
          engine.PushScriptObject(new BlockScope(engine.ScriptObjectStackTop()));
        try{
          Context context = new Context(new DocumentContext("eval code", engine), ((IConvertible)source).ToString());
          JSParser p = new JSParser(context);
          if (!isUnsafe)
            new SecurityPermission(SecurityPermissionFlag.Execution).PermitOnly();
          return ((Completion)p.ParseEvalBody().PartiallyEvaluate().Evaluate()).value;
        }finally{
          if (engine.doFast)
            engine.PopScriptObject();
        }

      }
Exemplo n.º 22
0
 private static object DefaultThisObject(VsaEngine engine)
 {
     Debug.Assert(engine != null);
     return ((IActivationObject) engine.ScriptObjectStackTop()).GetDefaultThisObject();
 }
Exemplo n.º 23
0
 public Object Call(Object[] arguments, bool construct, bool brackets, VsaEngine engine){
   try{
     if (this.name == null)
       //Happens when (non simple expr)(args) is evaluated from Eval or the Debugger
       return LateBinding.CallValue(this.obj, arguments, construct, brackets, engine,
         ((IActivationObject)engine.ScriptObjectStackTop()).GetDefaultThisObject(), JSBinder.ob, null, null);
     else
       return this.Call(JSBinder.ob, arguments, null, null, null, construct, brackets, engine);
   }catch(TargetInvocationException e){
     throw e.InnerException;
   }
 }