예제 #1
0
        public JSValue SetValue(JSContext ctx, JSValue this_obj, JSValue val)
        {
            if (!_fieldInfo.IsPublic && !_type.privateAccess)
            {
                return(JSApi.JS_ThrowInternalError(ctx, "field is inaccessible due to its protection level"));
            }
            object self = null;

            if (!_fieldInfo.IsStatic)
            {
                Values.js_get_cached_object(ctx, this_obj, out self);
                if (!_type.CheckThis(self))
                {
                    throw new ThisBoundException();
                }
            }
            object t_val = null;

            if (!Values.js_get_var(ctx, val, _fieldInfo.FieldType, out t_val))
            {
                return(JSApi.JS_ThrowInternalError(ctx, "failed to cast val"));
            }
            _fieldInfo.SetValue(self, t_val);
            return(JSApi.JS_UNDEFINED);
        }
예제 #2
0
        public JSValue SetValue(JSContext ctx, JSValue this_obj, JSValue val)
        {
            if (!_fieldInfo.IsPublic && !_type.privateAccess)
            {
                throw new InaccessibleMemberException(_fieldInfo.Name);
            }
            object self = null;

            if (!_fieldInfo.IsStatic)
            {
                Values.js_get_cached_object(ctx, this_obj, out self);
                if (!_type.CheckThis(self))
                {
                    throw new ThisBoundException();
                }
            }
            object t_val = null;

            if (!Values.js_get_var(ctx, val, _fieldInfo.FieldType, out t_val))
            {
                throw new InvalidCastException();
            }
            _fieldInfo.SetValue(self, t_val);
            return(JSApi.JS_UNDEFINED);
        }
예제 #3
0
        public JSValue SetValue(JSContext ctx, JSValue this_obj, JSValue val)
        {
            if (_propertyInfo.SetMethod == null)
            {
                throw new NullReferenceException("property setter is null");
            }
            if (!_propertyInfo.SetMethod.IsPublic && !_type.privateAccess)
            {
                throw new InaccessibleMemberException(_propertyInfo.Name);
            }
            object self = null;

            if (!_propertyInfo.SetMethod.IsStatic)
            {
                Values.js_get_cached_object(ctx, this_obj, out self);
                if (!_type.CheckThis(self))
                {
                    throw new ThisBoundException();
                }
            }
            object t_val = null;

            if (!Values.js_get_var(ctx, val, _propertyInfo.PropertyType, out t_val))
            {
                throw new InvalidCastException();
            }
            _propertyInfo.SetValue(self, t_val);
            return(JSApi.JS_UNDEFINED);
        }
예제 #4
0
        public JSValue GetValue(JSContext ctx, JSValue this_obj)
        {
            if (!_fieldInfo.IsPublic && !_type.privateAccess)
            {
                return(JSApi.JS_ThrowInternalError(ctx, "field is inaccessible due to its protection level"));
            }
            object self = null;

            if (!_fieldInfo.IsStatic)
            {
                Values.js_get_cached_object(ctx, this_obj, out self);
                if (!_type.CheckThis(self))
                {
                    throw new ThisBoundException();
                }
            }
            return(Values.js_push_var(ctx, _fieldInfo.GetValue(self)));
        }
예제 #5
0
        public JSValue GetValue(JSContext ctx, JSValue this_obj)
        {
            if (!_fieldInfo.IsPublic && !_type.privateAccess)
            {
                throw new InaccessibleMemberException(_fieldInfo.Name);
            }
            object self = null;

            if (!_fieldInfo.IsStatic)
            {
                Values.js_get_cached_object(ctx, this_obj, out self);
                if (!_type.CheckThis(self))
                {
                    throw new ThisBoundException();
                }
            }
            return(Values.js_push_var(ctx, _fieldInfo.GetValue(self)));
        }
예제 #6
0
        public JSValue GetValue(JSContext ctx, JSValue this_obj)
        {
            if (_propertyInfo.GetMethod == null)
            {
                throw new NullReferenceException("property getter is null");
            }
            if (!_propertyInfo.GetMethod.IsPublic && !_type.privateAccess)
            {
                throw new InaccessibleMemberException(_propertyInfo.Name);
            }
            object self = null;

            if (!_propertyInfo.GetMethod.IsStatic)
            {
                Values.js_get_cached_object(ctx, this_obj, out self);
                if (!_type.CheckThis(self))
                {
                    throw new ThisBoundException();
                }
            }
            return(Values.js_push_var(ctx, _propertyInfo.GetValue(self)));
        }
예제 #7
0
        public override JSValue Invoke(JSContext ctx, JSValue this_obj, int argc, JSValue[] argv)
        {
            if (!_methodInfo.IsPublic && !_type.privateAccess)
            {
                return(JSApi.JS_ThrowInternalError(ctx, "method is inaccessible due to its protection level"));
            }
            object self = null;

            if (!_methodInfo.IsStatic)
            {
                Values.js_get_cached_object(ctx, this_obj, out self);
                if (!_type.CheckThis(self))
                {
                    throw new ThisBoundException();
                }
            }
            var parameters = _methodInfo.GetParameters();
            var nArgs      = argc;
            var args       = new object[nArgs];

            for (var i = 0; i < nArgs; i++)
            {
                if (!Values.js_get_var(ctx, argv[i], parameters[i].ParameterType, out args[i]))
                {
                    return(JSApi.JS_ThrowInternalError(ctx, "failed to cast val"));
                }
            }
            if (_methodInfo.ReturnType != typeof(void))
            {
                var ret = _methodInfo.Invoke(self, args);
                return(Values.js_push_var(ctx, ret));
            }
            else
            {
                _methodInfo.Invoke(self, args);
                return(JSApi.JS_UNDEFINED);
            }
        }
