/// <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);
}