Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Mark some APIs throwing PNSE from runtime as unsupported on Browser #42310

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
**
=============================================================================*/

using System.Runtime.CompilerServices;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;

namespace System.Threading
{
Expand Down Expand Up @@ -170,28 +171,33 @@ public static bool IsEntered(object obj)
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern bool ObjWait(bool exitContext, int millisecondsTimeout, object obj);

[UnsupportedOSPlatform("browser")]
public static bool Wait(object obj, int millisecondsTimeout, bool exitContext)
{
if (obj == null)
throw (new ArgumentNullException(nameof(obj)));
return ObjWait(exitContext, millisecondsTimeout, obj);
}

[UnsupportedOSPlatform("browser")]
public static bool Wait(object obj, TimeSpan timeout, bool exitContext)
{
return Wait(obj, MillisecondsTimeoutFromTimeSpan(timeout), exitContext);
}

[UnsupportedOSPlatform("browser")]
public static bool Wait(object obj, int millisecondsTimeout)
{
return Wait(obj, millisecondsTimeout, false);
}

[UnsupportedOSPlatform("browser")]
public static bool Wait(object obj, TimeSpan timeout)
{
return Wait(obj, MillisecondsTimeoutFromTimeSpan(timeout), false);
}

[UnsupportedOSPlatform("browser")]
public static bool Wait(object obj)
{
return Wait(obj, Timeout.Infinite, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Versioning;

namespace System.Threading
{
Expand Down Expand Up @@ -182,6 +183,7 @@ internal ThreadHandle GetNativeHandle()
/// method on the IThreadable interface passed in the constructor. Once the
/// thread is dead, it cannot be restarted with another call to Start.
/// </summary>
[UnsupportedOSPlatform("browser")]
public void Start(object? parameter)
{
// In the case of a null delegate (second call to start on same thread)
Expand All @@ -196,6 +198,7 @@ public void Start(object? parameter)
Start();
}

[UnsupportedOSPlatform("browser")]
public void Start()
{
#if FEATURE_COMINTEROP_APARTMENT_SUPPORT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ public static void SetData(System.LocalDataStoreSlot slot, object? data) { }
public static void Sleep(int millisecondsTimeout) { }
public static void Sleep(System.TimeSpan timeout) { }
public static void SpinWait(int iterations) { }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public void Start() { }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public void Start(object? parameter) { }
[System.ObsoleteAttribute("Thread.Suspend has been deprecated. Please use other classes in System.Threading, such as Monitor, Mutex, Event, and Semaphore, to synchronize Threads or protect resources. https://go.microsoft.com/fwlink/?linkid=14202", false)]
public void Suspend() { }
Expand Down
5 changes: 5 additions & 0 deletions src/libraries/System.Threading/ref/System.Threading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,15 @@ public static void TryEnter(object obj, ref bool lockTaken) { }
public static void TryEnter(object obj, int millisecondsTimeout, ref bool lockTaken) { }
public static bool TryEnter(object obj, System.TimeSpan timeout) { throw null; }
public static void TryEnter(object obj, System.TimeSpan timeout, ref bool lockTaken) { }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public static bool Wait(object obj) { throw null; }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public static bool Wait(object obj, int millisecondsTimeout) { throw null; }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public static bool Wait(object obj, int millisecondsTimeout, bool exitContext) { throw null; }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public static bool Wait(object obj, System.TimeSpan timeout) { throw null; }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public static bool Wait(object obj, System.TimeSpan timeout, bool exitContext) { throw null; }
}
public sealed partial class Mutex : System.Threading.WaitHandle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.CompilerServices;
using System.Runtime.Versioning;

namespace System.Threading
{
Expand Down Expand Up @@ -80,19 +81,24 @@ public static bool IsEntered(object obj)
return IsEnteredNative(obj);
}

[UnsupportedOSPlatform("browser")]
public static bool Wait(object obj, int millisecondsTimeout, bool exitContext)
{
if (obj == null)
throw new ArgumentNullException(nameof(obj));
return ObjWait(exitContext, millisecondsTimeout, obj);
}

[UnsupportedOSPlatform("browser")]
public static bool Wait(object obj, TimeSpan timeout, bool exitContext) => Wait(obj, MillisecondsTimeoutFromTimeSpan(timeout), exitContext);

[UnsupportedOSPlatform("browser")]
public static bool Wait(object obj, int millisecondsTimeout) => Wait(obj, millisecondsTimeout, false);

[UnsupportedOSPlatform("browser")]
public static bool Wait(object obj, TimeSpan timeout) => Wait(obj, MillisecondsTimeoutFromTimeSpan(timeout), false);

[UnsupportedOSPlatform("browser")]
public static bool Wait(object obj) => Wait(obj, Timeout.Infinite, false);

public static void Pulse(object obj)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;

namespace System.Threading
{
Expand Down Expand Up @@ -251,11 +252,13 @@ public static void Sleep(int millisecondsTimeout)

internal static void UninterruptibleSleep0() => SleepInternal(0, false);

[UnsupportedOSPlatform("browser")]
public void Start()
{
StartInternal(this);
}

[UnsupportedOSPlatform("browser")]
public void Start(object parameter)
{
if (m_start is ThreadStart)
Expand Down