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

TargetParameterCountException when returning params in 2.5.1677 #299

Closed
rmja opened this issue Dec 11, 2023 · 4 comments
Closed

TargetParameterCountException when returning params in 2.5.1677 #299

rmja opened this issue Dec 11, 2023 · 4 comments

Comments

@rmja
Copy link
Contributor

rmja commented Dec 11, 2023

The following used to work:

using System;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NiL.JS;
using NiL.JS.BaseLibrary;
using NiL.JS.Core;
using NiL.JS.Extensions;

namespace Tests.Fuzz
{
    [TestClass]
    public sealed class Bug_XXX
    {
        [TestMethod]
        public async Task ReturnParamsFromAsyncFunction()
        {
            var script = Script.Parse(
                @"
export default class Test {
    async run(params) {
        return params;
    }
}
"
            );
            var context = new GlobalContext();
            var module = new Module($"main.js", script, context);
            module.Run();

            var ctor = module.Exports.Default.As<Function>();
            var instance = ctor.Construct(new Arguments());
            var run = instance.GetProperty("run").As<Function>();

            var ints = new int[] { 1, 2, 3 };
            var result = await run.MakeDelegate<Func<int[], Task<JSValue>>>()(ints);

            Assert.AreEqual(6, result);
        }
    }
}

However, it now throws TargetParameterCountException. The regression is introduced in commit f2ea242

@nilproject
Copy link
Owner

I have not found any version where it was working. There was no implicit conversion from Promise to Task (but there is opposite conversion. Probably, it's a bug).
I have made some changes in Promise and some of them could have caused to some problems of types conversions. I guess, original code is more complex and may contain something helpful for investigation

@rmja
Copy link
Contributor Author

rmja commented Dec 20, 2023

Year, sorry. This example shows the regression:

using Microsoft.VisualStudio.TestTools.UnitTesting;
using NiL.JS;
using NiL.JS.BaseLibrary;
using NiL.JS.Core;
using NiL.JS.Extensions;
using System;
using System.Threading.Tasks;

namespace Tests.Fuzz
{
    [TestClass]
    public sealed class Bug_XXX
    {
        [TestMethod]
        public async Task ReturnParamsFromAsyncFunction()
        {
            var script = Script.Parse(
                @"
export default class Test {
    async run(params) {
        return params;
    }
}
"
            );
            var context = new GlobalContext();
            var module = new Module($"main.js", script, context);
            module.Run();

            var ctor = module.Exports.Default.As<Function>();
            var instance = ctor.Construct(new Arguments());
            var run = instance.GetProperty("run").As<Function>();

            var param = JSON.parse("{}");
            var result = run.MakeDelegate<Func<JSValue, JSValue>>()(param);
            if (result.Value is Promise promise)
            {
                result = await promise.Task;
            }

            Assert.AreEqual(param, result);
        }
    }
}

@rmja
Copy link
Contributor Author

rmja commented Jan 5, 2024

@nilproject Have you been able to trigger the regression with the above example?

@nilproject
Copy link
Owner

Yeah, thanks, i've fixed this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants