Bladeren bron

Rename PromiseInstance to JsPromise (#1605)

Marko Lahma 2 jaren geleden
bovenliggende
commit
cc63b205dc

+ 1 - 1
Jint.Tests/Runtime/PromiseTests.cs

@@ -128,7 +128,7 @@ public class PromiseTests
         var engine = new Engine();
         var promise = engine.Evaluate("new Promise((resolve, reject)=>{});");
 
-        Assert.IsType<PromiseInstance>(promise);
+        Assert.IsType<JsPromise>(promise);
     }
 
     [Fact(Timeout = 5000)]

+ 1 - 1
Jint/Engine.Modules.cs

@@ -148,7 +148,7 @@ namespace Jint
             }
 
             // This should instead be returned and resolved in ImportModule(specifier) only so Host.ImportModuleDynamically can use this promise
-            if (evaluationResult is not PromiseInstance promise)
+            if (evaluationResult is not JsPromise promise)
             {
                 ExceptionHelper.ThrowInvalidOperationException($"Error while evaluating module: Module evaluation did not return a promise: {evaluationResult.Type}");
             }

+ 1 - 1
Jint/Engine.cs

@@ -436,7 +436,7 @@ namespace Jint
         /// <returns>a Promise instance and functions to either resolve or reject it</returns>
         public ManualPromise RegisterPromise()
         {
-            var promise = new PromiseInstance(this)
+            var promise = new JsPromise(this)
             {
                 _prototype = Realm.Intrinsics.Promise.PrototypeObject
             };

+ 2 - 2
Jint/JsValueExtensions.cs

@@ -47,7 +47,7 @@ namespace Jint
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
         public static bool IsPromise(this JsValue value)
         {
-            return value is PromiseInstance;
+            return value is JsPromise;
         }
 
         [Pure]
@@ -543,7 +543,7 @@ namespace Jint
         /// <returns>inner value if Promise the value itself otherwise</returns>
         public static JsValue UnwrapIfPromise(this JsValue value)
         {
-            if (value is PromiseInstance promise)
+            if (value is JsPromise promise)
             {
                 switch (promise.State)
                 {

+ 2 - 2
Jint/Native/Promise/PromiseInstance.cs → Jint/Native/Promise/JsPromise.cs

@@ -37,7 +37,7 @@ public sealed record ManualPromise(
 );
 
 
-internal sealed class PromiseInstance : ObjectInstance
+internal sealed class JsPromise : ObjectInstance
 {
     internal PromiseState State { get; private set; }
 
@@ -47,7 +47,7 @@ internal sealed class PromiseInstance : ObjectInstance
     internal List<PromiseReaction> PromiseRejectReactions = new();
     internal List<PromiseReaction> PromiseFulfillReactions = new();
 
-    internal PromiseInstance(Engine engine) : base(engine)
+    internal JsPromise(Engine engine) : base(engine)
     {
     }
 

+ 1 - 1
Jint/Native/Promise/PromiseConstructor.cs

@@ -79,7 +79,7 @@ namespace Jint.Native.Promise
             var promise = OrdinaryCreateFromConstructor(
                 newTarget,
                 static intrinsics => intrinsics.Promise.PrototypeObject,
-                static (Engine engine, Realm _, object? _) => new PromiseInstance(engine));
+                static (Engine engine, Realm _, object? _) => new JsPromise(engine));
 
             var (resolve, reject) = promise.CreateResolvingFunctions();
             try

+ 2 - 2
Jint/Native/Promise/PromiseOperations.cs

@@ -78,7 +78,7 @@ namespace Jint.Native.Promise
         //  d. Return Completion(thenCallResult).
         // .....Realm stuff....
         // 6. Return the Record { [[Job]]: job, [[Realm]]: thenRealm }.
-        internal static Action NewPromiseResolveThenableJob(PromiseInstance promise, ObjectInstance thenable, ICallable thenMethod)
+        internal static Action NewPromiseResolveThenableJob(JsPromise promise, ObjectInstance thenable, ICallable thenMethod)
         {
             return () =>
             {
@@ -114,7 +114,7 @@ namespace Jint.Native.Promise
         // https://tc39.es/ecma262/#sec-performpromisethen
         internal static JsValue PerformPromiseThen(
             Engine engine,
-            PromiseInstance promise,
+            JsPromise promise,
             JsValue onFulfilled,
             JsValue onRejected,
             PromiseCapability resultCapability)

+ 1 - 1
Jint/Native/Promise/PromisePrototype.cs

@@ -54,7 +54,7 @@ namespace Jint.Native.Promise
         {
             // 1. Let promise be the this value.
             // 2. If IsPromise(promise) is false, throw a TypeError exception.
-            var promise = thisValue as PromiseInstance;
+            var promise = thisValue as JsPromise;
             if (promise is null)
             {
                 ExceptionHelper.ThrowTypeError(_realm, "Method Promise.prototype.then called on incompatible receiver");

+ 1 - 1
Jint/Native/ShadowRealm/ShadowRealm.cs

@@ -215,7 +215,7 @@ public sealed class ShadowRealm : ObjectInstance
 
         var onFulfilled = new StepsFunction(_engine, callerRealm, exportNameString);
         var promiseCapability = PromiseConstructor.NewPromiseCapability(_engine, _engine.Realm.Intrinsics.Promise);
-        var value = PromiseOperations.PerformPromiseThen(_engine, (PromiseInstance) innerCapability.PromiseInstance, onFulfilled, callerRealm.Intrinsics.ThrowTypeError, promiseCapability);
+        var value = PromiseOperations.PerformPromiseThen(_engine, (JsPromise) innerCapability.PromiseInstance, onFulfilled, callerRealm.Intrinsics.ThrowTypeError, promiseCapability);
 
         return value;
     }

+ 2 - 2
Jint/Runtime/Host.cs

@@ -140,13 +140,13 @@ namespace Jint.Runtime
                 promise.Reject(ex.Error);
             }
 
-            FinishDynamicImport(referencingModule, specifier, promiseCapability, (PromiseInstance) promise.Promise);
+            FinishDynamicImport(referencingModule, specifier, promiseCapability, (JsPromise) promise.Promise);
         }
 
         /// <summary>
         /// https://tc39.es/ecma262/#sec-finishdynamicimport
         /// </summary>
-        internal virtual void FinishDynamicImport(IScriptOrModule? referencingModule, string specifier, PromiseCapability promiseCapability, PromiseInstance innerPromise)
+        internal virtual void FinishDynamicImport(IScriptOrModule? referencingModule, string specifier, PromiseCapability promiseCapability, JsPromise innerPromise)
         {
             var onFulfilled = new ClrFunctionInstance(Engine, "", (thisObj, args) =>
             {

+ 2 - 2
Jint/Runtime/Interpreter/Expressions/JintAwaitExpression.cs

@@ -26,9 +26,9 @@ internal sealed class JintAwaitExpression : JintExpression
         {
             var value = _awaitExpression.GetValue(context);
 
-            if (value is not PromiseInstance)
+            if (value is not JsPromise)
             {
-                var promiseInstance = new PromiseInstance(engine);
+                var promiseInstance = new JsPromise(engine);
                 promiseInstance.Resolve(value);
                 value = promiseInstance;
             }

+ 1 - 1
Jint/Runtime/Modules/CyclicModuleRecord.cs

@@ -426,7 +426,7 @@ public abstract class CyclicModuleRecord : ModuleRecord
         var onFullfilled = new ClrFunctionInstance(_engine, "fulfilled", AsyncModuleExecutionFulfilled, 1, PropertyFlag.Configurable);
         var onRejected = new ClrFunctionInstance(_engine, "rejected", AsyncModuleExecutionRejected, 1, PropertyFlag.Configurable);
 
-        PromiseOperations.PerformPromiseThen(_engine, (PromiseInstance) capability.PromiseInstance, onFullfilled, onRejected, null);
+        PromiseOperations.PerformPromiseThen(_engine, (JsPromise) capability.PromiseInstance, onFullfilled, onRejected, null);
 
         return ExecuteModule(capability);
     }