browsed 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/Gemfile.lock +2 -2
  4. data/README.md +12 -17
  5. data/bin/browse +13 -10
  6. data/lib/browsed.rb +9 -2
  7. data/lib/browsed/browser.rb +82 -0
  8. data/lib/browsed/chrome.rb +21 -12
  9. data/lib/browsed/client.rb +48 -130
  10. data/lib/browsed/constants.rb +7 -1
  11. data/lib/browsed/errors.rb +1 -0
  12. data/lib/browsed/extensions/hash.rb +27 -0
  13. data/lib/browsed/firefox.rb +18 -17
  14. data/lib/browsed/manager.rb +5 -5
  15. data/lib/browsed/{poltergeist.rb → phantomjs.rb} +2 -2
  16. data/lib/browsed/proxies.rb +26 -0
  17. data/lib/browsed/{extensions → proxies}/chrome/proxy_authentication.rb +3 -3
  18. data/lib/browsed/proxies/proxy-chain-server/node_modules/.bin/portastic +1 -0
  19. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/LICENSE +21 -0
  20. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/README.md +57 -0
  21. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/changelog.md +1 -0
  22. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/browser/bluebird.core.js +3824 -0
  23. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/browser/bluebird.core.min.js +31 -0
  24. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/browser/bluebird.js +5666 -0
  25. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/browser/bluebird.min.js +31 -0
  26. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/any.js +21 -0
  27. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/assert.js +55 -0
  28. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/async.js +165 -0
  29. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/bind.js +67 -0
  30. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/bluebird.js +11 -0
  31. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/call_get.js +123 -0
  32. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/cancel.js +129 -0
  33. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/catch_filter.js +42 -0
  34. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/context.js +69 -0
  35. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/debuggability.js +934 -0
  36. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/direct_resolve.js +46 -0
  37. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/each.js +30 -0
  38. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/errors.js +116 -0
  39. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/es5.js +80 -0
  40. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/filter.js +12 -0
  41. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/finally.js +146 -0
  42. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/generators.js +223 -0
  43. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/join.js +168 -0
  44. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/map.js +168 -0
  45. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/method.js +55 -0
  46. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/nodeback.js +51 -0
  47. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/nodeify.js +58 -0
  48. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/promise.js +789 -0
  49. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/promise_array.js +185 -0
  50. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/promisify.js +314 -0
  51. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/props.js +118 -0
  52. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/queue.js +73 -0
  53. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/race.js +49 -0
  54. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/reduce.js +172 -0
  55. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/schedule.js +62 -0
  56. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/settle.js +43 -0
  57. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/some.js +148 -0
  58. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/synchronous_inspection.js +103 -0
  59. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/thenables.js +86 -0
  60. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/timers.js +93 -0
  61. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/using.js +226 -0
  62. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/util.js +389 -0
  63. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/package.json +102 -0
  64. data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/CHANGELOG.md +408 -0
  65. data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/LICENSE +22 -0
  66. data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/Readme.md +428 -0
  67. data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/index.js +1224 -0
  68. data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/package.json +70 -0
  69. data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/typings/index.d.ts +310 -0
  70. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/.coveralls.yml +1 -0
  71. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/.eslintrc +11 -0
  72. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/.npmignore +9 -0
  73. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/.travis.yml +14 -0
  74. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/CHANGELOG.md +362 -0
  75. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/LICENSE +19 -0
  76. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/Makefile +50 -0
  77. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/README.md +312 -0
  78. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/component.json +19 -0
  79. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/karma.conf.js +70 -0
  80. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/node.js +1 -0
  81. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/package.json +88 -0
  82. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/src/browser.js +185 -0
  83. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/src/debug.js +202 -0
  84. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/src/index.js +10 -0
  85. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/src/inspector-log.js +15 -0
  86. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/src/node.js +248 -0
  87. data/lib/browsed/proxies/proxy-chain-server/node_modules/ms/index.js +152 -0
  88. data/lib/browsed/proxies/proxy-chain-server/node_modules/ms/license.md +21 -0
  89. data/lib/browsed/proxies/proxy-chain-server/node_modules/ms/package.json +69 -0
  90. data/lib/browsed/proxies/proxy-chain-server/node_modules/ms/readme.md +51 -0
  91. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/LICENSE +13 -0
  92. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/README.md +148 -0
  93. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/bin/portastic +65 -0
  94. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/history.md +7 -0
  95. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/index.js +4 -0
  96. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/lib/monitor.js +59 -0
  97. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/lib/portastic.js +167 -0
  98. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/LICENSE +21 -0
  99. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/README.md +677 -0
  100. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/changelog.md +1730 -0
  101. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/browser/bluebird.js +4892 -0
  102. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/browser/bluebird.min.js +31 -0
  103. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/any.js +21 -0
  104. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/assert.js +55 -0
  105. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/async.js +150 -0
  106. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/bind.js +72 -0
  107. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/bluebird.js +11 -0
  108. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/call_get.js +123 -0
  109. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/cancel.js +48 -0
  110. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/captured_trace.js +493 -0
  111. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/catch_filter.js +66 -0
  112. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/context.js +38 -0
  113. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/debuggability.js +162 -0
  114. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/direct_resolve.js +63 -0
  115. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/each.js +12 -0
  116. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/errors.js +111 -0
  117. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/es5.js +80 -0
  118. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/filter.js +12 -0
  119. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/finally.js +98 -0
  120. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/generators.js +136 -0
  121. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/join.js +107 -0
  122. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/map.js +133 -0
  123. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/method.js +44 -0
  124. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/nodeify.js +59 -0
  125. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/progress.js +76 -0
  126. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/promise.js +759 -0
  127. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/promise_array.js +142 -0
  128. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/promise_resolver.js +123 -0
  129. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/promisify.js +307 -0
  130. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/props.js +79 -0
  131. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/queue.js +90 -0
  132. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/race.js +47 -0
  133. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/reduce.js +148 -0
  134. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/schedule.js +35 -0
  135. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/settle.js +40 -0
  136. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/some.js +125 -0
  137. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/synchronous_inspection.js +94 -0
  138. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/thenables.js +84 -0
  139. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/timers.js +64 -0
  140. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/using.js +213 -0
  141. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/util.js +321 -0
  142. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/package.json +103 -0
  143. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/package.json +69 -0
  144. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/CHANGELOG.md +109 -0
  145. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/LICENSE +201 -0
  146. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/README.md +278 -0
  147. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/anonymize_proxy.js +100 -0
  148. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_base.js +319 -0
  149. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_custom_response.js +96 -0
  150. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_forward.js +173 -0
  151. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_tunnel_chain.js +132 -0
  152. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_tunnel_direct.js +89 -0
  153. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_tunnel_tcp_chain.js +271 -0
  154. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/index.js +26 -0
  155. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/run_locally.js +66 -0
  156. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/server.js +595 -0
  157. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/tcp_tunnel.js +138 -0
  158. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/testing_tcp_service.js +37 -0
  159. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/tools.js +220 -0
  160. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/package.json +104 -0
  161. data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/LICENSE +23 -0
  162. data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/README.md +28 -0
  163. data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/package.json +81 -0
  164. data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/underscore-min.js +5 -0
  165. data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/underscore-min.js.map +1 -0
  166. data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/underscore.js +1692 -0
  167. data/lib/browsed/proxies/proxy-chain-server/package-lock.json +63 -0
  168. data/lib/browsed/proxies/proxy-chain-server/package.json +15 -0
  169. data/lib/browsed/proxies/proxy-chain-server/server.js +25 -0
  170. data/lib/browsed/proxies/proxy_chain.rb +36 -0
  171. data/lib/browsed/version.rb +1 -1
  172. metadata +160 -4
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ module.exports = function(Promise) {
3
+ var errors = require("./errors.js");
4
+ var async = require("./async.js");
5
+ var CancellationError = errors.CancellationError;
6
+
7
+ Promise.prototype._cancel = function (reason) {
8
+ if (!this.isCancellable()) return this;
9
+ var parent;
10
+ var promiseToReject = this;
11
+ while ((parent = promiseToReject._cancellationParent) !== undefined &&
12
+ parent.isCancellable()) {
13
+ promiseToReject = parent;
14
+ }
15
+ this._unsetCancellable();
16
+ promiseToReject._target()._rejectCallback(reason, false, true);
17
+ };
18
+
19
+ Promise.prototype.cancel = function (reason) {
20
+ if (!this.isCancellable()) return this;
21
+ if (reason === undefined) reason = new CancellationError();
22
+ async.invokeLater(this._cancel, this, reason);
23
+ return this;
24
+ };
25
+
26
+ Promise.prototype.cancellable = function () {
27
+ if (this._cancellable()) return this;
28
+ async.enableTrampoline();
29
+ this._setCancellable();
30
+ this._cancellationParent = undefined;
31
+ return this;
32
+ };
33
+
34
+ Promise.prototype.uncancellable = function () {
35
+ var ret = this.then();
36
+ ret._unsetCancellable();
37
+ return ret;
38
+ };
39
+
40
+ Promise.prototype.fork = function (didFulfill, didReject, didProgress) {
41
+ var ret = this._then(didFulfill, didReject, didProgress,
42
+ undefined, undefined);
43
+
44
+ ret._setCancellable();
45
+ ret._cancellationParent = undefined;
46
+ return ret;
47
+ };
48
+ };
@@ -0,0 +1,493 @@
1
+ "use strict";
2
+ module.exports = function() {
3
+ var async = require("./async.js");
4
+ var util = require("./util.js");
5
+ var bluebirdFramePattern =
6
+ /[\\\/]bluebird[\\\/]js[\\\/](main|debug|zalgo|instrumented)/;
7
+ var stackFramePattern = null;
8
+ var formatStack = null;
9
+ var indentStackFrames = false;
10
+ var warn;
11
+
12
+ function CapturedTrace(parent) {
13
+ this._parent = parent;
14
+ var length = this._length = 1 + (parent === undefined ? 0 : parent._length);
15
+ captureStackTrace(this, CapturedTrace);
16
+ if (length > 32) this.uncycle();
17
+ }
18
+ util.inherits(CapturedTrace, Error);
19
+
20
+ CapturedTrace.prototype.uncycle = function() {
21
+ var length = this._length;
22
+ if (length < 2) return;
23
+ var nodes = [];
24
+ var stackToIndex = {};
25
+
26
+ for (var i = 0, node = this; node !== undefined; ++i) {
27
+ nodes.push(node);
28
+ node = node._parent;
29
+ }
30
+ length = this._length = i;
31
+ for (var i = length - 1; i >= 0; --i) {
32
+ var stack = nodes[i].stack;
33
+ if (stackToIndex[stack] === undefined) {
34
+ stackToIndex[stack] = i;
35
+ }
36
+ }
37
+ for (var i = 0; i < length; ++i) {
38
+ var currentStack = nodes[i].stack;
39
+ var index = stackToIndex[currentStack];
40
+ if (index !== undefined && index !== i) {
41
+ if (index > 0) {
42
+ nodes[index - 1]._parent = undefined;
43
+ nodes[index - 1]._length = 1;
44
+ }
45
+ nodes[i]._parent = undefined;
46
+ nodes[i]._length = 1;
47
+ var cycleEdgeNode = i > 0 ? nodes[i - 1] : this;
48
+
49
+ if (index < length - 1) {
50
+ cycleEdgeNode._parent = nodes[index + 1];
51
+ cycleEdgeNode._parent.uncycle();
52
+ cycleEdgeNode._length =
53
+ cycleEdgeNode._parent._length + 1;
54
+ } else {
55
+ cycleEdgeNode._parent = undefined;
56
+ cycleEdgeNode._length = 1;
57
+ }
58
+ var currentChildLength = cycleEdgeNode._length + 1;
59
+ for (var j = i - 2; j >= 0; --j) {
60
+ nodes[j]._length = currentChildLength;
61
+ currentChildLength++;
62
+ }
63
+ return;
64
+ }
65
+ }
66
+ };
67
+
68
+ CapturedTrace.prototype.parent = function() {
69
+ return this._parent;
70
+ };
71
+
72
+ CapturedTrace.prototype.hasParent = function() {
73
+ return this._parent !== undefined;
74
+ };
75
+
76
+ CapturedTrace.prototype.attachExtraTrace = function(error) {
77
+ if (error.__stackCleaned__) return;
78
+ this.uncycle();
79
+ var parsed = CapturedTrace.parseStackAndMessage(error);
80
+ var message = parsed.message;
81
+ var stacks = [parsed.stack];
82
+
83
+ var trace = this;
84
+ while (trace !== undefined) {
85
+ stacks.push(cleanStack(trace.stack.split("\n")));
86
+ trace = trace._parent;
87
+ }
88
+ removeCommonRoots(stacks);
89
+ removeDuplicateOrEmptyJumps(stacks);
90
+ util.notEnumerableProp(error, "stack", reconstructStack(message, stacks));
91
+ util.notEnumerableProp(error, "__stackCleaned__", true);
92
+ };
93
+
94
+ function reconstructStack(message, stacks) {
95
+ for (var i = 0; i < stacks.length - 1; ++i) {
96
+ stacks[i].push("From previous event:");
97
+ stacks[i] = stacks[i].join("\n");
98
+ }
99
+ if (i < stacks.length) {
100
+ stacks[i] = stacks[i].join("\n");
101
+ }
102
+ return message + "\n" + stacks.join("\n");
103
+ }
104
+
105
+ function removeDuplicateOrEmptyJumps(stacks) {
106
+ for (var i = 0; i < stacks.length; ++i) {
107
+ if (stacks[i].length === 0 ||
108
+ ((i + 1 < stacks.length) && stacks[i][0] === stacks[i+1][0])) {
109
+ stacks.splice(i, 1);
110
+ i--;
111
+ }
112
+ }
113
+ }
114
+
115
+ function removeCommonRoots(stacks) {
116
+ var current = stacks[0];
117
+ for (var i = 1; i < stacks.length; ++i) {
118
+ var prev = stacks[i];
119
+ var currentLastIndex = current.length - 1;
120
+ var currentLastLine = current[currentLastIndex];
121
+ var commonRootMeetPoint = -1;
122
+
123
+ for (var j = prev.length - 1; j >= 0; --j) {
124
+ if (prev[j] === currentLastLine) {
125
+ commonRootMeetPoint = j;
126
+ break;
127
+ }
128
+ }
129
+
130
+ for (var j = commonRootMeetPoint; j >= 0; --j) {
131
+ var line = prev[j];
132
+ if (current[currentLastIndex] === line) {
133
+ current.pop();
134
+ currentLastIndex--;
135
+ } else {
136
+ break;
137
+ }
138
+ }
139
+ current = prev;
140
+ }
141
+ }
142
+
143
+ function cleanStack(stack) {
144
+ var ret = [];
145
+ for (var i = 0; i < stack.length; ++i) {
146
+ var line = stack[i];
147
+ var isTraceLine = stackFramePattern.test(line) ||
148
+ " (No stack trace)" === line;
149
+ var isInternalFrame = isTraceLine && shouldIgnore(line);
150
+ if (isTraceLine && !isInternalFrame) {
151
+ if (indentStackFrames && line.charAt(0) !== " ") {
152
+ line = " " + line;
153
+ }
154
+ ret.push(line);
155
+ }
156
+ }
157
+ return ret;
158
+ }
159
+
160
+ function stackFramesAsArray(error) {
161
+ var stack = error.stack.replace(/\s+$/g, "").split("\n");
162
+ for (var i = 0; i < stack.length; ++i) {
163
+ var line = stack[i];
164
+ if (" (No stack trace)" === line || stackFramePattern.test(line)) {
165
+ break;
166
+ }
167
+ }
168
+ if (i > 0) {
169
+ stack = stack.slice(i);
170
+ }
171
+ return stack;
172
+ }
173
+
174
+ CapturedTrace.parseStackAndMessage = function(error) {
175
+ var stack = error.stack;
176
+ var message = error.toString();
177
+ stack = typeof stack === "string" && stack.length > 0
178
+ ? stackFramesAsArray(error) : [" (No stack trace)"];
179
+ return {
180
+ message: message,
181
+ stack: cleanStack(stack)
182
+ };
183
+ };
184
+
185
+ CapturedTrace.formatAndLogError = function(error, title) {
186
+ if (typeof console !== "undefined") {
187
+ var message;
188
+ if (typeof error === "object" || typeof error === "function") {
189
+ var stack = error.stack;
190
+ message = title + formatStack(stack, error);
191
+ } else {
192
+ message = title + String(error);
193
+ }
194
+ if (typeof warn === "function") {
195
+ warn(message);
196
+ } else if (typeof console.log === "function" ||
197
+ typeof console.log === "object") {
198
+ console.log(message);
199
+ }
200
+ }
201
+ };
202
+
203
+ CapturedTrace.unhandledRejection = function (reason) {
204
+ CapturedTrace.formatAndLogError(reason, "^--- With additional stack trace: ");
205
+ };
206
+
207
+ CapturedTrace.isSupported = function () {
208
+ return typeof captureStackTrace === "function";
209
+ };
210
+
211
+ CapturedTrace.fireRejectionEvent =
212
+ function(name, localHandler, reason, promise) {
213
+ var localEventFired = false;
214
+ try {
215
+ if (typeof localHandler === "function") {
216
+ localEventFired = true;
217
+ if (name === "rejectionHandled") {
218
+ localHandler(promise);
219
+ } else {
220
+ localHandler(reason, promise);
221
+ }
222
+ }
223
+ } catch (e) {
224
+ async.throwLater(e);
225
+ }
226
+
227
+ var globalEventFired = false;
228
+ try {
229
+ globalEventFired = fireGlobalEvent(name, reason, promise);
230
+ } catch (e) {
231
+ globalEventFired = true;
232
+ async.throwLater(e);
233
+ }
234
+
235
+ var domEventFired = false;
236
+ if (fireDomEvent) {
237
+ try {
238
+ domEventFired = fireDomEvent(name.toLowerCase(), {
239
+ reason: reason,
240
+ promise: promise
241
+ });
242
+ } catch (e) {
243
+ domEventFired = true;
244
+ async.throwLater(e);
245
+ }
246
+ }
247
+
248
+ if (!globalEventFired && !localEventFired && !domEventFired &&
249
+ name === "unhandledRejection") {
250
+ CapturedTrace.formatAndLogError(reason, "Unhandled rejection ");
251
+ }
252
+ };
253
+
254
+ function formatNonError(obj) {
255
+ var str;
256
+ if (typeof obj === "function") {
257
+ str = "[function " +
258
+ (obj.name || "anonymous") +
259
+ "]";
260
+ } else {
261
+ str = obj.toString();
262
+ var ruselessToString = /\[object [a-zA-Z0-9$_]+\]/;
263
+ if (ruselessToString.test(str)) {
264
+ try {
265
+ var newStr = JSON.stringify(obj);
266
+ str = newStr;
267
+ }
268
+ catch(e) {
269
+
270
+ }
271
+ }
272
+ if (str.length === 0) {
273
+ str = "(empty array)";
274
+ }
275
+ }
276
+ return ("(<" + snip(str) + ">, no stack trace)");
277
+ }
278
+
279
+ function snip(str) {
280
+ var maxChars = 41;
281
+ if (str.length < maxChars) {
282
+ return str;
283
+ }
284
+ return str.substr(0, maxChars - 3) + "...";
285
+ }
286
+
287
+ var shouldIgnore = function() { return false; };
288
+ var parseLineInfoRegex = /[\/<\(]([^:\/]+):(\d+):(?:\d+)\)?\s*$/;
289
+ function parseLineInfo(line) {
290
+ var matches = line.match(parseLineInfoRegex);
291
+ if (matches) {
292
+ return {
293
+ fileName: matches[1],
294
+ line: parseInt(matches[2], 10)
295
+ };
296
+ }
297
+ }
298
+ CapturedTrace.setBounds = function(firstLineError, lastLineError) {
299
+ if (!CapturedTrace.isSupported()) return;
300
+ var firstStackLines = firstLineError.stack.split("\n");
301
+ var lastStackLines = lastLineError.stack.split("\n");
302
+ var firstIndex = -1;
303
+ var lastIndex = -1;
304
+ var firstFileName;
305
+ var lastFileName;
306
+ for (var i = 0; i < firstStackLines.length; ++i) {
307
+ var result = parseLineInfo(firstStackLines[i]);
308
+ if (result) {
309
+ firstFileName = result.fileName;
310
+ firstIndex = result.line;
311
+ break;
312
+ }
313
+ }
314
+ for (var i = 0; i < lastStackLines.length; ++i) {
315
+ var result = parseLineInfo(lastStackLines[i]);
316
+ if (result) {
317
+ lastFileName = result.fileName;
318
+ lastIndex = result.line;
319
+ break;
320
+ }
321
+ }
322
+ if (firstIndex < 0 || lastIndex < 0 || !firstFileName || !lastFileName ||
323
+ firstFileName !== lastFileName || firstIndex >= lastIndex) {
324
+ return;
325
+ }
326
+
327
+ shouldIgnore = function(line) {
328
+ if (bluebirdFramePattern.test(line)) return true;
329
+ var info = parseLineInfo(line);
330
+ if (info) {
331
+ if (info.fileName === firstFileName &&
332
+ (firstIndex <= info.line && info.line <= lastIndex)) {
333
+ return true;
334
+ }
335
+ }
336
+ return false;
337
+ };
338
+ };
339
+
340
+ var captureStackTrace = (function stackDetection() {
341
+ var v8stackFramePattern = /^\s*at\s*/;
342
+ var v8stackFormatter = function(stack, error) {
343
+ if (typeof stack === "string") return stack;
344
+
345
+ if (error.name !== undefined &&
346
+ error.message !== undefined) {
347
+ return error.toString();
348
+ }
349
+ return formatNonError(error);
350
+ };
351
+
352
+ if (typeof Error.stackTraceLimit === "number" &&
353
+ typeof Error.captureStackTrace === "function") {
354
+ Error.stackTraceLimit = Error.stackTraceLimit + 6;
355
+ stackFramePattern = v8stackFramePattern;
356
+ formatStack = v8stackFormatter;
357
+ var captureStackTrace = Error.captureStackTrace;
358
+
359
+ shouldIgnore = function(line) {
360
+ return bluebirdFramePattern.test(line);
361
+ };
362
+ return function(receiver, ignoreUntil) {
363
+ Error.stackTraceLimit = Error.stackTraceLimit + 6;
364
+ captureStackTrace(receiver, ignoreUntil);
365
+ Error.stackTraceLimit = Error.stackTraceLimit - 6;
366
+ };
367
+ }
368
+ var err = new Error();
369
+
370
+ if (typeof err.stack === "string" &&
371
+ err.stack.split("\n")[0].indexOf("stackDetection@") >= 0) {
372
+ stackFramePattern = /@/;
373
+ formatStack = v8stackFormatter;
374
+ indentStackFrames = true;
375
+ return function captureStackTrace(o) {
376
+ o.stack = new Error().stack;
377
+ };
378
+ }
379
+
380
+ var hasStackAfterThrow;
381
+ try { throw new Error(); }
382
+ catch(e) {
383
+ hasStackAfterThrow = ("stack" in e);
384
+ }
385
+ if (!("stack" in err) && hasStackAfterThrow &&
386
+ typeof Error.stackTraceLimit === "number") {
387
+ stackFramePattern = v8stackFramePattern;
388
+ formatStack = v8stackFormatter;
389
+ return function captureStackTrace(o) {
390
+ Error.stackTraceLimit = Error.stackTraceLimit + 6;
391
+ try { throw new Error(); }
392
+ catch(e) { o.stack = e.stack; }
393
+ Error.stackTraceLimit = Error.stackTraceLimit - 6;
394
+ };
395
+ }
396
+
397
+ formatStack = function(stack, error) {
398
+ if (typeof stack === "string") return stack;
399
+
400
+ if ((typeof error === "object" ||
401
+ typeof error === "function") &&
402
+ error.name !== undefined &&
403
+ error.message !== undefined) {
404
+ return error.toString();
405
+ }
406
+ return formatNonError(error);
407
+ };
408
+
409
+ return null;
410
+
411
+ })([]);
412
+
413
+ var fireDomEvent;
414
+ var fireGlobalEvent = (function() {
415
+ if (util.isNode) {
416
+ return function(name, reason, promise) {
417
+ if (name === "rejectionHandled") {
418
+ return process.emit(name, promise);
419
+ } else {
420
+ return process.emit(name, reason, promise);
421
+ }
422
+ };
423
+ } else {
424
+ var customEventWorks = false;
425
+ var anyEventWorks = true;
426
+ try {
427
+ var ev = new self.CustomEvent("test");
428
+ customEventWorks = ev instanceof CustomEvent;
429
+ } catch (e) {}
430
+ if (!customEventWorks) {
431
+ try {
432
+ var event = document.createEvent("CustomEvent");
433
+ event.initCustomEvent("testingtheevent", false, true, {});
434
+ self.dispatchEvent(event);
435
+ } catch (e) {
436
+ anyEventWorks = false;
437
+ }
438
+ }
439
+ if (anyEventWorks) {
440
+ fireDomEvent = function(type, detail) {
441
+ var event;
442
+ if (customEventWorks) {
443
+ event = new self.CustomEvent(type, {
444
+ detail: detail,
445
+ bubbles: false,
446
+ cancelable: true
447
+ });
448
+ } else if (self.dispatchEvent) {
449
+ event = document.createEvent("CustomEvent");
450
+ event.initCustomEvent(type, false, true, detail);
451
+ }
452
+
453
+ return event ? !self.dispatchEvent(event) : false;
454
+ };
455
+ }
456
+
457
+ var toWindowMethodNameMap = {};
458
+ toWindowMethodNameMap["unhandledRejection"] = ("on" +
459
+ "unhandledRejection").toLowerCase();
460
+ toWindowMethodNameMap["rejectionHandled"] = ("on" +
461
+ "rejectionHandled").toLowerCase();
462
+
463
+ return function(name, reason, promise) {
464
+ var methodName = toWindowMethodNameMap[name];
465
+ var method = self[methodName];
466
+ if (!method) return false;
467
+ if (name === "rejectionHandled") {
468
+ method.call(self, promise);
469
+ } else {
470
+ method.call(self, reason, promise);
471
+ }
472
+ return true;
473
+ };
474
+ }
475
+ })();
476
+
477
+ if (typeof console !== "undefined" && typeof console.warn !== "undefined") {
478
+ warn = function (message) {
479
+ console.warn(message);
480
+ };
481
+ if (util.isNode && process.stderr.isTTY) {
482
+ warn = function(message) {
483
+ process.stderr.write("\u001b[31m" + message + "\u001b[39m\n");
484
+ };
485
+ } else if (!util.isNode && typeof (new Error().stack) === "string") {
486
+ warn = function(message) {
487
+ console.warn("%c" + message, "color: red");
488
+ };
489
+ }
490
+ }
491
+
492
+ return CapturedTrace;
493
+ };