Skip to content

Commit d6cc677

Browse files
Version 7.2.4: Added V8ScriptEngineFlags.UseCaseInsensitiveMemberBinding (GitHub Issue ClearFoundry#363); restored compatibility with older Linux systems going back to glibc-2.23 (GitHub Issue ClearFoundry#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.
1 parent 3e13f32 commit d6cc677

672 files changed

Lines changed: 2241 additions & 981 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

ClearScript.NoV8.sln.DotSettings

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
<s:Boolean x:Key="/Default/UserDictionary/Words/=E_00F3in/@EntryIndexedValue">True</s:Boolean>
7474
<s:Boolean x:Key="/Default/UserDictionary/Words/=FILEEXISTS/@EntryIndexedValue">True</s:Boolean>
7575
<s:Boolean x:Key="/Default/UserDictionary/Words/=fine/@EntryIndexedValue">True</s:Boolean>
76+
<s:Boolean x:Key="/Default/UserDictionary/Words/=foobarbaz/@EntryIndexedValue">True</s:Boolean>
7677
<s:Boolean x:Key="/Default/UserDictionary/Words/=FUNCDESC/@EntryIndexedValue">True</s:Boolean>
7778
<s:Boolean x:Key="/Default/UserDictionary/Words/=FUNCFLAGS/@EntryIndexedValue">True</s:Boolean>
7879
<s:Boolean x:Key="/Default/UserDictionary/Words/=guids/@EntryIndexedValue">True</s:Boolean>
@@ -92,6 +93,7 @@
9293
<s:Boolean x:Key="/Default/UserDictionary/Words/=MEMBERNOTFOUND/@EntryIndexedValue">True</s:Boolean>
9394
<s:Boolean x:Key="/Default/UserDictionary/Words/=memid/@EntryIndexedValue">True</s:Boolean>
9495
<s:Boolean x:Key="/Default/UserDictionary/Words/=MSXML/@EntryIndexedValue">True</s:Boolean>
96+
<s:Boolean x:Key="/Default/UserDictionary/Words/=NETFRAMEWORK/@EntryIndexedValue">True</s:Boolean>
9597
<s:Boolean x:Key="/Default/UserDictionary/Words/=NOINTERFACE/@EntryIndexedValue">True</s:Boolean>
9698
<s:Boolean x:Key="/Default/UserDictionary/Words/=Numerics/@EntryIndexedValue">True</s:Boolean>
9799
<s:Boolean x:Key="/Default/UserDictionary/Words/=oleaut/@EntryIndexedValue">True</s:Boolean>

ClearScript.sln.DotSettings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
<s:Boolean x:Key="/Default/UserDictionary/Words/=MEMBERNOTFOUND/@EntryIndexedValue">True</s:Boolean>
9494
<s:Boolean x:Key="/Default/UserDictionary/Words/=memid/@EntryIndexedValue">True</s:Boolean>
9595
<s:Boolean x:Key="/Default/UserDictionary/Words/=MSXML/@EntryIndexedValue">True</s:Boolean>
96+
<s:Boolean x:Key="/Default/UserDictionary/Words/=NETFRAMEWORK/@EntryIndexedValue">True</s:Boolean>
9697
<s:Boolean x:Key="/Default/UserDictionary/Words/=NOINTERFACE/@EntryIndexedValue">True</s:Boolean>
9798
<s:Boolean x:Key="/Default/UserDictionary/Words/=Numerics/@EntryIndexedValue">True</s:Boolean>
9899
<s:Boolean x:Key="/Default/UserDictionary/Words/=oleaut/@EntryIndexedValue">True</s:Boolean>

ClearScript/CanonicalRefTable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ private static ICanonicalRefMap GetMap(object obj)
3838
type == typeof(DateTime) ||
3939
type == typeof(DateTimeOffset) ||
4040
type == typeof(TimeSpan) ||
41-
type.GetCustomAttributes(typeof(ImmutableValueAttribute), false).Any())
41+
type.GetOrLoadCustomAttributes<ImmutableValueAttribute>(false).Any())
4242
{
4343
map = (ICanonicalRefMap)typeof(CanonicalRefMap<>).MakeGenericType(type).CreateInstance();
4444
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
using System;
5+
using System.Linq;
6+
using System.Reflection;
7+
8+
namespace Microsoft.ClearScript
9+
{
10+
/// <summary>
11+
/// Represents a custom attribute loader.
12+
/// </summary>
13+
public class CustomAttributeLoader
14+
{
15+
// ReSharper disable EmptyConstructor
16+
17+
/// <summary>
18+
/// Initializes a new <see cref="CustomAttributeLoader"/> instance.
19+
/// </summary>
20+
public CustomAttributeLoader()
21+
{
22+
// the help file builder (SHFB) insists on an empty constructor here
23+
}
24+
25+
// ReSharper restore EmptyConstructor
26+
27+
28+
/// <summary>
29+
/// Loads custom attributes of the specified type for the given resource.
30+
/// </summary>
31+
/// <typeparam name="T">The type, or a base type, of the custom attributes to load.</typeparam>
32+
/// <param name="resource">The resource for which to load custom attributes of type <typeparamref name="T"/>.</param>
33+
/// <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>
34+
/// <returns>An array of custom attributes of type <typeparamref name="T"/>.</returns>.
35+
/// <remarks>
36+
/// This method is performance-critical. Overrides must not invoke script engine methods or
37+
/// other ClearScript functionality. The base implementation loads custom attributes via
38+
/// reflection.
39+
/// </remarks>
40+
public virtual T[] LoadCustomAttributes<T>(ICustomAttributeProvider resource, bool inherit) where T : Attribute
41+
{
42+
if (resource is MemberInfo member)
43+
{
44+
return Attribute.GetCustomAttributes(member, typeof(T), inherit).OfType<T>().ToArray();
45+
}
46+
47+
if (resource is ParameterInfo parameter)
48+
{
49+
return Attribute.GetCustomAttributes(parameter, typeof(T), inherit).OfType<T>().ToArray();
50+
}
51+
52+
if (resource is Assembly assembly)
53+
{
54+
return Attribute.GetCustomAttributes(assembly, typeof(T), inherit).OfType<T>().ToArray();
55+
}
56+
57+
if (resource is Module module)
58+
{
59+
return Attribute.GetCustomAttributes(module, typeof(T), inherit).OfType<T>().ToArray();
60+
}
61+
62+
return resource.GetCustomAttributes(typeof(T), inherit).OfType<T>().ToArray();
63+
}
64+
}
65+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
using Microsoft.ClearScript.Util;
5+
6+
namespace Microsoft.ClearScript
7+
{
8+
internal static partial class CustomAttributes
9+
{
10+
public static void ClearCache()
11+
{
12+
keyCache.Values.ForEach(key => attributeCache.Remove(key));
13+
}
14+
}
15+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
namespace Microsoft.ClearScript
5+
{
6+
internal static partial class CustomAttributes
7+
{
8+
public static void ClearCache()
9+
{
10+
attributeCache.Clear();
11+
}
12+
}
13+
}

ClearScript/CustomAttributes.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
using System;
5+
using System.Collections.Concurrent;
6+
using System.Reflection;
7+
using System.Runtime.CompilerServices;
8+
using Microsoft.ClearScript.Util;
9+
10+
namespace Microsoft.ClearScript
11+
{
12+
internal static partial class CustomAttributes
13+
{
14+
private static readonly ConcurrentDictionary<(ICustomAttributeProvider, Type), object> keyCache = new ConcurrentDictionary<(ICustomAttributeProvider, Type), object>();
15+
private static readonly ConditionalWeakTable<object, object> attributeCache = new ConditionalWeakTable<object, object>();
16+
17+
public static T[] GetOrLoad<T>(ICustomAttributeProvider resource, bool inherit) where T : Attribute
18+
{
19+
return (T[])attributeCache.GetValue(GetKey<T>(resource), _ => HostSettings.CustomAttributeLoader.LoadCustomAttributes<T>(resource, inherit) ?? ArrayHelpers.GetEmptyArray<T>());
20+
}
21+
22+
public static bool Has<T>(ICustomAttributeProvider resource, bool inherit) where T : Attribute
23+
{
24+
return GetOrLoad<T>(resource, inherit).Length > 0;
25+
}
26+
27+
private static object GetKey<T>(ICustomAttributeProvider resource) where T : Attribute
28+
{
29+
return keyCache.GetOrAdd((resource, typeof(T)), _ => new object());
30+
}
31+
}
32+
}

ClearScript/Exports/VersionSymbols.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
#pragma once
77

8-
#define CLEARSCRIPT_VERSION_STRING "7.2.3"
9-
#define CLEARSCRIPT_VERSION_COMMA_SEPARATED 7,2,3
10-
#define CLEARSCRIPT_VERSION_STRING_INFORMATIONAL "7.2.3"
8+
#define CLEARSCRIPT_VERSION_STRING "7.2.4"
9+
#define CLEARSCRIPT_VERSION_COMMA_SEPARATED 7,2,4
10+
#define CLEARSCRIPT_VERSION_STRING_INFORMATIONAL "7.2.4"
1111
#define CLEARSCRIPT_FILE_FLAGS 0L

ClearScript/ExtensionMethods.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public void RebuildSummary()
3838

3939
private static bool IsScriptableExtensionMethod(MethodInfo method, Type accessContext, ScriptAccess defaultAccess)
4040
{
41-
return method.IsScriptable(accessContext, defaultAccess) && method.IsDefined(typeof(ExtensionAttribute), false);
41+
return method.IsScriptable(accessContext, defaultAccess) && method.HasCustomAttributes<ExtensionAttribute>(false);
4242
}
4343
}
4444

ClearScript/HostFunctions.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using System.Globalization;
88
using System.Linq;
99
using System.Linq.Expressions;
10-
using System.Reflection;
1110
using System.Runtime.InteropServices;
1211
using Microsoft.ClearScript.Util;
1312
using Microsoft.ClearScript.Util.COM;
@@ -1665,7 +1664,7 @@ public HostTypeCollection typeLibEnums<T>(T obj, HostTypeCollection collection =
16651664
}
16661665
}
16671666
}
1668-
else if (type.IsImport && (type.Assembly.GetCustomAttribute(typeof(ImportedFromTypeLibAttribute)) != null))
1667+
else if (type.IsImport && (type.Assembly.GetOrLoadCustomAttribute<ImportedFromTypeLibAttribute>(false) != null))
16691668
{
16701669
type.Assembly.GetReferencedEnums().ForEach(collection.AddType);
16711670
return collection;

0 commit comments

Comments
 (0)