]> git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/vim-mode/node_modules/event-kit/node_modules/grim/lib/deprecation.js
c366d1a709aa36e9b43436cf64de56b8351e402e
[rbdr/dotfiles] / atom / packages / vim-mode / node_modules / event-kit / node_modules / grim / lib / deprecation.js
1 (function() {
2 var Deprecation, _;
3
4 _ = require('underscore-plus');
5
6 module.exports = Deprecation = (function() {
7 Deprecation.generateStack = function() {
8 var error, originalPrepareStackTrace, stack;
9 originalPrepareStackTrace = Error.prepareStackTrace;
10 Error.prepareStackTrace = function(error, stack) {
11 return stack;
12 };
13 error = new Error();
14 Error.captureStackTrace(error);
15 stack = error.stack.slice(1);
16 Error.prepareStackTrace = originalPrepareStackTrace;
17 return stack;
18 };
19
20 Deprecation.getFunctionNameFromCallsite = function(callsite) {
21 var _ref, _ref1, _ref2;
22 if (callsite.isToplevel()) {
23 return (_ref = callsite.getFunctionName()) != null ? _ref : '<unknown>';
24 } else {
25 if (callsite.isConstructor()) {
26 return "new " + (callsite.getFunctionName());
27 } else if (callsite.getMethodName() && !callsite.getFunctionName()) {
28 return callsite.getMethodName();
29 } else {
30 return "" + (callsite.getTypeName()) + "." + ((_ref1 = (_ref2 = callsite.getMethodName()) != null ? _ref2 : callsite.getFunctionName()) != null ? _ref1 : '<anonymous>');
31 }
32 }
33 };
34
35 function Deprecation(message) {
36 this.message = message;
37 this.callCount = 0;
38 this.stacks = [];
39 }
40
41 Deprecation.prototype.getFunctionNameFromCallsite = function(callsite) {
42 return Deprecation.getFunctionNameFromCallsite(callsite);
43 };
44
45 Deprecation.prototype.getLocationFromCallsite = function(callsite) {
46 if (callsite.isNative()) {
47 return "native";
48 } else if (callsite.isEval()) {
49 return "eval at " + (this.getLocationFromCallsite(callsite.getEvalOrigin()));
50 } else {
51 return "" + (callsite.getFileName()) + ":" + (callsite.getLineNumber()) + ":" + (callsite.getColumnNumber());
52 }
53 };
54
55 Deprecation.prototype.getOriginName = function() {
56 return this.originName;
57 };
58
59 Deprecation.prototype.getMessage = function() {
60 return this.message;
61 };
62
63 Deprecation.prototype.getStacks = function() {
64 return _.clone(this.stacks);
65 };
66
67 Deprecation.prototype.getCallCount = function() {
68 return this.callCount;
69 };
70
71 Deprecation.prototype.addStack = function(stack) {
72 var existingStack;
73 if (this.originName == null) {
74 this.originName = this.getFunctionNameFromCallsite(stack[0]);
75 }
76 stack = this.parseStack(stack);
77 if (existingStack = this.isStackUnique(stack)) {
78 existingStack.callCount++;
79 } else {
80 this.stacks.push(stack);
81 }
82 return this.callCount++;
83 };
84
85 Deprecation.prototype.parseStack = function(stack) {
86 stack = stack.map((function(_this) {
87 return function(callsite) {
88 return {
89 functionName: _this.getFunctionNameFromCallsite(callsite),
90 location: _this.getLocationFromCallsite(callsite),
91 fileName: callsite.getFileName()
92 };
93 };
94 })(this));
95 stack.callCount = 1;
96 return stack;
97 };
98
99 Deprecation.prototype.isStackUnique = function(stack) {
100 var stacks;
101 stacks = this.stacks.filter(function(s) {
102 var callsite, functionName, i, location, _i, _len, _ref;
103 if (s.length !== stack.length) {
104 return false;
105 }
106 for (i = _i = 0, _len = s.length; _i < _len; i = ++_i) {
107 _ref = s[i], functionName = _ref.functionName, location = _ref.location;
108 callsite = stack[i];
109 if (!(functionName === callsite.functionName && location === callsite.location)) {
110 return false;
111 }
112 }
113 return true;
114 });
115 return stacks[0];
116 };
117
118 return Deprecation;
119
120 })();
121
122 }).call(this);