Get() public abstract method

Gets a value stored in the descriptor.
public abstract Get ( JsDictionaryObject that ) : JsInstance
that JsDictionaryObject A target object. This has a meaning in case of descriptors which helds an accessors, /// in value descriptors this parameter is ignored.
return JsInstance
Example #1
0
        public virtual void DefineOwnProperty(Descriptor currentDescriptor)
        {
            string     key = currentDescriptor.Name;
            Descriptor desc;

            if (properties.TryGet(key, out desc) && desc.Owner == this)
            {
                // updating an existing property
                switch (desc.DescriptorType)
                {
                case DescriptorType.Value:
                    switch (currentDescriptor.DescriptorType)
                    {
                    case DescriptorType.Value:
                        properties.Get(key).Set(this, currentDescriptor.Get(this));
                        break;

                    case DescriptorType.Accessor:
                        properties.Delete(key);
                        properties.Put(key, currentDescriptor);
                        break;

                    case DescriptorType.Clr:
                        throw new NotSupportedException();

                    default:
                        break;
                    }
                    break;

                case DescriptorType.Accessor:
                    PropertyDescriptor propDesc = (PropertyDescriptor)desc;
                    if (currentDescriptor.DescriptorType == DescriptorType.Accessor)
                    {
                        propDesc.GetFunction = ((PropertyDescriptor)currentDescriptor).GetFunction ?? propDesc.GetFunction;
                        propDesc.SetFunction = ((PropertyDescriptor)currentDescriptor).SetFunction ?? propDesc.SetFunction;
                    }
                    else
                    {
                        propDesc.Set(this, currentDescriptor.Get(this));
                    }
                    break;

                default:
                    break;
                }
            }
            else
            {
                // add a new property
                if (desc != null)
                {
                    desc.Owner.RedefineProperty(desc.Name); // if we have a cached property
                }
                properties.Put(key, currentDescriptor);
                m_length++;
            }
        }
Example #2
0
        public virtual void DefineOwnProperty(Descriptor currentDescriptor)
        {
            string     name = currentDescriptor.Name;
            Descriptor descriptor;

            if (this.properties.TryGet(name, out descriptor) && descriptor.Owner == this)
            {
                switch (descriptor.DescriptorType)
                {
                case DescriptorType.Value:
                    switch (currentDescriptor.DescriptorType)
                    {
                    case DescriptorType.Value:
                        this.properties.Get(name).Set(this, currentDescriptor.Get(this));
                        return;

                    case DescriptorType.Accessor:
                        this.properties.Delete(name);
                        this.properties.Put(name, currentDescriptor);
                        return;

                    case DescriptorType.Clr:
                        throw new NotSupportedException();

                    default:
                        return;
                    }

                case DescriptorType.Accessor:
                    PropertyDescriptor propertyDescriptor = (PropertyDescriptor)descriptor;
                    if (currentDescriptor.DescriptorType == DescriptorType.Accessor)
                    {
                        propertyDescriptor.GetFunction = ((PropertyDescriptor)currentDescriptor).GetFunction ?? propertyDescriptor.GetFunction;
                        propertyDescriptor.SetFunction = ((PropertyDescriptor)currentDescriptor).SetFunction ?? propertyDescriptor.SetFunction;
                        break;
                    }
                    propertyDescriptor.Set(this, currentDescriptor.Get(this));
                    break;
                }
            }
            else
            {
                if (descriptor != null)
                {
                    descriptor.Owner.RedefineProperty(descriptor.Name);
                }
                this.properties.Put(name, currentDescriptor);
                ++this.m_length;
            }
        }
        public void DefineOwnProperty(string key, Descriptor currentDescriptor)
        {
            Descriptor desc;

            if (properties.TryGet(key, out desc))
            {
                switch (desc.DescriptorType)
                {
                case DescriptorType.Value:
                    switch (currentDescriptor.DescriptorType)
                    {
                    case DescriptorType.Value:
                        properties.Get(key).Set(this, currentDescriptor.Get(this));
                        break;

                    case DescriptorType.Accessor:
                        properties.Delete(key);
                        properties.Put(key, currentDescriptor);
                        break;

                    case DescriptorType.Clr:
                        throw new NotSupportedException();

                    default:
                        break;
                    }
                    break;

                case DescriptorType.Accessor:
                    PropertyDescriptor propDesc = (PropertyDescriptor)desc;
                    if (currentDescriptor.DescriptorType == DescriptorType.Accessor)
                    {
                        propDesc.GetFunction = ((PropertyDescriptor)currentDescriptor).GetFunction ?? propDesc.GetFunction;
                        propDesc.SetFunction = ((PropertyDescriptor)currentDescriptor).SetFunction ?? propDesc.SetFunction;
                    }
                    else
                    {
                        propDesc.Set(this, currentDescriptor.Get(this));
                    }
                    break;

                default:
                    break;
                }
            }
            else
            {
                properties.Put(key, currentDescriptor);
            }
        }
