Comparing version 0.12.8 to 0.12.9
@@ -0,1 +1,20 @@ | ||
## 0.12.9 | ||
- Update Q from v0.8.12 to v0.9.0 | ||
## 0.12.8 | ||
- Defer throwing load errors to execution (Fixes #14) | ||
- Update bootstrapping for latest Q | ||
## 0.12.7 | ||
- Support returned exports in bootstrapping | ||
- Export more Node utilities (when used on Node) | ||
- Require.urlToPath -> Require.locationToPath(location) | ||
- Add Require.filePathToLocation(path) | ||
- Add Require.directoryPathToLocation(path) | ||
- Add Require.findPackagePath(directory) | ||
- Add Require.findPackageLocationAndModuleId(path) | ||
## 0.12.6 | ||
@@ -2,0 +21,0 @@ |
{ | ||
"name": "mr", | ||
"version": "0.12.8", | ||
"version": "0.12.9", | ||
"description": "A refresh-only CommonJS module system for browsers, used in Montage", | ||
@@ -5,0 +5,0 @@ "main": "require", |
{ | ||
"name": "q", | ||
"version": "0.8.12", | ||
"description": "A library for promises (CommonJS/Promises/A,B,D)", | ||
"homepage": "https://github.com/kriskowal/q", | ||
"author": "Kris Kowal <kris@cixar.com> (https://github.com/kriskowal)", | ||
"keywords": [ | ||
"q", | ||
"promise", | ||
"promises", | ||
"promises-a", | ||
"promises-a-plus", | ||
"deferred", | ||
"future", | ||
"async", | ||
"flow control", | ||
"fluent", | ||
"browser", | ||
"node" | ||
], | ||
"contributors": [ | ||
"Kris Kowal <kris@cixar.com> (https://github.com/kriskowal)", | ||
"Irakli Gozalishvili <rfobic@gmail.com> (http://jeditoolkit.com)", | ||
"Domenic Denicola <domenic@domenicdenicola.com> (http://domenicdenicola.com)" | ||
], | ||
"bugs": { | ||
"mail": "kris@cixar.com", | ||
"url": "http://github.com/kriskowal/q/issues" | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "http://github.com/kriskowal/q/raw/master/LICENSE" | ||
} | ||
], | ||
"main": "q.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/kriskowal/q.git" | ||
}, | ||
"engines": { | ||
"node": ">=0.6.0", | ||
"teleport": ">=0.2.0" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"jshint": ">=0.9.1", | ||
"cover": "*", | ||
"jasmine-node": "*", | ||
"opener": "*", | ||
"promises-aplus-tests": "~1.0" | ||
}, | ||
"scripts": { | ||
"test": "jasmine-node spec && promises-aplus-tests spec/aplus-adapter", | ||
"test-browser": "opener spec/q-spec.html", | ||
"lint": "jshint q.js", | ||
"cover": "cover run node_modules/jasmine-node/bin/jasmine-node spec && cover report html && opener cover_html/index.html" | ||
}, | ||
"overlay": { | ||
"teleport": { | ||
"dependencies": { | ||
"system": ">=0.0.4" | ||
} | ||
} | ||
}, | ||
"directories": { | ||
"test": "./spec" | ||
"name": "q", | ||
"version": "0.9.0", | ||
"description": "A library for promises (CommonJS/Promises/A,B,D)", | ||
"homepage": "https://github.com/kriskowal/q", | ||
"author": "Kris Kowal <kris@cixar.com> (https://github.com/kriskowal)", | ||
"keywords": [ | ||
"q", | ||
"promise", | ||
"promises", | ||
"promises-a", | ||
"promises-a-plus", | ||
"deferred", | ||
"future", | ||
"async", | ||
"flow control", | ||
"fluent", | ||
"browser", | ||
"node" | ||
], | ||
"contributors": [ | ||
"Kris Kowal <kris@cixar.com> (https://github.com/kriskowal)", | ||
"Irakli Gozalishvili <rfobic@gmail.com> (http://jeditoolkit.com)", | ||
"Domenic Denicola <domenic@domenicdenicola.com> (http://domenicdenicola.com)" | ||
], | ||
"bugs": { | ||
"mail": "kris@cixar.com", | ||
"url": "http://github.com/kriskowal/q/issues" | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "http://github.com/kriskowal/q/raw/master/LICENSE" | ||
} | ||
], | ||
"main": "q.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/kriskowal/q.git" | ||
}, | ||
"engines": { | ||
"node": ">=0.6.0", | ||
"teleport": ">=0.2.0" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"jshint": ">=0.9.1", | ||
"cover": "*", | ||
"jasmine-node": "1.2.2", | ||
"opener": "*", | ||
"promises-aplus-tests": "1.x" | ||
}, | ||
"scripts": { | ||
"test": "jasmine-node spec && promises-aplus-tests spec/aplus-adapter", | ||
"test-browser": "opener spec/q-spec.html", | ||
"lint": "jshint q.js", | ||
"cover": "cover run node_modules/jasmine-node/bin/jasmine-node spec && cover report html && opener cover_html/index.html" | ||
}, | ||
"overlay": { | ||
"teleport": { | ||
"dependencies": { | ||
"system": ">=0.0.4" | ||
} | ||
} | ||
}, | ||
"directories": { | ||
"test": "./spec" | ||
} | ||
} |
@@ -44,3 +44,3 @@ // vim:ts=4:sts=4:sw=4: | ||
} else if (typeof exports === "object") { | ||
definition(void 0, exports); | ||
module.exports = definition(); | ||
@@ -56,6 +56,3 @@ // RequireJS | ||
} else { | ||
ses.makeQ = function () { | ||
var Q = {}; | ||
return definition(void 0, Q); | ||
}; | ||
ses.makeQ = definition; | ||
} | ||
@@ -65,6 +62,6 @@ | ||
} else { | ||
definition(void 0, Q = {}); | ||
Q = definition(); | ||
} | ||
})(function (require, exports) { | ||
})(function () { | ||
"use strict"; | ||
@@ -79,15 +76,5 @@ | ||
// used for fallback "defend" and in "allResolved" | ||
// used for fallback in "allResolved" | ||
var noop = function () {}; | ||
// for the security conscious, defend may be a deep freeze as provided | ||
// by cajaVM. Otherwise we try to provide a shallow freeze just to | ||
// discourage promise changes that are not compatible with secure | ||
// usage. If Object.freeze does not exist, fall back to doing nothing | ||
// (no op). | ||
var defend = Object.freeze || noop; | ||
if (typeof cajaVM !== "undefined") { | ||
defend = cajaVM.def; | ||
} | ||
// use the fastest possible means to execute a task in a future turn | ||
@@ -101,24 +88,65 @@ // of the event loop. | ||
// In IE10, or use https://github.com/NobleJS/setImmediate | ||
nextTick = setImmediate; | ||
} else if (typeof MessageChannel !== "undefined") { | ||
// modern browsers | ||
// http://www.nonblocking.io/2011/06/windownexttick.html | ||
var channel = new MessageChannel(); | ||
// linked list of tasks (single, with head node) | ||
var head = {}, tail = head; | ||
channel.port1.onmessage = function () { | ||
head = head.next; | ||
var task = head.task; | ||
delete head.task; | ||
task(); | ||
}; | ||
nextTick = function (task) { | ||
tail = tail.next = {task: task}; | ||
channel.port2.postMessage(0); | ||
}; | ||
if (typeof window !== "undefined") { | ||
nextTick = setImmediate.bind(window); | ||
} else { | ||
nextTick = setImmediate; | ||
} | ||
} else { | ||
// old browsers | ||
nextTick = function (task) { | ||
setTimeout(task, 0); | ||
}; | ||
(function () { | ||
// linked list of tasks (single, with head node) | ||
var head = {task: void 0, next: null}, tail = head, | ||
maxPendingTicks = 2, pendingTicks = 0, queuedTasks = 0, usedTicks = 0, | ||
requestTick; | ||
function onTick() { | ||
// In case of multiple tasks ensure at least one subsequent tick | ||
// to handle remaining tasks in case one throws. | ||
--pendingTicks; | ||
if (++usedTicks >= maxPendingTicks) { | ||
// Amortize latency after thrown exceptions. | ||
usedTicks = 0; | ||
maxPendingTicks *= 4; // fast grow! | ||
var expectedTicks = queuedTasks && Math.min(queuedTasks - 1, maxPendingTicks); | ||
while (pendingTicks < expectedTicks) { | ||
++pendingTicks; | ||
requestTick(); | ||
} | ||
} | ||
while (queuedTasks) { | ||
--queuedTasks; // decrement here to ensure it's never negative | ||
head = head.next; | ||
var task = head.task; | ||
head.task = void 0; | ||
task(); | ||
} | ||
usedTicks = 0; | ||
} | ||
nextTick = function (task) { | ||
tail = tail.next = {task: task, next: null}; | ||
if (pendingTicks < ++queuedTasks && pendingTicks < maxPendingTicks) { | ||
++pendingTicks; | ||
requestTick(); | ||
} | ||
}; | ||
if (typeof MessageChannel !== "undefined") { | ||
// modern browsers | ||
// http://www.nonblocking.io/2011/06/windownexttick.html | ||
var channel = new MessageChannel(); | ||
channel.port1.onmessage = onTick; | ||
requestTick = function () { | ||
channel.port2.postMessage(0); | ||
}; | ||
} else { | ||
// old browsers | ||
requestTick = function () { | ||
setTimeout(onTick, 0); | ||
}; | ||
} | ||
})(); | ||
} | ||
@@ -137,15 +165,11 @@ | ||
// http://wiki.ecmascript.org/doku.php?id=conventions:safe_meta_programming | ||
var uncurryThis; | ||
// I have kept both variations because the first is theoretically | ||
// faster, if bind is available. | ||
if (Function.prototype.bind) { | ||
var Function_bind = Function.prototype.bind; | ||
uncurryThis = Function_bind.bind(Function_bind.call); | ||
} else { | ||
uncurryThis = function (f) { | ||
return function () { | ||
return f.call.apply(f, arguments); | ||
}; | ||
function uncurryThis(f) { | ||
var call = Function.call; | ||
return function () { | ||
return call.apply(f, arguments); | ||
}; | ||
} | ||
// This is equivalent, but slower: | ||
// uncurryThis = Function_bind.bind(Function_bind.call); | ||
// http://jsperf.com/uncurrythis | ||
@@ -212,6 +236,10 @@ var array_slice = uncurryThis(Array.prototype.slice); | ||
var object_hasOwnProperty = uncurryThis(Object.prototype.hasOwnProperty); | ||
var object_keys = Object.keys || function (object) { | ||
var keys = []; | ||
for (var key in object) { | ||
keys.push(key); | ||
if (object_hasOwnProperty(object, key)) { | ||
keys.push(key); | ||
} | ||
} | ||
@@ -221,3 +249,3 @@ return keys; | ||
var object_toString = Object.prototype.toString; | ||
var object_toString = uncurryThis(Object.prototype.toString); | ||
@@ -244,2 +272,4 @@ // generator related shims | ||
Q.longStackJumpLimit = 1; | ||
var STACK_JUMP_SEPARATOR = "From previous event:"; | ||
@@ -333,6 +363,15 @@ | ||
/** | ||
* Creates fulfilled promises from non-promises, | ||
* Passes Q promises through, | ||
* Coerces CommonJS/Promises/A+ promises to Q promises. | ||
*/ | ||
function Q(value) { | ||
return resolve(value); | ||
} | ||
/** | ||
* Performs a task in a future turn of the event loop. | ||
* @param {Function} task | ||
*/ | ||
exports.nextTick = nextTick; | ||
Q.nextTick = nextTick; | ||
@@ -348,3 +387,3 @@ /** | ||
*/ | ||
exports.defer = defer; | ||
Q.defer = defer; | ||
function defer() { | ||
@@ -362,12 +401,12 @@ // if "pending" is an "Array", that indicates that the promise has not yet | ||
promise.promiseSend = function (op, _, __, progress) { | ||
promise.promiseDispatch = function (resolve, op, operands) { | ||
var args = array_slice(arguments); | ||
if (pending) { | ||
pending.push(args); | ||
if (op === "when" && progress) { | ||
progressListeners.push(progress); | ||
if (op === "when" && operands[1]) { // progress operand | ||
progressListeners.push(operands[1]); | ||
} | ||
} else { | ||
nextTick(function () { | ||
value.promiseSend.apply(value, args); | ||
value.promiseDispatch.apply(value, args); | ||
}); | ||
@@ -381,6 +420,7 @@ } | ||
} | ||
return value.valueOf(); | ||
value = valueOf(value); // shorten chain | ||
return value; | ||
}; | ||
if (Error.captureStackTrace) { | ||
if (Error.captureStackTrace && Q.longStackJumpLimit > 0) { | ||
Error.captureStackTrace(promise, defer); | ||
@@ -401,3 +441,3 @@ | ||
nextTick(function () { | ||
value.promiseSend.apply(value, pending); | ||
value.promiseDispatch.apply(value, pending); | ||
}); | ||
@@ -409,6 +449,7 @@ }, void 0); | ||
defend(promise); | ||
deferred.promise = promise; | ||
deferred.resolve = become; | ||
deferred.fulfill = function (value) { | ||
become(fulfill(value)); | ||
}; | ||
deferred.reject = function (exception) { | ||
@@ -447,4 +488,2 @@ become(reject(exception)); | ||
}; | ||
// XXX deprecated | ||
defer.prototype.node = deprecate(defer.prototype.makeNodeResolver, "node", "makeNodeResolver"); | ||
@@ -457,3 +496,3 @@ /** | ||
*/ | ||
exports.promise = promise; | ||
Q.promise = promise; | ||
function promise(makePromise) { | ||
@@ -481,4 +520,4 @@ var deferred = defer(); | ||
*/ | ||
exports.makePromise = makePromise; | ||
function makePromise(descriptor, fallback, valueOf, exception) { | ||
Q.makePromise = makePromise; | ||
function makePromise(descriptor, fallback, valueOf, exception, isException) { | ||
if (fallback === void 0) { | ||
@@ -492,4 +531,3 @@ fallback = function (op) { | ||
promise.promiseSend = function (op, resolved /* ...args */) { | ||
var args = array_slice(arguments, 2); | ||
promise.promiseDispatch = function (resolve, op, args) { | ||
var result; | ||
@@ -500,3 +538,3 @@ try { | ||
} else { | ||
result = fallback.apply(promise, [op].concat(args)); | ||
result = fallback.call(promise, op, args); | ||
} | ||
@@ -506,4 +544,4 @@ } catch (exception) { | ||
} | ||
if (resolved) { | ||
resolved(result); | ||
if (resolve) { | ||
resolve(result); | ||
} | ||
@@ -516,8 +554,6 @@ }; | ||
if (exception) { | ||
if (isException) { | ||
promise.exception = exception; | ||
} | ||
defend(promise); | ||
return promise; | ||
@@ -535,25 +571,28 @@ } | ||
makePromise.prototype.thenReject = function (reason) { | ||
return when(this, function () { throw reason; }); | ||
}; | ||
// Chainable methods | ||
array_reduce( | ||
[ | ||
"isResolved", "isFulfilled", "isRejected", | ||
"when", "spread", "send", | ||
"get", "put", "del", | ||
"post", "invoke", | ||
"isFulfilled", "isRejected", "isPending", | ||
"dispatch", | ||
"when", "spread", | ||
"get", "put", "set", "del", "delete", | ||
"post", "send", "invoke", | ||
"keys", | ||
"apply", "call", "bind", | ||
"fapply", "fcall", "fbind", | ||
"all", "allResolved", | ||
"view", "viewInfo", | ||
"timeout", "delay", | ||
"catch", "finally", "fail", "fin", "progress", "end", "done", | ||
"nfcall", "nfapply", "nfbind", | ||
"catch", "finally", "fail", "fin", "progress", "done", | ||
"nfcall", "nfapply", "nfbind", "denodeify", "nbind", | ||
"ncall", "napply", "nbind", | ||
"npost", "ninvoke", | ||
"nend", "nodeify" | ||
"npost", "nsend", "ninvoke", | ||
"nodeify" | ||
], | ||
function (undefined, name) { | ||
makePromise.prototype[name] = function () { | ||
return exports[name].apply( | ||
exports, | ||
return Q[name].apply( | ||
Q, | ||
[this].concat(array_slice(arguments)) | ||
@@ -574,4 +613,2 @@ ); | ||
defend(makePromise.prototype); | ||
/** | ||
@@ -586,3 +623,3 @@ * If an object is not a promise, it is as "near" as possible. | ||
*/ | ||
exports.nearer = valueOf; | ||
Q.nearer = valueOf; | ||
function valueOf(value) { | ||
@@ -599,12 +636,8 @@ if (isPromise(value)) { | ||
*/ | ||
exports.isPromise = isPromise; | ||
Q.isPromise = isPromise; | ||
function isPromise(object) { | ||
return object && typeof object.promiseSend === "function"; | ||
return object && typeof object.promiseDispatch === "function"; | ||
} | ||
/** | ||
* @returns whether the given object can be coerced to a promise. | ||
* Otherwise it is a fulfilled value. | ||
*/ | ||
exports.isPromiseAlike = isPromiseAlike; | ||
Q.isPromiseAlike = isPromiseAlike; | ||
function isPromiseAlike(object) { | ||
@@ -615,7 +648,8 @@ return object && typeof object.then === "function"; | ||
/** | ||
* @returns whether the given object is a resolved promise. | ||
* @returns whether the given object is a pending promise, meaning not | ||
* fulfilled or rejected. | ||
*/ | ||
exports.isResolved = isResolved; | ||
function isResolved(object) { | ||
return isFulfilled(object) || isRejected(object); | ||
Q.isPending = isPending; | ||
function isPending(object) { | ||
return !isFulfilled(object) && !isRejected(object); | ||
} | ||
@@ -627,3 +661,3 @@ | ||
*/ | ||
exports.isFulfilled = isFulfilled; | ||
Q.isFulfilled = isFulfilled; | ||
function isFulfilled(object) { | ||
@@ -636,3 +670,3 @@ return !isPromiseAlike(valueOf(object)); | ||
*/ | ||
exports.isRejected = isRejected; | ||
Q.isRejected = isRejected; | ||
function isRejected(object) { | ||
@@ -662,2 +696,18 @@ object = valueOf(object); | ||
// Show unhandled rejection if Node exits without handling an outstanding | ||
// rejection. (Note that Browserify presently produces a process global | ||
// without the Emitter on interface) | ||
if (typeof process !== "undefined" && process.on) { | ||
process.on("exit", function () { | ||
for (var i = 0; i < errors.length; i++) { | ||
var error = errors[i]; | ||
if (error && typeof error.stack !== "undefined") { | ||
console.warn("Unhandled rejected promise:", error.stack); | ||
} else { | ||
console.warn("Unhandled rejected promise (no stack):", error); | ||
} | ||
} | ||
}); | ||
} | ||
/** | ||
@@ -667,3 +717,3 @@ * Constructs a rejected promise. | ||
*/ | ||
exports.reject = reject; | ||
Q.reject = reject; | ||
function reject(exception) { | ||
@@ -680,3 +730,3 @@ var rejection = makePromise({ | ||
} | ||
return rejected ? rejected(exception) : reject(exception); | ||
return rejected ? rejected(exception) : this; | ||
} | ||
@@ -687,3 +737,3 @@ }, function fallback() { | ||
return this; | ||
}, exception); | ||
}, exception, true); | ||
// note that the error has not been handled | ||
@@ -697,30 +747,7 @@ displayErrors(); | ||
/** | ||
* Constructs a promise for an immediate reference. | ||
* Constructs a fulfilled promise for an immediate reference. | ||
* @param value immediate reference | ||
*/ | ||
exports.begin = resolve; // XXX experimental | ||
exports.resolve = resolve; | ||
exports.ref = deprecate(resolve, "ref", "resolve"); // XXX deprecated, use resolve | ||
function resolve(object) { | ||
// If the object is already a Promise, return it directly. This enables | ||
// the resolve function to both be used to created references from objects, | ||
// but to tolerably coerce non-promises to promises. | ||
if (isPromise(object)) { | ||
return object; | ||
} | ||
// In order to break infinite recursion or loops between `then` and | ||
// `resolve`, it is necessary to attempt to extract fulfilled values | ||
// out of foreign promise implementations before attempting to wrap | ||
// them as unresolved promises. It is my hope that other | ||
// implementations will implement `valueOf` to synchronously extract | ||
// the fulfillment value from their fulfilled promises. If the | ||
// other promise library does not implement `valueOf`, the | ||
// implementations on primordial prototypes are harmless. | ||
object = valueOf(object); | ||
// assimilate thenables, CommonJS/Promises/A | ||
if (isPromiseAlike(object)) { | ||
var deferred = defer(); | ||
object.then(deferred.resolve, deferred.reject, deferred.notify); | ||
return deferred.promise; | ||
} | ||
Q.fulfill = fulfill; | ||
function fulfill(object) { | ||
return makePromise({ | ||
@@ -733,38 +760,20 @@ "when": function () { | ||
}, | ||
"put": function (name, value) { | ||
"set": function (name, value) { | ||
object[name] = value; | ||
return object; | ||
}, | ||
"del": function (name) { | ||
"delete": function (name) { | ||
delete object[name]; | ||
return object; | ||
}, | ||
"post": function (name, value) { | ||
return object[name].apply(object, value); | ||
"post": function (name, args) { | ||
// Mark Miller proposes that post with no name should apply a | ||
// promised function. | ||
if (name == null) { // iff name is null or undefined | ||
return object.apply(void 0, args); | ||
} else { | ||
return object[name].apply(object, args); | ||
} | ||
}, | ||
"apply": function (self, args) { | ||
return object.apply(self, args); | ||
"apply": function (thisP, args) { | ||
return object.apply(thisP, args); | ||
}, | ||
"fapply": function (args) { | ||
return object.apply(void 0, args); | ||
}, | ||
"viewInfo": function () { | ||
var on = object; | ||
var properties = {}; | ||
function fixFalsyProperty(name) { | ||
if (!properties[name]) { | ||
properties[name] = typeof on[name]; | ||
} | ||
} | ||
while (on) { | ||
Object.getOwnPropertyNames(on).forEach(fixFalsyProperty); | ||
on = Object.getPrototypeOf(on); | ||
} | ||
return { | ||
"type": typeof object, | ||
"properties": properties | ||
}; | ||
}, | ||
"keys": function () { | ||
@@ -779,2 +788,49 @@ return object_keys(object); | ||
/** | ||
* Constructs a promise for an immediate reference, passes promises through, or | ||
* coerces promises from different systems. | ||
* @param value immediate reference or promise | ||
*/ | ||
Q.resolve = resolve; | ||
function resolve(value) { | ||
// If the object is already a Promise, return it directly. This enables | ||
// the resolve function to both be used to created references from objects, | ||
// but to tolerably coerce non-promises to promises. | ||
if (isPromise(value)) { | ||
return value; | ||
} | ||
// In order to break infinite recursion or loops between `then` and | ||
// `resolve`, it is necessary to attempt to extract fulfilled values | ||
// out of foreign promise implementations before attempting to wrap | ||
// them as unresolved promises. It is my hope that other | ||
// implementations will implement `valueOf` to synchronously extract | ||
// the fulfillment value from their fulfilled promises. If the | ||
// other promise library does not implement `valueOf`, the | ||
// implementations on primordial prototypes are harmless. | ||
value = valueOf(value); | ||
// assimilate thenables, CommonJS/Promises/A+ | ||
if (isPromiseAlike(value)) { | ||
return coerce(value); | ||
} else { | ||
return fulfill(value); | ||
} | ||
} | ||
/** | ||
* Converts thenables to Q promises. | ||
* @param promise thenable promise | ||
* @returns a Q promise | ||
*/ | ||
function coerce(promise) { | ||
var deferred = defer(); | ||
nextTick(function () { | ||
try { | ||
promise.then(deferred.resolve, deferred.reject, deferred.notify); | ||
} catch (exception) { | ||
deferred.reject(exception); | ||
} | ||
}); | ||
return deferred.promise; | ||
} | ||
/** | ||
* Annotates an object such that it will never be | ||
@@ -788,9 +844,8 @@ * transferred away from this process over any promise | ||
*/ | ||
exports.master = master; | ||
Q.master = master; | ||
function master(object) { | ||
return makePromise({ | ||
"isDef": function () {} | ||
}, function fallback() { | ||
var args = array_slice(arguments); | ||
return send.apply(void 0, [object].concat(args)); | ||
}, function fallback(op, args) { | ||
return dispatch(object, op, args); | ||
}, function () { | ||
@@ -801,44 +856,2 @@ return valueOf(object); | ||
exports.viewInfo = viewInfo; | ||
function viewInfo(object, info) { | ||
object = resolve(object); | ||
if (info) { | ||
return makePromise({ | ||
"viewInfo": function () { | ||
return info; | ||
} | ||
}, function fallback() { | ||
var args = array_slice(arguments); | ||
return send.apply(void 0, [object].concat(args)); | ||
}, function () { | ||
return valueOf(object); | ||
}); | ||
} else { | ||
return send(object, "viewInfo"); | ||
} | ||
} | ||
exports.view = view; | ||
function view(object) { | ||
return viewInfo(object).when(function (info) { | ||
var view; | ||
if (info.type === "function") { | ||
view = function () { | ||
return apply(object, void 0, arguments); | ||
}; | ||
} else { | ||
view = {}; | ||
} | ||
var properties = info.properties || {}; | ||
object_keys(properties).forEach(function (name) { | ||
if (properties[name] === "function") { | ||
view[name] = function () { | ||
return post(object, name, arguments); | ||
}; | ||
} | ||
}); | ||
return resolve(view); | ||
}); | ||
} | ||
/** | ||
@@ -860,3 +873,3 @@ * Registers an observer on a promise. | ||
*/ | ||
exports.when = when; | ||
Q.when = when; | ||
function when(value, fulfilled, rejected, progressed) { | ||
@@ -893,3 +906,3 @@ var deferred = defer(); | ||
nextTick(function () { | ||
resolvedValue.promiseSend("when", function (value) { | ||
resolvedValue.promiseDispatch(function (value) { | ||
if (done) { | ||
@@ -901,3 +914,3 @@ return; | ||
deferred.resolve(_fulfilled(value)); | ||
}, function (exception) { | ||
}, "when", [function (exception) { | ||
if (done) { | ||
@@ -909,10 +922,25 @@ return; | ||
deferred.resolve(_rejected(exception)); | ||
}); | ||
}]); | ||
}); | ||
// Progress propagator need to be attached in the current tick. | ||
resolvedValue.promiseSend("when", void 0, void 0, function (value) { | ||
deferred.notify(_progressed(value)); | ||
}); | ||
resolvedValue.promiseDispatch(void 0, "when", [void 0, function (value) { | ||
var newValue; | ||
var threw = false; | ||
try { | ||
newValue = _progressed(value); | ||
} catch (e) { | ||
threw = true; | ||
if (Q.onerror) { | ||
Q.onerror(e); | ||
} else { | ||
throw e; | ||
} | ||
} | ||
if (!threw) { | ||
deferred.notify(newValue); | ||
} | ||
}]); | ||
return deferred.promise; | ||
@@ -931,3 +959,3 @@ } | ||
*/ | ||
exports.spread = spread; | ||
Q.spread = spread; | ||
function spread(promise, fulfilled, rejected) { | ||
@@ -974,3 +1002,3 @@ return when(promise, function (valuesOrPromises) { | ||
*/ | ||
exports.async = async; | ||
Q.async = async; | ||
function async(makeGenerator) { | ||
@@ -1013,3 +1041,3 @@ return function () { | ||
*/ | ||
exports['return'] = _return; | ||
Q['return'] = _return; | ||
function _return(value) { | ||
@@ -1034,7 +1062,7 @@ throw new QReturnValue(value); | ||
*/ | ||
exports.promised = promised; | ||
Q.promised = promised; | ||
function promised(callback) { | ||
return function () { | ||
return all([this, all(arguments)]).spread(function (self, args) { | ||
return callback.apply(self, args); | ||
return spread([this, all(arguments)], function (self, args) { | ||
return callback.apply(self, args); | ||
}); | ||
@@ -1045,51 +1073,13 @@ }; | ||
/** | ||
* Constructs a promise method that can be used to safely observe resolution of | ||
* a promise for an arbitrarily named method like "propfind" in a future turn. | ||
*/ | ||
exports.sender = deprecate(sender, "sender", "dispatcher"); // XXX deprecated, use dispatcher | ||
exports.Method = deprecate(sender, "Method", "dispatcher"); // XXX deprecated, use dispatcher | ||
function sender(op) { | ||
return function (object) { | ||
var args = array_slice(arguments, 1); | ||
return send.apply(void 0, [object, op].concat(args)); | ||
}; | ||
} | ||
/** | ||
* sends a message to a value in a future turn | ||
* @param object* the recipient | ||
* @param op the name of the message operation, e.g., "when", | ||
* @param ...args further arguments to be forwarded to the operation | ||
* @returns result {Promise} a promise for the result of the operation | ||
*/ | ||
exports.send = deprecate(send, "send", "dispatch"); // XXX deprecated, use dispatch | ||
function send(object, op) { | ||
var deferred = defer(); | ||
var args = array_slice(arguments, 2); | ||
object = resolve(object); | ||
nextTick(function () { | ||
object.promiseSend.apply( | ||
object, | ||
[op, deferred.resolve].concat(args) | ||
); | ||
}); | ||
return deferred.promise; | ||
} | ||
/** | ||
* sends a message to a value in a future turn | ||
* @param object* the recipient | ||
* @param op the name of the message operation, e.g., "when", | ||
* @param args further arguments to be forwarded to the operation | ||
* @returns result {Promise} a promise for the result of the operation | ||
*/ | ||
exports.dispatch = dispatch; | ||
Q.dispatch = dispatch; | ||
function dispatch(object, op, args) { | ||
var deferred = defer(); | ||
object = resolve(object); | ||
nextTick(function () { | ||
object.promiseSend.apply( | ||
object, | ||
[op, deferred.resolve].concat(args) | ||
); | ||
resolve(object).promiseDispatch(deferred.resolve, op, args); | ||
}); | ||
@@ -1105,3 +1095,3 @@ return deferred.promise; | ||
*/ | ||
exports.dispatcher = dispatcher; | ||
Q.dispatcher = dispatcher; | ||
function dispatcher(op) { | ||
@@ -1120,3 +1110,3 @@ return function (object) { | ||
*/ | ||
exports.get = dispatcher("get"); | ||
Q.get = dispatcher("get"); | ||
@@ -1130,3 +1120,3 @@ /** | ||
*/ | ||
exports.put = dispatcher("put"); | ||
Q.set = dispatcher("set"); | ||
@@ -1139,4 +1129,4 @@ /** | ||
*/ | ||
exports["delete"] = // XXX experimental | ||
exports.del = dispatcher("del"); | ||
Q["delete"] = // XXX experimental | ||
Q.del = dispatcher("delete"); | ||
@@ -1156,3 +1146,3 @@ /** | ||
// bound locally because it is used by other methods | ||
var post = exports.post = dispatcher("post"); | ||
var post = Q.post = dispatcher("post"); | ||
@@ -1166,6 +1156,8 @@ /** | ||
*/ | ||
exports.invoke = function (value, name) { | ||
Q.send = send; | ||
Q.invoke = send; // synonyms | ||
function send(value, name) { | ||
var args = array_slice(arguments, 2); | ||
return post(value, name, args); | ||
}; | ||
} | ||
@@ -1175,26 +1167,7 @@ /** | ||
* @param object promise or immediate reference for target function | ||
* @param thisp the `this` object for the call | ||
* @param args array of application arguments | ||
*/ | ||
// XXX deprecated, use fapply | ||
var apply = exports.apply = deprecate(dispatcher("apply"), "apply", "fapply"); | ||
/** | ||
* Applies the promised function in a future turn. | ||
* @param object promise or immediate reference for target function | ||
* @param args array of application arguments | ||
*/ | ||
var fapply = exports.fapply = dispatcher("fapply"); | ||
/** | ||
* Calls the promised function in a future turn. | ||
* @param object promise or immediate reference for target function | ||
* @param thisp the `this` object for the call | ||
* @param ...args array of application arguments | ||
*/ | ||
// XXX deprecated, use fcall | ||
exports.call = deprecate(call, "call", "fcall"); | ||
function call(value, thisp) { | ||
var args = array_slice(arguments, 2); | ||
return apply(value, thisp, args); | ||
Q.fapply = fapply; | ||
function fapply(value, args) { | ||
return dispatch(value, "apply", [void 0, args]); | ||
} | ||
@@ -1207,4 +1180,4 @@ | ||
*/ | ||
exports["try"] = fcall; // XXX experimental | ||
exports.fcall = fcall; | ||
Q["try"] = fcall; // XXX experimental | ||
Q.fcall = fcall; | ||
function fcall(value) { | ||
@@ -1219,21 +1192,5 @@ var args = array_slice(arguments, 1); | ||
* @param object promise or immediate reference for target function | ||
* @param thisp the `this` object for the call | ||
* @param ...args array of application arguments | ||
*/ | ||
exports.bind = deprecate(bind, "bind", "fbind"); // XXX deprecated, use fbind | ||
function bind(value, thisp) { | ||
var args = array_slice(arguments, 2); | ||
return function bound() { | ||
var allArgs = args.concat(array_slice(arguments)); | ||
return apply(value, thisp, allArgs); | ||
}; | ||
} | ||
/** | ||
* Binds the promised function, transforming return values into a fulfilled | ||
* promise and thrown errors into a rejected one. | ||
* @param object promise or immediate reference for target function | ||
* @param ...args array of application arguments | ||
*/ | ||
exports.fbind = fbind; | ||
Q.fbind = fbind; | ||
function fbind(value) { | ||
@@ -1243,3 +1200,3 @@ var args = array_slice(arguments, 1); | ||
var allArgs = args.concat(array_slice(arguments)); | ||
return fapply(value, allArgs); | ||
return dispatch(value, "apply", [this, allArgs]); | ||
}; | ||
@@ -1254,3 +1211,3 @@ } | ||
*/ | ||
exports.keys = dispatcher("keys"); | ||
Q.keys = dispatcher("keys"); | ||
@@ -1266,9 +1223,6 @@ /** | ||
// http://wiki.ecmascript.org/doku.php?id=strawman:concurrency&rev=1308776521#allfulfilled | ||
exports.all = all; | ||
Q.all = all; | ||
function all(promises) { | ||
return when(promises, function (promises) { | ||
var countDown = promises.length; | ||
if (countDown === 0) { | ||
return resolve(promises); | ||
} | ||
var countDown = 0; | ||
var deferred = defer(); | ||
@@ -1278,6 +1232,4 @@ array_reduce(promises, function (undefined, promise, index) { | ||
promises[index] = valueOf(promise); | ||
if (--countDown === 0) { | ||
deferred.resolve(promises); | ||
} | ||
} else { | ||
++countDown; | ||
when(promise, function (value) { | ||
@@ -1288,6 +1240,8 @@ promises[index] = value; | ||
} | ||
}) | ||
.fail(deferred.reject); | ||
}, deferred.reject); | ||
} | ||
}, void 0); | ||
if (countDown === 0) { | ||
deferred.resolve(promises); | ||
} | ||
return deferred.promise; | ||
@@ -1306,9 +1260,10 @@ }); | ||
*/ | ||
exports.allResolved = allResolved; | ||
Q.allResolved = allResolved; | ||
function allResolved(promises) { | ||
return when(promises, function (promises) { | ||
promises = array_map(promises, resolve); | ||
return when(all(array_map(promises, function (promise) { | ||
return when(promise, noop, noop); | ||
})), function () { | ||
return array_map(promises, resolve); | ||
return promises; | ||
}); | ||
@@ -1327,4 +1282,4 @@ }); | ||
*/ | ||
exports["catch"] = // XXX experimental | ||
exports.fail = fail; | ||
Q["catch"] = // XXX experimental | ||
Q.fail = fail; | ||
function fail(promise, rejected) { | ||
@@ -1342,3 +1297,3 @@ return when(promise, void 0, rejected); | ||
*/ | ||
exports.progress = progress; | ||
Q.progress = progress; | ||
function progress(promise, progressed) { | ||
@@ -1359,4 +1314,4 @@ return when(promise, void 0, void 0, progressed); | ||
*/ | ||
exports["finally"] = // XXX experimental | ||
exports.fin = fin; | ||
Q["finally"] = // XXX experimental | ||
Q.fin = fin; | ||
function fin(promise, callback) { | ||
@@ -1380,6 +1335,5 @@ return when(promise, function (value) { | ||
*/ | ||
exports.end = deprecate(done, "end", "done"); // XXX deprecated, use done | ||
exports.done = done; | ||
Q.done = done; | ||
function done(promise, fulfilled, rejected, progress) { | ||
function onUnhandledError(error) { | ||
var onUnhandledError = function (error) { | ||
// forward to a future turn so that ``when`` | ||
@@ -1390,4 +1344,4 @@ // does not catch it and turn it into a rejection. | ||
if (exports.onerror) { | ||
exports.onerror(error); | ||
if (Q.onerror) { | ||
Q.onerror(error); | ||
} else { | ||
@@ -1397,3 +1351,3 @@ throw error; | ||
}); | ||
} | ||
}; | ||
@@ -1405,2 +1359,5 @@ // Avoid unnecessary `nextTick`ing via an unnecessary `when`. | ||
if (typeof process === "object" && process && process.domain) { | ||
onUnhandledError = process.domain.bind(onUnhandledError); | ||
} | ||
fail(promiseToHandle, onUnhandledError); | ||
@@ -1417,3 +1374,3 @@ } | ||
*/ | ||
exports.timeout = timeout; | ||
Q.timeout = timeout; | ||
function timeout(promise, ms) { | ||
@@ -1444,3 +1401,3 @@ var deferred = defer(); | ||
*/ | ||
exports.delay = delay; | ||
Q.delay = delay; | ||
function delay(promise, timeout) { | ||
@@ -1467,3 +1424,3 @@ if (timeout === void 0) { | ||
*/ | ||
exports.nfapply = nfapply; | ||
Q.nfapply = nfapply; | ||
function nfapply(callback, args) { | ||
@@ -1487,3 +1444,3 @@ var nodeArgs = array_slice(args); | ||
*/ | ||
exports.nfcall = nfcall; | ||
Q.nfcall = nfcall; | ||
function nfcall(callback/*, ...args */) { | ||
@@ -1507,3 +1464,4 @@ var nodeArgs = array_slice(arguments, 1); | ||
*/ | ||
exports.nfbind = nfbind; | ||
Q.nfbind = nfbind; | ||
Q.denodeify = Q.nfbind; // synonyms | ||
function nfbind(callback/*, ...args */) { | ||
@@ -1521,60 +1479,16 @@ var baseArgs = array_slice(arguments, 1); | ||
/** | ||
* Passes a continuation to a Node function, which is called with a given | ||
* `this` value and arguments provided as an array, and returns a promise. | ||
* | ||
* Q.napply(FS.readFile, FS, [__filename]) | ||
* .then(function (content) { | ||
* }) | ||
* | ||
*/ | ||
exports.napply = deprecate(napply, "napply", "npost"); | ||
function napply(callback, thisp, args) { | ||
return nbind(callback, thisp).apply(void 0, args); | ||
} | ||
Q.nbind = nbind; | ||
function nbind(callback/*, ... args*/) { | ||
var baseArgs = array_slice(arguments, 1); | ||
return function () { | ||
var nodeArgs = baseArgs.concat(array_slice(arguments)); | ||
var deferred = defer(); | ||
nodeArgs.push(deferred.makeNodeResolver()); | ||
/** | ||
* Passes a continuation to a Node function, which is called with a given | ||
* `this` value and arguments provided individually, and returns a promise. | ||
* | ||
* Q.ncall(FS.readFile, FS, __filename) | ||
* .then(function (content) { | ||
* }) | ||
* | ||
*/ | ||
exports.ncall = deprecate(ncall, "ncall", "ninvoke"); | ||
function ncall(callback, thisp /*, ...args*/) { | ||
var args = array_slice(arguments, 2); | ||
return napply(callback, thisp, args); | ||
} | ||
var thisArg = this; | ||
function bound() { | ||
return callback.apply(thisArg, arguments); | ||
} | ||
/** | ||
* Wraps a NodeJS continuation passing function and returns an equivalent | ||
* version that returns a promise. | ||
* | ||
* Q.nbind(FS.readFile, FS)(__filename) | ||
* .then(console.log) | ||
* .done() | ||
* | ||
*/ | ||
exports.nbind = deprecate(nbind, "nbind", "nfbind"); | ||
function nbind(callback /* thisp, ...args*/) { | ||
if (arguments.length > 1) { | ||
var thisp = arguments[1]; | ||
var args = array_slice(arguments, 2); | ||
var originalCallback = callback; | ||
callback = function () { | ||
var combinedArgs = args.concat(array_slice(arguments)); | ||
return originalCallback.apply(thisp, combinedArgs); | ||
}; | ||
} | ||
return function () { | ||
var deferred = defer(); | ||
var args = array_slice(arguments); | ||
// add a continuation that resolves the promise | ||
args.push(deferred.makeNodeResolver()); | ||
// trap exceptions thrown by the callback | ||
fapply(callback, args) | ||
.fail(deferred.reject); | ||
fapply(bound, nodeArgs).fail(deferred.reject); | ||
return deferred.promise; | ||
@@ -1593,5 +1507,5 @@ }; | ||
*/ | ||
exports.npost = npost; | ||
Q.npost = npost; | ||
function npost(object, name, args) { | ||
var nodeArgs = array_slice(args); | ||
var nodeArgs = array_slice(args || []); | ||
var deferred = defer(); | ||
@@ -1614,8 +1528,8 @@ nodeArgs.push(deferred.makeNodeResolver()); | ||
*/ | ||
exports.ninvoke = ninvoke; | ||
function ninvoke(object, name /*, ...args*/) { | ||
Q.nsend = nsend; | ||
Q.ninvoke = Q.nsend; // synonyms | ||
function nsend(object, name /*, ...args*/) { | ||
var nodeArgs = array_slice(arguments, 2); | ||
var deferred = defer(); | ||
nodeArgs.push(deferred.makeNodeResolver()); | ||
post(object, name, nodeArgs).fail(deferred.reject); | ||
@@ -1625,4 +1539,3 @@ return deferred.promise; | ||
exports.nend = deprecate(nodeify, "nend", "nodeify"); // XXX deprecated, use nodeify | ||
exports.nodeify = nodeify; | ||
Q.nodeify = nodeify; | ||
function nodeify(promise, nodeback) { | ||
@@ -1647,2 +1560,4 @@ if (nodeback) { | ||
return Q; | ||
}); |
@@ -20,11 +20,11 @@ | ||
ends.promise = ends.promise.get("tail"); | ||
return result.fail(function (reason) { | ||
closed.resolve(); | ||
throw reason; | ||
return result.fail(function (error) { | ||
closed.resolve(error); | ||
throw error; | ||
}); | ||
}, | ||
closed: closed.promise, | ||
close: function (reason) { | ||
reason = reason || new Error("Can't get value from closed queue"); | ||
var end = {head: Q.reject(reason)}; | ||
close: function (error) { | ||
error = error || new Error("Can't get value from closed queue"); | ||
var end = {head: Q.reject(error)}; | ||
end.tail = end; | ||
@@ -31,0 +31,0 @@ ends.resolve(end); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
12
135618
18
2844
6