예제 #1
0
        public ClrObject(Engine engine, Object obj, ObjectInstance prototype, DomConverter converter)
            : base(engine)
        {
            _converter = converter;
            Target     = obj;
            Prototype  = prototype;
            Extensible = true;

            //todo: optimize reflection.
            _indexPropertyStr =
                Target.GetType().GetRecursive(x => x.BaseType).SelectMany(x =>
                                                                          x.GetProperties().Where(p => p.GetIndexParameters().Length != 0 &&
                                                                                                  p.GetCustomAttribute <JsHiddenAttribute>() == null &&
                                                                                                  p.GetIndexParameters()[0].ParameterType == typeof(string)))
                .FirstOrDefault();

            _indexPropertyInt =
                Target.GetType().GetRecursive(x => x.BaseType).SelectMany(x =>
                                                                          x.GetProperties().Where(p => p.GetIndexParameters().Length != 0 &&
                                                                                                  p.GetCustomAttribute <JsHiddenAttribute>() == null &&
                                                                                                  p.GetIndexParameters()[0].ParameterType == typeof(int)))
                .FirstOrDefault();

            _indexPropertyUlong =
                Target.GetType().GetRecursive(x => x.BaseType).SelectMany(x =>
                                                                          x.GetProperties().Where(p => p.GetIndexParameters().Length != 0 &&
                                                                                                  p.GetCustomAttribute <JsHiddenAttribute>() == null &&
                                                                                                  p.GetIndexParameters()[0].ParameterType == typeof(ulong)))
                .FirstOrDefault();
        }
예제 #2
0
 public ClrFuncCtor(
     Engine engine, Func <JsValue[], ObjectInstance> act,
     ObjectInstance prototype)
     : base(engine, null, null, false)
 {
     _act = act;
     FastAddProperty("prototype", prototype, false, false, false);
     DomConverter.DefineStatic(this, typeof(ClrType));
 }
예제 #3
0
        public ClrMethodInfoFunc(DomConverter converter, global::Jint.Engine engine, MethodInfo[] methods, JsValue owner)
            : base(engine, null, null, false)
        {
            _converter = converter;
            _owner     = owner;
            _methods   = methods.OrderByDescending(x => x.GetParameters().Length).ToArray();
            _invokers  = new Func <object, JsValue[], object> [methods.Length];
            Prototype  = engine.Function.PrototypeObject;

            var name = methods.First().GetName();

            FastAddProperty("name", new JsValue(name), false, false, false);
        }
예제 #4
0
        public static PropertyDescriptor Create(global::Jint.Engine engine,
                                                DomConverter converter,
                                                string propertyName,
                                                MethodInfo[] methods,
                                                JsValue owner)
        {
            var func = new ClrMethodInfoFunc(converter, engine, methods, owner);

            //todo: check if this necessary
            func.FastAddProperty("toString",
                                 new JsValue(new ClrFunctionInstance(engine,
                                                                     (value, values) => new JsValue("function " + propertyName + "() { [native code] }"))),
                                 false, false, false);

            return(new PropertyDescriptor(func, false, true, false));
        }