Skip to content

Commit

Permalink
Merge pull request #21 from KristofferStrube/feature/add-more-typed-a…
Browse files Browse the repository at this point in the history
…rrays

Feature/add more typed arrays
  • Loading branch information
KristofferStrube authored Oct 22, 2024
2 parents 609a314 + a9aca52 commit f6b4be8
Show file tree
Hide file tree
Showing 48 changed files with 3,363 additions and 5 deletions.
18 changes: 15 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,25 @@ jobs:
# Checkout the code
- uses: actions/checkout@v2

# Install .NET 7.0 SDK
- name: Setup .NET 7 preview
# Install .NET 9.0 SDK
- name: Setup .NET 9
uses: actions/setup-dotnet@v1
with:
dotnet-version: '7.0.x'
dotnet-version: '9.0.x'
include-prerelease: true

# Build
- name: Build
run: dotnet build

# Install PlayWright
- name: Install PlayWright
run: pwsh tests/IntegrationTests/bin/Debug/net8.0/playwright.ps1 install --with-deps

# Run tests
- name: Test
run: dotnet test

# Generate the website
- name: Publish
run: dotnet publish samples/KristofferStrube.Blazor.WebIDL.WasmExample/KristofferStrube.Blazor.WebIDL.WasmExample.csproj --configuration Release --output build
Expand Down
21 changes: 21 additions & 0 deletions Blazor.WebIDL.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KristofferStrube.Blazor.Web
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KristofferStrube.Blazor.WebIDL.ServerExample", "samples\KristofferStrube.Blazor.WebIDL.ServerExample\KristofferStrube.Blazor.WebIDL.ServerExample.csproj", "{764B6974-2E11-4ED5-8789-F17623613095}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{B961A374-912D-4CE5-B0D2-1E87F37338B7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorServer", "tests\BlazorServer\BlazorServer.csproj", "{EA8034DB-C93F-4D92-B4FC-44FF4C0F6E49}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IntegrationTests", "tests\IntegrationTests\IntegrationTests.csproj", "{E2AC3932-86B2-4C4B-AD8E-4EF72D53114F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -27,8 +33,23 @@ Global
{764B6974-2E11-4ED5-8789-F17623613095}.Debug|Any CPU.Build.0 = Debug|Any CPU
{764B6974-2E11-4ED5-8789-F17623613095}.Release|Any CPU.ActiveCfg = Release|Any CPU
{764B6974-2E11-4ED5-8789-F17623613095}.Release|Any CPU.Build.0 = Release|Any CPU
{EA8034DB-C93F-4D92-B4FC-44FF4C0F6E49}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EA8034DB-C93F-4D92-B4FC-44FF4C0F6E49}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EA8034DB-C93F-4D92-B4FC-44FF4C0F6E49}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EA8034DB-C93F-4D92-B4FC-44FF4C0F6E49}.Release|Any CPU.Build.0 = Release|Any CPU
{E2AC3932-86B2-4C4B-AD8E-4EF72D53114F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E2AC3932-86B2-4C4B-AD8E-4EF72D53114F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E2AC3932-86B2-4C4B-AD8E-4EF72D53114F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E2AC3932-86B2-4C4B-AD8E-4EF72D53114F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{EA8034DB-C93F-4D92-B4FC-44FF4C0F6E49} = {B961A374-912D-4CE5-B0D2-1E87F37338B7}
{E2AC3932-86B2-4C4B-AD8E-4EF72D53114F} = {B961A374-912D-4CE5-B0D2-1E87F37338B7}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2CA6E7EF-C3E3-4B76-B8F4-150853E45CF2}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using Microsoft.JSInterop;

namespace KristofferStrube.Blazor.WebIDL;

