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

[browser] Fix System.Delegate.DynamicInvoke method can not be resolved #47519

Merged
merged 23 commits into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from 14 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 Jan 27, 2021
ddb0485
Address review comment for assembly name
kjpou1 Jan 27, 2021
84c0ba6
Change this back to mscorlib as the recommended code cause a warning.
kjpou1 Jan 27, 2021
e6e8d34
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 Jan 29, 2021
ab9ae20
[browser] Remove linker trim exclusions for System.Delegate.DynamicI…
kjpou1 Jan 29, 2021
2070cb5
Remove dependency on System.Delegate.DynamicInvoke
kjpou1 Jan 29, 2021
255be2f
Add method to retrieve the Invoke method of the delegate
kjpou1 Jan 29, 2021
7203cbf
Create another test module for Delegate tests
kjpou1 Jan 29, 2021
cbbcbd9
Add MarshalFunctionReturnAction that marshals an Action delegate from…
kjpou1 Jan 29, 2021
7145696
More tests, Actions and Delegate methods
kjpou1 Jan 29, 2021
fb8247d
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 Feb 1, 2021
1c65efd
Add multi cast tests
kjpou1 Feb 1, 2021
019c642
Add anon and lamda del test
kjpou1 Feb 1, 2021
7f964e9
Add tests for marshaling TypedArray from different delegates.
kjpou1 Feb 1, 2021
6a61e70
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 Feb 2, 2021
5571af1
Address review comment. Remove unused variable argsroot.
kjpou1 Feb 2, 2021
823b67c
Remove extra assert as per review
kjpou1 Feb 2, 2021
28db172
Address review of switched expected
kjpou1 Feb 2, 2021
58548c6
As per review comment Rename all Marshal method names to Invoke
kjpou1 Feb 2, 2021
81a375a
Add more array type tests for delegates.
kjpou1 Feb 2, 2021
a19b8ca
Combine Delegate tests and Multi Cast delegate tests
kjpou1 Feb 2, 2021
6ac1cb8
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 Feb 10, 2021
b1f78ad
Fix accessor after merge conflict
kjpou1 Feb 10, 2021
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 @@ -262,12 +262,12 @@ private struct IntPtrAndHandle
internal RuntimeMethodHandle handle;
}

private static string GetCallSignature(IntPtr methodHandle)
private static string GetCallSignature(IntPtr methodHandle, object objForRuntimeType)
{
IntPtrAndHandle tmp = default(IntPtrAndHandle);
tmp.ptr = methodHandle;

MethodBase? mb = MethodBase.GetMethodFromHandle(tmp.handle);
MethodBase? mb = objForRuntimeType == null ? MethodBase.GetMethodFromHandle(tmp.handle) : MethodBase.GetMethodFromHandle(tmp.handle, Type.GetTypeHandle(objForRuntimeType));
if (mb == null)
return string.Empty;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
<Compile Include="System\Runtime\InteropServices\JavaScript\ArrayTests.cs" />
<!-- <Compile Include="System\Runtime\InteropServices\JavaScript\MapTests.cs" /> -->
<Compile Include="System\Runtime\InteropServices\JavaScript\MarshalTests.cs" />
<Compile Include="System\Runtime\InteropServices\JavaScript\DelegateTests.cs" />
<Compile Include="System\Runtime\InteropServices\JavaScript\HelperMarshal.cs" />
<Compile Include="System\Runtime\InteropServices\JavaScript\Http\HttpRequestMessageTest.cs" />
<Compile Include="System\Runtime\InteropServices\JavaScript\Http\HttpRequestMessageTest.cs" />
</ItemGroup>
<ItemGroup>
<!-- Part of the shared framework but not exposed. -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
// 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;
public static IEnumerable<object[]> Object_Prototype()
{
_objectPrototype ??= new Function("return Object.prototype.toString;");
yield return new object[] { _objectPrototype.Call() };
}

[Fact]
public static void MarshalFunction()
kjpou1 marked this conversation as resolved.
Show resolved Hide resolved
{
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 ]);
radical marked this conversation as resolved.
Show resolved Hide resolved
");

Assert.Equal(30, HelperMarshal._functionResultValue);
Assert.Equal(60, HelperMarshal._i32Value);
}

