Skip to content

Commit 5dfe023

Browse files
committed
works
1 parent 7827f9a commit 5dfe023

File tree

5 files changed

+38
-11
lines changed

5 files changed

+38
-11
lines changed

continue.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
- Promise constructor is exposed on RealmState and pulled from closure or realm for async generators; `Array.fromAsync` async-path now drives iteration iteratively (no recursive promise callbacks) and the full `Array_fromAsync` filter passes. Strict `arguments-object` assignment tests now build proper JS error objects and pass.
2929
- Module evaluation now walks requested modules ahead of body execution, ResolveExport/export\* follow the spec (cycle-aware, ambiguous names filtered), module namespaces expose unambiguous exports only, and namespace [[Set]]/Reflect.set return false instead of throwing.
3030
- Object destructuring rest now walks [[OwnPropertyKeys]] with exclusions checked before GetOwnPropertyDescriptor, skips Get for non-enumerables, and uses the original object (including proxies) instead of cloning; the proxy rest destructuring get/gOPD/ownKeys-order tests are passing.
31+
- Async functions now resolve their completion through the global Promise constructor even when executed from nested scopes (class/field environments fall back to the root global object), so the async class element clusters involving same-line static async methods/private names are green again.
3132

3233
## Next Iteration Plan
3334
1. When resuming broader work, run a narrow Language filter outside `ArgumentsObject`/`Array_fromAsync` to find the next hot cluster (avoid full 43k sweep).

src/Asynkron.JsEngine/Ast/ImmutableArrayClassMemberExtensions.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Asynkron.JsEngine;
33
using Asynkron.JsEngine.JsTypes;
44
using Asynkron.JsEngine.StdLib;
5+
using Microsoft.Extensions.Logging;
56

67
namespace Asynkron.JsEngine.Ast;
78

@@ -23,6 +24,15 @@ private void AssignClassMembers(IJsPropertyAccessor constructorAccessor,
2324
return;
2425
}
2526

27+
context.RealmState.Logger?.LogInformation(
28+
"Defining class member name='{Name}' isStatic={IsStatic} isPrivate={IsPrivate} isAsync={IsAsync} wasAsync={WasAsync} kind={Kind}",
29+
propertyName,
30+
member.IsStatic,
31+
member.IsPrivate,
32+
member.Function.IsAsync,
33+
member.Function.WasAsync,
34+
member.Kind);
35+
2636
var baseDisplayName = member.IsPrivate ? member.Name : propertyName;
2737
var displayName = member.Kind switch
2838
{

src/Asynkron.JsEngine/Ast/TypedAstEvaluator.TypedFunction.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,11 @@ public bool TryDefineProperty(string name, PropertyDescriptor descriptor)
381381
var context = _realmState.CreateContext(pushScope: false);
382382
var callerRestore = _caller;
383383
using var callerFrame = context.PushCaller(this, out var previousCaller);
384+
_realmState.Logger?.LogInformation(
385+
"InvokeWithContext enter func={Function} isAsync={IsAsync} wasAsync={WasAsync}",
386+
_function.Name?.Name ?? "<anonymous>",
387+
IsAsyncFunction,
388+
_wasAsyncFunction);
384389
if (!_isStrict && !IsArrowFunction)
385390
{
386391
_caller = previousCaller;
@@ -847,7 +852,9 @@ _function.Name is { } hoistedName &&
847852
throw new ThrowSignal(thrown);
848853
}
849854

850-
if (!IsAsyncFunction)
855+
// Use IsAsyncLike so CPS-transformed async functions (WasAsync=true, IsAsync=false)
856+
// still wrap completion values in a promise.
857+
if (!IsAsyncLike)
851858
{
852859
if (!context.IsReturn)
853860
{
@@ -949,6 +956,12 @@ value is not JsObject &&
949956
completionValue = Symbol.Undefined;
950957
}
951958

959+
_realmState.Logger?.LogInformation(
960+
"Async completion func={Function} isAsync={IsAsync} wasAsync={WasAsync} completionType={Type}",
961+
_function.Name?.Name ?? "<anonymous>",
962+
IsAsyncFunction,
963+
_wasAsyncFunction,
964+
completionValue?.GetType().Name ?? "null");
952965
return CreateResolvedPromise(completionValue, executionEnvironment);
953966
}
954967
catch (ThrowSignal signal) when (IsAsyncFunction || _wasAsyncFunction)

src/Asynkron.JsEngine/Ast/TypedAstEvaluator.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,11 +422,17 @@ promiseCtor is not IJsPropertyAccessor accessor ||
422422

423423
private static object? CreateResolvedPromise(object? value, JsEnvironment environment)
424424
{
425+
object? resolveCandidate = null;
425426
if (!environment.TryGet(Symbol.PromiseIdentifier, out var promiseCtor) ||
426427
promiseCtor is not IJsPropertyAccessor accessor ||
427-
!accessor.TryGetProperty("resolve", out var resolveValue) ||
428-
resolveValue is not IJsCallable resolveCallable)
429-
{
428+
!accessor.TryGetProperty("resolve", out resolveCandidate) ||
429+
resolveCandidate is not IJsCallable resolveCallable)
430+
{
431+
environment.RealmState?.Logger?.LogInformation(
432+
"CreateResolvedPromise falling back (promiseCtorType={CtorType}, hasResolve={HasResolve}, resolveCallable={ResolveCallable})",
433+
promiseCtor?.GetType().Name ?? "null",
434+
promiseCtor is IJsPropertyAccessor a && a.TryGetProperty("resolve", out _),
435+
resolveCandidate is IJsCallable);
430436
return value;
431437
}
432438

src/Asynkron.JsEngine/JsEnvironment.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,14 +1116,11 @@ public bool TryGet(Symbol name, out object? value)
11161116
current = current.Enclosing;
11171117
}
11181118

1119-
if (IsGlobalFunctionScope)
1119+
var rootGlobal = GetRootGlobalObject();
1120+
if (rootGlobal is not null && rootGlobal.TryGetProperty(name.Name, out var propertyValue))
11201121
{
1121-
var rootGlobal = GetRootGlobalObject();
1122-
if (rootGlobal is not null && rootGlobal.TryGetProperty(name.Name, out var propertyValue))
1123-
{
1124-
value = propertyValue;
1125-
return true;
1126-
}
1122+
value = propertyValue;
1123+
return true;
11271124
}
11281125

11291126
value = null;

0 commit comments

Comments
 (0)