Browse files

renamed files to use new extensions + got rid of obsolete files

  • Loading branch information...
1 parent 065afe0 commit 9a850539332b9b6f31b259c5466f7d28f52b5d02 @bjouhier bjouhier committed Mar 31, 2012
View
1 examples/misc/bench.js → examples/misc/bench._js
@@ -1,5 +1,4 @@
"use strict";
-if (!require('streamline/module')(module)) return;
var mode = typeof fstreamline__ !== 'undefined' ? "fibers" : "callback";
View
2 examples/misc/shebang-coffee.sh
@@ -1,4 +1,4 @@
-#!/usr/bin/env coffee-streamline
+#!/usr/bin/env _coffee
console.log "waiting 1 second"
setTimeout _, 1000
console.log "done!"
View
2 examples/misc/shebang.sh
@@ -1,4 +1,4 @@
-#!/usr/bin/env node-streamline
+#!/usr/bin/env _node
console.log("waiting 1 second");
setTimeout(_, 1000);
console.log("done!");
View
1 examples/streams/googleClient.js → examples/streams/googleClient._js
@@ -4,7 +4,6 @@
* Demonstrates the streamline http client wrapper
*/
"use strict";
-if (!require('streamline/module')(module)) return;
// require the streamline streams wrapper
var streams = require('streamline/lib/streams/server/streams');
View
3 lib/compile.js
@@ -1,3 +0,0 @@
-console.error("Module moved to subdirectory. New require path is streamline/lib/compiler/compile");
-var moved = require("./compiler/compile");
-for (var name in moved) exports[name] = moved[name];
View
2 lib/compiler/underscored.js
@@ -55,7 +55,7 @@ function run(options) {
// Streamlined JavaScript extension handler.
require.extensions['._js'] = function (module, filename) {
var code = fs.readFileSync(filename, "utf8");
- streamliners.node(module, filename, code);
+ streamliners.js(module, filename, code);
}
if (options.registerOnly) return;
View
4 lib/index.js
@@ -1,3 +1 @@
-//console.error("Module moved to subdirectory. New require path is streamline/lib/compiler");
-var moved = require("./compiler/index");
-for (var name in moved) exports[name] = moved[name];
+module.exports = require("./compiler/index");
View
3 lib/register.js
@@ -1,3 +0,0 @@
-console.error("Module moved to subdirectory. New require path is streamline/lib/compiler/register");
-var moved = require("./compiler/register");
-for (var name in moved) exports[name] = moved[name];
View
148 lib/streams/client/streams--fibers.js
@@ -1,148 +0,0 @@
-/*** Generated by streamline fibers 0.2.4 - DO NOT EDIT ***/var fstreamline__ = require("streamline/lib/fibers/runtime"); (fstreamline__.create(function(_) { /**
- * Copyright (c) 2011 Bruno Jouhier <bruno.jouhier@sage.com>
- * MIT License
- */
-"use strict";
-//streamline.options = { "lines" : "preserve" }
-/// !nodoc
-///
-/// # streamline/lib/streams/client/streams
-///
-/// Client Streams module
-/// The `streams` module contains _pull mode_ wrappers around AJAX streams.
-///
-// TODO: Client streams only deal with strings for now
-
-function DataBuffer(options) {
- var _chunks = [];
-
- this.read = fstreamline__.create(function(_, len) {
- if (len < 0) len = Infinity;
- if (len == 0) return "";
- var chunks = [],
- total = 0;
- while (total < len) {
- var chunk = _chunks.splice(0, 1)[0];
- if (!chunk) return chunks.length == 0 ? null : chunks.join('');
- if (total + chunk.length <= len) {
- chunks.push(chunk);
- total += chunk.length;
- } else {
- chunks.push(chunk.substring(0, len - total));
- _chunks.splice(0, 0, chunk.substring(len - total));
- total = len;
- }
- }
- return chunks.join('');
- }, 0)
- /// * `data = stream.readAll(_)`
- /// reads till the end of stream.
- /// Equivalent to `stream.read(_, -1)`.
- this.readAll = fstreamline__.create(function(_) {
- return fstreamline__.invoke(this, "read", [_, -1], 0);
- }, 0)
- /// * `stream.unread(chunk)`
- /// pushes the chunk back to the stream.
- /// returns `this` for chaining.
- this.unread = function(chunk) {
- _chunks.splice(0, 0, chunk);
- return this;
- }
-
- this.write = fstreamline__.create(function(_, data, enc) {
- _chunks.push(data);
- return this;
- }, 0)
-
- this.end = function(data, enc) {
- if (data) _chunks.push(data);
- return this;
- }
-
- this.contents = function() {
- return _chunks.join('');
- }
-}
-
-function HttpError(statusCode, message) {
- this.statusCode = statusCode;
- this.message = message;
- this.stack = new Error().stack;
-}
-
-function _fixHttpClientOptions(options) {
- if (!options) throw new Error("request error: no options");
- if (typeof options === "string") options = {
- url: options
- };
- return options;
-}
-///
-/// ## HttpClientRequest
-///
-/// This is a wrapper around jQuery's `$.ajax` call, with
-/// the same API as the server side HttpClientRequest
-///
-/// This stream is writable (see Writable Stream above).
-///
-/// * `request = streams.httpRequest(options)`
-/// creates the wrapper.
-/// The options are the following:
-/// * `method`: the HTTP method, `'GET'` by default.
-/// * `headers`: the HTTP headers.
-/// * `url`: the requested URL (with query string if necessary).
-/// * `proxy.url`: the proxy URL.
-/// * `lowMark` and `highMark`: low and high water mark values for buffering (in bytes or characters depending
-/// on encoding).
-/// Note that these values are only hints as the data is received in chunks.
-
-
-function HttpClientRequest(options) {
- options = _fixHttpClientOptions(options);
- DataBuffer.call(this, options);
- var _xhr;
- this.response = function(callback) {
- if (!callback) return __future.call(this, this.response, arguments, 0);
- $.ajax({
- url: options.url,
- headers: options.headers,
- type: options.method,
- data: this.contents(),
- dataType: "text",
- // bypass jQuery parsing
- beforeSend: function(xhr) {
- _xhr = xhr;
- },
- success: function(data, statusText, xhr) {
- callback(null, new HttpClientResponse(data, xhr));
- },
- error: function(xhr, statusText, message) {
- if (statusText == "error") callback(new HttpError(xhr.status, statusText + ": " + message));
- else callback(new HttpError(400, statusText + ": " + message));
- }
- });
- }
- this.abort = function() {
- _xhr && _xhr.abort();
- _xhr = null;
- }
-}
-
-function HttpClientResponse(data, xhr) {
- DataBuffer.call(this);
- this.end(data);
- this.statusCode = xhr.status;
- this.headers = {};
- var self = this;
- xhr.getAllResponseHeaders().replace(/\r\n/g, '\n').split('\n').forEach(function(header) {
- var pair = header.split(':');
- self.headers[pair[0].toLowerCase()] = pair[1] && pair[1].trim();
- });
-}
-
-exports.httpRequest = function(options) {
- return new HttpClientRequest(options);
-};
-}, 0).call(this, function(err) {
- if (err) throw err;
-}));
View
1 lib/streams/client/streams_.js → lib/streams/client/streams._js
@@ -3,7 +3,6 @@
* MIT License
*/
"use strict";
-//streamline.options = { "lines" : "preserve" }
/// !nodoc
///
/// # streamline/lib/streams/client/streams
View
1 lib/streams/jsonRequest.js → lib/streams/jsonRequest._js
@@ -3,7 +3,6 @@
* MIT License
*/
"use strict";
-if (!require('streamline/module')(module)) return;
var streams = require("./streams");
/// !nodoc -- experimental
View
1 lib/streams/readers.js → lib/streams/readers._js
@@ -3,7 +3,6 @@
* MIT License
*/
"use strict";
-if (!require('streamline/module')(module)) return;
var streams = require("./streams");
View
146 lib/streams/server/httpHelper.js
@@ -1,146 +0,0 @@
-/**
- * Copyright (c) 2011 Bruno Jouhier <bruno.jouhier@sage.com>
- * MIT License
- */
-"use strict";
-if (!require('streamline/module')(module)) return;
-
-console.log("streamline/lib/streams/server/httpHelper is OBSOLETE.\nYou can still turn it into a private module and hack it at your will.")
-var urlHelper = require("streamline/lib/util/url");
-/// !nodoc -- experimental
-///
-/// # streamline/lib/streams/server/httpHelper
-///
-/// HTTP helpers
-exports.HttpStatus = {
- OK: 200,
- Created: 201,
- Accepted: 202,
- NoContent: 204,
- MovedPermanently: 301,
- Found: 302,
- SeeOther: 303,
- NotModified: 304,
- TemporaryRedirect: 307,
- BadRequest: 400,
- Unauthorized: 401,
- Forbidden: 403,
- NotFound: 404,
- MethodNotAllowed: 405,
- NotAcceptable: 406,
- Conflict: 409,
- Gone: 410,
- PreconditionFailed: 412,
- UnsupportedMediaType: 415,
- InternalServerError: 500,
- NotImplemented: 501,
- ServiceUnavailable: 503
-}
-
-function _classifyMedia(str) {
- if (str == "*" || str == "*/*") return "*";
- var lower = str.toLowerCase();
- if (lower.indexOf("xml") >= 0) return "xml";
- if (lower.indexOf("html") >= 0) return "html";
- if (lower.indexOf("json") >= 0) return "json";
- if (lower.indexOf("text") >= 0) return "text";
- if (lower.indexOf("image") >= 0) return "image";
- if (lower.indexOf("pdf") >= 0) return "pdf";
- return "unknown";
-}
-
-exports.parseAccept = function(str) {
- // parse and sort by decreasing quality
- var accept = (str || "").toString().split(/,\s*/).map(function(part, i) {
- var m = part.match(/^([^\s,]+?)(?:;\s*q=(\d+(?:\.\d+)?))?$/)
- return m && [m[1], Number(m[2] || 1.0), i];
- }).filter(function(elt) {
- return elt;
- }).sort(function(elt1, elt2) {
- return elt2[1] - elt1[1] || elt1[2] - elt2[2]; // 2nd test to preserve order
- }).map(function(elt) {
- var split = elt[0].split(';');
- var result = {
- rawType: split[0],
- type: _classifyMedia(split[0]),
- parameters: {}
- };
- split.slice(1).forEach(function(str) {
- var pair = str.split(/\s*=\s*/);
- result.parameters[pair[0]] = pair[1];
- });
- return result;
- })
- // empty accept means accept anything
- return accept.length > 0 ? accept : [{
- rawType: "*",
- type: "*",
- parameters: {}
- }];
-}
-
-function HttpError(statusCode, message) {
- this.statusCode = statusCode;
- this.message = message;
- this.stack = new Error().stack;
-}
-
-exports.tracer = null;
-
-exports.HttpContext = function(request, response, options) {
- if (request == null) // subclassing
- return;
- options = options || {};
-
- if (exports.tracer) {
- exports.tracer("\nHTTP REQUEST: " + request.method + " " + request.url + "\n");
- exports.tracer("headers: " + JSON.stringify(request.headers) + "\n");
- }
-
- this.request = request;
- this.response = response;
- this.method = (request.headers[options.methodHeader || "x-http-method-override"] || request.method).toLowerCase();
- // URL stuff
- var _split = request.url.split('?');
- this.path = _split.splice(0, 1)[0];
- var _urlBegin = (request.socket.secure ? "https" : "http") + "://" + request.headers.host;
- this.url = _urlBegin + this.path;
- this.rawQuery = _split.join('?');
- this.query = urlHelper.parseQueryString(this.rawQuery);
- var _segments = this.path.split('/').map(function(seg) {
- return decodeURIComponent(seg);
- });
- var _segI = 1; // start after leading /
- this.walkUrl = function() {
- return _segments[_segI++];
- }
- this.walked = function() {
- return _urlBegin + _segments.slice(0, _segI).join("/");
- }
-
- // Accept stuff
- this.rawAccept = this.query[options.acceptParam] || request.headers.accept || "*";
- this.accept = exports.parseAccept(this.rawAccept);
-
- // Request body stuff
- this.parseBody = function(_) {
- var ct = request.headers["content-type"];
- if (!ct) return null;
- if (ct.indexOf("application/json") !== 0) throw new HttpError(415, "expected application/json, got: " + ct);
- // assume utf8 -- be smarter later
- //request.setEncoding('utf8');
- var str = request.readAll(_);
- if (str == null) return null;
- if (exports.tracer) exports.tracer("body: " + str + "\n")
- return JSON.parse(str);
- }
-
- this.reply = function(code, message, headers) {
- headers = headers || {};
- if (message && !headers["content-type"]) headers["content-type"] = "text/plain";
- response.writeHead(code, headers);
- response.end(message);
- }
-
- this.scratch = {}; // scratch area where business logic can write stuff
-}
View
1 lib/streams/server/streams.js → lib/streams/server/streams._js
@@ -3,7 +3,6 @@
* MIT License
*/
"use strict";
-if (!require('streamline/module')(module, { "ninja": true })) return;
/// !doc
///
View
10 lib/streams/streams.js
@@ -7,15 +7,9 @@
/// !nodoc -- experimental combo streams
///
-
-function copy(src, dst) {
- Object.keys(src).forEach(function(key) {
- dst[key] = src[key]
- })
-}
if (typeof process === "object" && typeof process.cwd === "function") {
var req = require; // trick to skip this dependency when serving client side requires
- copy(req('./server/streams'), exports);
+ module.exports = req('./server/streams');
} else {
- copy(require('./client/streams'), exports);
+ module.exports = require('./client/streams');
}
View
1 lib/tools/docTool.js → lib/tools/docTool._js
@@ -4,7 +4,6 @@
*/
"use strict";
-if (!require('streamline/module')(module)) return;
/// !doc
///
/// # streamline/lib/tools/docTool
View
3 lib/transform.js
@@ -1,3 +0,0 @@
-console.error("Module moved to subdirectory. New require path is streamline/lib/callbacks/transform");
-var moved = require("./callbacks/transform");
-for (var name in moved) exports[name] = moved[name];
View
338 lib/util/flows--fibers.js
@@ -1,338 +0,0 @@
-/*** Generated by streamline fibers 0.2.4 - DO NOT EDIT ***/var fstreamline__ = require("streamline/lib/fibers/runtime"); (fstreamline__.create(function(_) { /**
- * Copyright (c) 2011 Bruno Jouhier <bruno.jouhier@sage.com>
- *
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use,
- * copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following
- * conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * streamline.options = { "lines": "preserve" }
- */
-/// !doc
-///
-/// # streamline/lib/util/flows
-///
-/// Flows Module
-///
-/// The `streamline/lib/util/flows` module contains some handy utilities for streamline code
-///
-(function(exports) {
- "use strict";
- /// ## Array utilities
- ///
- /// The following functions are async equivalents of the ES5 Array methods (`forEach`, `map`, `filter`, ...)
- ///
- /// * `flows.each(_, array, fn, [thisObj])`
- /// applies `fn` sequentially to the elements of `array`.
- /// `fn` is called as `fn(_, elt, i)`.
- exports.each = fstreamline__.create(function(_, array, fn, thisObj) {
- if (!array || !array.length)
- return; // array;
- var len = array.length;
- for (var i = 0; i < len; i++)
- fstreamline__.invoke(fn, "call", [thisObj, _, array[i], i], 1)
- return array;
- }, 0)
- /// * `result = flows.map(_, array, fn, [thisObj])`
- /// transforms `array` by applying `fn` to each element in turn.
- /// `fn` is called as `fn(_, elt, i)`.
- exports.map = fstreamline__.create(function(_, array, fn, thisObj) {
- if (!array)
- return array;
- var result = [];
- var len = array.length;
- for (var i = 0; i < len; i++)
- result[i] = fstreamline__.invoke(fn, "call", [thisObj, _, array[i], i], 1);
- return result;
- }, 0)
- /// * `result = flows.filter(_, array, fn, [thisObj])`
- /// generates a new array that only contains the elements that satisfy the `fn` predicate.
- /// `fn` is called as `fn(_, elt)`.
- exports.filter = fstreamline__.create(function(_, array, fn, thisObj) {
- if (!array)
- return array;
- var result = [];
- var len = array.length;
- for (var i = 0; i < len; i++) {
- var elt = array[i];
- if (fstreamline__.invoke(fn, "call", [thisObj, _, elt], 1))
- result.push(elt)
- }
- return result;
- }, 0)
- /// * `bool = flows.every(_, array, fn, [thisObj])`
- /// returns true if `fn` is true on every element (if `array` is empty too).
- /// `fn` is called as `fn(_, elt)`.
- exports.every = fstreamline__.create(function(_, array, fn, thisObj) {
- if (!array)
- return; // undefined
- var len = array.length;
- for (var i = 0; i < len; i++) {
- if (!fstreamline__.invoke(fn, "call", [thisObj, _, array[i]], 1))
- return false;
- }
- return true;
- }, 0)
- /// * `bool = flows.some(_, array, fn, [thisObj])`
- /// returns true if `fn` is true for at least one element.
- /// `fn` is called as `fn(_, elt)`.
- exports.some = fstreamline__.create(function(_, array, fn, thisObj) {
- if (!array)
- return; // undefined
- var len = array.length;
- for (var i = 0; i < len; i++) {
- if (fstreamline__.invoke(fn, "call", [thisObj, _, array[i]], 1))
- return true;
- }
- return false;
- }, 0)
- /// * `result = flows.reduce(_, array, fn, val, [thisObj])`
- /// reduces by applying `fn` to each element.
- /// `fn` is called as `val = fn(_, val, elt, i, array)`.
- exports.reduce = fstreamline__.create(function(_, array, fn, v, thisObj) {
- if (!array)
- return v; // undefined
- var len = array.length;
- for (var i = 0; i < len; i++) {
- v = fstreamline__.invoke(fn, "call", [thisObj, _, v, array[i], i, array], 1);
- }
- return v;
- }, 0)
- /// * `result = flows.reduceRight(_, array, fn, val, [thisObj])`
- /// reduces from end to start by applying `fn` to each element.
- /// `fn` is called as `val = fn(_, val, elt, i, array)`.
- exports.reduceRight = fstreamline__.create(function(_, array, fn, v, thisObj) {
- if (!array)
- return v; // undefined
- var len = array.length;
- for (var i = len - 1; i >= 0; i--) {
- v = fstreamline__.invoke(fn, "call", [thisObj, _, v, array[i], i, array], 1);
- }
- return v;
- }, 0)
-
- /// * `array = flows.sort(_, array, compare, [beg], [end])`
- /// sorts the array.
- /// `compare` is called as `cmp = compare(_, elt1, elt2)`
- ///
- /// Note: this function _changes_ the original array (and returns it)
- exports.sort = fstreamline__.create(function(_, array, compare, beg, end){var _qsort_ = fstreamline__.create(_qsort);
- beg = beg || 0;
- end = end == null ? array.length - 1 : end;
-
- function _qsort(_, beg, end){
- if (beg >= end)
- return;
-
- if (end == beg + 1) {
- if (fstreamline__.invoke(null, compare, [_, array[beg], array[end]], 0) > 0) {
- var tmp = array[beg];
- array[beg] = array[end];
- array[end] = tmp;
- }
- return;
- }
-
- var mid = Math.floor((beg + end) / 2);
- var o = array[mid];
- var nbeg = beg;
- var nend = end;
-
- while (nbeg <= nend) {
- while (nbeg < end && fstreamline__.invoke(null, compare, [_, array[nbeg], o], 0) < 0)
- nbeg++;
-
- while (beg < nend && fstreamline__.invoke(null, compare, [_, o, array[nend]], 0) < 0)
- nend--;
-
- if (nbeg <= nend) {
- var tmp = array[nbeg];
- array[nbeg] = array[nend];
- array[nend] = tmp;
- nbeg++;
- nend--;
- }
- }
-
- if (nbeg < end)
- _qsort(_, nbeg, end);
- if (beg < nend)
- _qsort(_, beg, nend);
- }
- _qsort(_, beg, end);
- return array;
- }, 0)
- ///
- /// ## Object utility
- ///
- /// The following function can be used to iterate through object properties:
- ///
- /// * `flows.eachKey(_, obj, fn)`
- /// calls `fn(_, key, obj[key])` for every `key` in `obj`.
- exports.eachKey = fstreamline__.create(function(_, obj, fn, thisObj) {
- if (!obj)
- return obj;
- for (var key in obj) {
- if (Object.prototype.hasOwnProperty.call(obj, key))
- fstreamline__.invoke(fn, "call", [thisObj, _, key, obj[key]], 1);
- }
- return obj;
- }, 0)
- ///
- /// ## Workflow Utilities
- ///
- // deprecated -- don't document
- exports.spray = function(fns, max) {
- return new
- function() {
- var funnel = exports.funnel(max);
- this.collect = function(callback, count, trim) {
- 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);
- if (count == 0)
- return callback(null, results);
- var collected = 0;
- for (var i = 0; i < fns.length; i++) {
- (function(i) {
- funnel( function(err, result) {
- if (err)
- return callback(err);
- if (trim)
- results.push(result);
- else
- results[i] = result;
- if (++collected == count)
- return callback(null, results);
- }, fns[i])
- })(i);
- }
- }
- this.collectOne = function(callback) {
- return this.collect( function(err, result) {
- return callback(err, result && result[0]);
- }, 1, true)
- }
- this.collectAll = function(callback) {
- return this.collect(callback, -1, false);
- }
- }
-
- }
- /// * `fun = flows.funnel(max)`
- /// limits the number of concurrent executions of a given code block.
- ///
- /// The `funnel` function is typically used with the following pattern:
- ///
- /// ``` javascript
- /// // somewhere
- /// var myFunnel = flows.funnel(10); // create a funnel that only allows 10 concurrent executions.
- ///
- /// // elsewhere
- /// myFunnel(_, function(_) { /* code with at most 10 concurrent executions */ });
- /// ```
- ///
- /// The `diskUsage2.js` example demonstrates how these calls can be combined to control concurrent execution.
- ///
- /// The `funnel` function can also be used to implement critical sections. Just set funnel's `max` parameter to 1.
- exports.funnel = function(max) {
- max = typeof max == "undefined" ? -1 : max;
- var queue = [];
- var active = 0;
-
- return function(callback, fn) {
- //console.log("FUNNEL: active=" + active + ", queued=" + queue.length);
- if (max < 0)
- return fn(callback);
-
- queue.push({
- fn: fn,
- cb: callback
- });
-
- function _doOne() {
- var current = queue.splice(0, 1)[0];
- if (!current.cb)
- return current.fn();
- active++;
- current.fn( function(err, result) {
- active--;
- current.cb(err, result);
- while (active < max && queue.length > 0)
- _doOne();
- });
- }
-
- while (active < max && queue.length > 0)
- _doOne();
- }
- }
-
- ///
- /// * `results = flows.collect(_, futures)`
- /// collects the results of an array of futures
- exports.collect = fstreamline__.create(function(_, futures) {
- return fstreamline__.invoke(exports, "map", [_, futures, fstreamline__.create(function(_, future) {
- return fstreamline__.invoke(null, future, [_], 0);
- }, 0)], 0);
- }, 0)
-
- // Obsolete API - use require('streamline/lib/globals').context instead
- var globals = require("streamline/lib/globals");
- exports.setContext = function(ctx) {
- var old = globals.context;
- globals.context = ctx;
- return old;
- }
- exports.getContext = function() {
- return globals.context;
- }
-
- ///
- /// ## Miscellaneous
- ///
- /// Utility functions:
- ///
- /// * `flows.nextTick(_)`
- /// `nextTick` function for both browser and server.
- /// Aliased to `process.nextTick` on the server side.
- exports.nextTick = typeof process === "object" && typeof process.nextTick === "function"
- ? process.nextTick : function(callback) {
- setTimeout(function() { callback(); }, 0);
- };
-
- /// * `result = flows.apply(_, fn, thisObj, args, [index])`
- /// Helper to apply `Function.apply` to streamline functions.
- /// Equivalent to `result = fn.apply(thisObj, argsWith_)` where `argsWith_` is
- /// a modified argument list in which the callback has been inserted at `index`
- /// (at the end of the argument list if `index` is not specified).
- exports.apply = function apply(callback, fn, thisObj, args, index) {
- if (callback == null)
- return __future(apply, arguments, 0);
- Array.prototype.splice.call(args, index != null ? index : args.length, 0, callback);
- return fn.apply(thisObj, args);
- }
-
-
-})(typeof exports !== 'undefined' ? exports : (window.StreamlineFlows = window.StreamlineFlows || {}));
-
-}, 0).call(this, function(err) {
- if (err) throw err;
-}));
View
1 lib/util/flows_.js → lib/util/flows._js
@@ -22,7 +22,6 @@
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
- * streamline.options = { "lines": "preserve" }
*/
/// !doc
///
View
334 lib/util/flows.js
@@ -1,334 +0,0 @@
-/*** Generated by streamline 0.2.5 - DO NOT EDIT ***/ var __rt=require('streamline/lib/callbacks/runtime').runtime(__filename),__func=__rt.__func,__cb=__rt.__cb,__forIn=__rt.__forIn,__future=__rt.__future,__propagate=__rt.__propagate,__trap=__rt.__trap,__setEF=__rt.__setEF,__g=__rt.__g; (function(exports) {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- "use strict";
-
-
-
-
-
-
-
- exports.each = function exports_each__1(_, array, fn, thisObj) { var len, i; var __frame = { name: "exports_each__1", line: 44 }; return __func(_, this, arguments, exports_each__1, 0, __frame, function __$exports_each__1() {
- if ((!array || !array.length)) { return _(null); } ;
-
- len = array.length;
- i = 0; var __2 = false; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$exports_each__1() { __more = false; if (__2) { i++; } else { __2 = true; } ; var __1 = (i < len); if (__1) {
- return fn.call(thisObj, __cb(_, __frame, 5, 3, function __$exports_each__1() { while (__more) { __loop(); }; __more = true; }, true), array[i], i); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(function __$exports_each__1() {
- return _(null, array); }); }); };
-
-
-
-
- exports.map = function exports_map__2(_, array, fn, thisObj) { var result, len, i; var __frame = { name: "exports_map__2", line: 55 }; return __func(_, this, arguments, exports_map__2, 0, __frame, function __$exports_map__2() {
- if (!array) {
- return _(null, array); } ;
- result = [];
- len = array.length;
- i = 0; var __3 = false; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$exports_map__2() { __more = false; if (__3) { i++; } else { __3 = true; } ; var __2 = (i < len); if (__2) {
- return fn.call(thisObj, __cb(_, __frame, 6, 15, function ___(__0, __1) { result[i] = __1; while (__more) { __loop(); }; __more = true; }, true), array[i], i); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(function __$exports_map__2() {
- return _(null, result); }); }); };
-
-
-
-
- exports.filter = function exports_filter__3(_, array, fn, thisObj) { var result, len, i, elt; var __frame = { name: "exports_filter__3", line: 67 }; return __func(_, this, arguments, exports_filter__3, 0, __frame, function __$exports_filter__3() {
- if (!array) {
- return _(null, array); } ;
- result = [];
- len = array.length;
- i = 0; var __3 = false; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$exports_filter__3() { __more = false; if (__3) { i++; } else { __3 = true; } ; var __2 = (i < len); if (__2) {
- elt = array[i];
- return fn.call(thisObj, __cb(_, __frame, 7, 7, function ___(__0, __1) { return (function __$exports_filter__3(__then) { if (__1) {
- result.push(elt); __then(); } else { __then(); } ; })(function __$exports_filter__3() { while (__more) { __loop(); }; __more = true; }); }, true), elt); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(function __$exports_filter__3() {
-
- return _(null, result); }); }); };
-
-
-
-
- exports.every = function exports_every__4(_, array, fn, thisObj) { var len, i; var __frame = { name: "exports_every__4", line: 82 }; return __func(_, this, arguments, exports_every__4, 0, __frame, function __$exports_every__4() {
- if (!array) { return _(null); } ;
-
- len = array.length;
- i = 0; var __4 = false; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$exports_every__4() { __more = false; if (__4) { i++; } else { __4 = true; } ; var __3 = (i < len); if (__3) {
- return fn.call(thisObj, __cb(_, __frame, 5, 8, function ___(__0, __2) { var __1 = !__2; return (function __$exports_every__4(__then) { if (__1) {
- return _(null, false); } else { __then(); } ; })(function __$exports_every__4() { while (__more) { __loop(); }; __more = true; }); }, true), array[i]); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(function __$exports_every__4() {
-
- return _(null, true); }); }); };
-
-
-
-
- exports.some = function exports_some__5(_, array, fn, thisObj) { var len, i; var __frame = { name: "exports_some__5", line: 95 }; return __func(_, this, arguments, exports_some__5, 0, __frame, function __$exports_some__5() {
- if (!array) { return _(null); } ;
-
- len = array.length;
- i = 0; var __3 = false; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$exports_some__5() { __more = false; if (__3) { i++; } else { __3 = true; } ; var __2 = (i < len); if (__2) {
- return fn.call(thisObj, __cb(_, __frame, 5, 7, function ___(__0, __1) { return (function __$exports_some__5(__then) { if (__1) {
- return _(null, true); } else { __then(); } ; })(function __$exports_some__5() { while (__more) { __loop(); }; __more = true; }); }, true), array[i]); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(function __$exports_some__5() {
-
- return _(null, false); }); }); };
-
-
-
-
- exports.reduce = function exports_reduce__6(_, array, fn, v, thisObj) { var len, i; var __frame = { name: "exports_reduce__6", line: 108 }; return __func(_, this, arguments, exports_reduce__6, 0, __frame, function __$exports_reduce__6() {
- if (!array) {
- return _(null, v); } ;
- len = array.length;
- i = 0; var __3 = false; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$exports_reduce__6() { __more = false; if (__3) { i++; } else { __3 = true; } ; var __2 = (i < len); if (__2) {
- return fn.call(thisObj, __cb(_, __frame, 5, 7, function ___(__0, __1) { v = __1; while (__more) { __loop(); }; __more = true; }, true), v, array[i], i, array); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(function __$exports_reduce__6() {
-
- return _(null, v); }); }); };
-
-
-
-
- exports.reduceRight = function exports_reduceRight__7(_, array, fn, v, thisObj) { var len, i; var __frame = { name: "exports_reduceRight__7", line: 120 }; return __func(_, this, arguments, exports_reduceRight__7, 0, __frame, function __$exports_reduceRight__7() {
- if (!array) {
- return _(null, v); } ;
- len = array.length;
- i = (len - 1); var __3 = false; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$exports_reduceRight__7() { __more = false; if (__3) { i--; } else { __3 = true; } ; var __2 = (i >= 0); if (__2) {
- return fn.call(thisObj, __cb(_, __frame, 5, 7, function ___(__0, __1) { v = __1; while (__more) { __loop(); }; __more = true; }, true), v, array[i], i, array); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(function __$exports_reduceRight__7() {
-
- return _(null, v); }); }); };
-
-
-
-
-
-
-
- exports.sort = function exports_sort__8(_, array, compare, beg, end) {
-
-
-
- function _qsort(_, beg, end) { var tmp, mid, o, nbeg, nend; var __frame = { name: "_qsort", line: 139 }; return __func(_, this, arguments, _qsort, 0, __frame, function __$_qsort() {
- if ((beg >= end)) { return _(null); } ; return (function __$_qsort(__then) {
-
-
- if ((end == (beg + 1))) {
- return compare(__cb(_, __frame, 5, 8, function ___(__0, __2) { var __1 = (__2 > 0); return (function __$_qsort(__then) { if (__1) {
- tmp = array[beg];
- array[beg] = array[end];
- array[end] = tmp; __then(); } else { __then(); } ; })(function __$_qsort() { return _(null); }); }, true), array[beg], array[end]); } else { __then(); } ; })(function __$_qsort() {
-
-
-
-
- mid = Math.floor((((beg + end)) / 2));
- o = array[mid];
- nbeg = beg;
- nend = end; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$_qsort() { __more = false;
-
- var __4 = (nbeg <= nend); if (__4) { return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$_qsort() { __more = false; return (function __$_qsort(_) { return (function __$_qsort(_) {
- var __1 = (nbeg < end); if (!__1) { return _(null, __1); } ; return compare(__cb(_, __frame, 19, 25, function ___(__0, __3) { var __2 = (__3 < 0); return _(null, __2); }, true), array[nbeg], o); })(__cb(_, __frame, -138, 17, _, true)); })(__cb(_, __frame, -138, 17, function ___(__0, __5) { if (__5) {
- nbeg++; while (__more) { __loop(); }; __more = true; } else { __break(); } ; }, true)); }); do { __loop(); } while (__more); __more = true; })(function __$_qsort() { return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$_qsort() { __more = false; return (function __$_qsort(_) { return (function __$_qsort(_) {
-
- var __1 = (beg < nend); if (!__1) { return _(null, __1); } ; return compare(__cb(_, __frame, 22, 25, function ___(__0, __3) { var __2 = (__3 < 0); return _(null, __2); }, true), o, array[nend]); })(__cb(_, __frame, -138, 17, _, true)); })(__cb(_, __frame, -138, 17, function ___(__0, __7) { if (__7) {
- nend--; while (__more) { __loop(); }; __more = true; } else { __break(); } ; }, true)); }); do { __loop(); } while (__more); __more = true; })(function __$_qsort() {
-
- if ((nbeg <= nend)) {
- tmp = array[nbeg];
- array[nbeg] = array[nend];
- array[nend] = tmp;
- nbeg++;
- nend--; } ; while (__more) { __loop(); }; __more = true; }); }); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(function __$_qsort() { return (function __$_qsort(__then) {
-
-
-
- if ((nbeg < end)) {
- return _qsort(__cb(_, __frame, 35, 4, __then, true), nbeg, end); } else { __then(); } ; })(function __$_qsort() { return (function __$_qsort(__then) {
- if ((beg < nend)) {
- return _qsort(__cb(_, __frame, 37, 4, __then, true), beg, nend); } else { __then(); } ; })(_); }); }); }); }); }; var __frame = { name: "exports_sort__8", line: 135 }; return __func(_, this, arguments, exports_sort__8, 0, __frame, function __$exports_sort__8() { beg = (beg || 0); end = ((end == null) ? (array.length - 1) : end);
-
- return _qsort(__cb(_, __frame, 43, 2, function __$exports_sort__8() {
- return _(null, array); }, true), beg, end); }); };
-
-
-
-
-
-
-
-
- exports.eachKey = function exports_eachKey__9(_, obj, fn, thisObj) { var key; var __frame = { name: "exports_eachKey__9", line: 188 }; return __func(_, this, arguments, exports_eachKey__9, 0, __frame, function __$exports_eachKey__9() {
- if (!obj) {
- return _(null, obj); } ;
- var __1 = __forIn(obj); var __2 = 0; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$exports_eachKey__9() { __more = false; var __3 = (__2 < __1.length); if (__3) { key = __1[__2++]; return (function __$exports_eachKey__9(__then) {
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
- return fn.call(thisObj, __cb(_, __frame, 5, 4, __then, true), key, obj[key]); } else { __then(); } ; })(function __$exports_eachKey__9() { while (__more) { __loop(); }; __more = true; }); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(function __$exports_eachKey__9() {
-
- return _(null, obj); }); }); };
-
-
-
-
-
- exports.spray = function(fns, max) {
- return new function() {
-
- var funnel = exports.funnel(max);
- this.collect = function(callback, count, trim) {
- 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));
- if ((count == 0)) {
- return callback(null, results) };
- var collected = 0;
- for (var i = 0; (i < fns.length); i++) {
- (function(i) {
- funnel(function(err, result) {
- if (err) {
- return callback(err) };
- if (trim) {
- results.push(result); } else {
-
- results[i] = result; };
- if ((++collected == count)) {
- return callback(null, results) };
- }, fns[i]);
- })(i); }; };
-
-
- this.collectOne = function(callback) {
- return this.collect(function(err, result) {
- return callback(err, (result && result[0]));
- }, 1, true); };
-
- this.collectAll = function(callback) {
- return this.collect(callback, -1, false); }; }; };
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- exports.funnel = function(max) {
- max = ((typeof max == "undefined") ? -1 : max);
- var queue = [];
- var active = 0;
-
- return function(callback, fn) {
-
- if ((max < 0)) {
- return fn(callback) };
-
- queue.push({
- fn: fn,
- cb: callback });
-
-
- function _doOne() {
- var current = queue.splice(0, 1)[0];
- if (!current.cb) {
- return current.fn() };
- active++;
- current.fn(function(err, result) {
- active--;
- current.cb(err, result);
- while (((active < max) && (queue.length > 0))) { _doOne();; }; }); };
-
-
-
-
- while (((active < max) && (queue.length > 0))) { _doOne();; }; }; };
-
-
-
-
-
-
-
- exports.collect = function exports_collect__10(_, futures) { var __frame = { name: "exports_collect__10", line: 291 }; return __func(_, this, arguments, exports_collect__10, 0, __frame, function __$exports_collect__10() {
- return exports.map(__cb(_, __frame, 1, 9, _, true), futures, function __1(_, future) { var __frame = { name: "__1", line: 292 }; return __func(_, this, arguments, __1, 0, __frame, function __$__1() {
- return future(__cb(_, __frame, 1, 10, _, true)); }); }); }); };
-
-
-
-
- var globals = require("streamline/lib/globals");
- exports.setContext = function(ctx) {
- var old = globals.context;
- globals.context = ctx;
- return old; };
-
- exports.getContext = function() {
- return globals.context; };
-
-
-
-
-
-
-
-
-
-
- exports.nextTick = (((typeof process === "object") && (typeof process.nextTick === "function")) ? process.nextTick : function(callback) {
-
- setTimeout(function() { callback(); }, 0); });
-
-
-
-
-
-
-
- exports.apply = function apply(callback, fn, thisObj, args, index) {
- if ((callback == null)) {
- return __future(apply, arguments, 0) };
- Array.prototype.splice.call(args, ((index != null) ? index : args.length), 0, callback);
- return fn.apply(thisObj, args); };
-
-
-
-})(((typeof exports !== "undefined") ? exports : (window.StreamlineFlows = (window.StreamlineFlows || {}))));
View
211 test/common/flows-test--fibers.js
@@ -1,211 +0,0 @@
-/*** Generated by streamline fibers 0.2.4 - DO NOT EDIT ***/var fstreamline__ = require("streamline/lib/fibers/runtime"); (fstreamline__.create(function(_) {var delay_ = fstreamline__.create(delay), delayFail_ = fstreamline__.create(delayFail); //streamline.options = { "lines" : "preserve" }
-var module = QUnit.module;
-var flows = require("streamline/lib/util/flows");
-
-function delay(_, val) {
- fstreamline__.invoke(flows, "nextTick", [_], 0);
- return val;
-}
-
-function delayFail(_, err) {
- fstreamline__.invoke(flows, "nextTick", [_], 0);
- throw err;
-}
-
-module("flows");
-
-asyncTest("each", 1, fstreamline__.create(function(_) {
- var result = 1;
- fstreamline__.invoke(flows, "each", [_, [1, 2, 3, 4], fstreamline__.create(function(_, val) {
- result = result * delay(_, val);
- }, 0)], 0)
- strictEqual(result, 24);
- start();
-}, 0))
-asyncTest("map", 1, fstreamline__.create(function(_) {
- var result = fstreamline__.invoke(flows, "map", [_, [1, 2, 3, 4], fstreamline__.create(function(_, val) {
- return 2 * delay(_, val);
- }, 0)], 0);
- deepEqual(result, [2, 4, 6, 8]);
- start();
-}, 0))
-asyncTest("filter", 1, fstreamline__.create(function(_) {
- var result = fstreamline__.invoke(flows, "filter", [_, [1, 2, 3, 4], fstreamline__.create(function(_, val) {
- return delay(_, val) % 2;
- }, 0)], 0);
- deepEqual(result, [1, 3]);
- start();
-}, 0))
-asyncTest("every", 1, fstreamline__.create(function(_) {
- var result = fstreamline__.invoke(flows, "every", [_, [1, 2, 3, 4], fstreamline__.create(function(_, val) {
- return delay(_, val) < 5;
- }, 0)], 0);
- strictEqual(result, true);
- start();
-}, 0));
-asyncTest("every", 1, fstreamline__.create(function(_) {
- var result = fstreamline__.invoke(flows, "every", [_, [1, 2, 3, 4], fstreamline__.create(function(_, val) {
- return delay(_, val) < 3;
- }, 0)], 0);
- strictEqual(result, false);
- start();
-}, 0));
-asyncTest("some", 1, fstreamline__.create(function(_) {
- var result = fstreamline__.invoke(flows, "some", [_, [1, 2, 3, 4], fstreamline__.create(function(_, val) {
- return delay(_, val) < 3;
- }, 0)], 0);
- strictEqual(result, true);
- start();
-}, 0));
-asyncTest("some", 1, fstreamline__.create(function(_) {
- var result = fstreamline__.invoke(flows, "some", [_, [1, 2, 3, 4], fstreamline__.create(function(_, val) {
- return delay(_, val) < 0;
- }, 0)], 0);
- strictEqual(result, false);
- start();
-}, 0));
-asyncTest("reduce", 1, fstreamline__.create(function(_) {
- var result = fstreamline__.invoke(flows, "reduce", [_, [1, 2, 3, 4], fstreamline__.create(function(_, v, val) {
- return v * delay(_, val);
- }, 0), 1], 0);
- strictEqual(result, 24);
- start();
-}, 0));
-asyncTest("reduceRight", 1, fstreamline__.create(function(_) {
- var result = fstreamline__.invoke(flows, "reduceRight", [_, [1, 2, 3, 4], fstreamline__.create(function(_, v, val) {
- return v * delay(_, val);
- }, 0), 1], 0);
- strictEqual(result, 24);
- start();
-}, 0));
-asyncTest("sort", 3, fstreamline__.create(function(_) {
- var array = [1, 2, 3, 4];
- fstreamline__.invoke(flows, "sort", [_, array, fstreamline__.create(function(_, a, b) {
- return delay(_, a - b);
- }, 0)], 0);
- deepEqual(array, [1, 2, 3, 4], "In order array sort ok");
- array = [4, 3, 2, 1];
- fstreamline__.invoke(flows, "sort", [_, array, fstreamline__.create(function(_, a, b) {
- return delay(_, a - b);
- }, 0)], 0);
- deepEqual(array, [1, 2, 3, 4], "Reverse array sort ok");
- array = [1, 4, 2, 3];
- fstreamline__.invoke(flows, "sort", [_, array, fstreamline__.create(function(_, a, b) {
- return delay(_, a - b);
- }, 0)], 0);
- deepEqual(array, [1, 2, 3, 4], "Random array sort ok");
- start();
-}, 0));
-asyncTest("collectAll", 4, fstreamline__.create(function(_) {
- var total = 0;
- var peak = 0;
- var count = 0;
-
- function doIt(i) {
- return fstreamline__.create(function(_) {
- count++;
- peak = Math.max(count, peak);
- total = delay(_, i) + total;
- count--;
- return 2 * i;
- }, 0)
- }
-
- var results = fstreamline__.invoke(flows.spray([doIt(1), doIt(2), doIt(3)]), "collectAll", [_], 0);
- equal(total, 6);
- ok(peak >= 2);
- equal(count, 0);
- deepEqual(results, [2, 4, 6]);
- start();
-}, 0))
-asyncTest("collectOne", 4, fstreamline__.create(function(_) {
- var total = 0;
- var peak = 0;
- var count = 0;
-
- function doIt(i) {
- return fstreamline__.create(function(_) {
- count++;
- peak = Math.max(count, peak);
- total = delay(_, i) + total;
- count--;
- return 2 * i;
- }, 0)
- }
-
- var result = fstreamline__.invoke(flows.spray([doIt(1), doIt(2), doIt(3)]), "collectOne", [_], 0);
- ok(total == 1 || total == 2);
- ok(peak >= 2);
- ok(count > 0);
- ok(result == 2 || result == 4);
- start();
-}, 0))
-asyncTest("collectAll with limit", 1, fstreamline__.create(function(_) {
- var total = 0;
- var peak = 0;
- var count = 0;
-
- function doIt(i) {
- return fstreamline__.create(function(_) {
- count++;
- peak = Math.max(count, peak);
- total = delay(_, i) + total;
- count--;
- return 2 * i;
- }, 0)
- }
-
- var results = fstreamline__.invoke(flows.spray([doIt(1), doIt(2), doIt(3)], 2), "collectAll", [_], 0);
- deepEqual([total, peak, count, results], [6, 2, 0, [2, 4, 6]]);
- start();
-}, 0))
-asyncTest("contexts", 3, fstreamline__.create(function(_) {var testContext_ = fstreamline__.create(testContext);
- function testContext(_, x) {
- flows.setContext({
- val: x
- });
- var y = delay(_, 2 * x);
- strictEqual(y, 2 * flows.getContext().val);
- return y + 1;
- }
-
- var result = fstreamline__.invoke(flows.spray([
-
- fstreamline__.create(function(_) {
- return testContext(_, 3);
- }, 0),
-
- fstreamline__.create(function(_) {
- return testContext(_, 5);
- }, 0)
-
- ]), "collectAll", [_], 0);
- deepEqual(result, [7, 11]);
- start();
-}, 0))
-
-asyncTest("futures multiplex", 3, fstreamline__.create(function(_) {var doIt_ = fstreamline__.create(doIt);
- var result1 = 0;
- var result2 = 0;
- var result3 = 0;
-
- function doIt(future, _) {
- result1 = fstreamline__.invoke(null, future, [_], 0) + result1;
- result2 = fstreamline__.invoke(null, future, [_], 0) + result2;
- delay(_);
- result3 = fstreamline__.invoke(null, future, [_], 0) + result3;
- }
-
- var f1 = delay_(null, 1);
- var f10 = delay_(null, 10);
-
- fstreamline__.invoke(flows, "collect", [_, [doIt_(f1), doIt_(f10), doIt_(f1)]], 0);
-
- deepEqual(result1, 12);
- deepEqual(result2, 12);
- deepEqual(result3, 12);
- start();
-}, 0))
-}, 0).call(this, function(err) {
- if (err) throw err;
-}));
View
1 test/common/flows-test_.js → test/common/flows-test._js
@@ -1,4 +1,3 @@
-//streamline.options = { "lines" : "preserve" }
var module = QUnit.module;
var flows = require("streamline/lib/util/flows");
View
207 test/common/flows-test.js
@@ -1,207 +0,0 @@
-/*** Generated by streamline 0.2.5 - DO NOT EDIT ***/ var __rt=require('streamline/lib/callbacks/runtime').runtime(__filename),__func=__rt.__func,__cb=__rt.__cb,__propagate=__rt.__propagate,__trap=__rt.__trap,__future=__rt.__future,__setEF=__rt.__setEF,__g=__rt.__g; var module = QUnit.module;
-
-var flows = require("streamline/lib/util/flows");
-
-function delay(_, val) { var __frame = { name: "delay", line: 5 }; return __func(_, this, arguments, delay, 0, __frame, function __$delay() {
- return flows.nextTick(__cb(_, __frame, 1, 1, function __$delay() {
- return _(null, val); }, true)); });};
-
-
-function delayFail(_, err) { var __frame = { name: "delayFail", line: 10 }; return __func(_, this, arguments, delayFail, 0, __frame, function __$delayFail() {
- return flows.nextTick(__cb(_, __frame, 1, 1, function __$delayFail() {
- return _(err); }, true)); });};
-
-
-module("flows");
-
-asyncTest("each", 1, function __1(_) { var result; var __frame = { name: "__1", line: 17 }; return __func(_, this, arguments, __1, 0, __frame, function __$__1() {
- result = 1;
- return flows.each(__cb(_, __frame, 2, 1, function __$__1() {
-
-
- strictEqual(result, 24);
- start(); _(); }, true), [1,2,3,4,], function __1(_, val) { var __frame = { name: "__1", line: 19 }; return __func(_, this, arguments, __1, 0, __frame, function __$__1() { return delay(__cb(_, __frame, 1, 20, function ___(__0, __1) { result = (result * __1); _(); }, true), val); }); }); });});
-
-asyncTest("map", 1, function __2(_) { var result; var __frame = { name: "__2", line: 25 }; return __func(_, this, arguments, __2, 0, __frame, function __$__2() {
- return flows.map(__cb(_, __frame, 1, 14, function ___(__0, __2) { result = __2;
-
-
- deepEqual(result, [2,4,6,8,]);
- start(); _(); }, true), [1,2,3,4,], function __1(_, val) { var __frame = { name: "__1", line: 26 }; return __func(_, this, arguments, __1, 0, __frame, function __$__1() { return delay(__cb(_, __frame, 1, 13, function ___(__0, __2) { var __1 = (2 * __2); return _(null, __1); }, true), val); }); }); });});
-
-asyncTest("filter", 1, function __3(_) { var result; var __frame = { name: "__3", line: 32 }; return __func(_, this, arguments, __3, 0, __frame, function __$__3() {
- return flows.filter(__cb(_, __frame, 1, 14, function ___(__0, __2) { result = __2;
-
-
- deepEqual(result, [1,3,]);
- start(); _(); }, true), [1,2,3,4,], function __1(_, val) { var __frame = { name: "__1", line: 33 }; return __func(_, this, arguments, __1, 0, __frame, function __$__1() { return delay(__cb(_, __frame, 1, 9, function ___(__0, __2) { var __1 = (__2 % 2); return _(null, __1); }, true), val); }); }); });});
-
-asyncTest("every", 1, function __4(_) { var result; var __frame = { name: "__4", line: 39 }; return __func(_, this, arguments, __4, 0, __frame, function __$__4() {
- return flows.every(__cb(_, __frame, 1, 14, function ___(__0, __2) { result = __2;
-
-
- strictEqual(result, true);
- start(); _(); }, true), [1,2,3,4,], function __1(_, val) { var __frame = { name: "__1", line: 40 }; return __func(_, this, arguments, __1, 0, __frame, function __$__1() { return delay(__cb(_, __frame, 1, 9, function ___(__0, __2) { var __1 = (__2 < 5); return _(null, __1); }, true), val); }); }); });});
-
-asyncTest("every", 1, function __5(_) { var result; var __frame = { name: "__5", line: 46 }; return __func(_, this, arguments, __5, 0, __frame, function __$__5() {
- return flows.every(__cb(_, __frame, 1, 14, function ___(__0, __2) { result = __2;
-
-
- strictEqual(result, false);
- start(); _(); }, true), [1,2,3,4,], function __1(_, val) { var __frame = { name: "__1", line: 47 }; return __func(_, this, arguments, __1, 0, __frame, function __$__1() { return delay(__cb(_, __frame, 1, 9, function ___(__0, __2) { var __1 = (__2 < 3); return _(null, __1); }, true), val); }); }); });});
-
-asyncTest("some", 1, function __6(_) { var result; var __frame = { name: "__6", line: 53 }; return __func(_, this, arguments, __6, 0, __frame, function __$__6() {
- return flows.some(__cb(_, __frame, 1, 14, function ___(__0, __2) { result = __2;
-
-
- strictEqual(result, true);
- start(); _(); }, true), [1,2,3,4,], function __1(_, val) { var __frame = { name: "__1", line: 54 }; return __func(_, this, arguments, __1, 0, __frame, function __$__1() { return delay(__cb(_, __frame, 1, 9, function ___(__0, __2) { var __1 = (__2 < 3); return _(null, __1); }, true), val); }); }); });});
-
-asyncTest("some", 1, function __7(_) { var result; var __frame = { name: "__7", line: 60 }; return __func(_, this, arguments, __7, 0, __frame, function __$__7() {
- return flows.some(__cb(_, __frame, 1, 14, function ___(__0, __2) { result = __2;
-
-
- strictEqual(result, false);
- start(); _(); }, true), [1,2,3,4,], function __1(_, val) { var __frame = { name: "__1", line: 61 }; return __func(_, this, arguments, __1, 0, __frame, function __$__1() { return delay(__cb(_, __frame, 1, 9, function ___(__0, __2) { var __1 = (__2 < 0); return _(null, __1); }, true), val); }); }); });});
-
-asyncTest("reduce", 1, function __8(_) { var result; var __frame = { name: "__8", line: 67 }; return __func(_, this, arguments, __8, 0, __frame, function __$__8() {
- return flows.reduce(__cb(_, __frame, 1, 14, function ___(__0, __2) { result = __2;
-
-
- strictEqual(result, 24);
- start(); _(); }, true), [1,2,3,4,], function __1(_, v, val) { var __frame = { name: "__1", line: 68 }; return __func(_, this, arguments, __1, 0, __frame, function __$__1() { return delay(__cb(_, __frame, 1, 13, function ___(__0, __2) { var __1 = (v * __2); return _(null, __1); }, true), val); }); }, 1); });});
-
-asyncTest("reduceRight", 1, function __9(_) { var result; var __frame = { name: "__9", line: 74 }; return __func(_, this, arguments, __9, 0, __frame, function __$__9() {
- return flows.reduceRight(__cb(_, __frame, 1, 14, function ___(__0, __2) { result = __2;
-
-
- strictEqual(result, 24);
- start(); _(); }, true), [1,2,3,4,], function __1(_, v, val) { var __frame = { name: "__1", line: 75 }; return __func(_, this, arguments, __1, 0, __frame, function __$__1() { return delay(__cb(_, __frame, 1, 13, function ___(__0, __2) { var __1 = (v * __2); return _(null, __1); }, true), val); }); }, 1); });});
-
-asyncTest("sort", 3, function __10(_) { var array; var __frame = { name: "__10", line: 81 }; return __func(_, this, arguments, __10, 0, __frame, function __$__10() {
- array = [1,2,3,4,];
- return flows.sort(__cb(_, __frame, 2, 1, function __$__10() {
-
-
- deepEqual(array, [1,2,3,4,], "In order array sort ok");
- array = [4,3,2,1,];
- return flows.sort(__cb(_, __frame, 7, 1, function __$__10() {
-
-
- deepEqual(array, [1,2,3,4,], "Reverse array sort ok");
- array = [1,4,2,3,];
- return flows.sort(__cb(_, __frame, 12, 1, function __$__10() {
-
-
- deepEqual(array, [1,2,3,4,], "Random array sort ok");
- start(); _(); }, true), array, function __3(_, a, b) { var __frame = { name: "__3", line: 93 }; return __func(_, this, arguments, __3, 0, __frame, function __$__3() { return delay(__cb(_, __frame, 1, 9, _, true), (a - b)); }); }); }, true), array, function __2(_, a, b) { var __frame = { name: "__2", line: 88 }; return __func(_, this, arguments, __2, 0, __frame, function __$__2() { return delay(__cb(_, __frame, 1, 9, _, true), (a - b)); }); }); }, true), array, function __1(_, a, b) { var __frame = { name: "__1", line: 83 }; return __func(_, this, arguments, __1, 0, __frame, function __$__1() { return delay(__cb(_, __frame, 1, 9, _, true), (a - b)); }); }); });});
-
-asyncTest("collectAll", 4, function __11(_) { var total, peak, count, results;
-
-
-
-
- function doIt(i) {
- return function __1(_) { var __frame = { name: "__1", line: 105 }; return __func(_, this, arguments, __1, 0, __frame, function __$__1() {
- count++;
- peak = Math.max(count, peak);
- return delay(__cb(_, __frame, 3, 11, function ___(__0, __1) { total = (__1 + total);
- count--;
- return _(null, (2 * i)); }, true), i); }); }; }; var __frame = { name: "__11", line: 99 }; return __func(_, this, arguments, __11, 0, __frame, function __$__11() { total = 0; peak = 0; count = 0;
-
-
-
- return flows.spray([doIt(1),doIt(2),doIt(3),]).collectAll(__cb(_, __frame, 15, 15, function ___(__0, __1) { results = __1;
- equal(total, 6);
- ok((peak >= 2));
- equal(count, 0);
- deepEqual(results, [2,4,6,]);
- start(); _(); }, true)); });});
-
-asyncTest("collectOne", 4, function __12(_) { var total, peak, count, result;
-
-
-
-
- function doIt(i) {
- return function __1(_) { var __frame = { name: "__1", line: 127 }; return __func(_, this, arguments, __1, 0, __frame, function __$__1() {
- count++;
- peak = Math.max(count, peak);
- return delay(__cb(_, __frame, 3, 11, function ___(__0, __1) { total = (__1 + total);
- count--;
- return _(null, (2 * i)); }, true), i); }); }; }; var __frame = { name: "__12", line: 121 }; return __func(_, this, arguments, __12, 0, __frame, function __$__12() { total = 0; peak = 0; count = 0;
-
-
-
- return flows.spray([doIt(1),doIt(2),doIt(3),]).collectOne(__cb(_, __frame, 15, 14, function ___(__0, __1) { result = __1;
- ok(((total == 1) || (total == 2)));
- ok((peak >= 2));
- ok((count > 0));
- ok(((result == 2) || (result == 4)));
- start(); _(); }, true)); });});
-
-asyncTest("collectAll with limit", 1, function __13(_) { var total, peak, count, results;
-
-
-
-
- function doIt(i) {
- return function __1(_) { var __frame = { name: "__1", line: 149 }; return __func(_, this, arguments, __1, 0, __frame, function __$__1() {
- count++;
- peak = Math.max(count, peak);
- return delay(__cb(_, __frame, 3, 11, function ___(__0, __1) { total = (__1 + total);
- count--;
- return _(null, (2 * i)); }, true), i); }); }; }; var __frame = { name: "__13", line: 143 }; return __func(_, this, arguments, __13, 0, __frame, function __$__13() { total = 0; peak = 0; count = 0;
-
-
-
- return flows.spray([doIt(1),doIt(2),doIt(3),], 2).collectAll(__cb(_, __frame, 15, 15, function ___(__0, __1) { results = __1;
- deepEqual([total,peak,count,results,], [6,2,0,[2,4,6,],]);
- start(); _(); }, true)); });});
-
-asyncTest("contexts", 3, function __14(_) { var result;
- function testContext(_, x) { var y; var __frame = { name: "testContext", line: 163 }; return __func(_, this, arguments, testContext, 0, __frame, function __$testContext() {
- flows.setContext({
- val: x });
-
- return delay(__cb(_, __frame, 4, 10, function ___(__0, __1) { y = __1;
- strictEqual(y, (2 * flows.getContext().val));
- return _(null, (y + 1)); }, true), (2 * x)); }); }; var __frame = { name: "__14", line: 162 }; return __func(_, this, arguments, __14, 0, __frame, function __$__14() {
-
-
-
-
-
-
-
-
-
-
-
-
- return flows.spray([function __1(_) { var __frame = { name: "__1", line: 174 }; return __func(_, this, arguments, __1, 0, __frame, function __$__1() { return testContext(__cb(_, __frame, 1, 9, _, true), 3); }); },function __2(_) { var __frame = { name: "__2", line: 178 }; return __func(_, this, arguments, __2, 0, __frame, function __$__2() { return testContext(__cb(_, __frame, 1, 9, _, true), 5); }); },]).collectAll(__cb(_, __frame, 20, 14, function ___(__0, __3) { result = __3;
- deepEqual(result, [7,11,]);
- start(); _(); }, true)); });});
-
-
-asyncTest("futures multiplex", 3, function __15(_) { var result1, result2, result3, f1, f10;
-
-
-
-
- function doIt(future, _) { var __frame = { name: "doIt", line: 192 }; return __func(_, this, arguments, doIt, 1, __frame, function __$doIt() {
- return future(__cb(_, __frame, 1, 12, function ___(__0, __1) { result1 = (__1 + result1);
- return future(__cb(_, __frame, 2, 12, function ___(__0, __2) { result2 = (__2 + result2);
- return delay(__cb(_, __frame, 3, 2, function __$doIt() {
- return future(__cb(_, __frame, 4, 12, function ___(__0, __3) { result3 = (__3 + result3); _(); }, true)); }, true)); }, true)); }, true)); }); }; var __frame = { name: "__15", line: 187 }; return __func(_, this, arguments, __15, 0, __frame, function __$__15() { result1 = 0; result2 = 0; result3 = 0;
-
-
- f1 = delay(null, 1);
- f10 = delay(null, 10);
-
- return flows.collect(__cb(_, __frame, 15, 1, function __$__15() {
-
- deepEqual(result1, 12);
- deepEqual(result2, 12);
- deepEqual(result3, 12);
- start(); _(); }, true), [doIt(f1),doIt(f10),doIt(f1),]); });});
View
222 test/common/stack-test--fibers.js
@@ -1,222 +0,0 @@
-/*** Generated by streamline fibers 0.2.4 - DO NOT EDIT ***/var fstreamline__ = require("streamline/lib/fibers/runtime"); (fstreamline__.create(function(_) {var failAsync_ = fstreamline__.create(failAsync), failSync_ = fstreamline__.create(failSync), A_ = fstreamline__.create(A), B_ = fstreamline__.create(B), C_ = fstreamline__.create(C), D_ = fstreamline__.create(D), E_ = fstreamline__.create(E), F_ = fstreamline__.create(F), G_ = fstreamline__.create(G), H_ = fstreamline__.create(H), I_ = fstreamline__.create(I), T_ = fstreamline__.create(T); //streamline.options = { "lines" : "preserve" }
-// WARNING: DO NOT INSERT COMMENTS OR ANYTHING
-// Line numbers matter to this test!
-
-var module = QUnit.module;
-var flows = require("streamline/lib/util/flows");
-
-function nextTick(cb){
- setTimeout(function(){
- cb();
- }, 0);
-}
-
-function failAsync(_, code){
- throw new Error(code);
-}
-
-function failSync(_, code){
- (function fail(dummy){ // dummy to defeat CoffeeScript compat rule
- throw new Error(code);
- })(0);
-}
-
-var fail;
-
-function A(_, code){
- if (code == 1)
- fstreamline__.invoke(null, fail, [_, code], 0);
- if (code == 2)
- fstreamline__.invoke(null, fail, [_, code], 0);
- fstreamline__.invoke(null, nextTick, [_], 0);
- if (code == 3)
- fstreamline__.invoke(null, fail, [_, code], 0);
- for (var i = 0; i < 6; i++) {
- if (code == i)
- fstreamline__.invoke(null, fail, [_, code], 0);
- fstreamline__.invoke(null, nextTick, [_], 0);
- }
- if (code == 6)
- fstreamline__.invoke(null, fail, [_, code], 0);
- fstreamline__.invoke(null, nextTick, [_], 0);
- B(_, code);
- fstreamline__.invoke(null, nextTick, [_], 0);
- return "END";
-}
-
-function B(_, code){
- if (code == 7)
- fstreamline__.invoke(null, fail, [_, code], 0);
- C(_, code);
- fstreamline__.invoke(null, nextTick, [_], 0);
- C(_, code);
- D(_, code);
-}
-
-function C(_, code){
- if (code == 8)
- fstreamline__.invoke(null, fail, [_, code], 0);
-}
-
-function D(_, code){
- if (code == 9)
- fstreamline__.invoke(null, fail, [_, code], 0);
-}
-
-function E(_, code){
- try {
- fstreamline__.invoke(null, fail, [_, code], 0);
- }
- catch (ex) {
- if (code % 3 == 1)
- fstreamline__.invoke(null, fail, [_, code], 0);
- else if (code % 3 == 2)
- A(_, code);
- else
- return "OK " + code;
- }
-}
-
-function F(_, code){
- var f1 = A_(null, code);
- var f2 = A_(null, code + 1);
- return fstreamline__.invoke(null, f1, [_], 0) + " & " + fstreamline__.invoke(null, f2, [_], 0);
-}
-
-function G(_, code){
- if (code == 5)
- fstreamline__.invoke(null, fail, [_, code], 0);
- return "" + code;
-}
-
-function H(_, code){
- if (code % 2 == 0)
- fstreamline__.invoke(null, nextTick, [_], 0);
- return G(_, code);
-}
-
-function I(_, code){
- var s = "";
- for (var i = 0; i < code; i++)
- s += H(_, i);
- return s;
-}
-
-function T(_, fn, code, failFn){
- fail = failFn;
- var s = "{"
- try {
- return fstreamline__.invoke(null, fn, [_, code], 0);
- }
- catch (ex) {
- var s = ex.stack;
- //console.log(ex.rawStack);
- //console.log(ex.stack);
- //console.log(s);
- s = s.split('\n').map(function(l){
- var m = /^\s+at (\w+)\s\(.*:(\d+)\:.*\)/.exec(l);
- if (m)
- return m[1] + ":" + m[2];
- return l;
- }).join('/');
- var end = s.indexOf('/T:');
- return end < 0 ? s + "-- end frame missing" : s.substring(0, end);
- }
-}
-
-// safari hack
-var rawStack = new Error().stack ?
-function(raw) {
- return raw;
-} : function() {
- return "raw stack unavailable";
-}
-
-module("stacks");
-
-asyncTest("stacks", 20, fstreamline__.create(function(_) {
- strictEqual(T(_, A_, 1, failAsync_), rawStack("Error: 1/failAsync:15") + "/A:28");
- strictEqual(T(_, A_, 1, failSync_), rawStack("Error: 1/fail:20/failSync:21") + "/A:28");
- strictEqual(T(_, A_, 2, failAsync_), rawStack("Error: 2/failAsync:15") + "/A:30");
- strictEqual(T(_, A_, 2, failSync_), rawStack("Error: 2/fail:20/failSync:21") + "/A:30");
- strictEqual(T(_, A_, 3, failAsync_), rawStack("Error: 3/failAsync:15") + "/A:33");
- strictEqual(T(_, A_, 3, failSync_), rawStack("Error: 3/fail:20/failSync:21") + "/A:33");
- strictEqual(T(_, A_, 4, failAsync_), rawStack("Error: 4/failAsync:15") + "/A:36");
- strictEqual(T(_, A_, 4, failSync_), rawStack("Error: 4/fail:20/failSync:21") + "/A:36");
- strictEqual(T(_, A_, 5, failAsync_), rawStack("Error: 5/failAsync:15") + "/A:36");
- strictEqual(T(_, A_, 5, failSync_), rawStack("Error: 5/fail:20/failSync:21") + "/A:36");
- strictEqual(T(_, A_, 6, failAsync_), rawStack("Error: 6/failAsync:15") + "/A:40");
- strictEqual(T(_, A_, 6, failSync_), rawStack("Error: 6/fail:20/failSync:21") + "/A:40");
- strictEqual(T(_, A_, 7, failAsync_), rawStack("Error: 7/failAsync:15") + "/B:49/A:42");
- strictEqual(T(_, A_, 7, failSync_), rawStack("Error: 7/fail:20/failSync:21") + "/B:49/A:42");
- strictEqual(T(_, A_, 8, failAsync_), rawStack("Error: 8/failAsync:15") + "/C:58/B:50/A:42");
- strictEqual(T(_, A_, 8, failSync_), rawStack("Error: 8/fail:20/failSync:21") + "/C:58/B:50/A:42");
- strictEqual(T(_, A_, 9, failAsync_), rawStack("Error: 9/failAsync:15") + "/D:63/B:53/A:42");
- strictEqual(T(_, A_, 9, failSync_), rawStack("Error: 9/fail:20/failSync:21") + "/D:63/B:53/A:42");
- strictEqual(T(_, A_, 10, failAsync_), "END");
- strictEqual(T(_, A_, 10, failSync_), "END");
- start();
-}, 0))
-
-asyncTest("catch", 20, fstreamline__.create(function(_) {
- strictEqual(T(_, E_, 1, failAsync_), rawStack("Error: 1/failAsync:15") + "/E:72");
- strictEqual(T(_, E_, 1, failSync_), rawStack("Error: 1/fail:20/failSync:21") + "/E:72");
- strictEqual(T(_, E_, 2, failAsync_), rawStack("Error: 2/failAsync:15") + "/A:30/E:74");
- strictEqual(T(_, E_, 2, failSync_), rawStack("Error: 2/fail:20/failSync:21") + "/A:30/E:74");
- strictEqual(T(_, E_, 3, failAsync_), "OK 3");
- strictEqual(T(_, E_, 3, failSync_), "OK 3");
- strictEqual(T(_, E_, 4, failAsync_), rawStack("Error: 4/failAsync:15") + "/E:72");
- strictEqual(T(_, E_, 4, failSync_), rawStack("Error: 4/fail:20/failSync:21") + "/E:72");
- strictEqual(T(_, E_, 5, failAsync_), rawStack("Error: 5/failAsync:15") + "/A:36/E:74");
- strictEqual(T(_, E_, 5, failSync_), rawStack("Error: 5/fail:20/failSync:21") + "/A:36/E:74");
- strictEqual(T(_, E_, 6, failAsync_), "OK 6");
- strictEqual(T(_, E_, 6, failSync_), "OK 6");
- strictEqual(T(_, E_, 7, failAsync_), rawStack("Error: 7/failAsync:15") + "/E:72");
- strictEqual(T(_, E_, 7, failSync_), rawStack("Error: 7/fail:20/failSync:21") + "/E:72");
- strictEqual(T(_, E_, 8, failAsync_), rawStack("Error: 8/failAsync:15") + "/C:58/B:50/A:42/E:74");
- strictEqual(T(_, E_, 8, failSync_), rawStack("Error: 8/fail:20/failSync:21") + "/C:58/B:50/A:42/E:74");
- strictEqual(T(_, E_, 9, failAsync_), "OK 9");
- strictEqual(T(_, E_, 9, failSync_), "OK 9");
- strictEqual(T(_, E_, 10, failAsync_), rawStack("Error: 10/failAsync:15") + "/E:72");
- strictEqual(T(_, E_, 10, failSync_), rawStack("Error: 10/fail:20/failSync:21") + "/E:72");
- start();
-}, 0))
-
-asyncTest("futures", 20, fstreamline__.create(function(_) {
- strictEqual(T(_, F_, 1, failAsync_), rawStack("Error: 1/failAsync:15") + "/A:28/F:83");
- strictEqual(T(_, F_, 1, failSync_), rawStack("Error: 1/fail:20/failSync:21") + "/A:28/F:83");
- strictEqual(T(_, F_, 2, failAsync_), rawStack("Error: 2/failAsync:15") + "/A:30/F:83");
- strictEqual(T(_, F_, 2, failSync_), rawStack("Error: 2/fail:20/failSync:21") + "/A:30/F:83");
- strictEqual(T(_, F_, 3, failAsync_), rawStack("Error: 3/failAsync:15") + "/A:33/F:83");
- strictEqual(T(_, F_, 3, failSync_), rawStack("Error: 3/fail:20/failSync:21") + "/A:33/F:83");
- strictEqual(T(_, F_, 4, failAsync_), rawStack("Error: 4/failAsync:15") + "/A:36/F:83");
- strictEqual(T(_, F_, 4, failSync_), rawStack("Error: 4/fail:20/failSync:21") + "/A:36/F:83");
- strictEqual(T(_, F_, 5, failAsync_), rawStack("Error: 5/failAsync:15") + "/A:36/F:83");
- strictEqual(T(_, F_, 5, failSync_), rawStack("Error: 5/fail:20/failSync:21") + "/A:36/F:83");
- strictEqual(T(_, F_, 6, failAsync_), rawStack("Error: 6/failAsync:15") + "/A:40/F:83");
- strictEqual(T(_, F_, 6, failSync_), rawStack("Error: 6/fail:20/failSync:21") + "/A:40/F:83");
- strictEqual(T(_, F_, 7, failAsync_), rawStack("Error: 7/failAsync:15") + "/B:49/A:42/F:83");
- strictEqual(T(_, F_, 7, failSync_), rawStack("Error: 7/fail:20/failSync:21") + "/B:49/A:42/F:83");
- strictEqual(T(_, F_, 8, failAsync_), rawStack("Error: 8/failAsync:15") + "/C:58/B:50/A:42/F:83");
- strictEqual(T(_, F_, 8, failSync_), rawStack("Error: 8/fail:20/failSync:21") + "/C:58/B:50/A:42/F:83");
- strictEqual(T(_, F_, 9, failAsync_), rawStack("Error: 9/failAsync:15") + "/D:63/B:53/A:42/F:83");
- strictEqual(T(_, F_, 9, failSync_), rawStack("Error: 9/fail:20/failSync:21") + "/D:63/B:53/A:42/F:83");
- strictEqual(T(_, F_, 10, failAsync_), "END & END");
- strictEqual(T(_, F_, 10, failSync_), "END & END");
- start();
-}, 0))
-
-asyncTest("loop", 8, fstreamline__.create(function(_) {
- strictEqual(T(_, I_, 4, failAsync_), "0123");
- strictEqual(T(_, I_, 4, failSync_), "0123");
- strictEqual(T(_, I_, 5, failAsync_), "01234");
- strictEqual(T(_, I_, 5, failSync_), "01234");
- strictEqual(T(_, I_, 6, failAsync_), rawStack("Error: 5/failAsync:15") + "/G:88/H:95/I:101");
- strictEqual(T(_, I_, 6, failSync_), rawStack("Error: 5/fail:20/failSync:21") + "/G:88/H:95/I:101");
- strictEqual(T(_, I_, 7, failAsync_), rawStack("Error: 5/failAsync:15") + "/G:88/H:95/I:101");
- strictEqual(T(_, I_, 7, failSync_), rawStack("Error: 5/fail:20/failSync:21") + "/G:88/H:95/I:101");
- start();
-}, 0))
-}, 0).call(this, function(err) {
- if (err) throw err;
-}));
View
1 test/common/stack-test_.js → test/common/stack-test._js
@@ -1,4 +1,3 @@
-//streamline.options = { "lines" : "preserve" }
// WARNING: DO NOT INSERT COMMENTS OR ANYTHING
// Line numbers matter to this test!
View
218 test/common/stack-test.js
@@ -1,218 +0,0 @@
-/*** Generated by streamline 0.2.5 - DO NOT EDIT ***/ var __rt=require('streamline/lib/callbacks/runtime').runtime(__filename),__func=__rt.__func,__cb=__rt.__cb,__tryCatch=__rt.__tryCatch,__propagate=__rt.__propagate,__trap=__rt.__trap,__future=__rt.__future,__setEF=__rt.__setEF,__g=__rt.__g; var module = QUnit.module;
-
-
-
-
-var flows = require("streamline/lib/util/flows");
-
-function nextTick(cb) {
- setTimeout(function() {
- cb();
- }, 0);};
-
-
-function failAsync(_, code) { var __frame = { name: "failAsync", line: 14 }; return __func(_, this, arguments, failAsync, 0, __frame, function __$failAsync() {
- return _(new Error(code)); });};
-
-
-function failSync(_, code) { var __frame = { name: "failSync", line: 18 }; return __func(_, this, arguments, failSync, 0, __frame, function __$failSync() {
- (function fail(dummy) {
- throw new Error(code);
- })(0); _(); });};
-
-
-var fail;
-
-function A(_, code) { var i; var __frame = { name: "A", line: 26 }; return __func(_, this, arguments, A, 0, __frame, function __$A() { return (function __$A(__then) {
- if ((code == 1)) {
- return fail(__cb(_, __frame, 2, 2, __then, true), code); } else { __then(); } ; })(function __$A() { return (function __$A(__then) {
- if ((code == 2)) {
- return fail(__cb(_, __frame, 4, 2, __then, true), code); } else { __then(); } ; })(function __$A() {
- return nextTick(__cb(_, __frame, 5, 1, function __$A() { return (function __$A(__then) {
- if ((code == 3)) {
- return fail(__cb(_, __frame, 7, 2, __then, true), code); } else { __then(); } ; })(function __$A() {
- i = 0; var __6 = false; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$A() { __more = false; if (__6) { i++; } else { __6 = true; } ; var __5 = (i < 6); if (__5) { return (function __$A(__then) {
- if ((code == i)) {
- return fail(__cb(_, __frame, 10, 3, __then, true), code); } else { __then(); } ; })(function __$A() {
- return nextTick(__cb(_, __frame, 11, 2, function __$A() { while (__more) { __loop(); }; __more = true; }, true)); }); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(function __$A() { return (function __$A(__then) {
-
- if ((code == 6)) {
- return fail(__cb(_, __frame, 14, 2, __then, true), code); } else { __then(); } ; })(function __$A() {
- return nextTick(__cb(_, __frame, 15, 1, function __$A() {
- return B(__cb(_, __frame, 16, 1, function __$A() {
- return nextTick(__cb(_, __frame, 17, 1, function __$A() {
- return _(null, "END"); }, true)); }, true), code); }, true)); }); }); }); }, true)); }); }); });};
-
-
-function B(_, code) { var __frame = { name: "B", line: 47 }; return __func(_, this, arguments, B, 0, __frame, function __$B() { return (function __$B(__then) {
- if ((code == 7)) {
- return fail(__cb(_, __frame, 2, 2, __then, true), code); } else { __then(); } ; })(function __$B() {
- return C(__cb(_, __frame, 3, 1, function __$B() {
- return nextTick(__cb(_, __frame, 4, 1, function __$B() {
- return C(__cb(_, __frame, 5, 1, function __$B() {
- return D(__cb(_, __frame, 6, 1, _, true), code); }, true), code); }, true)); }, true), code); }); });};
-
-
-function C(_, code) { var __frame = { name: "C", line: 56 }; return __func(_, this, arguments, C, 0, __frame, function __$C() { return (function __$C(__then) {
- if ((code == 8)) {
- return fail(__cb(_, __frame, 2, 2, __then, true), code); } else { __then(); } ; })(_); });};
-
-
-function D(_, code) { var __frame = { name: "D", line: 61 }; return __func(_, this, arguments, D, 0, __frame, function __$D() { return (function __$D(__then) {
- if ((code == 9)) {
- return fail(__cb(_, __frame, 2, 2, __then, true), code); } else { __then(); } ; })(_); });};
-
-
-function E(_, code) { var __frame = { name: "E", line: 66 }; return __func(_, this, arguments, E, 0, __frame, function __$E() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$E() {
-
- return fail(__cb(_, __frame, 2, 2, __then, true), code); }); })(function ___(ex, __result) { __tryCatch(_, function __$E() { if (ex) { return (function __$E(__then) {
-
-
- if (((code % 3) == 1)) {
- return fail(__cb(_, __frame, 6, 3, __then, true), code); } else { return (function __$E(__then) {
- if (((code % 3) == 2)) {
- return A(__cb(_, __frame, 8, 3, __then, true), code); } else {
-
- return _(null, ("OK " + code)); } ; })(__then); } ; })(__then); } else { _(null, __result); } ; }); }); })(function ___() { __tryCatch(_, _); }); });};
-
-
-
-function F(_, code) { var f1, f2; var __frame = { name: "F", line: 80 }; return __func(_, this, arguments, F, 0, __frame, function __$F() {
- f1 = A(null, code);
- f2 = A(null, (code + 1));
- return f1(__cb(_, __frame, 3, 8, function ___(__0, __2) { return f2(__cb(_, __frame, 3, 24, function ___(__0, __3) { var __1 = ((__2 + " & ") + __3); return _(null, __1); }, true)); }, true)); });};
-
-
-function G(_, code) { var __frame = { name: "G", line: 86 }; return __func(_, this, arguments, G, 0, __frame, function __$G() { return (function __$G(__then) {
- if ((code == 5)) {
- return fail(__cb(_, __frame, 2, 2, __then, true), code); } else { __then(); } ; })(function __$G() {
- return _(null, ("" + code)); }); });};
-
-
-function H(_, code) { var __frame = { name: "H", line: 92 }; return __func(_, this, arguments, H, 0, __frame, function __$H() { return (function __$H(__then) {
- if (((code % 2) == 0)) {
- return nextTick(__cb(_, __frame, 2, 2, __then, true)); } else { __then(); } ; })(function __$H() {
- return G(__cb(_, __frame, 3, 8, _, true), code); }); });};
-
-
-function I(_, code) { var s, i; var __frame = { name: "I", line: 98 }; return __func(_, this, arguments, I, 0, __frame, function __$I() {
- s = "";
- i = 0; var __3 = false; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$I() { __more = false; if (__3) { i++; } else { __3 = true; } ; var __2 = (i < code); if (__2) {
- return H(__cb(_, __frame, 3, 7, function ___(__0, __1) { s += __1; while (__more) { __loop(); }; __more = true; }, true), i); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(function __$I() {
- return _(null, s); }); });};
-
-
-function T(_, fn, code, failFn) { var s, end; var __frame = { name: "T", line: 105 }; return __func(_, this, arguments, T, 0, __frame, function __$T() {
- fail = failFn;
- s = "{"; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$T() {
-
- return fn(__cb(_, __frame, 4, 9, _, true), code); }); })(function ___(ex, __result) { __tryCatch(_, function __$T() { if (ex) {
-
-
- s = ex.stack;
-
-
-
- s = s.split("\n").map(function(l) {
- var m = /^\s+at (\w+)\s\(.*:(\d+)\:.*\)/.exec(l);
- if (m) {
- return ((m[1] + ":") + m[2]) };
- return l;
- }).join("/");
- end = s.indexOf("/T:");
- return _(null, ((end < 0) ? (s + "-- end frame missing") : s.substring(0, end))); } else { _(null, __result); } ; }); }); })(function ___() { __tryCatch(_, _); }); });};
-
-
-
-
-var rawStack = (new Error().stack ? function(raw) {
-
- return raw;
-} : function() {
- return "raw stack unavailable";});
-
-
-module("stacks");
-
-asyncTest("stacks", 20, function __1(_) { var __frame = { name: "__1", line: 137 }; return __func(_, this, arguments, __1, 0, __frame, function __$__1() {
- return T(__cb(_, __frame, 1, 13, function ___(__0, __1) { strictEqual(__1, (rawStack("Error: 1/failAsync:15") + "/A:28"));
- return T(__cb(_, __frame, 2, 13, function ___(__0, __2) { strictEqual(__2, (rawStack("Error: 1/fail:20/failSync:21") + "/A:28"));
- return T(__cb(_, __frame, 3, 13, function ___(__0, __3) { strictEqual(__3, (rawStack("Error: 2/failAsync:15") + "/A:30"));
- return T(__cb(_, __frame, 4, 13, function ___(__0, __4) { strictEqual(__4, (rawStack("Error: 2/fail:20/failSync:21") + "/A:30"));
- return T(__cb(_, __frame, 5, 13, function ___(__0, __5) { strictEqual(__5, (rawStack("Error: 3/failAsync:15") + "/A:33"));
- return T(__cb(_, __frame, 6, 13, function ___(__0, __6) { strictEqual(__6, (rawStack("Error: 3/fail:20/failSync:21") + "/A:33"));
- return T(__cb(_, __frame, 7, 13, function ___(__0, __7) { strictEqual(__7, (rawStack("Error: 4/failAsync:15") + "/A:36"));
- return T(__cb(_, __frame, 8, 13, function ___(__0, __8) { strictEqual(__8, (rawStack("Error: 4/fail:20/failSync:21") + "/A:36"));
- return T(__cb(_, __frame, 9, 13, function ___(__0, __9) { strictEqual(__9, (rawStack("Error: 5/failAsync:15") + "/A:36"));
- return T(__cb(_, __frame, 10, 13, function ___(__0, __10) { strictEqual(__10, (rawStack("Error: 5/fail:20/failSync:21") + "/A:36"));
- return T(__cb(_, __frame, 11, 13, function ___(__0, __11) { strictEqual(__11, (rawStack("Error: 6/failAsync:15") + "/A:40"));
- return T(__cb(_, __frame, 12, 13, function ___(__0, __12) { strictEqual(__12, (rawStack("Error: 6/fail:20/failSync:21") + "/A:40"));
- return T(__cb(_, __frame, 13, 13, function ___(__0, __13) { strictEqual(__13, (rawStack("Error: 7/failAsync:15") + "/B:49/A:42"));
- return T(__cb(_, __frame, 14, 13, function ___(__0, __14) { strictEqual(__14, (rawStack("Error: 7/fail:20/failSync:21") + "/B:49/A:42"));
- return T(__cb(_, __frame, 15, 13, function ___(__0, __15) { strictEqual(__15, (rawStack("Error: 8/failAsync:15") + "/C:58/B:50/A:42"));
- return T(__cb(_, __frame, 16, 13, function ___(__0, __16) { strictEqual(__16, (rawStack("Error: 8/fail:20/failSync:21") + "/C:58/B:50/A:42"));
- return T(__cb(_, __frame, 17, 13, function ___(__0, __17) { strictEqual(__17, (rawStack("Error: 9/failAsync:15") + "/D:63/B:53/A:42"));
- return T(__cb(_, __frame, 18, 13, function ___(__0, __18) { strictEqual(__18, (rawStack("Error: 9/fail:20/failSync:21") + "/D:63/B:53/A:42"));
- return T(__cb(_, __frame, 19, 13, function ___(__0, __19) { strictEqual(__19, "END");
- return T(__cb(_, __frame, 20, 13, function ___(__0, __20) { strictEqual(__20, "END");
- start(); _(); }, true), A, 10, failSync); }, true), A, 10, failAsync); }, true), A, 9, failSync); }, true), A, 9, failAsync); }, true), A, 8, failSync); }, true), A, 8, failAsync); }, true), A, 7, failSync); }, true), A, 7, failAsync); }, true), A, 6, failSync); }, true), A, 6, failAsync); }, true), A, 5, failSync); }, true), A, 5, failAsync); }, true), A, 4, failSync); }, true), A, 4, failAsync); }, true), A, 3, failSync); }, true), A, 3, failAsync); }, true), A, 2, failSync); }, true), A, 2, failAsync); }, true), A, 1, failSync); }, true), A, 1, failAsync); });});