Пример #1
0
 /// <summary>
 /// http://www.ecma-international.org/ecma-262/5.1/#sec-12.13
 /// </summary>
 /// <param name="throwStatement"></param>
 /// <returns></returns>
 public Completion ExecuteThrowStatement(ThrowStatement throwStatement)
 {
     var exprRef = _engine.EvaluateExpression(throwStatement.Argument);
     Completion c = new Completion(Completion.Throw, _engine.GetValue(exprRef), null);
     c.Location = throwStatement.Location;
     return c;
 }
Пример #2
0
        /// <summary>
        /// http://www.ecma-international.org/ecma-262/5.1/#sec-12.10
        /// </summary>
        /// <param name="withStatement"></param>
        /// <returns></returns>
        public Completion ExecuteWithStatement(WithStatement withStatement)
        {
            var val = _engine.EvaluateExpression(withStatement.Object);
            var obj = TypeConverter.ToObject(_engine, _engine.GetValue(val));
            var oldEnv = _engine.ExecutionContext.LexicalEnvironment;
            var newEnv = LexicalEnvironment.NewObjectEnvironment(_engine, obj, oldEnv, true);
            _engine.ExecutionContext.LexicalEnvironment = newEnv;

            Completion c;
            try
            {
                c = ExecuteStatement(withStatement.Body);
            }
            catch (JavaScriptException e)
            {
                c = new Completion(Completion.Throw, e.Error, null);
                c.Location = withStatement.Location;
            }
            finally
            {
                _engine.ExecutionContext.LexicalEnvironment = oldEnv;
            }

            return c;
        }
Пример #3
0
        public Completion ExecuteStatementList(IEnumerable<Statement> statementList)
        {
            var c = new Completion(Completion.Normal, null, null);
            Completion sl = c;
            Statement s = null;

            try
            {
                foreach (var statement in statementList)
                {
                    s = statement;
                    c = ExecuteStatement(statement);
                    if (c.Type != Completion.Normal)
                    {
                        return new Completion(c.Type, c.Value != null ? c.Value : sl.Value, c.Identifier)
                        {
                            Location = c.Location
                        };
                    }

                    sl = c;
                }
            }
            catch(JavaScriptException v)
            {
                c = new Completion(Completion.Throw, v.Error, null);
                c.Location = s.Location;
                return c;
            }

            return new Completion(c.Type, c.GetValueOrDefault(), c.Identifier);
        }
Пример #4
0
        public Completion ExecuteStatementList(IList<Statement> statementList)
        {
            var c = new Completion(Completion.Normal, null, null);
            Completion sl = c;
            Statement s = null;

            try
            {
                for (var i = 0; i < statementList.Count; i++)
                {
                    s = statementList[i];
                    c = ExecuteStatement(s);
                    if (c.Type != Completion.Normal)
                    {
                        return new Completion(c.Type, c.Value.HasValue ? c.Value : sl.Value, c.Identifier)
                        {
                            Location = c.Location
                        };
                    }

                    sl = c;
                }
            }
            catch (JavaScriptException v)
            {
                c = new Completion(Completion.Throw, v.Error, null);
                if (s != null)
                    c.Location = s.Location;
                return c;
            }

            return new Completion(c.Type, c.GetValueOrDefault(), c.Identifier);
        }