Пример #1
0
        /// <summary>
        /// Returns the value of the member of the specified name referring to <c>super</c>.
        /// </summary>
        /// <param name="context">The runtime context.</param>
        /// <param name="name">The name of the member.</param>
        /// <returns>The value of the member <paramref name="name"/>.</returns>
        IScriptObject ISuperMemberObject.GetSuperMember(RuntimeContexts.RuntimeContext context, string name)
        {
            var cls = context.Class as ClassObject;

            if (cls != null)
            {
                var super = cls.Super;
                if (ClassHelper.IsExtendedFrom(this.Class, super))
                {
                    var member = super.GetMember(context, name, false);
                    var mtd    = member as ClassMethod;
                    if (mtd != null)
                    {
                        return(new BoundMethod(this, mtd));
                    }
                    var proget = member as PropertyGetter;
                    if (proget != null)
                    {
                        return(proget.GetProperty(this));
                    }
                    throw new InvalidOperationException(
                              string.Format(ExceptionResource.MemberNotFound, name));
                }
            }
            throw new InvalidOperationException(
                      ExceptionResource.SuperMustBeInExtendedClass);
        }
Пример #2
0
        internal ClassMember SetItem(RuntimeContexts.RuntimeContext context, bool isStatic)
        {
            var         members = isStatic ? StaticMembers : InstanceMembers;
            ClassMember value;
            string      rename;
            string      idxget = ClassHelper.RenameIndexerGetter;
            string      idxset = ClassHelper.RenameIndexerSetter;
            var         cls    = context.Class as ClassObject;

            if (cls != null)
            {
                rename = ClassHelper.RenamePrivate(idxset, cls.Name);
                if (members.TryGetValue(rename, out value) && value is IndexerSetter)
                {
                    return(value);
                }
                rename = ClassHelper.RenamePrivate(idxget, cls.Name);
                if (members.TryGetValue(rename, out value) && value is IndexerGetter)
                {
                    return(ClassHelper.ThrowIndexerIsReadonly());
                }
            }
            {
                rename = idxset;
                if (members.TryGetValue(rename, out value) && value is IndexerSetter)
                {
                    return(value);
                }
                rename = idxget;
                if (members.TryGetValue(rename, out value) && value is IndexerGetter)
                {
                    return(ClassHelper.ThrowIndexerIsReadonly());
                }
            }
            if (cls == this || ClassHelper.IsExtendedFrom(this, cls) || ClassHelper.IsExtendedFrom(cls, this))
            {
                rename = ClassHelper.RenameProtected(idxset);
                if (members.TryGetValue(rename, out value) && value is IndexerSetter)
                {
                    return(value);
                }
                rename = ClassHelper.RenameProtected(idxget);
                if (members.TryGetValue(rename, out value) && value is IndexerGetter)
                {
                    return(ClassHelper.ThrowIndexerIsReadonly());
                }
            }
            if (Super != null)
            {
                return(Super.SetItem(context, isStatic));
            }
            return(ClassHelper.ThrowIndexerNotSupported());
        }
Пример #3
0
        /// <summary>
        /// Returns the value of the member of the specified name.
        /// </summary>
        /// <param name="context">The runtime context.</param>
        /// <param name="name">The name of the member.</param>
        /// <returns>The value of the member <paramref name="name"/>.</returns>
        IScriptObject IMemberObject.GetMember(RuntimeContexts.RuntimeContext context, string name)
        {
            IScriptObject value;
            string        rename;
            var           cls = context.Class as ClassObject;

            if (cls != null)
            {
                rename = ClassHelper.RenamePrivate(name, cls.Name);
                if (Fields.TryGetValue(rename, out value))
                {
                    return(value);
                }
            }
            {
                rename = name;
                if (Fields.TryGetValue(rename, out value))
                {
                    return(value);
                }
            }
            if (cls == this.Class || ClassHelper.IsExtendedFrom(this.Class, cls) || ClassHelper.IsExtendedFrom(cls, this.Class))
            {
                rename = ClassHelper.RenameProtected(name);
                if (Fields.TryGetValue(rename, out value))
                {
                    return(value);
                }
            }
            {
                var member = Class.GetMember(context, name, false);
                var mtd    = member as ClassMethod;
                if (mtd != null)
                {
                    return(new BoundMethod(this, mtd));
                }
                var proget = member as PropertyGetter;
                if (proget != null)
                {
                    return(proget.GetProperty(this));
                }
            }
            throw new InvalidOperationException(
                      string.Format(ExceptionResource.MemberNotFound, name));
        }
