Skip to content

Commit

Permalink
iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
elringus committed Sep 14, 2023
1 parent 1a73034 commit 07484bd
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
4 changes: 2 additions & 2 deletions DotNet/Bootsharp.Builder.Test/Prepare/ExportTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ public record Info(string Foo);
public class Foo
{
[JSInvokable] public static void Void () {}
[JSInvokable] public static global::Space.Info? WithArgs (string a, global::System.Int32[] b) => default;
[JSInvokable] public static global::System.Threading.Tasks.Task Async () => default;
[JSInvokable] public static Info? WithArgs (string a, int[] b) => default;
[JSInvokable] public static Task Async () => default;
[JSInvokable] public static Task<Info?> AsyncWithArgs (Info? i) => default;
}
""", false));
Expand Down
48 changes: 46 additions & 2 deletions DotNet/Bootsharp.Builder.Test/Prepare/ImportTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public class Foo
using System.Runtime.InteropServices.JavaScript;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using static Bootsharp.Serializer;

namespace Bootsharp;

Expand Down Expand Up @@ -89,7 +88,6 @@ public class Baz
using System.Runtime.InteropServices.JavaScript;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using static Bootsharp.Serializer;

namespace Bootsharp;

Expand Down Expand Up @@ -134,4 +132,50 @@ internal static void RegisterDynamicDependencies ()
}
""");
}

[Fact]
public void ImportsFunctionsAndEvents ()
{
AddAssembly("asm", With(
"""
namespace Space;

public record Info(string Foo);

public class Foo
{
[JSFunction] public static partial Info? Bar (string a, int[] b);
[JSFunction] public static partial Task Baz ();
[JSFunction] public static partial Task<Info?> Nya (Info a);
[JSEvent] public static partial void OnBar (Info? a, bool b);
}
""", false));
Execute();
Contains(
"""
using System.Runtime.InteropServices.JavaScript;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;

namespace Bootsharp;

public partial class InteropImports_Space_Foo
{
[ModuleInitializer]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, "Bootsharp.InteropImports_Space_Foo", "asm")]
internal static void RegisterDynamicDependencies ()
{
Function.Set("Space.bar", Bar);
Function.Set("Space.baz", Baz);
Function.Set("Space.nya", Nya);
Function.Set("Space.onBar.broadcast", OnBar);
}

[JSImport("Space.bar", "Bootsharp")] internal static partial void Bar ();
[JSImport("Space.baz", "Bootsharp")] internal static partial void Baz ();
[JSImport("Space.nya", "Bootsharp")] internal static partial void Nya ();
[JSImport("Space.onBar.broadcast", "Bootsharp")] internal static partial void OnBar ();
}
""");
}
}
2 changes: 1 addition & 1 deletion DotNet/Bootsharp.Builder/Utilities/TypeUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public static bool ShouldSerialize (Type type) =>
!Is<long>(type) && !Is<int>(type) && !Is<float>(type) && !Is<double>(type) &&
!Is<nint>(type) && !Is<DateTime>(type) && !Is<DateTimeOffset>(type) && !Is<string>(type) &&
!Is<byte[]>(type) && !Is<int[]>(type) && !Is<double[]>(type) && !Is<string[]>(type) &&
!IsVoid(type) && !Is<Task>(type) && !(IsTaskWithResult(type) && !ShouldSerialize(GetTaskResult(type)));
!IsVoid(type) && !Is<Task>(type) && (!IsTaskWithResult(type) || ShouldSerialize(GetTaskResult(type)));

// can't compare types directly as they're inspected in other modules
private static bool Is<T> (Type type) => type.FullName == typeof(T).FullName;
Expand Down

0 comments on commit 07484bd

Please sign in to comment.