Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
a790cbb
Bump commonmarker from 0.23.9 to 0.23.10 in /docs (#529)
dependabot[bot] Aug 8, 2023
959ec3c
Version 7.4.3: Improved handling of anonymous host types; [V8] [JScri…
ClearScriptLib Aug 19, 2023
ebd71aa
Update ReadMe.md
ClearScriptLib Aug 20, 2023
cb50bb0
Bump activesupport from 7.0.6 to 7.0.7.2 in /docs (#532)
dependabot[bot] Aug 23, 2023
6df5f19
Version 7.4.4: Added ConcurrentPropertyBag (GitHub Issue #531); [V8] …
ClearScriptLib Oct 17, 2023
db18344
Make a `MemberComparer` class more reliable (#557)
Taritsyn Jan 11, 2024
78916b6
Bump nokogiri from 1.15.4 to 1.16.2 in /docs (#561)
dependabot[bot] Feb 6, 2024
28663e5
Version 7.4.5: [V8] Added AddPerformanceObject and SetTimerResolution…
ClearScriptLib Mar 25, 2024
55d9590
Bump nokogiri from 1.15.6 to 1.16.5 in /docs (#575)
dependabot[bot] May 13, 2024
349bed3
Bump rexml from 3.2.6 to 3.2.8 in /docs (#577)
dependabot[bot] May 17, 2024
1ba2687
Bump rexml from 3.2.8 to 3.3.3 in /docs (#588)
dependabot[bot] Aug 2, 2024
619115c
Bump rexml from 3.3.3 to 3.3.6 in /docs (#595)
dependabot[bot] Aug 22, 2024
4dae04f
Bump rexml from 3.3.6 to 3.3.9 in /docs (#608)
dependabot[bot] Oct 28, 2024
bb14185
Store assembly table as XML to eliminate BinaryFormatter security iss…
ClearScriptLib Dec 3, 2024
b594ec1
Don't depend on vulnerable packages (#614)
AnsisMalins Dec 3, 2024
1d2800b
Change MethodBindResult to a readonly ref struct (#616)
AnsisMalins Dec 13, 2024
49a4728
Merge branch 'master' of github.com:microsoft/ClearScript into micros…
AnsisMalins Jan 21, 2025
e6002ba
Fix compiler errors and remove TypesCache
AnsisMalins Jan 21, 2025
aa2e2e6
Remove MonoPInvokeCallbackAttribute
AnsisMalins Jan 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 0 additions & 1 deletion ClearScript.NoV8.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Numerics/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=oleaut/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Parameterless/@EntryIndexedValue">True</s:Boolean>

<s:Boolean x:Key="/Default/UserDictionary/Words/=Plex/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=prog/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Ptrs/@EntryIndexedValue">True</s:Boolean>
Expand Down
655 changes: 334 additions & 321 deletions ClearScript.sln

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion ClearScript.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Numerics/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=oleaut/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Parameterless/@EntryIndexedValue">True</s:Boolean>

<s:Boolean x:Key="/Default/UserDictionary/Words/=Plex/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=prog/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Ptrs/@EntryIndexedValue">True</s:Boolean>
Expand Down
14 changes: 7 additions & 7 deletions ClearScript/ByRefArg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,34 +46,34 @@ public T Value

public override object DynamicInvokeTarget => target.DynamicInvokeTarget;

public override HostTargetFlags GetFlags(IHostInvokeContext context)
public override HostTargetFlags GetFlags(IHostContext context)
{
return target.GetFlags(context);
}

public override string[] GetAuxMethodNames(IHostInvokeContext context, BindingFlags bindFlags)
public override string[] GetAuxMethodNames(IHostContext context, BindingFlags bindFlags)
{
return target.GetAuxMethodNames(context, bindFlags);
}

public override string[] GetAuxPropertyNames(IHostInvokeContext context, BindingFlags bindFlags)
public override string[] GetAuxPropertyNames(IHostContext context, BindingFlags bindFlags)
{
return target.GetAuxPropertyNames(context, bindFlags);
}

public override bool TryInvokeAuxMember(IHostInvokeContext context, string name, BindingFlags invokeFlags, object[] args, object[] bindArgs, out object result)
public override bool TryInvokeAuxMember(IHostContext context, string name, BindingFlags invokeFlags, object[] args, object[] bindArgs, out object result)
{
return target.TryInvokeAuxMember(context, name, invokeFlags, args, bindArgs, out result);
}

public override bool TryInvoke(IHostInvokeContext context, BindingFlags invokeFlags, object[] args, object[] bindArgs, out object result)
public override bool TryInvoke(IHostContext context, BindingFlags invokeFlags, object[] args, object[] bindArgs, out object result)
{
return target.TryInvoke(context, invokeFlags, args, bindArgs, out result);
}

public override Invocability GetInvocability(BindingFlags bindFlags, Type accessContext, ScriptAccess defaultAccess, bool ignoreDynamic)
public override Invocability GetInvocability(IHostContext context, BindingFlags bindFlags, bool ignoreDynamic)
{
return target.GetInvocability(bindFlags, accessContext, defaultAccess, ignoreDynamic);
return target.GetInvocability(context, bindFlags, ignoreDynamic);
}

#endregion
Expand Down
4 changes: 2 additions & 2 deletions ClearScript/CanonicalRefTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ private static ICanonicalRefMap GetMap(object obj)
type == typeof(TimeSpan) ||
type == typeof(Guid) ||
#if NET471_OR_GREATER || NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER
type.GetOrLoadCustomAttributes<System.Runtime.CompilerServices.IsReadOnlyAttribute>(false).Any() ||
type.GetOrLoadCustomAttributes<System.Runtime.CompilerServices.IsReadOnlyAttribute>(null, false).Any() ||
#endif
type.GetOrLoadCustomAttributes<ImmutableValueAttribute>(false).Any())
type.GetOrLoadCustomAttributes<ImmutableValueAttribute>(null, false).Any())
{
map = (ICanonicalRefMap)typeof(CanonicalRefMap<>).MakeGenericType(type).CreateInstance();
}
Expand Down
136 changes: 136 additions & 0 deletions ClearScript/CustomAttributeCache.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.CompilerServices;
using Microsoft.ClearScript.Util;

namespace Microsoft.ClearScript
{
internal sealed class CustomAttributeCache
{
private readonly ConditionalWeakTable<ICustomAttributeProvider, Entry> table = new ConditionalWeakTable<ICustomAttributeProvider, Entry>();

public T[] GetOrLoad<T>(CustomAttributeLoader loader, ICustomAttributeProvider resource, bool inherit) where T : Attribute
{
lock (table)
{
return GetOrLoad<T>(loader, table.GetOrCreateValue(resource), resource, inherit);
}
}

private T[] GetOrLoad<T>(CustomAttributeLoader loader, Entry entry, ICustomAttributeProvider resource, bool inherit) where T : Attribute
{
if (entry.TryGet<T>(out var attrs))
{
return attrs;
}

attrs = Load<T>(GetIsBypass(entry, resource) ? CustomAttributeLoader.Default : loader, resource, inherit);
entry.Add(attrs);

return attrs;
}

private static T[] Load<T>(CustomAttributeLoader loader, ICustomAttributeProvider resource, bool inherit) where T : Attribute
{
return loader.LoadCustomAttributes<T>(resource, inherit) ?? ArrayHelpers.GetEmptyArray<T>();
}

private bool GetIsBypass(ICustomAttributeProvider resource)
{
// ReSharper disable once InconsistentlySynchronizedField
return GetIsBypass(table.GetOrCreateValue(resource), resource);
}

private bool GetIsBypass(Entry entry, ICustomAttributeProvider resource)
{
if (!entry.IsBypass.HasValue)
{
entry.IsBypass = GetIsBypassInternal(resource);
}

return entry.IsBypass.Value;
}

private bool GetIsBypassInternal(ICustomAttributeProvider resource)
{
if (Load<BypassCustomAttributeLoaderAttribute>(CustomAttributeLoader.Default, resource, false).Length > 0)
{
return true;
}

var parent = GetParent(resource);
if (parent != null)
{
return GetIsBypass(parent);
}

return false;
}

private static ICustomAttributeProvider GetParent(ICustomAttributeProvider resource)
{
if (resource is ParameterInfo parameter)
{
return parameter.Member;
}

if (resource is Type type)
{
return (type.DeclaringType as ICustomAttributeProvider) ?? type.Module;
}

if (resource is MemberInfo member)
{
return member.DeclaringType;
}

if (resource is Module module)
{
return module.Assembly;
}

return null;
}

#region Nested type: Entry

// ReSharper disable ClassNeverInstantiated.Local

private sealed class Entry
{
private readonly Dictionary<Type, object> map = new Dictionary<Type, object>();

public bool? IsBypass { get; set; }

public void Add<T>(T[] attrs)
{
map.Add(typeof(T), attrs);
}

public bool TryGet<T>(out T[] attrs)
{
if (map.TryGetValue(typeof(T), out var attrsObject))
{
attrs = attrsObject as T[];
return true;
}

attrs = null;
return false;
}
}

// ReSharper restore ClassNeverInstantiated.Local

#endregion
}

[AttributeUsage(AttributeTargets.All, Inherited = false)]
internal sealed class BypassCustomAttributeLoaderAttribute : Attribute
{
}
}
12 changes: 12 additions & 0 deletions ClearScript/CustomAttributeLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ namespace Microsoft.ClearScript
/// </summary>
public class CustomAttributeLoader
{
private readonly CustomAttributeCache cache = new CustomAttributeCache();

// ReSharper disable EmptyConstructor

/// <summary>
Expand All @@ -22,6 +24,11 @@ public CustomAttributeLoader()
// the help file builder (SHFB) insists on an empty constructor here
}

/// <summary>
/// Gets the default custom attribute loader.
/// </summary>
public static CustomAttributeLoader Default { get; } = new CustomAttributeLoader();

// ReSharper restore EmptyConstructor

/// <summary>
Expand Down Expand Up @@ -60,5 +67,10 @@ public virtual T[] LoadCustomAttributes<T>(ICustomAttributeProvider resource, bo

return resource.GetCustomAttributes(typeof(T), inherit).OfType<T>().ToArray();
}

internal T[] GetOrLoad<T>(ICustomAttributeProvider resource, bool inherit) where T : Attribute
{
return cache.GetOrLoad<T>(this, resource, inherit);
}
}
}
21 changes: 0 additions & 21 deletions ClearScript/CustomAttributes.NetFramework.cs

This file was deleted.

21 changes: 0 additions & 21 deletions ClearScript/CustomAttributes.NetStandard.cs

This file was deleted.

Loading