コード例 #1
0
ファイル: With.cs プロジェクト: lulzzz/sito
        public override JSValue Evaluate(Context context)
        {
            JSValue          scopeObject = null;
            WithContext      intcontext  = null;
            Action <Context> action      = null;

            if (context._executionMode >= ExecutionMode.Resume)
            {
                action = context.SuspendData[this] as Action <Context>;
                if (action != null)
                {
                    action(context);
                    return(null);
                }
            }

            if (context._executionMode != ExecutionMode.Resume && context.Debugging)
            {
                context.raiseDebugger(_scope);
            }

            scopeObject = _scope.Evaluate(context);
            if (context._executionMode == ExecutionMode.Suspend)
            {
                context.SuspendData[this] = null;
                return(null);
            }

            intcontext = new WithContext(scopeObject, context);
            action     = c =>
            {
                try
                {
                    intcontext._executionMode = c._executionMode;
                    intcontext._executionInfo = c._executionInfo;
                    intcontext.Activate();
                    c._lastResult    = _body.Evaluate(intcontext) ?? intcontext._lastResult;
                    c._executionMode = intcontext._executionMode;
                    c._executionInfo = intcontext._executionInfo;
                    if (c._executionMode == ExecutionMode.Suspend)
                    {
                        c.SuspendData[this] = action;
                    }
                }
                finally
                {
                    intcontext.Deactivate();
                }
            };

            if (context.Debugging && !(_body is CodeBlock))
            {
                context.raiseDebugger(_body);
            }

            action(context);
            return(null);
        }