Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

q

Package Overview
Dependencies
Maintainers
1
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

q - npm Package Compare versions

Comparing version 0.8.10 to 0.8.11

queue.js

2

package.json
{
"name": "q",
"version": "0.8.10",
"version": "0.8.11",
"description": "A library for promises (CommonJS/Promises/A,B,D)",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/kriskowal/q",

299

q.js

@@ -27,29 +27,2 @@ // vim:ts=4:sts=4:sw=4:

*
* With formatStackTrace and formatSourcePosition functions
* Copyright 2006-2008 the V8 project authors. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

@@ -264,129 +237,51 @@

function formatStackTrace(error, frames) {
var lines = [];
try {
lines.push(error.toString());
} catch (e) {
try {
lines.push("<error: " + e + ">");
} catch (ee) {
lines.push("<error>");
}
}
for (var i = 0; i < frames.length; i++) {
var frame = frames[i];
var line;
var STACK_JUMP_SEPARATOR = "From previous event:";
// <Inserted by @domenic>
if (typeof frame === "string") {
lines.push(frame);
// </Inserted by @domenic>
} else {
try {
line = formatSourcePosition(frame);
} catch (e) {
try {
line = "<error: " + e + ">";
} catch (ee) {
// Any code that reaches this point is seriously nasty!
line = "<error>";
}
}
lines.push(" at " + line);
}
function makeStackTraceLong(error, promise) {
// If possible (that is, if in V8), transform the error stack
// trace by removing Node and Q cruft, then concatenating with
// the stack trace of the promise we are ``done``ing. See #57.
if (promise.stack &&
typeof error === "object" &&
error !== null &&
error.stack &&
error.stack.indexOf(STACK_JUMP_SEPARATOR) === -1
) {
error.stack = filterStackString(error.stack) +
"\n" + STACK_JUMP_SEPARATOR + "\n" +
filterStackString(promise.stack);
}
return lines.join("\n");
}
function formatSourcePosition(frame) {
var fileLocation = "";
if (frame.isNative()) {
fileLocation = "native";
} else if (frame.isEval()) {
fileLocation = "eval at " + frame.getEvalOrigin();
} else {
var fileName = frame.getFileName();
if (fileName) {
fileLocation += fileName;
var lineNumber = frame.getLineNumber();
if (lineNumber !== null) {
fileLocation += ":" + lineNumber;
var columnNumber = frame.getColumnNumber();
if (columnNumber) {
fileLocation += ":" + columnNumber;
}
}
function filterStackString(stackString) {
var lines = stackString.split("\n");
var desiredLines = [];
for (var i = 0; i < lines.length; ++i) {
var line = lines[i];
if (!isInternalFrame(line) && !isNodeFrame(line)) {
desiredLines.push(line);
}
}
if (!fileLocation) {
fileLocation = "unknown source";
}
var line = "";
var functionName = frame.getFunction().name;
var addPrefix = true;
var isConstructor = frame.isConstructor();
var isMethodCall = !(frame.isToplevel() || isConstructor);
if (isMethodCall) {
var methodName = frame.getMethodName();
line += frame.getTypeName() + ".";
if (functionName) {
line += functionName;
if (methodName && (methodName !== functionName)) {
line += " [as " + methodName + "]";
}
} else {
line += methodName || "<anonymous>";
}
} else if (isConstructor) {
line += "new " + (functionName || "<anonymous>");
} else if (functionName) {
line += functionName;
} else {
line += fileLocation;
addPrefix = false;
}
if (addPrefix) {
line += " (" + fileLocation + ")";
}
return line;
return desiredLines.join("\n");
}
function isInternalFrame(fileName, frame) {
if (fileName !== qFileName) {
return false;
}
var line = frame.getLineNumber();
return line >= qStartingLine && line <= qEndingLine;
function isNodeFrame(stackLine) {
return stackLine.indexOf("(module.js:") !== -1 ||
stackLine.indexOf("(node.js:") !== -1;
}
/*
* Retrieves an array of structured stack frames parsed from the ``stack``
* property of a given object.
*
* @param objectWithStack {Object} an object with a ``stack`` property: usually
* an error or promise.
*
* @returns an array of stack frame objects. For more information, see
* [V8's JavaScript stack trace API documentation](http://code.google.com/p/v8/wiki/JavaScriptStackTraceApi).
*/
function getStackFrames(objectWithStack) {
var oldPrepareStackTrace = Error.prepareStackTrace;
function isInternalFrame(stackLine) {
var pieces = /at .+ \((.*):(\d+):\d+\)/.exec(stackLine);
Error.prepareStackTrace = function (error, frames) {
// Filter out frames from the innards of Node and Q.
return frames.filter(function (frame) {
var fileName = frame.getFileName();
return (
fileName !== "module.js" &&
fileName !== "node.js" &&
!isInternalFrame(fileName, frame)
);
});
};
if (!pieces) {
return false;
}
var stack = objectWithStack.stack;
var fileName = pieces[1];
var lineNumber = pieces[2];
Error.prepareStackTrace = oldPrepareStackTrace;
return stack;
return fileName === qFileName &&
lineNumber >= qStartingLine &&
lineNumber <= qEndingLine;
}

@@ -481,2 +376,7 @@

Error.captureStackTrace(promise, defer);
// Reify the stack into a string by using the accessor; this prevents
// memory leaks as per GH-111. At the same time, cut off the first line;
// it's always just "[object Promise]\n", as per the `toString`.
promise.stack = promise.stack.substring(promise.stack.indexOf("\n") + 1);
}

@@ -630,2 +530,3 @@

"catch", "finally", "fail", "fin", "progress", "end", "done",
"nfcall", "nfapply", "nfbind",
"ncall", "napply", "nbind",

@@ -667,9 +568,3 @@ "npost", "ninvoke",

function valueOf(value) {
// if !Object.isObject(value)
// generates a known JSHint "constructor invocation without new" warning
// supposed to be fixed, but isn't? https://github.com/jshint/jshint/issues/392
/*jshint newcap: false */
if (Object(value) !== value) {
return value;
} else if (isPromise(value)) {
if (isPromise(value)) {
return value.valueOf();

@@ -939,7 +834,11 @@ }

function _rejected(exception) {
try {
return rejected ? rejected(exception) : reject(exception);
} catch (newException) {
return reject(newException);
if (rejected) {
makeStackTraceLong(exception, resolvedValue);
try {
return rejected(exception);
} catch (newException) {
return reject(newException);
}
}
return reject(exception);
}

@@ -1421,24 +1320,4 @@

nextTick(function () {
// If possible (that is, if in V8), transform the error stack
// trace by removing Node and Q cruft, then concatenating with
// the stack trace of the promise we are ``done``ing. See #57.
var errorStackFrames;
if (
Error.captureStackTrace &&
typeof error === "object" &&
(errorStackFrames = getStackFrames(error))
) {
var promiseStackFrames = getStackFrames(promise);
makeStackTraceLong(error, promise);
// Check to make sure the stack trace hasn't already been
// rendered (possibly by us).
if (typeof errorStackFrames !== "string") {
var combinedStackFrames = errorStackFrames.concat(
"From previous event:",
promiseStackFrames
);
error.stack = formatStackTrace(error, combinedStackFrames);
}
}
if (exports.onerror) {

@@ -1478,3 +1357,7 @@ exports.onerror(error);

deferred.resolve(value);
}, deferred.reject);
}, function (exception) {
clearTimeout(timeoutId);
deferred.reject(exception);
});
return deferred.promise;

@@ -1505,2 +1388,64 @@ }

/**
* Passes a continuation to a Node function, which is called with the given
* arguments provided as an array, and returns a promise.
*
* var readFile = require("fs").readFile;
* Q.nfapply(readFile, [__filename])
* .then(function (content) {
* })
*
*/
exports.nfapply = nfapply;
function nfapply(callback, args) {
var nodeArgs = array_slice(args);
var deferred = defer();
nodeArgs.push(deferred.makeNodeResolver());
fapply(callback, nodeArgs).fail(deferred.reject);
return deferred.promise;
}
/**
* Passes a continuation to a Node function, which is called with the given
* arguments provided individually, and returns a promise.
*
* var readFile = require("fs").readFile;
* Q.nfcall(readFile, __filename)
* .then(function (content) {
* })
*
*/
exports.nfcall = nfcall;
function nfcall(callback/*, ...args */) {
var nodeArgs = array_slice(arguments, 1);
var deferred = defer();
nodeArgs.push(deferred.makeNodeResolver());
fapply(callback, nodeArgs).fail(deferred.reject);
return deferred.promise;
}
/**
* Wraps a NodeJS continuation passing function and returns an equivalent
* version that returns a promise.
*
* Q.nfbind(FS.readFile, __filename)("utf-8")
* .then(console.log)
* .done()
*
*/
exports.nfbind = nfbind;
function nfbind(callback/*, ...args */) {
var baseArgs = array_slice(arguments, 1);
return function () {
var nodeArgs = baseArgs.concat(array_slice(arguments));
var deferred = defer();
nodeArgs.push(deferred.makeNodeResolver());
fapply(callback, nodeArgs).fail(deferred.reject);
return deferred.promise;
};
}
/**
* Passes a continuation to a Node function, which is called with a given

@@ -1515,3 +1460,3 @@ * `this` value and arguments provided as an array, and returns a promise.

*/
exports.napply = napply;
exports.napply = deprecate(napply, "napply", "npost");
function napply(callback, thisp, args) {

@@ -1531,3 +1476,3 @@ return nbind(callback, thisp).apply(void 0, args);

*/
exports.ncall = ncall;
exports.ncall = deprecate(ncall, "ncall", "ninvoke");
function ncall(callback, thisp /*, ...args*/) {

@@ -1547,3 +1492,3 @@ var args = array_slice(arguments, 2);

*/
exports.nbind = nbind;
exports.nbind = deprecate(nbind, "nbind", "nfbind");
function nbind(callback /* thisp, ...args*/) {

@@ -1550,0 +1495,0 @@ if (arguments.length > 1) {

@@ -418,3 +418,3 @@ [![Build Status](https://secure.travis-ci.org/kriskowal/q.png)](http://travis-ci.org/kriskowal/q)

If you have to interface with asynchronous functions that are callback-based
instead of promise-based, Q provides a few shortcuts (like ``Q.ncall`` and
instead of promise-based, Q provides a few shortcuts (like ``Q.nfcall`` and
friends). But much of the time, the solution will be to use *deferreds*.

@@ -586,18 +586,18 @@

And there are ``Q.ncall`` and ``Q.ninvoke`` for even shorter
And there are ``Q.nfcall`` and ``Q.ninvoke`` for even shorter
expression.
```javascript
return Q.ncall(FS.readFile, FS, "foo.txt", "utf-8");
return Q.nfcall(FS.readFile, "foo.txt", "utf-8");
```
```javascript
return Q.ninvoke(FS, 'readFile', "foo.txt", "utf-8");
return Q.ninvoke(FS, "readFile", "foo.txt", "utf-8");
```
There is also a ``Q.nbind`` function that that creates a reusable
There is also a ``Q.nfbind`` function that that creates a reusable
wrapper.
```javascript
var readFile = Q.nbind(FS.readFile, FS)
var readFile = Q.nfbind(FS.readFile);
return readFile("foo.txt", "utf-8");

@@ -604,0 +604,0 @@ ```

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc