Skip to content

Commit

Permalink
[browser][wasm] Implement JavaScript managed object reference counting (
Browse files Browse the repository at this point in the history
#37417)

* Add Browser specific files to the project

* Browser specific file modification to not include Quic support

* Add Browser specific support files for Http Handler code

* Add Interop code for JavaScript support

* Remove unused reference

* Add Http handler bindings implementation

- This still needs to have the code implement nullable

* Nullable support

* Add browser files back after upstream merge conflict

* Use attribute Link syntax for Common files to bring in sync with existing format

* Address Missing license header

* Code formatting and removal of comment code.

* Address PR comments.

* Address commit comments

* Add blank line between License and first line of code.  Address comments

* Replace SocketsHttpHandler build for Browser.

- Throws `PlatformNotSupportedException` for properties and methods of the HttpMessageHandler abstract implementation.

* Cleanup SendAsync code when doing the call out to JavaScript Fetch.

- Addresses commit comments.

* Refactor BrowserHttpHandler code.

* Cleanup

* Remove null check as it should be checked in outer classes

* Cleanup var usage to use explicit type.  Address commit comments

- For all of these vars, please replace them with the actual type, except when the type is obvious from a new or explicit cast on the right-hand side.

* Move `.ConfigureAwait(true)` to `.ConfigureAwait(false)`

- Address review comments

* Change accessor of Runtime javascript interop methods.

* Change accessor of Runtime javascript interop methods.

* Address review comments for unused code

* Cleanup leftover debug WriteLines

* Remove the AllowNull attributes as per review comments.

* Update src/libraries/Common/src/Interop/Browser/Interop.Runtime.cs

Co-Authored-By: Marek Safar <[email protected]>

* throw different exception type as per review comment

* use char[] array instead and return new string(array).

- Address review comments

* Initial addition of Browser Interop library

* use char[] array instead and return new string(array).

- Address review comments

* Add project references so the Interop.JavaScript project builds

* Coding Style update

* Split the runtime methods into two modules.

- .Api contains the methods that are only used internally from JavaScript bindings code.

* Move System.Runtime.Interop.JavaScript to \src\libraries

- Address review comments

* Change preprocessor to upper case TARGETS_BROWSER

- Address review comments

* Update src/libraries/Common/src/Interop/Browser/Interop.Runtime.Api.cs

Co-authored-by: Marek Safar <[email protected]>

* Update src/libraries/Common/src/Interop/Browser/Interop.Runtime.Api.cs

Co-authored-by: Marek Safar <[email protected]>

* Update src/libraries/Common/src/Interop/Browser/Interop.Runtime.Api.cs

Co-authored-by: Marek Safar <[email protected]>

* Rename from .Api to .Bridge to address review comments

* Modify .csproj files to reflect .Bridge.cs change.

* Remove unnecessary constant

* Add docs

* Update Bridge link

* Collapse code as per review comment.

* Address review comments on `Task.ConfigureAwait(continueOnCapturedContext: true)`.

- Added comment in source code.

* Address review comment about using PropertyInfo reflection.

- GetMethod("get_Result") is less expensive to use.

* Coding Style - Address review comments

* Part of code style and object documentation to partially address review comments.

* Update src/libraries/Common/src/Interop/Browser/Interop.JavaScript.JSObject.cs

Co-authored-by: Stephen Toub <[email protected]>

* Update src/libraries/Common/src/Interop/Browser/Interop.Runtime.Bridge.cs

Co-authored-by: Stephen Toub <[email protected]>

* Update src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs

Co-authored-by: Stephen Toub <[email protected]>

* Update src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs

Co-authored-by: Stephen Toub <[email protected]>

* Update src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs

Co-authored-by: Stephen Toub <[email protected]>

* Update src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs

Co-authored-by: Stephen Toub <[email protected]>

* Update src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs

Co-authored-by: Stephen Toub <[email protected]>

* Add class docs and code style updates

- Address review comments

* Update src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs

Co-authored-by: Stephen Toub <[email protected]>

* Fix badly formed XML

* Update src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs

Co-authored-by: Stephen Toub <[email protected]>

* Remove unnecessary Property implementations.

* Update src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs

Co-authored-by: Stephen Toub <[email protected]>

* Update code style involving the use of `var`

* Modify the underlying sockets field name.

- address review comments.

* Style and address review comments

* Remove reliance on ConnectHelper.cs code as it is not supported on Browser

- This removes the reliance on the QUIC support.

* Update src/libraries/Common/src/Interop/Browser/Interop.Runtime.Bridge.cs

Co-authored-by: Stephen Toub <[email protected]>

* Remove null check for httpresponse.Content as it is always assigned to.

- Address review comments

* Address review comments

* Remove methods that will not be implemented right now,

* Add properties back to fix build error

- error : MembersMustExist : Member 'public System.Boolean System.Net.Http.SocketsHttpHandler.XXXXXXXXXXXX.get()' does not exist in the implementation but it does exist in the contract.

* Remove tcs TaskCompletionSource to address review comments

* code style change

* Remove disposing of _abortCts here as it causes runtime errors as being disposed of too early

* Address review comment for GetType()

* Rename library as per discussions

* Add lock around the _boundObjects and _rawToJS access.

- Address concurrency review comments

* Address review comments for disposing of CancellationTokenSource

* Address new HttpContent overloads in .NET 5 that take CancellationToken

* Add project and test structure for JavaScript InteropServices

* Remove previous modification as it is no longer needed.

* Update src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs

Co-authored-by: Stephen Toub <[email protected]>

* Remove custom message passed to the PNSE .ctor

* Update `mono` to dotnet or .NET

* Address review comment for internal sealed class

* Address extra message text

* Move these source modules to System.Runtime.InteropServices.JavaScript

* Add interop source modules to System.Runtime.InteropServices.JavaScript project

* Remove placeholder source

* Reference System.Runtime.InteropServices.JavaScript project

* Address review comments Unsafe.SizeOf

* Finish move of sources to InteropServices.JavaScript

* Remove ActiveIssue to address review comments

* Add core implementations

* Add core object implementation for Map

* Remove unused targetframework

* Fix PNSE in HttpClientHandler .ctor

- When creating an instance of the browser webassembly `System.Net.Http.BrowserHttpHandler` the following error is thrown.

```
System.PlatformNotSupportedException: Operation is not supported on this platform.
    at System.Net.Http.BrowserHttpHandler.get_SslOptions()
    at System.Net.Http.HttpClientHandler.ThrowForModifiedManagedSslOptionsIfStarted()
    at System.Net.Http.HttpClientHandler.set_ClientCertificateOptions(ClientCertificateOption value)
    at System.Net.Http.HttpClientHandler..ctor()
    at System.Net.Http.HttpClient..ctor()

```

* Remove extra parameters to `PlatformNotSupportedException`

* Fix tests due to underlying field name changing and reflection being used to obtain the socket field

* Initial commit of reference counting code.

* Update code formatting

* Update solution formatting

* [browser][wasm] Add support for marshaling the AnyRef SafeHandle

- When calling into the bindings from managed code the` JSObject` reference handle is incremented.
- After execution of the call the `JSObject` reference is decremented.
- Special processing for the `GlobalObject` where the object is set with `ownsHandle` = false so that it is not released.
- Release reference counts on javascript exceptions.

* Code cleanup and formatting.

* Clean up

* Fix delegate code and address review comments

* Code clean up and change accessor on AnyRefHandle

* Move outside block

* Remove unused method

* Remove nullable type from dictionary

* Remove comments

* Marking methods with Linker-friendly reflection by using DynamicDependency attribute

* address redundant using

* Address lock review comment

* Address review comments

* remove nullable code

* Address review comments

* Add Debug.Assert to address review comment

* Address assert comments and code formatting

Co-authored-by: Marek Safar <[email protected]>
Co-authored-by: Stephen Toub <[email protected]>
  • Loading branch information
3 people authored Jun 12, 2020
1 parent f633f18 commit 208bce9
Show file tree
Hide file tree
Showing 26 changed files with 481 additions and 277 deletions.
9 changes: 0 additions & 9 deletions src/libraries/Common/src/Interop/Browser/Interop.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ internal static partial class Runtime
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern object ReleaseObject(int jsObjHandle, out int exceptionalResult);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern object NewObjectJS(int jsObjHandle, object[] parms, out int exceptionalResult);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern object BindCoreObject(int jsObjHandle, int gcHandle, out int exceptionalResult);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern object BindHostObject(int jsObjHandle, int gcHandle, out int exceptionalResult);
Expand Down Expand Up @@ -91,13 +89,6 @@ public static int New(string hostClassName, params object[] parms)
return (int)res;
}

