Пример #1
0
        public override JSValue Evaluate(Context context)
        {
            JSValue checkResult;

            do
            {
                if (context._executionMode != ExecutionMode.Resume || !context.SuspendData.ContainsKey(this))
                {
                    if (context._debugging && !(body is CodeBlock))
                    {
                        context.raiseDebugger(body);
                    }

                    context._lastResult = body.Evaluate(context) ?? context._lastResult;
                    if (context._executionMode != ExecutionMode.None)
                    {
                        if (context._executionMode < ExecutionMode.Return)
                        {
                            var me     = context._executionInfo == null || System.Array.IndexOf(labels, context._executionInfo._oValue as string) != -1;
                            var _break = (context._executionMode > ExecutionMode.Continue) || !me;
                            if (me)
                            {
                                context._executionMode = ExecutionMode.None;
                                context._executionInfo = JSValue.notExists;
                            }
                            if (_break)
                            {
                                return(null);
                            }
                        }
                        else
                        {
                            return(null);
                        }
                    }
                }

                if (context._debugging)
                {
                    context.raiseDebugger(condition);
                }

                checkResult = condition.Evaluate(context);
                if (context._executionMode == ExecutionMode.Suspend)
                {
                    context.SuspendData[this] = null;
                    return(null);
                }
            }while ((bool)checkResult);
            return(null);
        }
Пример #2
0
        public override JSValue Evaluate(Context context)
        {
            if (context._module == null)
            {
                ExceptionHelper.Throw(new BaseLibrary.Error("Module undefined"));
            }

            if (_reexportSourceModuleName != null)
            {
                if (string.IsNullOrEmpty(context._module.FilePath))
                {
                    ExceptionHelper.Throw(new BaseLibrary.Error("Module must has name"));
                }

                var module = context._module.Import(_reexportSourceModuleName);

                if (_map.Count == 0)
                {
                    foreach (var item in module.Exports)
                    {
                        context._module.Exports[item.Key] = item.Value;
                    }
                }
                else
                {
                    for (var i = 0; i < _map.Count; i++)
                    {
                        context._module.Exports[_map[i].Key] = module.Exports[_map[i].Value.ToString()];
                    }
                }
            }
            else if (_internalDefinition != null)
            {
                _internalDefinition.Evaluate(context);

                var variableDef = _internalDefinition as VariableDefinition;
                if (variableDef != null)
                {
                    for (var i = 0; i < variableDef._variables.Length; i++)
                    {
                        context._module.Exports[variableDef._variables[i].name] = variableDef._variables[i].references[0].Evaluate(context);
                    }
                }
                else
                {
                    var entityDef = _internalDefinition as EntityDefinition;

                    context._module.Exports[entityDef.Name] = entityDef.reference.Descriptor.Get(context, false, 1);
                }
            }
            else
            {
                for (var i = 0; i < _map.Count; i++)
                {
                    context._module.Exports[_map[i].Key] = _map[i].Value.Evaluate(context);
                }
            }

            return(null);
        }
