Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpavelsavara <pavel.savara@gmail.com>2022-03-10 14:58:44 +0300
committerpavelsavara <pavel.savara@gmail.com>2022-03-10 14:58:44 +0300
commitb8868746e0be2e07761ddefb46c7e9d51d6bf29e (patch)
treea0b1e13c7a1e0419bcf5876deec3e535191839ff
parentf768cb84e41ad64b5bcb7568ccb3fedc886c92ab (diff)
parentf12e2d64110de786a4eb2f985c086fbb32631603 (diff)
Merge branch 'wasm_interop_prep1' into wasm_jsimport_jsexport_v2wasm_jsimport_jsexport_v2_base
-rw-r--r--src/libraries/Common/src/Interop/Browser/Interop.Runtime.cs36
-rw-r--r--src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs5
-rw-r--r--src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/BrowserWebSockets/BrowserWebSocket.cs11
-rw-r--r--src/libraries/System.Private.Runtime.InteropServices.JavaScript/System.Private.Runtime.InteropServices.JavaScript.sln23
-rw-r--r--src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System.Private.Runtime.InteropServices.JavaScript.csproj13
-rw-r--r--src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Array.cs14
-rw-r--r--src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/ArrayBuffer.cs4
-rw-r--r--src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/CoreObject.cs29
-rw-r--r--src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/DataView.cs28
-rw-r--r--src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Float32Array.cs39
-rw-r--r--src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Float64Array.cs39
-rw-r--r--src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Function.cs4
-rw-r--r--src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/HostObject.cs27
-rw-r--r--src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Int16Array.cs40
-rw-r--r--src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Int32Array.cs39
-rw-r--r--src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Int8Array.cs50
-rw-r--r--src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSException.cs2
-rw-r--r--src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSObject.References.cs6
-rw-r--r--src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSObject.cs79
-rw-r--r--src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Map.cs256
-rw-r--r--src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Runtime.CS.Owned.cs37
-rw-r--r--src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Runtime.JS.Owned.cs12
-rw-r--r--src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Runtime.cs12
-rw-r--r--src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/SharedArrayBuffer.cs51
-rw-r--r--src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/TypedArray.cs235
-rw-r--r--src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Uint16Array.cs40
-rw-r--r--src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Uint32Array.cs40
-rw-r--r--src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Uint8Array.cs64
-rw-r--r--src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Uint8ClampedArray.cs47
-rw-r--r--src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System.Private.Runtime.InteropServices.JavaScript.Tests.csproj2
-rw-r--r--src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/ArrayTests.cs1
-rw-r--r--src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/DataViewTests.cs1
-rw-r--r--src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/DelegateTests.cs14
-rw-r--r--src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/HelperMarshal.cs250
-rw-r--r--src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/JavaScriptTests.cs289
-rw-r--r--src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/MapTests.cs213
-rw-r--r--src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/MarshalTests.cs268
-rw-r--r--src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/SharedArrayBufferTests.cs156
-rw-r--r--src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/TypedArrayTests.cs288
-rw-r--r--src/mono/wasm/runtime/cancelable-promise.ts6
-rw-r--r--src/mono/wasm/runtime/cjs/dotnet.cjs.lib.js2
-rw-r--r--src/mono/wasm/runtime/corebindings.c6
-rw-r--r--src/mono/wasm/runtime/cs-to-js.ts2
-rw-r--r--src/mono/wasm/runtime/cwraps.ts11
-rw-r--r--src/mono/wasm/runtime/driver.c2
-rw-r--r--src/mono/wasm/runtime/es6/dotnet.es6.lib.js2
-rw-r--r--src/mono/wasm/runtime/event-listener.ts89
-rw-r--r--src/mono/wasm/runtime/exports.ts3
-rw-r--r--src/mono/wasm/runtime/method-binding.ts15
-rw-r--r--src/mono/wasm/runtime/method-calls.ts10
-rw-r--r--src/mono/wasm/runtime/startup.ts11
-rw-r--r--src/mono/wasm/runtime/strings.ts20
-rw-r--r--src/mono/wasm/runtime/types.ts10
-rw-r--r--src/mono/wasm/runtime/web-socket.ts2
-rw-r--r--src/mono/wasm/wasm.proj4
55 files changed, 231 insertions, 2728 deletions
diff --git a/src/libraries/Common/src/Interop/Browser/Interop.Runtime.cs b/src/libraries/Common/src/Interop/Browser/Interop.Runtime.cs
index 051b412b119..0a22de28191 100644
--- a/src/libraries/Common/src/Interop/Browser/Interop.Runtime.cs
+++ b/src/libraries/Common/src/Interop/Browser/Interop.Runtime.cs
@@ -17,47 +17,43 @@ internal static partial class Interop
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern object CompileFunction(string str, out int exceptionalResult);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal static extern object InvokeJSWithArgs(int jsHandle, string method, object?[] parms, out int exceptionalResult);
+ internal static extern object InvokeJSWithArgs(IntPtr jsHandle, string method, object?[] parms, out int exceptionalResult);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal static extern object GetObjectProperty(int jsHandle, string propertyName, out int exceptionalResult);
+ internal static extern object GetObjectProperty(IntPtr jsHandle, string propertyName, out int exceptionalResult);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal static extern object SetObjectProperty(int jsHandle, string propertyName, object value, bool createIfNotExists, bool hasOwnProperty, out int exceptionalResult);
+ internal static extern object SetObjectProperty(IntPtr jsHandle, string propertyName, object value, bool createIfNotExists, bool hasOwnProperty, out int exceptionalResult);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal static extern object GetByIndex(int jsHandle, int index, out int exceptionalResult);
+ internal static extern object GetByIndex(IntPtr jsHandle, int index, out int exceptionalResult);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal static extern object SetByIndex(int jsHandle, int index, object? value, out int exceptionalResult);
+ internal static extern object SetByIndex(IntPtr jsHandle, int index, object? value, out int exceptionalResult);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern object GetGlobalObject(string? globalName, out int exceptionalResult);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal static extern object ReleaseCSOwnedObject(int jsHandle);
+ internal static extern object TypedArrayToArray(IntPtr jsHandle, out int exceptionalResult);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal static extern object CreateCSOwnedObject(string className, object[] parms, out int exceptionalResult);
+ internal static extern object ReleaseCSOwnedObject(IntPtr jsHandle);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal static extern object TypedArrayToArray(int jsHandle, out int exceptionalResult);
+ internal static extern object CreateCSOwnedObject(string className, object[] parms, out int exceptionalResult);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal static extern object TypedArrayCopyTo(int jsHandle, int arrayPtr, int begin, int end, int bytesPerElement, out int exceptionalResult);
+ internal static extern object TypedArrayCopyTo(IntPtr jsHandle, int arrayPtr, int begin, int end, int bytesPerElement, out int exceptionalResult);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern object TypedArrayFrom(int arrayPtr, int begin, int end, int bytesPerElement, int type, out int exceptionalResult);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal static extern object TypedArrayCopyFrom(int jsHandle, int arrayPtr, int begin, int end, int bytesPerElement, out int exceptionalResult);
+ internal static extern object TypedArrayCopyFrom(IntPtr jsHandle, int arrayPtr, int begin, int end, int bytesPerElement, out int exceptionalResult);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal static extern string? AddEventListener(int jsHandle, string name, int gcHandle, int optionsJsHandle);
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal static extern string? RemoveEventListener(int jsHandle, string name, int gcHandle, bool capture);
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal static extern object WebSocketSend(int webSocketJSHandle, IntPtr messagePtr, int offset, int length, int messageType, bool endOfMessage, out int promiseJSHandle, out int exceptionalResult);
+ internal static extern object WebSocketSend(IntPtr webSocketJSHandle, IntPtr messagePtr, int offset, int length, int messageType, bool endOfMessage, out IntPtr promiseJSHandle, out int exceptionalResult);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal static extern object WebSocketReceive(int webSocketJSHandle, IntPtr bufferPtr, int offset, int length, IntPtr responsePtr, out int promiseJSHandle, out int exceptionalResult);
+ internal static extern object WebSocketReceive(IntPtr webSocketJSHandle, IntPtr bufferPtr, int offset, int length, IntPtr responsePtr, out IntPtr promiseJSHandle, out int exceptionalResult);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal static extern object WebSocketOpen(string uri, object[]? subProtocols, Delegate onClosed, out int webSocketJSHandle, out int promiseJSHandle, out int exceptionalResult);
+ internal static extern object WebSocketOpen(string uri, object[]? subProtocols, Delegate onClosed, out IntPtr webSocketJSHandle, out IntPtr promiseJSHandle, out int exceptionalResult);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal static extern string WebSocketAbort(int webSocketJSHandle, out int exceptionalResult);
+ internal static extern string WebSocketAbort(IntPtr webSocketJSHandle, out int exceptionalResult);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal static extern object WebSocketClose(int webSocketJSHandle, int code, string? reason, bool waitForCloseReceived, out int promiseJSHandle, out int exceptionalResult);
+ internal static extern object WebSocketClose(IntPtr webSocketJSHandle, int code, string? reason, bool waitForCloseReceived, out IntPtr promiseJSHandle, out int exceptionalResult);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal static extern string CancelPromise(int promiseJSHandle, out int exceptionalResult);
+ internal static extern string CancelPromise(IntPtr promiseJSHandle, out int exceptionalResult);
// / <summary>
// / Execute the provided string in the JavaScript context
diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs b/src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs
index 1b4ac0fce85..6ca60b37164 100644
--- a/src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs
+++ b/src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs
@@ -13,7 +13,6 @@ using System.Threading.Tasks;
using JSObject = System.Runtime.InteropServices.JavaScript.JSObject;
using JSException = System.Runtime.InteropServices.JavaScript.JSException;
-using HostObject = System.Runtime.InteropServices.JavaScript.HostObject;
using Uint8Array = System.Runtime.InteropServices.JavaScript.Uint8Array;
using Function = System.Runtime.InteropServices.JavaScript.Function;
@@ -194,7 +193,7 @@ namespace System.Net.Http
// Process headers
// Cors has its own restrictions on headers.
// https://developer.mozilla.org/en-US/docs/Web/API/Headers
- using (HostObject jsHeaders = new HostObject("Headers"))
+ using (JSObject jsHeaders = new JSObject("Headers"))
{
foreach (KeyValuePair<string, IEnumerable<string>> header in request.Headers)
{
@@ -217,7 +216,7 @@ namespace System.Net.Http
}
- JSObject abortController = new HostObject("AbortController");
+ JSObject abortController = new JSObject("AbortController");
using JSObject signal = (JSObject)abortController.GetObjectProperty("signal");
requestObject.SetObjectProperty("signal", signal);
diff --git a/src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/BrowserWebSockets/BrowserWebSocket.cs b/src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/BrowserWebSockets/BrowserWebSocket.cs
index 92e30113c5c..380a08546cd 100644
--- a/src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/BrowserWebSockets/BrowserWebSocket.cs
+++ b/src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/BrowserWebSockets/BrowserWebSocket.cs
@@ -7,6 +7,7 @@ using System.Threading.Tasks;
using System.Runtime.InteropServices.JavaScript;
using JavaScript = System.Runtime.InteropServices.JavaScript;
+using JSObject = System.Runtime.InteropServices.JavaScript.JSObject;
namespace System.Net.WebSockets
{
@@ -183,7 +184,7 @@ namespace System.Net.WebSockets
}
};
- var openTask = JavaScript.Runtime.WebSocketOpen(uri.ToString(), subProtocols, onClose, out _innerWebSocket, out int promiseJSHandle);
+ var openTask = JavaScript.Runtime.WebSocketOpen(uri.ToString(), subProtocols, onClose, out _innerWebSocket, out IntPtr promiseJSHandle);
var wrappedTask = CancelationHelper(openTask, promiseJSHandle, cancellationToken, _state);
await wrappedTask.ConfigureAwait(true);
@@ -212,7 +213,7 @@ namespace System.Net.WebSockets
{
try
{
- var sendTask = JavaScript.Runtime.WebSocketSend(_innerWebSocket!, buffer, (int)messageType, endOfMessage, out int promiseJSHandle);
+ var sendTask = JavaScript.Runtime.WebSocketSend(_innerWebSocket!, buffer, (int)messageType, endOfMessage, out IntPtr promiseJSHandle);
if (sendTask == null)
{
// return synchronously
@@ -241,7 +242,7 @@ namespace System.Net.WebSockets
try
{
ArraySegment<int> response = new ArraySegment<int>(new int[3]);
- var receiveTask = JavaScript.Runtime.WebSocketReceive(_innerWebSocket!, buffer, response, out int promiseJSHandle);
+ var receiveTask = JavaScript.Runtime.WebSocketReceive(_innerWebSocket!, buffer, response, out IntPtr promiseJSHandle);
if (receiveTask == null)
{
// return synchronously
@@ -286,7 +287,7 @@ namespace System.Net.WebSockets
_closeStatus = closeStatus;
_closeStatusDescription = statusDescription;
- var closeTask = JavaScript.Runtime.WebSocketClose(_innerWebSocket!, (int)closeStatus, statusDescription, waitForCloseReceived, out int promiseJSHandle);
+ var closeTask = JavaScript.Runtime.WebSocketClose(_innerWebSocket!, (int)closeStatus, statusDescription, waitForCloseReceived, out IntPtr promiseJSHandle);
if (closeTask != null)
{
var wrappedTask = CancelationHelper(closeTask, promiseJSHandle, cancellationToken, _state);
@@ -300,7 +301,7 @@ namespace System.Net.WebSockets
}
}
- private async ValueTask<object> CancelationHelper(Task<object> jsTask, int promiseJSHandle, CancellationToken cancellationToken, WebSocketState previousState)
+ private async ValueTask<object> CancelationHelper(Task<object> jsTask, IntPtr promiseJSHandle, CancellationToken cancellationToken, WebSocketState previousState)
{
if (jsTask.IsCompletedSuccessfully)
{
diff --git a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/System.Private.Runtime.InteropServices.JavaScript.sln b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/System.Private.Runtime.InteropServices.JavaScript.sln
index b64ac26550c..11e35b7f83f 100644
--- a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/System.Private.Runtime.InteropServices.JavaScript.sln
+++ b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/System.Private.Runtime.InteropServices.JavaScript.sln
@@ -15,6 +15,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{F323228E-200
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "gen", "gen", "{53D4886A-6035-458C-834C-D7EDC02A0E26}"
EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Net.Http", "..\System.Net.Http\src\System.Net.Http.csproj", "{BB41B80A-455B-40D2-98A0-6663DDB4C1FD}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Net.WebSockets.Client", "..\System.Net.WebSockets.Client\src\System.Net.WebSockets.Client.csproj", "{7E3B9F01-EBA5-4253-A7F4-CC0E0CC59F1B}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Console", "..\System.Console\src\System.Console.csproj", "{0A8F9368-C66E-4F93-BE3F-001F73F963E6}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -41,16 +47,31 @@ Global
{8061897F-550F-4932-8D35-126BE3CA894C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8061897F-550F-4932-8D35-126BE3CA894C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8061897F-550F-4932-8D35-126BE3CA894C}.Release|Any CPU.Build.0 = Release|Any CPU
+ {BB41B80A-455B-40D2-98A0-6663DDB4C1FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {BB41B80A-455B-40D2-98A0-6663DDB4C1FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {BB41B80A-455B-40D2-98A0-6663DDB4C1FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {BB41B80A-455B-40D2-98A0-6663DDB4C1FD}.Release|Any CPU.Build.0 = Release|Any CPU
+ {7E3B9F01-EBA5-4253-A7F4-CC0E0CC59F1B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {7E3B9F01-EBA5-4253-A7F4-CC0E0CC59F1B}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {7E3B9F01-EBA5-4253-A7F4-CC0E0CC59F1B}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {7E3B9F01-EBA5-4253-A7F4-CC0E0CC59F1B}.Release|Any CPU.Build.0 = Release|Any CPU
+ {0A8F9368-C66E-4F93-BE3F-001F73F963E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {0A8F9368-C66E-4F93-BE3F-001F73F963E6}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {0A8F9368-C66E-4F93-BE3F-001F73F963E6}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {0A8F9368-C66E-4F93-BE3F-001F73F963E6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{ABCD5AB6-389B-466D-96E6-B41A671B7454} = {0866D4B1-55B3-44F7-8683-61FF19EC2CFD}
- {4A88DCA2-2A9F-4497-AE84-C15B81F21782} = {0866D4B1-55B3-44F7-8683-61FF19EC2CFD}
{1EF4B421-0137-4C27-A6D2-DFC2B09E52F0} = {F323228E-200C-4069-98A1-E2400F3061B3}
+ {4A88DCA2-2A9F-4497-AE84-C15B81F21782} = {0866D4B1-55B3-44F7-8683-61FF19EC2CFD}
{A6F2F5A8-7B65-4B59-A1AF-5712E84CAE3A} = {53D4886A-6035-458C-834C-D7EDC02A0E26}
{8061897F-550F-4932-8D35-126BE3CA894C} = {53D4886A-6035-458C-834C-D7EDC02A0E26}
+ {BB41B80A-455B-40D2-98A0-6663DDB4C1FD} = {F323228E-200C-4069-98A1-E2400F3061B3}
+ {7E3B9F01-EBA5-4253-A7F4-CC0E0CC59F1B} = {F323228E-200C-4069-98A1-E2400F3061B3}
+ {0A8F9368-C66E-4F93-BE3F-001F73F963E6} = {F323228E-200C-4069-98A1-E2400F3061B3}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {339DAF44-AC08-4D3B-BB34-6DA417E800E7}
diff --git a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System.Private.Runtime.InteropServices.JavaScript.csproj b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System.Private.Runtime.InteropServices.JavaScript.csproj
index 2ac3e51dd2a..af10e0fd5fd 100644
--- a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System.Private.Runtime.InteropServices.JavaScript.csproj
+++ b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System.Private.Runtime.InteropServices.JavaScript.csproj
@@ -13,22 +13,9 @@
<Compile Include="System\Runtime\InteropServices\JavaScript\JSException.cs" />
<Compile Include="System\Runtime\InteropServices\JavaScript\JSObject.cs" />
<Compile Include="System\Runtime\InteropServices\JavaScript\DataView.cs" />
- <Compile Include="System\Runtime\InteropServices\JavaScript\Float32Array.cs" />
- <Compile Include="System\Runtime\InteropServices\JavaScript\Float64Array.cs" />
- <Compile Include="System\Runtime\InteropServices\JavaScript\Int8Array.cs" />
- <Compile Include="System\Runtime\InteropServices\JavaScript\Int16Array.cs" />
- <Compile Include="System\Runtime\InteropServices\JavaScript\Int32Array.cs" />
<Compile Include="System\Runtime\InteropServices\JavaScript\Uint8Array.cs" />
- <Compile Include="System\Runtime\InteropServices\JavaScript\Uint16Array.cs" />
- <Compile Include="System\Runtime\InteropServices\JavaScript\Uint32Array.cs" />
- <Compile Include="System\Runtime\InteropServices\JavaScript\Uint8ClampedArray.cs" />
- <Compile Include="System\Runtime\InteropServices\JavaScript\TypedArray.cs" />
<Compile Include="System\Runtime\InteropServices\JavaScript\Array.cs" />
<Compile Include="System\Runtime\InteropServices\JavaScript\ArrayBuffer.cs" />
- <Compile Include="System\Runtime\InteropServices\JavaScript\SharedArrayBuffer.cs" />
- <Compile Include="System\Runtime\InteropServices\JavaScript\Map.cs" />
- <Compile Include="System\Runtime\InteropServices\JavaScript\CoreObject.cs" />
- <Compile Include="System\Runtime\InteropServices\JavaScript\HostObject.cs" />
<Compile Include="System\Runtime\InteropServices\JavaScript\Function.cs" />
<Compile Include="System\Runtime\InteropServices\JavaScript\JSObject.References.cs" />
</ItemGroup>
diff --git a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Array.cs b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Array.cs
index cd13b0c110e..58fc899642e 100644
--- a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Array.cs
+++ b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Array.cs
@@ -1,14 +1,12 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System;
-
namespace System.Runtime.InteropServices.JavaScript
{
/// <summary>
/// Initializes a new instance of JavaScript Core Array class.
/// </summary>
- public class Array : CoreObject
+ public class Array : JSObject
{
/// <summary>
/// Initializes a new instance of the Array class.
@@ -101,5 +99,15 @@ namespace System.Runtime.InteropServices.JavaScript
}
}
+
+ /// <summary>
+ /// Gets or sets the length.
+ /// </summary>
+ /// <value>The length.</value>
+ public int Length
+ {
+ get => Convert.ToInt32(GetObjectProperty("length"));
+ set => SetObjectProperty("length", value, false);
+ }
}
}
diff --git a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/ArrayBuffer.cs b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/ArrayBuffer.cs
index 9ba3fb5d8f2..651cd7cd974 100644
--- a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/ArrayBuffer.cs
+++ b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/ArrayBuffer.cs
@@ -1,11 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System;
-
namespace System.Runtime.InteropServices.JavaScript
{
- public class ArrayBuffer : CoreObject
+ public class ArrayBuffer : JSObject
{
/// <summary>
/// Initializes a new instance of the JavaScript Core ArrayBuffer class.
diff --git a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/CoreObject.cs b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/CoreObject.cs
deleted file mode 100644
index 6a887fe66ce..00000000000
--- a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/CoreObject.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-namespace System.Runtime.InteropServices.JavaScript
-{
- /// <summary>
- /// Core objects are the standard built-in objects and functions.
- /// </summary>
- /// <remarks>
- /// These objects are part of the JavaScript environment. Not to be confused
- /// with objects provided by the host application or the browser context
- /// such as DOM. For more information about the distinction between the
- /// DOM and core JavaScript, see JavaScript technologies overview:
- /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/JavaScript_technologies_overview
- ///
- /// Core objects are treated differently in the bridge code as they are
- /// guaranteed to be there.
- /// </remarks>
- public abstract class CoreObject : JSObject
- {
- internal CoreObject(IntPtr jsHandle) : base(jsHandle)
- {
- }
-
- protected CoreObject(string typeName, params object[] _params) : base(typeName, _params)
- {
- }
- }
-}
diff --git a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/DataView.cs b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/DataView.cs
index 8023e35c4fc..30ee2b5eebe 100644
--- a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/DataView.cs
+++ b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/DataView.cs
@@ -1,15 +1,13 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System;
-
namespace System.Runtime.InteropServices.JavaScript
{
/// <summary>
/// The DataView view provides a low-level interface for reading and writing multiple number types in a
/// binary ArrayBuffer, without having to care about the platform's endianness.
/// </summary>
- public class DataView : CoreObject
+ public class DataView : JSObject
{
/// <summary>
/// Initializes a new instance of the DataView class.
@@ -38,30 +36,6 @@ namespace System.Runtime.InteropServices.JavaScript
/// <summary>
/// Initializes a new instance of the DataView class.
/// </summary>
- /// <param name="buffer">SharedArrayBuffer to use as the storage backing the new DataView object.</param>
- public DataView(SharedArrayBuffer buffer) : base(nameof(DataView), buffer)
- { }
-
- /// <summary>
- /// Initializes a new instance of the DataView class.
- /// </summary>
- /// <param name="buffer">SharedArrayBuffer to use as the storage backing the new DataView object.</param>
- /// <param name="byteOffset">The offset, in bytes, to the first byte in the above buffer for the new view to reference. If unspecified, the buffer view starts with the first byte.</param>
- public DataView(SharedArrayBuffer buffer, int byteOffset) : base(nameof(DataView), buffer, byteOffset)
- { }
-
- /// <summary>
- /// Initializes a new instance of the DataView class.
- /// </summary>
- /// <param name="buffer">SharedArrayBuffer to use as the storage backing the new DataView object.</param>
- /// <param name="byteOffset">The offset, in bytes, to the first byte in the above buffer for the new view to reference. If unspecified, the buffer view starts with the first byte.</param>
- /// <param name="byteLength">The number of elements in the byte array. If unspecified, the view's length will match the buffer's length.</param>
- public DataView(SharedArrayBuffer buffer, int byteOffset, int byteLength) : base(nameof(DataView), buffer, byteOffset, byteLength)
- { }
-
- /// <summary>
- /// Initializes a new instance of the DataView class.
- /// </summary>
/// <param name="jsHandle">Js handle.</param>
internal DataView(IntPtr jsHandle) : base(jsHandle)
{ }
diff --git a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Float32Array.cs b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Float32Array.cs
deleted file mode 100644
index 2549df601e9..00000000000
--- a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Float32Array.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System;
-
-namespace System.Runtime.InteropServices.JavaScript
-{
- public sealed class Float32Array : TypedArray<Float32Array, float>
- {
- public Float32Array() { }
-
- public Float32Array(int length) : base(length) { }
-
- public Float32Array(ArrayBuffer buffer) : base(buffer) { }
-
- public Float32Array(ArrayBuffer buffer, int byteOffset) : base(buffer, byteOffset) { }
-
- public Float32Array(ArrayBuffer buffer, int byteOffset, int length) : base(buffer, byteOffset, length) { }
-
- public Float32Array(SharedArrayBuffer buffer) : base(buffer) { }
-
- public Float32Array(SharedArrayBuffer buffer, int byteOffset) : base(buffer, byteOffset) { }
-
- public Float32Array(SharedArrayBuffer buffer, int byteOffset, int length) : base(buffer, byteOffset, length) { }
-
- internal Float32Array(IntPtr jsHandle) : base(jsHandle)
- { }
-
- /// <summary>
- /// Defines an implicit conversion of Float32Array class to a float
- /// </summary>
- public static implicit operator Span<float>(Float32Array typedarray) => typedarray.ToArray();
-
- /// <summary>
- /// Defines an implicit conversion of float to a Float32Array class.
- /// </summary>
- public static implicit operator Float32Array(Span<float> span) => From(span);
- }
-}
diff --git a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Float64Array.cs b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Float64Array.cs
deleted file mode 100644
index e0aa9c5f5e8..00000000000
--- a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Float64Array.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System;
-
-namespace System.Runtime.InteropServices.JavaScript
-{
- public sealed class Float64Array : TypedArray<Float64Array, double>
- {
- public Float64Array() { }
-
- public Float64Array(int length) : base(length) { }
-
- public Float64Array(ArrayBuffer buffer) : base(buffer) { }
-
- public Float64Array(ArrayBuffer buffer, int byteOffset) : base(buffer, byteOffset) { }
-
- public Float64Array(ArrayBuffer buffer, int byteOffset, int length) : base(buffer, byteOffset, length) { }
-
- public Float64Array(SharedArrayBuffer buffer) : base(buffer) { }
-
- public Float64Array(SharedArrayBuffer buffer, int byteOffset) : base(buffer, byteOffset) { }
-
- public Float64Array(SharedArrayBuffer buffer, int byteOffset, int length) : base(buffer, byteOffset, length) { }
-
- internal Float64Array(IntPtr jsHandle) : base(jsHandle)
- { }
-
- /// <summary>
- /// Defines an implicit conversion of Float64Array class to a double
- /// </summary>
- public static implicit operator Span<double>(Float64Array typedarray) => typedarray.ToArray();
-
- /// <summary>
- /// Defines an implicit conversion of double to a Float64Array class.
- /// </summary>
- public static implicit operator Float64Array(Span<double> span) => From(span);
- }
-}
diff --git a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Function.cs b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Function.cs
index 674a0b27b4a..65a83b6dfaf 100644
--- a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Function.cs
+++ b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Function.cs
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System;
-
namespace System.Runtime.InteropServices.JavaScript
{
/// <summary>
@@ -14,7 +12,7 @@ namespace System.Runtime.InteropServices.JavaScript
/// allows executing code in the global scope, prompting better programming habits and allowing for more efficient
/// code minification.
/// </remarks>
- public class Function : CoreObject
+ public class Function : JSObject
{
public Function(params object[] args) : base(nameof(Function), args)
{ }
diff --git a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/HostObject.cs b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/HostObject.cs
deleted file mode 100644
index ac6ebf62148..00000000000
--- a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/HostObject.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System;
-
-namespace System.Runtime.InteropServices.JavaScript
-{
- /// <summary>
- /// Host objects are object supplied by the host environment.
- /// </summary>
- /// <remarks>
- /// These objects are not part of the JavaScript environment and provided by the host application
- /// or the browser context such as DOM. For more information about the distinction between the
- /// DOM and core JavaScript, see JavaScript technologies overview:
- /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/JavaScript_technologies_overview
- ///
- /// Host objects are treated differently in the bridge code as they are not guaranteed to exist.
- /// </remarks>
- public interface IHostObject
- { }
-
- public class HostObject : JSObject, IHostObject
- {
- public HostObject(string typeName, params object[] _params) : base(typeName, _params)
- { }
- }
-}
diff --git a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Int16Array.cs b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Int16Array.cs
deleted file mode 100644
index 36362263cb4..00000000000
--- a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Int16Array.cs
+++ /dev/null
@@ -1,40 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System;
-
-namespace System.Runtime.InteropServices.JavaScript
-{
- public sealed class Int16Array : TypedArray<Int16Array, short>
- {
- public Int16Array() { }
-
- public Int16Array(int length) : base(length) { }
-
- public Int16Array(ArrayBuffer buffer) : base(buffer) { }
-
- public Int16Array(ArrayBuffer buffer, int byteOffset) : base(buffer, byteOffset) { }
-
- public Int16Array(ArrayBuffer buffer, int byteOffset, int length) : base(buffer, byteOffset, length) { }
-
- public Int16Array(SharedArrayBuffer buffer) : base(buffer) { }
-
- public Int16Array(SharedArrayBuffer buffer, int byteOffset) : base(buffer, byteOffset) { }
-
- public Int16Array(SharedArrayBuffer buffer, int byteOffset, int length) : base(buffer, byteOffset, length) { }
-
- internal Int16Array(IntPtr jsHandle) : base(jsHandle)
- { }
-
- /// <summary>
- /// Defines an implicit conversion of Int16Array class to a short
- /// </summary>
- [CLSCompliant(false)]
- public static implicit operator Span<short>(Int16Array typedarray) => typedarray.ToArray();
-
- /// <summary>
- /// Defines an implicit conversion of short to a Int16Array class.
- /// </summary>
- public static implicit operator Int16Array(Span<short> span) => From(span);
- }
-}
diff --git a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Int32Array.cs b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Int32Array.cs
deleted file mode 100644
index 651fcaf5ee8..00000000000
--- a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Int32Array.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System;
-
-namespace System.Runtime.InteropServices.JavaScript
-{
- public sealed class Int32Array : TypedArray<Int32Array, int>
- {
- public Int32Array() { }
-
- public Int32Array(int length) : base(length) { }
-
- public Int32Array(ArrayBuffer buffer) : base(buffer) { }
-
- public Int32Array(ArrayBuffer buffer, int byteOffset) : base(buffer, byteOffset) { }
-
- public Int32Array(ArrayBuffer buffer, int byteOffset, int length) : base(buffer, byteOffset, length) { }
-
- public Int32Array(SharedArrayBuffer buffer) : base(buffer) { }
-
- public Int32Array(SharedArrayBuffer buffer, int byteOffset) : base(buffer, byteOffset) { }
-
- public Int32Array(SharedArrayBuffer buffer, int byteOffset, int length) : base(buffer, byteOffset, length) { }
-
- internal Int32Array(IntPtr jsHandle) : base(jsHandle)
- { }
-
- /// <summary>
- /// Defines an implicit conversion of Int32Array class to a int
- /// </summary>
- public static implicit operator Span<int>(Int32Array typedarray) => typedarray.ToArray();
-
- /// <summary>
- /// Defines an implicit conversion of int to a Int32Array class.
- /// </summary>
- public static implicit operator Int32Array(Span<int> span) => From(span);
- }
-}
diff --git a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Int8Array.cs b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Int8Array.cs
deleted file mode 100644
index 9f0037208a8..00000000000
--- a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Int8Array.cs
+++ /dev/null
@@ -1,50 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System;
-
-namespace System.Runtime.InteropServices.JavaScript
-{
- [CLSCompliant(false)]
- public sealed class Int8Array : TypedArray<Int8Array, sbyte>
- {
- public Int8Array()
- { }
-
- public Int8Array(int length) : base(length)
- { }
-
- public Int8Array(ArrayBuffer buffer) : base(buffer)
- { }
-
- public Int8Array(ArrayBuffer buffer, int byteOffset) : base(buffer, byteOffset)
- { }
-
- public Int8Array(ArrayBuffer buffer, int byteOffset, int length) : base(buffer, byteOffset, length)
- { }
-
- public Int8Array(SharedArrayBuffer buffer) : base(buffer)
- { }
-
- public Int8Array(SharedArrayBuffer buffer, int byteOffset) : base(buffer, byteOffset)
- { }
-
- public Int8Array(SharedArrayBuffer buffer, int byteOffset, int length) : base(buffer, byteOffset, length)
- { }
-
- internal Int8Array(IntPtr jsHandle) : base(jsHandle)
- { }
-
- /// <summary>
- /// Defines an implicit conversion of Int8Array class to a sbyte
- /// </summary>
- [CLSCompliant(false)]
- public static implicit operator Span<sbyte>(Int8Array typedarray) => typedarray.ToArray();
-
- /// <summary>
- /// Defines an implicit conversion of sbyte to a Int8Array class.
- /// </summary>
- [CLSCompliant(false)]
- public static implicit operator Int8Array(Span<sbyte> span) => From(span);
- }
-}
diff --git a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSException.cs b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSException.cs
index 7fa68522f9d..b87b67fe689 100644
--- a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSException.cs
+++ b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSException.cs
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System;
-
namespace System.Runtime.InteropServices.JavaScript
{
/// <summary>
diff --git a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSObject.References.cs b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSObject.References.cs
index d31f1543ce7..60e8b539899 100644
--- a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSObject.References.cs
+++ b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSObject.References.cs
@@ -12,7 +12,7 @@ namespace System.Runtime.InteropServices.JavaScript
{
private GCHandle? InFlight;
private int InFlightCounter;
- public int JSHandle => (int)handle;
+ public IntPtr JSHandle => handle;
public bool IsDisposed { get; private set; }
public JSObject() : base(true)
@@ -24,7 +24,7 @@ namespace System.Runtime.InteropServices.JavaScript
SetHandle(jsHandle);
}
- protected JSObject(string typeName, object[] _params) : base(true)
+ public JSObject(string typeName, params object[] _params) : base(true)
{
InFlight = null;
InFlightCounter = 0;
@@ -100,7 +100,7 @@ namespace System.Runtime.InteropServices.JavaScript
public override bool Equals([NotNullWhen(true)] object? obj) => obj is JSObject other && JSHandle == other.JSHandle;
- public override int GetHashCode() => JSHandle;
+ public override int GetHashCode() => (int)JSHandle;
public override string ToString()
{
diff --git a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSObject.cs b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSObject.cs
index 33588095b31..f85fbccfa7b 100644
--- a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSObject.cs
+++ b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSObject.cs
@@ -3,17 +3,11 @@
namespace System.Runtime.InteropServices.JavaScript
{
- public interface IJSObject
- {
- int JSHandle { get; }
- int Length { get; }
- }
-
/// <summary>
/// JSObjects are wrappers for a native JavaScript object, and
/// they retain a reference to the JavaScript object for the lifetime of this C# object.
/// </summary>
- public partial class JSObject : IJSObject, IDisposable
+ public partial class JSObject : IDisposable
{
/// <summary>
/// Invoke a named method of the object, or throws a JSException on error.
@@ -45,67 +39,6 @@ namespace System.Runtime.InteropServices.JavaScript
return res;
}
- public struct EventListenerOptions {
- public bool Capture;
- public bool Once;
- public bool Passive;
- public object? Signal;
- }
-
- public int AddEventListener(string name, Action<JSObject> listener, EventListenerOptions? options = null)
- {
- AssertNotDisposed();
-
- var optionsDict = options.HasValue
- ? new JSObject()
- : null;
-
- try {
- if (options?.Signal != null)
- throw new NotImplementedException("EventListenerOptions.Signal");
-
- var jsfunc = Runtime.GetJSOwnedObjectGCHandle(listener);
- // int exception;
- if (options.HasValue) {
- // TODO: Optimize this
- var _options = options.Value;
- optionsDict?.SetObjectProperty("capture", _options.Capture, true, true);
- optionsDict?.SetObjectProperty("once", _options.Once, true, true);
- optionsDict?.SetObjectProperty("passive", _options.Passive, true, true);
- }
-
- // TODO: Pass options explicitly instead of using the object
- // TODO: Handle errors
- // We can't currently do this because adding any additional parameters or a return value causes
- // a signature mismatch at runtime
- var ret = Interop.Runtime.AddEventListener(JSHandle, name, jsfunc, optionsDict?.JSHandle ?? 0);
- if (ret != null)
- throw new JSException(ret);
- return jsfunc;
- } finally {
- optionsDict?.Dispose();
- }
- }
-
- public void RemoveEventListener(string name, Action<JSObject>? listener, EventListenerOptions? options = null)
- {
- AssertNotDisposed();
-
- if (listener == null)
- return;
- var jsfunc = Runtime.GetJSOwnedObjectGCHandle(listener);
- RemoveEventListener(name, jsfunc, options);
- }
-
- public void RemoveEventListener(string name, int listenerGCHandle, EventListenerOptions? options = null)
- {
- AssertNotDisposed();
-
- var ret = Interop.Runtime.RemoveEventListener(JSHandle, name, listenerGCHandle, options?.Capture ?? false);
- if (ret != null)
- throw new JSException(ret);
- }
-
/// <summary>
/// Returns the named property from the object, or throws a JSException on error.
/// </summary>
@@ -160,16 +93,6 @@ namespace System.Runtime.InteropServices.JavaScript
}
/// <summary>
- /// Gets or sets the length.
- /// </summary>
- /// <value>The length.</value>
- public int Length
- {
- get => Convert.ToInt32(GetObjectProperty("length"));
- set => SetObjectProperty("length", value, false);
- }
-
- /// <summary>
/// Returns a boolean indicating whether the object has the specified property as its own property (as opposed to inheriting it).
/// </summary>
/// <returns><c>true</c>, if the object has the specified property as own property, <c>false</c> otherwise.</returns>
diff --git a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Map.cs b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Map.cs
deleted file mode 100644
index 4de1e1febc0..00000000000
--- a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Map.cs
+++ /dev/null
@@ -1,256 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System.Collections;
-
-namespace System.Runtime.InteropServices.JavaScript
-{
- /// <summary>
- /// The Map object holds key-value pairs and remembers the original insertion order of the keys.
- /// Any value (both objects and primitive values) may be used as either a key or a value.
- /// </summary>
- public class Map : CoreObject, IDictionary
- {
- /// <summary>
- /// Initializes a new instance of the Map class.
- /// </summary>
- public Map() : base(nameof(Map))
- { }
-
- /// <summary>
- /// Initializes a new instance of the Map class.
- /// </summary>
- /// <param name="jsHandle">Js handle.</param>
- internal Map(IntPtr jsHandle) : base(jsHandle)
- { }
-
- /// <summary>
- /// Gets a value indicating whether the Map object has a fixed size.
- /// </summary>
- public bool IsFixedSize => false;
-
- /// <summary>
- /// Gets a value indicating whether the Map object is read-only.
- /// </summary>
- public bool IsReadOnly => false;
-
- /// <summary>
- /// Gets an System.Collections.ICollection object containing the keys of the Map object.
- /// </summary>
- public ICollection Keys => new MapItemCollection(this, "keys");
-
- /// <summary>
- /// Gets an System.Collections.ICollection object containing the values of the Map object.
- /// </summary>
- public ICollection Values => new MapItemCollection(this, "values");
-
- public int Count => (int)GetObjectProperty("size");
-
- public bool IsSynchronized => false;
-
- public object SyncRoot => false;
-
- public void Add(object key, object? value) => Invoke("set", key, value);
-
- public void Clear() => Invoke("clear");
-
- public bool Contains(object key) => (bool)Invoke("has", key);
-
- public IDictionaryEnumerator GetEnumerator() => new MapEnumerator(this);
-
- public void Remove(object key) => Invoke("delete", key);
-
- public void CopyTo(System.Array array, int index) => throw new NotImplementedException();
-
- // Construct and return an enumerator.
- IEnumerator IEnumerable.GetEnumerator() => new MapEnumerator(this);
-
- /// <summary>
- /// Gets or sets the Map with the key specified by <paramref name="key" />.
- /// </summary>
- /// <param name="key">The key.</param>
- public object? this[object key]
- {
- get
- {
- return Invoke("get", key);
- }
- set
- {
- Invoke("set", key, value);
- }
- }
-
- private sealed class MapEnumerator : IDictionaryEnumerator, IDisposable
- {
- private JSObject? _mapIterator;
- private readonly Map _map;
- public MapEnumerator(Map map)
- {
- _map = map;
- }
-
- // Return the current item.
- public object Current => new DictionaryEntry(Key, Value);
-
- // Return the current dictionary entry.
- public DictionaryEntry Entry => (DictionaryEntry)Current;
-
- // Return the key of the current item.
- public object Key { get; private set; } = new object();
-
- // Return the value of the current item.
- public object? Value { get; private set; }
-
- // Advance to the next item.
- public bool MoveNext()
- {
- if (_mapIterator == null)
- _mapIterator = (JSObject)_map.Invoke("entries");
-
- using (var result = (JSObject)_mapIterator.Invoke("next"))
- {
- using (var resultValue = (Array)result.GetObjectProperty("value"))
- {
- if (resultValue != null)
- {
- Key = resultValue[0];
- Value = resultValue[1];
- }
- else
- {
- Value = null;
- }
- }
- return !(bool)result.GetObjectProperty("done");
- }
- }
-
- // Reset the index to restart the enumeration.
- public void Reset()
- {
- _mapIterator?.Dispose();
- _mapIterator = null;
- }
-
- #region IDisposable Support
- private bool _disposedValue; // To detect redundant calls
-
- private void Dispose(bool disposing)
- {
- if (!_disposedValue)
- {
- _mapIterator?.Dispose();
- _mapIterator = null;
- _disposedValue = true;
- }
- }
-
- ~MapEnumerator()
- {
- // Do not change this code. Put cleanup code in Dispose(bool disposing) above.
- Dispose(false);
- }
-
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
- #endregion
- }
-
- /// <summary>
- /// Class that implements an ICollection over the "keys" or "values"
- /// </summary>
- private sealed class MapItemCollection : ICollection
- {
- private readonly Map _map;
- private readonly string _iterator; // "keys" or "values"
-
- public MapItemCollection(Map map, string iterator)
- {
- _map = map;
- _iterator = iterator;
-
- }
- public int Count => _map.Count;
-
- public bool IsSynchronized => false;
-
- public object SyncRoot => this;
-
- public void CopyTo(System.Array array, int index) => throw new NotImplementedException();
-
- // Construct and return an enumerator.
- public IEnumerator GetEnumerator() => new MapItemEnumerator(this);
-
- /// <summary>
- /// The custom enumerator used by MapItemCollection
- /// </summary>
- private sealed class MapItemEnumerator : IEnumerator
- {
-
- private readonly MapItemCollection _mapItemCollection;
- private JSObject? _mapItemIterator;
-
- public object? Current { get; private set; }
-
- public MapItemEnumerator(MapItemCollection mapCollection)
- {
- _mapItemCollection = mapCollection;
- }
-
- public bool MoveNext()
- {
- if (_mapItemIterator == null)
- _mapItemIterator = (JSObject)_mapItemCollection._map.Invoke(_mapItemCollection._iterator);
-
- using (var result = (JSObject)_mapItemIterator.Invoke("next"))
- {
- bool done = (bool)result.GetObjectProperty("done");
- if (!done)
- Current = result.GetObjectProperty("value");
- return !done;
- }
- }
-
- public void Reset()
- {
- _mapItemIterator?.Dispose();
- _mapItemIterator = null;
- }
-
- #region IDisposable Support
- private bool _disposedValue; // To detect redundant calls
-
- private void Dispose(bool disposing)
- {
- if (!_disposedValue)
- {
-
- _mapItemIterator?.Dispose();
- _mapItemIterator = null;
- _disposedValue = true;
- }
- }
-
- ~MapItemEnumerator()
- {
- // Do not change this code. Put cleanup code in Dispose(bool disposing) above.
- Dispose(false);
- }
-
- // This code added to correctly implement the disposable pattern.
- public void Dispose()
- {
- // Do not change this code. Put cleanup code in Dispose(bool disposing) above.
- Dispose(true);
- // TODO: uncomment the following line if the finalizer is overridden above.
- GC.SuppressFinalize(this);
- }
- #endregion
- }
- }
- }
-}
diff --git a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Runtime.CS.Owned.cs b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Runtime.CS.Owned.cs
index 370525c935a..4d285bdc4c5 100644
--- a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Runtime.CS.Owned.cs
+++ b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Runtime.CS.Owned.cs
@@ -9,11 +9,11 @@ namespace System.Runtime.InteropServices.JavaScript
{
private static readonly Dictionary<int, WeakReference<JSObject>> _csOwnedObjects = new Dictionary<int, WeakReference<JSObject>>();
- public static JSObject? GetCSOwnedObjectByJSHandle(int jsHandle, int shouldAddInflight)
+ public static JSObject? GetCSOwnedObjectByJSHandle(IntPtr jsHandle, int shouldAddInflight)
{
lock (_csOwnedObjects)
{
- if (_csOwnedObjects.TryGetValue(jsHandle, out WeakReference<JSObject>? reference))
+ if (_csOwnedObjects.TryGetValue((int)jsHandle, out WeakReference<JSObject>? reference))
{
reference.TryGetTarget(out JSObject? jsObject);
if (shouldAddInflight != 0 && jsObject != null)
@@ -27,17 +27,17 @@ namespace System.Runtime.InteropServices.JavaScript
}
- public static int TryGetCSOwnedObjectJSHandle(object rawObj, int shouldAddInflight)
+ public static IntPtr TryGetCSOwnedObjectJSHandle(object rawObj, int shouldAddInflight)
{
JSObject? jsObject = rawObj as JSObject;
if (jsObject != null && shouldAddInflight != 0)
{
jsObject.AddInFlight();
}
- return jsObject?.JSHandle ?? 0;
+ return jsObject?.JSHandle ?? IntPtr.Zero;
}
- public static int GetCSOwnedObjectJSHandle(JSObject jsObject, int shouldAddInflight)
+ public static IntPtr GetCSOwnedObjectJSHandle(JSObject jsObject, int shouldAddInflight)
{
jsObject.AssertNotDisposed();
@@ -65,17 +65,7 @@ namespace System.Runtime.InteropServices.JavaScript
MappedType.ArrayBuffer => new ArrayBuffer(jsHandle),
MappedType.DataView => new DataView(jsHandle),
MappedType.Function => new Function(jsHandle),
- MappedType.Map => new Map(jsHandle),
- MappedType.SharedArrayBuffer => new SharedArrayBuffer(jsHandle),
- MappedType.Int8Array => new Int8Array(jsHandle),
MappedType.Uint8Array => new Uint8Array(jsHandle),
- MappedType.Uint8ClampedArray => new Uint8ClampedArray(jsHandle),
- MappedType.Int16Array => new Int16Array(jsHandle),
- MappedType.Uint16Array => new Uint16Array(jsHandle),
- MappedType.Int32Array => new Int32Array(jsHandle),
- MappedType.Uint32Array => new Uint32Array(jsHandle),
- MappedType.Float32Array => new Float32Array(jsHandle),
- MappedType.Float64Array => new Float64Array(jsHandle),
_ => throw new ArgumentOutOfRangeException(nameof(mappedType))
};
_csOwnedObjects[(int)jsHandle] = new WeakReference<JSObject>(jsObject, trackResurrection: true);
@@ -97,7 +87,7 @@ namespace System.Runtime.InteropServices.JavaScript
lock (_csOwnedObjects)
{
- _csOwnedObjects.Remove(objToRelease.JSHandle);
+ _csOwnedObjects.Remove((int)objToRelease.JSHandle);
Interop.Runtime.ReleaseCSOwnedObject(objToRelease.JSHandle);
}
return true;
@@ -106,14 +96,15 @@ namespace System.Runtime.InteropServices.JavaScript
internal static IntPtr CreateCSOwnedObject(JSObject proxy, string typeName, params object[] parms)
{
object res = Interop.Runtime.CreateCSOwnedObject(typeName, parms, out int exception);
+
if (exception != 0)
throw new JSException((string)res);
- var jsHandle = (int)res;
+ var jsHandle = (IntPtr)(int)res;
lock (_csOwnedObjects)
{
- _csOwnedObjects[jsHandle] = new WeakReference<JSObject>(proxy, trackResurrection: true);
+ _csOwnedObjects[(int)jsHandle] = new WeakReference<JSObject>(proxy, trackResurrection: true);
}
return (IntPtr)jsHandle;
@@ -130,17 +121,7 @@ namespace System.Runtime.InteropServices.JavaScript
ArrayBuffer = 2,
DataView = 3,
Function = 4,
- Map = 5,
- SharedArrayBuffer = 6,
- Int8Array = 10,
Uint8Array = 11,
- Uint8ClampedArray = 12,
- Int16Array = 13,
- Uint16Array = 14,
- Int32Array = 15,
- Uint32Array = 16,
- Float32Array = 17,
- Float64Array = 18,
}
}
}
diff --git a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Runtime.JS.Owned.cs b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Runtime.JS.Owned.cs
index d91fd2407a8..b1383e66b20 100644
--- a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Runtime.JS.Owned.cs
+++ b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Runtime.JS.Owned.cs
@@ -10,7 +10,7 @@ namespace System.Runtime.InteropServices.JavaScript
{
private static object JSOwnedObjectLock = new object();
// we use this to maintain identity of GCHandle for a managed object
- private static Dictionary<object, int> GCHandleFromJSOwnedObject = new Dictionary<object, int>();
+ private static Dictionary<object, IntPtr> GCHandleFromJSOwnedObject = new Dictionary<object, IntPtr>(ReferenceEqualityComparer.Instance);
public static object GetJSOwnedObjectByGCHandle(int gcHandle)
@@ -26,18 +26,18 @@ namespace System.Runtime.InteropServices.JavaScript
// strong references, allowing the managed object to be collected.
// This ensures that things like delegates and promises will never 'go away' while JS
// is expecting to be able to invoke or await them.
- public static int GetJSOwnedObjectGCHandle(object obj)
+ public static IntPtr GetJSOwnedObjectGCHandle(object obj)
{
if (obj == null)
- return 0;
+ return IntPtr.Zero;
- int result;
+ IntPtr result;
lock (JSOwnedObjectLock)
{
if (GCHandleFromJSOwnedObject.TryGetValue(obj, out result))
return result;
- result = (int)(IntPtr)GCHandle.Alloc(obj, GCHandleType.Normal);
+ result = (IntPtr)GCHandle.Alloc(obj, GCHandleType.Normal);
GCHandleFromJSOwnedObject[obj] = result;
return result;
}
@@ -55,7 +55,7 @@ namespace System.Runtime.InteropServices.JavaScript
}
}
- public static int CreateTaskSource()
+ public static IntPtr CreateTaskSource()
{
var tcs = new TaskCompletionSource<object>();
return GetJSOwnedObjectGCHandle(tcs);
diff --git a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Runtime.cs b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Runtime.cs
index 9de855fd4b5..2509220b8f0 100644
--- a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Runtime.cs
+++ b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Runtime.cs
@@ -323,16 +323,16 @@ namespace System.Runtime.InteropServices.JavaScript
return new Uri(uri);
}
- public static void CancelPromise(int promiseJSHandle)
+ public static void CancelPromise(IntPtr promiseJSHandle)
{
var res = Interop.Runtime.CancelPromise(promiseJSHandle, out int exception);
if (exception != 0)
throw new JSException(res);
}
- public static Task<object> WebSocketOpen(string uri, object[]? subProtocols, Delegate onClosed, out JSObject webSocket, out int promiseJSHandle)
+ public static Task<object> WebSocketOpen(string uri, object[]? subProtocols, Delegate onClosed, out JSObject webSocket, out IntPtr promiseJSHandle)
{
- var res = Interop.Runtime.WebSocketOpen(uri, subProtocols, onClosed, out int webSocketJSHandle, out promiseJSHandle, out int exception);
+ var res = Interop.Runtime.WebSocketOpen(uri, subProtocols, onClosed, out IntPtr webSocketJSHandle, out promiseJSHandle, out int exception);
if (exception != 0)
throw new JSException((string)res);
webSocket = new JSObject((IntPtr)webSocketJSHandle);
@@ -340,7 +340,7 @@ namespace System.Runtime.InteropServices.JavaScript
return (Task<object>)res;
}
- public static unsafe Task<object>? WebSocketSend(JSObject webSocket, ArraySegment<byte> buffer, int messageType, bool endOfMessage, out int promiseJSHandle)
+ public static unsafe Task<object>? WebSocketSend(JSObject webSocket, ArraySegment<byte> buffer, int messageType, bool endOfMessage, out IntPtr promiseJSHandle)
{
fixed (byte* messagePtr = buffer.Array)
{
@@ -357,7 +357,7 @@ namespace System.Runtime.InteropServices.JavaScript
}
}
- public static unsafe Task<object>? WebSocketReceive(JSObject webSocket, ArraySegment<byte> buffer, ReadOnlySpan<int> response, out int promiseJSHandle)
+ public static unsafe Task<object>? WebSocketReceive(JSObject webSocket, ArraySegment<byte> buffer, ReadOnlySpan<int> response, out IntPtr promiseJSHandle)
{
fixed (int* responsePtr = response)
fixed (byte* bufferPtr = buffer.Array)
@@ -373,7 +373,7 @@ namespace System.Runtime.InteropServices.JavaScript
}
}
- public static Task<object>? WebSocketClose(JSObject webSocket, int code, string? reason, bool waitForCloseReceived, out int promiseJSHandle)
+ public static Task<object>? WebSocketClose(JSObject webSocket, int code, string? reason, bool waitForCloseReceived, out IntPtr promiseJSHandle)
{
var res = Interop.Runtime.WebSocketClose(webSocket.JSHandle, code, reason, waitForCloseReceived, out promiseJSHandle, out int exception);
if (exception != 0)
diff --git a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/SharedArrayBuffer.cs b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/SharedArrayBuffer.cs
deleted file mode 100644
index 6abcb9864c2..00000000000
--- a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/SharedArrayBuffer.cs
+++ /dev/null
@@ -1,51 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System;
-
-namespace System.Runtime.InteropServices.JavaScript
-{
- public class SharedArrayBuffer : CoreObject
- {
- /// <summary>
- /// Initializes a new instance of the JavaScript Core SharedArrayBuffer class.
- /// </summary>
- /// <param name="length">The size, in bytes, of the array buffer to create.</param>
- public SharedArrayBuffer(int length) : base(nameof(SharedArrayBuffer), length)
- { }
-
- internal SharedArrayBuffer(IntPtr jsHandle) : base(jsHandle)
- { }
-
- /// <summary>
- /// The size, in bytes, of the array. This is established when the array is constructed and cannot be changed.
- /// </summary>
- /// <value>The size, in bytes, of the array.</value>
- public int ByteLength => (int)GetObjectProperty("byteLength");
-
- /// <summary>
- /// Returns a new JavaScript Core SharedArrayBuffer whose contents are a copy of this SharedArrayBuffer's bytes.
- /// </summary>
- /// <returns>a new JavaScript Core SharedArrayBuffer</returns>
- public SharedArrayBuffer Slice() => (SharedArrayBuffer)Invoke("slice");
-
- /// <summary>
- /// Returns a new JavaScript Core SharedArrayBuffer whose contents are a copy of this SharedArrayBuffer's bytes from begin,
- /// inclusive, through to the end of the sequence, exclusive. If begin is negative, it refers to an index from the end
- /// of the array, as opposed to from the beginning.
- /// </summary>
- /// <returns>a new JavaScript Core SharedArrayBuffer</returns>
- /// <param name="begin">Beginning index of copy zero based.</param>
- public SharedArrayBuffer Slice(int begin) => (SharedArrayBuffer)Invoke("slice", begin);
-
- /// <summary>
- /// Returns a new JavaScript Core SharedArrayBuffer whose contents are a copy of this SharedArrayBuffer's bytes from begin,
- /// inclusive, up to end, exclusive. If either begin or end is negative, it refers to an index from the end
- /// of the array, as opposed to from the beginning.
- /// </summary>
- /// <returns>a new JavaScript Core SharedArrayBuffer</returns>
- /// <param name="begin">Beginning index of copy.</param>
- /// <param name="end">Ending index, exclusive.</param>
- public SharedArrayBuffer Slice(int begin, int end) => (SharedArrayBuffer)Invoke("slice", begin, end);
- }
-}
diff --git a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/TypedArray.cs b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/TypedArray.cs
deleted file mode 100644
index 6a45c28216a..00000000000
--- a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/TypedArray.cs
+++ /dev/null
@@ -1,235 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System.Runtime.CompilerServices;
-
-namespace System.Runtime.InteropServices.JavaScript
-{
- public interface ITypedArray
- {
- int BytesPerElement { get; }
- string Name { get; }
- int ByteLength { get; }
- ArrayBuffer Buffer { get; }
-
- void Set(Array array);
- void Set(Array array, int offset);
-
- void Set(ITypedArray typedArray);
- void Set(ITypedArray typedArray, int offset);
- TypedArrayTypeCode GetTypedArrayType();
- }
-
- public interface ITypedArray<T, U> where U : struct
- {
- T Slice();
- T Slice(int begin);
- T Slice(int begin, int end);
-
- T SubArray();
- T SubArray(int begin);
- T SubArray(int begin, int end);
- }
-
- public enum TypedArrayTypeCode
- {
- Int8Array = 5,
- Uint8Array = 6,
- Int16Array = 7,
- Uint16Array = 8,
- Int32Array = 9,
- Uint32Array = 10,
- Float32Array = 13,
- Float64Array = 14,
- Uint8ClampedArray = 0xF,
- }
-
- /// <summary>
- /// Represents a JavaScript TypedArray.
- /// </summary>
- public abstract class TypedArray<T, U> : CoreObject, ITypedArray, ITypedArray<T, U>
- where U : struct
- where T: JSObject
- {
- protected TypedArray() : base(typeof(T).Name)
- { }
-
- protected TypedArray(int length) : base(typeof(T).Name, length)
- { }
-
- protected TypedArray(ArrayBuffer buffer) : base(typeof(T).Name, buffer)
- { }
-
- protected TypedArray(ArrayBuffer buffer, int byteOffset) : base(typeof(T).Name, buffer, byteOffset)
- { }
-
- protected TypedArray(ArrayBuffer buffer, int byteOffset, int length) : base(typeof(T).Name, buffer, byteOffset, length)
- { }
-
- protected TypedArray(SharedArrayBuffer buffer) : base(typeof(T).Name, buffer)
- { }
-
- protected TypedArray(SharedArrayBuffer buffer, int byteOffset) : base(typeof(T).Name, buffer, byteOffset)
- { }
-
- protected TypedArray(SharedArrayBuffer buffer, int byteOffset, int length) : base(typeof(T).Name, buffer, byteOffset, length)
- { }
-
- internal TypedArray(IntPtr jsHandle) : base(jsHandle)
- { }
-
- public TypedArrayTypeCode GetTypedArrayType()
- {
- switch (this)
- {
- case Int8Array _:
- return TypedArrayTypeCode.Int8Array;
- case Uint8Array _:
- return TypedArrayTypeCode.Uint8Array;
- case Uint8ClampedArray _:
- return TypedArrayTypeCode.Uint8ClampedArray;
- case Int16Array _:
- return TypedArrayTypeCode.Int16Array;
- case Uint16Array _:
- return TypedArrayTypeCode.Uint16Array;
- case Int32Array _:
- return TypedArrayTypeCode.Int32Array;
- case Uint32Array _:
- return TypedArrayTypeCode.Uint32Array;
- case Float32Array _:
- return TypedArrayTypeCode.Float32Array;
- case Float64Array _:
- return TypedArrayTypeCode.Float64Array;
- default:
- throw new ArrayTypeMismatchException(SR.TypedArrayNotCorrectType);
- }
- }
-
- public int BytesPerElement => (int)GetObjectProperty("BYTES_PER_ELEMENT");
- public string Name => (string)GetObjectProperty("name");
- public int ByteLength => (int)GetObjectProperty("byteLength");
- public ArrayBuffer Buffer => (ArrayBuffer)GetObjectProperty("buffer");
-
- public void Fill(U value) => Invoke("fill", value);
- public void Fill(U value, int start) => Invoke("fill", value, start);
- public void Fill(U value, int start, int end) => Invoke("fill", value, start, end);
-
- public void Set(Array array) => Invoke("set", array);
- public void Set(Array array, int offset) => Invoke("set", array, offset);
- public void Set(ITypedArray typedArray) => Invoke("set", typedArray);
- public void Set(ITypedArray typedArray, int offset) => Invoke("set", typedArray, offset);
-
- public T Slice() => (T)Invoke("slice");
- public T Slice(int begin) => (T)Invoke("slice", begin);
- public T Slice(int begin, int end) => (T)Invoke("slice", begin, end);
-
- public T SubArray() => (T)Invoke("subarray");
- public T SubArray(int begin) => (T)Invoke("subarray", begin);
- public T SubArray(int begin, int end) => (T)Invoke("subarray", begin, end);
-
- public U? this[int i]
- {
- get
- {
- AssertNotDisposed();
-
- object jsValue = Interop.Runtime.GetByIndex(JSHandle, i, out int exception);
-
- if (exception != 0)
- throw new JSException((string)jsValue);
-
- // The value returned from the index.
- return UnBoxValue(jsValue);
- }
- set
- {
- AssertNotDisposed();
-
- object res = Interop.Runtime.SetByIndex(JSHandle, i, value, out int exception);
-
- if (exception != 0)
- throw new JSException((string)res);
-
- }
- }
-
- private U? UnBoxValue(object jsValue)
- {
- if (jsValue == null)
- return null;
-
- return (U)Convert.ChangeType(jsValue, typeof(U));
- }
-
- public U[] ToArray()
- {
- AssertNotDisposed();
-
- object res = Interop.Runtime.TypedArrayToArray(JSHandle, out int exception);
-
- if (exception != 0)
- throw new JSException((string)res);
- return (U[])res;
- }
-
- public static unsafe T From(ReadOnlySpan<U> span)
- {
- // source has to be instantiated.
- if (span == null)
- {
- throw new System.ArgumentException(SR.Format(SR.ArgumentCannotBeNull, nameof(span)));
- }
-
- TypedArrayTypeCode type = (TypedArrayTypeCode)Type.GetTypeCode(typeof(U));
- // Special case for Uint8ClampedArray, a clamped array which represents an array of 8-bit unsigned integers clamped to 0-255;
- if (type == TypedArrayTypeCode.Uint8Array && typeof(T) == typeof(Uint8ClampedArray))
- type = TypedArrayTypeCode.Uint8ClampedArray; // This is only passed to the JavaScript side so it knows it will be a Uint8ClampedArray
-
- ReadOnlySpan<byte> bytes = MemoryMarshal.AsBytes(span);
- fixed (byte* ptr = bytes)
- {
- object res = Interop.Runtime.TypedArrayFrom((int)ptr, 0, span.Length, Unsafe.SizeOf<U>(), (int)type, out int exception);
- if (exception != 0)
- throw new JSException((string)res);
- var r = (T)res;
- r.ReleaseInFlight();
- return r;
- }
-
- }
-
- public unsafe int CopyTo(Span<U> span)
- {
- AssertNotDisposed();
-
- ReadOnlySpan<byte> bytes = MemoryMarshal.AsBytes(span);
- fixed (byte* ptr = bytes)
- {
- object res = Interop.Runtime.TypedArrayCopyTo(JSHandle, (int)ptr, 0, span.Length, Unsafe.SizeOf<U>(), out int exception);
- if (exception != 0)
- throw new JSException((string)res);
- return (int)res / Unsafe.SizeOf<U>();
- }
- }
-
- public unsafe int CopyFrom(ReadOnlySpan<U> span)
- {
- AssertNotDisposed();
-
- // source has to be instantiated.
- if (span == null || span.Length == 0)
- {
- throw new System.ArgumentException(SR.Format(SR.ArgumentCannotBeNullWithLength, nameof(span)));
- }
-
- ReadOnlySpan<byte> bytes = MemoryMarshal.AsBytes(span);
- fixed (byte* ptr = bytes)
- {
- object res = Interop.Runtime.TypedArrayCopyFrom(JSHandle, (int)ptr, 0, span.Length, Unsafe.SizeOf<U>(), out int exception);
- if (exception != 0)
- throw new JSException((string)res);
- return (int)res / Unsafe.SizeOf<U>();
- }
- }
- }
-}
diff --git a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Uint16Array.cs b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Uint16Array.cs
deleted file mode 100644
index 53a2379a573..00000000000
--- a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Uint16Array.cs
+++ /dev/null
@@ -1,40 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System;
-
-namespace System.Runtime.InteropServices.JavaScript
-{
- [CLSCompliant(false)]
- public sealed class Uint16Array : TypedArray<Uint16Array, ushort>
- {
- public Uint16Array() { }
-
- public Uint16Array(int length) : base(length) { }
-
- public Uint16Array(ArrayBuffer buffer) : base(buffer) { }
-
- public Uint16Array(ArrayBuffer buffer, int byteOffset) : base(buffer, byteOffset) { }
-
- public Uint16Array(ArrayBuffer buffer, int byteOffset, int length) : base(buffer, byteOffset, length) { }
-
- public Uint16Array(SharedArrayBuffer buffer) : base(buffer) { }
-
- public Uint16Array(SharedArrayBuffer buffer, int byteOffset) : base(buffer, byteOffset) { }
-
- public Uint16Array(SharedArrayBuffer buffer, int byteOffset, int length) : base(buffer, byteOffset, length) { }
-
- internal Uint16Array(IntPtr jsHandle) : base(jsHandle)
- { }
-
- /// <summary>
- /// Defines an implicit conversion of Uint16Array class to a ushort
- /// </summary>
- public static implicit operator Span<ushort>(Uint16Array typedarray) => typedarray.ToArray();
-
- /// <summary>
- /// Defines an implicit conversion of ushort to a Uint16Array class.
- /// </summary>
- public static implicit operator Uint16Array(Span<ushort> span) => From(span);
- }
-}
diff --git a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Uint32Array.cs b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Uint32Array.cs
deleted file mode 100644
index c341db5f900..00000000000
--- a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Uint32Array.cs
+++ /dev/null
@@ -1,40 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System;
-
-namespace System.Runtime.InteropServices.JavaScript
-{
- [CLSCompliant(false)]
- public sealed class Uint32Array : TypedArray<Uint32Array, uint>
- {
- public Uint32Array() { }
-
- public Uint32Array(int length) : base(length) { }
-
- public Uint32Array(ArrayBuffer buffer) : base(buffer) { }
-
- public Uint32Array(ArrayBuffer buffer, int byteOffset) : base(buffer, byteOffset) { }
-
- public Uint32Array(ArrayBuffer buffer, int byteOffset, int length) : base(buffer, byteOffset, length) { }
-
- public Uint32Array(SharedArrayBuffer buffer) : base(buffer) { }
-
- public Uint32Array(SharedArrayBuffer buffer, int byteOffset) : base(buffer, byteOffset) { }
-
- public Uint32Array(SharedArrayBuffer buffer, int byteOffset, int length) : base(buffer, byteOffset, length) { }
-
- internal Uint32Array(IntPtr jsHandle) : base(jsHandle)
- { }
-
- /// <summary>
- /// Defines an implicit conversion of Uint32Array class to a uint
- /// </summary>
- public static implicit operator Span<uint>(Uint32Array typedarray) => typedarray.ToArray();
-
- /// <summary>
- /// Defines an implicit conversion of uint to a Uint32Array class.
- /// </summary>
- public static implicit operator Uint32Array(Span<uint> span) => From(span);
- }
-}
diff --git a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Uint8Array.cs b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Uint8Array.cs
index 80089405f31..29fe0c561ee 100644
--- a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Uint8Array.cs
+++ b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Uint8Array.cs
@@ -1,11 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System;
-
namespace System.Runtime.InteropServices.JavaScript
{
- public sealed class Uint8Array : TypedArray<Uint8Array, byte>
+ public sealed class Uint8Array : JSObject
{
/// <summary>
/// Initializes a new instance of the JavaScript Core Uint8Array class.
@@ -13,35 +11,69 @@ namespace System.Runtime.InteropServices.JavaScript
public Uint8Array()
{ }
- public Uint8Array(int length) : base(length)
- { }
-
- public Uint8Array(ArrayBuffer buffer) : base(buffer)
- { }
-
- public Uint8Array(ArrayBuffer buffer, int byteOffset) : base(buffer, byteOffset)
- { }
-
- public Uint8Array(ArrayBuffer buffer, int byteOffset, int length) : base(buffer, byteOffset, length)
+ public Uint8Array(int length) : base(nameof(Uint8Array), length)
{ }
- public Uint8Array(SharedArrayBuffer buffer) : base(buffer)
+ public Uint8Array(ArrayBuffer buffer) : base(nameof(Uint8Array), buffer)
{ }
- public Uint8Array(SharedArrayBuffer buffer, int byteOffset) : base(buffer, byteOffset)
+ public Uint8Array(ArrayBuffer buffer, int byteOffset) : base(nameof(Uint8Array), buffer, byteOffset)
{ }
- public Uint8Array(SharedArrayBuffer buffer, int byteOffset, int length) : base(buffer, byteOffset, length)
+ public Uint8Array(ArrayBuffer buffer, int byteOffset, int length) : base(nameof(Uint8Array), buffer, byteOffset, length)
{ }
internal Uint8Array(IntPtr jsHandle) : base(jsHandle)
{ }
+ public int Length
+ {
+ get => Convert.ToInt32(GetObjectProperty("length"));
+ set => SetObjectProperty("length", value, false);
+ }
+
/// <summary>
/// Defines an implicit conversion of JavaScript Core Uint8Array class to a Span&lt;byte&gt;
/// </summary>
public static implicit operator Span<byte>(Uint8Array typedarray) => typedarray.ToArray();
public static implicit operator Uint8Array(Span<byte> span) => From(span);
+
+ public byte[] ToArray()
+ {
+ AssertNotDisposed();
+
+ object res = Interop.Runtime.TypedArrayToArray(JSHandle, out int exception);
+
+ if (exception != 0)
+ throw new JSException((string)res);
+ return (byte[])res;
+ }
+
+ public static unsafe Uint8Array From(ReadOnlySpan<byte> span)
+ {
+ // source has to be instantiated.
+ if (span == null)
+ {
+ throw new System.ArgumentException(SR.Format(SR.ArgumentCannotBeNull, nameof(span)));
+ }
+
+ ReadOnlySpan<byte> bytes = MemoryMarshal.AsBytes(span);
+ fixed (byte* ptr = bytes)
+ {
+ object res = Interop.Runtime.TypedArrayFrom((int)ptr, 0, span.Length, sizeof(byte), (int)TypedArrayTypeCode.Uint8Array, out int exception);
+ if (exception != 0)
+ throw new JSException((string)res);
+ var r = (Uint8Array)res;
+ r.ReleaseInFlight();
+ return r;
+ }
+
+ }
+
+ public enum TypedArrayTypeCode
+ {
+ Uint8Array = 6,
+ }
}
}
diff --git a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Uint8ClampedArray.cs b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Uint8ClampedArray.cs
deleted file mode 100644
index debaddfef22..00000000000
--- a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Uint8ClampedArray.cs
+++ /dev/null
@@ -1,47 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System;
-
-namespace System.Runtime.InteropServices.JavaScript
-{
- public sealed class Uint8ClampedArray : TypedArray<Uint8ClampedArray, byte>
- {
- /// <summary>
- /// Initializes a new instance of the JavaScript Core Uint8ClampedArray class.
- /// </summary>
- public Uint8ClampedArray()
- { }
-
- public Uint8ClampedArray(int length) : base(length)
- { }
-
- public Uint8ClampedArray(ArrayBuffer buffer) : base(buffer)
- { }
-
- public Uint8ClampedArray(ArrayBuffer buffer, int byteOffset) : base(buffer, byteOffset)
- { }
-
- public Uint8ClampedArray(ArrayBuffer buffer, int byteOffset, int length) : base(buffer, byteOffset, length)
- { }
-
- public Uint8ClampedArray(SharedArrayBuffer buffer) : base(buffer)
- { }
-
- public Uint8ClampedArray(SharedArrayBuffer buffer, int byteOffset) : base(buffer, byteOffset)
- { }
-
- public Uint8ClampedArray(SharedArrayBuffer buffer, int byteOffset, int length) : base(buffer, byteOffset, length)
- { }
-
- internal Uint8ClampedArray(IntPtr jsHandle) : base(jsHandle)
- { }
-
- /// <summary>
- /// Defines an implicit conversion of JavaScript Core Uint8ClampedArray class to a Span&lt;byte&gt;
- /// </summary>
- public static implicit operator Span<byte>(Uint8ClampedArray typedarray) => typedarray.ToArray();
-
- public static implicit operator Uint8ClampedArray(Span<byte> span) => From(span);
- }
-}
diff --git a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System.Private.Runtime.InteropServices.JavaScript.Tests.csproj b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System.Private.Runtime.InteropServices.JavaScript.Tests.csproj
index c8da8951199..871f62d5d16 100644
--- a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System.Private.Runtime.InteropServices.JavaScript.Tests.csproj
+++ b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System.Private.Runtime.InteropServices.JavaScript.Tests.csproj
@@ -9,9 +9,7 @@
<Compile Include="System\Runtime\InteropServices\JavaScript\JavaScriptTests.cs" />
<Compile Include="System\Runtime\InteropServices\JavaScript\DataViewTests.cs" />
<Compile Include="System\Runtime\InteropServices\JavaScript\TypedArrayTests.cs" />
- <Compile Include="System\Runtime\InteropServices\JavaScript\SharedArrayBufferTests.cs" />
<Compile Include="System\Runtime\InteropServices\JavaScript\ArrayTests.cs" />
- <!-- <Compile Include="System\Runtime\InteropServices\JavaScript\MapTests.cs" /> -->
<Compile Include="System\Runtime\InteropServices\JavaScript\MarshalTests.cs" />
<Compile Include="System\Runtime\InteropServices\JavaScript\DelegateTests.cs" />
<Compile Include="System\Runtime\InteropServices\JavaScript\HelperMarshal.cs" />
diff --git a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/ArrayTests.cs b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/ArrayTests.cs
index 8b80b5d038d..ae247a1bb2f 100644
--- a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/ArrayTests.cs
+++ b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/ArrayTests.cs
@@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections.Generic;
-using System.Runtime.InteropServices.JavaScript;
using Xunit;
namespace System.Runtime.InteropServices.JavaScript.Tests
diff --git a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/DataViewTests.cs b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/DataViewTests.cs
index 4ca783e5542..4e06bf20f00 100644
--- a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/DataViewTests.cs
+++ b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/DataViewTests.cs
@@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections.Generic;
-using System.Runtime.InteropServices.JavaScript;
using Xunit;
namespace System.Runtime.InteropServices.JavaScript.Tests
diff --git a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/DelegateTests.cs b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/DelegateTests.cs
index ccb9a1ade66..44939de5769 100644
--- a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/DelegateTests.cs
+++ b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/DelegateTests.cs
@@ -165,14 +165,6 @@ namespace System.Runtime.InteropServices.JavaScript.Tests
{
_objectPrototype ??= new Function("return Object.prototype.toString;");
yield return new object[] { _objectPrototype.Call(), "Uint8Array", Uint8Array.From(new byte[10]) };
- yield return new object[] { _objectPrototype.Call(), "Uint8ClampedArray", Uint8ClampedArray.From(new byte[10]) };
- yield return new object[] { _objectPrototype.Call(), "Int8Array", Int8Array.From(new sbyte[10]) };
- yield return new object[] { _objectPrototype.Call(), "Uint16Array", Uint16Array.From(new ushort[10]) };
- yield return new object[] { _objectPrototype.Call(), "Int16Array", Int16Array.From(new short[10]) };
- yield return new object[] { _objectPrototype.Call(), "Uint32Array", Uint32Array.From(new uint[10]) };
- yield return new object[] { _objectPrototype.Call(), "Int32Array", Int32Array.From(new int[10]) };
- yield return new object[] { _objectPrototype.Call(), "Float32Array", Float32Array.From(new float[10]) };
- yield return new object[] { _objectPrototype.Call(), "Float64Array", Float64Array.From(new double[10]) };
yield return new object[] { _objectPrototype.Call(), "Array", new Array(10) };
}
@@ -181,7 +173,7 @@ namespace System.Runtime.InteropServices.JavaScript.Tests
public static void InvokeFunctionAcceptingArrayTypes(Function objectPrototype, string creator, JSObject arrayType)
{
HelperMarshal._funcActionBufferObjectResultValue = arrayType;
- Assert.Equal(10, HelperMarshal._funcActionBufferObjectResultValue.Length);
+ Assert.Equal(10, HelperMarshal._funcActionBufferObjectResultValue.GetObjectProperty("length"));
Assert.Equal($"[object {creator}]", objectPrototype.Call(HelperMarshal._funcActionBufferObjectResultValue));
Runtime.InvokeJS($@"
@@ -191,8 +183,8 @@ namespace System.Runtime.InteropServices.JavaScript.Tests
setAction(buffer);
");
- Assert.Equal(50, HelperMarshal._funcActionBufferObjectResultValue.Length);
- Assert.Equal(HelperMarshal._funcActionBufferObjectResultValue.Length, HelperMarshal._funcActionBufferResultLengthValue);
+ Assert.Equal(50, HelperMarshal._funcActionBufferObjectResultValue.GetObjectProperty("length"));
+ Assert.Equal(HelperMarshal._funcActionBufferObjectResultValue.GetObjectProperty("length"), HelperMarshal._funcActionBufferResultLengthValue);
Assert.Equal($"[object {creator}]", objectPrototype.Call(HelperMarshal._funcActionBufferObjectResultValue));
}
diff --git a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/HelperMarshal.cs b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/HelperMarshal.cs
index f612dcb76be..cf2a8a7d81b 100644
--- a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/HelperMarshal.cs
+++ b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/HelperMarshal.cs
@@ -1,11 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Runtime.InteropServices.JavaScript;
-using System.Collections.Generic;
-using System.Linq;
using System.Threading.Tasks;
-using Xunit;
namespace System.Runtime.InteropServices.JavaScript.Tests
{
@@ -48,13 +44,6 @@ namespace System.Runtime.InteropServices.JavaScript.Tests
_byteBuffer = buffer.ToArray();
}
- internal static int[] _intBuffer;
- private static void MarshalArrayBufferToInt32Array(ArrayBuffer buffer)
- {
- using (var ints = new Int32Array(buffer))
- _intBuffer = ints.ToArray();
- }
-
internal static string _stringResource;
private static void InvokeString(string s)
{
@@ -83,11 +72,11 @@ namespace System.Runtime.InteropServices.JavaScript.Tests
return _stringResource;
}
- internal static string _marshalledString;
+ internal static string _marshaledString;
private static string InvokeMarshalString()
{
- _marshalledString = "Hic Sunt Dracones";
- return _marshalledString;
+ _marshaledString = "Hic Sunt Dracones";
+ return _marshaledString;
}
internal static object _object1;
@@ -104,16 +93,16 @@ namespace System.Runtime.InteropServices.JavaScript.Tests
return obj;
}
- internal static object _marshalledObject;
+ internal static object _marshaledObject;
private static object InvokeMarshalObj()
{
- _marshalledObject = new object();
- return _marshalledObject;
+ _marshaledObject = new object();
+ return _marshaledObject;
}
private static object InvokeReturnMarshalObj()
{
- return _marshalledObject;
+ return _marshaledObject;
}
internal static int _valOne, _valTwo;
@@ -183,63 +172,6 @@ namespace System.Runtime.InteropServices.JavaScript.Tests
obj.SetObjectProperty("myBoolean", true, createIfNotExist);
}
- private static void MarshalByteBufferToInts(ArrayBuffer buffer)
- {
- using (var bytes = new Uint8Array(buffer))
- {
- var byteBuffer = bytes.ToArray();
- _intBuffer = new int[bytes.Length / sizeof(int)];
- for (int i = 0; i < bytes.Length; i += sizeof(int))
- _intBuffer[i / sizeof(int)] = BitConverter.ToInt32(byteBuffer, i);
- }
- }
-
- private static void MarshalInt32Array(Int32Array buffer)
- {
- _intBuffer = buffer.ToArray();
- }
-
- internal static float[] _floatBuffer;
- private static void MarshalFloat32Array(Float32Array buffer)
- {
- _floatBuffer = buffer.ToArray();
- }
- private static void MarshalArrayBufferToFloat32Array(ArrayBuffer buffer)
- {
- using (var floats = new Float32Array(buffer))
- _floatBuffer = floats.ToArray();
- }
-
- internal static double[] _doubleBuffer;
- private static void MarshalFloat64Array(Float64Array buffer)
- {
- _doubleBuffer = buffer.ToArray();
- }
-
- private static void MarshalArrayBufferToFloat64Array(ArrayBuffer buffer)
- {
- using (var doubles = new Float64Array(buffer))
- _doubleBuffer = doubles.ToArray();
- }
-
- private static void MarshalByteBufferToDoubles(ArrayBuffer buffer)
- {
- using (var doubles = new Float64Array(buffer))
- _doubleBuffer = doubles.ToArray();
- }
-
- private static void SetTypedArraySByte(JSObject obj)
- {
- sbyte[] buffer = Enumerable.Repeat((sbyte)0x20, 11).ToArray();
- obj.SetObjectProperty("typedArray", Int8Array.From(buffer));
- }
-
- internal static sbyte[] _taSByte;
- private static void GetTypedArraySByte(JSObject obj)
- {
- _taSByte = ((Int8Array)obj.GetObjectProperty("typedArray")).ToArray();
- }
-
private static void SetTypedArrayByte(JSObject obj)
{
var dragons = "hic sunt dracones";
@@ -253,78 +185,6 @@ namespace System.Runtime.InteropServices.JavaScript.Tests
_taByte = ((Uint8Array)obj.GetObjectProperty("dracones")).ToArray();
}
- private static void SetTypedArrayShort(JSObject obj)
- {
- short[] buffer = Enumerable.Repeat((short)0x20, 13).ToArray();
- obj.SetObjectProperty("typedArray", Int16Array.From(buffer));
- }
-
- internal static short[] _taShort;
- private static void GetTypedArrayShort(JSObject obj)
- {
- _taShort = ((Int16Array)obj.GetObjectProperty("typedArray")).ToArray();
- }
-
- private static void SetTypedArrayUShort(JSObject obj)
- {
- ushort[] buffer = Enumerable.Repeat((ushort)0x20, 14).ToArray();
- obj.SetObjectProperty("typedArray", Uint16Array.From(buffer));
- }
-
- internal static ushort[] _taUShort;
- private static void GetTypedArrayUShort(JSObject obj)
- {
- _taUShort = ((Uint16Array)obj.GetObjectProperty("typedArray")).ToArray();
- }
-
- private static void SetTypedArrayInt(JSObject obj)
- {
- int[] buffer = Enumerable.Repeat((int)0x20, 15).ToArray();
- obj.SetObjectProperty("typedArray", Int32Array.From(buffer));
- }
-
- internal static int[] _taInt;
- private static void GetTypedArrayInt(JSObject obj)
- {
- _taInt = ((Int32Array)obj.GetObjectProperty("typedArray")).ToArray();
- }
-
- public static void SetTypedArrayUInt(JSObject obj)
- {
- uint[] buffer = Enumerable.Repeat((uint)0x20, 16).ToArray();
- obj.SetObjectProperty("typedArray", Uint32Array.From(buffer));
- }
-
- internal static uint[] _taUInt;
- private static void GetTypedArrayUInt(JSObject obj)
- {
- _taUInt = ((Uint32Array)obj.GetObjectProperty("typedArray")).ToArray();
- }
-
- private static void SetTypedArrayFloat(JSObject obj)
- {
- float[] buffer = Enumerable.Repeat(3.14f, 17).ToArray();
- obj.SetObjectProperty("typedArray", Float32Array.From(buffer));
- }
-
- internal static float[] _taFloat;
- private static void GetTypedArrayFloat(JSObject obj)
- {
- _taFloat = ((Float32Array)obj.GetObjectProperty("typedArray")).ToArray();
- }
-
- private static void SetTypedArrayDouble(JSObject obj)
- {
- double[] buffer = Enumerable.Repeat(3.14d, 18).ToArray();
- obj.SetObjectProperty("typedArray", Float64Array.From(buffer));
- }
-
- internal static double[] _taDouble;
- private static void GetTypedArrayDouble(JSObject obj)
- {
- _taDouble = ((Float64Array)obj.GetObjectProperty("typedArray")).ToArray();
- }
-
private static Function _sumFunction;
private static void CreateFunctionSum()
{
@@ -522,17 +382,6 @@ namespace System.Runtime.InteropServices.JavaScript.Tests
internal static JSObject _funcActionBufferObjectResultValue;
internal static int _funcActionBufferResultLengthValue;
- private static Func<Uint8ClampedArray, Action<Uint8ClampedArray>> CreateFunctionAcceptingUint8ClampedArray()
- {
- return (buffer) =>
- {
- _funcActionBufferObjectResultValue = buffer;
- return (i1) =>
- {
- _funcActionBufferResultLengthValue = i1.Length;
- };
- };
- }
private static Func<Uint8Array, Action<Uint8Array>> CreateFunctionAcceptingUint8Array()
{
@@ -545,91 +394,6 @@ namespace System.Runtime.InteropServices.JavaScript.Tests
};
};
}
-
- private static Func<Int8Array, Action<Int8Array>> CreateFunctionAcceptingInt8Array()
- {
- return (buffer) =>
- {
- _funcActionBufferObjectResultValue = buffer;
- return (i1) =>
- {
- _funcActionBufferResultLengthValue = i1.Length;
- };
- };
- }
-
- private static Func<Uint16Array, Action<Uint16Array>> CreateFunctionAcceptingUint16Array()
- {
- return (buffer) =>
- {
- _funcActionBufferObjectResultValue = buffer;
- return (i1) =>
- {
- _funcActionBufferResultLengthValue = i1.Length;
- };
- };
- }
-
- private static Func<Int16Array, Action<Int16Array>> CreateFunctionAcceptingInt16Array()
- {
- return (buffer) =>
- {
- _funcActionBufferObjectResultValue = buffer;
- return (i1) =>
- {
- _funcActionBufferResultLengthValue = i1.Length;
- };
- };
- }
-
- private static Func<Uint32Array, Action<Uint32Array>> CreateFunctionAcceptingUint32Array()
- {
- return (buffer) =>
- {
- _funcActionBufferObjectResultValue = buffer;
- return (i1) =>
- {
- _funcActionBufferResultLengthValue = i1.Length;
- };
- };
- }
-
- private static Func<Int32Array, Action<Int32Array>> CreateFunctionAcceptingInt32Array()
- {
- return (buffer) =>
- {
- _funcActionBufferObjectResultValue = buffer;
- return (i1) =>
- {
- _funcActionBufferResultLengthValue = i1.Length;
- };
- };
- }
-
- private static Func<Float32Array, Action<Float32Array>> CreateFunctionAcceptingFloat32Array()
- {
- return (buffer) =>
- {
- _funcActionBufferObjectResultValue = buffer;
- return (i1) =>
- {
- _funcActionBufferResultLengthValue = i1.Length;
- };
- };
- }
-
- private static Func<Float64Array, Action<Float64Array>> CreateFunctionAcceptingFloat64Array()
- {
- return (buffer) =>
- {
- _funcActionBufferObjectResultValue = buffer;
- return (i1) =>
- {
- _funcActionBufferResultLengthValue = i1.Length;
- };
- };
- }
-
private static Func<Array, Action<Array>> CreateFunctionAcceptingArray()
{
return (buffer) =>
diff --git a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/JavaScriptTests.cs b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/JavaScriptTests.cs
index 7158c38899c..c41253f5c8f 100644
--- a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/JavaScriptTests.cs
+++ b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/JavaScriptTests.cs
@@ -13,71 +13,8 @@ namespace System.Runtime.InteropServices.JavaScript.Tests
[Fact]
public static void CoreTypes()
{
- var arr = new Uint8ClampedArray(50);
- Assert.Equal(50, arr.Length);
- Assert.Equal(TypedArrayTypeCode.Uint8ClampedArray, arr.GetTypedArrayType());
-
var arr1 = new Uint8Array(50);
Assert.Equal(50, arr1.Length);
- Assert.Equal(TypedArrayTypeCode.Uint8Array, arr1.GetTypedArrayType());
-
- var arr2 = new Uint16Array(50);
- Assert.Equal(50, arr2.Length);
- Assert.Equal(TypedArrayTypeCode.Uint16Array, arr2.GetTypedArrayType());
-
- var arr3 = new Uint32Array(50);
- Assert.Equal(50, arr3.Length);
- Assert.Equal(TypedArrayTypeCode.Uint32Array, arr3.GetTypedArrayType());
-
- var arr4 = new Int8Array(50);
- Assert.Equal(50, arr4.Length);
- Assert.Equal(TypedArrayTypeCode.Int8Array, arr4.GetTypedArrayType());
-
- var arr5 = new Int16Array(50);
- Assert.Equal(50, arr5.Length);
- Assert.Equal(TypedArrayTypeCode.Int16Array, arr5.GetTypedArrayType());
-
- var arr6 = new Int32Array(50);
- Assert.Equal(50, arr6.Length);
- Assert.Equal(TypedArrayTypeCode.Int32Array, arr6.GetTypedArrayType());
-
- var arr7 = new Float32Array(50);
- Assert.Equal(50, arr7.Length);
- Assert.Equal(TypedArrayTypeCode.Float32Array, arr7.GetTypedArrayType());
-
- var arr8 = new Float64Array(50);
- Assert.Equal(50, arr8.Length);
- Assert.Equal(TypedArrayTypeCode.Float64Array, arr8.GetTypedArrayType());
-
- var sharedArr40 = new SharedArrayBuffer(40);
- var sharedArr50 = new SharedArrayBuffer(50);
-
- var arr9 = new Uint8ClampedArray(sharedArr50);
- Assert.Equal(50, arr9.Length);
-
- var arr10 = new Uint8Array(sharedArr50);
- Assert.Equal(50, arr10.Length);
-
- var arr11 = new Uint16Array(sharedArr50);
- Assert.Equal(25, arr11.Length);
-
- var arr12 = new Uint32Array(sharedArr40);
- Assert.Equal(10, arr12.Length);
-
- var arr13 = new Int8Array(sharedArr50);
- Assert.Equal(50, arr13.Length);
-
- var arr14 = new Int16Array(sharedArr40);
- Assert.Equal(20, arr14.Length);
-
- var arr15 = new Int32Array(sharedArr40);
- Assert.Equal(10, arr15.Length);
-
- var arr16 = new Float32Array(sharedArr40);
- Assert.Equal(10, arr16.Length);
-
- var arr17 = new Float64Array(sharedArr40);
- Assert.Equal(5, arr17.Length);
}
[Fact]
@@ -119,6 +56,7 @@ namespace System.Runtime.InteropServices.JavaScript.Tests
}
[Fact]
+ [OuterLoop("slow")]
public static async Task BagIterator()
{
await Task.Delay(1);
@@ -194,13 +132,16 @@ namespace System.Runtime.InteropServices.JavaScript.Tests
{
var entriesIterator = (JSObject)makeRangeIterator.Call(null, 0, count, 1);
Assert.NotNull(entriesIterator);
- using (entriesIterator) {
+ using (entriesIterator)
+ {
var enumerable = entriesIterator.ToEnumerable();
var enumerator = enumerable.GetEnumerator();
Assert.NotNull(enumerator);
- using (enumerator) {
- while (enumerator.MoveNext()) {
+ using (enumerator)
+ {
+ while (enumerator.MoveNext())
+ {
Assert.NotNull(enumerator.Current);
index++;
}
@@ -237,222 +178,6 @@ namespace System.Runtime.InteropServices.JavaScript.Tests
}
}
- private static JSObject SetupListenerTest () {
- var factory = new Function(@"return {
- listeners: [],
- eventFactory:function(data){
- return {
- data:data
- };
- },
- addEventListener: function (name, listener, options) {
- if (name === 'throwError')
- throw new Error('throwError throwing');
- var capture = !options ? false : !!options.capture;
- for (var i = 0; i < this.listeners.length; i++) {
- var item = this.listeners[i];
- if (item[0] !== name)
- continue;
- var itemCapture = !item[2] ? false : !!item[2].capture;
- if (itemCapture !== capture)
- continue;
- if (item[1] === listener)
- return;
- }
- this.listeners.push([name, listener, options || null]);
- },
- removeEventListener: function (name, listener, capture) {
- for (var i = 0; i < this.listeners.length; i++) {
- var item = this.listeners[i];
- if (item[0] !== name)
- continue;
- if (item[1] !== listener)
- continue;
- var itemCapture = !item[2] ? false : !!item[2].capture;
- if (itemCapture !== !!capture)
- continue;
- this.listeners.splice(i, 1);
- return;
- }
- },
- fireEvent: function (name, evt) {
- this._fireEventImpl(name, true, evt);
- this._fireEventImpl(name, false, evt);
- },
- _fireEventImpl: function (name, capture, evt) {
- for (var i = 0; i < this.listeners.length; i++) {
- var item = this.listeners[i];
- if (item[0] !== name)
- continue;
- var itemCapture = !item[2] ? false : (item[2].capture || false);
- if (itemCapture !== capture)
- continue;
- item[1].call(this, evt);
- }
- },
-};
-");
- return (JSObject)factory.Call();
- }
-
- [Fact]
- public static void AddEventListenerWorks () {
- var temp = new bool[2];
- var obj = SetupListenerTest();
- obj.AddEventListener("test", (JSObject envt) => {
- var data = (int)envt.GetObjectProperty("data");
- temp[data] = true;
- });
- var evnt0 = obj.Invoke("eventFactory", 0);
- var evnt1 = obj.Invoke("eventFactory", 1);
- obj.Invoke("fireEvent", "test", evnt0);
- obj.Invoke("fireEvent", "test", evnt1);
- Assert.True(temp[0]);
- Assert.True(temp[1]);
- }
-
- [Fact]
- public static void EventsAreNotCollected()
- {
- const int attempts = 100; // we fire 100 events in a loop, to try that it's GC same
- var temp = new bool[100];
- var obj = SetupListenerTest();
- obj.AddEventListener("test", (JSObject envt) => {
- var data = (int)envt.GetObjectProperty("data");
- temp[data] = true;
- });
- var evnt = obj.Invoke("eventFactory", 0);
- for (int i = 0; i < attempts; i++)
- {
- var evnti = obj.Invoke("eventFactory", 0);
- obj.Invoke("fireEvent", "test", evnt);
- obj.Invoke("fireEvent", "test", evnti);
- // we are trying to test that managed side doesn't lose strong reference to evnt instance
- Runtime.InvokeJS("if (globalThis.gc) globalThis.gc();");// needs v8 flag --expose-gc
- GC.Collect();
- }
- }
-
- [Fact]
- public static void AddEventListenerPassesOptions () {
- var log = new List<string>();
- var obj = SetupListenerTest();
- obj.AddEventListener("test", (JSObject envt) => {
- log.Add("Capture");
- }, new JSObject.EventListenerOptions { Capture = true });
- obj.AddEventListener("test", (JSObject envt) => {
- log.Add("Non-capture");
- }, new JSObject.EventListenerOptions { Capture = false });
- obj.Invoke("fireEvent", "test");
- Assert.Equal("Capture", log[0]);
- Assert.Equal("Non-capture", log[1]);
- }
-
- [Fact]
- public static void AddEventListenerForwardsExceptions () {
- var obj = SetupListenerTest();
- obj.AddEventListener("test", (JSObject envt) => {
- throw new Exception("Test exception");
- });
- var exc = Assert.Throws<JSException>(() => {
- obj.Invoke("fireEvent", "test");
- });
- Assert.Contains("Test exception", exc.Message);
-
- exc = Assert.Throws<JSException>(() => {
- obj.AddEventListener("throwError", (JSObject envt) => {
- throw new Exception("Should not be called");
- });
- });
- Assert.Contains("throwError throwing", exc.Message);
- obj.Invoke("fireEvent", "throwError");
- }
-
- [Fact]
- public static void RemovedEventListenerIsNotCalled () {
- var obj = SetupListenerTest();
- Action<JSObject> del = (JSObject envt) => {
- throw new Exception("Should not be called");
- };
- obj.AddEventListener("test", del);
- Assert.Throws<JSException>(() => {
- obj.Invoke("fireEvent", "test");
- });
-
- obj.RemoveEventListener("test", del);
- obj.Invoke("fireEvent", "test");
- }
-
- [Fact]
- public static void RegisterSameEventListener () {
- var counter = new int[1];
- var obj = SetupListenerTest();
- Action<JSObject> del = (JSObject envt) => {
- counter[0]++;
- };
-
- obj.AddEventListener("test1", del);
- obj.AddEventListener("test2", del);
-
- obj.Invoke("fireEvent", "test1");
- Assert.Equal(1, counter[0]);
- obj.Invoke("fireEvent", "test2");
- Assert.Equal(2, counter[0]);
-
- obj.RemoveEventListener("test1", del);
- obj.Invoke("fireEvent", "test1");
- obj.Invoke("fireEvent", "test2");
- Assert.Equal(3, counter[0]);
-
- obj.RemoveEventListener("test2", del);
- obj.Invoke("fireEvent", "test1");
- obj.Invoke("fireEvent", "test2");
- Assert.Equal(3, counter[0]);
- }
-
- [Fact]
- public static void UseAddEventListenerResultToRemove () {
- var obj = SetupListenerTest();
- Action<JSObject> del = (JSObject envt) => {
- throw new Exception("Should not be called");
- };
- var handle = obj.AddEventListener("test", del);
- Assert.Throws<JSException>(() => {
- obj.Invoke("fireEvent", "test");
- });
-
- obj.RemoveEventListener("test", handle);
- obj.Invoke("fireEvent", "test");
- }
-
- [Fact]
- public static void RegisterSameEventListenerToMultipleSources () {
- var counter = new int[1];
- var a = SetupListenerTest();
- var b = SetupListenerTest();
- Action<JSObject> del = (JSObject envt) => {
- counter[0]++;
- };
-
- a.AddEventListener("test", del);
- b.AddEventListener("test", del);
-
- a.Invoke("fireEvent", "test");
- Assert.Equal(1, counter[0]);
- b.Invoke("fireEvent", "test");
- Assert.Equal(2, counter[0]);
-
- a.RemoveEventListener("test", del);
- a.Invoke("fireEvent", "test");
- b.Invoke("fireEvent", "test");
- Assert.Equal(3, counter[0]);
-
- b.RemoveEventListener("test", del);
- a.Invoke("fireEvent", "test");
- b.Invoke("fireEvent", "test");
- Assert.Equal(3, counter[0]);
- }
-
[Fact]
public static void RoundtripCSDate()
{
diff --git a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/MapTests.cs b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/MapTests.cs
deleted file mode 100644
index e5d04fb03b1..00000000000
--- a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/MapTests.cs
+++ /dev/null
@@ -1,213 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System.Collections;
-using System.Collections.Generic;
-using System.Runtime.InteropServices.JavaScript;
-using Xunit;
-
-namespace System.Runtime.InteropServices.JavaScript.Tests
-{
- public static class MapTests
- {
- [Fact]
- public static void Ctor_Empty()
- {
- var map = new Map();
- Assert.Equal(0, map.Count);
- Assert.Equal(0, map.Length);
- }
-
- [Theory]
- [InlineData(0)]
- [InlineData(10)]
- [InlineData(100)]
- public static void Map_Add(int numberOfElements)
- {
- var map = new Map();
- for (int i = 0; i < numberOfElements; i++)
- {
- map.Add(i, $"value{i}");
- }
- Assert.Equal(numberOfElements, map.Count);
- }
-
- [Theory]
- [InlineData(0)]
- [InlineData(10)]
- [InlineData(1000)]
- public static void Map_AddContains(int numberOfElements)
- {
- var map = new Map();
- for (int i = 0; i < numberOfElements; i++)
- {
- map.Add(i, $"value{i}");
- }
- Assert.Equal(numberOfElements, map.Count);
-
- for (int i = 0; i < numberOfElements; i++)
- {
- Assert.True(map.Contains(i));
- }
- }
-
- [Theory]
- [InlineData(0)]
- [InlineData(10)]
- [InlineData(1000)]
- public static void Map_Iterator(int numberOfElements)
- {
- var map = new Map();
- for (int i = 0; i < numberOfElements; i++)
- {
- map.Add(i, $"value{i}");
- }
- Assert.Equal(numberOfElements, map.Count);
-
- int d = 0;
- foreach (var value in map)
- {
- d++;
- }
- Assert.Equal(numberOfElements, d);
- }
-
- [Theory]
- [InlineData(0)]
- [InlineData(10)]
- [InlineData(1000)]
- public static void Map_IteratorKeyValue(int numberOfElements)
- {
- var map = new Map();
- for (int i = 0; i < numberOfElements; i++)
- {
- map.Add(i, $"value{i}");
- }
- Assert.Equal(numberOfElements, map.Count);
-
- int d = 0;
- foreach (DictionaryEntry value in map)
- {
- Assert.Equal(d, value.Key);
- Assert.Equal($"value{d++}", value.Value);
- }
- Assert.Equal(numberOfElements, d);
- }
-
- [Theory]
- [InlineData(10)]
- [InlineData(100)]
- public static void Map_Contains(int numberOfElements)
- {
- var map = new Map();
- for (int i = 0; i < numberOfElements; i++)
- {
- map.Add(i, $"value{i}");
- }
- Assert.Equal(numberOfElements, map.Count);
- Assert.True(map.Contains(numberOfElements - 1));
- }
-
- [Fact]
- public static void Add_ClearRepeatedly()
- {
- const int Iterations = 2;
- const int Count = 2;
-
- var hash = new Map();
- for (int i = 0; i < Iterations; i++)
- {
- for (int j = 0; j < Count; j++)
- {
- string key = $"Key: i={i}, j={j}";
- string value = $"Value: i={i}, j={j}";
- hash.Add(key, value);
- }
-
- Assert.Equal(Count, hash.Count);
- hash.Clear();
- }
- }
-
- [Fact]
- public static void ContainsKey()
- {
- var map1 = Helpers.CreateStringMap(100);
- Helpers.PerformActionOnAllMapWrappers(map1, map2 =>
- {
- for (int i = 0; i < map2.Count; i++)
- {
- string key = $"Key_{i}";
- Assert.True(map2.Contains(key));
- }
-
- Assert.False(map2.Contains("Non Existent Key"));
- Assert.False(map2.Contains(101));
-
- string removedKey = "Key_1";
- map2.Remove(removedKey);
- Assert.False(map2.Contains(removedKey));
- });
- }
-
- [Fact]
- public static void RemoveKey()
- {
- var map1 = Helpers.CreateStringMap(100);
- Helpers.PerformActionOnAllMapWrappers(map1, map2 =>
- {
- for (int i = 0; i < map2.Count; i++)
- {
- string key = $"Key_{i}";
- Assert.True(map2.Contains(key));
- }
- Assert.Equal(map2.Count, map2.Keys.Count);
-
- foreach (var key in map2.Keys)
- {
- map2.Remove(key);
- }
- Assert.Equal(0, map2.Keys.Count);
- });
- }
-
- [Fact]
- public static void ContainsValue()
- {
- Map map1 = Helpers.CreateStringMap(100);
- Helpers.PerformActionOnAllMapWrappers(map1, map2 =>
- {
- for (int i = 0; i < map2.Count; i++)
- {
- string value = $"Value_{i}";
- Assert.True(map2[$"Key_{i}"].ToString() == value);
- }
- Assert.True(map2["Non Existent Value"] == null);
- Assert.True(map2[101] == null);
- });
- }
-
- private static class Helpers
- {
- public static void PerformActionOnAllMapWrappers(Map map, Action<Map> action)
- {
- action(map);
- }
-
- public static Map CreateStringMap(int count, int start = 0)
- {
- var map = new Map();
-
- for (int i = start; i < start + count; i++)
- {
- string key = $"Key_{i}";
- string value = $"Value_{i}";
-
- map.Add(key, value);
- }
-
- return map;
- }
- }
- }
-}
diff --git a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/MarshalTests.cs b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/MarshalTests.cs
index f8955384981..16b8dfb3f8d 100644
--- a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/MarshalTests.cs
+++ b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/MarshalTests.cs
@@ -1,9 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Runtime.InteropServices.JavaScript;
-using System.Collections.Generic;
-using System.Threading;
using System.Threading.Tasks;
using Xunit;
@@ -41,43 +38,8 @@ namespace System.Runtime.InteropServices.JavaScript.Tests
Assert.Equal(16, HelperMarshal._byteBuffer.Length);
}
- [Fact]
- public static void MarshalArrayBuffer2Int()
- {
- Runtime.InvokeJS(@"
- var buffer = new ArrayBuffer(16);
- var int32View = new Int32Array(buffer);
- for (var i = 0; i < int32View.length; i++) {
- int32View[i] = i * 2;
- }
- App.call_test_method (""MarshalArrayBufferToInt32Array"", [ buffer ]);
- ");
- Assert.Equal(4, HelperMarshal._intBuffer.Length);
- Assert.Equal(0, HelperMarshal._intBuffer[0]);
- Assert.Equal(2, HelperMarshal._intBuffer[1]);
- Assert.Equal(4, HelperMarshal._intBuffer[2]);
- Assert.Equal(6, HelperMarshal._intBuffer[3]);
- }
- [Fact]
- public static void MarshalArrayBuffer2Int2()
- {
- Runtime.InvokeJS(@"
- var buffer = new ArrayBuffer(16);
- var int32View = new Int32Array(buffer);
- for (var i = 0; i < int32View.length; i++) {
- int32View[i] = i * 2;
- }
- App.call_test_method (""MarshalByteBufferToInts"", [ buffer ]);
- ");
-
- Assert.Equal(4, HelperMarshal._intBuffer.Length);
- Assert.Equal(0, HelperMarshal._intBuffer[0]);
- Assert.Equal(2, HelperMarshal._intBuffer[1]);
- Assert.Equal(4, HelperMarshal._intBuffer[2]);
- Assert.Equal(6, HelperMarshal._intBuffer[3]);
- }
[Fact]
public static void MarshalStringToCS()
@@ -114,13 +76,13 @@ namespace System.Runtime.InteropServices.JavaScript.Tests
[Fact]
public static void MarshalStringToJS()
{
- HelperMarshal._marshalledString = HelperMarshal._stringResource = null;
+ HelperMarshal._marshaledString = HelperMarshal._stringResource = null;
Runtime.InvokeJS(@"
var str = App.call_test_method (""InvokeMarshalString"");
App.call_test_method (""InvokeString"", [ str ]);
");
- Assert.NotNull(HelperMarshal._marshalledString);
- Assert.Equal(HelperMarshal._marshalledString, HelperMarshal._stringResource);
+ Assert.NotNull(HelperMarshal._marshaledString);
+ Assert.Equal(HelperMarshal._marshaledString, HelperMarshal._stringResource);
}
[Fact]
@@ -140,7 +102,7 @@ namespace System.Runtime.InteropServices.JavaScript.Tests
[Fact]
public static void CSObjectKeepIdentityAcrossCalls()
{
- HelperMarshal._marshalledObject = HelperMarshal._object1 = HelperMarshal._object2 = null;
+ HelperMarshal._marshaledObject = HelperMarshal._object1 = HelperMarshal._object2 = null;
Runtime.InvokeJS(@"
var obj = App.call_test_method (""InvokeMarshalObj"");
var res = App.call_test_method (""InvokeObj1"", [ obj ]);
@@ -148,7 +110,7 @@ namespace System.Runtime.InteropServices.JavaScript.Tests
");
Assert.NotNull(HelperMarshal._object1);
- Assert.Same(HelperMarshal._marshalledObject, HelperMarshal._object1);
+ Assert.Same(HelperMarshal._marshaledObject, HelperMarshal._object1);
Assert.Same(HelperMarshal._object1, HelperMarshal._object2);
}
@@ -165,7 +127,7 @@ namespace System.Runtime.InteropServices.JavaScript.Tests
[InlineData(double.MinValue)]
public static void InvokeUnboxNumberString(object o)
{
- HelperMarshal._marshalledObject = o;
+ HelperMarshal._marshaledObject = o;
HelperMarshal._object1 = HelperMarshal._object2 = null;
var value = Runtime.InvokeJS(@"
var obj = App.call_test_method (""InvokeReturnMarshalObj"");
@@ -188,7 +150,7 @@ namespace System.Runtime.InteropServices.JavaScript.Tests
[InlineData(double.MinValue)]
public static void InvokeUnboxNumber(object o, object expected = null)
{
- HelperMarshal._marshalledObject = o;
+ HelperMarshal._marshaledObject = o;
HelperMarshal._object1 = HelperMarshal._object2 = null;
Runtime.InvokeJS(@"
var obj = App.call_test_method (""InvokeReturnMarshalObj"");
@@ -211,12 +173,12 @@ namespace System.Runtime.InteropServices.JavaScript.Tests
[InlineData(double.MinValue)]
public static void InvokeUnboxStringNumber(object o, object expected = null)
{
- HelperMarshal._marshalledObject = HelperMarshal._object1 = HelperMarshal._object2 = null;
- Runtime.InvokeJS(String.Format (@"
+ HelperMarshal._marshaledObject = HelperMarshal._object1 = HelperMarshal._object2 = null;
+ Runtime.InvokeJS(String.Format(@"
var res = App.call_test_method (""InvokeObj1"", [ {0} ]);
", o));
- Assert.Equal (expected ?? o, HelperMarshal._object1);
+ Assert.Equal(expected ?? o, HelperMarshal._object1);
}
[Fact]
@@ -413,114 +375,9 @@ namespace System.Runtime.InteropServices.JavaScript.Tests
Assert.Equal(16, HelperMarshal._byteBuffer.Length);
}
- [Fact]
- public static void MarshalTypedArray2Int()
- {
- Runtime.InvokeJS(@"
- var buffer = new ArrayBuffer(16);
- var int32View = new Int32Array(buffer);
- for (var i = 0; i < int32View.length; i++) {
- int32View[i] = i * 2;
- }
- App.call_test_method (""MarshalInt32Array"", [ int32View ]);
- ");
-
- Assert.Equal(4, HelperMarshal._intBuffer.Length);
- Assert.Equal(0, HelperMarshal._intBuffer[0]);
- Assert.Equal(2, HelperMarshal._intBuffer[1]);
- Assert.Equal(4, HelperMarshal._intBuffer[2]);
- Assert.Equal(6, HelperMarshal._intBuffer[3]);
- }
-
- [Fact]
- public static void MarshalTypedArray2Float()
- {
- Runtime.InvokeJS(@"
- var typedArray = new Float32Array([1, 2.1334, 3, 4.2, 5]);
- App.call_test_method (""MarshalFloat32Array"", [ typedArray ]);
- ");
-
- Assert.Equal(1, HelperMarshal._floatBuffer[0]);
- Assert.Equal(2.1334f, HelperMarshal._floatBuffer[1]);
- Assert.Equal(3, HelperMarshal._floatBuffer[2]);
- Assert.Equal(4.2f, HelperMarshal._floatBuffer[3]);
- Assert.Equal(5, HelperMarshal._floatBuffer[4]);
- }
-
- [Fact]
- public static void MarshalArrayBuffer2Float2()
+ private static void RunMarshalTypedArrayJS(string type)
{
Runtime.InvokeJS(@"
- var buffer = new ArrayBuffer(16);
- var float32View = new Float32Array(buffer);
- for (var i = 0; i < float32View.length; i++) {
- float32View[i] = i * 2.5;
- }
- App.call_test_method (""MarshalArrayBufferToFloat32Array"", [ buffer ]);
- ");
-
- Assert.Equal(4, HelperMarshal._floatBuffer.Length);
- Assert.Equal(0, HelperMarshal._floatBuffer[0]);
- Assert.Equal(2.5f, HelperMarshal._floatBuffer[1]);
- Assert.Equal(5, HelperMarshal._floatBuffer[2]);
- Assert.Equal(7.5f, HelperMarshal._floatBuffer[3]);
- }
-
- [Fact]
- public static void MarshalTypedArray2Double()
- {
- Runtime.InvokeJS(@"
- var typedArray = new Float64Array([1, 2.1334, 3, 4.2, 5]);
- App.call_test_method (""MarshalFloat64Array"", [ typedArray ]);
- ");
-
- Assert.Equal(1, HelperMarshal._doubleBuffer[0]);
- Assert.Equal(2.1334d, HelperMarshal._doubleBuffer[1]);
- Assert.Equal(3, HelperMarshal._doubleBuffer[2]);
- Assert.Equal(4.2d, HelperMarshal._doubleBuffer[3]);
- Assert.Equal(5, HelperMarshal._doubleBuffer[4]);
- }
-
- [Fact]
- public static void MarshalArrayBuffer2Double()
- {
- Runtime.InvokeJS(@"
- var buffer = new ArrayBuffer(32);
- var float64View = new Float64Array(buffer);
- for (var i = 0; i < float64View.length; i++) {
- float64View[i] = i * 2.5;
- }
- App.call_test_method (""MarshalByteBufferToDoubles"", [ buffer ]);
- ");
-
- Assert.Equal(4, HelperMarshal._doubleBuffer.Length);
- Assert.Equal(0, HelperMarshal._doubleBuffer[0]);
- Assert.Equal(2.5d, HelperMarshal._doubleBuffer[1]);
- Assert.Equal(5, HelperMarshal._doubleBuffer[2]);
- Assert.Equal(7.5d, HelperMarshal._doubleBuffer[3]);
- }
-
- [Fact]
- public static void MarshalArrayBuffer2Double2()
- {
- Runtime.InvokeJS(@"
- var buffer = new ArrayBuffer(32);
- var float64View = new Float64Array(buffer);
- for (var i = 0; i < float64View.length; i++) {
- float64View[i] = i * 2.5;
- }
- App.call_test_method (""MarshalArrayBufferToFloat64Array"", [ buffer ]);
- ");
-
- Assert.Equal(4, HelperMarshal._doubleBuffer.Length);
- Assert.Equal(0, HelperMarshal._doubleBuffer[0]);
- Assert.Equal(2.5f, HelperMarshal._doubleBuffer[1]);
- Assert.Equal(5, HelperMarshal._doubleBuffer[2]);
- Assert.Equal(7.5f, HelperMarshal._doubleBuffer[3]);
- }
-
- private static void RunMarshalTypedArrayJS(string type) {
- Runtime.InvokeJS(@"
var obj = { };
App.call_test_method (""SetTypedArray" + type + @""", [ obj ]);
App.call_test_method (""GetTypedArray" + type + @""", [ obj ]);
@@ -528,15 +385,6 @@ namespace System.Runtime.InteropServices.JavaScript.Tests
}
[Fact]
- public static void MarshalTypedArraySByte()
- {
- RunMarshalTypedArrayJS("SByte");
- Assert.Equal(11, HelperMarshal._taSByte.Length);
- Assert.Equal(32, HelperMarshal._taSByte[0]);
- Assert.Equal(32, HelperMarshal._taSByte[HelperMarshal._taSByte.Length - 1]);
- }
-
- [Fact]
public static void MarshalTypedArrayByte()
{
RunMarshalTypedArrayJS("Byte");
@@ -546,59 +394,7 @@ namespace System.Runtime.InteropServices.JavaScript.Tests
Assert.Equal("hic sunt dracones", System.Text.Encoding.Default.GetString(HelperMarshal._taByte));
}
- [Fact]
- public static void MarshalTypedArrayShort()
- {
- RunMarshalTypedArrayJS("Short");
- Assert.Equal(13, HelperMarshal._taShort.Length);
- Assert.Equal(32, HelperMarshal._taShort[0]);
- Assert.Equal(32, HelperMarshal._taShort[HelperMarshal._taShort.Length - 1]);
- }
- [Fact]
- public static void MarshalTypedArrayUShort()
- {
- RunMarshalTypedArrayJS("UShort");
- Assert.Equal(14, HelperMarshal._taUShort.Length);
- Assert.Equal(32, HelperMarshal._taUShort[0]);
- Assert.Equal(32, HelperMarshal._taUShort[HelperMarshal._taUShort.Length - 1]);
- }
-
- [Fact]
- public static void MarshalTypedArrayInt()
- {
- RunMarshalTypedArrayJS("Int");
- Assert.Equal(15, HelperMarshal._taInt.Length);
- Assert.Equal(32, HelperMarshal._taInt[0]);
- Assert.Equal(32, HelperMarshal._taInt[HelperMarshal._taInt.Length - 1]);
- }
-
- [Fact]
- public static void MarshalTypedArrayUInt()
- {
- RunMarshalTypedArrayJS("UInt");
- Assert.Equal(16, HelperMarshal._taUInt.Length);
- Assert.Equal(32, (int)HelperMarshal._taUInt[0]);
- Assert.Equal(32, (int)HelperMarshal._taUInt[HelperMarshal._taUInt.Length - 1]);
- }
-
- [Fact]
- public static void MarshalTypedArrayFloat()
- {
- RunMarshalTypedArrayJS("Float");
- Assert.Equal(17, HelperMarshal._taFloat.Length);
- Assert.Equal(3.14f, HelperMarshal._taFloat[0]);
- Assert.Equal(3.14f, HelperMarshal._taFloat[HelperMarshal._taFloat.Length - 1]);
- }
-
- [Fact]
- public static void MarshalTypedArrayDouble()
- {
- RunMarshalTypedArrayJS("Double");
- Assert.Equal(18, HelperMarshal._taDouble.Length);
- Assert.Equal(3.14d, HelperMarshal._taDouble[0]);
- Assert.Equal(3.14d, HelperMarshal._taDouble[HelperMarshal._taDouble.Length - 1]);
- }
[Fact]
public static void TestFunctionSum()
@@ -621,7 +417,7 @@ namespace System.Runtime.InteropServices.JavaScript.Tests
");
Assert.Equal(2, HelperMarshal._minValue);
}
-
+
[Fact]
public static void BoundStaticMethodMissingArgs()
{
@@ -636,7 +432,7 @@ namespace System.Runtime.InteropServices.JavaScript.Tests
");
Assert.Equal(0, HelperMarshal._intValue);
}
-
+
[Fact]
public static void BoundStaticMethodExtraArgs()
{
@@ -647,7 +443,7 @@ namespace System.Runtime.InteropServices.JavaScript.Tests
");
Assert.Equal(200, HelperMarshal._intValue);
}
-
+
[Fact]
public static void BoundStaticMethodArgumentTypeCoercion()
{
@@ -667,7 +463,7 @@ namespace System.Runtime.InteropServices.JavaScript.Tests
");
Assert.Equal(400, HelperMarshal._intValue);
}
-
+
[Fact]
public static void BoundStaticMethodUnpleasantArgumentTypeCoercion()
{
@@ -697,9 +493,9 @@ namespace System.Runtime.InteropServices.JavaScript.Tests
Assert.Equal(0xFFFFFFFEu, HelperMarshal._uintValue);
}
-
+
[Fact]
- public static void ReturnUintEnum ()
+ public static void ReturnUintEnum()
{
HelperMarshal._uintValue = 0;
HelperMarshal._enumValue = TestEnum.BigValue;
@@ -711,9 +507,9 @@ namespace System.Runtime.InteropServices.JavaScript.Tests
");
Assert.Equal((uint)TestEnum.BigValue, HelperMarshal._uintValue);
}
-
+
[Fact]
- public static void PassUintEnumByValue ()
+ public static void PassUintEnumByValue()
{
HelperMarshal._enumValue = TestEnum.Zero;
Runtime.InvokeJS(@$"
@@ -722,9 +518,9 @@ namespace System.Runtime.InteropServices.JavaScript.Tests
");
Assert.Equal(TestEnum.BigValue, HelperMarshal._enumValue);
}
-
+
[Fact]
- public static void PassUintEnumByValueMasqueradingAsInt ()
+ public static void PassUintEnumByValueMasqueradingAsInt()
{
HelperMarshal._enumValue = TestEnum.Zero;
// HACK: We're explicitly telling the bindings layer to pass an int here, not an enum
@@ -735,25 +531,25 @@ namespace System.Runtime.InteropServices.JavaScript.Tests
");
Assert.Equal(TestEnum.BigValue, HelperMarshal._enumValue);
}
-
+
[Fact]
- public static void PassUintEnumByNameIsNotImplemented ()
+ public static void PassUintEnumByNameIsNotImplemented()
{
HelperMarshal._enumValue = TestEnum.Zero;
- var exc = Assert.Throws<JSException>( () =>
- Runtime.InvokeJS(@$"
+ var exc = Assert.Throws<JSException>(() =>
+ Runtime.InvokeJS(@$"
var set_enum = INTERNAL.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}SetEnumValue"", ""j"");
set_enum (""BigValue"");
")
);
Assert.StartsWith("Error: Expected numeric value for enum argument, got 'BigValue'", exc.Message);
}
-
+
[Fact]
- public static void CannotUnboxUint64 ()
+ public static void CannotUnboxUint64()
{
- var exc = Assert.Throws<JSException>( () =>
- Runtime.InvokeJS(@$"
+ var exc = Assert.Throws<JSException>(() =>
+ Runtime.InvokeJS(@$"
var get_u64 = INTERNAL.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}GetUInt64"", """");
var u64 = get_u64();
")
@@ -902,16 +698,16 @@ namespace System.Runtime.InteropServices.JavaScript.Tests
Assert.Null(result);
}
- private static async Task<bool> MarshalTask(string helperMethodName, string helperMethodArgs = "", string resolvedBody = "")
+ private static async Task<bool> MarshalTask(string helperMethodName, string helperMethodArgs = "", string resolvedBody = "")
{
Runtime.InvokeJS(
@"globalThis.__test_promise_completed = false; " +
@"globalThis.__test_promise_resolved = false; " +
@"globalThis.__test_promise_failed = false; " +
$@"var t = App.call_test_method ('{helperMethodName}', [ {helperMethodArgs} ], 'i'); " +
- "t.then(result => { globalThis.__test_promise_resolved = true; " + resolvedBody + " })" +
+ "t.then(result => { globalThis.__test_promise_resolved = true; " + resolvedBody + " })" +
" .catch(e => { globalThis.__test_promise_failed = true; })" +
- " .finally(result => { globalThis.__test_promise_completed = true; }); " +
+ " .finally(result => { globalThis.__test_promise_completed = true; }); " +
""
);
diff --git a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/SharedArrayBufferTests.cs b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/SharedArrayBufferTests.cs
deleted file mode 100644
index 7ca2e660a4e..00000000000
--- a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/SharedArrayBufferTests.cs
+++ /dev/null
@@ -1,156 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System.Collections.Generic;
-using Xunit;
-
-namespace System.Runtime.InteropServices.JavaScript.Tests
-{
- public static class SharedArrayBufferTests
- {
- private static Function _objectPrototype;
-
- public static IEnumerable<object[]> Object_Prototype()
- {
- _objectPrototype ??= new Function("return Object.prototype.toString;");
- yield return new object[] { _objectPrototype.Call() };
- }
-
- [Theory]
- [MemberData(nameof(Object_Prototype))]
- public static void SharedArrayBuffer_NonZeroLength(Function objectPrototype)
- {
- SharedArrayBuffer d = new SharedArrayBuffer(50);
- Assert.Equal("[object SharedArrayBuffer]", objectPrototype.Call(d));
- Assert.Equal(50, d.ByteLength);
- }
-
- [Fact]
- public static void SharedArrayBufferSlice()
- {
- SharedArrayBuffer d = new SharedArrayBuffer(50);
- Assert.Equal(50, d.Slice().ByteLength);
- }
-
- [Fact]
- public static void SharedArrayBuffer_Slice_BeginEndForFullArray()
- {
- SharedArrayBuffer d = new SharedArrayBuffer(50);
- Assert.Equal(50, d.Slice(0, 50).ByteLength);
- }
-
- [Fact]
- public static void SharedArrayBuffer_Slice_BeginZero()
- {
- SharedArrayBuffer d = new SharedArrayBuffer(50);
- Assert.Equal(50, d.Slice(0).ByteLength);
- }
-
- [Fact]
- public static void SharedArrayBuffer_Slice_BeginNegative()
- {
- SharedArrayBuffer d = new SharedArrayBuffer(50);
- Assert.Equal(3, d.Slice(-3).ByteLength);
- }
-
- [Fact]
- public static void SharedArrayBuffer_Slice_BeginEndSubset()
- {
- SharedArrayBuffer d = new SharedArrayBuffer(50);
- Assert.Equal(3, d.Slice(1, 4).ByteLength);
- }
-
- [Fact]
- public static void SharedArrayBufferSliceAndDice()
- {
- // create a SharedArrayBuffer with a size in bytes
- SharedArrayBuffer buffer = new SharedArrayBuffer(16);
- Int32Array int32View = new Int32Array(buffer); // create view
- // produces Int32Array [0, 0, 0, 0]
-
- int32View[1] = 42;
-
- Assert.Equal(4, int32View.Length);
- Assert.Equal(42, int32View[1]);
-
- Int32Array sliced = new Int32Array(buffer.Slice(4,12));
- // expected output: Int32Array [42, 0]
-
- Assert.Equal(2, sliced.Length);
- Assert.Equal(42, sliced[0]);
- Assert.Equal(0, sliced[1]);
- }
-
- [Fact]
- public static void SharedArrayBufferSliceAndDiceAndUseThroughSpan()
- {
- // create a SharedArrayBuffer with a size in bytes
- SharedArrayBuffer buffer = new SharedArrayBuffer(16);
- Int32Array int32View = new Int32Array(buffer); // create view
- // produces Int32Array [0, 0, 0, 0]
-
- int32View[1] = 42;
-
- Assert.Equal(4, int32View.Length);
- Assert.Equal(42, int32View[1]);
-
- Int32Array sliced = new Int32Array(buffer.Slice(4,12));
- // expected output: Int32Array [42, 0]
-
- Span<int> nativeArray = sliced;
-
- int sum = 0;
- for (int i = 0; i < nativeArray.Length; i++)
- {
- sum += nativeArray[i];
- }
-
- Assert.Equal(42, sum);
- }
-
- [Theory]
- [MemberData(nameof(GetTestData), 16)]
- public static void SharedArrayBufferSliceAndDice3_Subset(SharedArrayBuffer buffer)
- {
- Int32Array sliced = new Int32Array(buffer.Slice(4,12));
-
- Assert.Equal(2, sliced.Length);
- Assert.Equal(42, sliced[0]);
- Assert.Equal(12, sliced[1]);
- }
-
- [Theory]
- [MemberData(nameof(GetTestData), 16)]
- public static void SharedArrayBufferSliceAndDice3_SubsetFromTheBack(SharedArrayBuffer buffer)
- {
- Int32Array sliced = new Int32Array(buffer.Slice(-4));
-
- Assert.Equal(1, sliced.Length);
- Assert.Equal(13, sliced[0]);
- }
-
- [Theory]
- [MemberData(nameof(GetTestData), 16)]
- public static void SharedArrayBufferSliceAndDice3_SubsetFromTheBackWithEnd(SharedArrayBuffer buffer)
- {
- Int32Array sliced = new Int32Array(buffer.Slice(-12, -4));
-
- Assert.Equal(2, sliced.Length);
- Assert.Equal(42, sliced[0]);
- Assert.Equal(12, sliced[1]);
- }
-
- public static TheoryData<SharedArrayBuffer> GetTestData(int length)
- {
- // create a SharedArrayBuffer with a size in bytes
- SharedArrayBuffer buffer = new SharedArrayBuffer(length);
- Int32Array int32View = new Int32Array(buffer); // create view
- for (int i = 0; i < int32View.Length; i ++)
- int32View[i] = i + 10;
-
- int32View[1] = 42;
- return new TheoryData<SharedArrayBuffer> { buffer };
- }
-
- }
-}
diff --git a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/TypedArrayTests.cs b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/TypedArrayTests.cs
index 896835795f1..9df7fd8719b 100644
--- a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/TypedArrayTests.cs
+++ b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/TypedArrayTests.cs
@@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections.Generic;
-using System.Runtime.InteropServices.JavaScript;
using Xunit;
namespace System.Runtime.InteropServices.JavaScript.Tests
@@ -19,16 +18,6 @@ namespace System.Runtime.InteropServices.JavaScript.Tests
[Theory]
[MemberData(nameof(Object_Prototype))]
- public static void Uint8ClampedArrayFrom(Function objectPrototype)
- {
- var clamped = new byte[50];
- Uint8ClampedArray from = Uint8ClampedArray.From(clamped);
- Assert.Equal(50, from.Length);
- Assert.Equal("[object Uint8ClampedArray]", objectPrototype.Call(from));
- }
-
- [Theory]
- [MemberData(nameof(Object_Prototype))]
public static void Uint8ArrayFrom(Function objectPrototype)
{
var array = new byte[50];
@@ -39,288 +28,11 @@ namespace System.Runtime.InteropServices.JavaScript.Tests
[Theory]
[MemberData(nameof(Object_Prototype))]
- public static void Uint16ArrayFrom(Function objectPrototype)
- {
- var array = new ushort[50];
- Uint16Array from = Uint16Array.From(array);
- Assert.Equal(50, from.Length);
- Assert.Equal("[object Uint16Array]", objectPrototype.Call(from));
- }
-
- [Theory]
- [MemberData(nameof(Object_Prototype))]
- public static void Uint32ArrayFrom(Function objectPrototype)
- {
- var array = new uint[50];
- Uint32Array from = Uint32Array.From(array);
- Assert.Equal(50, from.Length);
- Assert.Equal("[object Uint32Array]", objectPrototype.Call(from));
- }
-
- [Theory]
- [MemberData(nameof(Object_Prototype))]
- public static void Int8ArrayFrom(Function objectPrototype)
- {
- var array = new sbyte[50];
- Int8Array from = Int8Array.From(array);
- Assert.Equal(50, from.Length);
- Assert.Equal("[object Int8Array]", objectPrototype.Call(from));
- }
-
- [Theory]
- [MemberData(nameof(Object_Prototype))]
- public static void Int16ArrayFrom(Function objectPrototype)
- {
- var array = new short[50];
- Int16Array from = Int16Array.From(array);
- Assert.Equal(50, from.Length);
- Assert.Equal("[object Int16Array]", objectPrototype.Call(from));
- }
-
- [Theory]
- [MemberData(nameof(Object_Prototype))]
- public static void Int32ArrayFrom(Function objectPrototype)
- {
- var array = new int[50];
- Int32Array from = Int32Array.From(array);
- Assert.Equal(50, from.Length);
- Assert.Equal("[object Int32Array]", objectPrototype.Call(from));
- }
-
- [Theory]
- [MemberData(nameof(Object_Prototype))]
- public static void Float32ArrayFrom(Function objectPrototype)
- {
- var array = new float[50];
- Float32Array from = Float32Array.From(array);
- Assert.Equal(50, from.Length);
- Assert.Equal("[object Float32Array]", objectPrototype.Call(from));
- }
-
- [Theory]
- [MemberData(nameof(Object_Prototype))]
- public static void Float64ArrayFrom(Function objectPrototype)
- {
- var array = new double[50];
- Float64Array from = Float64Array.From(array);
- Assert.Equal(50, from.Length);
- Assert.Equal("[object Float64Array]", objectPrototype.Call(from));
- }
-
- [Theory]
- [MemberData(nameof(Object_Prototype))]
- public static void Uint8ClampedArrayFromSharedArrayBuffer(Function objectPrototype)
- {
- Uint8ClampedArray from = new Uint8ClampedArray(new SharedArrayBuffer(50));
- Assert.Equal(50, from.Length);
- Assert.Equal("[object Uint8ClampedArray]", objectPrototype.Call(from));
- }
-
- [Theory]
- [MemberData(nameof(Object_Prototype))]
- public static void Uint8ArrayFromSharedArrayBuffer(Function objectPrototype)
- {
- Uint8Array from = new Uint8Array(new SharedArrayBuffer(50));
- Assert.Equal(50, from.Length);
- Assert.Equal("[object Uint8Array]", objectPrototype.Call(from));
- }
-
- [Theory]
- [MemberData(nameof(Object_Prototype))]
- public static void Uint16ArrayFromSharedArrayBuffer(Function objectPrototype)
- {
- Uint16Array from = new Uint16Array(new SharedArrayBuffer(50));
- Assert.Equal(25, from.Length);
- Assert.Equal("[object Uint16Array]", objectPrototype.Call(from));
- }
-
- [Theory]
- [MemberData(nameof(Object_Prototype))]
- public static void Uint32ArrayFromSharedArrayBuffer(Function objectPrototype)
- {
- Uint32Array from = new Uint32Array(new SharedArrayBuffer(40));
- Assert.Equal(10, from.Length);
- Assert.Equal("[object Uint32Array]", objectPrototype.Call(from));
- }
-
- [Theory]
- [MemberData(nameof(Object_Prototype))]
- public static void Int8ArrayFromSharedArrayBuffer(Function objectPrototype)
- {
- Int8Array from = new Int8Array(new SharedArrayBuffer(50));
- Assert.True(from.Length == 50);
- Assert.Equal("[object Int8Array]", objectPrototype.Call(from));
- }
-
- [Theory]
- [MemberData(nameof(Object_Prototype))]
- public static void Int16ArrayFromSharedArrayBuffer(Function objectPrototype)
- {
- Int16Array from = new Int16Array(new SharedArrayBuffer(50));
- Assert.True(from.Length == 25);
- Assert.Equal("[object Int16Array]", objectPrototype.Call(from));
- }
-
- [Theory]
- [MemberData(nameof(Object_Prototype))]
- public static void Int32ArrayFromSharedArrayBuffer(Function objectPrototype)
- {
- Int32Array from = new Int32Array(new SharedArrayBuffer(40));
- Assert.True(from.Length == 10);
- Assert.Equal("[object Int32Array]", objectPrototype.Call(from));
- }
-
- [Theory]
- [MemberData(nameof(Object_Prototype))]
- public static void Float32ArrayFromSharedArrayBuffer(Function objectPrototype)
- {
- Float32Array from = new Float32Array(new SharedArrayBuffer(40));
- Assert.True(from.Length == 10);
- Assert.Equal("[object Float32Array]", objectPrototype.Call(from));
- }
-
- [Theory]
- [MemberData(nameof(Object_Prototype))]
- public static void Float64ArrayFromSharedArrayBuffer(Function objectPrototype)
- {
- Float64Array from = new Float64Array(new SharedArrayBuffer(40));
- Assert.True(from.Length == 5);
- Assert.Equal("[object Float64Array]", objectPrototype.Call(from));
- }
-
- [Theory]
- [MemberData(nameof(Object_Prototype))]
- public static void Uint8ClampedArrayFromArrayBuffer(Function objectPrototype)
- {
- Uint8ClampedArray from = new Uint8ClampedArray(new ArrayBuffer(50));
- Assert.True(from.Length == 50);
- Assert.Equal("[object Uint8ClampedArray]", objectPrototype.Call(from));
- }
-
- [Theory]
- [MemberData(nameof(Object_Prototype))]
public static void Uint8ArrayFromArrayBuffer(Function objectPrototype)
{
Uint8Array from = new Uint8Array(new ArrayBuffer(50));
Assert.True(from.Length == 50);
Assert.Equal("[object Uint8Array]", objectPrototype.Call(from));
}
-
- [Theory]
- [MemberData(nameof(Object_Prototype))]
- public static void Uint16ArrayFromArrayBuffer(Function objectPrototype)
- {
- Uint16Array from = new Uint16Array(new ArrayBuffer(50));
- Assert.True(from.Length == 25);
- Assert.Equal("[object Uint16Array]", objectPrototype.Call(from));
- }
-
- [Theory]
- [MemberData(nameof(Object_Prototype))]
- public static void Uint32ArrayFromArrayBuffer(Function objectPrototype)
- {
- Uint32Array from = new Uint32Array(new ArrayBuffer(40));
- Assert.True(from.Length == 10);
- Assert.Equal("[object Uint32Array]", objectPrototype.Call(from));
- }
-
- [Theory]
- [MemberData(nameof(Object_Prototype))]
- public static void Int8ArrayFromArrayBuffer(Function objectPrototype)
- {
- Int8Array from = new Int8Array(new ArrayBuffer(50));
- Assert.True(from.Length == 50);
- Assert.Equal("[object Int8Array]", objectPrototype.Call(from));
- }
-
- [Theory]
- [MemberData(nameof(Object_Prototype))]
- public static void Int16ArrayFromArrayBuffer(Function objectPrototype)
- {
- Int16Array from = new Int16Array(new ArrayBuffer(50));
- Assert.True(from.Length == 25);
- Assert.Equal("[object Int16Array]", objectPrototype.Call(from));
- }
-
- [Theory]
- [MemberData(nameof(Object_Prototype))]
- public static void Int32ArrayFromArrayBuffer(Function objectPrototype)
- {
- Int32Array from = new Int32Array(new ArrayBuffer(40));
- Assert.True(from.Length == 10);
- Assert.Equal("[object Int32Array]", objectPrototype.Call(from));
- }
-
- [Theory]
- [MemberData(nameof(Object_Prototype))]
- public static void Float32ArrayFromArrayBuffer(Function objectPrototype)
- {
- Float32Array from = new Float32Array(new ArrayBuffer(40));
- Assert.True(from.Length == 10);
- Assert.Equal("[object Float32Array]", objectPrototype.Call(from));
- }
-
- [Theory]
- [MemberData(nameof(Object_Prototype))]
- public static void Float64ArrayFromArrayBuffer(Function objectPrototype)
- {
- Float64Array from = new Float64Array(new ArrayBuffer(40));
- Assert.True(from.Length == 5);
- Assert.Equal("[object Float64Array]", objectPrototype.Call(from));
- }
-
- [Fact]
- public static void TypedArrayTypeUint8ClampedArray()
- {
- Assert.Equal(TypedArrayTypeCode.Uint8ClampedArray, new Uint8ClampedArray().GetTypedArrayType());
- }
-
- [Fact]
- public static void TypedArrayTypeUint8Array()
- {
- Assert.Equal(TypedArrayTypeCode.Uint8Array, new Uint8Array().GetTypedArrayType());
- }
-
- [Fact]
- public static void TypedArrayTypeUint16Array()
- {
- Assert.Equal(TypedArrayTypeCode.Uint16Array, new Uint16Array().GetTypedArrayType());
- }
-
- [Fact]
- public static void TypedArrayTypeUint32Array()
- {
- Assert.Equal(TypedArrayTypeCode.Uint32Array, new Uint32Array().GetTypedArrayType());
- }
-
- [Fact]
- public static void TypedArrayTypeInt8Array()
- {
- Assert.Equal(TypedArrayTypeCode.Int8Array, new Int8Array().GetTypedArrayType());
- }
-
- [Fact]
- public static void TypedArrayTypeInt16Array()
- {
- Assert.Equal(TypedArrayTypeCode.Int16Array, new Int16Array().GetTypedArrayType());
- }
-
- [Fact]
- public static void TypedArrayTypeInt32Array()
- {
- Assert.Equal(TypedArrayTypeCode.Int32Array, new Int32Array().GetTypedArrayType());
- }
-
- [Fact]
- public static void TypedArrayTypeFloat32Array()
- {
- Assert.Equal(TypedArrayTypeCode.Float32Array, new Float32Array().GetTypedArrayType());
- }
-
- [Fact]
- public static void TypedArrayTypeFloat64Array()
- {
- Assert.Equal(TypedArrayTypeCode.Float64Array, new Float64Array().GetTypedArrayType());
- }
}
}
diff --git a/src/mono/wasm/runtime/cancelable-promise.ts b/src/mono/wasm/runtime/cancelable-promise.ts
index 8b749498354..83fd769f57c 100644
--- a/src/mono/wasm/runtime/cancelable-promise.ts
+++ b/src/mono/wasm/runtime/cancelable-promise.ts
@@ -7,7 +7,7 @@ import { JSHandle, MonoString } from "./types";
import { Int32Ptr } from "./types/emscripten";
export const _are_promises_supported = ((typeof Promise === "object") || (typeof Promise === "function")) && (typeof Promise.resolve === "function");
-const promise_control_symbol = Symbol.for("wasm promise_control");
+export const promise_control_symbol = Symbol.for("wasm promise_control");
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export function isThenable(js_obj: any): boolean {
@@ -31,7 +31,7 @@ export function mono_wasm_cancel_promise(thenable_js_handle: JSHandle, is_except
export interface PromiseControl {
isDone: boolean;
resolve: (data?: any) => void;
- reject: (reason: string) => void;
+ reject: (reason: any) => void;
}
export function _create_cancelable_promise(afterResolve?: () => void, afterReject?: () => void): {
@@ -50,7 +50,7 @@ export function _create_cancelable_promise(afterResolve?: () => void, afterRejec
}
}
},
- reject: (reason: string) => {
+ reject: (reason: any) => {
if (!promise_control!.isDone) {
promise_control!.isDone = true;
reject(reason);
diff --git a/src/mono/wasm/runtime/cjs/dotnet.cjs.lib.js b/src/mono/wasm/runtime/cjs/dotnet.cjs.lib.js
index 93edd268995..664bccf25cd 100644
--- a/src/mono/wasm/runtime/cjs/dotnet.cjs.lib.js
+++ b/src/mono/wasm/runtime/cjs/dotnet.cjs.lib.js
@@ -55,8 +55,6 @@ const linked_functions = [
"mono_wasm_typed_array_copy_to",
"mono_wasm_typed_array_from",
"mono_wasm_typed_array_copy_from",
- "mono_wasm_add_event_listener",
- "mono_wasm_remove_event_listener",
"mono_wasm_cancel_promise",
"mono_wasm_web_socket_open",
"mono_wasm_web_socket_send",
diff --git a/src/mono/wasm/runtime/corebindings.c b/src/mono/wasm/runtime/corebindings.c
index 3f9c744e6d6..c22d5e39d3e 100644
--- a/src/mono/wasm/runtime/corebindings.c
+++ b/src/mono/wasm/runtime/corebindings.c
@@ -26,8 +26,6 @@ extern MonoObject* mono_wasm_typed_array_to_array (int js_handle, int *is_except
extern MonoObject* mono_wasm_typed_array_copy_to (int js_handle, int ptr, int begin, int end, int bytes_per_element, int *is_exception);
extern MonoObject* mono_wasm_typed_array_from (int ptr, int begin, int end, int bytes_per_element, int type, int *is_exception);
extern MonoObject* mono_wasm_typed_array_copy_from (int js_handle, int ptr, int begin, int end, int bytes_per_element, int *is_exception);
-extern MonoString* mono_wasm_add_event_listener (int jsObjHandle, MonoString *name, int weakDelegateHandle, int optionsObjHandle);
-extern MonoString* mono_wasm_remove_event_listener (int jsObjHandle, MonoString *name, int weakDelegateHandle, int capture);
extern MonoString* mono_wasm_cancel_promise (int thenable_js_handle, int *is_exception);
extern MonoObject* mono_wasm_web_socket_open (MonoString *uri, MonoArray *subProtocols, MonoDelegate *on_close, int *web_socket_js_handle, int *thenable_js_handle, int *is_exception);
extern MonoObject* mono_wasm_web_socket_send (int webSocket_js_handle, void* buffer_ptr, int offset, int length, int message_type, int end_of_message, int *thenable_js_handle, int *is_exception);
@@ -51,8 +49,6 @@ void core_initialize_internals ()
mono_add_internal_call ("Interop/Runtime::TypedArrayFrom", mono_wasm_typed_array_from);
mono_add_internal_call ("Interop/Runtime::TypedArrayCopyFrom", mono_wasm_typed_array_copy_from);
mono_add_internal_call ("Interop/Runtime::CompileFunction", mono_wasm_compile_function);
- mono_add_internal_call ("Interop/Runtime::AddEventListener", mono_wasm_add_event_listener);
- mono_add_internal_call ("Interop/Runtime::RemoveEventListener", mono_wasm_remove_event_listener);
mono_add_internal_call ("Interop/Runtime::WebSocketOpen", mono_wasm_web_socket_open);
mono_add_internal_call ("Interop/Runtime::WebSocketSend", mono_wasm_web_socket_send);
mono_add_internal_call ("Interop/Runtime::WebSocketReceive", mono_wasm_web_socket_receive);
@@ -70,7 +66,7 @@ void core_initialize_internals ()
// Uint32Array | uint32_t | uint (unsigned integer)
// Float32Array | float | float
// Float64Array | double | double
-// typed array marshalling
+// typed array marshaling
#define MARSHAL_ARRAY_BYTE 10
#define MARSHAL_ARRAY_UBYTE 11
#define MARSHAL_ARRAY_UBYTE_C 12 // alias of MARSHAL_ARRAY_UBYTE
diff --git a/src/mono/wasm/runtime/cs-to-js.ts b/src/mono/wasm/runtime/cs-to-js.ts
index de208efe3c9..591f654b0b6 100644
--- a/src/mono/wasm/runtime/cs-to-js.ts
+++ b/src/mono/wasm/runtime/cs-to-js.ts
@@ -69,7 +69,7 @@ function _unbox_mono_obj_root_with_known_nonprimitive_type_impl(root: WasmRoot<a
case MarshalType.ARRAY_UINT:
case MarshalType.ARRAY_FLOAT:
case MarshalType.ARRAY_DOUBLE:
- throw new Error("Marshalling of primitive arrays are not supported. Use the corresponding TypedArray instead.");
+ throw new Error("Marshaling of primitive arrays are not supported.");
case <MarshalType>20: // clr .NET DateTime
return new Date(corebindings._get_date_value(root.value));
case <MarshalType>21: // clr .NET DateTimeOffset
diff --git a/src/mono/wasm/runtime/cwraps.ts b/src/mono/wasm/runtime/cwraps.ts
index c3015f1ef3b..7567ac91411 100644
--- a/src/mono/wasm/runtime/cwraps.ts
+++ b/src/mono/wasm/runtime/cwraps.ts
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
import {
+ assert,
MonoArray, MonoAssembly, MonoClass,
MonoMethod, MonoObject, MonoString,
MonoType
@@ -143,4 +144,12 @@ for (const sig of fn_signatures) {
};
}
-export default wrapped_c_functions; \ No newline at end of file
+export default wrapped_c_functions;
+export function wrap_c_function(name: string): Function {
+ const wf: any = wrapped_c_functions;
+ const sig = fn_signatures.find(s => s[0] === name);
+ assert(sig, () => `Function ${name} not found`);
+ const fce = Module.cwrap(sig[0], sig[1], sig[2], sig[3]);
+ wf[sig[0]] = fce;
+ return fce;
+} \ No newline at end of file
diff --git a/src/mono/wasm/runtime/driver.c b/src/mono/wasm/runtime/driver.c
index 146c9dfb9cf..c5954cf3ef4 100644
--- a/src/mono/wasm/runtime/driver.c
+++ b/src/mono/wasm/runtime/driver.c
@@ -74,7 +74,7 @@ char *mono_method_get_full_name (MonoMethod *method);
#define MARSHAL_TYPE_URI 22
#define MARSHAL_TYPE_SAFEHANDLE 23
-// typed array marshalling
+// typed array marshaling
#define MARSHAL_ARRAY_BYTE 10
#define MARSHAL_ARRAY_UBYTE 11
#define MARSHAL_ARRAY_UBYTE_C 12
diff --git a/src/mono/wasm/runtime/es6/dotnet.es6.lib.js b/src/mono/wasm/runtime/es6/dotnet.es6.lib.js
index 98c6238cd3f..402dd8b15d6 100644
--- a/src/mono/wasm/runtime/es6/dotnet.es6.lib.js
+++ b/src/mono/wasm/runtime/es6/dotnet.es6.lib.js
@@ -92,8 +92,6 @@ const linked_functions = [
"mono_wasm_typed_array_copy_to",
"mono_wasm_typed_array_from",
"mono_wasm_typed_array_copy_from",
- "mono_wasm_add_event_listener",
- "mono_wasm_remove_event_listener",
"mono_wasm_cancel_promise",
"mono_wasm_web_socket_open",
"mono_wasm_web_socket_send",
diff --git a/src/mono/wasm/runtime/event-listener.ts b/src/mono/wasm/runtime/event-listener.ts
deleted file mode 100644
index e2f1b59d4bf..00000000000
--- a/src/mono/wasm/runtime/event-listener.ts
+++ /dev/null
@@ -1,89 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-import { mono_wasm_new_root } from "./roots";
-import { isChromium, prevent_timer_throttling } from "./scheduling";
-import { JSHandle, GCHandle, MonoString, MonoStringNull } from "./types";
-import { _wrap_delegate_gc_handle_as_function } from "./cs-to-js";
-import { mono_wasm_get_jsobj_from_js_handle, _js_owned_object_finalized, _lookup_js_owned_object, _use_finalization_registry } from "./gc-handles";
-import { wrap_error } from "./method-calls";
-import { conv_string } from "./strings";
-
-const listener_registration_count_symbol = Symbol.for("wasm listener_registration_count");
-
-export function mono_wasm_add_event_listener(js_handle: JSHandle, name: MonoString, listener_gc_handle: GCHandle, optionsHandle: JSHandle): MonoString {
- const nameRoot = mono_wasm_new_root(name);
- try {
- const sName = conv_string(nameRoot.value);
-
- const obj = mono_wasm_get_jsobj_from_js_handle(js_handle);
- if (!obj)
- throw new Error("ERR09: Invalid JS object handle for '" + sName + "'");
-
- const throttling = isChromium || obj.constructor.name !== "WebSocket"
- ? undefined
- : prevent_timer_throttling;
-
- const listener = _wrap_delegate_gc_handle_as_function(listener_gc_handle, throttling) as ListenerExtension;
- if (!listener)
- throw new Error("ERR10: Invalid listener gc_handle");
-
- const options = optionsHandle
- ? mono_wasm_get_jsobj_from_js_handle(optionsHandle)
- : null;
-
- if (!_use_finalization_registry) {
- // we are counting registrations because same delegate could be registered into multiple sources
- listener[listener_registration_count_symbol] = listener[listener_registration_count_symbol] ? listener[listener_registration_count_symbol] + 1 : 1;
- }
-
- if (options)
- obj.addEventListener(sName, listener, options);
- else
- obj.addEventListener(sName, listener);
- return MonoStringNull;
- } catch (ex) {
- return wrap_error(null, ex);
- } finally {
- nameRoot.release();
- }
-}
-
-export function mono_wasm_remove_event_listener(js_handle: JSHandle, name: MonoString, listener_gc_handle: GCHandle, capture: boolean): MonoString {
- const nameRoot = mono_wasm_new_root(name);
- try {
-
- const obj = mono_wasm_get_jsobj_from_js_handle(js_handle);
- if (!obj)
- throw new Error("ERR11: Invalid JS object handle");
- const listener = _lookup_js_owned_object(listener_gc_handle) as ListenerExtension;
- // Removing a nonexistent listener should not be treated as an error
- if (!listener)
- return MonoStringNull;
- const sName = conv_string(nameRoot.value);
-
- obj.removeEventListener(sName, listener, !!capture);
- // We do not manually remove the listener from the delegate registry here,
- // because that same delegate may have been used as an event listener for
- // other events or event targets. The GC will automatically clean it up
- // and trigger the FinalizationRegistry handler if it's unused
-
- // When FinalizationRegistry is not supported by this browser, we cleanup manuall after unregistration
- if (!_use_finalization_registry) {
- listener[listener_registration_count_symbol]--;
- if (listener[listener_registration_count_symbol] === 0) {
- _js_owned_object_finalized(listener_gc_handle);
- }
- }
-
- return MonoStringNull;
- } catch (ex) {
- return wrap_error(null, ex);
- } finally {
- nameRoot.release();
- }
-}
-
-type ListenerExtension = Function & {
- [listener_registration_count_symbol]: number
-} \ No newline at end of file
diff --git a/src/mono/wasm/runtime/exports.ts b/src/mono/wasm/runtime/exports.ts
index 8ec6dc161ad..1c1a5cbee49 100644
--- a/src/mono/wasm/runtime/exports.ts
+++ b/src/mono/wasm/runtime/exports.ts
@@ -54,7 +54,6 @@ import {
} from "./method-calls";
import { mono_wasm_typed_array_copy_to, mono_wasm_typed_array_from, mono_wasm_typed_array_copy_from, mono_wasm_load_bytes_into_heap } from "./buffers";
import { mono_wasm_cancel_promise } from "./cancelable-promise";
-import { mono_wasm_add_event_listener, mono_wasm_remove_event_listener } from "./event-listener";
import { mono_wasm_release_cs_owned_object } from "./gc-handles";
import { mono_wasm_web_socket_open, mono_wasm_web_socket_send, mono_wasm_web_socket_receive, mono_wasm_web_socket_close, mono_wasm_web_socket_abort } from "./web-socket";
import cwraps from "./cwraps";
@@ -293,8 +292,6 @@ export const __linker_exports: any = {
mono_wasm_typed_array_copy_to,
mono_wasm_typed_array_from,
mono_wasm_typed_array_copy_from,
- mono_wasm_add_event_listener,
- mono_wasm_remove_event_listener,
mono_wasm_cancel_promise,
mono_wasm_web_socket_open,
mono_wasm_web_socket_send,
diff --git a/src/mono/wasm/runtime/method-binding.ts b/src/mono/wasm/runtime/method-binding.ts
index 04010b20ab7..c7de40542e0 100644
--- a/src/mono/wasm/runtime/method-binding.ts
+++ b/src/mono/wasm/runtime/method-binding.ts
@@ -16,12 +16,11 @@ import {
_get_args_root_buffer_for_method_call, _get_buffer_for_method_call,
_handle_exception_for_call, _teardown_after_call
} from "./method-calls";
-import cwraps from "./cwraps";
+import cwraps, { wrap_c_function } from "./cwraps";
import { VoidPtr } from "./types/emscripten";
const primitiveConverters = new Map<string, Converter>();
const _signature_converters = new Map<string, Converter>();
-const _method_descriptions = new Map<MonoMethod, string>();
export function _get_type_name(typePtr: MonoType): string {
@@ -43,11 +42,7 @@ export function _get_class_name(classPtr: MonoClass): string {
}
export function find_method(klass: MonoClass, name: string, n: number): MonoMethod {
- const result = cwraps.mono_wasm_assembly_find_method(klass, name, n);
- if (result) {
- _method_descriptions.set(result, name);
- }
- return result;
+ return cwraps.mono_wasm_assembly_find_method(klass, name, n);
}
export function get_method(method_name: string): MonoMethod {
@@ -217,7 +212,7 @@ export function _compile_converter_for_marshal_string(args_marshal: string/*Args
const closure: any = {
Module,
_malloc: Module._malloc,
- mono_wasm_unbox_rooted: cwraps.mono_wasm_unbox_rooted,
+ mono_wasm_unbox_rooted: wrap_c_function("mono_wasm_unbox_rooted"),
setI32,
setU32,
setF32,
@@ -403,9 +398,9 @@ export function mono_bind_method(method: MonoMethod, this_arg: MonoObject | null
_get_buffer_for_method_call,
_handle_exception_for_call,
_teardown_after_call,
- mono_wasm_try_unbox_primitive_and_get_type: cwraps.mono_wasm_try_unbox_primitive_and_get_type,
+ mono_wasm_try_unbox_primitive_and_get_type: wrap_c_function("mono_wasm_try_unbox_primitive_and_get_type"),
_unbox_mono_obj_root_with_known_nonprimitive_type,
- invoke_method: cwraps.mono_wasm_invoke_method,
+ invoke_method: wrap_c_function("mono_wasm_invoke_method"),
method,
this_arg,
token,
diff --git a/src/mono/wasm/runtime/method-calls.ts b/src/mono/wasm/runtime/method-calls.ts
index ae2bcb24d27..b5aa2bb2f3c 100644
--- a/src/mono/wasm/runtime/method-calls.ts
+++ b/src/mono/wasm/runtime/method-calls.ts
@@ -155,7 +155,7 @@ export function call_method(method: MonoMethod, this_arg: MonoObject | undefined
let buffer = VoidPtrNull, converter = undefined, argsRootBuffer = undefined;
let is_result_marshaled = true;
- // TODO: Only do this if the signature needs marshalling
+ // TODO: Only do this if the signature needs marshaling
_create_temp_frame();
// check if the method signature needs argument mashalling
@@ -482,7 +482,8 @@ export function mono_method_get_call_signature(method: MonoMethod, mono_obj?: Mo
}
}
-export function mono_method_resolve(fqn: string): MonoMethod {
+export function parseFQN(fqn: string)
+ : { assembly: string, namespace: string, classname: string, methodname: string } {
const assembly = fqn.substring(fqn.indexOf("[") + 1, fqn.indexOf("]")).trim();
fqn = fqn.substring(fqn.indexOf("]") + 1).trim();
@@ -503,6 +504,11 @@ export function mono_method_resolve(fqn: string): MonoMethod {
throw new Error("No class name specified");
if (!methodname.trim())
throw new Error("No method name specified");
+ return { assembly, namespace, classname, methodname };
+}
+
+export function mono_method_resolve(fqn: string): MonoMethod {
+ const { assembly, namespace, classname, methodname } = parseFQN(fqn);
const asm = cwraps.mono_wasm_assembly_load(assembly);
if (!asm)
diff --git a/src/mono/wasm/runtime/startup.ts b/src/mono/wasm/runtime/startup.ts
index 8801ac704b0..44751d8a57a 100644
--- a/src/mono/wasm/runtime/startup.ts
+++ b/src/mono/wasm/runtime/startup.ts
@@ -336,18 +336,7 @@ export function bindings_lazy_init(): void {
(<any>ArrayBuffer.prototype)[wasm_type_symbol] = 2;
(<any>DataView.prototype)[wasm_type_symbol] = 3;
(<any>Function.prototype)[wasm_type_symbol] = 4;
- (<any>Map.prototype)[wasm_type_symbol] = 5;
- if (typeof SharedArrayBuffer !== "undefined")
- (<any>SharedArrayBuffer.prototype)[wasm_type_symbol] = 6;
- (<any>Int8Array.prototype)[wasm_type_symbol] = 10;
(<any>Uint8Array.prototype)[wasm_type_symbol] = 11;
- (<any>Uint8ClampedArray.prototype)[wasm_type_symbol] = 12;
- (<any>Int16Array.prototype)[wasm_type_symbol] = 13;
- (<any>Uint16Array.prototype)[wasm_type_symbol] = 14;
- (<any>Int32Array.prototype)[wasm_type_symbol] = 15;
- (<any>Uint32Array.prototype)[wasm_type_symbol] = 16;
- (<any>Float32Array.prototype)[wasm_type_symbol] = 17;
- (<any>Float64Array.prototype)[wasm_type_symbol] = 18;
runtimeHelpers._box_buffer_size = 65536;
runtimeHelpers._unbox_buffer_size = 65536;
diff --git a/src/mono/wasm/runtime/strings.ts b/src/mono/wasm/runtime/strings.ts
index 02c3b1fa302..da38f2c9100 100644
--- a/src/mono/wasm/runtime/strings.ts
+++ b/src/mono/wasm/runtime/strings.ts
@@ -30,7 +30,7 @@ export class StringDecoder {
pLengthBytes = <any>this.mono_wasm_string_decoder_buffer + 4,
pIsInterned = <any>this.mono_wasm_string_decoder_buffer + 8;
- cwraps.mono_wasm_string_get_data(mono_string, <any>ppChars, <any>pLengthBytes, <any>pIsInterned);
+ cwraps.mono_wasm_string_get_data(this.mono_wasm_string_root.value, <any>ppChars, <any>pLengthBytes, <any>pIsInterned);
let result = mono_wasm_empty_string;
const lengthBytes = getI32(pLengthBytes),
@@ -38,18 +38,16 @@ export class StringDecoder {
isInterned = getI32(pIsInterned);
if (pLengthBytes && pChars) {
- if (
- isInterned &&
-
- interned_string_table.has(<any>mono_string) //TODO remove 2x lookup
- ) {
- result = interned_string_table.get(<any>mono_string)!;
- // console.log(`intern table cache hit ${mono_string} ${result.length}`);
- } else {
+ if (isInterned) {
+ result = interned_string_table.get(<any>this.mono_wasm_string_root.value)!;
+ }
+
+ if (!result) {
result = this.decode(<any>pChars, <any>pChars + lengthBytes);
if (isInterned) {
// console.log("interned", mono_string, result.length);
- interned_string_table.set(<any>mono_string, result);
+ interned_string_table.set(<any>this.mono_wasm_string_root.value, result);
+ interned_js_string_table.set(result, <any>this.mono_wasm_string_root.value);
}
}
}
@@ -81,7 +79,7 @@ export class StringDecoder {
}
const interned_string_table = new Map<MonoString, string>();
-const interned_js_string_table = new Map<string, MonoString>();
+export const interned_js_string_table = new Map<string, MonoString>();
let _empty_string_ptr: MonoString = <any>0;
const _interned_string_full_root_buffers = [];
let _interned_string_current_root_buffer: WasmRootBuffer | null = null;
diff --git a/src/mono/wasm/runtime/types.ts b/src/mono/wasm/runtime/types.ts
index cc0d1b24583..d56656f885e 100644
--- a/src/mono/wasm/runtime/types.ts
+++ b/src/mono/wasm/runtime/types.ts
@@ -40,8 +40,10 @@ export const MonoTypeNull: MonoType = <MonoType><any>0;
export const MonoStringNull: MonoString = <MonoString><any>0;
export const JSHandleDisposed: JSHandle = <JSHandle><any>-1;
export const JSHandleNull: JSHandle = <JSHandle><any>0;
+export const GCHandleNull: GCHandle = <GCHandle><any>0;
export const VoidPtrNull: VoidPtr = <VoidPtr><any>0;
export const CharPtrNull: CharPtr = <CharPtr><any>0;
+export const NativePointerNull: NativePointer = <NativePointer><any>0;
export function coerceNull<T extends ManagedPointer | NativePointer>(ptr: T | null | undefined): T {
return (<any>ptr | <any>0) as any;
@@ -188,9 +190,13 @@ export type DotnetModuleConfigImports = {
url?: any;
}
-export function assert(condition: unknown, messsage: string): asserts condition {
+export function assert(condition: unknown, messageFactory: string | (() => string)): asserts condition {
if (!condition) {
- throw new Error(`Assert failed: ${messsage}`);
+ const message = typeof messageFactory === "string"
+ ? messageFactory
+ : messageFactory();
+ console.error(`Assert failed: ${message}`);
+ throw new Error(`Assert failed: ${message}`);
}
}
diff --git a/src/mono/wasm/runtime/web-socket.ts b/src/mono/wasm/runtime/web-socket.ts
index 3a6753b4f7f..e013e867aef 100644
--- a/src/mono/wasm/runtime/web-socket.ts
+++ b/src/mono/wasm/runtime/web-socket.ts
@@ -343,7 +343,7 @@ function _mono_wasm_web_socket_on_message(ws: WebSocketExtension, event: Message
});
}
if (promise_queue.getLength() && event_queue.getLength() > 1) {
- throw new Error("ERR20: Invalid WS state");// assert
+ throw new Error("ERR21: Invalid WS state");// assert
}
while (promise_queue.getLength() && event_queue.getLength()) {
const promise_control = promise_queue.dequeue()!;
diff --git a/src/mono/wasm/wasm.proj b/src/mono/wasm/wasm.proj
index df423fbf994..7e79a2eaea5 100644
--- a/src/mono/wasm/wasm.proj
+++ b/src/mono/wasm/wasm.proj
@@ -119,8 +119,8 @@
<_EmccLinkFlags Include="-s FORCE_FILESYSTEM=1" />
<_EmccLinkFlags Include="-s EXPORTED_RUNTIME_METHODS=&quot;['FS','print','ccall','cwrap','setValue','getValue','UTF8ToString','UTF8ArrayToString','FS_createPath','FS_createDataFile','removeRunDependency','addRunDependency', 'FS_readFile']&quot;" />
<!-- _htons,_ntohs,__get_daylight,__get_timezone,__get_tzname are exported temporarily, until the issue is fixed in emscripten, https://github.com/dotnet/runtime/issues/64724 -->
- <_EmccLinkFlags Include="-s EXPORTED_FUNCTIONS=_free,_malloc,_memalign,_memset" Condition="$([MSBuild]::VersionGreaterThan('$(_EmccVersion)', '3.0'))" />
- <_EmccLinkFlags Include="-s EXPORTED_FUNCTIONS=_free,_malloc,_htons,_ntohs,__get_daylight,__get_timezone,__get_tzname,_memalign" Condition="$([MSBuild]::VersionLessThan('$(_EmccVersion)', '3.0'))" />
+ <_EmccLinkFlags Include="-s EXPORTED_FUNCTIONS=_free,_malloc,stackSave,stackRestore,stackAlloc,_memalign,_memset" Condition="$([MSBuild]::VersionGreaterThan('$(_EmccVersion)', '3.0'))" />
+ <_EmccLinkFlags Include="-s EXPORTED_FUNCTIONS=_free,_malloc,stackSave,stackRestore,stackAlloc,_htons,_ntohs,__get_daylight,__get_timezone,__get_tzname,_memalign" Condition="$([MSBuild]::VersionLessThan('$(_EmccVersion)', '3.0'))" />
<_EmccLinkFlags Include="--source-map-base http://example.com" />
<_EmccLinkFlags Include="-s STRICT_JS=1" />
<_EmccLinkFlags Include="-s EXPORT_NAME=&quot;'createDotnetRuntime'&quot;" />