/// <summary>
/// A view on to a buffer type instance that exposes it as an array of IEEE 754 floating point numbers of 8 bytes.
/// </summary>
/// <remarks><see href="https://webidl.spec.whatwg.org/#idl-Float64Array">See the API definition here</see>.</remarks>
[IJSWrapperConverter]
public class Float64ArrayInProcess : Float64Array, ITypedArrayInProcess<double, Float64ArrayInProcess, Float64Array>
{
/// <summary>
/// A lazily loaded task that evaluates to a helper module instance from the Blazor.WebIDL library.
/// </summary>
public IJSInProcessObjectReference InProcessHelper { get; }

/// <inheritdoc/>
public new IJSInProcessObjectReference JSReference { get; }

/// <inheritdoc/>
public static async Task<Float64ArrayInProcess> CreateAsync(IJSRuntime jSRuntime, IJSInProcessObjectReference jSReference)
{
return await CreateAsync(jSRuntime, jSReference, new());
}

/// <inheritdoc/>
public static async Task<Float64ArrayInProcess> CreateAsync(IJSRuntime jSRuntime, IJSInProcessObjectReference jSReference, CreationOptions options)
{
IJSInProcessObjectReference inProcessHelper = await jSRuntime.GetInProcessHelperAsync();
return new(jSRuntime, inProcessHelper, jSReference, options);
}

/// <inheritdoc/>
public static new async Task<Float64ArrayInProcess> CreateAsync(IJSRuntime jSRuntime)
{
return await ITypedArrayInProcess<double, Float64ArrayInProcess, Float64Array>.CreateInternalAsync(jSRuntime);
}

/// <inheritdoc/>
public static new async Task<Float64ArrayInProcess> CreateAsync<TFromElement, TFromTypedArray>(IJSRuntime jSRuntime, TypedArray<TFromElement, TFromTypedArray> typedArray) where TFromTypedArray : IJSCreatable<TFromTypedArray>
{
return await ITypedArrayInProcess<double, Float64ArrayInProcess, Float64Array>.CreateInternalAsync(jSRuntime, typedArray);
}

/// <inheritdoc/>
public static new async Task<Float64ArrayInProcess> CreateAsync(IJSRuntime jSRuntime, IArrayBuffer buffer, long? byteOffset, long? length)
{
return await ITypedArrayInProcess<double, Float64ArrayInProcess, Float64Array>.CreateInternalAsync(jSRuntime, buffer, byteOffset, length);
}

/// <inheritdoc/>
public static new async Task<Float64ArrayInProcess> CreateAsync(IJSRuntime jSRuntime, long length)
{
return await ITypedArrayInProcess<double, Float64ArrayInProcess, Float64Array>.CreateInternalAsync(jSRuntime, length);
}

/// <inheritdoc cref="IJSInProcessCreatable{TInProcess, T}.CreateAsync(IJSRuntime, IJSInProcessObjectReference, CreationOptions)"/>
protected Float64ArrayInProcess(IJSRuntime jSRuntime, IJSInProcessObjectReference inProcessHelper, IJSInProcessObjectReference jSReference, CreationOptions options) : base(jSRuntime, jSReference, options)
{
this.InProcessHelper = inProcessHelper;
JSReference = jSReference;
}

/// <inheritdoc/>
public new async Task<IArrayBufferInProcess> GetBufferAsync()
{
return await ITypedArrayInProcess<double, Float64ArrayInProcess, Float64Array>.GetBufferAsync(this);
}

/// <inheritdoc/>
public double At(long index)
{
return ITypedArrayInProcess<double, Float64ArrayInProcess, Float64Array>.At(this, index);
}

/// <inheritdoc/>
public long Length => ITypedArrayInProcess<double, Float64ArrayInProcess, Float64Array>.GetLength(this);
}
26 changes: 26 additions & 0 deletions src/KristofferStrube.Blazor.WebIDL/TypedArrays/Float64Array.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Microsoft.JSInterop;

namespace KristofferStrube.Blazor.WebIDL;

