PropertyDescriptor AddOwnPropertyDescriptor(string field, PropertyDescriptor.Attributes attributes) { var propDesc = Map.GetPropertyDescriptor(field); if (propDesc == null || propDesc.IsUndefined || propDesc.IsInherited) { propDesc = Map.AddOwnProperty(this, field, Runtime.Instance.GetFieldId(field), attributes); } else if (attributes != propDesc.GetAttributes()) { Trace.Assert(!propDesc.IsNotConfigurable, "Cannot reconfigure property {0} in the object", field); var maps = new PropertyMap[Map.Property.Index + 1]; var i = 0; var m = Map; while (m.Property != propDesc) { maps[i++] = m; m = m.Parent; } Debug.Assert( propDesc != null && m != null && m.Parent != null , "Invalid situation, we must have found a proper map pointing to existing property descriptor"); m = m.Parent.AddOwnProperty(field, Runtime.Instance.GetFieldId(field), attributes); for (--i; i >= 0; --i) { var pd = maps[i].Property; m = m.AddOwnProperty(pd.Name, pd.NameId, pd.GetAttributes()); } Map = m; } Debug.Assert(!propDesc.IsInherited && (propDesc.IsDataDescriptor || propDesc.IsAccessorDescriptor), "You can use this method only for own properties"); return(propDesc); }
/// only none-array fields can have attributes other than Data, therefore we only need the followings and no need to virtualize public PropertyDescriptor AddOwnPropertyDescriptorByFieldId(int fieldId, PropertyDescriptor.Attributes attributes) { Debug.Assert(fieldId >= 0, "FieldId cannot be negative!"); var propDesc = Map.GetPropertyDescriptorByFieldId(fieldId); if (propDesc == null || propDesc.IsUndefined || propDesc.IsInherited) { propDesc = Map.AddOwnProperty(this, Runtime.Instance.GetFieldName(fieldId), fieldId, attributes); } else { Trace.Assert(attributes == propDesc.GetAttributes(), "Updating existing own propery with different attributes is not supported via FieldID"); } Debug.Assert(!propDesc.IsInherited && (propDesc.IsDataDescriptor || propDesc.IsAccessorDescriptor), "You can use this method only for own properties"); return(propDesc); }
/// <summary> /// This method is public for the compiler to generate faster code by directly manipulating the map when needed /// </summary> public PropertyMap AddOwnProperty(string field, int fieldId, PropertyDescriptor.Attributes attributes) { Debug.Assert(fieldId != Runtime.InvalidFieldId, "Invalid situation! FieldId of {0} is not assigned", field); Debug.Assert(GetOwnPropertyDescriptorByFieldId(fieldId) == null, "Invalid situation! Field {0} alread exists in the map", field); PropertyMap newMap = null; if (_children == null) { _children = new Dictionary <int, PropertyMap>(); } int key = ((int)attributes << 16) | (fieldId & 0xFFFF); if (!_children.TryGetValue(key, out newMap)) { var overridenProperty = Metadata.GetInheritedPropertyDescriptorByFieldId(fieldId); newMap = new PropertyMap(Metadata, this, new PropertyDescriptor(field, fieldId, this.Property.Index + 1, attributes), overridenProperty); _children[key] = newMap; } return(newMap); }
internal PropertyDescriptor AddInheritedProperty(string field, int fieldId, int index, PropertyDescriptor.Attributes attributes = PropertyDescriptor.Attributes.Undefined) { var propDesc = new PropertyDescriptor(field, fieldId, index, attributes); _inheritedProperties.AddFirst(propDesc); return(propDesc); }
internal PropertyDescriptor AddOwnProperty(DObject obj, string field, int fieldId, PropertyDescriptor.Attributes attributes) { PropertyMap newMap = AddOwnProperty(field, fieldId, attributes); obj.Map = newMap; var mapMetadata = Metadata.GetMapMetadataOfPrototype(obj, false); if (mapMetadata != null) { mapMetadata.PropagateAdditionDownPrototypeChain(obj, newMap.Property); //obj is some other objects' prototype } return(newMap.Property); }
public void DefineOwnProperty(string field, DProperty v, PropertyDescriptor.Attributes flags = PropertyDescriptor.Attributes.None) { var pd = AddOwnPropertyDescriptor(field, PropertyDescriptor.Attributes.Accessor | flags); Fields[pd.Index].Set(v); }
public void DefineOwnProperty(string field, ref DValue v, PropertyDescriptor.Attributes attributes) { var pd = AddOwnPropertyDescriptor(field, attributes); Fields[pd.Index].Set(ref v); }
public void DefineOwnProperty(string field, DObject v, PropertyDescriptor.Attributes attributes) { var pd = AddOwnPropertyDescriptor(field, attributes); Fields[pd.Index].Set(v); }