protected JSExpression GetThisScope(MethodBase methodScope, Type typeScope) { var thisScope = methodScope.IsStatic ? null : new JSArrayLookupExpression { Array = JSFactory.Identifier("arguments"), Indexer = new JSNumberLiteral { Value = 0 } } as JSExpression; if (thisScope != null && typeScope.IsValueType) { thisScope = new JSCallExpression { Function = JSFactory.Identifier(thisScope, "r") } } ; return(thisScope); } }
public JSFunctionDelcaration GetFirstCallInitializer(CilAssembly assembly, CilType type, CilMethod method) { if (type.IsIgnored) { throw new ArgumentException("cannot translate method of ignored class"); } if (!method.NeedInitializer) { throw new ArgumentException("method need no initialization"); } var functionBlock = new List <JSStatement>(); JSExpression closedMethodInitializer; JSExpression openMethodInitializer = JSFactory.Identifier("asm", GetMethodIdentifier(method.ReflectionMethod) + "_init"); if (HasGenericParameters(method)) { closedMethodInitializer = new JSCallExpression { Function = openMethodInitializer, Arguments = GetGenericParameterList(method.ReflectionMethod) .Select(t => JSFactory.Identifier(t.Name)) .ToList() }; } else { closedMethodInitializer = openMethodInitializer; } functionBlock.Add( new JSCallExpression { Function = JSFactory.Identifier(closedMethodInitializer, "apply"), Arguments = { JSFactory.Identifier("this"), JSFactory.Identifier("arguments") } }.ToStatement()); JSExpression openMethodImplementation = JSFactory.Identifier("asm", GetMethodIdentifier(method.ReflectionMethod) + "_"); JSExpression closedMethodImplementation; if (HasGenericParameters(method)) { closedMethodImplementation = new JSCallExpression { Function = openMethodImplementation, Arguments = GetGenericParameterList(method.ReflectionMethod) .Select(t => JSFactory.Identifier(t.Name)) .ToList() }; } else { closedMethodImplementation = openMethodImplementation; } functionBlock.Add( new JSReturnExpression { Expression = new JSCallExpression { Function = JSFactory.Identifier(closedMethodImplementation, "apply"), Arguments = { JSFactory.Identifier("this"), JSFactory.Identifier("arguments") } } }.ToStatement()); var ps = GetParameterCount(method); var f = new JSFunctionDelcaration { Body = functionBlock, Parameters = Enumerable.Range(0, ps).Select(i => new JSFunctionParameter { Name = "arg" + i }).ToList() }; return(HasGenericParameters(method) ? CreateGenericFunction(method, f) : f); }