[Fact]
public static void MarshalFunctionLooptyLoop()
{
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 MarshalFunctionLooptyLoopIncrement()
kjpou1 marked this conversation as resolved.
Show resolved Hide resolved
{
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 MarshalFunctionReturnAction()
kjpou1 marked this conversation as resolved.
Show resolved Hide resolved
{
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 MarshalActionIntInt()
{
HelperMarshal._actionResultValue = 0;

Runtime.InvokeJS(@"
var actionDelegate = App.call_test_method (""CreateActionDelegate"", [ ]);
actionDelegate(30,40);
");

Assert.Equal(70, HelperMarshal._actionResultValue);
}

[Fact]
public static void MarshalActionFloatIntToIntInt()
radical marked this conversation as resolved.
Show resolved Hide resolved
{
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 MarshalDelegateMethod()
{
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 MarshalAnonDelegateMethod()
kjpou1 marked this conversation as resolved.
Show resolved Hide resolved
{
HelperMarshal._delAnonMethodStringResultValue = string.Empty;
Runtime.InvokeJS(@"
var del = App.call_test_method (""CreateDelegateAnonMethodReturnString"", [ ]);
del(""Hic sunt dracones"");
");

Assert.Equal("Notification received for: Hic sunt dracones", HelperMarshal._delAnonMethodStringResultValue);
}


[Fact]
public static void MarshalLambdaDelegateMethod()
{
HelperMarshal._delLambdaMethodStringResultValue = string.Empty;
Runtime.InvokeJS(@"
var del = App.call_test_method (""CreateDelegateLambdaMethodReturnString"", [ ]);
del(""Hic sunt dracones"");
");

Assert.Equal("Notification received for: Hic sunt dracones", HelperMarshal._delLambdaMethodStringResultValue);
}

[Fact]
public static void MarshalDelegateMethodReturnString()
{
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);
}

[Fact]
public static void MarshalCustomMultiDelegateAcceptingString()
kjpou1 marked this conversation as resolved.
Show resolved Hide resolved
{
HelperMarshal._custMultiDelStringResultValue = string.Empty;
Runtime.InvokeJS(@"
var del = App.call_test_method (""CreateCustomMultiDelegateAcceptingString"", [ ]);
del(""Moin"");
");

Assert.Equal(" Hello, Moin! GoodMorning, Moin!", HelperMarshal._custMultiDelStringResultValue);
}

[Fact]
public static void MarshalCustomMultiActionAcceptingString()
{
HelperMarshal._custMultiActionStringResultValue = string.Empty;
Runtime.InvokeJS(@"
var del = App.call_test_method (""CreateCustomMultiActionAcceptingString"", [ ]);
del(""MoinMoin"");
");

Assert.Equal(" Hello, MoinMoin! GoodMorning, MoinMoin!", HelperMarshal._custMultiActionStringResultValue);
}

[Theory]
[MemberData(nameof(Object_Prototype))]
kjpou1 marked this conversation as resolved.
Show resolved Hide resolved
public static void MarshalFunctionAcceptingUint8Array(Function objectPrototype)
kjpou1 marked this conversation as resolved.
Show resolved Hide resolved
{
var clamped = new byte[10];
HelperMarshal._funcActionBufferResultValue = Uint8Array.From(clamped);
Assert.Equal(10, HelperMarshal._funcActionBufferResultValue.Length);
Assert.NotEqual("[object Uint8ClampedArray]", objectPrototype.Call(HelperMarshal._funcActionBufferResultValue));
kjpou1 marked this conversation as resolved.
Show resolved Hide resolved
Assert.Equal("[object Uint8Array]", objectPrototype.Call(HelperMarshal._funcActionBufferResultValue));

Runtime.InvokeJS(@"
var buffer = new Uint8Array(50);
var del = App.call_test_method (""CreateFunctionAcceptingUint8Array"", [ ]);
var setAction = del(buffer);
setAction(buffer);
");

Assert.Equal(50, HelperMarshal._funcActionBufferResultValue.Length);
Assert.Equal(HelperMarshal._funcActionBufferResultLengthValue, HelperMarshal._funcActionBufferResultValue.Length);
kjpou1 marked this conversation as resolved.
Show resolved Hide resolved
Assert.NotEqual("[object Uint8ClampedArray]", objectPrototype.Call(HelperMarshal._funcActionBufferResultValue));
Assert.Equal("[object Uint8Array]", objectPrototype.Call(HelperMarshal._funcActionBufferResultValue));

}

}
}
Loading