public DomFunctionInstance(EngineInstance engine, MethodInfo method)
            : base(engine.Jint, method.GetParameterNames(), null, false)
        {
            _engine = engine;
            _method = method;

            FastAddProperty("toString", new ClrFunctionInstance(Engine, ToString), true, false, true);
        }
        /// <summary>
        /// Evaluates the given source.
        /// </summary>
        /// <param name="source">The source code to evaluate.</param>
        /// <param name="options">The options to consider.</param>
        public void Evaluate(String source, ScriptOptions options)
        {
            var objectContext = options.Context;
            var instance = default(EngineInstance);

            if (_contexts.TryGetValue(objectContext, out instance) == false)
                _contexts.Add(objectContext, instance = new EngineInstance(objectContext, _external));

            instance.RunScript(source);
        }
        public DomNodeInstance(EngineInstance engine, Object value)
            : base(engine.Jint)
        {
            _engine = engine;
            _value = value;
            SetAllMembers(value.GetType());

            //  DOM objects can have properties added dynamically
            Extensible = true;
            Prototype = engine.Jint.Object;
        }
        public static JsValue ToJsValue(this Object obj, EngineInstance engine)
        {
            if (obj == null)
                return JsValue.Null;

            if (obj is String)
                return new JsValue((String)obj);
            else if (obj is Int32)
                return new JsValue((Int32)obj);
            else if (obj is UInt32)
                return new JsValue((UInt32)obj);
            else if (obj is Double)
                return new JsValue((Double)obj);
            else if (obj is Single)
                return new JsValue((Single)obj);
            else if (obj is Boolean)
                return new JsValue((Boolean)obj);
            else if (obj is Enum)
                return new JsValue(Convert.ToInt32(obj));

            return engine.GetDomNode(obj);
        }
예제 #5
0
        public static JsValue ToJsValue(this Object obj, EngineInstance engine)
        {
            if (obj == null)
            {
                return(JsValue.Null);
            }

            if (obj is String)
            {
                return(new JsValue((String)obj));
            }
            else if (obj is Int32)
            {
                return(new JsValue((Int32)obj));
            }
            else if (obj is UInt32)
            {
                return(new JsValue((UInt32)obj));
            }
            else if (obj is Double)
            {
                return(new JsValue((Double)obj));
            }
            else if (obj is Single)
            {
                return(new JsValue((Single)obj));
            }
            else if (obj is Boolean)
            {
                return(new JsValue((Boolean)obj));
            }
            else if (obj is Enum)
            {
                return(new JsValue(Convert.ToInt32(obj)));
            }

            return(engine.GetDomNode(obj));
        }
예제 #6
0
        public static T ToCallback <T>(this FunctionInstance function, EngineInstance engine)
        {
            var type       = typeof(T);
            var methodInfo = type.GetRuntimeMethods().First(m => m.Name == "Invoke");
            var convert    = typeof(Extensions).GetRuntimeMethod("ToJsValue", ToJsValueSignature);
            var mps        = methodInfo.GetParameters();
            var parameters = new ParameterExpression[mps.Length];

            for (var i = 0; i < mps.Length; i++)
            {
                parameters[i] = Expression.Parameter(mps[i].ParameterType, mps[i].Name);
            }

            var objExpr    = Expression.Constant(function);
            var engineExpr = Expression.Constant(engine);
            var call       = Expression.Call(objExpr, "Call", new Type[0], new Expression[]
            {
                Expression.Call(convert, parameters[0], engineExpr),
                Expression.NewArrayInit(typeof(JsValue), parameters.Skip(1).Select(m => Expression.Call(convert, m, engineExpr)).ToArray())
            });

            return(Expression.Lambda <T>(call, parameters).Compile());
        }
예제 #7
0
        public static Object As(this JsValue value, Type targetType, EngineInstance engine)
        {
            if (value != JsValue.Null)
            {
                if (targetType == typeof(Int32))
                {
                    return(TypeConverter.ToInt32(value));
                }
                else if (targetType == typeof(Double))
                {
                    return(TypeConverter.ToNumber(value));
                }
                else if (targetType == typeof(String))
                {
                    return(value.IsPrimitive() ? TypeConverter.ToString(value) : value.ToString());
                }
                else if (targetType == typeof(Boolean))
                {
                    return(TypeConverter.ToBoolean(value));
                }
                else if (targetType == typeof(UInt32))
                {
                    return(TypeConverter.ToUint32(value));
                }
                else if (targetType == typeof(UInt16))
                {
                    return(TypeConverter.ToUint16(value));
                }
                else
                {
                    return(value.AsComplex(targetType, engine));
                }
            }

            return(null);
        }
예제 #8
0
 public DomConstructorInstance(EngineInstance engine, ConstructorInfo constructor)
     : base(engine.Jint, null, null, false)
 {
     _engine      = engine;
     _constructor = constructor;
 }
 public DomConstructors(EngineInstance engine)
 {
     Object = engine.Jint.Object;
     _engine = engine;
 }
 partial void Setup(EngineInstance engine);
예제 #11
0
 public static JsValue RunScript(this EngineInstance engine, String source, INode context)
 {
     return(engine.RunScript(source, context.ToJsValue(engine)));
 }
예제 #12
0
 public static JsValue RunScript(this EngineInstance engine, String source)
 {
     return(engine.RunScript(source, engine.Window));
 }
 public DomConstructorInstance(EngineInstance engine, ConstructorInfo constructor)
     : base(engine.Jint, null, null, false)
 {
     _engine = engine;
     _constructor = constructor;
 }
        public static Object As(this Object value, Type targetType, EngineInstance engine)
        {
            if (value == null)
                return value;

            var sourceType = value.GetType();

            if (sourceType == targetType || sourceType.IsSubclassOf(targetType) || targetType.IsInstanceOfType(value) || targetType.IsAssignableFrom(sourceType))
                return value;
            else if (sourceType == typeof(Double) && targetType == typeof(Int32))
                return (Int32)(Double)value;

            if (targetType.IsSubclassOf(typeof(Delegate)) && value is FunctionInstance)
                return targetType.ToDelegate((FunctionInstance)value, engine);

            var method = sourceType.PrepareConvert(targetType);

            if (method != null)
                return method.Invoke(value, null);

            throw new JavaScriptException("[Internal] Could not find corresponding cast target.");
        }
 public DomConstructorInstance(EngineInstance engine, ConstructorInfo constructor)
     : this(engine, constructor.DeclaringType)
 {
     _constructor = constructor;
 }
예제 #16
0
 partial void Setup(EngineInstance engine);
예제 #17
0
 public DomConstructors(EngineInstance engine)
 {
     Object  = engine.Jint.Object;
     _engine = engine;
 }