|
2 | 2 | using Esprima.Ast; |
3 | 3 | using Jint.Native; |
4 | 4 | using Jint.Native.Function; |
| 5 | +using Jint.Native.Generator; |
5 | 6 | using Jint.Native.Promise; |
6 | 7 | using Jint.Runtime.Environments; |
7 | 8 | using Jint.Runtime.Interpreter.Expressions; |
@@ -63,11 +64,7 @@ internal Completion EvaluateBody(EvaluationContext context, Function functionObj |
63 | 64 | } |
64 | 65 | else if (Function.Generator) |
65 | 66 | { |
66 | | - // TODO generators |
67 | | - // result = EvaluateGeneratorBody(functionObject, argumentsList); |
68 | | - argumentsInstance = context.Engine.FunctionDeclarationInstantiation(functionObject, argumentsList); |
69 | | - _bodyStatementList ??= new JintStatementList(Function); |
70 | | - result = _bodyStatementList.Execute(context); |
| 67 | + result = EvaluateGeneratorBody(context, functionObject, argumentsList); |
71 | 68 | } |
72 | 69 | else |
73 | 70 | { |
@@ -108,7 +105,11 @@ private static void AsyncFunctionStart(EvaluationContext context, PromiseCapabil |
108 | 105 | /// <summary> |
109 | 106 | /// https://tc39.es/ecma262/#sec-asyncblockstart |
110 | 107 | /// </summary> |
111 | | - private static void AsyncBlockStart(EvaluationContext context, PromiseCapability promiseCapability, Func<EvaluationContext, Completion> asyncBody, in ExecutionContext asyncContext) |
| 108 | + private static void AsyncBlockStart( |
| 109 | + EvaluationContext context, |
| 110 | + PromiseCapability promiseCapability, |
| 111 | + Func<EvaluationContext, Completion> asyncBody, |
| 112 | + in ExecutionContext asyncContext) |
112 | 113 | { |
113 | 114 | var runningContext = context.Engine.ExecutionContext; |
114 | 115 | // Set the code evaluation state of asyncContext such that when evaluation is resumed for that execution contxt the following steps will be performed: |
@@ -149,10 +150,23 @@ 8. Return unused. |
149 | 150 | /// <summary> |
150 | 151 | /// https://tc39.es/ecma262/#sec-runtime-semantics-evaluategeneratorbody |
151 | 152 | /// </summary> |
152 | | - private static Completion EvaluateGeneratorBody(Function functionObject, JsValue[] argumentsList) |
| 153 | + private Completion EvaluateGeneratorBody( |
| 154 | + EvaluationContext context, |
| 155 | + Function functionObject, |
| 156 | + JsValue[] argumentsList) |
153 | 157 | { |
154 | | - ExceptionHelper.ThrowNotImplementedException("generators not implemented"); |
155 | | - return default; |
| 158 | + var engine = context.Engine; |
| 159 | + engine.FunctionDeclarationInstantiation(functionObject, argumentsList); |
| 160 | + var G = engine.Realm.Intrinsics.Function.OrdinaryCreateFromConstructor( |
| 161 | + functionObject, |
| 162 | + static intrinsics => intrinsics.GeneratorFunction.PrototypeObject.PrototypeObject, |
| 163 | + static (Engine engine , Realm _, object? _) => new GeneratorInstance(engine)); |
| 164 | + |
| 165 | + _bodyStatementList ??= new JintStatementList(Function); |
| 166 | + _bodyStatementList.Reset(); |
| 167 | + G.GeneratorStart(_bodyStatementList); |
| 168 | + |
| 169 | + return new Completion(CompletionType.Return, G, Function.Body); |
156 | 170 | } |
157 | 171 |
|
158 | 172 | internal State Initialize() |
|
0 commit comments