Skip to content

Commit

Permalink
Rename PromiseInstance to JsPromise (#1605)
Browse files Browse the repository at this point in the history
  • Loading branch information
lahma authored Jul 31, 2023
1 parent 5689052 commit cc63b20
Show file tree
Hide file tree
Showing 12 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Jint.Tests/Runtime/PromiseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void PromiseCtor_ReturnsPromiseJsValue()
var engine = new Engine();
var promise = engine.Evaluate("new Promise((resolve, reject)=>{});");

Assert.IsType<PromiseInstance>(promise);
Assert.IsType<JsPromise>(promise);
}

[Fact(Timeout = 5000)]
Expand Down
2 changes: 1 addition & 1 deletion Jint/Engine.Modules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ private JsValue EvaluateModule(string specifier, ModuleRecord module)
}

// 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}");
}
Expand Down
2 changes: 1 addition & 1 deletion Jint/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ private Engine ScriptEvaluation(ScriptRecord scriptRecord)
/// <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
};
Expand Down
4 changes: 2 additions & 2 deletions Jint/JsValueExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static bool IsDate(this JsValue value)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsPromise(this JsValue value)
{
return value is PromiseInstance;
return value is JsPromise;
}

[Pure]
Expand Down Expand Up @@ -543,7 +543,7 @@ private static JsValue ThrowNotObject(JsValue value)
/// <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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Action<JsValue> Reject
);


internal sealed class PromiseInstance : ObjectInstance
internal sealed class JsPromise : ObjectInstance
{
internal PromiseState State { get; private set; }

Expand All @@ -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)
{
}

Expand Down
2 changes: 1 addition & 1 deletion Jint/Native/Promise/PromiseConstructor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public override ObjectInstance Construct(JsValue[] arguments, JsValue newTarget)
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
Expand Down
4 changes: 2 additions & 2 deletions Jint/Native/Promise/PromiseOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private static Action NewPromiseReactionJob(PromiseReaction reaction, JsValue va
// 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 () =>
{
Expand Down Expand Up @@ -114,7 +114,7 @@ internal static JsValue TriggerPromiseReactions(Engine engine, List<PromiseReact
// https://tc39.es/ecma262/#sec-performpromisethen
internal static JsValue PerformPromiseThen(
Engine engine,
PromiseInstance promise,
JsPromise promise,
JsValue onFulfilled,
JsValue onRejected,
PromiseCapability resultCapability)
Expand Down
2 changes: 1 addition & 1 deletion Jint/Native/Promise/PromisePrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private JsValue Then(JsValue thisValue, JsValue[] arguments)
{
// 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");
Expand Down
2 changes: 1 addition & 1 deletion Jint/Native/ShadowRealm/ShadowRealm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ internal JsValue ShadowRealmImportValue(

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;
}
Expand Down
4 changes: 2 additions & 2 deletions Jint/Runtime/Host.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@ internal virtual void ImportModuleDynamically(IScriptOrModule? referencingModule
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) =>
{
Expand Down
4 changes: 2 additions & 2 deletions Jint/Runtime/Interpreter/Expressions/JintAwaitExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ protected override object EvaluateInternal(EvaluationContext context)
{
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;
}
Expand Down
2 changes: 1 addition & 1 deletion Jint/Runtime/Modules/CyclicModuleRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ private Completion ExecuteAsyncModule()
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);
}
Expand Down

0 comments on commit cc63b20

Please sign in to comment.