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;
 }
コード例 #2
0
 internal override void Compile()
 {
     if (this.binaryCode == null)
     {
         JSParser parser = new JSParser(this.codeContext);
         if (base.ItemType == ((JSVsaItemType) 0x16))
         {
             this.binaryCode = parser.ParseExpressionItem();
         }
         else
         {
             this.binaryCode = parser.Parse();
         }
         if (this.optimize && !parser.HasAborted)
         {
             this.binaryCode.ProcessAssemblyAttributeLists();
             this.binaryCode.PartiallyEvaluate();
         }
         if (base.engine.HasErrors && !base.engine.alwaysGenerateIL)
         {
             throw new EndOfFile();
         }
         if (this.compileToIL)
         {
             this.compiledBlock = this.binaryCode.TranslateToILClass(base.engine.CompilerGlobals).CreateType();
         }
     }
 }
コード例 #3
0
        // Compile this item.
        internal override bool Compile()
        {
            if (parsed == null && sourceText != null)
            {
                Context context = new Context(sourceText);
                context.codebase      = new CodeBase(codebaseOption, this);
                context.codebase.site = engine.Site;
                JSParser parser = new JSParser(context);
                parser.printSupported = engine.printSupported;
                try
                {
                    parsed = parser.ParseSource(false);
                }
                catch (JScriptException e)
                {
#if !CONFIG_SMALL_CONSOLE
                    ScriptStream.Error.WriteLine(e.Message);
#else
                    ScriptStream.WriteLine(e.Message);
#endif
                    return(false);
                }
                if (parser.numErrors > 0)
                {
                    // There were errors that were partially recovered.
                    parsed = null;
                    return(false);
                }
            }
            return(true);
        }
コード例 #4
0
 internal override void CheckForErrors() {
   if (this.compiledClass == null) {
     JSParser p = new JSParser(this.codeContext);
     AST prog = (ScriptBlock)p.Parse();
     //prog.PartiallyEvaluate();
   }
 }
コード例 #5
0
        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();
            }
        }
コード例 #6
0
 internal override void Compile()
 {
     if (this.binaryCode == null)
     {
         JSParser parser = new JSParser(this.codeContext);
         if (base.ItemType == ((JSVsaItemType)0x16))
         {
             this.binaryCode = parser.ParseExpressionItem();
         }
         else
         {
             this.binaryCode = parser.Parse();
         }
         if (this.optimize && !parser.HasAborted)
         {
             this.binaryCode.ProcessAssemblyAttributeLists();
             this.binaryCode.PartiallyEvaluate();
         }
         if (base.engine.HasErrors && !base.engine.alwaysGenerateIL)
         {
             throw new EndOfFile();
         }
         if (this.compileToIL)
         {
             this.compiledBlock = this.binaryCode.TranslateToILClass(base.engine.CompilerGlobals).CreateType();
         }
     }
 }
コード例 #7
0
 public virtual bool ParseNamedBreakPoint(string input, out string functionName, out int nargs, out string arguments, out string returnType, out ulong offset)
 {
     functionName = "";
     nargs        = 0;
     arguments    = "";
     returnType   = "";
     offset       = 0L;
     string[] strArray = new JSParser(this.codeContext).ParseNamedBreakpoint(out nargs);
     if ((strArray == null) || (strArray.Length != 4))
     {
         return(false);
     }
     if (strArray[0] != null)
     {
         functionName = strArray[0];
     }
     if (strArray[1] != null)
     {
         arguments = strArray[1];
     }
     if (strArray[2] != null)
     {
         returnType = strArray[2];
     }
     if (strArray[3] != null)
     {
         offset = ((IConvertible)Microsoft.JScript.Convert.LiteralToNumber(strArray[3])).ToUInt64(null);
     }
     return(true);
 }
コード例 #8
0
ファイル: vsastaticcode.cs プロジェクト: ydunk/masters
 internal override void CheckForErrors()
 {
     if (this.compiledClass == null)
     {
         JSParser p    = new JSParser(this.codeContext);
         AST      prog = (ScriptBlock)p.Parse();
         //prog.PartiallyEvaluate();
     }
 }
