コード例 #1
0
        public static JsValue Call(this EngineInstance instance, MethodInfo method, JsValue thisObject, JsValue[] arguments)
        {
            if (method != null && thisObject.Type == Types.Object)
            {
                if (thisObject.AsObject() is DomNodeInstance node)
                {
                    try
                    {
                        if (method.IsStatic)
                        {
                            var newArgs = new List <JsValue>
                            {
                                thisObject,
                            };
                            newArgs.AddRange(arguments);
                            var parameters = instance.BuildArgs(method, newArgs.ToArray());
                            return(method.Invoke(null, parameters).ToJsValue(instance));
                        }
                        else
                        {
                            var parameters = instance.BuildArgs(method, arguments);
                            return(method.Invoke(node.Value, parameters).ToJsValue(instance));
                        }
                    }
                    catch (TargetInvocationException)
                    {
                        throw new JavaScriptException(instance.Jint.Error);
                    }
                }
            }

            return(JsValue.Undefined);
        }
コード例 #2
0
        ObjectInstance IConstructor.Construct(JsValue[] arguments)
        {
            if (_constructor == null)
            {
                throw new JavaScriptException("Illegal constructor.");
            }

            try
            {
                var parameters = _instance.BuildArgs(_constructor, arguments);
                var obj        = _constructor.Invoke(parameters);
                return(_instance.GetDomNode(obj));
            }
            catch
            {
                throw new JavaScriptException(_instance.Jint.Error);
            }
        }
コード例 #3
0
        private void SetProperty(String name, MethodInfo getter, MethodInfo setter, DomPutForwardsAttribute putsForward)
        {
            FastSetProperty(name, new PropertyDescriptor(
                                new DomDelegateInstance(_instance, name, (obj, values) =>
                                                        _instance.Call(getter, obj, values)),
                                new DomDelegateInstance(_instance, name, (obj, values) =>
            {
                if (putsForward != null)
                {
                    var ep       = Array.Empty <Object>();
                    var that     = obj.AsObject() as DomNodeInstance;
                    var target   = getter.Invoke(that.Value, ep);
                    var propName = putsForward.PropertyName;
                    var prop     = getter.ReturnType
                                   .GetInheritedProperties()
                                   .FirstOrDefault(m => m.GetCustomAttributes <DomNameAttribute>().Any(n => n.OfficialName.Is(propName)));
                    var args = _instance.BuildArgs(prop.SetMethod, values);
                    prop.SetMethod.Invoke(target, args);
                    return(prop.GetMethod.Invoke(target, ep).ToJsValue(_instance));
                }

                return(_instance.Call(setter, obj, values));
            }), false, false));
        }