Skip to content

Commit

Permalink
Do not build stack trace on some and every
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Dec 3, 2015
1 parent 10cac79 commit d0fea73
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions lib/some-every.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = function (resolvent) {
assign(this, deferred());
this.processCb = this.processCb.bind(this);
this.processValue = this.processValue.bind(this);
this.process();
this.continue();
return this.promise;
}
++this.current;
Expand All @@ -34,11 +34,27 @@ module.exports = function (resolvent) {

Iterator.prototype = {
current: 0,
state: false,
continue: function () {
var result;
while (!this.state) {
result = this.process();
if (this.state !== 'cb') break;
result = this.processCb(result);
if (this.state !== 'value') break;
this.processValue(result);
}
},
process: function () {
var value = assimilate(this.list[this.current]);
if (isPromise(value)) {
if (!value.resolved) {
value.done(this.processCb, this.reject);
value.done(function (result) {
result = this.processCb(result);
if (this.state !== 'value') return;
this.processValue(result);
if (!this.state) this.continue();
}.bind(this), this.reject);
return;
}
if (value.failed) {
Expand All @@ -47,21 +63,25 @@ module.exports = function (resolvent) {
}
value = value.value;
}
this.processCb(value);
this.state = 'cb';
return value;
},
processCb: function (value) {
if (this.cb) {
try {
value = call.call(this.cb, this.context, value, this.current,
this.list);
value = call.call(this.cb, this.context, value, this.current, this.list);
} catch (e) {
this.reject(e);
return;
}
value = assimilate(value);
if (isPromise(value)) {
if (!value.resolved) {
value.done(this.processValue, this.reject);
value.done(function (result) {
this.state = 'value';
this.processValue(result);
if (!this.state) this.continue();
}.bind(this), this.reject);
return;
}
if (value.failed) {
Expand All @@ -71,7 +91,8 @@ module.exports = function (resolvent) {
value = value.value;
}
}
this.processValue(value);
this.state = 'value';
return value;
},
processValue: function (value) {
if (Boolean(value) === resolvent) {
Expand All @@ -80,7 +101,7 @@ module.exports = function (resolvent) {
}
while (++this.current < this.length) {
if (this.current in this.list) {
this.process();
this.state = false;
return;
}
}
Expand Down

0 comments on commit d0fea73

Please sign in to comment.