コード例 #9
0
ファイル: eval.cs プロジェクト: ArildF/masters
 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();
   }
 }
コード例 #10
0
        // Perform a constructor call on this object.
        internal override Object Construct(VsaEngine engine, Object[] args)
        {
            String    parameters;
            String    body;
            String    defn;
            int       index;
            JSParser  parser;
            JFunction func;

            // Collect up the parameters and body.
            if (args.Length == 0)
            {
                parameters = String.Empty;
                body       = String.Empty;
            }
            else if (args.Length == 1)
            {
                parameters = String.Empty;
                body       = Convert.ToString(args[0]);
            }
            else
            {
                parameters = Convert.ToString(args[0]);
                for (index = 1; index < (args.Length - 1); ++index)
                {
                    parameters =
                        String.Concat(parameters, ",",
                                      Convert.ToString(args[index]));
                }
                body = Convert.ToString(args[args.Length - 1]);
            }

            // Build a complete function definition and parse it.
            defn   = "function (" + parameters + ") { " + body + " }";
            parser = new JSParser(new Context(defn));
            func   = parser.ParseFunctionSource();

            // Build the function object and return it.
            return(new FunctionObject
                       (EngineInstance.GetEngineInstance(engine)
                       .GetFunctionPrototype(), func,
                       engine.GetMainScope()));
        }
コード例 #11
0
ファイル: vsastaticcode.cs プロジェクト: ydunk/masters
 internal void Parse()
 {
     if (this.block == null && this.compiledClass == null)
     {
         GlobalScope glob = (GlobalScope)this.engine.GetGlobalScope().GetObject();
         //Provide for the possibility of forward references to declarations in code blocks yet to come.
         glob.evilScript = !glob.fast || this.engine.GetStaticCodeBlockCount() > 1;
         this.engine.Globals.ScopeStack.Push(glob);
         try{
             JSParser p = new JSParser(this.codeContext);
             this.block = (ScriptBlock)p.Parse();
             if (p.HasAborted)
             {
                 this.block = null;
             }
         }finally{
             this.engine.Globals.ScopeStack.Pop();
         }
     }
 }
コード例 #12
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();
         }
     }
 }
コード例 #13
0
ファイル: functionconstructor.cs プロジェクト: ArildF/masters
 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)Globals.contextEngine.ScriptObjectStackTop()).GetGlobalScope());
   try{
     return (ScriptFunction)p.ParseFunctionExpression().PartiallyEvaluate().Evaluate();
   }finally{
     engine.PopScriptObject();
   }
 }
コード例 #14
0
ファイル: eval.cs プロジェクト: SSCLI/sscli_20021101
 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();
         }
     }
 }
コード例 #15
0
 internal void Parse()
 {
     if ((this.block == null) && (this.compiledClass == null))
     {
         GlobalScope item = (GlobalScope) base.engine.GetGlobalScope().GetObject();
         item.evilScript = !item.fast || (base.engine.GetStaticCodeBlockCount() > 1);
         base.engine.Globals.ScopeStack.Push(item);
         try
         {
             JSParser parser = new JSParser(this.codeContext);
             this.block = parser.Parse();
             if (parser.HasAborted)
             {
                 this.block = null;
             }
         }
         finally
         {
             base.engine.Globals.ScopeStack.Pop();
         }
     }
 }
コード例 #16
0
 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;
 }
コード例 #17
0
 internal void Parse()
 {
     if ((this.block == null) && (this.compiledClass == null))
     {
         GlobalScope item = (GlobalScope)base.engine.GetGlobalScope().GetObject();
         item.evilScript = !item.fast || (base.engine.GetStaticCodeBlockCount() > 1);
         base.engine.Globals.ScopeStack.Push(item);
         try
         {
             JSParser parser = new JSParser(this.codeContext);
             this.block = parser.Parse();
             if (parser.HasAborted)
             {
                 this.block = null;
             }
         }
         finally
         {
             base.engine.Globals.ScopeStack.Pop();
         }
     }
 }
