/// <summary> /// Defines or redefines the value and attributes of a property. The prototype chain is /// not searched so if the property exists but only in the prototype chain a new property /// will be created. /// </summary> /// <param name="key"> The property key of the property to modify. </param> /// <param name="descriptor"> The property value and attributes. </param> /// <param name="throwOnError"> <c>true</c> to throw an exception if the property could not /// be set. This can happen if the property is not configurable or the object is sealed. </param> /// <returns> <c>true</c> if the property was successfully modified; <c>false</c> otherwise. </returns> public override bool DefineProperty(object key, PropertyDescriptor descriptor, bool throwOnError) { // Check if the property is an indexed property. uint arrayIndex = ArrayInstance.ParseArrayIndex(key); if (arrayIndex < this.Length) { return(IsCompatiblePropertyDescriptor(IsExtensible, descriptor, GetOwnPropertyDescriptor(arrayIndex))); } // Delegate to the base class. return(base.DefineProperty(key, descriptor, throwOnError)); }
public static new ArrayInstance OwnKeys(object target) { if (target is ObjectInstance targetObjectInstance) { // Indexes should be in numeric order. var indexes = new List <uint>(); foreach (var key in targetObjectInstance.OwnKeys) { if (key is string keyStr) { uint arrayIndex = ArrayInstance.ParseArrayIndex(keyStr); if (arrayIndex != uint.MaxValue) { indexes.Add(arrayIndex); } } } indexes.Sort(); var result = targetObjectInstance.Engine.Array.New(); foreach (uint index in indexes) { result.Push(index.ToString()); } // Strings, in insertion order. foreach (var key in targetObjectInstance.OwnKeys) { if (key is string keyStr) { uint arrayIndex = ArrayInstance.ParseArrayIndex(keyStr); if (arrayIndex == uint.MaxValue) { result.Push(keyStr); } } } // Symbols, in insertion order. foreach (var key in targetObjectInstance.OwnKeys) { if (key is Symbol) { result.Push(key); } } return(result); } throw new JavaScriptException(ErrorType.TypeError, "Reflect.ownKeys called on non-object."); }
public static ArrayInstance OwnKeys(ObjectInstance target) { // Indexes should be in numeric order. var indexes = new List <uint>(); foreach (var property in target.Properties) { if (property.Key is string key) { uint arrayIndex = ArrayInstance.ParseArrayIndex(key); if (arrayIndex != uint.MaxValue) { indexes.Add(arrayIndex); } } } indexes.Sort(); var result = target.Engine.Array.New(); foreach (uint index in indexes) { result.Push(index.ToString()); } // Strings, in insertion order. foreach (var property in target.Properties) { if (property.Key is string key) { uint arrayIndex = ArrayInstance.ParseArrayIndex(key); if (arrayIndex == uint.MaxValue) { result.Push(property.Key); } } } // Symbols, in insertion order. foreach (var property in target.Properties) { if (property.Key is Symbol) { result.Push(property.Key); } } return(result); }
public static ArrayInstance GetOwnPropertyNames(ObjectInstance obj) { // Indexes should be in numeric order. var indexes = new List <uint>(); foreach (var key in obj.OwnKeys) { if (key is string keyStr) { uint arrayIndex = ArrayInstance.ParseArrayIndex(keyStr); if (arrayIndex != uint.MaxValue) { indexes.Add(arrayIndex); } } } indexes.Sort(); var result = obj.Engine.Array.New(); foreach (uint index in indexes) { result.Push(index.ToString()); } // Strings, in insertion order. foreach (var key in obj.OwnKeys) { if (key is string keyStr) { uint arrayIndex = ArrayInstance.ParseArrayIndex(keyStr); if (arrayIndex == uint.MaxValue) { result.Push(keyStr); } } } return(result); }