public static JSObject? NewJSObject(JSObject? jsFuncPtr = null, params object[] parms)
{
object res = NewObjectJS(jsFuncPtr?.JSHandle ?? 0, parms, out int exception);
if (exception != 0)
throw new JSException((string)res);
return res as JSObject;
}
public static object GetGlobalObject(string? str = null)
{
int exception;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,23 @@
# Visual Studio 15
VisualStudioVersion = 15.0.27213.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Runtime.InteropServices.JavaScript.Tests", "tests\System.Runtime.InteropServices.JavaScript.Tests.csproj", "{7A93B8A0-E663-4CB1-B6A5-850E5EC56146}"
ProjectSection(ProjectDependencies) = postProject
{4AC5343E-6E31-4BA5-A795-0493AE7E9008} = {4AC5343E-6E31-4BA5-A795-0493AE7E9008}
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Runtime.InteropServices.JavaScript", "src\System.Runtime.InteropServices.JavaScript.csproj", "{4AC5343E-6E31-4BA5-A795-0493AE7E9008}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{1A2F9F4A-A032-433E-B914-ADD5992BB178}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E107E9C1-E893-4E87-987E-04EF0DCEAEFD}"
EndProject
Project("{9344BDBB-3E7F-41FC-A0DD-8665D75EE146}") = "System.Runtime.InteropServices.JavaScript.Tests", "tests\System.Runtime.InteropServices.JavaScript.Tests.csproj", "{4F753464-0719-4559-9E0F-86175CECA903}"
ProjectSection(ProjectDependencies) = postProject
{644FCC7F-1478-4D30-BF66-40E0ADF8723C} = {644FCC7F-1478-4D30-BF66-40E0ADF8723C}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Runtime.InteropServices.JavaScript", "src\System.Runtime.InteropServices.JavaScript.csproj", "{644FCC7F-1478-4D30-BF66-40E0ADF8723C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7A93B8A0-E663-4CB1-B6A5-850E5EC56146}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7A93B8A0-E663-4CB1-B6A5-850E5EC56146}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7A93B8A0-E663-4CB1-B6A5-850E5EC56146}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7A93B8A0-E663-4CB1-B6A5-850E5EC56146}.Release|Any CPU.Build.0 = Release|Any CPU
{B0FFC4A8-BAC3-4A7F-8FD5-5B680209371C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B0FFC4A8-BAC3-4A7F-8FD5-5B680209371C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B0FFC4A8-BAC3-4A7F-8FD5-5B680209371C}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -31,10 +27,6 @@ Global
{96AF3242-A368-4F13-B006-A722CC3B8517}.Debug|Any CPU.Build.0 = Debug|Any CPU
{96AF3242-A368-4F13-B006-A722CC3B8517}.Release|Any CPU.ActiveCfg = Release|Any CPU
{96AF3242-A368-4F13-B006-A722CC3B8517}.Release|Any CPU.Build.0 = Release|Any CPU
{4AC5343E-6E31-4BA5-A795-0493AE7E9008}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4AC5343E-6E31-4BA5-A795-0493AE7E9008}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4AC5343E-6E31-4BA5-A795-0493AE7E9008}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4AC5343E-6E31-4BA5-A795-0493AE7E9008}.Release|Any CPU.Build.0 = Release|Any CPU
{CEFAB3B8-3B7F-4B6C-9A5F-2DCDD1A551B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CEFAB3B8-3B7F-4B6C-9A5F-2DCDD1A551B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CEFAB3B8-3B7F-4B6C-9A5F-2DCDD1A551B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -43,17 +35,25 @@ Global
{375E5A4A-9026-411E-9CD8-606874CFF7F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{375E5A4A-9026-411E-9CD8-606874CFF7F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{375E5A4A-9026-411E-9CD8-606874CFF7F0}.Release|Any CPU.Build.0 = Release|Any CPU
{4F753464-0719-4559-9E0F-86175CECA903}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4F753464-0719-4559-9E0F-86175CECA903}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4F753464-0719-4559-9E0F-86175CECA903}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4F753464-0719-4559-9E0F-86175CECA903}.Release|Any CPU.Build.0 = Release|Any CPU
{644FCC7F-1478-4D30-BF66-40E0ADF8723C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{644FCC7F-1478-4D30-BF66-40E0ADF8723C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{644FCC7F-1478-4D30-BF66-40E0ADF8723C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{644FCC7F-1478-4D30-BF66-40E0ADF8723C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{7A93B8A0-E663-4CB1-B6A5-850E5EC56146} = {1A2F9F4A-A032-433E-B914-ADD5992BB178}
{B0FFC4A8-BAC3-4A7F-8FD5-5B680209371C} = {1A2F9F4A-A032-433E-B914-ADD5992BB178}
{96AF3242-A368-4F13-B006-A722CC3B8517} = {1A2F9F4A-A032-433E-B914-ADD5992BB178}
{4AC5343E-6E31-4BA5-A795-0493AE7E9008} = {E107E9C1-E893-4E87-987E-04EF0DCEAEFD}
{CEFAB3B8-3B7F-4B6C-9A5F-2DCDD1A551B5} = {1A2F9F4A-A032-433E-B914-ADD5992BB178}
{375E5A4A-9026-411E-9CD8-606874CFF7F0} = {E107E9C1-E893-4E87-987E-04EF0DCEAEFD}
{4F753464-0719-4559-9E0F-86175CECA903} = {1A2F9F4A-A032-433E-B914-ADD5992BB178}
{644FCC7F-1478-4D30-BF66-40E0ADF8723C} = {E107E9C1-E893-4E87-987E-04EF0DCEAEFD}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2151451C-8B2A-44DB-881E-B922A4795A30}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,48 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
using Microsoft.Win32.SafeHandles;

namespace System.Runtime.InteropServices.JavaScript
{
public class AnyRef
public abstract class AnyRef : SafeHandleMinusOneIsInvalid
{
public int JSHandle { get; protected private set; }
internal GCHandle Handle;
private GCHandle AnyRefHandle;
public int JSHandle => (int)handle;

internal AnyRef(int jsHandle, bool ownsHandle) : this((IntPtr)jsHandle, ownsHandle)
{ }

internal AnyRef(IntPtr jsHandle, bool ownsHandle) : base(ownsHandle)
{
SetHandle(jsHandle);
AnyRefHandle = GCHandle.Alloc(this, ownsHandle ? GCHandleType.Weak : GCHandleType.Normal);
}
internal int Int32Handle => (int)(IntPtr)AnyRefHandle;

protected void FreeGCHandle()
{
AnyRefHandle.Free();
}
#if DEBUG_HANDLE
private int _refCount;

internal AnyRef(int jsHandle)
internal void AddRef()
{
JSHandle = jsHandle;
Handle = GCHandle.Alloc(this);
Interlocked.Increment(ref _refCount);
}

internal AnyRef(IntPtr jsHandle)
internal void Release()
{
JSHandle = (int)jsHandle;
Handle = GCHandle.Alloc(this);
Debug.Assert(_refCount > 0, "AnyRefSafeHandle: Release() called more times than AddRef");
Interlocked.Decrement(ref _refCount);
}

internal int Int32Handle => (int)(IntPtr)Handle;
internal int RefCount => _refCount;
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public Array(params object[] _params) : base(Interop.Runtime.New<Array>(_params)
/// Initializes a new instance of the Array/> class.
/// </summary>
/// <param name="jsHandle">Js handle.</param>
internal Array(IntPtr jsHandle) : base(jsHandle)
/// <param name="ownsHandle">Whether or not the handle is owned by the clr or not.</param>
internal Array(IntPtr jsHandle, bool ownsHandle) : base(jsHandle, ownsHandle)
{ }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public ArrayBuffer(int length) : base(Interop.Runtime.New<ArrayBuffer>(length))
/// Initializes a new instance of the JavaScript Core ArrayBuffer class.
/// </summary>
/// <param name="jsHandle">Js handle.</param>
internal ArrayBuffer(IntPtr jsHandle) : base(jsHandle)
/// <param name="ownsHandle">Whether or not the handle is owned by the clr or not.</param>
internal ArrayBuffer(IntPtr jsHandle, bool ownsHandle) : base(jsHandle, ownsHandle)
{ }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ namespace System.Runtime.InteropServices.JavaScript
/// </remarks>
public abstract class CoreObject : JSObject
{
protected CoreObject(int jsHandle) : base(jsHandle)
protected CoreObject(int jsHandle) : base(jsHandle, true)
{
object result = Interop.Runtime.BindCoreObject(jsHandle, (int)(IntPtr)Handle, out int exception);
object result = Interop.Runtime.BindCoreObject(jsHandle, Int32Handle, out int exception);
if (exception != 0)
throw new JSException($"CoreObject Error binding: {result}");
}

internal CoreObject(IntPtr js_handle) : base(js_handle)
internal CoreObject(IntPtr jsHandle, bool ownsHandle) : base(jsHandle, ownsHandle)
{ }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,23 @@ public DataView(SharedArrayBuffer buffer, int byteOffset, int byteLength) : base
/// <summary>
/// Initializes a new instance of the DataView class.
/// </summary>
/// <param name="js_handle">Js handle.</param>
internal DataView(IntPtr js_handle) : base(js_handle)
/// <param name="jsHandle">Js handle.</param>
/// <param name="ownsHandle">Managed owned</param>
internal DataView(IntPtr jsHandle, bool ownsHandle) : base(jsHandle, ownsHandle)
{ }

/// <summary>
/// Gets the length (in bytes) of this view from the start of its ArrayBuffer. Fixed at construction time and thus read only.
/// </summary>
/// <value>The length (in bytes) of this view.</value>
public int ByteLength => (int)GetObjectProperty("byteLength");

/// <summary>
/// Gets the offset (in bytes) of this view from the start of its ArrayBuffer. Fixed at construction time and thus read only.
/// </summary>
/// <value>The offset (in bytes) of this view.</value>
public int ByteOffset => (int)GetObjectProperty("byteOffset");

/// <summary>
/// Gets the ArrayBuffer referenced by this view. Fixed at construction time and thus read only.
/// </summary>
Expand All @@ -97,20 +101,23 @@ internal DataView(IntPtr js_handle) : base(js_handle)
/// <param name="byteOffset">Byte offset.</param>
/// <param name="littleEndian">Indicates whether the 64-bit float is stored in little- or big-endian format. If <c>false</c>, a big-endian value is read.</param>
public double GetFloat64(int byteOffset, bool littleEndian = false) => UnBoxValue<double>(Invoke("getFloat64", byteOffset, littleEndian));

/// <summary>
/// Gets the signed 16-bit integer (short) at the specified byte offset from the start of the DataView.
/// </summary>
/// <returns>A signed 16-bit ineger (short) number.</returns>
/// <param name="byteOffset">Byte offset.</param>
/// <param name="littleEndian">Indicates whether the 16-bit integer (short) is stored in little- or big-endian format. If <c>false</c>, a big-endian value is read.</param>
public short GetInt16(int byteOffset, bool littleEndian = false) => UnBoxValue<short>(Invoke("getInt16", byteOffset, littleEndian));

/// <summary>
/// Gets the signed 32-bit integer (int) at the specified byte offset from the start of the DataView.
/// </summary>
/// <returns>A signed 32-bit ineger (int) number.</returns>
/// <param name="byteOffset">Byte offset.</param>
/// <param name="littleEndian">Indicates whether the 32-bit integer (int) is stored in little- or big-endian format. If <c>false</c>, a big-endian value is read.</param>
public int GetInt32(int byteOffset, bool littleEndian = false) => UnBoxValue<int>(Invoke("getInt32", byteOffset, littleEndian));

/// <summary>
/// Gets the signed 8-bit byte (sbyte) at the specified byte offset from the start of the DataView.
/// </summary>
Expand All @@ -119,6 +126,7 @@ internal DataView(IntPtr js_handle) : base(js_handle)
/// <param name="littleEndian">Indicates whether the 8-bit byte is stored in little- or big-endian format. If <c>false</c>, a big-endian value is read.</param>
[CLSCompliant(false)]
public sbyte GetInt8(int byteOffset, bool littleEndian = false) => UnBoxValue<sbyte>(Invoke("getInt8", byteOffset, littleEndian));

/// <summary>
/// Gets the unsigned 16-bit integer (short) at the specified byte offset from the start of the DataView.
/// </summary>
Expand All @@ -127,6 +135,7 @@ internal DataView(IntPtr js_handle) : base(js_handle)
/// <param name="littleEndian">Indicates whether the unsigned 16-bit float is stored in little- or big-endian format. If <c>false</c>, a big-endian value is read.</param>
[CLSCompliant(false)]
public ushort GetUint16(int byteOffset, bool littleEndian = false) => UnBoxValue<ushort>(Invoke("getUint16", byteOffset, littleEndian));

/// <summary>
/// Gets the usigned 32-bit integer (uint) at the specified byte offset from the start of the DataView.
/// </summary>
Expand All @@ -135,13 +144,15 @@ internal DataView(IntPtr js_handle) : base(js_handle)
/// <param name="littleEndian">Indicates whether the 32-bit float is stored in little- or big-endian format. If <c>false</c>, a big-endian value is read.</param>
[CLSCompliant(false)]
public uint GetUint32(int byteOffset, bool littleEndian = false) => UnBoxValue<uint>(Invoke("getUint32", byteOffset, littleEndian));

/// <summary>
/// Gets the unsigned 8-bit byte (byte) at the specified byte offset from the start of the DataView.
/// </summary>
/// <returns>A unsigned 8-bit byte (byte) number.</returns>
/// <param name="byteOffset">Byte offset.</param>
/// <param name="littleEndian">Indicates whether the 32-bit float is stored in little- or big-endian format. If <c>false</c>, a big-endian value is read.</param>
public byte GetUint8(int byteOffset, bool littleEndian = false) => UnBoxValue<byte>(Invoke("getUint8", byteOffset, littleEndian));

/// <summary>
/// Sets the signed 32-bit float (float) at the specified byte offset from the start of the DataView.
/// </summary>
Expand All @@ -157,20 +168,23 @@ internal DataView(IntPtr js_handle) : base(js_handle)
/// <param name="value">double value.</param>
/// <param name="littleEndian">Indicates whether the 64-bit float is stored in little- or big-endian format. If <c>false</c>, a big-endian value is read.</param>
public void SetFloat64(int byteOffset, double value, bool littleEndian = false) => Invoke("setFloat64", byteOffset, value, littleEndian);

/// <summary>
/// Sets the signed 16-bit integer (short) at the specified byte offset from the start of the DataView.
/// </summary>
/// <param name="byteOffset">Byte offset.</param>
/// <param name="value">short value.</param>
/// <param name="littleEndian">Indicates whether the 16-bit integer (short) is stored in little- or big-endian format. If <c>false</c>, a big-endian value is read.</param>
public void SetInt16(int byteOffset, short value, bool littleEndian = false) => Invoke("setInt16", byteOffset, value, littleEndian);

/// <summary>
/// Sets the signed 32-bit integer (int) at the specified byte offset from the start of the DataView.
/// </summary>
/// <param name="byteOffset">Byte offset.</param>
/// <param name="value">int value.</param>
/// <param name="littleEndian">Indicates whether the 32-bit integer (int) is stored in little- or big-endian format. If <c>false</c>, a big-endian value is read.</param>
public void SetInt32(int byteOffset, int value, bool littleEndian = false) => Invoke("setInt32", byteOffset, value, littleEndian);

/// <summary>
/// Sets the signed 8-bit byte (sbyte) at the specified byte offset from the start of the DataView.
/// </summary>
Expand All @@ -179,6 +193,7 @@ internal DataView(IntPtr js_handle) : base(js_handle)
/// <param name="littleEndian">Indicates whether the 8-bit byte is stored in little- or big-endian format. If <c>false</c>, a big-endian value is read.</param>
[CLSCompliant(false)]
public void SetInt8(int byteOffset, sbyte value, bool littleEndian = false) => Invoke("setInt8", byteOffset, value, littleEndian);

/// <summary>
/// Sets the unsigned 16-bit integer (short) at the specified byte offset from the start of the DataView.
/// </summary>
Expand All @@ -187,6 +202,7 @@ internal DataView(IntPtr js_handle) : base(js_handle)
/// <param name="littleEndian">Indicates whether the unsigned 16-bit float is stored in little- or big-endian format. If <c>false</c>, a big-endian value is read.</param>
[CLSCompliant(false)]
public void SetUint16(int byteOffset, ushort value, bool littleEndian = false) => Invoke("setUint16", byteOffset, value, littleEndian);

/// <summary>
/// Sets the usigned 32-bit integer (uint) at the specified byte offset from the start of the DataView.
/// </summary>
Expand All @@ -195,6 +211,7 @@ internal DataView(IntPtr js_handle) : base(js_handle)
/// <param name="littleEndian">Indicates whether the 32-bit float is stored in little- or big-endian format. If <c>false</c>, a big-endian value is read.</param>
[CLSCompliant(false)]
public void SetUint32(int byteOffset, uint value, bool littleEndian = false) => Invoke("setUint32", byteOffset, value, littleEndian);

/// <summary>
/// Sets the unsigned 8-bit byte (sbyte) at the specified byte offset from the start of the DataView.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public Float32Array() { }

public Float32Array(int length) : base(length) { }


public Float32Array(ArrayBuffer buffer) : base(buffer) { }

public Float32Array(ArrayBuffer buffer, int byteOffset) : base(buffer, byteOffset) { }
Expand All @@ -25,7 +24,8 @@ public Float32Array(SharedArrayBuffer buffer, int byteOffset) : base(buffer, byt

public Float32Array(SharedArrayBuffer buffer, int byteOffset, int length) : base(buffer, byteOffset, length) { }

internal Float32Array(IntPtr js_handle) : base(js_handle) { }
internal Float32Array(IntPtr jsHandle, bool ownsHandle) : base(jsHandle, ownsHandle)
{ }

/// <summary>
/// Defines an implicit conversion of Float32Array class to a float
Expand Down
Loading

0 comments on commit 208bce9

Please sign in to comment.