Jurassic.Library.ObjectInstance.Delete C# (CSharp) Method

Delete() public method

Deletes the property with the given name.
public Delete ( object key, bool throwOnError ) : bool
key object The property key of the property to delete.
throwOnError bool true to throw an exception if the property could not /// be set because the property was marked as non-configurable.
return bool
        public bool Delete(object key, bool throwOnError)
        {
            // Check if the property is an indexed property.
            uint arrayIndex = ArrayInstance.ParseArrayIndex(key);
            if (arrayIndex != uint.MaxValue)
                return Delete(arrayIndex, throwOnError);

            // Retrieve the attributes for the property.
            var propertyInfo = this.schema.GetPropertyIndexAndAttributes(key);
            if (propertyInfo.Exists == false)
                return true;    // Property doesn't exist - delete succeeded!

            // Check if the property can be deleted.
            if (propertyInfo.IsConfigurable == false)
            {
                if (throwOnError == true)
                    throw new JavaScriptException(this.Engine, ErrorType.TypeError, string.Format("The property '{0}' cannot be deleted.", key));
                return false;
            }

            // Delete the property.
            this.schema = this.schema.DeleteProperty(key);
            return true;
        }

Same methods

ObjectInstance::Delete ( uint index, bool throwOnError ) : bool

Usage Example

Esempio n. 1
0
        /// <summary>
        /// Deletes the property with the given name.
        /// </summary>
        /// <param name="key"> The property key of the property to delete. </param>
        /// <param name="throwOnError"> <c>true</c> to throw an exception if the property could not
        /// be set because the property was marked as non-configurable.  </param>
        /// <returns> <c>true</c> if the property was successfully deleted, or if the property did
        /// not exist; <c>false</c> if the property was marked as non-configurable and
        /// <paramref name="throwOnError"/> was <c>false</c>. </returns>
        public override bool Delete(object key, bool throwOnError)
        {
            // Check for revocation.
            if (target == null || handler == null)
            {
                throw new JavaScriptException(ErrorType.TypeError, "Cannot call 'deleteProperty' on a proxy that has been revoked.");
            }

            // Call the handler, if one exists.
            var trap = handler.GetMethod("deleteProperty");

            if (trap == null)
            {
                return(target.Delete(key, throwOnError));
            }
            var result = TypeConverter.ToBoolean(trap.CallLateBound(handler, target, key));

            if (!result)
            {
                return(false);
            }

            // Validate.
            var targetDescriptor = target.GetOwnPropertyDescriptor(key);

            if (targetDescriptor.Exists)
            {
                if (!targetDescriptor.IsConfigurable)
                {
                    throw new JavaScriptException(ErrorType.TypeError, $"'deleteProperty' on proxy: trap returned truish for property '{TypeConverter.ToString(key)}' which is non-configurable in the proxy target.");
                }
                if (!target.IsExtensible)
                {
                    throw new JavaScriptException(ErrorType.TypeError, $"'deleteProperty' on proxy: trap returned truish for property '{TypeConverter.ToString(key)}' but the proxy target is non-extensible.");
                }
            }
            return(true);
        }
All Usage Examples Of Jurassic.Library.ObjectInstance::Delete