react / wstein / node_modules / jest-cli / node_modules / jsdom / node_modules / request / node_modules / har-validator / node_modules / bluebird / js / main / debuggability.js
81160 views"use strict";1module.exports = function(Promise, CapturedTrace) {2var async = require("./async.js");3var Warning = require("./errors.js").Warning;4var util = require("./util.js");5var canAttachTrace = util.canAttachTrace;6var unhandledRejectionHandled;7var possiblyUnhandledRejection;8var debugging = false || (util.isNode &&9(!!process.env["BLUEBIRD_DEBUG"] ||10process.env["NODE_ENV"] === "development"));1112if (debugging) {13async.disableTrampolineIfNecessary();14}1516Promise.prototype._ensurePossibleRejectionHandled = function () {17this._setRejectionIsUnhandled();18async.invokeLater(this._notifyUnhandledRejection, this, undefined);19};2021Promise.prototype._notifyUnhandledRejectionIsHandled = function () {22CapturedTrace.fireRejectionEvent("rejectionHandled",23unhandledRejectionHandled, undefined, this);24};2526Promise.prototype._notifyUnhandledRejection = function () {27if (this._isRejectionUnhandled()) {28var reason = this._getCarriedStackTrace() || this._settledValue;29this._setUnhandledRejectionIsNotified();30CapturedTrace.fireRejectionEvent("unhandledRejection",31possiblyUnhandledRejection, reason, this);32}33};3435Promise.prototype._setUnhandledRejectionIsNotified = function () {36this._bitField = this._bitField | 524288;37};3839Promise.prototype._unsetUnhandledRejectionIsNotified = function () {40this._bitField = this._bitField & (~524288);41};4243Promise.prototype._isUnhandledRejectionNotified = function () {44return (this._bitField & 524288) > 0;45};4647Promise.prototype._setRejectionIsUnhandled = function () {48this._bitField = this._bitField | 2097152;49};5051Promise.prototype._unsetRejectionIsUnhandled = function () {52this._bitField = this._bitField & (~2097152);53if (this._isUnhandledRejectionNotified()) {54this._unsetUnhandledRejectionIsNotified();55this._notifyUnhandledRejectionIsHandled();56}57};5859Promise.prototype._isRejectionUnhandled = function () {60return (this._bitField & 2097152) > 0;61};6263Promise.prototype._setCarriedStackTrace = function (capturedTrace) {64this._bitField = this._bitField | 1048576;65this._fulfillmentHandler0 = capturedTrace;66};6768Promise.prototype._isCarryingStackTrace = function () {69return (this._bitField & 1048576) > 0;70};7172Promise.prototype._getCarriedStackTrace = function () {73return this._isCarryingStackTrace()74? this._fulfillmentHandler075: undefined;76};7778Promise.prototype._captureStackTrace = function () {79if (debugging) {80this._trace = new CapturedTrace(this._peekContext());81}82return this;83};8485Promise.prototype._attachExtraTrace = function (error, ignoreSelf) {86if (debugging && canAttachTrace(error)) {87var trace = this._trace;88if (trace !== undefined) {89if (ignoreSelf) trace = trace._parent;90}91if (trace !== undefined) {92trace.attachExtraTrace(error);93} else if (!error.__stackCleaned__) {94var parsed = CapturedTrace.parseStackAndMessage(error);95util.notEnumerableProp(error, "stack",96parsed.message + "\n" + parsed.stack.join("\n"));97util.notEnumerableProp(error, "__stackCleaned__", true);98}99}100};101102Promise.prototype._warn = function(message) {103var warning = new Warning(message);104var ctx = this._peekContext();105if (ctx) {106ctx.attachExtraTrace(warning);107} else {108var parsed = CapturedTrace.parseStackAndMessage(warning);109warning.stack = parsed.message + "\n" + parsed.stack.join("\n");110}111CapturedTrace.formatAndLogError(warning, "");112};113114Promise.onPossiblyUnhandledRejection = function (fn) {115possiblyUnhandledRejection = typeof fn === "function" ? fn : undefined;116};117118Promise.onUnhandledRejectionHandled = function (fn) {119unhandledRejectionHandled = typeof fn === "function" ? fn : undefined;120};121122Promise.longStackTraces = function () {123if (async.haveItemsQueued() &&124debugging === false125) {126throw new Error("cannot enable long stack traces after promises have been created\u000a\u000a See http://goo.gl/DT1qyG\u000a");127}128debugging = CapturedTrace.isSupported();129if (debugging) {130async.disableTrampolineIfNecessary();131}132};133134Promise.hasLongStackTraces = function () {135return debugging && CapturedTrace.isSupported();136};137138if (!CapturedTrace.isSupported()) {139Promise.longStackTraces = function(){};140debugging = false;141}142143return function() {144return debugging;145};146};147148149