diff --git a/src/captured_trace.js b/src/captured_trace.js index 102310a4b..ebfbe85c4 100644 --- a/src/captured_trace.js +++ b/src/captured_trace.js @@ -2,7 +2,7 @@ module.exports = function() { var async = require("./async.js"); var ASSERT = require("./assert.js"); -var inherits = require("./util.js").inherits; +var util = require("./util.js"); var bluebirdFramePattern = /[\\\/]bluebird[\\\/]js[\\\/](main|debug|zalgo|instrumented)/; var stackFramePattern = null; @@ -18,7 +18,7 @@ function CapturedTrace(parent) { // there must be cycles if (length > 32) this.uncycle(); } -inherits(CapturedTrace, Error); +util.inherits(CapturedTrace, Error); CapturedTrace.prototype.uncycle = function() { var length = this._length; @@ -435,9 +435,7 @@ var captureStackTrace = (function stackDetection() { var fireDomEvent; var fireGlobalEvent = (function() { - if (typeof process !== "undefined" && - typeof process.version === "string" && - typeof window === "undefined") { + if (util.isNode) { return function(name, reason, promise) { if (name === REJECTION_HANDLED_EVENT) { return process.emit(name, promise); diff --git a/src/debuggability.js b/src/debuggability.js index 429fe4e27..ea34a1544 100644 --- a/src/debuggability.js +++ b/src/debuggability.js @@ -7,13 +7,9 @@ var ASSERT = require("./assert.js"); var canAttachTrace = util.canAttachTrace; var unhandledRejectionHandled; var possiblyUnhandledRejection; -var debugging = __DEBUG__ || !!( - typeof process !== "undefined" && - typeof process.execPath === "string" && - typeof process.env === "object" && - (process.env["BLUEBIRD_DEBUG"] || - process.env["NODE_ENV"] === "development") -); +var debugging = __DEBUG__ || (util.isNode && + (!!process.env["BLUEBIRD_DEBUG"] || + process.env["NODE_ENV"] === "development")); Promise.prototype._ensurePossibleRejectionHandled = function () { this._setRejectionIsUnhandled(); diff --git a/src/promise.js b/src/promise.js index 471e67039..80c6eddbb 100644 --- a/src/promise.js +++ b/src/promise.js @@ -37,7 +37,6 @@ var PromiseResolver = require("./promise_resolver.js"); var nodebackForPromise = PromiseResolver._nodebackForPromise; var errorObj = util.errorObj; var tryCatch = util.tryCatch; - function Promise(resolver) { if (typeof resolver !== "function") { throw new TypeError(CONSTRUCT_ERROR_ARG); diff --git a/src/schedule.js b/src/schedule.js index 0322d9ab3..54d294d36 100644 --- a/src/schedule.js +++ b/src/schedule.js @@ -1,6 +1,6 @@ "use strict"; var schedule; -if (typeof process === "object" && typeof process.version === "string") { +if (require("./util.js").isNode) { var version = process.version.split(".").map(Number); schedule = (version[0] === 0 && version[1] > 10) || (version[0] > 0) ? global.setImmediate : process.nextTick; diff --git a/src/util.js b/src/util.js index 608c37d6d..e824feb42 100644 --- a/src/util.js +++ b/src/util.js @@ -269,7 +269,9 @@ var ret = { ensureErrorObject: ensureErrorObject, originatesFromRejection: originatesFromRejection, markAsOriginatingFromRejection: markAsOriginatingFromRejection, - classString: classString + classString: classString, + isNode: typeof process !== "undefined" && + classString(process).toLowerCase() === "[object process]" }; try {throw new Error(); } catch (e) {ret.lastLineError = e;} module.exports = ret;