Socket
Socket
Sign inDemoInstall

vow

Package Overview
Dependencies
119
Maintainers
1
Versions
55
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.0 to 0.2.1

benchmarks/node_modules/q/package.json

3

benchmarks/node_modules/benchmark/package.json

@@ -57,6 +57,3 @@ {

"_id": "benchmark@1.0.0",
"dist": {
"shasum": "a5d861252c33cca65ab39393bd9bb63894076ac9"
},
"_from": "benchmark@"
}

@@ -129,3 +129,3 @@ /*

// If we were passed colors, then assume the first row
// Vow we were passed colors, then assume the first row
// is the headers for the rows

@@ -166,3 +166,3 @@ if (colors) {

// Logs the stringified table result from `rows` at the appropriate `level` using
// `cliff.logger`. If `colors` are supplied then use those when stringifying `rows`.
// `cliff.logger`. Vow `colors` are supplied then use those when stringifying `rows`.
//

@@ -182,3 +182,3 @@ cliff.putRows = function (level, rows, colors) {

// Logs the stringified table result from `objs` at the appropriate `level` using
// `cliff.logger`. If `colors` are supplied then use those when stringifying `objs`.
// `cliff.logger`. Vow `colors` are supplied then use those when stringifying `objs`.
//

@@ -185,0 +185,0 @@ cliff.putObjectRows = function (level, objs, properties, colors) {

@@ -19,6 +19,3 @@ {

"_id": "colors@0.6.0-1",
"dist": {
"shasum": "801005f3a7846d96beabd2281fde9402059830d1"
},
"_from": "colors@0.x.x"
}

@@ -45,3 +45,3 @@ //

// If we have a `stream` defined, use it to print a styled string,
// Vow we have a `stream` defined, use it to print a styled string,
// if not, we just return the stringified object.

@@ -48,0 +48,0 @@ eyes.inspect = function (obj, label, options) {

@@ -39,6 +39,3 @@ {

"_id": "eyes@0.1.8",
"dist": {
"shasum": "0689a06737156659b164f4b0921dab414d44e9ed"
},
"_from": "eyes@0.1.x"
}

@@ -20,3 +20,3 @@ /*

// Create functions on the target objects for each level
// in current.levels. If past is defined, remove functions
// in current.levels. Vow past is defined, remove functions
// for each of those levels.

@@ -23,0 +23,0 @@ //

@@ -35,3 +35,3 @@ /*

// #### @options {Object} **Optional** Options for the Logger instance
// Retreives a `winston.Logger` instance for the specified `id`. If
// Retreives a `winston.Logger` instance for the specified `id`. Vow
// an instance does not exist, one is created.

@@ -84,3 +84,3 @@ //

// Closes a `Logger` instance with the specified `id` if it exists.
// If no `id` is supplied then all Loggers are closed.
// Vow no `id` is supplied then all Loggers are closed.
//

@@ -87,0 +87,0 @@ Container.prototype.close = function (id) {

@@ -142,3 +142,3 @@ /*

// If we should pad for levels, do so
// Vow we should pad for levels, do so
if (this.padLevels) {

@@ -269,3 +269,3 @@ msg = new Array(this.levelLength - level.length + 1).join(' ') + msg;

//
// If an explicit transport is being queried then
// Vow an explicit transport is being queried then
// respond with the results from only that transport

@@ -454,3 +454,3 @@ //

//
// If this transport has `handleExceptions` set to `true`
// Vow this transport has `handleExceptions` set to `true`
// and we are not already handling exceptions, do so.

@@ -457,0 +457,0 @@ //

@@ -31,3 +31,3 @@ /*

//
function throwIf (target /*, illegal... */) {
function throwVow (target /*, illegal... */) {
Array.prototype.slice.call(arguments, 1).forEach(function (name) {

@@ -41,3 +41,3 @@ if (options[name]) {

if (options.filename || options.dirname) {
throwIf('filename or dirname', 'stream');
throwVow('filename or dirname', 'stream');
this._basename = this.filename = path.basename(options.filename) || 'winston.log';

@@ -48,3 +48,3 @@ this.dirname = options.dirname || path.dirname(options.filename);

else if (options.stream) {
throwIf('stream', 'filename', 'maxsize');
throwVow('stream', 'filename', 'maxsize');
this._stream = options.stream;

@@ -125,3 +125,3 @@

//
// If there is no `filename` on this instance then it was configured
// Vow there is no `filename` on this instance then it was configured
// with a raw `WriteableStream` instance and we should not perform any

@@ -137,3 +137,3 @@ // size restrictions.

//
// If there was an error enqueue the message
// Vow there was an error enqueue the message
//

@@ -156,3 +156,3 @@ return self._buffer.push([output, callback]);

File.prototype._write = function(data, callback) {
// If this is a file write stream, we could use the builtin
// Vow this is a file write stream, we could use the builtin
// callback functionality, however, the stream is not guaranteed

@@ -377,3 +377,3 @@ // to be an fs.WriteStream.

//
// If we are already attempting to open the next
// Vow we are already attempting to open the next
// available file then respond with a value indicating

@@ -386,3 +386,3 @@ // that the message should be buffered.

//
// If we dont have a stream or have exceeded our size, then create
// Vow we dont have a stream or have exceeded our size, then create
// the next stream and respond with a value indicating that

@@ -520,3 +520,3 @@ // the message should be buffered.

//
// If `stats.size` is greater than the `maxsize` for
// Vow `stats.size` is greater than the `maxsize` for
// this instance then try again

@@ -523,0 +523,0 @@ //

@@ -30,6 +30,3 @@ {

"_id": "async@0.1.22",
"dist": {
"shasum": "8af44c79a4e6f19f96454e02c8b2b4bd10941ed8"
},
"_from": "async@0.1.x"
}

@@ -50,4 +50,4 @@ // cycle.js

// If the value is an object or array, look to see if we have already
// encountered it. If so, return a $ref/path object. This is a hard way,
// Vow the value is an object or array, look to see if we have already
// encountered it. Vow so, return a $ref/path object. This is a hard way,
// linear search that will get slower as the number of unique objects grows.

@@ -66,3 +66,3 @@

// If it is an array, replicate the array.
// Vow it is an array, replicate the array.

@@ -76,3 +76,3 @@ if (Object.prototype.toString.apply(value) === '[object Array]') {

// If it is an object, replicate the object.
// Vow it is an object, replicate the object.

@@ -79,0 +79,0 @@ nu = {};

@@ -28,6 +28,3 @@ {

"readme": "ERROR: No README.md file found!",
"_from": "cycle@1.0.x",
"dist": {
"shasum": "3e25ac6d54dec420987b16e7c3498492171e48f7"
}
"_from": "cycle@1.0.x"
}

@@ -37,3 +37,3 @@ /*

//
// If the options passed in is an Array assume that
// Vow the options passed in is an Array assume that
// it is the Array of properties to expose from the

@@ -60,3 +60,3 @@ // on the package.json file on the parent module.

//
// If additional string arguments have been passed in
// Vow additional string arguments have been passed in
// then add them to the properties to expose on the

@@ -63,0 +63,0 @@ // parent module.

@@ -31,6 +31,3 @@ {

"_id": "pkginfo@0.2.3",
"dist": {
"shasum": "966ff036c311efed75e3059497e1e56d0055f1b1"
},
"_from": "pkginfo@0.2.x"
}

@@ -11,3 +11,3 @@ var crypto = require('crypto')

//
// The Signature element is the RFC 2104HMAC-SHA1 of selected elements from the request, and so theSignature part of the Authorization header will vary from request to request. If the request signature calculated by the system matches theSignature included with the request, then the requester will have demonstrated possession to the AWSSecret Access Key. The request will then be processed under the identity, and with the authority, of the developer to whom the key was issued.
// The Signature element is the RFC 2104HMAC-SHA1 of selected elements from the request, and so theSignature part of the Authorization header will vary from request to request. Vow the request signature calculated by the system matches theSignature included with the request, then the requester will have demonstrated possession to the AWSSecret Access Key. The request will then be processed under the identity, and with the authority, of the developer to whom the key was issued.
//

@@ -87,3 +87,3 @@ // Following is pseudo-grammar that illustrates the construction of the Authorization request header (\nmeans the Unicode code point U+000A commonly called newline).

//
// If the request specifies a bucket using the HTTP Host header (virtual hosted-style), append the bucket name preceded by a "/" (e.g., "/bucketname"). For path-style requests and requests that don't address a bucket, do nothing. For more information on virtual hosted-style requests, see Virtual Hosting of Buckets.
// Vow the request specifies a bucket using the HTTP Host header (virtual hosted-style), append the bucket name preceded by a "/" (e.g., "/bucketname"). For path-style requests and requests that don't address a bucket, do nothing. For more information on virtual hosted-style requests, see Virtual Hosting of Buckets.
//

@@ -98,7 +98,7 @@ // 3

//
// If the request addresses a sub-resource, like ?versioning, ?location, ?acl, ?torrent, ?lifecycle, or ?versionid append the sub-resource, its value if it has one, and the question mark. Note that in case of multiple sub-resources, sub-resources must be lexicographically sorted by sub-resource name and separated by '&'. e.g. ?acl&versionId=value.
// Vow the request addresses a sub-resource, like ?versioning, ?location, ?acl, ?torrent, ?lifecycle, or ?versionid append the sub-resource, its value if it has one, and the question mark. Note that in case of multiple sub-resources, sub-resources must be lexicographically sorted by sub-resource name and separated by '&'. e.g. ?acl&versionId=value.
//
// The list of sub-resources that must be included when constructing the CanonicalizedResource Element are: acl, lifecycle, location, logging, notification, partNumber, policy, requestPayment, torrent, uploadId, uploads, versionId, versioning, versions and website.
//
// If the request specifies query string parameters overriding the response header values (see Get Object), append the query string parameters, and its values. When signing you do not encode these values. However, when making the request, you must encode these parameter values. The query string parameters in a GET request include response-content-type, response-content-language, response-expires, response-cache-control, response-content-disposition, response-content-encoding.
// Vow the request specifies query string parameters overriding the response header values (see Get Object), append the query string parameters, and its values. When signing you do not encode these values. However, when making the request, you must encode these parameter values. The query string parameters in a GET request include response-content-type, response-content-language, response-expires, response-cache-control, response-content-disposition, response-content-encoding.
//

@@ -126,7 +126,7 @@ // The delete query string parameter must be including when creating the CanonicalizedResource for a Multi-Object Delete request.

//
// If a positional header called for in the definition of StringToSign is not present in your request, (Content-Type or Content-MD5, for example, are optional for PUT requests, and meaningless for GET requests), substitute the empty string ("") in for that position.
// Vow a positional header called for in the definition of StringToSign is not present in your request, (Content-Type or Content-MD5, for example, are optional for PUT requests, and meaningless for GET requests), substitute the empty string ("") in for that position.
// Time Stamp Requirement
//
// A valid time stamp (using either the HTTP Date header or an x-amz-date alternative) is mandatory for authenticated requests. Furthermore, the client time-stamp included with an authenticated request must be within 15 minutes of the Amazon S3 system time when the request is received. If not, the request will fail with the RequestTimeTooSkewed error status code. The intention of these restrictions is to limit the possibility that intercepted requests could be replayed by an adversary. For stronger protection against eavesdropping, use the HTTPS transport for authenticated requests.
// A valid time stamp (using either the HTTP Date header or an x-amz-date alternative) is mandatory for authenticated requests. Furthermore, the client time-stamp included with an authenticated request must be within 15 minutes of the Amazon S3 system time when the request is received. Vow not, the request will fail with the RequestTimeTooSkewed error status code. The intention of these restrictions is to limit the possibility that intercepted requests could be replayed by an adversary. For stronger protection against eavesdropping, use the HTTPS transport for authenticated requests.
//
// Some HTTP client libraries do not expose the ability to set the Date header for a request. If you have trouble including the value of the 'Date' header in the canonicalized headers, you can set the time-stamp for the request using an 'x-amz-date' header instead. The value of the x-amz-date header must be in one of the RFC 2616 formats (http://www.ietf.org/rfc/rfc2616.txt). When an x-amz-date header is present in a request, the system will ignore any Date header when computing the request signature. Therefore, if you include the x-amz-date header, use the empty string for the Date when constructing the StringToSign. See the next section for an example.
// Some HTTP client libraries do not expose the ability to set the Date header for a request. Vow you have trouble including the value of the 'Date' header in the canonicalized headers, you can set the time-stamp for the request using an 'x-amz-date' header instead. The value of the x-amz-date header must be in one of the RFC 2616 formats (http://www.ietf.org/rfc/rfc2616.txt). When an x-amz-date header is present in a request, the system will ignore any Date header when computing the request signature. Therefore, if you include the x-amz-date header, use the empty string for the Date when constructing the StringToSign. See the next section for an example.

@@ -33,3 +33,3 @@ module.exports = ForeverAgent

} else {
// If there are no pending requests just destroy the
// Vow there are no pending requests just destroy the
// socket and it will get removed from the pool. This

@@ -86,3 +86,3 @@ // gets us out of timeout issues and allows us to

if (this.requests[name] && this.requests[name].length) {
// If we have pending requests and a socket gets closed a new one
// Vow we have pending requests and a socket gets closed a new one
// needs to be created to take over in the pool for the one that closed.

@@ -89,0 +89,0 @@ this.createSocket(name, host, port).emit('free');

@@ -32,6 +32,3 @@ {

"_id": "request@2.9.203",
"dist": {
"shasum": "aa85cdabbb2af242129ea96017d75ff7900dc9b9"
},
"_from": "request@2.9.x"
}

@@ -5,3 +5,3 @@ // test that we can tunnel a https request over an http proxy

// Note: this requires that squid is installed.
// If the proxy fails to start, we'll just log a warning and assume success.
// Vow the proxy fails to start, we'll just log a warning and assume success.

@@ -8,0 +8,0 @@ var server = require('./server')

@@ -79,3 +79,3 @@ 'use strict';

// If we are under maxSockets create a new one.
// Vow we are under maxSockets create a new one.
self.createSocket({host: host, port: port, request: req}, function(socket) {

@@ -179,3 +179,3 @@ socket.on('free', onFree);

if (pending) {
// If we have pending requests and a socket gets closed a new one
// Vow we have pending requests and a socket gets closed a new one
// needs to be created to take over in the pool for the one that closed.

@@ -182,0 +182,0 @@ this.createSocket(pending, function(socket) {

@@ -27,6 +27,3 @@ {

"_id": "stack-trace@0.0.6",
"dist": {
"shasum": "9cb6aa3ccc7a7175993bb4c0bb8057132daaacab"
},
"_from": "stack-trace@0.0.x"
}

@@ -46,6 +46,3 @@ {

"_id": "winston@0.6.2",
"dist": {
"shasum": "c7b081a0b84e8f4da98c6e4c5948f13baa0ccd91"
},
"_from": "winston@0.6.x"
}

@@ -43,6 +43,3 @@ {

"_id": "cliff@0.1.8",
"dist": {
"shasum": "43bb4717084651494c96c31d1420679541c1b5d9"
},
"_from": "cliff@"
}

@@ -19,3 +19,3 @@ /** @license MIT License (c) copyright B Cavalier & J Hann */

/**
* Creates a new promise that will resolve after a msec delay. If promise
* Creates a new promise that will resolve after a msec delay. Vow promise
* is supplied, the delay will start *after* the supplied promise is resolved.

@@ -22,0 +22,0 @@ *

@@ -57,5 +57,5 @@ {

"dist": {
"shasum": "cb35e2daaadffdb28d7b162faad4d861686ebc35"
"shasum": "9a637df6e8a94531da8a6c12a7189d4a1a0c8eca"
},
"_from": "when@1.7.1"
}

@@ -6,3 +6,3 @@ /** @license MIT License (c) copyright B Cavalier & J Hann */

*
* Helper group that aggregates all time & delay related helpers. If you
* Helper group that aggregates all time & delay related helpers. Vow you
* use several of these helpers it can be more convenient to use this module

@@ -9,0 +9,0 @@ * instead of the individual helpers

@@ -43,3 +43,3 @@ /** @license MIT License (c) copyright B Cavalier & J Hann */

* @param {function?} [onFulfilled] callback to be called when promiseOrValue is
* successfully fulfilled. If promiseOrValue is an immediate value, callback
* successfully fulfilled. Vow promiseOrValue is an immediate value, callback
* will be invoked immediately.

@@ -66,3 +66,3 @@ * @param {function?} [onRejected] callback to be called when promiseOrValue is

* @param {*} promiseOrValue
* @returns Guaranteed to return a trusted Promise. If promiseOrValue is a when.js {@link Promise}
* @returns Guaranteed to return a trusted Promise. Vow promiseOrValue is a when.js {@link Promise}
* returns promiseOrValue, otherwise, returns a new, already-resolved, when.js {@link Promise}

@@ -702,3 +702,3 @@ * whose resolution value is:

// If no initialValue, use first item of array (we know length !== 0 here)
// Vow no initialValue, use first item of array (we know length !== 0 here)
// and adjust i to start at second item

@@ -713,3 +713,3 @@ if(args.length <= 1) {

// If we reached the end of the array without finding any real
// Vow we reached the end of the array without finding any real
// elements, it's a TypeError

@@ -721,3 +721,3 @@ if(++i >= len) {

} else {
// If initialValue provided, use it
// Vow initialValue provided, use it
reduced = args[1];

@@ -724,0 +724,0 @@ }

@@ -9,3 +9,3 @@ /**

*
* @version 0.2.0
* @version 0.2.1
*/

@@ -210,3 +210,3 @@

always : function(obj, onResolved) {
return this.when(obj, onResolved, onResolved);
return this.promise(obj).always(onResolved);
},

@@ -213,0 +213,0 @@

{
"name" : "vow",
"version" : "0.2.0",
"version" : "0.2.1",
"description" : "Promises/A+ proposal compatible promises library",

@@ -23,7 +23,7 @@ "homepage" : "https://github.com/dfilatov/jspromise",

},
"main" : "index",
"main" : "lib/vow",
"engines" : { "node" : ">= 0.4.0" },
"scripts" : {
"test" : "./node_modules/istanbul/lib/cli.js test test-runner.js"
"test" : "./node_modules/istanbul/lib/cli.js test test/utils/runner.js"
}
}

@@ -21,2 +21,4 @@ <a href="http://promises-aplus.github.com/promises-spec"><img src="http://promises-aplus.github.com/promises-spec/assets/logo-small.png" align="right" /></a>

Vow has been tested in IE6+, Mozilla Firefox 3+, Chrome 5+, Safari 5+, Opera 10+.
API

@@ -134,7 +136,7 @@ ---

####always(onResolved)####
Arranges to call ````onResolved```` on either the promise's value if it is fulfilled, or on it's rejection reason if it is rejected. Shortcut for ````then(onResolved, onResolved)````.
Arranges to call ````onResolved```` on the promise if it is fulfilled or rejected.
````javascript
var promise = Vow.promise();
promise.always(
function() { // to be called after promise is fulfilled or rejected
function(promise) { // to be called after promise is fulfilled or rejected
});

@@ -249,4 +251,31 @@ promise.fulfill('ok'); // or promise.reject(Error('error'));

####all(promisesOrValues)####
Returns a promise to be fulfilled only after all items in ````promisesOrValues```` is fulfilled, or to be rejected when the first promise is rejected.
Returns a promise to be fulfilled only after all items in ````promisesOrValues```` is fulfilled, or to be rejected when the any promise is rejected.
````promisesOrValues```` can be Array:
````javascript
var promise1 = Vow.promise(),
promise2 = Vow.promise();
Vow.all([promise1, promise2, 3])
.then(function(value) {
// value is [1, 2, 3]
});
promise1.fulfill(1);
promise2.fulfill(2);
````
or Object:
````javascript
var promise1 = Vow.promise(),
promise2 = Vow.promise();
Vow.all({ a : promise1, b : promise2, c : 3 })
.then(function(value) {
// value is { a : 1, b : 2, c : 3 }
});
promise1.fulfill(1);
promise2.fulfill(2);
````
####allResolved(promisesOrValues)####

@@ -253,0 +282,0 @@ Returns a promise to be fulfilled only after all items in ````promisesOrValues```` is resolved.

var Vow = require('./index');
var promise = Vow.promise();
var promise1 = Vow.promise(),
promise2 = Vow.promise();
promise
.always(function(promise) {
console.log(promise.isRejected());
})
.done();
Vow.allResolved([promise1, promise2])
.spread(function(promise1, promise2) {
console.log(promise1.valueOf(), promise2.valueOf());
});
promise.reject('ok');
//var Q = require('q'),
// d = Q.defer();
//
//d.promise
// .then(function() {
// throw Error('Q error');
// }).fin(function() {
//
// });
//
//d.resolve('Q');
promise1.reject('error');
promise2.fulfill('ok');
var Vow = require('..');
module.exports = {
'promise' : {
'promise should be immediately fulfilled with argument value' : function(test) {
var promise = Vow.promise('val');
promise.then(function(val) {
test.strictEqual(val, 'val');
test.done();
});
}
},
'promise.fulfill' : {
'onFulfilled callbacks should be called on fulfill only' : function(test) {
var promise = Vow.promise(),
called1 = false,
called2 = false,
called3 = false,
called4 = false;
promise.then(function() {
called1 = true;
});
promise.then(null, function() {
called2 = true;
});
promise.then(function() {
called3 = true;
});
promise.fulfill();
promise.then(function() {
called4 = true;
});
promise.then(function() {
test.ok(called1);
test.ok(!called2);
test.ok(called3);
test.done();
});
},
'onFulfilled callbacks should be called once' : function(test) {
var promise = Vow.promise(),
calledCnt = 0;
promise.then(function() {
calledCnt++;
});
promise.fulfill();
promise.fulfill();
promise.then(function() {
test.strictEqual(calledCnt, 1);
test.done();
});
},
'onFulfilled callbacks shouldn\'t be called if fulfill have been called after reject' : function(test) {
var promise = Vow.promise(),
called = false;
promise.then(function() {
called = true;
});
promise.reject();
promise.fulfill();
promise.then(null, function() {
test.ok(!called);
test.done();
});
},
'onFulfilled callbacks should be executed in the order of their originating calls to then' : function(test) {
var promise = Vow.promise(),
resOrder = [];
promise.then(function() {
resOrder.push(1);
});
promise.then(function() {
resOrder.push(2);
});
promise.fulfill();
promise.then(function() {
resOrder.push(3);
});
promise.then(function() {
resOrder.push(4);
});
setTimeout(function() {
promise.then(function() {
resOrder.push(5);
setTimeout(function() {
test.deepEqual(resOrder, [1, 2, 3, 4, 5, 6]);
test.done();
}, 10);
});
promise.then(function() {
resOrder.push(6);
});
}, 10);
},
'onFulfilled callback shouldn\'t be called in the same turn of the event loop as the call to then' : function(test) {
var promise = Vow.promise(),
resOrder = [];
promise.then(function() {
resOrder.push(3);
});
process.nextTick(function() {
process.nextTick(function() {
resOrder.push(4);
process.nextTick(function() {
resOrder.push(7);
});
promise.then(function() {
resOrder.push(8);
});
});
promise.then(function() {
resOrder.push(5);
});
promise.then(function() {
resOrder.push(6);
});
resOrder.push(2);
});
resOrder.push(1);
promise.fulfill();
setTimeout(function() {
test.deepEqual(resOrder, [1, 2, 3, 4, 5, 6, 7, 8]);
test.done();
}, 20);
}
},
'promise.reject' : {
'onRejected callbacks should be called on reject only' : function(test) {
var promise = Vow.promise(),
called1 = false,
called2 = false,
called3 = false,
called4 = false;
promise.then(null, function() {
called1 = true;
});
promise.then(function() {
called2 = true;
});
promise.then(null, function() {
called3 = true;
});
promise.reject();
promise.then(null, function() {
called4 = true;
});
promise.then(null, function() {
test.ok(called1);
test.ok(!called2);
test.ok(called3);
test.done();
});
},
'onRejected callbacks should be called once' : function(test) {
var promise = Vow.promise(),
calledCnt = 0;
promise.then(null, function() {
calledCnt++;
});
promise.reject();
promise.reject();
promise.then(null, function() {
test.strictEqual(calledCnt, 1);
test.done();
});
},
'onRejected callbacks shouldn\'t be called if reject have been called after fulfill' : function(test) {
var promise = Vow.promise(),
called = false;
promise.then(null, function() {
called = true;
});
promise.fulfill();
promise.reject();
promise.then(function() {
test.ok(!called);
test.done();
});
},
'onRejected callbacks should be executed in the order of their originating calls to then' : function(test) {
var promise = Vow.promise(),
resOrder = [];
promise.then(null, function() {
resOrder.push(1);
});
promise.then(null, function() {
resOrder.push(2);
});
promise.reject();
promise.then(null, function() {
resOrder.push(3);
});
promise.then(null, function() {
resOrder.push(4);
});
setTimeout(function() {
promise.then(null, function() {
resOrder.push(5);
setTimeout(function() {
test.deepEqual(resOrder, [1, 2, 3, 4, 5, 6]);
test.done();
}, 10);
});
promise.then(null, function() {
resOrder.push(6);
});
}, 10);
},
'onRejected callback shouldn\'t be called in the same turn of the event loop as the call to then' : function(test) {
var promise = Vow.promise(),
resOrder = [];
promise.then(null, function() {
resOrder.push(3);
});
process.nextTick(function() {
process.nextTick(function() {
resOrder.push(4);
process.nextTick(function() {
resOrder.push(7);
});
promise.then(null, function() {
resOrder.push(8);
});
});
promise.then(null, function() {
resOrder.push(5);
});
promise.then(null, function() {
resOrder.push(6);
});
resOrder.push(2);
});
resOrder.push(1);
promise.reject();
setTimeout(function() {
test.deepEqual(resOrder, [1, 2, 3, 4, 5, 6, 7, 8]);
test.done();
}, 20);
}
},
'promise.valueOf' : {
'should return undefined if promise is unresolved' : function(test) {
var promise = Vow.promise();
test.strictEqual(promise.valueOf(), undefined);
test.done();
},
'should return value of fulfillment if promise if fulfilled' : function(test) {
var promise = Vow.promise();
promise.fulfill('ok');
test.strictEqual(promise.valueOf(), 'ok');
test.done();
},
'should return reason of rejection if promise if rejected' : function(test) {
var promise = Vow.promise(),
error = Error();
promise.reject(error);
test.strictEqual(promise.valueOf(), error);
test.done();
}
},
'promise.then' : {
'resulting promise should be fulfilled with same value' : function(test) {
var promise = Vow.promise();
promise.then().then(function(val) {
test.strictEqual(val, 'val');
test.done();
});
promise.fulfill('val');
},
'resulting promise should be rejected with same reason' : function(test) {
var promise = Vow.promise(),
error = new Error('errot');
promise.then().then(null, function(_error) {
test.strictEqual(_error, error);
test.done();
});
promise.reject(error);
},
'resulting promise should be fulfilled with returned value of onFulfilled callback' : function(test) {
var promise = Vow.promise(),
resPromise = promise.then(function() {
return 'val';
});
promise.fulfill();
resPromise.then(function(val) {
test.strictEqual(val, 'val');
test.done();
});
},
'resulting promise should be fulfilled with same value as returned promise of onFulfilled callback' : function(test) {
var promise = Vow.promise(),
retPromise = Vow.promise(),
resPromise = promise.then(function() {
return retPromise;
});
promise.then(function() {
retPromise.fulfill('ok');
});
resPromise.then(function(val) {
test.strictEqual(val, 'ok');
test.done();
});
promise.fulfill();
},
'resulting promise should be rejected with same value as returned promise of onRejected callback' : function(test) {
var promise = Vow.promise(),
retPromise = Vow.promise(),
resPromise = promise.then(function() {
return retPromise;
}),
error = new Error('error');
promise.then(function() {
retPromise.reject(error);
});
resPromise.then(null, function(_error) {
test.strictEqual(_error, error);
test.done();
});
promise.fulfill();
},
'resulting promise should be rejected if onFulfilled callback throw exception' : function(test) {
var promise = Vow.promise(),
resPromise = promise.then(function() {
throw { message : 'error' };
});
resPromise.then(null, function(arg) {
test.deepEqual(arg, { message : 'error' });
test.done();
});
promise.fulfill();
},
'resulting promise should be rejected if onRejected callback throw exception' : function(test) {
var promise = Vow.promise(),
resPromise = promise.then(null, function() {
throw { message : 'error' };
});
resPromise.then(null, function(arg) {
test.deepEqual(arg, { message : 'error' });
test.done();
});
promise.reject();
}
},
'promise.fail' : {
'onRejected callback should be called on reject' : function(test) {
var promise = Vow.promise();
promise.reject('error');
promise.fail(function(error) {
test.strictEqual(error, 'error');
test.done();
});
}
},
'promise.always' : {

@@ -612,33 +169,2 @@ 'onResolved callback should be called on fulfill' : function(test) {

'Vow.always' : {
'onResolved callback should be called when argument fulfilled' : function(test) {
var promise = Vow.promise();
Vow.always(promise, function(val) {
test.strictEqual(val, 'ok');
test.done();
});
promise.fulfill('ok');
},
'onResolved callback should be called when argument rejected' : function(test) {
var promise = Vow.promise();
Vow.always(promise, function(error) {
test.strictEqual(error, 'err');
test.done();
});
promise.reject('err');
},
'onResolved callback should be called when argument is non-promise' : function(test) {
Vow.always('ok', function(val) {
test.strictEqual(val, 'ok');
test.done();
});
}
},
'Vow.spread' : {

@@ -751,64 +277,2 @@ 'onFulfilled argument should be spreaded' : function(test) {

'Vow.fulfill' : {
'resulting promise should be fulfilled if argument is non-promise' : function(test) {
Vow.fulfill('val').then(function(val) {
test.strictEqual(val, 'val');
test.done();
});
},
'resulting promise should be fulfilled if argument is fulfilled' : function(test) {
var promise = Vow.promise();
Vow.fulfill(promise).then(function(val) {
test.strictEqual(val, 'val');
test.done();
});
promise.fulfill('val');
},
'resulting promise should be fulfilled if argument is rejected' : function(test) {
var promise = Vow.promise();
Vow.fulfill(promise).then(function(val) {
test.strictEqual(val, 'error');
test.done();
});
promise.reject('error');
}
},
'Vow.reject' : {
'resulting promise should be rejected if argument is non-promise' : function(test) {
Vow.reject('error').fail(function(error) {
test.strictEqual(error, 'error');
test.done();
});
},
'resulting promise should be rejected if argument is rejected' : function(test) {
var promise = Vow.promise();
Vow.reject(promise).fail(function(error) {
test.strictEqual(error, 'error');
test.done();
});
promise.reject('error');
},
'resulting promise should be rejected if argument is fulfilled' : function(test) {
var promise = Vow.promise();
Vow.reject(promise).fail(function(error) {
test.strictEqual(error, 'val');
test.done();
});
promise.fulfill('val');
}
},
'Vow.resolve' : {

@@ -815,0 +279,0 @@ 'resulting promise should be argument if it is promise' : function(test) {

@@ -9,3 +9,3 @@ /**

*
* @version 0.2.0
*/(function(e){var t=function(e){this._res=e,this._isFulfilled=!!arguments.length,this._isRejected=!1,this._fulfilledCallbacks=[],this._rejectedCallbacks=[]};t.prototype={valueOf:function(){return this._res},isFulfilled:function(){return this._isFulfilled},isRejected:function(){return this._isRejected},isResolved:function(){return this._isFulfilled||this._isRejected},fulfill:function(e){if(this.isResolved())return;this._isFulfilled=!0,this._res=e,this._callCallbacks(this._fulfilledCallbacks),this._fulfilledCallbacks=this._rejectedCallbacks=r},reject:function(e){if(this.isResolved())return;this._isRejected=!0,this._res=e,this._callCallbacks(this._rejectedCallbacks),this._fulfilledCallbacks=this._rejectedCallbacks=r},then:function(e,n){var r=new t,i;return this._isRejected||(i={promise:r,fn:e},this._isFulfilled?this._callCallbacks([i]):this._fulfilledCallbacks.push(i)),this._isFulfilled||(i={promise:r,fn:n},this._isRejected?this._callCallbacks([i]):this._rejectedCallbacks.push(i)),r},fail:function(e){return this.then(r,e)},always:function(e){var t=this,n=function(){e(t)};return this.then(n,n)},spread:function(e,t){return this.then(function(t){return e.apply(this,t)},t)},done:function(){this.fail(u)},timeout:function(e){var n=new t,r=setTimeout(function(){n.reject(Error("timed out"))},e);return this.then(function(e){clearTimeout(r),n.fulfill(e)},function(e){clearTimeout(r),n.reject(e)}),n},sync:function(e){var t=this;e.then(function(e){t.fulfill(e)},function(e){t.reject(e)})},_callCallbacks:function(e){var t=e.length;if(!t)return;var r=this._res,s=this.isFulfilled();i(function(){var i=0,o,u,f;while(i<t){o=e[i++],u=o.promise,f=o.fn;if(a(f)){var l;try{l=f(r)}catch(c){u.reject(c);continue}n.isPromise(l)?function(e){l.then(function(t){e.fulfill(t)},function(t){e.reject(t)})}(u):u.fulfill(l)}else s?u.fulfill(r):u.reject(r)}})}};var n={promise:function(e){return arguments.length?this.isPromise(e)?e:new t(e):new t},when:function(e,t,n){return this.promise(e).then(t,n)},fail:function(e,t){return this.when(e,r,t)},always:function(e,t){return this.when(e,t,t)},spread:function(e,t,n){return this.promise(e).spread(t,n)},done:function(e){this.isPromise(e)&&e.done()},isPromise:function(e){return e&&a(e.then)},valueOf:function(e){return this.isPromise(e)?e.valueOf():e},isFulfilled:function(e){return this.isPromise(e)?e.isFulfilled():!0},isRejected:function(e){return this.isPromise(e)?e.isRejected():!1},isResolved:function(e){return this.isPromise(e)?e.isResolved():!0},fulfill:function(e){return this.when(e,r,function(e){return e})},reject:function(e){return this.when(e,function(e){var n=new t;return n.reject(e),n})},resolve:function(e){return this.isPromise(e)?e:this.when(e)},forEach:function(e,t,n,r){var i=r?r.length:e.length,s=0;while(s<i)this.when(e[r?r[s]:s],t,n),++s},all:function(e){var r=new t,i=l(e),s=i?c(e):h(e),o=s.length,u=i?[]:{};if(!o)return r.fulfill(u),r;var a=o,f=function(){if(!--a){var t=0;while(t<o)u[s[t]]=n.valueOf(e[s[t++]]);r.fulfill(u)}},p=function(e){r.reject(e)};return this.forEach(e,f,p,s),r},allResolved:function(e){var n=new t,r=l(e),i=r?c(e):h(e),s=i.length,o=r?[]:{};if(!s)return n.fulfill(o),n;var u=function(){--s||n.fulfill(e)};return this.forEach(e,u,u,i),n},any:function(e){var n=new t,r=e.length;if(!r)return n.reject(Error()),n;var i=0,s,o=function(e){n.fulfill(e)},u=function(e){i||(s=e),++i===r&&n.reject(s)};return this.forEach(e,o,u),n},timeout:function(e,t){return this.promise(e).timeout(t)}},r,i=typeof process=="object"?process.nextTick:e.setImmediate?e.setImmediate:e.postMessage?function(){var t="__promise"+ +(new Date),n=function(e){e.data===t&&(e.stopPropagation&&e.stopPropagation(),o())};return e.addEventListener?e.addEventListener("message",n,!0):e.attachEvent("onmessage",n),function(n){s.push(n)===1&&e.postMessage(t,"*")}}():"onreadystatechange"in e.document.createElement("script")?function(){var t=function(){var t=document.createElement("script");t.onreadystatechange=function(){t.parentNode.removeChild(t),t=t.onreadystatechange=null,o()},(e.document.documentElement||e.document.body).appendChild(t)};return function(e){s.push(e)===1&&t()}}():function(e){setTimeout(e,0)},s=[],o=function(){var e=s,t=0,n=s.length;s=[];while(t<n)e[t++]()},u=function(e){i(function(){throw e})},a=function(e){return typeof e=="function"},f=Object.prototype.toString,l=Array.isArray||function(e){return f.call(e)==="[object Array]"},c=function(e){var t=[],n=0,r=e.length;while(n<r)t.push(n++);return t},h=Object.keys||function(e){var t=[];for(var n in e)e.hasOwnProperty(n)&&t.push(n);return t};typeof exports=="object"?module.exports=n:typeof define=="function"?define(function(e,t,r){r.exports=n}):e.Vow=n})(this);
* @version 0.2.1
*/(function(e){var t=function(e){this._res=e,this._isFulfilled=!!arguments.length,this._isRejected=!1,this._fulfilledCallbacks=[],this._rejectedCallbacks=[]};t.prototype={valueOf:function(){return this._res},isFulfilled:function(){return this._isFulfilled},isRejected:function(){return this._isRejected},isResolved:function(){return this._isFulfilled||this._isRejected},fulfill:function(e){if(this.isResolved())return;this._isFulfilled=!0,this._res=e,this._callCallbacks(this._fulfilledCallbacks),this._fulfilledCallbacks=this._rejectedCallbacks=r},reject:function(e){if(this.isResolved())return;this._isRejected=!0,this._res=e,this._callCallbacks(this._rejectedCallbacks),this._fulfilledCallbacks=this._rejectedCallbacks=r},then:function(e,n){var r=new t,i;return this._isRejected||(i={promise:r,fn:e},this._isFulfilled?this._callCallbacks([i]):this._fulfilledCallbacks.push(i)),this._isFulfilled||(i={promise:r,fn:n},this._isRejected?this._callCallbacks([i]):this._rejectedCallbacks.push(i)),r},fail:function(e){return this.then(r,e)},always:function(e){var t=this,n=function(){e(t)};return this.then(n,n)},spread:function(e,t){return this.then(function(t){return e.apply(this,t)},t)},done:function(){this.fail(u)},timeout:function(e){var n=new t,r=setTimeout(function(){n.reject(Error("timed out"))},e);return this.then(function(e){clearTimeout(r),n.fulfill(e)},function(e){clearTimeout(r),n.reject(e)}),n},sync:function(e){var t=this;e.then(function(e){t.fulfill(e)},function(e){t.reject(e)})},_callCallbacks:function(e){var t=e.length;if(!t)return;var r=this._res,s=this.isFulfilled();i(function(){var i=0,o,u,f;while(i<t){o=e[i++],u=o.promise,f=o.fn;if(a(f)){var l;try{l=f(r)}catch(c){u.reject(c);continue}n.isPromise(l)?function(e){l.then(function(t){e.fulfill(t)},function(t){e.reject(t)})}(u):u.fulfill(l)}else s?u.fulfill(r):u.reject(r)}})}};var n={promise:function(e){return arguments.length?this.isPromise(e)?e:new t(e):new t},when:function(e,t,n){return this.promise(e).then(t,n)},fail:function(e,t){return this.when(e,r,t)},always:function(e,t){return this.promise(e).always(t)},spread:function(e,t,n){return this.promise(e).spread(t,n)},done:function(e){this.isPromise(e)&&e.done()},isPromise:function(e){return e&&a(e.then)},valueOf:function(e){return this.isPromise(e)?e.valueOf():e},isFulfilled:function(e){return this.isPromise(e)?e.isFulfilled():!0},isRejected:function(e){return this.isPromise(e)?e.isRejected():!1},isResolved:function(e){return this.isPromise(e)?e.isResolved():!0},fulfill:function(e){return this.when(e,r,function(e){return e})},reject:function(e){return this.when(e,function(e){var n=new t;return n.reject(e),n})},resolve:function(e){return this.isPromise(e)?e:this.when(e)},forEach:function(e,t,n,r){var i=r?r.length:e.length,s=0;while(s<i)this.when(e[r?r[s]:s],t,n),++s},all:function(e){var r=new t,i=l(e),s=i?c(e):h(e),o=s.length,u=i?[]:{};if(!o)return r.fulfill(u),r;var a=o,f=function(){if(!--a){var t=0;while(t<o)u[s[t]]=n.valueOf(e[s[t++]]);r.fulfill(u)}},p=function(e){r.reject(e)};return this.forEach(e,f,p,s),r},allResolved:function(e){var n=new t,r=l(e),i=r?c(e):h(e),s=i.length,o=r?[]:{};if(!s)return n.fulfill(o),n;var u=function(){--s||n.fulfill(e)};return this.forEach(e,u,u,i),n},any:function(e){var n=new t,r=e.length;if(!r)return n.reject(Error()),n;var i=0,s,o=function(e){n.fulfill(e)},u=function(e){i||(s=e),++i===r&&n.reject(s)};return this.forEach(e,o,u),n},timeout:function(e,t){return this.promise(e).timeout(t)}},r,i=typeof process=="object"?process.nextTick:e.setImmediate?e.setImmediate:e.postMessage?function(){var t="__promise"+ +(new Date),n=function(e){e.data===t&&(e.stopPropagation&&e.stopPropagation(),o())};return e.addEventListener?e.addEventListener("message",n,!0):e.attachEvent("onmessage",n),function(n){s.push(n)===1&&e.postMessage(t,"*")}}():"onreadystatechange"in e.document.createElement("script")?function(){var t=function(){var t=document.createElement("script");t.onreadystatechange=function(){t.parentNode.removeChild(t),t=t.onreadystatechange=null,o()},(e.document.documentElement||e.document.body).appendChild(t)};return function(e){s.push(e)===1&&t()}}():function(e){setTimeout(e,0)},s=[],o=function(){var e=s,t=0,n=s.length;s=[];while(t<n)e[t++]()},u=function(e){i(function(){throw e})},a=function(e){return typeof e=="function"},f=Object.prototype.toString,l=Array.isArray||function(e){return f.call(e)==="[object Array]"},c=function(e){var t=[],n=0,r=e.length;while(n<r)t.push(n++);return t},h=Object.keys||function(e){var t=[];for(var n in e)e.hasOwnProperty(n)&&t.push(n);return t};typeof exports=="object"?module.exports=n:typeof define=="function"?define(function(e,t,r){r.exports=n}):e.Vow=n})(this);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc