Sha256: 4888e4fe1fd7d1e1eeb7552e5158bec0f7b7ec538180780941289a55aa1172b5

Contents?: true

Size: 1.52 KB

Versions: 47

Compression:

Stored size: 1.52 KB

Contents

"use strict";
var util = require("./util");
var maybeWrapAsError = util.maybeWrapAsError;
var errors = require("./errors");
var OperationalError = errors.OperationalError;
var es5 = require("./es5");

function isUntypedError(obj) {
    return obj instanceof Error &&
        es5.getPrototypeOf(obj) === Error.prototype;
}

var rErrorKey = /^(?:name|message|stack|cause)$/;
function wrapAsOperationalError(obj) {
    var ret;
    if (isUntypedError(obj)) {
        ret = new OperationalError(obj);
        ret.name = obj.name;
        ret.message = obj.message;
        ret.stack = obj.stack;
        var keys = es5.keys(obj);
        for (var i = 0; i < keys.length; ++i) {
            var key = keys[i];
            if (!rErrorKey.test(key)) {
                ret[key] = obj[key];
            }
        }
        return ret;
    }
    util.markAsOriginatingFromRejection(obj);
    return obj;
}

function nodebackForPromise(promise, multiArgs) {
    return function(err, value) {
        if (promise === null) return;
        if (err) {
            var wrapped = wrapAsOperationalError(maybeWrapAsError(err));
            promise._attachExtraTrace(wrapped);
            promise._reject(wrapped);
        } else if (!multiArgs) {
            promise._fulfill(value);
        } else {
            var $_len = arguments.length;var args = new Array(Math.max($_len - 1, 0)); for(var $_i = 1; $_i < $_len; ++$_i) {args[$_i - 1] = arguments[$_i];};
            promise._fulfill(args);
        }
        promise = null;
    };
}

module.exports = nodebackForPromise;

Version data entries

47 entries across 43 versions & 15 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/bluebird/js/release/nodeback.js
disco_app-0.18.0 test/dummy/node_modules/bluebird/js/release/nodeback.js
disco_app-0.18.2 test/dummy/node_modules/bluebird/js/release/nodeback.js
disco_app-0.16.1 test/dummy/node_modules/bluebird/js/release/nodeback.js
disco_app-0.15.2 test/dummy/node_modules/bluebird/js/release/nodeback.js
disco_app-0.18.4 test/dummy/node_modules/bluebird/js/release/nodeback.js
disco_app-0.18.1 test/dummy/node_modules/bluebird/js/release/nodeback.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/bluebird/js/release/nodeback.js
disco_app-0.14.0 test/dummy/node_modules/bluebird/js/release/nodeback.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/bluebird/js/release/nodeback.js
tang-0.2.1 spec/tang_app/node_modules/bluebird/js/release/nodeback.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/bluebird/js/release/nodeback.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/bluebird/js/release/nodeback.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/bluebird/js/release/nodeback.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/bluebird/js/release/nodeback.js
tang-0.2.0 spec/tang_app/node_modules/bluebird/js/release/nodeback.js
tang-0.1.0 spec/tang_app/node_modules/bluebird/js/release/nodeback.js
tang-0.0.9 spec/tang_app/node_modules/bluebird/js/release/nodeback.js
enju_library-0.3.8 spec/dummy/node_modules/bluebird/js/release/nodeback.js
ilog-0.4.1 node_modules/consolidate/node_modules/bluebird/js/release/nodeback.js