Skip to content

Commit

Permalink
issue #254 - fixed glitch in fibers fast transform and recompiled
Browse files Browse the repository at this point in the history
  • Loading branch information
bjouhier committed Mar 7, 2015
1 parent 1522ba6 commit e2aff27
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 51 deletions.
2 changes: 1 addition & 1 deletion lib/fibers-fast/flows.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
function() {
var funnel = exports.funnel(max);
this.collect = function(_, count, trim) {
return fstreamline__.invoke((function(callback) {
return fstreamline__.invoke(function(callback) {
if (typeof(callback) != "function") throw new Error("invalid call to collect: no callback")
var results = trim ? [] : new Array(fns.length);
count = count < 0 ? fns.length : Math.min(count, fns.length);
Expand Down
1 change: 1 addition & 0 deletions lib/fibers-fast/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ function transform(source, options) {
function walkExpr() {
skipTo(expr.range[0]);
if (expr.type === 'MemberExpression') {
skipTo(expr.object.range[0]);
if (!expr.computed) {
// Method call: foo.bar(_)
walk(expr.object);
Expand Down
47 changes: 22 additions & 25 deletions lib/generators/runtime-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ function require(str) {
/// `var galaxy = require('galaxy');`
///

var resume;

function link(src, name, dst) {
Object.defineProperty(src, name, {
configurable: false,
Expand All @@ -57,6 +55,9 @@ function require(str) {
return gl[secret] || link(gl, secret, { context: {} });
})();

if (typeof glob.yielded === "undefined") glob.yielded = true;
glob.PENDING = glob.PENDING || {};

var stackHelper, stackHelperError;
try {
stackHelper = require('galaxy-stack');
Expand Down Expand Up @@ -92,8 +93,6 @@ function require(str) {
return Object.prototype.toString.call(val) === "[object Generator]";
}

var PENDING = {};

function Frame(g) {
this.g = g;
this.prev = glob.frame;
Expand Down Expand Up @@ -132,20 +131,18 @@ function require(str) {
glob.frame = glob.frame.prev;
}

var yielded = true;

function run(g, cb, options) {
var rsm = resume;
var rsm = glob.resume;
var emit = glob.emitter && stackHelper && function(ev, g) {
g.frame = g.frame || new Frame(g);
glob.emitter.emit(ev, g.frame);
}

try {
resume = function(err, val) {
if (emit && yielded) {
glob.resume = function(err, val) {
if (emit && glob.yielded) {
emit("resume", g);
yielded = false;
glob.yielded = false;
}
while (g) {
if (options && options.interrupt && options.interrupt()) return;
Expand All @@ -157,19 +154,19 @@ function require(str) {
err = null;
// if we get PENDING, the current call completed with a pending I/O
// resume will be called again when the I/O completes. So just save the context and return here.
if (val === PENDING) {
if (emit && !yielded) {
if (val === glob.PENDING) {
if (emit && !glob.yielded) {
emit("yield", g);
yielded = true;
glob.yielded = true;
}
return;
}
// if we get [PENDING, e, r], the current call invoked its callback synchronously
// we just loop to send/throw what the callback gave us.
if (val && val[0] === PENDING) {
if (val && val[0] === glob.PENDING) {
err = val[1];
val = val[2];
if (err) err = wrapError(err, g, resume);
if (err) err = wrapError(err, g, glob.resume);
}
// else, if g is done we unwind it we send val to the parent generator (or through cb if we are at the top)
else if (v.done) {
Expand Down Expand Up @@ -198,7 +195,7 @@ function require(str) {
// the send/throw call failed.
// we unwind the current generator and we rethrow into the parent generator (or through cb if at the top)
//g.close();
err = wrapError(ex, g, resume);
err = wrapError(ex, g, glob.resume);
if (emit) popFrame(g);
g = g.prev;
val = undefined;
Expand All @@ -210,10 +207,10 @@ function require(str) {
}

// start the resume loop
resume();
glob.resume();
} finally {
// restore resume global
resume = rsm;
glob.resume = rsm;
}
}

Expand Down Expand Up @@ -241,28 +238,28 @@ function require(str) {
// Set things up so that call returns:
// * PENDING if it completes with a pending I/O (and cb will be called later)
// * [PENDING, e, r] if the callback is called synchronously.
var result = PENDING,
var result = glob.PENDING,
sync = true;
var rsm = resume;
var rsm = glob.resume;

// convert args to array so that args.length gets correctly set if idx is args.length
args = Array.prototype.slice.call(args, 0);
var cx = glob.context;
args[idx == null ? args.length : idx] = function(e, r) {
var oldContext = glob.context;
var oldResume = resume;
var oldResume = glob.resume;
try {
if (options) r = mapResults(options, Array.prototype.slice.call(arguments, 1));
glob.context = cx;
resume = rsm;
glob.resume = rsm;
if (sync) {
result = [PENDING, e, r];
result = [glob.PENDING, e, r];
} else {
resume(e, r);
glob.resume(e, r);
}
} finally {
glob.context = oldContext;
resume = oldResume;
glob.resume = oldResume;
}
}
fn.apply(that, args);
Expand Down
47 changes: 22 additions & 25 deletions lib/generators/transform-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -8752,8 +8752,6 @@ if (typeof exports !== 'undefined') {
/// `var galaxy = require('galaxy');`
///

var resume;

function link(src, name, dst) {
Object.defineProperty(src, name, {
configurable: false,
Expand All @@ -8779,6 +8777,9 @@ if (typeof exports !== 'undefined') {
return gl[secret] || link(gl, secret, { context: {} });
})();

if (typeof glob.yielded === "undefined") glob.yielded = true;
glob.PENDING = glob.PENDING || {};

var stackHelper, stackHelperError;
try {
stackHelper = require('galaxy-stack');
Expand Down Expand Up @@ -8814,8 +8815,6 @@ if (typeof exports !== 'undefined') {
return Object.prototype.toString.call(val) === "[object Generator]";
}

var PENDING = {};

function Frame(g) {
this.g = g;
this.prev = glob.frame;
Expand Down Expand Up @@ -8854,20 +8853,18 @@ if (typeof exports !== 'undefined') {
glob.frame = glob.frame.prev;
}

var yielded = true;

function run(g, cb, options) {
var rsm = resume;
var rsm = glob.resume;
var emit = glob.emitter && stackHelper && function(ev, g) {
g.frame = g.frame || new Frame(g);
glob.emitter.emit(ev, g.frame);
}

try {
resume = function(err, val) {
if (emit && yielded) {
glob.resume = function(err, val) {
if (emit && glob.yielded) {
emit("resume", g);
yielded = false;
glob.yielded = false;
}
while (g) {
if (options && options.interrupt && options.interrupt()) return;
Expand All @@ -8879,19 +8876,19 @@ if (typeof exports !== 'undefined') {
err = null;
// if we get PENDING, the current call completed with a pending I/O
// resume will be called again when the I/O completes. So just save the context and return here.
if (val === PENDING) {
if (emit && !yielded) {
if (val === glob.PENDING) {
if (emit && !glob.yielded) {
emit("yield", g);
yielded = true;
glob.yielded = true;
}
return;
}
// if we get [PENDING, e, r], the current call invoked its callback synchronously
// we just loop to send/throw what the callback gave us.
if (val && val[0] === PENDING) {
if (val && val[0] === glob.PENDING) {
err = val[1];
val = val[2];
if (err) err = wrapError(err, g, resume);
if (err) err = wrapError(err, g, glob.resume);
}
// else, if g is done we unwind it we send val to the parent generator (or through cb if we are at the top)
else if (v.done) {
Expand Down Expand Up @@ -8920,7 +8917,7 @@ if (typeof exports !== 'undefined') {
// the send/throw call failed.
// we unwind the current generator and we rethrow into the parent generator (or through cb if at the top)
//g.close();
err = wrapError(ex, g, resume);
err = wrapError(ex, g, glob.resume);
if (emit) popFrame(g);
g = g.prev;
val = undefined;
Expand All @@ -8932,10 +8929,10 @@ if (typeof exports !== 'undefined') {
}

// start the resume loop
resume();
glob.resume();
} finally {
// restore resume global
resume = rsm;
glob.resume = rsm;
}
}

Expand Down Expand Up @@ -8963,28 +8960,28 @@ if (typeof exports !== 'undefined') {
// Set things up so that call returns:
// * PENDING if it completes with a pending I/O (and cb will be called later)
// * [PENDING, e, r] if the callback is called synchronously.
var result = PENDING,
var result = glob.PENDING,
sync = true;
var rsm = resume;
var rsm = glob.resume;

// convert args to array so that args.length gets correctly set if idx is args.length
args = Array.prototype.slice.call(args, 0);
var cx = glob.context;
args[idx == null ? args.length : idx] = function(e, r) {
var oldContext = glob.context;
var oldResume = resume;
var oldResume = glob.resume;
try {
if (options) r = mapResults(options, Array.prototype.slice.call(arguments, 1));
glob.context = cx;
resume = rsm;
glob.resume = rsm;
if (sync) {
result = [PENDING, e, r];
result = [glob.PENDING, e, r];
} else {
resume(e, r);
glob.resume(e, r);
}
} finally {
glob.context = oldContext;
resume = oldResume;
glob.resume = oldResume;
}
}
fn.apply(that, args);
Expand Down

0 comments on commit e2aff27

Please sign in to comment.