regenerator
Advanced tools
Comparing version 0.2.3 to 0.2.4
@@ -19,3 +19,3 @@ { | ||
], | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"homepage": "http://github.com/facebook/regenerator", | ||
@@ -22,0 +22,0 @@ "repository": { |
@@ -37,3 +37,3 @@ /** | ||
var generator = this; | ||
var context = new Context; | ||
var context = new Context(); | ||
var state = GenStateSuspendedStart; | ||
@@ -43,4 +43,5 @@ | ||
state = GenStateExecuting; | ||
do var value = innerFn.call(self, context); | ||
while (value === ContinueSentinel); | ||
do { | ||
var value = innerFn.call(self, context); | ||
} while (value === ContinueSentinel); | ||
// If an exception is thrown from innerFn, we leave state === | ||
@@ -87,7 +88,7 @@ // GenStateExecuting and loop back for another invocation. | ||
generator["throw"] = function(exception) { | ||
generator.throw = function(exception) { | ||
assertCanInvoke(); | ||
if (context.delegate) { | ||
var info = context.delegate["throw"](exception); | ||
var info = context.delegate.throw(exception); | ||
if (info.done) { | ||
@@ -105,7 +106,9 @@ context.delegate = null; | ||
while (true) try { | ||
while (true) { | ||
context.dispatchException(exception); | ||
return invoke(); | ||
} catch (thrown) { | ||
exception = thrown; | ||
try { | ||
return invoke(); | ||
} catch (thrown) { | ||
exception = thrown; | ||
} | ||
} | ||
@@ -131,8 +134,6 @@ }; | ||
// class optimizations for simple generators. | ||
var tempIndex = 0; | ||
var tempName; | ||
while (tempName = "t" + tempIndex, // N.B. Comma operator! | ||
tempIndex < 20 || hasOwn.call(this, tempName)) { | ||
for (var tempIndex = 0, tempName; | ||
hasOwn.call(this, tempName = "t" + tempIndex) || tempIndex < 20; | ||
++tempIndex) { | ||
this[tempName] = null; | ||
++tempIndex; | ||
} | ||
@@ -139,0 +140,0 @@ }, |
@@ -9,3 +9,2 @@ /** | ||
*/ | ||
!function(t){function e(t,e){return new n(t,e||null)}function n(t,e){function n(){f=h;do var n=t.call(e,u);while(n===s);return f=u.done?c:a,{value:n,done:u.done}}function i(){if(f===h)throw new Error("Generator is already running");if(f===c)throw new Error("Generator has already finished")}var l=this,u=new r,f=o;l.next=function(t){if(i(),u.delegate){var e=u.delegate.next(t);if(!e.done)return e;u.delegate=null}for(f===a&&(u.sent=t);;)try{return n()}catch(r){u.dispatchException(r)}},l["throw"]=function(t){if(i(),u.delegate){var e=u.delegate["throw"](t);if(!e.done)return e;u.delegate=null}if(f===o)throw f=c,t;for(;;)try{return u.dispatchException(t),n()}catch(r){t=r}}}function r(){this.reset()}var i=Object.prototype.hasOwnProperty;if(!t.wrapGenerator){t.wrapGenerator=e,"undefined"!=typeof exports&&(exports.wrapGenerator=e);var o="suspendedStart",a="suspendedYield",h="executing",c="completed",s={};r.prototype={constructor:r,reset:function(){this.next=0,this.sent=void 0,this.tryStack=[],this.done=!1,this.delegate=null;for(var t,e=0;t="t"+e,20>e||i.call(this,t);)this[t]=null,++e},stop:function(){if(i.call(this,"thrown")){var t=this.thrown;throw delete this.thrown,t}return this.done=!0,this.rval},keys:function(t){return Object.keys(t).reverse()},pushTry:function(t,e,n){e&&this.tryStack.push({finallyLoc:e,finallyTempVar:n}),t&&this.tryStack.push({catchLoc:t})},popCatch:function(t){var e=this.tryStack.length-1,n=this.tryStack[e];n&&n.catchLoc===t&&(this.tryStack.length=e)},popFinally:function(t){var e=this.tryStack.length-1,n=this.tryStack[e];n&&i.call(n,"finallyLoc")||(n=this.tryStack[--e]),n&&n.finallyLoc===t&&(this.tryStack.length=e)},dispatchException:function(t){var e,n=[],r=!1;if(this.done)throw t;for(var i=this.tryStack.length-1;i>=0;--i){if(e=this.tryStack[i],e.catchLoc){this.thrown=t,this.next=e.catchLoc,r=!0;break}e.finallyLoc&&(n.push(e),r=!0)}if(!r)throw t;for(;e=n.pop();)this[e.finallyTempVar]=this.next,this.next=e.finallyLoc},delegateYield:function(t,e){this.next=e;var n=t.next(this.sent);return n.done?(this.delegate=null,s):(this.delegate=t,n.value)}}}}(Function("return this")()); | ||
!function(t){function e(t,e){return new n(t,e||null)}function n(t,e){function n(){f=h;do var n=t.call(e,u);while(n===s);return f=u.done?c:a,{value:n,done:u.done}}function i(){if(f===h)throw new Error("Generator is already running");if(f===c)throw new Error("Generator has already finished")}var l=this,u=new r,f=o;l.next=function(t){if(i(),u.delegate){var e=u.delegate.next(t);if(!e.done)return e;u.delegate=null}for(f===a&&(u.sent=t);;)try{return n()}catch(r){u.dispatchException(r)}},l.throw=function(t){if(i(),u.delegate){var e=u.delegate.throw(t);if(!e.done)return e;u.delegate=null}if(f===o)throw f=c,t;for(;;){u.dispatchException(t);try{return n()}catch(r){t=r}}}}function r(){this.reset()}var i=Object.prototype.hasOwnProperty;if(!t.wrapGenerator){t.wrapGenerator=e,"undefined"!=typeof exports&&(exports.wrapGenerator=e);var o="suspendedStart",a="suspendedYield",h="executing",c="completed",s={};r.prototype={constructor:r,reset:function(){this.next=0,this.sent=void 0,this.tryStack=[],this.done=!1,this.delegate=null;for(var t,e=0;i.call(this,t="t"+e)||20>e;++e)this[t]=null},stop:function(){if(i.call(this,"thrown")){var t=this.thrown;throw delete this.thrown,t}return this.done=!0,this.rval},keys:function(t){return Object.keys(t).reverse()},pushTry:function(t,e,n){e&&this.tryStack.push({finallyLoc:e,finallyTempVar:n}),t&&this.tryStack.push({catchLoc:t})},popCatch:function(t){var e=this.tryStack.length-1,n=this.tryStack[e];n&&n.catchLoc===t&&(this.tryStack.length=e)},popFinally:function(t){var e=this.tryStack.length-1,n=this.tryStack[e];n&&i.call(n,"finallyLoc")||(n=this.tryStack[--e]),n&&n.finallyLoc===t&&(this.tryStack.length=e)},dispatchException:function(t){var e,n=[],r=!1;if(this.done)throw t;for(var i=this.tryStack.length-1;i>=0;--i){if(e=this.tryStack[i],e.catchLoc){this.thrown=t,this.next=e.catchLoc,r=!0;break}e.finallyLoc&&(n.push(e),r=!0)}if(!r)throw t;for(;e=n.pop();)this[e.finallyTempVar]=this.next,this.next=e.finallyLoc},delegateYield:function(t,e){this.next=e;var n=t.next(this.sent);return n.done?(this.delegate=null,s):(this.delegate=t,n.value)}}}}(Function("return this")()); |
@@ -70,4 +70,4 @@ /** | ||
enqueue(convert, [ | ||
"test/tests.es6.js", | ||
"test/tests.es5.js" | ||
"./test/tests.es6.js", | ||
"./test/tests.es5.js" | ||
]); | ||
@@ -79,3 +79,3 @@ | ||
"--reporter", "spec", | ||
"test/tests.es6.js" | ||
"./test/tests.es6.js" | ||
]); | ||
@@ -86,3 +86,3 @@ } | ||
"--reporter", "spec", | ||
"test/tests.es5.js" | ||
"./test/tests.es5.js" | ||
]); | ||
@@ -111,3 +111,3 @@ | ||
"./test/tests.es5.js", | ||
"test/tests.browser.js" | ||
"./test/tests.browser.js" | ||
]); | ||
@@ -114,0 +114,0 @@ } catch (ignored) { |
@@ -793,1 +793,20 @@ /** | ||
}); | ||
describe("generator .throw method", function() { | ||
it("should work after the final call to .next", function() { | ||
function *gen() { | ||
yield 1; | ||
} | ||
var g = gen(); | ||
assert.deepEqual(g.next(), { value: 1, done: false }); | ||
var exception = new Error("unhandled exception"); | ||
try { | ||
g.throw(exception); | ||
assert.ok(false, "should have thrown an exception"); | ||
} catch (err) { | ||
assert.strictEqual(err, exception); | ||
} | ||
}); | ||
}); |
82895
2371