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,66 @@
1
+ "use strict";
2
+ module.exports = function(NEXT_FILTER) {
3
+ var util = require("./util.js");
4
+ var errors = require("./errors.js");
5
+ var tryCatch = util.tryCatch;
6
+ var errorObj = util.errorObj;
7
+ var keys = require("./es5.js").keys;
8
+ var TypeError = errors.TypeError;
9
+
10
+ function CatchFilter(instances, callback, promise) {
11
+ this._instances = instances;
12
+ this._callback = callback;
13
+ this._promise = promise;
14
+ }
15
+
16
+ function safePredicate(predicate, e) {
17
+ var safeObject = {};
18
+ var retfilter = tryCatch(predicate).call(safeObject, e);
19
+
20
+ if (retfilter === errorObj) return retfilter;
21
+
22
+ var safeKeys = keys(safeObject);
23
+ if (safeKeys.length) {
24
+ errorObj.e = new TypeError("Catch filter must inherit from Error or be a simple predicate function\u000a\u000a See http://goo.gl/o84o68\u000a");
25
+ return errorObj;
26
+ }
27
+ return retfilter;
28
+ }
29
+
30
+ CatchFilter.prototype.doFilter = function (e) {
31
+ var cb = this._callback;
32
+ var promise = this._promise;
33
+ var boundTo = promise._boundValue();
34
+ for (var i = 0, len = this._instances.length; i < len; ++i) {
35
+ var item = this._instances[i];
36
+ var itemIsErrorType = item === Error ||
37
+ (item != null && item.prototype instanceof Error);
38
+
39
+ if (itemIsErrorType && e instanceof item) {
40
+ var ret = tryCatch(cb).call(boundTo, e);
41
+ if (ret === errorObj) {
42
+ NEXT_FILTER.e = ret.e;
43
+ return NEXT_FILTER;
44
+ }
45
+ return ret;
46
+ } else if (typeof item === "function" && !itemIsErrorType) {
47
+ var shouldHandle = safePredicate(item, e);
48
+ if (shouldHandle === errorObj) {
49
+ e = errorObj.e;
50
+ break;
51
+ } else if (shouldHandle) {
52
+ var ret = tryCatch(cb).call(boundTo, e);
53
+ if (ret === errorObj) {
54
+ NEXT_FILTER.e = ret.e;
55
+ return NEXT_FILTER;
56
+ }
57
+ return ret;
58
+ }
59
+ }
60
+ }
61
+ NEXT_FILTER.e = e;
62
+ return NEXT_FILTER;
63
+ };
64
+
65
+ return CatchFilter;
66
+ };
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ module.exports = function(Promise, CapturedTrace, isDebugging) {
3
+ var contextStack = [];
4
+ function Context() {
5
+ this._trace = new CapturedTrace(peekContext());
6
+ }
7
+ Context.prototype._pushContext = function () {
8
+ if (!isDebugging()) return;
9
+ if (this._trace !== undefined) {
10
+ contextStack.push(this._trace);
11
+ }
12
+ };
13
+
14
+ Context.prototype._popContext = function () {
15
+ if (!isDebugging()) return;
16
+ if (this._trace !== undefined) {
17
+ contextStack.pop();
18
+ }
19
+ };
20
+
21
+ function createContext() {
22
+ if (isDebugging()) return new Context();
23
+ }
24
+
25
+ function peekContext() {
26
+ var lastIndex = contextStack.length - 1;
27
+ if (lastIndex >= 0) {
28
+ return contextStack[lastIndex];
29
+ }
30
+ return undefined;
31
+ }
32
+
33
+ Promise.prototype._peekContext = peekContext;
34
+ Promise.prototype._pushContext = Context.prototype._pushContext;
35
+ Promise.prototype._popContext = Context.prototype._popContext;
36
+
37
+ return createContext;
38
+ };
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ module.exports = function(Promise, CapturedTrace) {
3
+ var getDomain = Promise._getDomain;
4
+ var async = require("./async.js");
5
+ var Warning = require("./errors.js").Warning;
6
+ var util = require("./util.js");
7
+ var canAttachTrace = util.canAttachTrace;
8
+ var unhandledRejectionHandled;
9
+ var possiblyUnhandledRejection;
10
+ var debugging = false || (util.isNode &&
11
+ (!!process.env["BLUEBIRD_DEBUG"] ||
12
+ process.env["NODE_ENV"] === "development"));
13
+
14
+ if (util.isNode && process.env["BLUEBIRD_DEBUG"] == 0) debugging = false;
15
+
16
+ if (debugging) {
17
+ async.disableTrampolineIfNecessary();
18
+ }
19
+
20
+ Promise.prototype._ignoreRejections = function() {
21
+ this._unsetRejectionIsUnhandled();
22
+ this._bitField = this._bitField | 16777216;
23
+ };
24
+
25
+ Promise.prototype._ensurePossibleRejectionHandled = function () {
26
+ if ((this._bitField & 16777216) !== 0) return;
27
+ this._setRejectionIsUnhandled();
28
+ async.invokeLater(this._notifyUnhandledRejection, this, undefined);
29
+ };
30
+
31
+ Promise.prototype._notifyUnhandledRejectionIsHandled = function () {
32
+ CapturedTrace.fireRejectionEvent("rejectionHandled",
33
+ unhandledRejectionHandled, undefined, this);
34
+ };
35
+
36
+ Promise.prototype._notifyUnhandledRejection = function () {
37
+ if (this._isRejectionUnhandled()) {
38
+ var reason = this._getCarriedStackTrace() || this._settledValue;
39
+ this._setUnhandledRejectionIsNotified();
40
+ CapturedTrace.fireRejectionEvent("unhandledRejection",
41
+ possiblyUnhandledRejection, reason, this);
42
+ }
43
+ };
44
+
45
+ Promise.prototype._setUnhandledRejectionIsNotified = function () {
46
+ this._bitField = this._bitField | 524288;
47
+ };
48
+
49
+ Promise.prototype._unsetUnhandledRejectionIsNotified = function () {
50
+ this._bitField = this._bitField & (~524288);
51
+ };
52
+
53
+ Promise.prototype._isUnhandledRejectionNotified = function () {
54
+ return (this._bitField & 524288) > 0;
55
+ };
56
+
57
+ Promise.prototype._setRejectionIsUnhandled = function () {
58
+ this._bitField = this._bitField | 2097152;
59
+ };
60
+
61
+ Promise.prototype._unsetRejectionIsUnhandled = function () {
62
+ this._bitField = this._bitField & (~2097152);
63
+ if (this._isUnhandledRejectionNotified()) {
64
+ this._unsetUnhandledRejectionIsNotified();
65
+ this._notifyUnhandledRejectionIsHandled();
66
+ }
67
+ };
68
+
69
+ Promise.prototype._isRejectionUnhandled = function () {
70
+ return (this._bitField & 2097152) > 0;
71
+ };
72
+
73
+ Promise.prototype._setCarriedStackTrace = function (capturedTrace) {
74
+ this._bitField = this._bitField | 1048576;
75
+ this._fulfillmentHandler0 = capturedTrace;
76
+ };
77
+
78
+ Promise.prototype._isCarryingStackTrace = function () {
79
+ return (this._bitField & 1048576) > 0;
80
+ };
81
+
82
+ Promise.prototype._getCarriedStackTrace = function () {
83
+ return this._isCarryingStackTrace()
84
+ ? this._fulfillmentHandler0
85
+ : undefined;
86
+ };
87
+
88
+ Promise.prototype._captureStackTrace = function () {
89
+ if (debugging) {
90
+ this._trace = new CapturedTrace(this._peekContext());
91
+ }
92
+ return this;
93
+ };
94
+
95
+ Promise.prototype._attachExtraTrace = function (error, ignoreSelf) {
96
+ if (debugging && canAttachTrace(error)) {
97
+ var trace = this._trace;
98
+ if (trace !== undefined) {
99
+ if (ignoreSelf) trace = trace._parent;
100
+ }
101
+ if (trace !== undefined) {
102
+ trace.attachExtraTrace(error);
103
+ } else if (!error.__stackCleaned__) {
104
+ var parsed = CapturedTrace.parseStackAndMessage(error);
105
+ util.notEnumerableProp(error, "stack",
106
+ parsed.message + "\n" + parsed.stack.join("\n"));
107
+ util.notEnumerableProp(error, "__stackCleaned__", true);
108
+ }
109
+ }
110
+ };
111
+
112
+ Promise.prototype._warn = function(message) {
113
+ var warning = new Warning(message);
114
+ var ctx = this._peekContext();
115
+ if (ctx) {
116
+ ctx.attachExtraTrace(warning);
117
+ } else {
118
+ var parsed = CapturedTrace.parseStackAndMessage(warning);
119
+ warning.stack = parsed.message + "\n" + parsed.stack.join("\n");
120
+ }
121
+ CapturedTrace.formatAndLogError(warning, "");
122
+ };
123
+
124
+ Promise.onPossiblyUnhandledRejection = function (fn) {
125
+ var domain = getDomain();
126
+ possiblyUnhandledRejection =
127
+ typeof fn === "function" ? (domain === null ? fn : domain.bind(fn))
128
+ : undefined;
129
+ };
130
+
131
+ Promise.onUnhandledRejectionHandled = function (fn) {
132
+ var domain = getDomain();
133
+ unhandledRejectionHandled =
134
+ typeof fn === "function" ? (domain === null ? fn : domain.bind(fn))
135
+ : undefined;
136
+ };
137
+
138
+ Promise.longStackTraces = function () {
139
+ if (async.haveItemsQueued() &&
140
+ debugging === false
141
+ ) {
142
+ throw new Error("cannot enable long stack traces after promises have been created\u000a\u000a See http://goo.gl/DT1qyG\u000a");
143
+ }
144
+ debugging = CapturedTrace.isSupported();
145
+ if (debugging) {
146
+ async.disableTrampolineIfNecessary();
147
+ }
148
+ };
149
+
150
+ Promise.hasLongStackTraces = function () {
151
+ return debugging && CapturedTrace.isSupported();
152
+ };
153
+
154
+ if (!CapturedTrace.isSupported()) {
155
+ Promise.longStackTraces = function(){};
156
+ debugging = false;
157
+ }
158
+
159
+ return function() {
160
+ return debugging;
161
+ };
162
+ };
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var util = require("./util.js");
3
+ var isPrimitive = util.isPrimitive;
4
+
5
+ module.exports = function(Promise) {
6
+ var returner = function () {
7
+ return this;
8
+ };
9
+ var thrower = function () {
10
+ throw this;
11
+ };
12
+ var returnUndefined = function() {};
13
+ var throwUndefined = function() {
14
+ throw undefined;
15
+ };
16
+
17
+ var wrapper = function (value, action) {
18
+ if (action === 1) {
19
+ return function () {
20
+ throw value;
21
+ };
22
+ } else if (action === 2) {
23
+ return function () {
24
+ return value;
25
+ };
26
+ }
27
+ };
28
+
29
+
30
+ Promise.prototype["return"] =
31
+ Promise.prototype.thenReturn = function (value) {
32
+ if (value === undefined) return this.then(returnUndefined);
33
+
34
+ if (isPrimitive(value)) {
35
+ return this._then(
36
+ wrapper(value, 2),
37
+ undefined,
38
+ undefined,
39
+ undefined,
40
+ undefined
41
+ );
42
+ } else if (value instanceof Promise) {
43
+ value._ignoreRejections();
44
+ }
45
+ return this._then(returner, undefined, undefined, value, undefined);
46
+ };
47
+
48
+ Promise.prototype["throw"] =
49
+ Promise.prototype.thenThrow = function (reason) {
50
+ if (reason === undefined) return this.then(throwUndefined);
51
+
52
+ if (isPrimitive(reason)) {
53
+ return this._then(
54
+ wrapper(reason, 1),
55
+ undefined,
56
+ undefined,
57
+ undefined,
58
+ undefined
59
+ );
60
+ }
61
+ return this._then(thrower, undefined, undefined, reason, undefined);
62
+ };
63
+ };
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ module.exports = function(Promise, INTERNAL) {
3
+ var PromiseReduce = Promise.reduce;
4
+
5
+ Promise.prototype.each = function (fn) {
6
+ return PromiseReduce(this, fn, null, INTERNAL);
7
+ };
8
+
9
+ Promise.each = function (promises, fn) {
10
+ return PromiseReduce(promises, fn, null, INTERNAL);
11
+ };
12
+ };
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ var es5 = require("./es5.js");
3
+ var Objectfreeze = es5.freeze;
4
+ var util = require("./util.js");
5
+ var inherits = util.inherits;
6
+ var notEnumerableProp = util.notEnumerableProp;
7
+
8
+ function subError(nameProperty, defaultMessage) {
9
+ function SubError(message) {
10
+ if (!(this instanceof SubError)) return new SubError(message);
11
+ notEnumerableProp(this, "message",
12
+ typeof message === "string" ? message : defaultMessage);
13
+ notEnumerableProp(this, "name", nameProperty);
14
+ if (Error.captureStackTrace) {
15
+ Error.captureStackTrace(this, this.constructor);
16
+ } else {
17
+ Error.call(this);
18
+ }
19
+ }
20
+ inherits(SubError, Error);
21
+ return SubError;
22
+ }
23
+
24
+ var _TypeError, _RangeError;
25
+ var Warning = subError("Warning", "warning");
26
+ var CancellationError = subError("CancellationError", "cancellation error");
27
+ var TimeoutError = subError("TimeoutError", "timeout error");
28
+ var AggregateError = subError("AggregateError", "aggregate error");
29
+ try {
30
+ _TypeError = TypeError;
31
+ _RangeError = RangeError;
32
+ } catch(e) {
33
+ _TypeError = subError("TypeError", "type error");
34
+ _RangeError = subError("RangeError", "range error");
35
+ }
36
+
37
+ var methods = ("join pop push shift unshift slice filter forEach some " +
38
+ "every map indexOf lastIndexOf reduce reduceRight sort reverse").split(" ");
39
+
40
+ for (var i = 0; i < methods.length; ++i) {
41
+ if (typeof Array.prototype[methods[i]] === "function") {
42
+ AggregateError.prototype[methods[i]] = Array.prototype[methods[i]];
43
+ }
44
+ }
45
+
46
+ es5.defineProperty(AggregateError.prototype, "length", {
47
+ value: 0,
48
+ configurable: false,
49
+ writable: true,
50
+ enumerable: true
51
+ });
52
+ AggregateError.prototype["isOperational"] = true;
53
+ var level = 0;
54
+ AggregateError.prototype.toString = function() {
55
+ var indent = Array(level * 4 + 1).join(" ");
56
+ var ret = "\n" + indent + "AggregateError of:" + "\n";
57
+ level++;
58
+ indent = Array(level * 4 + 1).join(" ");
59
+ for (var i = 0; i < this.length; ++i) {
60
+ var str = this[i] === this ? "[Circular AggregateError]" : this[i] + "";
61
+ var lines = str.split("\n");
62
+ for (var j = 0; j < lines.length; ++j) {
63
+ lines[j] = indent + lines[j];
64
+ }
65
+ str = lines.join("\n");
66
+ ret += str + "\n";
67
+ }
68
+ level--;
69
+ return ret;
70
+ };
71
+
72
+ function OperationalError(message) {
73
+ if (!(this instanceof OperationalError))
74
+ return new OperationalError(message);
75
+ notEnumerableProp(this, "name", "OperationalError");
76
+ notEnumerableProp(this, "message", message);
77
+ this.cause = message;
78
+ this["isOperational"] = true;
79
+
80
+ if (message instanceof Error) {
81
+ notEnumerableProp(this, "message", message.message);
82
+ notEnumerableProp(this, "stack", message.stack);
83
+ } else if (Error.captureStackTrace) {
84
+ Error.captureStackTrace(this, this.constructor);
85
+ }
86
+
87
+ }
88
+ inherits(OperationalError, Error);
89
+
90
+ var errorTypes = Error["__BluebirdErrorTypes__"];
91
+ if (!errorTypes) {
92
+ errorTypes = Objectfreeze({
93
+ CancellationError: CancellationError,
94
+ TimeoutError: TimeoutError,
95
+ OperationalError: OperationalError,
96
+ RejectionError: OperationalError,
97
+ AggregateError: AggregateError
98
+ });
99
+ notEnumerableProp(Error, "__BluebirdErrorTypes__", errorTypes);
100
+ }
101
+
102
+ module.exports = {
103
+ Error: Error,
104
+ TypeError: _TypeError,
105
+ RangeError: _RangeError,
106
+ CancellationError: errorTypes.CancellationError,
107
+ OperationalError: errorTypes.OperationalError,
108
+ TimeoutError: errorTypes.TimeoutError,
109
+ AggregateError: errorTypes.AggregateError,
110
+ Warning: Warning
111
+ };