2 var es5 = require("./es5.js");
3 var canEvaluate = typeof navigator == "undefined";
4 var haveGetters = (function(){
7 es5.defineProperty(o, "f", {
20 var errorObj = {e: {}};
22 function tryCatcher() {
24 var target = tryCatchTarget;
25 tryCatchTarget = null;
26 return target.apply(this, arguments);
32 function tryCatch(fn) {
37 var inherits = function(Child, Parent) {
38 var hasProp = {}.hasOwnProperty;
41 this.constructor = Child;
42 this.constructor$ = Parent;
43 for (var propertyName in Parent.prototype) {
44 if (hasProp.call(Parent.prototype, propertyName) &&
45 propertyName.charAt(propertyName.length-1) !== "$"
47 this[propertyName + "$"] = Parent.prototype[propertyName];
51 T.prototype = Parent.prototype;
52 Child.prototype = new T();
53 return Child.prototype;
57 function isPrimitive(val) {
58 return val == null || val === true || val === false ||
59 typeof val === "string" || typeof val === "number";
63 function isObject(value) {
64 return !isPrimitive(value);
67 function maybeWrapAsError(maybeError) {
68 if (!isPrimitive(maybeError)) return maybeError;
70 return new Error(safeToString(maybeError));
73 function withAppended(target, appendee) {
74 var len = target.length;
75 var ret = new Array(len + 1);
77 for (i = 0; i < len; ++i) {
84 function getDataPropertyOrDefault(obj, key, defaultValue) {
86 var desc = Object.getOwnPropertyDescriptor(obj, key);
89 return desc.get == null && desc.set == null
94 return {}.hasOwnProperty.call(obj, key) ? obj[key] : undefined;
98 function notEnumerableProp(obj, name, value) {
99 if (isPrimitive(obj)) return obj;
106 es5.defineProperty(obj, name, descriptor);
110 function thrower(r) {
114 var inheritedDataKeys = (function() {
115 var excludedPrototypes = [
121 var isExcludedProto = function(val) {
122 for (var i = 0; i < excludedPrototypes.length; ++i) {
123 if (excludedPrototypes[i] === val) {
131 var getKeys = Object.getOwnPropertyNames;
132 return function(obj) {
134 var visitedKeys = Object.create(null);
135 while (obj != null && !isExcludedProto(obj)) {
142 for (var i = 0; i < keys.length; ++i) {
144 if (visitedKeys[key]) continue;
145 visitedKeys[key] = true;
146 var desc = Object.getOwnPropertyDescriptor(obj, key);
147 if (desc != null && desc.get == null && desc.set == null) {
151 obj = es5.getPrototypeOf(obj);
156 var hasProp = {}.hasOwnProperty;
157 return function(obj) {
158 if (isExcludedProto(obj)) return [];
161 /*jshint forin:false */
162 enumeration: for (var key in obj) {
163 if (hasProp.call(obj, key)) {
166 for (var i = 0; i < excludedPrototypes.length; ++i) {
167 if (hasProp.call(excludedPrototypes[i], key)) {
168 continue enumeration;
180 var thisAssignmentPattern = /this\s*\.\s*\S+\s*=/;
181 function isClass(fn) {
183 if (typeof fn === "function") {
184 var keys = es5.names(fn.prototype);
186 var hasMethods = es5.isES5 && keys.length > 1;
187 var hasMethodsOtherThanConstructor = keys.length > 0 &&
188 !(keys.length === 1 && keys[0] === "constructor");
189 var hasThisAssignmentAndStaticMethods =
190 thisAssignmentPattern.test(fn + "") && es5.names(fn).length > 0;
192 if (hasMethods || hasMethodsOtherThanConstructor ||
193 hasThisAssignmentAndStaticMethods) {
203 function toFastProperties(obj) {
204 /*jshint -W027,-W055,-W031*/
213 var rident = /^[a-z$_][a-z$_0-9]*$/i;
214 function isIdentifier(str) {
215 return rident.test(str);
218 function filledRange(count, prefix, suffix) {
219 var ret = new Array(count);
220 for(var i = 0; i < count; ++i) {
221 ret[i] = prefix + i + suffix;
226 function safeToString(obj) {
230 return "[no string representation]";
234 function markAsOriginatingFromRejection(e) {
236 notEnumerableProp(e, "isOperational", true);
241 function originatesFromRejection(e) {
242 if (e == null) return false;
243 return ((e instanceof Error["__BluebirdErrorTypes__"].OperationalError) ||
244 e["isOperational"] === true);
247 function canAttachTrace(obj) {
248 return obj instanceof Error && es5.propertyIsWritable(obj, "stack");
251 var ensureErrorObject = (function() {
252 if (!("stack" in new Error())) {
253 return function(value) {
254 if (canAttachTrace(value)) return value;
255 try {throw new Error(safeToString(value));}
256 catch(err) {return err;}
259 return function(value) {
260 if (canAttachTrace(value)) return value;
261 return new Error(safeToString(value));
266 function classString(obj) {
267 return {}.toString.call(obj);
270 function copyDescriptors(from, to, filter) {
271 var keys = es5.names(from);
272 for (var i = 0; i < keys.length; ++i) {
276 es5.defineProperty(to, key, es5.getDescriptor(from, key));
284 isIdentifier: isIdentifier,
285 inheritedDataKeys: inheritedDataKeys,
286 getDataPropertyOrDefault: getDataPropertyOrDefault,
288 isArray: es5.isArray,
289 haveGetters: haveGetters,
290 notEnumerableProp: notEnumerableProp,
291 isPrimitive: isPrimitive,
293 canEvaluate: canEvaluate,
297 withAppended: withAppended,
298 maybeWrapAsError: maybeWrapAsError,
299 toFastProperties: toFastProperties,
300 filledRange: filledRange,
301 toString: safeToString,
302 canAttachTrace: canAttachTrace,
303 ensureErrorObject: ensureErrorObject,
304 originatesFromRejection: originatesFromRejection,
305 markAsOriginatingFromRejection: markAsOriginatingFromRejection,
306 classString: classString,
307 copyDescriptors: copyDescriptors,
308 hasDevTools: typeof chrome !== "undefined" && chrome &&
309 typeof chrome.loadTimes === "function",
310 isNode: typeof process !== "undefined" &&
311 classString(process).toLowerCase() === "[object process]"
313 ret.isRecentNode = ret.isNode && (function() {
314 var version = process.versions.node.split(".").map(Number);
315 return (version[0] === 0 && version[1] > 10) || (version[0] > 0);
318 if (ret.isNode) ret.toFastProperties(process);
320 try {throw new Error(); } catch (e) {ret.lastLineError = e;}
321 module.exports = ret;