コード例 #1
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));
            }
        }