[wasm] Initial addition of Browser WebAssembly support (#35573)
authorKenneth Pouncey <kjpou@pt.lu>
Mon, 1 Jun 2020 05:37:19 +0000 (07:37 +0200)
committerGitHub <noreply@github.com>
Mon, 1 Jun 2020 05:37:19 +0000 (07:37 +0200)
commitca527ba36844ea8c6c04283f90398f5277c7b5fb
tree16357b22953a34203a9c467203fec94926243ebe
parentbdf6a5a0e86101d438316c83d420eb03624b5fc4
[wasm] Initial addition of Browser WebAssembly support (#35573)

* Add Browser specific files to the project

* Browser specific file modification to not include Quic support

* Add Browser specific support files for Http Handler code

* Add Interop code for JavaScript support

* Remove unused reference

* Add Http handler bindings implementation

- This still needs to have the code implement nullable

* Nullable support

* Add browser files back after upstream merge conflict

* Use attribute Link syntax for Common files to bring in sync with existing format

* Address Missing license header

* Code formatting and removal of comment code.

* Address PR comments.

* Address commit comments

* Add blank line between License and first line of code.  Address comments

* Replace SocketsHttpHandler build for Browser.

- Throws `PlatformNotSupportedException` for properties and methods of the HttpMessageHandler abstract implementation.

* Cleanup SendAsync code when doing the call out to JavaScript Fetch.

- Addresses commit comments.

* Refactor BrowserHttpHandler code.

* Cleanup

* Remove null check as it should be checked in outer classes

* Cleanup var usage to use explicit type.  Address commit comments

- For all of these vars, please replace them with the actual type, except when the type is obvious from a new or explicit cast on the right-hand side.

* Move `.ConfigureAwait(true)` to `.ConfigureAwait(false)`

- Address review comments

* Change accessor of Runtime javascript interop methods.

* Change accessor of Runtime javascript interop methods.

* Address review comments for unused code

* Cleanup leftover debug WriteLines

* Remove the AllowNull attributes as per review comments.

* Update src/libraries/Common/src/Interop/Browser/Interop.Runtime.cs

Co-Authored-By: Marek Safar <marek.safar@gmail.com>
* throw different exception type as per review comment

* use char[] array instead and return new string(array).

- Address review comments

* Initial addition of Browser Interop library

* use char[] array instead and return new string(array).

- Address review comments

* Add project references so the Interop.JavaScript project builds

* Coding Style update

* Split the runtime methods into two modules.

- .Api contains the methods that are only used internally from JavaScript bindings code.

* Move System.Runtime.Interop.JavaScript to \src\libraries

- Address review comments

* Change preprocessor to upper case TARGETS_BROWSER

- Address review comments

* Update src/libraries/Common/src/Interop/Browser/Interop.Runtime.Api.cs

Co-authored-by: Marek Safar <marek.safar@gmail.com>
* Update src/libraries/Common/src/Interop/Browser/Interop.Runtime.Api.cs

Co-authored-by: Marek Safar <marek.safar@gmail.com>
* Update src/libraries/Common/src/Interop/Browser/Interop.Runtime.Api.cs

Co-authored-by: Marek Safar <marek.safar@gmail.com>
* Rename from .Api to .Bridge to address review comments

* Modify .csproj files to reflect .Bridge.cs change.

* Remove unnecessary constant

* Add docs

* Update Bridge link

* Collapse code as per review comment.

* Address review comments on `Task.ConfigureAwait(continueOnCapturedContext: true)`.

- Added comment in source code.

* Address review comment about using PropertyInfo reflection.

- GetMethod("get_Result") is less expensive to use.

* Coding Style - Address review comments

* Part of code style and object documentation to partially address review comments.

* Update src/libraries/Common/src/Interop/Browser/Interop.JavaScript.JSObject.cs

Co-authored-by: Stephen Toub <stoub@microsoft.com>
* Update src/libraries/Common/src/Interop/Browser/Interop.Runtime.Bridge.cs

Co-authored-by: Stephen Toub <stoub@microsoft.com>
* Update src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs

Co-authored-by: Stephen Toub <stoub@microsoft.com>
* Update src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs

Co-authored-by: Stephen Toub <stoub@microsoft.com>
* Update src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs

Co-authored-by: Stephen Toub <stoub@microsoft.com>
* Update src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs

Co-authored-by: Stephen Toub <stoub@microsoft.com>
* Update src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs

Co-authored-by: Stephen Toub <stoub@microsoft.com>
* Add class docs and code style updates

- Address review comments

* Update src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs

Co-authored-by: Stephen Toub <stoub@microsoft.com>
* Fix badly formed XML

* Update src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs

Co-authored-by: Stephen Toub <stoub@microsoft.com>
* Remove unnecessary Property implementations.

* Update src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs

Co-authored-by: Stephen Toub <stoub@microsoft.com>
* Update code style involving the use of `var`

* Modify the underlying sockets field name.

- address review comments.

* Style and address review comments

* Remove reliance on ConnectHelper.cs code as it is not supported on Browser

- This removes the reliance on the QUIC support.

* Update src/libraries/Common/src/Interop/Browser/Interop.Runtime.Bridge.cs

Co-authored-by: Stephen Toub <stoub@microsoft.com>
* Remove null check for httpresponse.Content as it is always assigned to.

- Address review comments

* Address review comments

* Remove methods that will not be implemented right now,

* Add properties back to fix build error

- error : MembersMustExist : Member 'public System.Boolean System.Net.Http.SocketsHttpHandler.XXXXXXXXXXXX.get()' does not exist in the implementation but it does exist in the contract.

* Remove tcs TaskCompletionSource to address review comments

* code style change

* Remove disposing of _abortCts here as it causes runtime errors as being disposed of too early

* Address review comment for GetType()

* Rename library as per discussions

* Add lock around the _boundObjects and _rawToJS access.

- Address concurrency review comments

* Address review comments for disposing of CancellationTokenSource

* Address new HttpContent overloads in .NET 5 that take CancellationToken

* Add project and test structure for JavaScript InteropServices

* Remove previous modification as it is no longer needed.

* Update src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs

Co-authored-by: Stephen Toub <stoub@microsoft.com>
* Remove custom message passed to the PNSE .ctor

* Update `mono` to dotnet or .NET

* Address review comment for internal sealed class

* Address extra message text

* Move these source modules to System.Runtime.InteropServices.JavaScript

* Add interop source modules to System.Runtime.InteropServices.JavaScript project

* Remove placeholder source

* Reference System.Runtime.InteropServices.JavaScript project

* Address review comments Unsafe.SizeOf

* Finish move of sources to InteropServices.JavaScript

* Remove ActiveIssue to address review comments

* Add core implementations

* Add core object implementation for Map

* Remove unused targetframework

* Fix PNSE in HttpClientHandler .ctor

- When creating an instance of the browser webassembly `System.Net.Http.BrowserHttpHandler` the following error is thrown.

```
System.PlatformNotSupportedException: Operation is not supported on this platform.
    at System.Net.Http.BrowserHttpHandler.get_SslOptions()
    at System.Net.Http.HttpClientHandler.ThrowForModifiedManagedSslOptionsIfStarted()
    at System.Net.Http.HttpClientHandler.set_ClientCertificateOptions(ClientCertificateOption value)
    at System.Net.Http.HttpClientHandler..ctor()
    at System.Net.Http.HttpClient..ctor()

```

* Remove extra parameters to `PlatformNotSupportedException`

* Fix tests due to underlying field name changing and reflection being used to obtain the socket field

Co-authored-by: Marek Safar <marek.safar@gmail.com>
Co-authored-by: Stephen Toub <stoub@microsoft.com>
36 files changed:
src/libraries/Common/src/Interop/Browser/Interop.Runtime.cs [new file with mode: 0644]
src/libraries/Common/tests/System/Net/Http/TestHelper.cs
src/libraries/System.Net.Http/src/System.Net.Http.csproj
src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs [new file with mode: 0644]
src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/SocketsHttpHandler.cs [new file with mode: 0644]
src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/SystemProxyInfo.Browser.cs [new file with mode: 0644]
src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.cs
src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTestBase.SocketsHttpHandler.cs
src/libraries/System.Runtime.InteropServices.JavaScript/Directory.Build.props [new file with mode: 0644]
src/libraries/System.Runtime.InteropServices.JavaScript/System.Runtime.InteropServices.JavaScript.sln [new file with mode: 0644]
src/libraries/System.Runtime.InteropServices.JavaScript/src/System.Runtime.InteropServices.JavaScript.csproj [new file with mode: 0644]
src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/AnyRef.cs [new file with mode: 0644]
src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Array.cs [new file with mode: 0644]
src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/ArrayBuffer.cs [new file with mode: 0644]
src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/CoreObject.cs [new file with mode: 0644]
src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/DataView.cs [new file with mode: 0644]
src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Float32Array.cs [new file with mode: 0644]
src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Float64Array.cs [new file with mode: 0644]
src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Function.cs [new file with mode: 0644]
src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/HostObject.cs [new file with mode: 0644]
src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Int16Array.cs [new file with mode: 0644]
src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Int32Array.cs [new file with mode: 0644]
src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Int8Array.cs [new file with mode: 0644]
src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSException.cs [new file with mode: 0644]
src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSObject.cs [new file with mode: 0644]
src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Map.cs [new file with mode: 0644]
src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Runtime.cs [new file with mode: 0644]
src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/SharedArrayBuffer.cs [new file with mode: 0644]
src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/TypedArray.cs [new file with mode: 0644]
src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Uint16Array.cs [new file with mode: 0644]
src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Uint32Array.cs [new file with mode: 0644]
src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Uint8Array.cs [new file with mode: 0644]
src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Uint8ClampedArray.cs [new file with mode: 0644]
src/libraries/System.Runtime.InteropServices.JavaScript/tests/AssemblyInfo.cs [new file with mode: 0644]
src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.Tests.csproj [new file with mode: 0644]
src/libraries/System.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/JavaScriptTests.cs [new file with mode: 0644]