[browser][wasm] Wasm address miscellaneous code comments (#37235)
authorKenneth Pouncey <kjpou@pt.lu>
Tue, 2 Jun 2020 14:47:09 +0000 (16:47 +0200)
committerGitHub <noreply@github.com>
Tue, 2 Jun 2020 14:47:09 +0000 (16:47 +0200)
* 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

src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs
src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/SocketsHttpHandler.cs
src/libraries/System.Runtime.InteropServices.JavaScript/Directory.Build.props
src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Map.cs

index a046f0a..0b4b513 100644 (file)
@@ -36,12 +36,11 @@ namespace System.Net.Http
         /// <summary>
         /// Gets whether the current Browser supports streaming responses
         /// </summary>
-        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<string, object?> Properties => throw new PlatformNotSupportedException();
+        private Dictionary<string, object?>? _properties;
+        public IDictionary<string, object?> Properties => _properties ??= new Dictionary<string, object?>();
 
         protected internal override async Task<HttpResponseMessage> 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);
index a2d41cd..16ddc93 100644 (file)
@@ -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<string, object?> Properties => throw new PlatformNotSupportedException("Property Properties is not supported.");
+        public IDictionary<string, object?> Properties => throw new PlatformNotSupportedException();
 
         protected internal override Task<HttpResponseMessage> SendAsync(
-            HttpRequestMessage request, CancellationToken cancellationToken) => throw new PlatformNotSupportedException("Method SendAsync is not supported.");
+            HttpRequestMessage request, CancellationToken cancellationToken) => throw new PlatformNotSupportedException();
     }
 }
index 465e111..5f6e490 100644 (file)
@@ -4,4 +4,4 @@
     <StrongNameKeyId>Microsoft</StrongNameKeyId>
     <IsNETCoreApp>true</IsNETCoreApp>
   </PropertyGroup>
-</Project>
\ No newline at end of file
+</Project>
index 95a61d2..6b70df7 100644 (file)
@@ -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.