Example #1
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);
        }
	// 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;
			}
Example #3
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);
        }
Example #4
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;
			}