コード例 #18
0
        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);
        }
コード例 #19
0
        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);
        }
コード例 #20
0
 internal void Parse() {
   if (this.block == null && this.compiledClass == null) {
     GlobalScope glob = (GlobalScope)this.engine.GetGlobalScope().GetObject();
     //Provide for the possibility of forward references to declarations in code blocks yet to come.
     glob.evilScript = !glob.fast || this.engine.GetStaticCodeBlockCount() > 1;
     this.engine.Globals.ScopeStack.Push(glob);
     try{
       JSParser p = new JSParser(this.codeContext);
       this.block = (ScriptBlock)p.Parse();
       if (p.HasAborted)
         this.block = null;
     }finally{
       this.engine.Globals.ScopeStack.Pop();
     }
   }
 }
コード例 #21
0
	// Compile this item.
	internal override bool Compile()
			{
				if(parsed == null && sourceText != null)
				{
					Context context = new Context(sourceText);
					context.codebase = new CodeBase(codebaseOption, this);
					context.codebase.site = engine.Site;
					JSParser parser = new JSParser(context);
					parser.printSupported = engine.printSupported;
					try
					{
						parsed = parser.ParseSource(false);
					}
					catch(JScriptException e)
					{
#if !CONFIG_SMALL_CONSOLE
						ScriptStream.Error.WriteLine(e.Message);
#else
						ScriptStream.WriteLine(e.Message);
#endif
						return false;
					}
					if(parser.numErrors > 0)
					{
						// There were errors that were partially recovered.
						parsed = null;
						return false;
					}
				}
				return true;
			}
コード例 #22
0
ファイル: Eval.cs プロジェクト: ForNeVeR/pnet
        // 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);
        }
コード例 #23
0
ファイル: Eval.cs プロジェクト: jjenki11/blaze-chem-rendering
	// 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;
			}
コード例 #24
0
 public virtual bool ParseNamedBreakPoint(string input, out string functionName, out int nargs, out string arguments, out string returnType, out ulong offset)
 {
     functionName = "";
     nargs = 0;
     arguments = "";
     returnType = "";
     offset = 0L;
     string[] strArray = new JSParser(this.codeContext).ParseNamedBreakpoint(out nargs);
     if ((strArray == null) || (strArray.Length != 4))
     {
         return false;
     }
     if (strArray[0] != null)
     {
         functionName = strArray[0];
     }
     if (strArray[1] != null)
     {
         arguments = strArray[1];
     }
     if (strArray[2] != null)
     {
         returnType = strArray[2];
     }
     if (strArray[3] != null)
     {
         offset = ((IConvertible) Microsoft.JScript.Convert.LiteralToNumber(strArray[3])).ToUInt64(null);
     }
     return true;
 }
コード例 #25
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();
        }

      }
コード例 #26
0
	// Perform a constructor call on this object.
	internal override Object Construct(VsaEngine engine, Object[] args)
			{
				String parameters;
				String body;
				String defn;
				int index;
				JSParser parser;
				JFunction func;

				// Collect up the parameters and body.
				if(args.Length == 0)
				{
					parameters = String.Empty;
					body = String.Empty;
				}
				else if(args.Length == 1)
				{
					parameters = String.Empty;
					body = Convert.ToString(args[0]);
				}
				else
				{
					parameters = Convert.ToString(args[0]);
					for(index = 1; index < (args.Length - 1); ++index)
					{
						parameters =
							String.Concat(parameters, ",",
										  Convert.ToString(args[index]));
					}
					body = Convert.ToString(args[args.Length - 1]);
				}

				// Build a complete function definition and parse it.
				defn = "function (" + parameters + ") { " + body + " }";
				parser = new JSParser(new Context(defn));
				func = parser.ParseFunctionSource();

				// Build the function object and return it.
				return new FunctionObject
					(EngineInstance.GetEngineInstance(engine)
						.GetFunctionPrototype(), func,
					 engine.GetMainScope());
			}