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

Update test262 suite and implement Promise.try #1895

Merged
merged 1 commit into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Jint.Tests.Test262/Test262Harness.settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"SuiteGitSha": "c2ae5ed5e90d86e17730730b003e9b6fb050693e",
"SuiteGitSha": "9dec509c93fa9b19d46330d90a43f871bb1aaf84",
//"SuiteDirectory": "//mnt/c/work/test262",
"TargetPath": "./Generated",
"Namespace": "Jint.Tests.Test262",
Expand Down
29 changes: 28 additions & 1 deletion Jint/Native/Promise/PromiseConstructor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ protected override void Initialize()
{
const PropertyFlag PropertyFlags = PropertyFlag.Configurable | PropertyFlag.Writable;
const PropertyFlag LengthFlags = PropertyFlag.Configurable;
var properties = new PropertyDictionary(6, checkExistingKeys: false)
var properties = new PropertyDictionary(8, checkExistingKeys: false)
{
["all"] = new(new PropertyDescriptor(new ClrFunction(Engine, "all", All, 1, LengthFlags), PropertyFlags)),
["allSettled"] = new(new PropertyDescriptor(new ClrFunction(Engine, "allSettled", AllSettled, 1, LengthFlags), PropertyFlags)),
["any"] = new(new PropertyDescriptor(new ClrFunction(Engine, "any", Any, 1, LengthFlags), PropertyFlags)),
["race"] = new(new PropertyDescriptor(new ClrFunction(Engine, "race", Race, 1, LengthFlags), PropertyFlags)),
["reject"] = new(new PropertyDescriptor(new ClrFunction(Engine, "reject", Reject, 1, LengthFlags), PropertyFlags)),
["resolve"] = new(new PropertyDescriptor(new ClrFunction(Engine, "resolve", Resolve, 1, LengthFlags), PropertyFlags)),
["try"] = new(new PropertyDescriptor(new ClrFunction(Engine, "try", Try, 1, LengthFlags), PropertyFlags)),
["withResolvers"] = new(new PropertyDescriptor(new ClrFunction(Engine, "withResolvers", WithResolvers , 0, LengthFlags), PropertyFlags)),
};
SetProperties(properties);
Expand Down Expand Up @@ -169,6 +170,32 @@ private JsValue Reject(JsValue thisObject, JsValue[] arguments)
return instance;
}

/// <summary>
/// https://tc39.es/proposal-promise-try/
/// </summary>
private JsValue Try(JsValue thisObject, JsValue[] arguments)
{
if (!thisObject.IsObject())
{
ExceptionHelper.ThrowTypeError(_realm, "Promise.try called on non-object");
}

var callbackfn = arguments.At(0);
var promiseCapability = NewPromiseCapability(_engine, thisObject);

try
{
var status = callbackfn.Call(Undefined, arguments.Skip(1));
promiseCapability.Resolve.Call(Undefined, new[] { status });
}
catch (JavaScriptException e)
{
promiseCapability.Reject.Call(Undefined, new[] { e.Error });
}

return promiseCapability.PromiseInstance;
}

// This helper methods executes the first 6 steps in the specs belonging to static Promise methods like all, any etc.
// If it returns false, that means it has an error and it is already rejected
// If it returns true, the logic specific to the calling function should continue executing
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ and many more.
- ✔ Float16Array (Jint v4, requires NET 6 target or higher)
- ✔ Import attributes
- ✔ JSON modules
- ✔ `Promise.try` (Jint v4)
- ✔ `Promise.withResolvers`
- ✔ Resizable and growable ArrayBuffers
- ✔ Set methods (`intersection`, `union`, `difference`, `symmetricDifference`, `isSubsetOf`, `isSupersetOf`, `isDisjointFrom`)
Expand Down