protected override PExpr DoVisit()
 {
     if (IsPendingOrSignal(ref _try, Expr.TryExpr))
     {
         RuntimeError e = _try.AsErrorResult;
         if (e == null || !e.IsCatchable)
         {
             return(PendingOrSignal(_try));
         }
         if (!_catching)
         {
             if (Expr.ExceptionParameter != null)
             {
                 // There can be no error when setting a standard, variable, RefRuntimeObject.
                 Visitor.ScopeManager.Register(Expr.ExceptionParameter).SetValue(Expr.ExceptionParameter, e.ThrownValue);
             }
             Visitor.FirstChanceError = null;
             _catching = true;
         }
         if (IsPendingOrSignal(ref _catch, Expr.CatchExpr))
         {
             return(PendingOrSignal(_catch));
         }
     }
     return(SetResult(RuntimeObj.Undefined));
 }
            /// <summary>
            /// Updates the status based on the current <see cref="PExpr"/>.
            /// </summary>
            /// <param name="r">The current <see cref="PExpr"/>.</param>
            internal protected virtual void UpdateStatus(PExpr r)
            {
                _error  = (_result = r.Result) as RuntimeError;
                _status = ScriptEngineStatus.None;
                if (r.AsErrorResult != null)
                {
                    _status |= ScriptEngineStatus.IsError;
                }
                if (r.IsPending)
                {
                    Debug.Assert(r.DeferredStatus != PExpr.DeferredKind.None);
                    switch (r.DeferredStatus)
                    {
                    case PExpr.DeferredKind.Timeout: _status |= ScriptEngineStatus.Timeout; break;

                    case PExpr.DeferredKind.Breakpoint: _status |= ScriptEngineStatus.Breakpoint; break;

                    case PExpr.DeferredKind.AsyncCall: _status |= ScriptEngineStatus.AsyncCall; break;

                    case PExpr.DeferredKind.FirstChanceError: _status |= ScriptEngineStatus.FirstChanceError; break;

                    default: Debug.Fail("UpdateStatus"); break;
                    }
                }
                else
                {
                    _status |= ScriptEngineStatus.IsFinished;
                }
            }
Example #3
0
 internal PExpr StepOver(Frame f, StepOverKind kind)
 {
     if (!f.IsResolved)
     {
         RuntimeError fError = null;
         if (kind != StepOverKind.InternalStepOver)
         {
             fError       = _firstChanceError;
             _breakOnNext = kind == StepOverKind.ExternalStepIn;
             if (_hasTimeout)
             {
                 _timeLimit = DateTime.UtcNow + _timeout;
             }
         }
         do
         {
             Debug.Assert(Frames.Contains(f));
             if (fError != null)
             {
                 PExpr r = _currentFrame.SetResult(fError);
                 _currentFrame.DoDispose();
                 fError = null;
             }
             else
             {
                 PExpr r = _currentFrame.VisitAndClean();
                 if (r.IsPending)
                 {
                     return(r);
                 }
             }
         }while(!f.IsResolved);
     }
     return(new PExpr(f.Result));
 }
 protected override PExpr DoVisit()
 {
     if (IsPendingOrSignal(ref _try, Expr.TryExpr))
     {
         RuntimeError e = _try.AsErrorResult;
         if (e == null || !e.IsCatchable)
         {
             return(PendingOrSignal(_try));
         }
         if (!_catching)
         {
             if (Expr.ExceptionParameter != null)
             {
                 _visitor.ScopeManager.Register(Expr.ExceptionParameter).Value = e.ThrownValue;
             }
             _visitor.FirstChanceError = null;
             _catching = true;
         }
         if (IsPendingOrSignal(ref _catch, Expr.CatchExpr))
         {
             return(PendingOrSignal(_catch));
         }
     }
     return(SetResult(RuntimeObj.Undefined));
 }
 /// <summary>
 /// Resets the current execution. This frees the <see cref="ScriptEngine"/>: new calls to its <see cref="G:ScriptEngine.Execute"/> can be made.
 /// </summary>
 public void Dispose()
 {
     if (_visitor != null)
     {
         _engine.StopExecution();
         _error   = null;
         _result  = null;
         _status  = ScriptEngineStatus.None;
         _visitor = null;
     }
 }
