-
-
Notifications
You must be signed in to change notification settings - Fork 562
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support params arrays in delegate invocation (#1520)
Co-authored-by: Marko Lahma <[email protected]>
- Loading branch information
Showing
3 changed files
with
53 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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,33 @@ | ||
using Jint.Runtime.Interop; | ||
|
||
namespace Jint.Tests.Runtime; | ||
|
||
public class DelegateWrapperTests | ||
{ | ||
[Fact] | ||
public void ShouldSpreadParameters() | ||
{ | ||
var engine = new Engine(); | ||
engine.SetValue("registerCallback", new DelegateWrapper(engine, new RegisterCallbackDelegate(RegisterCallback))); | ||
|
||
engine.Execute(@" | ||
var argsConcat = ''; | ||
registerCallback((valTest, valOther, valNumber) => { | ||
argsConcat+=typeof valTest; | ||
argsConcat+=' ' + typeof valOther; | ||
argsConcat+=' ' + typeof valNumber; | ||
}, 'test', 'other', 1337); | ||
"); | ||
|
||
Assert.True(engine.Evaluate("argsConcat == 'string string number'").AsBoolean()); | ||
} | ||
|
||
private static void RegisterCallback(CallbackAction callback, params object[] arguments) | ||
{ | ||
callback.Invoke(arguments); | ||
} | ||
|
||
private delegate void RegisterCallbackDelegate(CallbackAction callback, params object[] arguments); | ||
|
||
private delegate void CallbackAction(params object[] arguments); | ||
} |
This file contains 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 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