Example #4
0
 public override void DefineOwnProperty(string key, Descriptor d)
 {
     try {
         put(Convert.ToInt32(key), d.Get(this));
     }
     catch (FormatException) {
         base.DefineOwnProperty(key, d);
     }
 }
Example #5
0
 public override JsInstance this[string index] {
     get {
         if (index == THIS && thisDescriptor != null)
         {
             return(thisDescriptor.Get(this));
         }
         if (index == ARGUMENTS && argumentsDescriptor != null)
         {
             return(argumentsDescriptor.Get(this));
         }
         return(base[index]); // will use overriden GetDescriptor
     }
     set {
         if (index == THIS)
         {
             if (thisDescriptor != null)
             {
                 thisDescriptor.Set(this, value);
             }
             else
             {
                 DefineOwnProperty(thisDescriptor = new ValueDescriptor(this, index, value));
             }
         }
         else if (index == ARGUMENTS)
         {
             if (argumentsDescriptor != null)
             {
                 argumentsDescriptor.Set(this, value);
             }
             else
             {
                 DefineOwnProperty(argumentsDescriptor = new ValueDescriptor(this, index, value));
             }
         }
         else
         {
             Descriptor d = GetDescriptor(index);
             if (d != null)
             {
                 d.Set(this, value);
             }
             else if (globalScope != null)
             {
                 // TODO: move to Execution visitor
                 // define missing property in the global scope
                 globalScope.DefineOwnProperty(index, value);
             }
             else
             {
                 // this scope is a global scope
                 DefineOwnProperty(index, value);
             }
         }
     }
 }
Example #6
0
 public virtual IEnumerable <JsInstance> GetValues()
 {
     foreach (Descriptor descriptor1 in this.properties.Values)
     {
         Descriptor descriptor = descriptor1;
         if (descriptor.Enumerable)
         {
             yield return(descriptor.Get(this));
         }
         descriptor = (Descriptor)null;
     }
 }
Example #7
0
        public virtual bool TryGetProperty(string index, out JsInstance result)
        {
            Descriptor descriptor = this.GetDescriptor(index);

            if (descriptor == null)
            {
                result = (JsInstance)JsUndefined.Instance;
                return(false);
            }
            result = descriptor.Get(this);
            return(true);
        }
        public virtual Descriptor GetDescriptor(string index)
        {
            if (index == PROTOTYPE)
            {
                return(prototypeDescriptor);
            }

            if (index == CONSTRUCTOR && constructorDescriptor != null)
            {
                return(constructorDescriptor);
            }

            Descriptor result;

            if (properties.TryGet(index, out result))
            {
                if (index == CONSTRUCTOR)
                {
                    constructorDescriptor = result;
                }
                return(result);
            }

            JsDictionaryObject prototype = Prototype;

            if (prototype != JsUndefined.Instance && prototype != JsNull.Instance)
            {
                result = Prototype.GetDescriptor(index);
                if (result != null)
                {
                    return(result);
                }

                if (index != CONSTRUCTOR)
                {
                    Descriptor ctorDescriptor = GetDescriptor(CONSTRUCTOR);
                    if (ctorDescriptor != null)
                    {
                        JsInstance ctor = ctorDescriptor.Get(this);
                        if (ctor != JsUndefined.Instance && ctor != JsNull.Instance)
                        {
                            return(((JsFunction)ctor).Scope.GetDescriptor(index));
                        }
                    }
                }

                return(result);
            }
            else
            {
                return(null);
            }
        }
Example #9
0
        public override void DefineOwnProperty(Descriptor d)
        {
            int index;

            if (int.TryParse(d.Name, out index))
            {
                put(index, d.Get(this));
            }
            else
            {
                base.DefineOwnProperty(d);
            }
        }
Example #10
0
        public override void DefineOwnProperty(Descriptor d)
        {
            int result;

            if (int.TryParse(d.Name, out result))
            {
                this.put(result, d.Get((JsDictionaryObject)this));
            }
            else
            {
                base.DefineOwnProperty(d);
            }
        }
        public bool TryGetProperty(string index, out JsInstance result)
        {
            Descriptor d = GetDescriptor(index);

            if (d == null)
            {
                result = JsUndefined.Instance;
                return(false);
            }

            result = d.Get(this);

            return(true);
        }
        public override JsInstance this[string index]
        {
            get
            {
                if (index == THIS && thisDescriptor != null)
                {
                    return(thisDescriptor.Get(this));
                }
                if (index == ARGUMENTS && argumentsDescriptor != null)
                {
                    return(argumentsDescriptor.Get(this));
                }
                return(base[index]);
            }
            set
            {
                if (Extensible)
                {
                    if (index == THIS)
                    {
                        if (thisDescriptor != null)
                        {
                            thisDescriptor.Set(this, value);
                        }
                        else
                        {
                            DefineOwnProperty(index, thisDescriptor = new ValueDescriptor(this, index, value));
                        }
                    }
                    if (index == ARGUMENTS)
                    {
                        if (argumentsDescriptor != null)
                        {
                            argumentsDescriptor.Set(this, value);
                        }
                        else
                        {
                            DefineOwnProperty(index, argumentsDescriptor = new ValueDescriptor(this, index, value));
                        }
                    }

                    base[index] = value;
                }
                else
                {
                    Prototype[index] = value;
                }
            }
        }
