react / wstein / node_modules / jest-cli / node_modules / jsdom / node_modules / request / node_modules / har-validator / node_modules / bluebird / js / main / util.js
81160 views"use strict";1var es5 = require("./es5.js");2var canEvaluate = typeof navigator == "undefined";3var haveGetters = (function(){4try {5var o = {};6es5.defineProperty(o, "f", {7get: function () {8return 3;9}10});11return o.f === 3;12}13catch (e) {14return false;15}1617})();1819var errorObj = {e: {}};20var tryCatchTarget;21function tryCatcher() {22try {23return tryCatchTarget.apply(this, arguments);24} catch (e) {25errorObj.e = e;26return errorObj;27}28}29function tryCatch(fn) {30tryCatchTarget = fn;31return tryCatcher;32}3334var inherits = function(Child, Parent) {35var hasProp = {}.hasOwnProperty;3637function T() {38this.constructor = Child;39this.constructor$ = Parent;40for (var propertyName in Parent.prototype) {41if (hasProp.call(Parent.prototype, propertyName) &&42propertyName.charAt(propertyName.length-1) !== "$"43) {44this[propertyName + "$"] = Parent.prototype[propertyName];45}46}47}48T.prototype = Parent.prototype;49Child.prototype = new T();50return Child.prototype;51};525354function isPrimitive(val) {55return val == null || val === true || val === false ||56typeof val === "string" || typeof val === "number";5758}5960function isObject(value) {61return !isPrimitive(value);62}6364function maybeWrapAsError(maybeError) {65if (!isPrimitive(maybeError)) return maybeError;6667return new Error(safeToString(maybeError));68}6970function withAppended(target, appendee) {71var len = target.length;72var ret = new Array(len + 1);73var i;74for (i = 0; i < len; ++i) {75ret[i] = target[i];76}77ret[i] = appendee;78return ret;79}8081function getDataPropertyOrDefault(obj, key, defaultValue) {82if (es5.isES5) {83var desc = Object.getOwnPropertyDescriptor(obj, key);84if (desc != null) {85return desc.get == null && desc.set == null86? desc.value87: defaultValue;88}89} else {90return {}.hasOwnProperty.call(obj, key) ? obj[key] : undefined;91}92}9394function notEnumerableProp(obj, name, value) {95if (isPrimitive(obj)) return obj;96var descriptor = {97value: value,98configurable: true,99enumerable: false,100writable: true101};102es5.defineProperty(obj, name, descriptor);103return obj;104}105106107var wrapsPrimitiveReceiver = (function() {108return this !== "string";109}).call("string");110111function thrower(r) {112throw r;113}114115var inheritedDataKeys = (function() {116if (es5.isES5) {117var oProto = Object.prototype;118var getKeys = Object.getOwnPropertyNames;119return function(obj) {120var ret = [];121var visitedKeys = Object.create(null);122while (obj != null && obj !== oProto) {123var keys;124try {125keys = getKeys(obj);126} catch (e) {127return ret;128}129for (var i = 0; i < keys.length; ++i) {130var key = keys[i];131if (visitedKeys[key]) continue;132visitedKeys[key] = true;133var desc = Object.getOwnPropertyDescriptor(obj, key);134if (desc != null && desc.get == null && desc.set == null) {135ret.push(key);136}137}138obj = es5.getPrototypeOf(obj);139}140return ret;141};142} else {143return function(obj) {144var ret = [];145/*jshint forin:false */146for (var key in obj) {147ret.push(key);148}149return ret;150};151}152153})();154155function isClass(fn) {156try {157if (typeof fn === "function") {158var keys = es5.names(fn.prototype);159if (es5.isES5) return keys.length > 1;160return keys.length > 0 &&161!(keys.length === 1 && keys[0] === "constructor");162}163return false;164} catch (e) {165return false;166}167}168169function toFastProperties(obj) {170/*jshint -W027,-W055,-W031*/171function f() {}172f.prototype = obj;173var l = 8;174while (l--) new f();175return obj;176eval(obj);177}178179var rident = /^[a-z$_][a-z$_0-9]*$/i;180function isIdentifier(str) {181return rident.test(str);182}183184function filledRange(count, prefix, suffix) {185var ret = new Array(count);186for(var i = 0; i < count; ++i) {187ret[i] = prefix + i + suffix;188}189return ret;190}191192function safeToString(obj) {193try {194return obj + "";195} catch (e) {196return "[no string representation]";197}198}199200function markAsOriginatingFromRejection(e) {201try {202notEnumerableProp(e, "isOperational", true);203}204catch(ignore) {}205}206207function originatesFromRejection(e) {208if (e == null) return false;209return ((e instanceof Error["__BluebirdErrorTypes__"].OperationalError) ||210e["isOperational"] === true);211}212213function canAttachTrace(obj) {214return obj instanceof Error && es5.propertyIsWritable(obj, "stack");215}216217var ensureErrorObject = (function() {218if (!("stack" in new Error())) {219return function(value) {220if (canAttachTrace(value)) return value;221try {throw new Error(safeToString(value));}222catch(err) {return err;}223};224} else {225return function(value) {226if (canAttachTrace(value)) return value;227return new Error(safeToString(value));228};229}230})();231232function classString(obj) {233return {}.toString.call(obj);234}235236function copyDescriptors(from, to, filter) {237var keys = es5.names(from);238for (var i = 0; i < keys.length; ++i) {239var key = keys[i];240if (filter(key)) {241es5.defineProperty(to, key, es5.getDescriptor(from, key));242}243}244}245246var ret = {247isClass: isClass,248isIdentifier: isIdentifier,249inheritedDataKeys: inheritedDataKeys,250getDataPropertyOrDefault: getDataPropertyOrDefault,251thrower: thrower,252isArray: es5.isArray,253haveGetters: haveGetters,254notEnumerableProp: notEnumerableProp,255isPrimitive: isPrimitive,256isObject: isObject,257canEvaluate: canEvaluate,258errorObj: errorObj,259tryCatch: tryCatch,260inherits: inherits,261withAppended: withAppended,262maybeWrapAsError: maybeWrapAsError,263wrapsPrimitiveReceiver: wrapsPrimitiveReceiver,264toFastProperties: toFastProperties,265filledRange: filledRange,266toString: safeToString,267canAttachTrace: canAttachTrace,268ensureErrorObject: ensureErrorObject,269originatesFromRejection: originatesFromRejection,270markAsOriginatingFromRejection: markAsOriginatingFromRejection,271classString: classString,272copyDescriptors: copyDescriptors,273hasDevTools: typeof chrome !== "undefined" && chrome &&274typeof chrome.loadTimes === "function",275isNode: typeof process !== "undefined" &&276classString(process).toLowerCase() === "[object process]"277};278ret.isRecentNode = ret.isNode && (function() {279var version = process.versions.node.split(".").map(Number);280return (version[0] === 0 && version[1] > 10) || (version[0] > 0);281})();282try {throw new Error(); } catch (e) {ret.lastLineError = e;}283module.exports = ret;284285286