-
Notifications
You must be signed in to change notification settings - Fork 5.3k
[browser] Fix System.Delegate.DynamicInvoke method can not be resolved #47519
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
Merged
marek-safar
merged 23 commits into
dotnet:master
from
kjpou1:wasm-fix-delegate-trimming
Feb 10, 2021
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
377a8e4
[browser] Fix System.Delegate.DynamicInvoke method can not be resolved
kjpou1 ddb0485
Address review comment for assembly name
kjpou1 84c0ba6
Change this back to mscorlib as the recommended code cause a warning.
kjpou1 e6e8d34
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 ab9ae20
[browser] Remove linker trim exclusions for System.Delegate.DynamicI…
kjpou1 2070cb5
Remove dependency on System.Delegate.DynamicInvoke
kjpou1 255be2f
Add method to retrieve the Invoke method of the delegate
kjpou1 7203cbf
Create another test module for Delegate tests
kjpou1 cbbcbd9
Add MarshalFunctionReturnAction that marshals an Action delegate from…
kjpou1 7145696
More tests, Actions and Delegate methods
kjpou1 fb8247d
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 1c65efd
Add multi cast tests
kjpou1 019c642
Add anon and lamda del test
kjpou1 7f964e9
Add tests for marshaling TypedArray from different delegates.
kjpou1 6a61e70
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 5571af1
Address review comment. Remove unused variable argsroot.
kjpou1 823b67c
Remove extra assert as per review
kjpou1 28db172
Address review of switched expected
kjpou1 58548c6
As per review comment Rename all Marshal method names to Invoke
kjpou1 81a375a
Add more array type tests for delegates.
kjpou1 a19b8ca
Combine Delegate tests and Multi Cast delegate tests
kjpou1 6ac1cb8
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 b1f78ad
Fix accessor after merge conflict
kjpou1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
199 changes: 199 additions & 0 deletions
199
...teropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/DelegateTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,199 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Runtime.InteropServices.JavaScript; | ||
| using System.Collections.Generic; | ||
| using Xunit; | ||
|
|
||
| namespace System.Runtime.InteropServices.JavaScript.Tests | ||
| { | ||
| public static class DelegateTests | ||
| { | ||
| private static Function _objectPrototype; | ||
|
|
||
| [Fact] | ||
| public static void InvokeFunction() | ||
| { | ||
| HelperMarshal._functionResultValue = 0; | ||
| HelperMarshal._i32Value = 0; | ||
|
|
||
| Runtime.InvokeJS(@" | ||
| var funcDelegate = App.call_test_method (""CreateFunctionDelegate"", [ ]); | ||
| var res = funcDelegate (10, 20); | ||
| App.call_test_method (""InvokeI32"", [ res, res ]); | ||
| "); | ||
|
|
||
| Assert.Equal(30, HelperMarshal._functionResultValue); | ||
| Assert.Equal(60, HelperMarshal._i32Value); | ||
| } | ||
|
|
||
| [Fact] | ||
| public static void InvokeFunctionInLoopUsingConstanceValues() | ||
| { | ||
| HelperMarshal._functionResultValue = 0; | ||
| HelperMarshal._i32Value = 0; | ||
|
|
||
| Runtime.InvokeJS(@" | ||
| var funcDelegate = App.call_test_method (""CreateFunctionDelegate"", [ ]); | ||
| var res = funcDelegate (10, 20); | ||
| for (x = 0; x < 1000; x++) | ||
| { | ||
| res = funcDelegate (10, 20); | ||
| } | ||
radical marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| App.call_test_method (""InvokeI32"", [ res, res ]); | ||
| "); | ||
|
|
||
| Assert.Equal(30, HelperMarshal._functionResultValue); | ||
| Assert.Equal(60, HelperMarshal._i32Value); | ||
| } | ||
|
|
||
| [Fact] | ||
| public static void InvokeFunctionInLoopUsingIncrementedValues() | ||
| { | ||
| HelperMarshal._functionResultValue = 0; | ||
| HelperMarshal._i32Value = 0; | ||
| Runtime.InvokeJS(@" | ||
| var funcDelegate = App.call_test_method (""CreateFunctionDelegate"", [ ]); | ||
| var res = funcDelegate (10, 20); | ||
| for (x = 0; x < 1000; x++) | ||
| { | ||
| res = funcDelegate (x, x); | ||
| } | ||
| App.call_test_method (""InvokeI32"", [ res, res ]); | ||
| "); | ||
|
|
||
| Assert.Equal(1998, HelperMarshal._functionResultValue); | ||
| Assert.Equal(3996, HelperMarshal._i32Value); | ||
| } | ||
|
|
||
| [Fact] | ||
| public static void InvokeActionTReturnedByInvokingFuncT() | ||
| { | ||
| HelperMarshal._functionActionResultValue = 0; | ||
| HelperMarshal._functionActionResultValueOfAction = 0; | ||
|
|
||
| Runtime.InvokeJS(@" | ||
| var funcDelegate = App.call_test_method (""CreateFunctionDelegateWithAction"", [ ]); | ||
| var actionDelegate = funcDelegate (10, 20); | ||
| actionDelegate(30,40); | ||
| "); | ||
|
|
||
| Assert.Equal(30, HelperMarshal._functionActionResultValue); | ||
| Assert.Equal(70, HelperMarshal._functionActionResultValueOfAction); | ||
| } | ||
|
|
||
| [Fact] | ||
| public static void InvokeActionIntInt() | ||
| { | ||
| HelperMarshal._actionResultValue = 0; | ||
|
|
||
| Runtime.InvokeJS(@" | ||
| var actionDelegate = App.call_test_method (""CreateActionDelegate"", [ ]); | ||
| actionDelegate(30,40); | ||
| "); | ||
|
|
||
| Assert.Equal(70, HelperMarshal._actionResultValue); | ||
| } | ||
|
|
||
| [Fact] | ||
| public static void InvokeActionFloatIntToIntInt() | ||
| { | ||
| HelperMarshal._actionResultValue = 0; | ||
| Runtime.InvokeJS(@" | ||
| var actionDelegate = App.call_test_method (""CreateActionDelegate"", [ ]); | ||
| actionDelegate(3.14,40); | ||
| "); | ||
|
|
||
| Assert.Equal(43, HelperMarshal._actionResultValue); | ||
| } | ||
|
|
||
| [Fact] | ||
| public static void InvokeDelegateMethod() | ||
| { | ||
| HelperMarshal._delMethodResultValue = string.Empty; | ||
| Runtime.InvokeJS(@" | ||
| var del = App.call_test_method (""CreateDelegateMethod"", [ ]); | ||
| del(""Hic sunt dracones""); | ||
| "); | ||
|
|
||
| Assert.Equal("Hic sunt dracones", HelperMarshal._delMethodResultValue); | ||
| } | ||
|
|
||
| [Fact] | ||
| public static void InvokeDelegateMethodReturnString() | ||
| { | ||
| HelperMarshal._delMethodStringResultValue = string.Empty; | ||
| Runtime.InvokeJS(@" | ||
| var del = App.call_test_method (""CreateDelegateMethodReturnString"", [ ]); | ||
| var res = del(""Hic sunt dracones""); | ||
| App.call_test_method (""SetTestString1"", [ res ]); | ||
| "); | ||
|
|
||
| Assert.Equal("Received: Hic sunt dracones", HelperMarshal._delMethodStringResultValue); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData("CreateCustomMultiCastDelegate_VoidString", "Moin")] | ||
| [InlineData("CreateMultiCastAction_VoidString", "MoinMoin")] | ||
| public static void InvokeMultiCastDelegate_VoidString(string creator, string testStr) | ||
| { | ||
| HelperMarshal._delegateCallResult = string.Empty; | ||
| Runtime.InvokeJS($@" | ||
| var del = App.call_test_method (""{creator}"", [ ]); | ||
| del(""{testStr}""); | ||
| "); | ||
| Assert.Equal($" Hello, {testStr}! GoodMorning, {testStr}!", HelperMarshal._delegateCallResult); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData("CreateDelegateFromAnonymousMethod_VoidString")] | ||
| [InlineData("CreateDelegateFromLambda_VoidString")] | ||
| [InlineData("CreateDelegateFromMethod_VoidString")] | ||
| [InlineData("CreateActionT_VoidString")] | ||
| public static void InvokeDelegate_VoidString(string creator) | ||
| { | ||
| HelperMarshal._delegateCallResult = string.Empty; | ||
| var s = Runtime.InvokeJS($@" | ||
| var del = App.call_test_method (""{creator}"", [ ]); | ||
| del(""Hic sunt dracones""); | ||
| "); | ||
|
|
||
| Assert.Equal("Notification received for: Hic sunt dracones", HelperMarshal._delegateCallResult); | ||
| } | ||
|
|
||
| public static IEnumerable<object[]> ArrayType_TestData() | ||
| { | ||
| _objectPrototype ??= new Function("return Object.prototype.toString;"); | ||
| yield return new object[] { _objectPrototype.Call(), "Uint8Array", Uint8Array.From(new byte[10]) }; | ||
| yield return new object[] { _objectPrototype.Call(), "Uint8ClampedArray", Uint8ClampedArray.From(new byte[10]) }; | ||
| yield return new object[] { _objectPrototype.Call(), "Int8Array", Int8Array.From(new sbyte[10]) }; | ||
| yield return new object[] { _objectPrototype.Call(), "Uint16Array", Uint16Array.From(new ushort[10]) }; | ||
| yield return new object[] { _objectPrototype.Call(), "Int16Array", Int16Array.From(new short[10]) }; | ||
| yield return new object[] { _objectPrototype.Call(), "Uint32Array", Uint32Array.From(new uint[10]) }; | ||
| yield return new object[] { _objectPrototype.Call(), "Int32Array", Int32Array.From(new int[10]) }; | ||
| yield return new object[] { _objectPrototype.Call(), "Float32Array", Float32Array.From(new float[10]) }; | ||
| yield return new object[] { _objectPrototype.Call(), "Float64Array", Float64Array.From(new double[10]) }; | ||
| yield return new object[] { _objectPrototype.Call(), "Array", new Array(10) }; | ||
| } | ||
|
|
||
| [Theory] | ||
| [MemberData(nameof(ArrayType_TestData))] | ||
| public static void InvokeFunctionAcceptingArrayTypes(Function objectPrototype, string creator, JSObject arrayType ) | ||
| { | ||
| HelperMarshal._funcActionBufferObjectResultValue = arrayType; | ||
| Assert.Equal(10, HelperMarshal._funcActionBufferObjectResultValue.Length); | ||
| Assert.Equal($"[object {creator}]", objectPrototype.Call(HelperMarshal._funcActionBufferObjectResultValue)); | ||
|
|
||
| Runtime.InvokeJS($@" | ||
| var buffer = new {creator}(50); | ||
| var del = App.call_test_method (""CreateFunctionAccepting{creator}"", [ ]); | ||
| var setAction = del(buffer); | ||
| setAction(buffer); | ||
| "); | ||
|
|
||
| Assert.Equal(50, HelperMarshal._funcActionBufferObjectResultValue.Length); | ||
| Assert.Equal(HelperMarshal._funcActionBufferObjectResultValue.Length, HelperMarshal._funcActionBufferResultLengthValue); | ||
| Assert.Equal($"[object {creator}]", objectPrototype.Call(HelperMarshal._funcActionBufferObjectResultValue)); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.