예제 #8
0
        public JSValue Invoke(JSContext ctx, JSValue this_obj, int argc, JSValue[] argv)
        {
            try
            {
                var op           = Values.js_parse_event_op(ctx, argv[0]);
                var delegateType = _eventInfo.EventHandlerType;

                switch (op)
                {
                case Values.EVT_OP_ADD:
                {
                    var eventInfoAddMethod = _eventInfo.GetAddMethod(true);
                    if (eventInfoAddMethod == null)
                    {
                        throw new InaccessibleMemberException(_eventInfo.Name);
                    }

                    if (!eventInfoAddMethod.IsPublic && !_type.privateAccess)
                    {
                        throw new InaccessibleMemberException(_eventInfo.Name);
                    }

                    object self = null;
                    if (!eventInfoAddMethod.IsStatic)
                    {
                        Values.js_get_cached_object(ctx, this_obj, out self);
                        if (!_type.CheckThis(self))
                        {
                            throw new ThisBoundException();
                        }
                    }

                    Delegate value;
                    if (!Values.js_get_delegate(ctx, argv[1], delegateType, out value))
                    {
                        throw new ParameterException(_type.type, _varName, delegateType, 1);
                    }
                    _eventInfo.AddEventHandler(self, value);
                    return(JSApi.JS_UNDEFINED);
                }

                case Values.EVT_OP_REMOVE:
                {
                    var eventInfoRemoveMethod = _eventInfo.GetRemoveMethod(true);
                    if (eventInfoRemoveMethod == null)
                    {
                        throw new InaccessibleMemberException(_eventInfo.Name);
                    }

                    if (!eventInfoRemoveMethod.IsPublic && !_type.privateAccess)
                    {
                        throw new InaccessibleMemberException(_eventInfo.Name);
                    }

                    object self = null;
                    if (!eventInfoRemoveMethod.IsStatic)
                    {
                        Values.js_get_cached_object(ctx, this_obj, out self);
                        if (!_type.CheckThis(self))
                        {
                            throw new ThisBoundException();
                        }
                    }

                    Delegate value;
                    if (!Values.js_get_delegate(ctx, argv[1], delegateType, out value))
                    {
                        throw new ParameterException(_type.type, _varName, delegateType, 1);
                    }
                    _eventInfo.RemoveEventHandler(self, value);
                    return(JSApi.JS_UNDEFINED);
                }

                default: throw new JSException("invalid event op");
                }
            }
            catch (Exception exception)
            {
                return(JSApi.ThrowException(ctx, exception));
            }
        }
예제 #9
0
        public JSValue Invoke(JSContext ctx, JSValue this_obj, int argc, JSValue[] argv)
        {
            if (!_fieldInfo.IsPublic && !_type.privateAccess)
            {
                throw new InaccessibleMemberException(_fieldInfo.Name);
            }

            object self = null;

            if (!_fieldInfo.IsStatic)
            {
                Values.js_get_cached_object(ctx, this_obj, out self);
                if (!_type.CheckThis(self))
                {
                    throw new ThisBoundException();
                }
            }

            try
            {
                var op           = Values.js_parse_event_op(ctx, argv[0]);
                var delegateType = _fieldInfo.FieldType;

                switch (op)
                {
                case Values.EVT_OP_ADD:
                {
                    Delegate value;
                    if (!Values.js_get_delegate(ctx, argv[1], delegateType, out value))
                    {
                        throw new ParameterException(_type.type, _varName, delegateType, 1);
                    }
                    var fValue = (Delegate)_fieldInfo.GetValue(self);
                    _fieldInfo.SetValue(self, Delegate.Combine(fValue, value));
                    return(JSApi.JS_UNDEFINED);
                }

                case Values.EVT_OP_REMOVE:
                {
                    Delegate value;
                    if (!Values.js_get_delegate(ctx, argv[1], delegateType, out value))
                    {
                        throw new ParameterException(_type.type, _varName, delegateType, 1);
                    }
                    var fValue = (Delegate)_fieldInfo.GetValue(self);
                    _fieldInfo.SetValue(self, Delegate.Remove(fValue, value));
                    return(JSApi.JS_UNDEFINED);
                }

                case Values.EVT_OP_SET:
                {
                    Delegate value;
                    if (!Values.js_get_delegate(ctx, argv[1], delegateType, out value))
                    {
                        throw new ParameterException(_type.type, _varName, delegateType, 1);
                    }
                    _fieldInfo.SetValue(self, value);
                    return(JSApi.JS_UNDEFINED);
                }

                case Values.EVT_OP_GET:
                {
                    var ret = (Delegate)_fieldInfo.GetValue(self);
                    return(Values.js_push_delegate(ctx, ret));
                }

                default: throw new JSException("invalid event op");
                }
            }
            catch (Exception exception)
            {
                return(JSApi.ThrowException(ctx, exception));
            }
        }