Example #13
0
 public virtual JsInstance this[string index] {
     get {
         Descriptor d = GetDescriptor(index);
         return(d != null?d.Get(this) : JsUndefined.Instance);
     }
     set {
         Descriptor d = GetDescriptor(index);
         if (d == null || (d.Owner != this && d.DescriptorType == DescriptorType.Value))
         {
             DefineOwnProperty(new ValueDescriptor(this, index, value));
         }
         else
         {
             d.Set(this, value);
         }
     }
 }
Example #14
0
 public virtual JsInstance this[string index]
 {
     get
     {
         Descriptor descriptor = this.GetDescriptor(index);
         return(descriptor != null?descriptor.Get(this) : (JsInstance)JsUndefined.Instance);
     }
     set
     {
         Descriptor descriptor = this.GetDescriptor(index);
         if (descriptor == null || descriptor.Owner != this && descriptor.DescriptorType == DescriptorType.Value)
         {
             this.DefineOwnProperty((Descriptor) new ValueDescriptor(this, index, value));
         }
         else
         {
             descriptor.Set(this, value);
         }
     }
 }
        public virtual JsInstance this[string index]
        {
            get
            {
                Descriptor d = GetDescriptor(index);
                return(d != null?d.Get(this) : JsUndefined.Instance);
            }
            set
            {
                Descriptor d = GetDescriptor(index);
                if (d == null || (d.DescriptorType == DescriptorType.Value && d.Owner != this))
                {
                    bool enumerable = index != PROTOTYPE;

                    if (index == PROTOTYPE)
                    {
                        prototypeDescriptor.Set(this, value);
                    }
                    else
                    {
                        if (d == null)
                        {
                            properties.Put(index, new ValueDescriptor(this, index, value)
                            {
                                Enumerable = enumerable
                            });
                        }
                        else
                        {
                            d.Set(this, value);
                        }
                    }
                }
                else
                {
                    d.Set(this, value);
                }
            }
        }
 public override JsInstance Get(JsDictionaryObject that)
 {
     return(d.Get(that));
 }
Example #17
0
File: JsArray.cs Project: cosh/Jint
 public override void DefineOwnProperty(Descriptor d)
 {
     int index;
     if(int.TryParse(d.Name, out index))
         put(index, d.Get(this));
     else
         base.DefineOwnProperty(d);
 }
Example #18
0
 public override void DefineOwnProperty(string key, Descriptor d)
 {
     try {
         put(Convert.ToInt32(key), d.Get(this));
     }
     catch (FormatException) {
         base.DefineOwnProperty(key, d);
     }
 }
Example #19
0
 public override JsInstance this[string index] {
     get {
         if (index == THIS && thisDescriptor != null)
         {
             return(thisDescriptor.Get(this));
         }
         if (index == ARGUMENTS && argumentsDescriptor != null)
         {
             return(argumentsDescriptor.Get(this));
         }
         return(base[index]); // will use overriden GetDescriptor
     }
     set {
         if (index == THIS)
         {
             if (thisDescriptor != null)
             {
                 thisDescriptor.Set(this, value);
             }
             else
             {
                 DefineOwnProperty(index, thisDescriptor = new ValueDescriptor(this, index, value));
             }
         }
         else if (index == ARGUMENTS)
         {
             if (argumentsDescriptor != null)
             {
                 argumentsDescriptor.Set(this, value);
             }
             else
             {
                 DefineOwnProperty(index, argumentsDescriptor = new ValueDescriptor(this, index, value));
             }
         }
         else
         {
             Descriptor d = GetDescriptor(index);
             if (d != null)
             {
                 // we have a property in the scopes hierarchy or in the bag
                 if (d.Owner == bag || d.Owner == this || d.Owner.IsPrototypeOf(this))
                 {
                     // if this is an own property of the bag or in scopes
                     d.Set(d.Owner, value);
                 }
                 else
                 {
                     // this property should be from one of prototypes of the bag
                     if (bag != null)
                     {
                         bag[index] = value;
                     }
                 }
             }
             else if (globalScope != null)
             {
                 // define missing property in the global scope
                 globalScope.DefineOwnProperty(index, value);
             }
             else
             {
                 // this scope is a global scope
                 DefineOwnProperty(index, value);
             }
         }
     }
 }