From b6d8ebd81c2a006ff592667d2c3d559cc4c7933c Mon Sep 17 00:00:00 2001 From: Kenneth Pouncey Date: Tue, 2 Jun 2020 16:47:09 +0200 Subject: [PATCH] [browser][wasm] Wasm address miscellaneous code comments (#37235) * Remove custom messages being passed to PNSE. * Address miscellaneous code review comments - Remove unnecessary sealed - implement Properties instead of throwing PNSE - refactoring to avoid the explicit static cctor * Add extra new line at end of file * Remove TODO comments --- .../Http/BrowserHttpHandler/BrowserHttpHandler.cs | 12 ++-- .../Http/BrowserHttpHandler/SocketsHttpHandler.cs | 80 +++++++++++----------- .../Directory.Build.props | 2 +- .../Runtime/InteropServices/JavaScript/Map.cs | 7 -- 4 files changed, 47 insertions(+), 54 deletions(-) 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 a046f0a..0b4b513 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 @@ -36,12 +36,11 @@ namespace System.Net.Http /// /// Gets whether the current Browser supports streaming responses /// - private static bool StreamingSupported { get; } - - static BrowserHttpHandler() + private static bool StreamingSupported { get; } = GetIsStreamingSupported(); + private static bool GetIsStreamingSupported() { using (var streamingSupported = new Function("return typeof Response !== 'undefined' && 'body' in Response.prototype && typeof ReadableStream === 'function'")) - StreamingSupported = (bool)streamingSupported.Call(); + return (bool)streamingSupported.Call(); } public bool UseCookies @@ -122,7 +121,8 @@ namespace System.Net.Http set => throw new PlatformNotSupportedException(); } - public IDictionary Properties => throw new PlatformNotSupportedException(); + private Dictionary? _properties; + public IDictionary Properties => _properties ??= new Dictionary(); protected internal override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { @@ -367,7 +367,7 @@ namespace System.Net.Http protected override Task SerializeToStreamAsync(Stream stream, TransportContext? context) => SerializeToStreamAsync(stream, context, CancellationToken.None); - protected sealed override async Task SerializeToStreamAsync(Stream stream, TransportContext? context, CancellationToken cancellationToken) + protected override async Task SerializeToStreamAsync(Stream stream, TransportContext? context, CancellationToken cancellationToken) { byte[] data = await GetResponseData().ConfigureAwait(continueOnCapturedContext: true); await stream.WriteAsync(data, 0, data.Length, cancellationToken).ConfigureAwait(continueOnCapturedContext: true); diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/SocketsHttpHandler.cs b/src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/SocketsHttpHandler.cs index a2d41cd..16ddc93 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/SocketsHttpHandler.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/SocketsHttpHandler.cs @@ -14,123 +14,123 @@ namespace System.Net.Http { public bool UseCookies { - get => throw new PlatformNotSupportedException("Property UseCookies is not supported."); - set => throw new PlatformNotSupportedException("Property UseCookies is not supported."); + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } [AllowNull] public CookieContainer CookieContainer { - get => throw new PlatformNotSupportedException("Property CookieContainer is not supported."); - set => throw new PlatformNotSupportedException("Property CookieContainer is not supported."); + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } public DecompressionMethods AutomaticDecompression { - get => throw new PlatformNotSupportedException("Property AutomaticDecompression is not supported."); - set => throw new PlatformNotSupportedException("Property AutomaticDecompression is not supported."); + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } public bool UseProxy { - get => throw new PlatformNotSupportedException("Property UseProxy is not supported."); - set => throw new PlatformNotSupportedException("Property UseProxy is not supported."); + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } public IWebProxy? Proxy { - get => throw new PlatformNotSupportedException("Property Proxy is not supported."); - set => throw new PlatformNotSupportedException("Property Proxy is not supported."); + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } public ICredentials? DefaultProxyCredentials { - get => throw new PlatformNotSupportedException("Property Credentials is not supported."); - set => throw new PlatformNotSupportedException("Property Credentials is not supported."); + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } public bool PreAuthenticate { - get => throw new PlatformNotSupportedException("Property PreAuthenticate is not supported."); - set => throw new PlatformNotSupportedException("Property PreAuthenticate is not supported."); + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } public ICredentials? Credentials { - get => throw new PlatformNotSupportedException("Property Credentials is not supported."); - set => throw new PlatformNotSupportedException("Property Credentials is not supported."); + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } public bool AllowAutoRedirect { - get => throw new PlatformNotSupportedException("Property AllowAutoRedirect is not supported."); - set => throw new PlatformNotSupportedException("Property AllowAutoRedirect is not supported."); + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } public int MaxAutomaticRedirections { - get => throw new PlatformNotSupportedException("Property MaxAutomaticRedirections is not supported."); - set => throw new PlatformNotSupportedException("Property MaxAutomaticRedirections is not supported."); + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } public int MaxConnectionsPerServer { - get => throw new PlatformNotSupportedException("Property MaxConnectionsPerServer is not supported."); - set => throw new PlatformNotSupportedException("Property MaxConnectionsPerServer is not supported."); + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } public int MaxResponseDrainSize { - get => throw new PlatformNotSupportedException("Property MaxResponseDrainSize is not supported."); - set => throw new PlatformNotSupportedException("Property MaxResponseDrainSize is not supported."); + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } public TimeSpan ResponseDrainTimeout { - get => throw new PlatformNotSupportedException("Property ResponseDrainTimeout is not supported."); - set => throw new PlatformNotSupportedException("Property ResponseDrainTimeout is not supported."); + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } public int MaxResponseHeadersLength { - get => throw new PlatformNotSupportedException("Property MaxResponseHeadersLength is not supported."); - set => throw new PlatformNotSupportedException("Property MaxResponseHeadersLength is not supported."); + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } [AllowNull] public SslClientAuthenticationOptions SslOptions { - get => throw new PlatformNotSupportedException("Property SslOptions is not supported."); - set => throw new PlatformNotSupportedException("Property SslOptions is not supported."); + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } public TimeSpan PooledConnectionLifetime { - get => throw new PlatformNotSupportedException("Property PooledConnectionLifetime is not supported."); - set => throw new PlatformNotSupportedException("Property PooledConnectionLifetime is not supported."); + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } public TimeSpan PooledConnectionIdleTimeout { - get => throw new PlatformNotSupportedException("Property PooledConnectionLifetime is not supported."); - set => throw new PlatformNotSupportedException("Property PooledConnectionLifetime is not supported."); + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } public TimeSpan ConnectTimeout { - get => throw new PlatformNotSupportedException("Property ConnectTimeout is not supported."); - set => throw new PlatformNotSupportedException("Property ConnectTimeout is not supported."); + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } public TimeSpan Expect100ContinueTimeout { - get => throw new PlatformNotSupportedException("Property Expect100ContinueTimeout is not supported."); - set => throw new PlatformNotSupportedException("Property Expect100ContinueTimeout is not supported."); + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - public IDictionary Properties => throw new PlatformNotSupportedException("Property Properties is not supported."); + public IDictionary Properties => throw new PlatformNotSupportedException(); protected internal override Task SendAsync( - HttpRequestMessage request, CancellationToken cancellationToken) => throw new PlatformNotSupportedException("Method SendAsync is not supported."); + HttpRequestMessage request, CancellationToken cancellationToken) => throw new PlatformNotSupportedException(); } } diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/Directory.Build.props b/src/libraries/System.Runtime.InteropServices.JavaScript/Directory.Build.props index 465e111..5f6e490 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/Directory.Build.props +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/Directory.Build.props @@ -4,4 +4,4 @@ Microsoft true - \ No newline at end of file + diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Map.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Map.cs index 95a61d2..6b70df7 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Map.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Map.cs @@ -236,20 +236,13 @@ namespace System.Runtime.InteropServices.JavaScript { if (!_disposedValue) { - if (disposing) - { - // TODO: dispose managed state (managed objects). - } - // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below. - // TODO: set large fields to null. _mapItemIterator?.Dispose(); _mapItemIterator = null; _disposedValue = true; } } - //TODO: override a finalizer only if Dispose (bool disposing) above has code to free unmanaged resources. ~MapItemEnumerator() { // Do not change this code. Put cleanup code in Dispose(bool disposing) above. -- 2.7.4