-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Version 7.2.4: Added V8ScriptEngineFlags.UseCaseInsensitiveMemberBind…
…ing (GitHub Issue #363); restored compatibility with older Linux systems going back to glibc-2.23 (GitHub Issue #362); overhauled attribute access and added custom attribute loaders; added case-insensitivity support to PropertyBag and DynamicHostObject; added .NET 6 targets to test projects; updated API documentation. Tested with V8 10.0.139.8.
- Loading branch information
1 parent
3e13f32
commit d6cc677
Showing
672 changed files
with
2,241 additions
and
981 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
using System; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
namespace Microsoft.ClearScript | ||
{ | ||
/// <summary> | ||
/// Represents a custom attribute loader. | ||
/// </summary> | ||
public class CustomAttributeLoader | ||
{ | ||
// ReSharper disable EmptyConstructor | ||
|
||
/// <summary> | ||
/// Initializes a new <see cref="CustomAttributeLoader"/> instance. | ||
/// </summary> | ||
public CustomAttributeLoader() | ||
{ | ||
// the help file builder (SHFB) insists on an empty constructor here | ||
} | ||
|
||
// ReSharper restore EmptyConstructor | ||
|
||
|
||
/// <summary> | ||
/// Loads custom attributes of the specified type for the given resource. | ||
/// </summary> | ||
/// <typeparam name="T">The type, or a base type, of the custom attributes to load.</typeparam> | ||
/// <param name="resource">The resource for which to load custom attributes of type <typeparamref name="T"/>.</param> | ||
/// <param name="inherit"><c>True</c> to include custom attributes of type <typeparamref name="T"/> defined for ancestors of <paramref name="resource"/>, <c>false</c> otherwise.</param> | ||
/// <returns>An array of custom attributes of type <typeparamref name="T"/>.</returns>. | ||
/// <remarks> | ||
/// This method is performance-critical. Overrides must not invoke script engine methods or | ||
/// other ClearScript functionality. The base implementation loads custom attributes via | ||
/// reflection. | ||
/// </remarks> | ||
public virtual T[] LoadCustomAttributes<T>(ICustomAttributeProvider resource, bool inherit) where T : Attribute | ||
{ | ||
if (resource is MemberInfo member) | ||
{ | ||
return Attribute.GetCustomAttributes(member, typeof(T), inherit).OfType<T>().ToArray(); | ||
} | ||
|
||
if (resource is ParameterInfo parameter) | ||
{ | ||
return Attribute.GetCustomAttributes(parameter, typeof(T), inherit).OfType<T>().ToArray(); | ||
} | ||
|
||
if (resource is Assembly assembly) | ||
{ | ||
return Attribute.GetCustomAttributes(assembly, typeof(T), inherit).OfType<T>().ToArray(); | ||
} | ||
|
||
if (resource is Module module) | ||
{ | ||
return Attribute.GetCustomAttributes(module, typeof(T), inherit).OfType<T>().ToArray(); | ||
} | ||
|
||
return resource.GetCustomAttributes(typeof(T), inherit).OfType<T>().ToArray(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
using Microsoft.ClearScript.Util; | ||
|
||
namespace Microsoft.ClearScript | ||
{ | ||
internal static partial class CustomAttributes | ||
{ | ||
public static void ClearCache() | ||
{ | ||
keyCache.Values.ForEach(key => attributeCache.Remove(key)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
namespace Microsoft.ClearScript | ||
{ | ||
internal static partial class CustomAttributes | ||
{ | ||
public static void ClearCache() | ||
{ | ||
attributeCache.Clear(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using Microsoft.ClearScript.Util; | ||
|
||
namespace Microsoft.ClearScript | ||
{ | ||
internal static partial class CustomAttributes | ||
{ | ||
private static readonly ConcurrentDictionary<(ICustomAttributeProvider, Type), object> keyCache = new ConcurrentDictionary<(ICustomAttributeProvider, Type), object>(); | ||
private static readonly ConditionalWeakTable<object, object> attributeCache = new ConditionalWeakTable<object, object>(); | ||
|
||
public static T[] GetOrLoad<T>(ICustomAttributeProvider resource, bool inherit) where T : Attribute | ||
{ | ||
return (T[])attributeCache.GetValue(GetKey<T>(resource), _ => HostSettings.CustomAttributeLoader.LoadCustomAttributes<T>(resource, inherit) ?? ArrayHelpers.GetEmptyArray<T>()); | ||
} | ||
|
||
public static bool Has<T>(ICustomAttributeProvider resource, bool inherit) where T : Attribute | ||
{ | ||
return GetOrLoad<T>(resource, inherit).Length > 0; | ||
} | ||
|
||
private static object GetKey<T>(ICustomAttributeProvider resource) where T : Attribute | ||
{ | ||
return keyCache.GetOrAdd((resource, typeof(T)), _ => new object()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.