diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
index 0759d0370079f..4d0b7b0787bff 100644
--- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
+++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
@@ -2529,9 +2529,9 @@
-
+
-
+
diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPool.Portable.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPool.Portable.cs
index 39e1d6453263e..a9c4e038129a4 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPool.Portable.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPool.Portable.cs
@@ -19,7 +19,9 @@ public static partial class ThreadPool
{
// Indicates whether the thread pool should yield the thread from the dispatch loop to the runtime periodically so that
// the runtime may use the thread for processing other work
+#if !(TARGET_BROWSER && FEATURE_WASM_THREADS)
internal static bool YieldFromDispatchLoop => false;
+#endif
#if NATIVEAOT
private const bool IsWorkerTrackingEnabledInConfig = false;
diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Interop/LegacyExports.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Interop/LegacyExports.cs
index 38605743fad93..c15b81826b0fb 100644
--- a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Interop/LegacyExports.cs
+++ b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Interop/LegacyExports.cs
@@ -32,18 +32,15 @@ internal static void PreventTrimming()
public static void GetCSOwnedObjectByJSHandleRef(nint jsHandle, int shouldAddInflight, out JSObject? result)
{
- lock (JSHostImplementation.s_csOwnedObjects)
+ if (JSHostImplementation.ThreadCsOwnedObjects.TryGetValue((int)jsHandle, out WeakReference? reference))
{
- if (JSHostImplementation.s_csOwnedObjects.TryGetValue((int)jsHandle, out WeakReference? reference))
+ reference.TryGetTarget(out JSObject? jsObject);
+ if (shouldAddInflight != 0)
{
- reference.TryGetTarget(out JSObject? jsObject);
- if (shouldAddInflight != 0)
- {
- jsObject?.AddInFlight();
- }
- result = jsObject;
- return;
+ jsObject?.AddInFlight();
}
+ result = jsObject;
+ return;
}
result = null;
}
@@ -77,14 +74,12 @@ public static void CreateCSOwnedProxyRef(nint jsHandle, LegacyHostImplementation
JSObject? res = null;
- lock (JSHostImplementation.s_csOwnedObjects)
+ if (!JSHostImplementation.ThreadCsOwnedObjects.TryGetValue((int)jsHandle, out WeakReference? reference) ||
+ !reference.TryGetTarget(out res) ||
+ res.IsDisposed)
{
- if (!JSHostImplementation.s_csOwnedObjects.TryGetValue((int)jsHandle, out WeakReference? reference) ||
- !reference.TryGetTarget(out res) ||
- res.IsDisposed)
- {
#pragma warning disable CS0612 // Type or member is obsolete
- res = mappedType switch
+ res = mappedType switch
{
LegacyHostImplementation.MappedType.JSObject => new JSObject(jsHandle),
LegacyHostImplementation.MappedType.Array => new Array(jsHandle),
@@ -95,8 +90,7 @@ public static void CreateCSOwnedProxyRef(nint jsHandle, LegacyHostImplementation
_ => throw new ArgumentOutOfRangeException(nameof(mappedType))
};
#pragma warning restore CS0612 // Type or member is obsolete
- JSHostImplementation.s_csOwnedObjects[(int)jsHandle] = new WeakReference(res, trackResurrection: true);
- }
+ JSHostImplementation.ThreadCsOwnedObjects[(int)jsHandle] = new WeakReference(res, trackResurrection: true);
}
if (shouldAddInflight != 0)
{
diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSHostImplementation.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSHostImplementation.cs
index 7738bb834fc21..b439586d21301 100644
--- a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSHostImplementation.cs
+++ b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSHostImplementation.cs
@@ -15,7 +15,20 @@ internal static partial class JSHostImplementation
private const string TaskGetResultName = "get_Result";
private static MethodInfo? s_taskGetResultMethodInfo;
// we use this to maintain identity of JSHandle for a JSObject proxy
- public static readonly Dictionary> s_csOwnedObjects = new Dictionary>();
+#if FEATURE_WASM_THREADS
+ [ThreadStatic]
+#endif
+ private static Dictionary>? s_csOwnedObjects;
+
+ public static Dictionary> ThreadCsOwnedObjects
+ {
+ get
+ {
+ s_csOwnedObjects ??= new ();
+ return s_csOwnedObjects;
+ }
+ }
+
// we use this to maintain identity of GCHandle for a managed object
public static Dictionary