[ES7] yield star should not return if the inner iterator.throw returns { done: true }
[WebKit-https.git] / Source / JavaScriptCore / builtins / GeneratorPrototype.js
index 597a882..69463c3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 Yusuke Suzuki <utatane.tea@gmail.com>.
+ * Copyright (C) 2015-2016 Yusuke Suzuki <utatane.tea@gmail.com>.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -29,15 +29,6 @@ function generatorResume(generator, sentValue, resumeMode)
 {
     "use strict";
 
-    // GeneratorState.
-    const Completed = -1;
-    const Executing = -2;
-
-    // ResumeMode.
-    const NormalMode = 0;
-    const ReturnMode = 1;
-    const ThrowMode = 2;
-
     let state = generator.@generatorState;
     let done = false;
     let value = @undefined;
@@ -45,26 +36,26 @@ function generatorResume(generator, sentValue, resumeMode)
     if (typeof state !== 'number')
         throw new @TypeError("|this| should be a generator");
 
-    if (state === Executing)
+    if (state === @GeneratorStateExecuting)
         throw new @TypeError("Generator is executing");
 
-    if (state === Completed) {
-        if (resumeMode === ThrowMode)
+    if (state === @GeneratorStateCompleted) {
+        if (resumeMode === @GeneratorResumeModeThrow)
             throw sentValue;
 
         done = true;
-        if (resumeMode === ReturnMode)
+        if (resumeMode === @GeneratorResumeModeReturn)
             value = sentValue;
     } else {
         try {
-            generator.@generatorState = Executing;
+            generator.@generatorState = @GeneratorStateExecuting;
             value = generator.@generatorNext.@call(generator.@generatorThis, generator, state, sentValue, resumeMode);
-            if (generator.@generatorState === Executing) {
-                generator.@generatorState = Completed;
+            if (generator.@generatorState === @GeneratorStateExecuting) {
+                generator.@generatorState = @GeneratorStateCompleted;
                 done = true;
             }
         } catch (error) {
-            generator.@generatorState = Completed;
+            generator.@generatorState = @GeneratorStateCompleted;
             throw error;
         }
     }
@@ -75,19 +66,19 @@ function next(value)
 {
     "use strict";
 
-    return @generatorResume(this, value, /* NormalMode */ 0);
+    return @generatorResume(this, value, @GeneratorResumeModeNormal);
 }
 
 function return(value)
 {
     "use strict";
 
-    return @generatorResume(this, value, /* ReturnMode */ 1);
+    return @generatorResume(this, value, @GeneratorResumeModeReturn);
 }
 
 function throw(exception)
 {
     "use strict";
 
-    return @generatorResume(this, exception, /* ThrowMode */ 2);
+    return @generatorResume(this, exception, @GeneratorResumeModeThrow);
 }