Skip to content

Commit

Permalink
fix #299
Browse files Browse the repository at this point in the history
  • Loading branch information
nilproject committed Jan 6, 2024
1 parent ea0aa5c commit e1a173b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion NiL.JS/BaseLibrary/Promise.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private void callbackInvoke()

public static Promise resolve(JSValue data)
{
return data.As<Promise>() ?? new Promise(fromResult(data));
return data.Value as Promise ?? new Promise(fromResult(data));
}

public static Promise reject(JSValue data)
Expand Down
44 changes: 44 additions & 0 deletions Tests/Fuzz/Bug_299.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
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_299
{
[TestMethod]
public async Task Promise_299()
{
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);
}
}
}

0 comments on commit e1a173b

Please sign in to comment.