Example #6
0
            public virtual PExpr SetResult(RuntimeObj result)
            {
                Debug.Assert(_result == null);
                RuntimeError e = result as RuntimeError;

                if (e != null && !(e.Expr is SyntaxErrorExpr) && Visitor.EnableFirstChanceError)
                {
                    Visitor.FirstChanceError = e;
                    return(new PExpr(this, PExprKind.FirstChanceError));
                }
                return(new PExpr((_result = result)));
            }
 /// <summary>
 /// Updates the status based on the current <see cref="PExpr"/>.
 /// </summary>
 /// <param name="r">The current <see cref="PExpr"/>.</param>
 protected internal virtual void UpdateStatus( PExpr r )
 {
     _error = (_result = r.Result) as RuntimeError;
     _status = ScriptEngineStatus.None;
     if( r.AsErrorResult != null ) _status |= ScriptEngineStatus.IsError;
     if( r.IsPending )
     {
         Debug.Assert( r.DeferredStatus != PExpr.DeferredKind.None );
         switch( r.DeferredStatus )
         {
             case PExpr.DeferredKind.Timeout: _status |= ScriptEngineStatus.Timeout; break;
             case PExpr.DeferredKind.Breakpoint: _status |= ScriptEngineStatus.Breakpoint; break;
             case PExpr.DeferredKind.AsyncCall: _status |= ScriptEngineStatus.AsyncCall; break;
             case PExpr.DeferredKind.FirstChanceError: _status |= ScriptEngineStatus.FirstChanceError; break;
             default: Debug.Fail( "UpdateStatus" ); break;
         }
     }
     else _status |= ScriptEngineStatus.IsFinished;
 }
 /// <summary>
 /// Resets the current execution. This frees the <see cref="ScriptEngine"/>: new calls to its <see cref="G:ScriptEngine.Execute"/> can be made. 
 /// </summary>
 public void Dispose()
 {
     if( _visitor != null )
     {
         _engine.StopExecution();
         _error = null;
         _result = null;
         _status = ScriptEngineStatus.None;
         _visitor = null;
     }
 }
Example #9
0
 public void ResetCurrentEvaluation()
 {
     _firstFrame       = _currentFrame = null;
     _firstChanceError = null;
 }
Example #10
0
            protected override PExpr DoVisit()
            {
                if (IsPendingOrSignal(ref _expression, Expr.Expression))
                {
                    RuntimeError e = _expression.AsErrorResult;
                    if (e != null &&
                        e.IsReferenceError &&
                        ((int)Expr.TokenType & 15) == ((int)TokenizerToken.TypeOf & 15))
                    {
                        return(SetResult(StringObj.Create(RuntimeObj.TypeUndefined)));
                    }
                    return(PendingOrSignal(_expression));
                }
                RuntimeObj result = _expression.Result;

                // Minus and Plus are classified as a binary operator.
                // Handle those special cases here.
                if (Expr.TokenType == TokenizerToken.Minus)
                {
                    result = DoubleObj.Create(-result.ToDouble());
                }
                else if (Expr.TokenType == TokenizerToken.Plus)
                {
                    result = DoubleObj.Create(result.ToDouble());
                }
                else
                {
                    switch ((int)Expr.TokenType & 15)
                    {
                    case (int)TokenizerToken.Not & 15:
                    {
                        result = result.ToBoolean() ? BooleanObj.False : BooleanObj.True;
                        break;
                    }

                    case (int)TokenizerToken.BitwiseNot & 15:
                    {
                        result = DoubleObj.Create(~JSSupport.ToInt64(result.ToDouble()));
                        break;
                    }

                    case (int)TokenizerToken.TypeOf & 15:
                    {
                        // Well known Javascript bug: typeof null === "object".
                        if (result == RuntimeObj.Null)
                        {
                            result = StringObj.Create(RuntimeObj.TypeObject);
                        }
                        else
                        {
                            result = StringObj.Create(result.Type);
                        }
                        break;
                    }

                    case (int)TokenizerToken.IndexOf & 15:
                    {
                        RefRuntimeIndexedObj iO = result as RefRuntimeIndexedObj;
                        if (iO == null)
                        {
                            result = new RuntimeError(Expr, "No associated index. indexof must be used on a foreach variable.");
                        }
                        else
                        {
                            result = iO.Index;
                        }
                        break;
                    }

                    case (int)TokenizerToken.Void & 15:
                    {
                        result = RuntimeObj.Undefined;
                        break;
                    }

                    default: throw UnsupportedOperatorException();
                    }
                }
                return(SetResult(result));
            }