Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[browser][wasm] Implement JavaScript managed object reference counting #37417

Merged
merged 145 commits into from
Jun 12, 2020
Merged
Show file tree
Hide file tree
Changes from 140 commits
Commits
Show all changes
145 commits
Select commit Hold shift + click to select a range
d17e863
Add Browser specific files to the project
kjpou1 Apr 28, 2020
aafa4b0
Browser specific file modification to not include Quic support
kjpou1 Apr 28, 2020
7d52436
Add Browser specific support files for Http Handler code
kjpou1 Apr 28, 2020
242ade6
Add Interop code for JavaScript support
kjpou1 Apr 28, 2020
2ca93d8
Remove unused reference
kjpou1 Apr 28, 2020
ab0e0de
Add Http handler bindings implementation
kjpou1 Apr 28, 2020
bc39563
Nullable support
kjpou1 Apr 28, 2020
b60ee5b
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 Apr 28, 2020
92f74c4
Add browser files back after upstream merge conflict
kjpou1 Apr 28, 2020
a9248de
Use attribute Link syntax for Common files to bring in sync with exis…
kjpou1 Apr 28, 2020
dc82e45
Address Missing license header
kjpou1 Apr 29, 2020
cc70c9f
Code formatting and removal of comment code.
kjpou1 Apr 29, 2020
c96a6f1
Address PR comments.
kjpou1 Apr 29, 2020
bb9ff24
Address commit comments
kjpou1 Apr 29, 2020
2f7ace0
Add blank line between License and first line of code. Address comments
kjpou1 Apr 29, 2020
ced6437
Replace SocketsHttpHandler build for Browser.
kjpou1 Apr 29, 2020
5c89333
Cleanup SendAsync code when doing the call out to JavaScript Fetch.
kjpou1 Apr 29, 2020
4eb5dd1
Refactor BrowserHttpHandler code.
kjpou1 Apr 29, 2020
d5360b6
Cleanup
kjpou1 Apr 29, 2020
d1b537d
Remove null check as it should be checked in outer classes
kjpou1 Apr 29, 2020
39947b1
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 Apr 29, 2020
2d8e124
Cleanup var usage to use explicit type. Address commit comments
kjpou1 Apr 30, 2020
d443cfd
Move `.ConfigureAwait(true)` to `.ConfigureAwait(false)`
kjpou1 Apr 30, 2020
0d63762
Change accessor of Runtime javascript interop methods.
kjpou1 Apr 30, 2020
a91637c
Change accessor of Runtime javascript interop methods.
kjpou1 Apr 30, 2020
cdbbf0f
Address review comments for unused code
kjpou1 Apr 30, 2020
5814d1d
Cleanup leftover debug WriteLines
kjpou1 Apr 30, 2020
146b6d7
Remove the AllowNull attributes as per review comments.
kjpou1 Apr 30, 2020
1f510f4
Update src/libraries/Common/src/Interop/Browser/Interop.Runtime.cs
kjpou1 Apr 30, 2020
90b83f6
throw different exception type as per review comment
kjpou1 Apr 30, 2020
da394d6
use char[] array instead and return new string(array).
kjpou1 Apr 30, 2020
95af576
Initial addition of Browser Interop library
kjpou1 Apr 30, 2020
ada3198
use char[] array instead and return new string(array).
kjpou1 Apr 30, 2020
daa02cc
Add project references so the Interop.JavaScript project builds
kjpou1 May 4, 2020
8395f8f
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 May 4, 2020
d45f9a9
Coding Style update
kjpou1 May 4, 2020
c1190d2
Split the runtime methods into two modules.
kjpou1 May 4, 2020
93100b5
Move System.Runtime.Interop.JavaScript to \src\libraries
kjpou1 May 4, 2020
5845ee3
Change preprocessor to upper case TARGETS_BROWSER
kjpou1 May 4, 2020
3c75797
Update src/libraries/Common/src/Interop/Browser/Interop.Runtime.Api.cs
kjpou1 May 4, 2020
c7c80bc
Update src/libraries/Common/src/Interop/Browser/Interop.Runtime.Api.cs
kjpou1 May 4, 2020
568211e
Update src/libraries/Common/src/Interop/Browser/Interop.Runtime.Api.cs
kjpou1 May 4, 2020
282efa0
Rename from .Api to .Bridge to address review comments
kjpou1 May 5, 2020
b09e224
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 May 5, 2020
fa165aa
Modify .csproj files to reflect .Bridge.cs change.
kjpou1 May 5, 2020
b57fef9
Remove unnecessary constant
kjpou1 May 5, 2020
a4753c0
Add docs
kjpou1 May 6, 2020
ee9c8d9
Update Bridge link
kjpou1 May 6, 2020
1eb5d23
Collapse code as per review comment.
kjpou1 May 6, 2020
49193b8
Address review comments on `Task.ConfigureAwait(continueOnCapturedCon…
kjpou1 May 6, 2020
6ce0e8d
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 May 6, 2020
1a655e5
Address review comment about using PropertyInfo reflection.
kjpou1 May 6, 2020
4636867
Coding Style - Address review comments
kjpou1 May 7, 2020
35380b5
Part of code style and object documentation to partially address revi…
kjpou1 May 7, 2020
233c3b3
Update src/libraries/Common/src/Interop/Browser/Interop.JavaScript.JS…
kjpou1 May 8, 2020
5e0ebf2
Update src/libraries/Common/src/Interop/Browser/Interop.Runtime.Bridg…
kjpou1 May 8, 2020
117c9ef
Update src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpH…
kjpou1 May 8, 2020
8604280
Update src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpH…
kjpou1 May 8, 2020
65c1f22
Update src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpH…
kjpou1 May 8, 2020
3d6ce31
Update src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpH…
kjpou1 May 8, 2020
de114a5
Update src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpH…
kjpou1 May 8, 2020
9244cb4
Add class docs and code style updates
kjpou1 May 8, 2020
fb95c39
Update src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpH…
kjpou1 May 8, 2020
22f5ea2
Fix badly formed XML
kjpou1 May 8, 2020
37a2b42
Update src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpH…
kjpou1 May 8, 2020
b20d6b5
Remove unnecessary Property implementations.
kjpou1 May 8, 2020
fc302f3
Update src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpH…
kjpou1 May 8, 2020
3a93043
Update code style involving the use of `var`
kjpou1 May 8, 2020
4818f60
Modify the underlying sockets field name.
kjpou1 May 8, 2020
521e772
Style and address review comments
kjpou1 May 8, 2020
688f5a7
Remove reliance on ConnectHelper.cs code as it is not supported on Br…
kjpou1 May 8, 2020
ea27792
Update src/libraries/Common/src/Interop/Browser/Interop.Runtime.Bridg…
kjpou1 May 8, 2020
04c53ae
Remove null check for httpresponse.Content as it is always assigned to.
kjpou1 May 8, 2020
ca9e2db
Address review comments
kjpou1 May 8, 2020
6e1542f
Remove methods that will not be implemented right now,
kjpou1 May 8, 2020
ea7f1c3
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 May 11, 2020
7e39ffb
Add properties back to fix build error
kjpou1 May 11, 2020
703e504
Remove tcs TaskCompletionSource to address review comments
kjpou1 May 11, 2020
6414529
code style change
kjpou1 May 11, 2020
a74d985
Remove disposing of _abortCts here as it causes runtime errors as bei…
kjpou1 May 11, 2020
4baf426
Address review comment for GetType()
kjpou1 May 11, 2020
ea61992
Rename library as per discussions
kjpou1 May 12, 2020
004ab2d
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 May 12, 2020
0ae1bf7
Add lock around the _boundObjects and _rawToJS access.
kjpou1 May 12, 2020
63b4e1e
Address review comments for disposing of CancellationTokenSource
kjpou1 May 15, 2020
e8ea3a9
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 May 18, 2020
648e61c
Address new HttpContent overloads in .NET 5 that take CancellationToken
kjpou1 May 18, 2020
dd05832
Add project and test structure for JavaScript InteropServices
kjpou1 May 19, 2020
796692b
Remove previous modification as it is no longer needed.
kjpou1 May 20, 2020
626d6c9
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 May 20, 2020
df1be16
Update src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpH…
kjpou1 May 20, 2020
e206e4b
Remove custom message passed to the PNSE .ctor
kjpou1 May 20, 2020
704bf8a
Update `mono` to dotnet or .NET
kjpou1 May 20, 2020
33222ea
Address review comment for internal sealed class
kjpou1 May 20, 2020
79e3287
Address extra message text
kjpou1 May 20, 2020
fbb6e6f
Move these source modules to System.Runtime.InteropServices.JavaScript
kjpou1 May 20, 2020
6614009
Add interop source modules to System.Runtime.InteropServices.JavaScri…
kjpou1 May 20, 2020
bdc38c4
Remove placeholder source
kjpou1 May 20, 2020
fcb9802
Reference System.Runtime.InteropServices.JavaScript project
kjpou1 May 20, 2020
b8abce1
Address review comments Unsafe.SizeOf
kjpou1 May 20, 2020
a712114
Finish move of sources to InteropServices.JavaScript
kjpou1 May 25, 2020
0185c17
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 May 25, 2020
e46ab9f
Remove ActiveIssue to address review comments
kjpou1 May 25, 2020
80b2132
Add core implementations
kjpou1 May 25, 2020
af5d902
Add core object implementation for Map
kjpou1 May 25, 2020
f2fb363
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 May 25, 2020
e5de014
Remove unused targetframework
kjpou1 May 26, 2020
530afe4
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 May 26, 2020
c72e64c
Fix PNSE in HttpClientHandler .ctor
kjpou1 May 26, 2020
5f17ee1
Remove extra parameters to `PlatformNotSupportedException`
kjpou1 May 26, 2020
d9c6dc4
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 May 27, 2020
0bd5966
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 May 27, 2020
25db30b
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 May 28, 2020
1468104
Fix tests due to underlying field name changing and reflection being …
kjpou1 May 28, 2020
da63da8
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 May 29, 2020
a276806
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 Jun 1, 2020
5d6f024
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 Jun 1, 2020
9bcdbcb
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 Jun 2, 2020
4706c69
Initial commit of reference counting code.
kjpou1 Jun 2, 2020
77e7e68
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 Jun 2, 2020
a7af316
Update code formatting
kjpou1 Jun 2, 2020
9e5ce12
Update solution formatting
kjpou1 Jun 2, 2020
ff19d0c
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 Jun 2, 2020
7c5cc2c
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 Jun 3, 2020
2d20cc1
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 Jun 4, 2020
9f74e50
[browser][wasm] Add support for marshaling the AnyRef SafeHandle
kjpou1 Jun 4, 2020
3702917
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 Jun 8, 2020
38cefb6
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 Jun 9, 2020
aaf4bd6
Code cleanup and formatting.
kjpou1 Jun 9, 2020
639e7a3
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 Jun 10, 2020
5377cd9
Clean up
kjpou1 Jun 10, 2020
67330f1
Fix delegate code and address review comments
kjpou1 Jun 10, 2020
acdf5e6
Code clean up and change accessor on AnyRefHandle
kjpou1 Jun 10, 2020
ed308a3
Move outside block
kjpou1 Jun 10, 2020
05b0371
Remove unused method
kjpou1 Jun 10, 2020
2749f18
Remove nullable type from dictionary
kjpou1 Jun 10, 2020
403bedd
Remove comments
kjpou1 Jun 10, 2020
51e66a3
Marking methods with Linker-friendly reflection by using DynamicDepen…
kjpou1 Jun 10, 2020
4cc6fb4
address redundant using
kjpou1 Jun 10, 2020
31c640f
Address lock review comment
kjpou1 Jun 10, 2020
2743369
Address review comments
kjpou1 Jun 11, 2020
08a05cd
remove nullable code
kjpou1 Jun 11, 2020
9cee16a
Address review comments
kjpou1 Jun 11, 2020
d504b30
Add Debug.Assert to address review comment
kjpou1 Jun 11, 2020
9e74013
Address assert comments and code formatting
kjpou1 Jun 11, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,44 @@
// 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;
protected GCHandle AnyRefHandle;
kjpou1 marked this conversation as resolved.
Show resolved Hide resolved
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;

#if DEBUG_HANDLE
kjpou1 marked this conversation as resolved.
Show resolved Hide resolved
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