1- using  System . Diagnostics ; 
2- using  Jint . Native . Iterator ; 
1+ using  Jint . Native . Iterator ; 
32using  Jint . Native . Object ; 
43using  Jint . Runtime ; 
54using  Jint . Runtime . Environments ; 
@@ -73,7 +72,27 @@ public JsValue GeneratorResume(JsValue value, JsValue generatorBrand)
7372            _generatorState  =  GeneratorState . Executing ; 
7473            _engine . EnterExecutionContext ( genContext ) ; 
7574
76-             return  EvaluateGenerator ( ) ; 
75+             var  result  =  _generatorBody . Execute ( ) ; 
76+ 
77+             JsValue  resultValue  =  null ; 
78+             if  ( result . Type  ==  CompletionType . Normal ) 
79+             { 
80+                 _generatorState  =  GeneratorState . Completed ; 
81+                 resultValue  =  IteratorInstance . ValueIteratorPosition . Done ; 
82+             } 
83+             else  if  ( result . Type  ==  CompletionType . Return ) 
84+             { 
85+                 resultValue  =  result . Value ; 
86+             } 
87+ 
88+             if  ( result . Type  ==  CompletionType . Throw ) 
89+             { 
90+                 // TODO handle 
91+                 _generatorState  =  GeneratorState . Completed ; 
92+                 throw  new  JavaScriptException ( result . Value ) ; 
93+             } 
94+ 
95+             return  resultValue ; 
7796        } 
7897
7998        /// <summary> 
@@ -105,12 +124,17 @@ public JsValue GeneratorResumeAbrupt(in Completion abruptCompletion, JsValue gen
105124
106125            _generatorState  =  GeneratorState . Executing ; 
107126
108-             _engine . EnterExecutionContext ( genContext ) ; 
127+             // _engine.EnterExecutionContext(genContext);
109128
110-             // Resume the suspended evaluation of genContext using abruptCompletion as the result of the operation that suspended it. 
111-             // Let result be the completion record returned by the resumed computation. 
129+             _generatorState  =  GeneratorState . Completed ; 
130+ 
131+             if  ( abruptCompletion . Type  ==  CompletionType . Throw ) 
132+             { 
133+                 // TODO handle 
134+                 throw  new  JavaScriptException ( abruptCompletion . Value ) ; 
135+             } 
112136
113-             return  EvaluateGenerator ( ) ; 
137+             return  IteratorInstance . ValueIteratorPosition . Done ; 
114138        } 
115139
116140        private  GeneratorState  GeneratorValidate ( JsValue  generatorBrand ) 
@@ -127,27 +151,5 @@ private GeneratorState GeneratorValidate(JsValue generatorBrand)
127151
128152            return  _generatorState ; 
129153        } 
130- 
131-         private  JsValue  EvaluateGenerator ( ) 
132-         { 
133-             var  result  =  _generatorBody . Execute ( ) ; 
134-             JsValue  resultValue  =  null ; 
135-             if  ( result . Type  ==  CompletionType . Normal ) 
136-             { 
137-                 _generatorState  =  GeneratorState . Completed ; 
138-                 resultValue  =  IteratorInstance . ValueIteratorPosition . Done ; 
139-             } 
140-             else  if  ( result . Type  ==  CompletionType . Return ) 
141-             { 
142-                 resultValue  =  result . Value ; 
143-             } 
144- 
145-             if  ( result . Type  ==  CompletionType . Throw ) 
146-             { 
147-                 // TODO handle 
148-             } 
149- 
150-             return  resultValue ; 
151-         } 
152154    } 
153155} 
0 commit comments