Set() public method

public Set ( JsDictionaryObject that, JsInstance value ) : void
that JsDictionaryObject
value JsInstance
return void
Beispiel #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++;
            }
        }
        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);
            }
        }
Beispiel #3
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;
            }
        }