Пример #3
0
        public override JSValue Evaluate(Context context)
        {
            for (;;)
            {
                if (context._debugging && !(body is CodeBlock))
                {
                    context.raiseDebugger(body);
                }

                context._lastResult = body.Evaluate(context) ?? context._lastResult;
                if (context._executionMode != ExecutionMode.None)
                {
                    if (context._executionMode < ExecutionMode.Return)
                    {
                        var me     = context._executionInfo == null || System.Array.IndexOf(labels, context._executionInfo._oValue as string) != -1;
                        var _break = (context._executionMode > ExecutionMode.Continue) || !me;
                        if (me)
                        {
                            context._executionMode = ExecutionMode.None;
                            context._executionInfo = JSValue.notExists;
                        }
                        if (_break)
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
        }
Пример #4
0
        public override JSValue Evaluate(Context context)
        {
            bool conditionResult;

            if (context._executionMode != ExecutionMode.Resume || !context.SuspendData.ContainsKey(this))
            {
                if (context._debugging)
                {
                    context.raiseDebugger(condition);
                }

                conditionResult = (bool)condition.Evaluate(context);
                if (context._executionMode == ExecutionMode.Suspend)
                {
                    return(null);
                }
            }
            else
            {
                conditionResult = (bool)context.SuspendData[this];
            }

            if (conditionResult)
            {
                if (then != null)
                {
                    if (context._debugging && !(then is CodeBlock))
                    {
                        context.raiseDebugger(then);
                    }

                    var temp = then.Evaluate(context);
                    if (temp != null)
                    {
                        context._lastResult = temp;
                    }
                }
            }
            else if (@else != null)
            {
                if (context._debugging && !(@else is CodeBlock))
                {
                    context.raiseDebugger(@else);
                }

                var temp = @else.Evaluate(context);
                if (temp != null)
                {
                    context._lastResult = temp;
                }
            }

            if (context._executionMode == ExecutionMode.Suspend)
            {
                context.SuspendData[this] = conditionResult;
            }

            return(null);
        }
Пример #5
0
        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);
        }
Пример #6
0
        public override JSValue Evaluate(Context context)
        {
            var res = statement.Evaluate(context);

            if ((context._executionMode == ExecutionMode.Break) && (context._executionInfo != null) && (context._executionInfo._oValue as string == Label))
            {
                context._executionMode = ExecutionMode.None;
                context._executionInfo = JSValue.notExists;
            }
            return(res);
        }
Пример #7
0
        private void finallyHandler(Context context, Exception exception)
        {
            if (context._debugging)
            {
                context.raiseDebugger(finallyBody);
            }

            var abort = context._executionMode;
            var ainfo = context._executionInfo;

            if (abort == ExecutionMode.Return && ainfo != null)
            {
                if (ainfo.Defined)
                {
                    ainfo = ainfo.CloneImpl(false);
                }
                else
                {
                    ainfo = JSValue.Undefined;
                }
            }

            context._executionMode = ExecutionMode.Regular;
            context._executionInfo = JSValue.undefined;

            Action <Context> finallyAction = null;

            finallyAction = (c) =>
            {
                c._lastResult = finallyBody.Evaluate(c) ?? context._lastResult;
                if (c._executionMode == ExecutionMode.Regular)
                {
                    c._executionMode = abort;
                    c._executionInfo = ainfo;
                    if (exception != null)
                    {
                        throw exception as JSException ?? new JSException(null as JSValue, exception);
                    }
                }
                else if (c._executionMode == ExecutionMode.Suspend)
                {
                    c.SuspendData[this] = finallyAction;
                }
            };
            finallyAction(context);
        }
Пример #8
0
        public override JSValue Evaluate(Context context)
        {
            if (_initializer != null && (context._executionMode != ExecutionMode.Resume || context.SuspendData[this] == _initializer))
            {
                if (context._executionMode != ExecutionMode.Resume && context._debugging)
                {
                    context.raiseDebugger(_initializer);
                }

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

            var be        = _body != null;
            var pe        = _post != null;
            var @continue = false;

            if (context._executionMode != ExecutionMode.Resume || context.SuspendData[this] == _condition)
            {
                if (context._executionMode != ExecutionMode.Resume && context._debugging)
                {
                    context.raiseDebugger(_condition);
                }

                @continue = (bool)_condition.Evaluate(context);
                if (context._executionMode == ExecutionMode.Suspend)
                {
                    context.SuspendData[this] = _condition;
                    return(null);
                }

                if (!@continue)
                {
                    return(null);
                }
            }

            do
            {
                if (be && (context._executionMode != ExecutionMode.Resume || context.SuspendData[this] == _body))
                {
                    if (context._executionMode != ExecutionMode.Resume && context._debugging && !(_body is CodeBlock))
                    {
                        context.raiseDebugger(_body);
                    }

                    var temp = _body.Evaluate(context);
                    if (temp != null)
                    {
                        context._lastResult = temp;
                    }

                    if (context._executionMode != ExecutionMode.None)
                    {
                        if (context._executionMode < ExecutionMode.Return)
                        {
                            var me     = context._executionInfo == null || System.Array.IndexOf(labels, context._executionInfo._oValue as string) != -1;
                            var _break = (context._executionMode > ExecutionMode.Continue) || !me;
                            if (me)
                            {
                                context._executionMode = ExecutionMode.None;
                                context._executionInfo = null;
                            }

                            if (_break)
                            {
                                return(null);
                            }
                        }
                        else if (context._executionMode == ExecutionMode.Suspend)
                        {
                            context.SuspendData[this] = _body;
                            return(null);
                        }
                        else
                        {
                            return(null);
                        }
                    }
                }

                if (pe && (context._executionMode != ExecutionMode.Resume || context.SuspendData[this] == _post))
                {
                    if (context._executionMode != ExecutionMode.Resume && context._debugging)
                    {
                        context.raiseDebugger(_post);
                    }

                    _post.Evaluate(context);
                }

                if (context._executionMode != ExecutionMode.Resume && context._debugging)
                {
                    context.raiseDebugger(_condition);
                }

                @continue = (bool)_condition.Evaluate(context);
                if (context._executionMode == ExecutionMode.Suspend)
                {
                    context.SuspendData[this] = _condition;
                    return(null);
                }
            }while (@continue);

            return(null);
        }
Пример #9
0
 public override JSValue Evaluate(Context context)
 {
     return(node.Evaluate(context));
 }
Пример #10
0
        public override JSValue Evaluate(Context context)
        {
#if DEBUG
            if (functions != null)
            {
                throw new InvalidOperationException();
            }
#endif
            JSValue imageValue = null;
            int     caseIndex  = 1;
            int     lineIndex  = cases[0].index;

            if (context._executionMode >= ExecutionMode.Resume)
            {
                var sdata = context.SuspendData[this] as SuspendData;
                if (sdata.imageValue == null)
                {
                    imageValue = image.Evaluate(context);
                }
                else
                {
                    imageValue = sdata.imageValue;
                }
                caseIndex = sdata.caseIndex;
                lineIndex = sdata.lineIndex;
            }
            else
            {
                if (context._debugging)
                {
                    context.raiseDebugger(image);
                }

                imageValue = image.Evaluate(context);
            }
            if (context._executionMode == ExecutionMode.Suspend)
            {
                context.SuspendData[this] = new SuspendData()
                {
                    caseIndex = 1
                };
                return(null);
            }

            for (; caseIndex < cases.Length; caseIndex++)
            {
                if (context._debugging)
                {
                    context.raiseDebugger(cases[caseIndex].statement);
                }

                var cseResult = cases[caseIndex].statement.Evaluate(context);
                if (context._executionMode == ExecutionMode.Suspend)
                {
                    context.SuspendData[this] = new SuspendData()
                    {
                        caseIndex  = caseIndex,
                        imageValue = imageValue
                    };
                    return(null);
                }

                if (Expressions.StrictEqual.Check(imageValue, cseResult))
                {
                    lineIndex = cases[caseIndex].index;
                    caseIndex = cases.Length;
                    break;
                }
            }
            for (; lineIndex < lines.Length; lineIndex++)
            {
                if (lines[lineIndex] == null)
                {
                    continue;
                }

                context._lastResult = lines[lineIndex].Evaluate(context) ?? context._lastResult;
                if (context._executionMode != ExecutionMode.Regular)
                {
                    if (context._executionMode == ExecutionMode.Break && context._executionInfo == null)
                    {
                        context._executionMode = ExecutionMode.Regular;
                    }
                    else if (context._executionMode == ExecutionMode.Suspend)
                    {
                        context.SuspendData[this] = new SuspendData()
                        {
                            caseIndex  = caseIndex,
                            imageValue = imageValue,
                            lineIndex  = lineIndex
                        };
                    }
                    return(null);
                }
            }
            return(null);
        }
Пример #11
0
        private void catchHandler(Context context, Exception e)
        {
            if (context._debugging)
            {
                context.raiseDebugger(catchBody);
            }

            if (catchBody is Empty)
            {
                return;
            }

            JSValue cvar = null;

#if !(PORTABLE || NETCORE)
            if (e is RuntimeWrappedException)
            {
                cvar = new JSValue();
                cvar.Assign((e as RuntimeWrappedException).WrappedException as JSValue);
            }
            else
#endif
            {
                cvar = e is JSException ? (e as JSException).Error.CloneImpl(false) : context.GlobalContext.ProxyValue(e);
            }

            cvar._attributes |= JSValueAttributesInternal.DoNotDelete;
            var catchContext = new CatchContext(cvar, context, catchVariableDesc.name);
#if DEBUG
            if (!(e is JSException))
            {
                System.Diagnostics.Debugger.Break();
            }
#endif

            Action <Context> catchAction = null;
            catchAction = (c) =>
            {
                try
                {
                    catchContext._executionMode = c._executionMode;
                    catchContext._executionInfo = c._executionInfo;
                    catchContext.Activate();
                    catchContext._lastResult = catchBody.Evaluate(catchContext) ?? catchContext._lastResult;
                }
                finally
                {
                    c._lastResult = catchContext._lastResult ?? c._lastResult;
                    catchContext.Deactivate();
                }
                c._executionMode = catchContext._executionMode;
                c._executionInfo = catchContext._executionInfo;

                if (c._executionMode == ExecutionMode.Suspend)
                {
                    if (finallyBody != null)
                    {
                        c.SuspendData[this] = new Action <Context>((c2) =>
                        {
                            try
                            {
                                catchAction(c2);
                            }
                            finally
                            {
                                if (c2._executionMode != ExecutionMode.Suspend)
                                {
                                    finallyHandler(c2, e);
                                }
                            }
                        });
                    }
                    else
                    {
                        c.SuspendData[this] = catchAction;
                    }
                }
            };
            catchAction(context);
        }
Пример #12
0
        public override JSValue Evaluate(Context context)
        {
            Exception exception = null;

            if (context._executionMode >= ExecutionMode.Resume)
            {
                var action = context.SuspendData[this] as Action <Context>;
                if (action != null)
                {
                    action(context);
                    return(null);
                }
            }
            else
            {
                if (context._debugging && !(body is CodeBlock))
                {
                    context.raiseDebugger(body);
                }
            }

            try
            {
                body.Evaluate(context);

                if (context._executionMode == ExecutionMode.Suspend)
                {
                    context.SuspendData[this] = null;
                }
            }
            catch (Exception e)
            {
                if (this._catch)
                {
                    if (catchBody != null)
                    {
                        catchHandler(context, e);
                    }
                }
                else
                {
                    if (finallyBody == null)
                    {
                        throw;
                    }
                    exception = e;
                }
            }
            finally
            {
                if (context._executionMode != ExecutionMode.Suspend && finallyBody != null)
                {
                    finallyHandler(context, exception);
                    exception = null;
                }
            }

            if (context._executionMode != ExecutionMode.Suspend && exception != null)
            {
                throw exception;
            }

            return(null);
        }
Пример #13
0
 private static JSValue safeGet(JSValue temp, CodeNode source, Context context)
 {
     temp.Assign(source.Evaluate(context));
     return(temp);
 }
Пример #14
0
        public override JSValue Evaluate(Context context)
        {
            bool    be = body != null;
            JSValue checkResult;

            if (context._executionMode != ExecutionMode.Resume || context.SuspendData[this] == condition)
            {
                if (context._executionMode != ExecutionMode.Resume && context._debugging)
                {
                    context.raiseDebugger(condition);
                }

                checkResult = condition.Evaluate(context);
                if (context._executionMode == ExecutionMode.Suspend)
                {
                    context.SuspendData[this] = condition;
                    return(null);
                }
                if (!(bool)checkResult)
                {
                    return(null);
                }
            }

            do
            {
                if (be &&
                    (context._executionMode != ExecutionMode.Resume ||
                     context.SuspendData[this] == body))
                {
                    if (context._executionMode != ExecutionMode.Resume && context._debugging && !(body is CodeBlock))
                    {
                        context.raiseDebugger(body);
                    }

                    var temp = body.Evaluate(context);
                    if (temp != null)
                    {
                        context._lastResult = temp;
                    }
                    if (context._executionMode != ExecutionMode.None)
                    {
                        if (context._executionMode < ExecutionMode.Return)
                        {
                            var me     = context._executionInfo == null || System.Array.IndexOf(labels, context._executionInfo._oValue as string) != -1;
                            var _break = (context._executionMode > ExecutionMode.Continue) || !me;
                            if (me)
                            {
                                context._executionMode = ExecutionMode.None;
                                context._executionInfo = null;
                            }
                            if (_break)
                            {
                                return(null);
                            }
                        }
                        else if (context._executionMode == ExecutionMode.Suspend)
                        {
                            context.SuspendData[this] = body;
                            return(null);
                        }
                        else
                        {
                            return(null);
                        }
                    }
                }

                if (context._executionMode != ExecutionMode.Resume && context._debugging)
                {
                    context.raiseDebugger(condition);
                }

                checkResult = condition.Evaluate(context);
                if (context._executionMode == ExecutionMode.Suspend)
                {
                    context.SuspendData[this] = condition;
                    return(null);
                }
            }while ((bool)checkResult);
            return(null);
        }
Пример #15
0
        public override JSValue Evaluate(Context context)
        {
            SuspendData suspendData = null;

            if (context._executionMode >= ExecutionMode.Resume)
            {
                suspendData = context.SuspendData[this] as SuspendData;
            }

            JSValue source = null;

            if (suspendData == null || suspendData.source == null)
            {
                if (context._debugging && !(_source is CodeBlock))
                {
                    context.raiseDebugger(_source);
                }

                source = _source.Evaluate(context);
                if (context._executionMode == ExecutionMode.Suspend)
                {
                    context.SuspendData[this] = null;
                    return(null);
                }
            }
            else
            {
                source = suspendData.source;
            }

            JSValue variable = null;

            if (suspendData == null || suspendData.variable == null)
            {
                if (context._debugging && !(_variable is CodeBlock))
                {
                    context.raiseDebugger(_variable);
                }

                var varialeDefStat = _variable as VariableDefinition;
                if (varialeDefStat != null)
                {
                    _variable.Evaluate(context);
                    variable = (varialeDefStat._initializers[0]._left ?? varialeDefStat._initializers[0]).EvaluateForWrite(context);
                }
                else if (_variable is Assignment)
                {
                    _variable.Evaluate(context);
                    variable = (_variable as Assignment)._left.Evaluate(context);
                }
                else
                {
                    variable = _variable.EvaluateForWrite(context);
                }
                if (context._executionMode == ExecutionMode.Suspend)
                {
                    if (suspendData == null)
                    {
                        suspendData = new SuspendData();
                    }
                    context.SuspendData[this] = suspendData;
                    suspendData.source        = source;
                    return(null);
                }
            }
            else
            {
                variable = suspendData.variable;
            }

            if (!source.Defined ||
                (source._valueType >= JSValueType.Object && source._oValue == null) ||
                _body == null)
            {
                return(JSValue.undefined);
            }

            var index         = 0;
            var processedKeys = (suspendData != null ? suspendData.processedKeys : null) ?? new HashSet <string>(StringComparer.Ordinal);

            while (source != null)
            {
                var keys = (suspendData != null ? suspendData.keys : null) ?? source.GetEnumerator(false, EnumerationMode.RequireValues);
                while (context._executionMode >= ExecutionMode.Resume || keys.MoveNext())
                {
                    if (context._executionMode != ExecutionMode.Resume)
                    {
                        var key = keys.Current.Key;
                        variable._valueType = JSValueType.String;
                        variable._oValue    = key;
                        if (processedKeys.Contains(key))
                        {
                            continue;
                        }
                        processedKeys.Add(key);
                        if ((keys.Current.Value._attributes & JSValueAttributesInternal.DoNotEnumerate) != 0)
                        {
                            continue;
                        }

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

                    context._lastResult = _body.Evaluate(context) ?? context._lastResult;
                    if (context._executionMode != ExecutionMode.None)
                    {
                        if (context._executionMode < ExecutionMode.Return)
                        {
                            var me     = context._executionInfo == null || System.Array.IndexOf(_labels, context._executionInfo._oValue as string) != -1;
                            var _break = (context._executionMode > ExecutionMode.Continue) || !me;
                            if (me)
                            {
                                context._executionMode = ExecutionMode.None;
                                context._executionInfo = JSValue.notExists;
                            }
                            if (_break)
                            {
                                return(null);
                            }
                        }
                        else if (context._executionMode == ExecutionMode.Suspend)
                        {
                            if (suspendData == null)
                            {
                                suspendData = new SuspendData();
                            }
                            context.SuspendData[this] = suspendData;

                            suspendData.source        = source;
                            suspendData.variable      = variable;
                            suspendData.processedKeys = processedKeys;
                            suspendData.keys          = keys;
                            return(null);
                        }
                        else
                        {
                            return(null);
                        }
                    }

                    index++;
                }

                source = source.__proto__;
                if (source == JSValue.@null || !source.Defined || (source._valueType >= JSValueType.Object && source._oValue == null))
                {
                    break;
                }
            }
            return(null);
        }
Пример #16
0
        public override JSValue Evaluate(Context context)
        {
            SuspendData suspendData = null;

            if (context._executionMode >= ExecutionMode.Resume)
            {
                suspendData = context.SuspendData[this] as SuspendData;
            }

            JSValue source = null;

            if (suspendData == null || suspendData.source == null)
            {
                if (context._debugging && !(_source is CodeBlock))
                {
                    context.raiseDebugger(_source);
                }

                source = _source.Evaluate(context);
                if (context._executionMode == ExecutionMode.Suspend)
                {
                    context.SuspendData[this] = null;
                    return(null);
                }
            }
            else
            {
                source = suspendData.source;
            }

            JSValue variable = null;

            if (suspendData == null || suspendData.variable == null)
            {
                if (context._debugging && !(_variable is CodeBlock))
                {
                    context.raiseDebugger(_variable);
                }

                var varialeDefStat = _variable as VariableDefinition;
                if (varialeDefStat != null)
                {
                    _variable.Evaluate(context);
                    variable = (varialeDefStat._initializers[0]._left ?? varialeDefStat._initializers[0]).EvaluateForWrite(context);
                }
                else if (_variable is Assignment)
                {
                    _variable.Evaluate(context);
                    variable = (_variable as Assignment)._left.Evaluate(context);
                }
                else
                {
                    variable = _variable.EvaluateForWrite(context);
                }
                if (context._executionMode == ExecutionMode.Suspend)
                {
                    if (suspendData == null)
                    {
                        suspendData = new SuspendData();
                    }
                    context.SuspendData[this] = suspendData;
                    suspendData.source        = source;
                    return(null);
                }
            }
            else
            {
                variable = suspendData.variable;
            }

            if (!source.Defined || source.IsNull || _body == null)
            {
                return(null);
            }

            var iterator = (suspendData != null ? suspendData.iterator : null) ?? source.AsIterable().iterator();

            if (iterator == null)
            {
                return(null);
            }

            IIteratorResult iteratorResult = context._executionMode != ExecutionMode.Resume ? iterator.next() : null;

            while (context._executionMode >= ExecutionMode.Resume || !iteratorResult.done)
            {
                if (context._executionMode != ExecutionMode.Resume)
                {
                    variable.Assign(iteratorResult.value);
                }

                _body.Evaluate(context);

                if (context._executionMode != ExecutionMode.None)
                {
                    if (context._executionMode < ExecutionMode.Return)
                    {
                        var me     = context._executionInfo == null || System.Array.IndexOf(_labels, context._executionInfo._oValue as string) != -1;
                        var _break = (context._executionMode > ExecutionMode.Continue) || !me;
                        if (me)
                        {
                            context._executionMode = ExecutionMode.None;
                            context._executionInfo = JSValue.notExists;
                        }
                        if (_break)
                        {
                            return(null);
                        }
                    }
                    else if (context._executionMode == ExecutionMode.Suspend)
                    {
                        if (suspendData == null)
                        {
                            suspendData = new SuspendData();
                        }
                        context.SuspendData[this] = suspendData;

                        suspendData.source   = source;
                        suspendData.variable = variable;
                        suspendData.iterator = iterator;
                        return(null);
                    }
                    else
                    {
                        return(null);
                    }
                }

                iteratorResult = iterator.next();
            }

            return(null);
        }
Пример #17
0
        public override JSValue Evaluate(Context context)
        {
            JSValue imageValue = null;
            int     caseIndex  = 1;
            int     lineIndex  = Cases[0].index;

            if (context._executionMode >= ExecutionMode.Resume)
            {
                var sdata = context.SuspendData[this] as SuspendData;
                imageValue = sdata.imageValue ?? image.Evaluate(context);
                caseIndex  = sdata.caseIndex;
                lineIndex  = sdata.lineIndex;
            }
            else
            {
                if (context.Debugging)
                {
                    context.raiseDebugger(image);
                }

                imageValue = image.Evaluate(context);
            }
            if (context._executionMode == ExecutionMode.Suspend)
            {
                context.SuspendData[this] = new SuspendData {
                    caseIndex = 1
                };
                return(null);
            }

            for (; caseIndex < Cases.Length; caseIndex++)
            {
                if (context.Debugging)
                {
                    context.raiseDebugger(Cases[caseIndex].statement);
                }

                var cseResult = Cases[caseIndex].statement.Evaluate(context);
                if (context._executionMode == ExecutionMode.Suspend)
                {
                    context.SuspendData[this] = new SuspendData
                    {
                        caseIndex  = caseIndex,
                        imageValue = imageValue
                    };
                    return(null);
                }

                if (StrictEqual.Check(imageValue, cseResult))
                {
                    lineIndex = Cases[caseIndex].index;
                    caseIndex = Cases.Length;
                    break;
                }
            }
            for (; lineIndex < Body.Length; lineIndex++)
            {
                if (Body[lineIndex] == null)
                {
                    continue;
                }

                context._lastResult = Body[lineIndex].Evaluate(context) ?? context._lastResult;
                if (context._executionMode != ExecutionMode.None)
                {
                    if (context._executionMode == ExecutionMode.Break)
                    {
                        context._executionMode = ExecutionMode.None;
                    }
                    else if (context._executionMode == ExecutionMode.Suspend)
                    {
                        context.SuspendData[this] = new SuspendData
                        {
                            caseIndex  = caseIndex,
                            imageValue = imageValue,
                            lineIndex  = lineIndex
                        };
                    }
                    return(null);
                }
            }
            return(null);
        }