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); }
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); }