Пример #4
0
        /// <summary>
        /// Sets the value of the member of the specified name to the specified value.
        /// </summary>
        /// <param name="context">The runtime context.</param>
        /// <param name="name">The name of the member.</param>
        /// <param name="value">The value to set.</param>
        void IMemberObject.SetMember(RuntimeContexts.RuntimeContext context, string name, IScriptObject value)
        {
            string rename;
            var    cls = context.Class as ClassObject;

            if (cls != null)
            {
                rename = ClassHelper.RenamePrivate(name, cls.Name);
                if (Fields.ContainsKey(rename))
                {
                    Fields[rename] = value;
                    return;
                }
            }
            {
                rename = name;
                if (Fields.ContainsKey(rename))
                {
                    Fields[rename] = value;
                    return;
                }
            }
            if (cls == this.Class || ClassHelper.IsExtendedFrom(this.Class, cls) || ClassHelper.IsExtendedFrom(cls, this.Class))
            {
                rename = ClassHelper.RenameProtected(name);
                if (Fields.ContainsKey(rename))
                {
                    Fields[rename] = value;
                    return;
                }
            }
            {
                var member = Class.SetMember(context, name, false);
                var proset = member as PropertySetter;
                if (proset != null)
                {
                    proset.SetProperty(this, value);
                    return;
                }
            }
            throw new InvalidOperationException(
                      string.Format(ExceptionResource.MemberNotFound, name));
        }
Пример #5
0
        /// <summary>
        /// Invokes the <c>get</c> accessor of the indexer referring to <c>super</c> with the specified parameters and returns the value.
        /// </summary>
        /// <param name="context">The runtime context.</param>
        /// <param name="indices">The parameters passed to the indexer.</param>
        /// <returns>The return value of the indexer.</returns>
        IScriptObject ISuperIndexableObject.GetSuperItem(RuntimeContexts.RuntimeContext context, List <IScriptObject> indices)
        {
            var cls = context.Class as ClassObject;

            if (cls != null)
            {
                var super = cls.Super;
                if (ClassHelper.IsExtendedFrom(this.Class, super))
                {
                    var member = super.GetItem(context, false);
                    var idxget = member as IndexerGetter;
                    if (idxget != null)
                    {
                        return(idxget.GetItem(this, indices));
                    }
                    throw new InvalidOperationException(
                              ExceptionResource.IndexerNotSupported);
                }
            }
            throw new InvalidOperationException(
                      ExceptionResource.SuperMustBeInExtendedClass);
        }
Пример #6
0
        /// <summary>
        /// Sets the value of the member of the specified name referring to <c>super</c> to the specified value.
        /// </summary>
        /// <param name="context">The runtime context.</param>
        /// <param name="name">The name of the member.</param>
        /// <param name="value">The value to set.</param>
        void ISuperMemberObject.SetSuperMember(RuntimeContexts.RuntimeContext context, string name, IScriptObject value)
        {
            var cls = context.Class as ClassObject;

            if (cls != null)
            {
                var super = cls.Super;
                if (ClassHelper.IsExtendedFrom(this.Class, super))
                {
                    var member = super.SetMember(context, name, false);
                    var proset = member as PropertySetter;
                    if (proset != null)
                    {
                        proset.SetProperty(this, value);
                        return;
                    }
                    throw new InvalidOperationException(
                              string.Format(ExceptionResource.MemberNotFound, name));
                }
            }
            throw new InvalidOperationException(
                      ExceptionResource.SuperMustBeInExtendedClass);
        }
Пример #7
0
        internal ClassMember SetMember(RuntimeContexts.RuntimeContext context, string name, bool isStatic)
        {
            var         members = isStatic ? StaticMembers : InstanceMembers;
            ClassMember value;
            string      rename;
            string      propget = ClassHelper.RenamePropertyGetter(name);
            string      propset = ClassHelper.RenamePropertySetter(name);
            var         cls     = context.Class as ClassObject;

            if (cls != null)
            {
                rename = ClassHelper.RenamePrivate(name, cls.Name);
                if (members.TryGetValue(rename, out value) && value is ClassMethod)
                {
                    return(ClassHelper.ThrowCannotAssignMethod(name));
                }
                rename = ClassHelper.RenamePrivate(propset, cls.Name);
                if (members.TryGetValue(rename, out value) && value is PropertySetter)
                {
                    return(value);
                }
                rename = ClassHelper.RenamePrivate(propget, cls.Name);
                if (members.TryGetValue(rename, out value) && value is PropertyGetter)
                {
                    return(ClassHelper.ThrowPropertyIsReadonly(name));
                }
            }
            {
                rename = name;
                if (members.TryGetValue(rename, out value) && value is ClassMethod)
                {
                    return(ClassHelper.ThrowCannotAssignMethod(name));
                }
                rename = propset;
                if (members.TryGetValue(rename, out value) && value is PropertySetter)
                {
                    return(value);
                }
                rename = propget;
                if (members.TryGetValue(rename, out value) && value is PropertyGetter)
                {
                    return(ClassHelper.ThrowPropertyIsReadonly(name));
                }
            }
            if (cls == this || ClassHelper.IsExtendedFrom(this, cls) || ClassHelper.IsExtendedFrom(cls, this))
            {
                rename = ClassHelper.RenameProtected(name);
                if (members.TryGetValue(rename, out value) && value is ClassMethod)
                {
                    return(value);
                }
                rename = ClassHelper.RenameProtected(propset);
                if (members.TryGetValue(rename, out value) && value is PropertySetter)
                {
                    return(value);
                }
                rename = ClassHelper.RenameProtected(propget);
                if (members.TryGetValue(rename, out value) && value is PropertyGetter)
                {
                    return(ClassHelper.ThrowPropertyIsReadonly(name));
                }
            }
            if (Super != null)
            {
                return(Super.SetMember(context, name, isStatic));
            }
            return(ClassHelper.ThrowMemberNotFound(name));
        }