forked from stacktracejs/stacktrace.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExceptionLab.js
More file actions
69 lines (62 loc) · 1.89 KB
/
ExceptionLab.js
File metadata and controls
69 lines (62 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*global module, exports, define*/
(function(global) {
function createException() {
return ((function(x) {
try {
x.undef();
return x;
} catch (ex) {
return ex;
}
})(null));
}
function printProp(prop, value) {
if (typeof value === "string") {
value = '"' + value.replace(/"/g, '\\"').replace(/\r/g, "\\r").replace(/\n/g, '\\n" +\n "') + '"';
}
return prop + ': ' + value;
}
function getExceptionProps(ex) {
/*jshint forin:false*/
var prop, props = [], exceptionPropertyNames = {
message: true,
name: true,
stack: true,
stacktrace: true,
'arguments': true,
type: true
};
// find all (including non-enumerable) own properties
if (typeof Object.getOwnPropertyNames === "function") {
var ownPropertyNames = Object.getOwnPropertyNames(ex);
for (var i = 0; i < ownPropertyNames.length; i++) {
exceptionPropertyNames[ownPropertyNames[i]] = true;
}
}
// find own and inherited enumerable properties
for (prop in ex) {
exceptionPropertyNames[prop] = true;
}
for (prop in exceptionPropertyNames) {
var value = ex[prop];
if (typeof value !== "undefined") {
props.push(printProp(prop, value));
}
}
return props;
}
var api = {
createException: createException,
getExceptionProps: getExceptionProps
};
if (typeof exports === 'object') {
// Node
module.exports = api;
} else if (typeof define === 'function' && define.amd) {
// AMD
define(api);
} else {
// Browser globals
global.ExceptionLab = api;
}
}(this));