|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"use strict"; |
|
var global = require("./global.js"); |
|
var ASSERT = require("./assert.js"); |
|
var es5 = require("./es5.js"); |
|
var haveGetters = (function(){ |
|
try { |
|
var o = {}; |
|
es5.defineProperty(o, "f", { |
|
get: function () { |
|
return 3; |
|
} |
|
}); |
|
return o.f === 3; |
|
} |
|
catch (e) { |
|
return false; |
|
} |
|
|
|
})(); |
|
|
|
var canEvaluate = (function() { |
|
if (typeof window !== "undefined" && window !== null && |
|
typeof window.document !== "undefined" && |
|
typeof navigator !== "undefined" && navigator !== null && |
|
typeof navigator.appName === "string" && |
|
window === global) { |
|
return false; |
|
} |
|
return true; |
|
})(); |
|
|
|
function deprecated(msg) { |
|
if (typeof console !== "undefined" && console !== null && |
|
typeof console.warn === "function") { |
|
console.warn("Bluebird: " + msg); |
|
} |
|
} |
|
|
|
var errorObj = {e: {}}; |
|
function tryCatch1(fn, receiver, arg) { |
|
try { |
|
return fn.call(receiver, arg); |
|
} |
|
catch (e) { |
|
errorObj.e = e; |
|
return errorObj; |
|
} |
|
} |
|
|
|
function tryCatch2(fn, receiver, arg, arg2) { |
|
try { |
|
return fn.call(receiver, arg, arg2); |
|
} |
|
catch (e) { |
|
errorObj.e = e; |
|
return errorObj; |
|
} |
|
} |
|
|
|
function tryCatchApply(fn, args, receiver) { |
|
try { |
|
return fn.apply(receiver, args); |
|
} |
|
catch (e) { |
|
errorObj.e = e; |
|
return errorObj; |
|
} |
|
} |
|
|
|
var inherits = function(Child, Parent) { |
|
var hasProp = {}.hasOwnProperty; |
|
|
|
function T() { |
|
this.constructor = Child; |
|
this.constructor$ = Parent; |
|
for (var propertyName in Parent.prototype) { |
|
if (hasProp.call(Parent.prototype, propertyName) && |
|
propertyName.charAt(propertyName.length-1) !== "$" |
|
) { |
|
this[propertyName + "$"] = Parent.prototype[propertyName]; |
|
} |
|
} |
|
} |
|
T.prototype = Parent.prototype; |
|
Child.prototype = new T(); |
|
return Child.prototype; |
|
}; |
|
|
|
function asString(val) { |
|
return typeof val === "string" ? val : ("" + val); |
|
} |
|
|
|
function isPrimitive(val) { |
|
return val == null || val === true || val === false || |
|
typeof val === "string" || typeof val === "number"; |
|
|
|
} |
|
|
|
function isObject(value) { |
|
return !isPrimitive(value); |
|
} |
|
|
|
function maybeWrapAsError(maybeError) { |
|
if (!isPrimitive(maybeError)) return maybeError; |
|
|
|
return new Error(asString(maybeError)); |
|
} |
|
|
|
function withAppended(target, appendee) { |
|
var len = target.length; |
|
var ret = new Array(len + 1); |
|
var i; |
|
for (i = 0; i < len; ++i) { |
|
ret[i] = target[i]; |
|
} |
|
ret[i] = appendee; |
|
return ret; |
|
} |
|
|
|
|
|
function notEnumerableProp(obj, name, value) { |
|
var descriptor = { |
|
value: value, |
|
configurable: true, |
|
enumerable: false, |
|
writable: true |
|
}; |
|
es5.defineProperty(obj, name, descriptor); |
|
return obj; |
|
} |
|
|
|
|
|
var wrapsPrimitiveReceiver = (function() { |
|
return this !== "string"; |
|
}).call("string"); |
|
|
|
function thrower(r) { |
|
throw r; |
|
} |
|
|
|
|
|
var ret = { |
|
thrower: thrower, |
|
isArray: es5.isArray, |
|
haveGetters: haveGetters, |
|
notEnumerableProp: notEnumerableProp, |
|
isPrimitive: isPrimitive, |
|
isObject: isObject, |
|
canEvaluate: canEvaluate, |
|
deprecated: deprecated, |
|
errorObj: errorObj, |
|
tryCatch1: tryCatch1, |
|
tryCatch2: tryCatch2, |
|
tryCatchApply: tryCatchApply, |
|
inherits: inherits, |
|
withAppended: withAppended, |
|
asString: asString, |
|
maybeWrapAsError: maybeWrapAsError, |
|
wrapsPrimitiveReceiver: wrapsPrimitiveReceiver |
|
}; |
|
|
|
module.exports = ret; |
|
|