public JsNode VisitDynamicInvocationResolveResult(DynamicInvocationResolveResult res) { var target2 = VisitExpression(res.Target); var args2 = VisitExpressions(res.Arguments); if (res.InvocationType == DynamicInvocationType.Invocation) { var node2 = target2.Invoke(args2.ToArray()); return(node2); } else if (res.InvocationType == DynamicInvocationType.ObjectCreation) { var node2 = Js.New(target2, args2.ToArray()); return(node2); } else if (res.InvocationType == DynamicInvocationType.Indexing) { var node2 = target2.IndexerAccess(args2.Single()); return(node2); } else { throw new NotImplementedException("Dynamics: " + res.InvocationType); } }
public JsNode VisitThrowStatement(ThrowStatement node) { JsExpression node2; IType exceptionType; if (node.Expression == null || node.Expression.IsNull) //happens when performing "throw;" { var cc = node.GetParent <CatchClause>(); if (cc != null) { node2 = Js.Member(cc.VariableName); var type = cc.Type; if (type == null || type.IsNull) { exceptionType = Project.Compilation.FindType(KnownTypeCode.Exception); } else { exceptionType = cc.Type.Resolve().Type; } } else { throw new Exception("Rethrow not supported, catch clause not found"); } } else { node2 = VisitExpression(node.Expression); var res = node.Expression.Resolve(); exceptionType = res.Type; if (res is ConversionResolveResult) { exceptionType = ((ConversionResolveResult)res).Input.Type; } } if (!Sk.IsNativeError(exceptionType.GetDefinitionOrArrayType())) { node2 = Js.Member("$CreateException").Invoke(node2, Js.New(Js.Member("Error"))); } return(new JsThrowStatement { Expression = node2 }); }
public void Process() { AfterFunction = BeforeFunction; SetParents(BeforeFunction.Block); foreach (var me in BeforeFunction.Block.Descendants <JsMemberExpression>().ToList()) { if (me.PreviousMember == null && me.NodeType == JsNodeType.MemberExpression) { me.PreviousMember = Js.This(); } } BeginNewStep(); ProcessStatement(BeforeFunction.Block); BeforeFunction.Block.Statements.Clear(); var func = new JsFunction { Block = new JsBlock { Statements = new List <JsStatement>() } }; var i = 0; func.Block.Statements.Add(Js.Var("result").Statement()); var stSwitch = Js.Switch(_state()); var lastStep = Js.Block().Add(_state().Assign(Js.Value(Steps.Count)).Statement()).Add(new JsBreakStatement()); Steps.Add(new YieldStep { Statements = { lastStep } }); foreach (var step in Steps) { stSwitch.Case(Js.Value(i), step.Statements); i++; } func.Block.Statements.Add(stSwitch); func.Block.Statements.Add(Js.Member("result").Assign(Js.Value(false)).Statement()); func.Block.Statements.Add(Js.Return(Js.Member("result"))); BeforeFunction.Block.Statements.Add(Js.Return(Js.New(Js.Member("CustomEnumerable"), func))); return; }