Ejemplo n.º 1
0
        public static NSJSFunctionCallback Complier(MethodInfo m)
        {
            if (m == null)
            {
                throw new ArgumentNullException("m");
            }
            CompilerCacheKey key = new CompilerCacheKey
            {
                method = m,
                type   = m.DeclaringType,
            };

            lock (syncobj)
            {
                NSJSFunctionCallback callback;
                if (fnCompilerCaches.TryGetValue(key, out callback))
                {
                    return(callback);
                }
                else
                {
                    ParameterExpression arguments = Expression.Parameter(typeof(NSJSFunctionCallbackInfo), "arguments");
                    ParameterExpression self      = Expression.Variable(m.DeclaringType, "this");

                    IList <ParameterExpression> localvar = GetLocalVar(m);
                    Expression <Action <NSJSFunctionCallbackInfo> > expression = Expression.Lambda <Action <NSJSFunctionCallbackInfo> >(
                        Expression.Block(
                            new ParameterExpression[] { self },
                            new Expression[]
                    {
                        Expression.Block(
                            localvar,
                            ComplierBlock(m, arguments, self, localvar)
                            )
                    }
                            )
                        , arguments);

                    ParameterExpression info = Expression.Parameter(typeof(IntPtr), "info");
                    Expression <NSJSFunctionCallback> launcher = Expression.Lambda <NSJSFunctionCallback>(
                        Expression.Block(new ParameterExpression[] { arguments },
                                         Expression.Assign(arguments, Expression.Call(Get <MethodInfo>(typeof(NSJSFunctionCallbackInfo), "From"), info)),
                                         Expression.Call(Expression.Constant(JSINVKHANDLING), "Invoke", null, arguments, Expression.Constant(expression.Compile()))
                                         ), info);

                    callback = launcher.Compile();
                    fnCompilerCaches.Add(key, callback);
                    return(callback);
                }
            }
        }
Ejemplo n.º 2
0
        private static NSJSFunctionCallback GetCompilerCache(MethodInfo m)
        {
            CompilerCacheKey key = new CompilerCacheKey
            {
                method = m,
                type   = m.DeclaringType,
            };

            lock (syncobj)
            {
                NSJSFunctionCallback callback;
                fnCompilerCaches.TryGetValue(key, out callback);
                return(callback);
            }
        }