/// <summary>
/// A view on to a buffer type instance that exposes it as an array of IEEE 754 floating point numbers of 8 bytes.
/// </summary>
/// <remarks><see href="https://webidl.spec.whatwg.org/#idl-Float64Array">See the API definition here</see>.</remarks>
[IJSWrapperConverter]
public class Float64Array : TypedArray<double, Float64Array>, IJSCreatable<Float64Array>
{
/// <inheritdoc/>
public static Task<Float64Array> CreateAsync(IJSRuntime jSRuntime, IJSObjectReference jSReference)
{
return Task.FromResult(new Float64Array(jSRuntime, jSReference, new()));
}

/// <inheritdoc/>
public static Task<Float64Array> CreateAsync(IJSRuntime jSRuntime, IJSObjectReference jSReference, CreationOptions options)
{
return Task.FromResult(new Float64Array(jSRuntime, jSReference, options));
}

/// <inheritdoc cref="CreateAsync(IJSRuntime, IJSObjectReference, CreationOptions)"/>
protected Float64Array(IJSRuntime jSRuntime, IJSObjectReference jSReference, CreationOptions options) : base(jSRuntime, jSReference, options) { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using Microsoft.JSInterop;

namespace KristofferStrube.Blazor.WebIDL;

/// <summary>
/// A view on to a buffer type instance that exposes it as an array of shorts.
/// </summary>
/// <remarks><see href="https://webidl.spec.whatwg.org/#idl-Int16Array">See the API definition here</see>.</remarks>
[IJSWrapperConverter]
public class Int16ArrayInProcess : Int16Array, ITypedArrayInProcess<short, Int16ArrayInProcess, Int16Array>
{
/// <summary>
/// A lazily loaded task that evaluates to a helper module instance from the Blazor.WebIDL library.
/// </summary>
public IJSInProcessObjectReference InProcessHelper { get; }

/// <inheritdoc/>
public new IJSInProcessObjectReference JSReference { get; }

/// <inheritdoc/>
public static async Task<Int16ArrayInProcess> CreateAsync(IJSRuntime jSRuntime, IJSInProcessObjectReference jSReference)
{
return await CreateAsync(jSRuntime, jSReference, new());
}

/// <inheritdoc/>
public static async Task<Int16ArrayInProcess> CreateAsync(IJSRuntime jSRuntime, IJSInProcessObjectReference jSReference, CreationOptions options)
{
IJSInProcessObjectReference inProcessHelper = await jSRuntime.GetInProcessHelperAsync();
return new(jSRuntime, inProcessHelper, jSReference, options);
}

/// <inheritdoc/>
public static new async Task<Int16ArrayInProcess> CreateAsync(IJSRuntime jSRuntime)
{
return await ITypedArrayInProcess<short, Int16ArrayInProcess, Int16Array>.CreateInternalAsync(jSRuntime);
}

/// <inheritdoc/>
public static new async Task<Int16ArrayInProcess> CreateAsync<TFromElement, TFromTypedArray>(IJSRuntime jSRuntime, TypedArray<TFromElement, TFromTypedArray> typedArray) where TFromTypedArray : IJSCreatable<TFromTypedArray>
{
return await ITypedArrayInProcess<short, Int16ArrayInProcess, Int16Array>.CreateInternalAsync(jSRuntime, typedArray);
}

/// <inheritdoc/>
public static new async Task<Int16ArrayInProcess> CreateAsync(IJSRuntime jSRuntime, IArrayBuffer buffer, long? byteOffset, long? length)
{
return await ITypedArrayInProcess<short, Int16ArrayInProcess, Int16Array>.CreateInternalAsync(jSRuntime, buffer, byteOffset, length);
}

/// <inheritdoc/>
public static new async Task<Int16ArrayInProcess> CreateAsync(IJSRuntime jSRuntime, long length)
{
return await ITypedArrayInProcess<short, Int16ArrayInProcess, Int16Array>.CreateInternalAsync(jSRuntime, length);
}

/// <inheritdoc cref="IJSInProcessCreatable{TInProcess, T}.CreateAsync(IJSRuntime, IJSInProcessObjectReference, CreationOptions)"/>
protected Int16ArrayInProcess(IJSRuntime jSRuntime, IJSInProcessObjectReference inProcessHelper, IJSInProcessObjectReference jSReference, CreationOptions options) : base(jSRuntime, jSReference, options)
{
this.InProcessHelper = inProcessHelper;
JSReference = jSReference;
}

/// <inheritdoc/>
public new async Task<IArrayBufferInProcess> GetBufferAsync()
{
return await ITypedArrayInProcess<short, Int16ArrayInProcess, Int16Array>.GetBufferAsync(this);
}

/// <inheritdoc/>
public short At(long index)
{
return ITypedArrayInProcess<short, Int16ArrayInProcess, Int16Array>.At(this, index);
}

/// <inheritdoc/>
public long Length => ITypedArrayInProcess<short, Int16ArrayInProcess, Int16Array>.GetLength(this);

/// <inheritdoc/>
public new async ValueTask DisposeAsync()
{
await InProcessHelper.DisposeAsync();
await IJSWrapper.DisposeJSReference(this);
await base.DisposeAsync();
GC.SuppressFinalize(this);
}
}
26 changes: 26 additions & 0 deletions src/KristofferStrube.Blazor.WebIDL/TypedArrays/Int16Array.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Microsoft.JSInterop;

namespace KristofferStrube.Blazor.WebIDL;

/// <summary>
/// A view on to a buffer type instance that exposes it as an array of shorts.
/// </summary>
/// <remarks><see href="https://webidl.spec.whatwg.org/#idl-Int16Array">See the API definition here</see>.</remarks>
[IJSWrapperConverter]
public class Int16Array : TypedArray<short, Int16Array>, IJSCreatable<Int16Array>
{
/// <inheritdoc/>
public static Task<Int16Array> CreateAsync(IJSRuntime jSRuntime, IJSObjectReference jSReference)
{
return Task.FromResult(new Int16Array(jSRuntime, jSReference, new()));
}

/// <inheritdoc/>
public static Task<Int16Array> CreateAsync(IJSRuntime jSRuntime, IJSObjectReference jSReference, CreationOptions options)
{
return Task.FromResult(new Int16Array(jSRuntime, jSReference, options));
}

/// <inheritdoc cref="CreateAsync(IJSRuntime, IJSObjectReference, CreationOptions)"/>
protected Int16Array(IJSRuntime jSRuntime, IJSObjectReference jSReference, CreationOptions options) : base(jSRuntime, jSReference, options) { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using Microsoft.JSInterop;

namespace KristofferStrube.Blazor.WebIDL;

/// <summary>
/// A view on to a buffer type instance that exposes it as an array of ints.
/// </summary>
/// <remarks><see href="https://webidl.spec.whatwg.org/#idl-Int32Array">See the API definition here</see>.</remarks>
[IJSWrapperConverter]
public class Int32ArrayInProcess : Int32Array, ITypedArrayInProcess<int, Int32ArrayInProcess, Int32Array>
{
/// <summary>
/// A lazily loaded task that evaluates to a helper module instance from the Blazor.WebIDL library.
/// </summary>
public IJSInProcessObjectReference InProcessHelper { get; }

/// <inheritdoc/>
public new IJSInProcessObjectReference JSReference { get; }

/// <inheritdoc/>
public static async Task<Int32ArrayInProcess> CreateAsync(IJSRuntime jSRuntime, IJSInProcessObjectReference jSReference)
{
return await CreateAsync(jSRuntime, jSReference, new());
}

/// <inheritdoc/>
public static async Task<Int32ArrayInProcess> CreateAsync(IJSRuntime jSRuntime, IJSInProcessObjectReference jSReference, CreationOptions options)
{
IJSInProcessObjectReference inProcessHelper = await jSRuntime.GetInProcessHelperAsync();
return new(jSRuntime, inProcessHelper, jSReference, options);
}

/// <inheritdoc/>
public static new async Task<Int32ArrayInProcess> CreateAsync(IJSRuntime jSRuntime)
{
return await ITypedArrayInProcess<int, Int32ArrayInProcess, Int32Array>.CreateInternalAsync(jSRuntime);
}

/// <inheritdoc/>
public static new async Task<Int32ArrayInProcess> CreateAsync<TFromElement, TFromTypedArray>(IJSRuntime jSRuntime, TypedArray<TFromElement, TFromTypedArray> typedArray) where TFromTypedArray : IJSCreatable<TFromTypedArray>
{
return await ITypedArrayInProcess<int, Int32ArrayInProcess, Int32Array>.CreateInternalAsync(jSRuntime, typedArray);
}

/// <inheritdoc/>
public static new async Task<Int32ArrayInProcess> CreateAsync(IJSRuntime jSRuntime, IArrayBuffer buffer, long? byteOffset, long? length)
{
return await ITypedArrayInProcess<int, Int32ArrayInProcess, Int32Array>.CreateInternalAsync(jSRuntime, buffer, byteOffset, length);
}

/// <inheritdoc/>
public static new async Task<Int32ArrayInProcess> CreateAsync(IJSRuntime jSRuntime, long length)
{
return await ITypedArrayInProcess<int, Int32ArrayInProcess, Int32Array>.CreateInternalAsync(jSRuntime, length);
}

/// <inheritdoc cref="IJSInProcessCreatable{TInProcess, T}.CreateAsync(IJSRuntime, IJSInProcessObjectReference, CreationOptions)"/>
protected Int32ArrayInProcess(IJSRuntime jSRuntime, IJSInProcessObjectReference inProcessHelper, IJSInProcessObjectReference jSReference, CreationOptions options) : base(jSRuntime, jSReference, options)
{
this.InProcessHelper = inProcessHelper;
JSReference = jSReference;
}

/// <inheritdoc/>
public new async Task<IArrayBufferInProcess> GetBufferAsync()
{
return await ITypedArrayInProcess<int, Int32ArrayInProcess, Int32Array>.GetBufferAsync(this);
}

/// <inheritdoc/>
public int At(long index)
{
return ITypedArrayInProcess<int, Int32ArrayInProcess, Int32Array>.At(this, index);
}

/// <inheritdoc/>
public long Length => ITypedArrayInProcess<int, Int32ArrayInProcess, Int32Array>.GetLength(this);

/// <inheritdoc/>
public new async ValueTask DisposeAsync()
{
await InProcessHelper.DisposeAsync();
await IJSWrapper.DisposeJSReference(this);
await base.DisposeAsync();
GC.SuppressFinalize(this);
}
}
Loading

0 comments on commit f6b4be8

Please sign in to comment.