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,46 @@
1
+ "use strict";
2
+ module.exports = function(Promise) {
3
+ function returner() {
4
+ return this.value;
5
+ }
6
+ function thrower() {
7
+ throw this.reason;
8
+ }
9
+
10
+ Promise.prototype["return"] =
11
+ Promise.prototype.thenReturn = function (value) {
12
+ if (value instanceof Promise) value.suppressUnhandledRejections();
13
+ return this._then(
14
+ returner, undefined, undefined, {value: value}, undefined);
15
+ };
16
+
17
+ Promise.prototype["throw"] =
18
+ Promise.prototype.thenThrow = function (reason) {
19
+ return this._then(
20
+ thrower, undefined, undefined, {reason: reason}, undefined);
21
+ };
22
+
23
+ Promise.prototype.catchThrow = function (reason) {
24
+ if (arguments.length <= 1) {
25
+ return this._then(
26
+ undefined, thrower, undefined, {reason: reason}, undefined);
27
+ } else {
28
+ var _reason = arguments[1];
29
+ var handler = function() {throw _reason;};
30
+ return this.caught(reason, handler);
31
+ }
32
+ };
33
+
34
+ Promise.prototype.catchReturn = function (value) {
35
+ if (arguments.length <= 1) {
36
+ if (value instanceof Promise) value.suppressUnhandledRejections();
37
+ return this._then(
38
+ undefined, returner, undefined, {value: value}, undefined);
39
+ } else {
40
+ var _value = arguments[1];
41
+ if (_value instanceof Promise) _value.suppressUnhandledRejections();
42
+ var handler = function() {return _value;};
43
+ return this.caught(value, handler);
44
+ }
45
+ };
46
+ };
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ module.exports = function(Promise, INTERNAL) {
3
+ var PromiseReduce = Promise.reduce;
4
+ var PromiseAll = Promise.all;
5
+
6
+ function promiseAllThis() {
7
+ return PromiseAll(this);
8
+ }
9
+
10
+ function PromiseMapSeries(promises, fn) {
11
+ return PromiseReduce(promises, fn, INTERNAL, INTERNAL);
12
+ }
13
+
14
+ Promise.prototype.each = function (fn) {
15
+ return PromiseReduce(this, fn, INTERNAL, 0)
16
+ ._then(promiseAllThis, undefined, undefined, this, undefined);
17
+ };
18
+
19
+ Promise.prototype.mapSeries = function (fn) {
20
+ return PromiseReduce(this, fn, INTERNAL, INTERNAL);
21
+ };
22
+
23
+ Promise.each = function (promises, fn) {
24
+ return PromiseReduce(promises, fn, INTERNAL, 0)
25
+ ._then(promiseAllThis, undefined, undefined, promises, undefined);
26
+ };
27
+
28
+ Promise.mapSeries = PromiseMapSeries;
29
+ };
30
+
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ var es5 = require("./es5");
3
+ var Objectfreeze = es5.freeze;
4
+ var util = require("./util");
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
+ es5.defineProperty(Error, "__BluebirdErrorTypes__", {
100
+ value: errorTypes,
101
+ writable: false,
102
+ enumerable: false,
103
+ configurable: false
104
+ });
105
+ }
106
+
107
+ module.exports = {
108
+ Error: Error,
109
+ TypeError: _TypeError,
110
+ RangeError: _RangeError,
111
+ CancellationError: errorTypes.CancellationError,
112
+ OperationalError: errorTypes.OperationalError,
113
+ TimeoutError: errorTypes.TimeoutError,
114
+ AggregateError: errorTypes.AggregateError,
115
+ Warning: Warning
116
+ };
@@ -0,0 +1,80 @@
1
+ var isES5 = (function(){
2
+ "use strict";
3
+ return this === undefined;
4
+ })();
5
+
6
+ if (isES5) {
7
+ module.exports = {
8
+ freeze: Object.freeze,
9
+ defineProperty: Object.defineProperty,
10
+ getDescriptor: Object.getOwnPropertyDescriptor,
11
+ keys: Object.keys,
12
+ names: Object.getOwnPropertyNames,
13
+ getPrototypeOf: Object.getPrototypeOf,
14
+ isArray: Array.isArray,
15
+ isES5: isES5,
16
+ propertyIsWritable: function(obj, prop) {
17
+ var descriptor = Object.getOwnPropertyDescriptor(obj, prop);
18
+ return !!(!descriptor || descriptor.writable || descriptor.set);
19
+ }
20
+ };
21
+ } else {
22
+ var has = {}.hasOwnProperty;
23
+ var str = {}.toString;
24
+ var proto = {}.constructor.prototype;
25
+
26
+ var ObjectKeys = function (o) {
27
+ var ret = [];
28
+ for (var key in o) {
29
+ if (has.call(o, key)) {
30
+ ret.push(key);
31
+ }
32
+ }
33
+ return ret;
34
+ };
35
+
36
+ var ObjectGetDescriptor = function(o, key) {
37
+ return {value: o[key]};
38
+ };
39
+
40
+ var ObjectDefineProperty = function (o, key, desc) {
41
+ o[key] = desc.value;
42
+ return o;
43
+ };
44
+
45
+ var ObjectFreeze = function (obj) {
46
+ return obj;
47
+ };
48
+
49
+ var ObjectGetPrototypeOf = function (obj) {
50
+ try {
51
+ return Object(obj).constructor.prototype;
52
+ }
53
+ catch (e) {
54
+ return proto;
55
+ }
56
+ };
57
+
58
+ var ArrayIsArray = function (obj) {
59
+ try {
60
+ return str.call(obj) === "[object Array]";
61
+ }
62
+ catch(e) {
63
+ return false;
64
+ }
65
+ };
66
+
67
+ module.exports = {
68
+ isArray: ArrayIsArray,
69
+ keys: ObjectKeys,
70
+ names: ObjectKeys,
71
+ defineProperty: ObjectDefineProperty,
72
+ getDescriptor: ObjectGetDescriptor,
73
+ freeze: ObjectFreeze,
74
+ getPrototypeOf: ObjectGetPrototypeOf,
75
+ isES5: isES5,
76
+ propertyIsWritable: function() {
77
+ return true;
78
+ }
79
+ };
80
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ module.exports = function(Promise, INTERNAL) {
3
+ var PromiseMap = Promise.map;
4
+
5
+ Promise.prototype.filter = function (fn, options) {
6
+ return PromiseMap(this, fn, options, INTERNAL);
7
+ };
8
+
9
+ Promise.filter = function (promises, fn, options) {
10
+ return PromiseMap(promises, fn, options, INTERNAL);
11
+ };
12
+ };
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ module.exports = function(Promise, tryConvertToPromise, NEXT_FILTER) {
3
+ var util = require("./util");
4
+ var CancellationError = Promise.CancellationError;
5
+ var errorObj = util.errorObj;
6
+ var catchFilter = require("./catch_filter")(NEXT_FILTER);
7
+
8
+ function PassThroughHandlerContext(promise, type, handler) {
9
+ this.promise = promise;
10
+ this.type = type;
11
+ this.handler = handler;
12
+ this.called = false;
13
+ this.cancelPromise = null;
14
+ }
15
+
16
+ PassThroughHandlerContext.prototype.isFinallyHandler = function() {
17
+ return this.type === 0;
18
+ };
19
+
20
+ function FinallyHandlerCancelReaction(finallyHandler) {
21
+ this.finallyHandler = finallyHandler;
22
+ }
23
+
24
+ FinallyHandlerCancelReaction.prototype._resultCancelled = function() {
25
+ checkCancel(this.finallyHandler);
26
+ };
27
+
28
+ function checkCancel(ctx, reason) {
29
+ if (ctx.cancelPromise != null) {
30
+ if (arguments.length > 1) {
31
+ ctx.cancelPromise._reject(reason);
32
+ } else {
33
+ ctx.cancelPromise._cancel();
34
+ }
35
+ ctx.cancelPromise = null;
36
+ return true;
37
+ }
38
+ return false;
39
+ }
40
+
41
+ function succeed() {
42
+ return finallyHandler.call(this, this.promise._target()._settledValue());
43
+ }
44
+ function fail(reason) {
45
+ if (checkCancel(this, reason)) return;
46
+ errorObj.e = reason;
47
+ return errorObj;
48
+ }
49
+ function finallyHandler(reasonOrValue) {
50
+ var promise = this.promise;
51
+ var handler = this.handler;
52
+
53
+ if (!this.called) {
54
+ this.called = true;
55
+ var ret = this.isFinallyHandler()
56
+ ? handler.call(promise._boundValue())
57
+ : handler.call(promise._boundValue(), reasonOrValue);
58
+ if (ret === NEXT_FILTER) {
59
+ return ret;
60
+ } else if (ret !== undefined) {
61
+ promise._setReturnedNonUndefined();
62
+ var maybePromise = tryConvertToPromise(ret, promise);
63
+ if (maybePromise instanceof Promise) {
64
+ if (this.cancelPromise != null) {
65
+ if (maybePromise._isCancelled()) {
66
+ var reason =
67
+ new CancellationError("late cancellation observer");
68
+ promise._attachExtraTrace(reason);
69
+ errorObj.e = reason;
70
+ return errorObj;
71
+ } else if (maybePromise.isPending()) {
72
+ maybePromise._attachCancellationCallback(
73
+ new FinallyHandlerCancelReaction(this));
74
+ }
75
+ }
76
+ return maybePromise._then(
77
+ succeed, fail, undefined, this, undefined);
78
+ }
79
+ }
80
+ }
81
+
82
+ if (promise.isRejected()) {
83
+ checkCancel(this);
84
+ errorObj.e = reasonOrValue;
85
+ return errorObj;
86
+ } else {
87
+ checkCancel(this);
88
+ return reasonOrValue;
89
+ }
90
+ }
91
+
92
+ Promise.prototype._passThrough = function(handler, type, success, fail) {
93
+ if (typeof handler !== "function") return this.then();
94
+ return this._then(success,
95
+ fail,
96
+ undefined,
97
+ new PassThroughHandlerContext(this, type, handler),
98
+ undefined);
99
+ };
100
+
101
+ Promise.prototype.lastly =
102
+ Promise.prototype["finally"] = function (handler) {
103
+ return this._passThrough(handler,
104
+ 0,
105
+ finallyHandler,
106
+ finallyHandler);
107
+ };
108
+
109
+
110
+ Promise.prototype.tap = function (handler) {
111
+ return this._passThrough(handler, 1, finallyHandler);
112
+ };
113
+
114
+ Promise.prototype.tapCatch = function (handlerOrPredicate) {
115
+ var len = arguments.length;
116
+ if(len === 1) {
117
+ return this._passThrough(handlerOrPredicate,
118
+ 1,
119
+ undefined,
120
+ finallyHandler);
121
+ } else {
122
+ var catchInstances = new Array(len - 1),
123
+ j = 0, i;
124
+ for (i = 0; i < len - 1; ++i) {
125
+ var item = arguments[i];
126
+ if (util.isObject(item)) {
127
+ catchInstances[j++] = item;
128
+ } else {
129
+ return Promise.reject(new TypeError(
130
+ "tapCatch statement predicate: "
131
+ + "expecting an object but got " + util.classString(item)
132
+ ));
133
+ }
134
+ }
135
+ catchInstances.length = j;
136
+ var handler = arguments[i];
137
+ return this._passThrough(catchFilter(catchInstances, handler, this),
138
+ 1,
139
+ undefined,
140
+ finallyHandler);
141
+ }
142
+
143
+ };
144
+
145
+ return PassThroughHandlerContext;
146
+ };
@@ -0,0 +1,223 @@
1
+ "use strict";
2
+ module.exports = function(Promise,
3
+ apiRejection,
4
+ INTERNAL,
5
+ tryConvertToPromise,
6
+ Proxyable,
7
+ debug) {
8
+ var errors = require("./errors");
9
+ var TypeError = errors.TypeError;
10
+ var util = require("./util");
11
+ var errorObj = util.errorObj;
12
+ var tryCatch = util.tryCatch;
13
+ var yieldHandlers = [];
14
+
15
+ function promiseFromYieldHandler(value, yieldHandlers, traceParent) {
16
+ for (var i = 0; i < yieldHandlers.length; ++i) {
17
+ traceParent._pushContext();
18
+ var result = tryCatch(yieldHandlers[i])(value);
19
+ traceParent._popContext();
20
+ if (result === errorObj) {
21
+ traceParent._pushContext();
22
+ var ret = Promise.reject(errorObj.e);
23
+ traceParent._popContext();
24
+ return ret;
25
+ }
26
+ var maybePromise = tryConvertToPromise(result, traceParent);
27
+ if (maybePromise instanceof Promise) return maybePromise;
28
+ }
29
+ return null;
30
+ }
31
+
32
+ function PromiseSpawn(generatorFunction, receiver, yieldHandler, stack) {
33
+ if (debug.cancellation()) {
34
+ var internal = new Promise(INTERNAL);
35
+ var _finallyPromise = this._finallyPromise = new Promise(INTERNAL);
36
+ this._promise = internal.lastly(function() {
37
+ return _finallyPromise;
38
+ });
39
+ internal._captureStackTrace();
40
+ internal._setOnCancel(this);
41
+ } else {
42
+ var promise = this._promise = new Promise(INTERNAL);
43
+ promise._captureStackTrace();
44
+ }
45
+ this._stack = stack;
46
+ this._generatorFunction = generatorFunction;
47
+ this._receiver = receiver;
48
+ this._generator = undefined;
49
+ this._yieldHandlers = typeof yieldHandler === "function"
50
+ ? [yieldHandler].concat(yieldHandlers)
51
+ : yieldHandlers;
52
+ this._yieldedPromise = null;
53
+ this._cancellationPhase = false;
54
+ }
55
+ util.inherits(PromiseSpawn, Proxyable);
56
+
57
+ PromiseSpawn.prototype._isResolved = function() {
58
+ return this._promise === null;
59
+ };
60
+
61
+ PromiseSpawn.prototype._cleanup = function() {
62
+ this._promise = this._generator = null;
63
+ if (debug.cancellation() && this._finallyPromise !== null) {
64
+ this._finallyPromise._fulfill();
65
+ this._finallyPromise = null;
66
+ }
67
+ };
68
+
69
+ PromiseSpawn.prototype._promiseCancelled = function() {
70
+ if (this._isResolved()) return;
71
+ var implementsReturn = typeof this._generator["return"] !== "undefined";
72
+
73
+ var result;
74
+ if (!implementsReturn) {
75
+ var reason = new Promise.CancellationError(
76
+ "generator .return() sentinel");
77
+ Promise.coroutine.returnSentinel = reason;
78
+ this._promise._attachExtraTrace(reason);
79
+ this._promise._pushContext();
80
+ result = tryCatch(this._generator["throw"]).call(this._generator,
81
+ reason);
82
+ this._promise._popContext();
83
+ } else {
84
+ this._promise._pushContext();
85
+ result = tryCatch(this._generator["return"]).call(this._generator,
86
+ undefined);
87
+ this._promise._popContext();
88
+ }
89
+ this._cancellationPhase = true;
90
+ this._yieldedPromise = null;
91
+ this._continue(result);
92
+ };
93
+
94
+ PromiseSpawn.prototype._promiseFulfilled = function(value) {
95
+ this._yieldedPromise = null;
96
+ this._promise._pushContext();
97
+ var result = tryCatch(this._generator.next).call(this._generator, value);
98
+ this._promise._popContext();
99
+ this._continue(result);
100
+ };
101
+
102
+ PromiseSpawn.prototype._promiseRejected = function(reason) {
103
+ this._yieldedPromise = null;
104
+ this._promise._attachExtraTrace(reason);
105
+ this._promise._pushContext();
106
+ var result = tryCatch(this._generator["throw"])
107
+ .call(this._generator, reason);
108
+ this._promise._popContext();
109
+ this._continue(result);
110
+ };
111
+
112
+ PromiseSpawn.prototype._resultCancelled = function() {
113
+ if (this._yieldedPromise instanceof Promise) {
114
+ var promise = this._yieldedPromise;
115
+ this._yieldedPromise = null;
116
+ promise.cancel();
117
+ }
118
+ };
119
+
120
+ PromiseSpawn.prototype.promise = function () {
121
+ return this._promise;
122
+ };
123
+
124
+ PromiseSpawn.prototype._run = function () {
125
+ this._generator = this._generatorFunction.call(this._receiver);
126
+ this._receiver =
127
+ this._generatorFunction = undefined;
128
+ this._promiseFulfilled(undefined);
129
+ };
130
+
131
+ PromiseSpawn.prototype._continue = function (result) {
132
+ var promise = this._promise;
133
+ if (result === errorObj) {
134
+ this._cleanup();
135
+ if (this._cancellationPhase) {
136
+ return promise.cancel();
137
+ } else {
138
+ return promise._rejectCallback(result.e, false);
139
+ }
140
+ }
141
+
142
+ var value = result.value;
143
+ if (result.done === true) {
144
+ this._cleanup();
145
+ if (this._cancellationPhase) {
146
+ return promise.cancel();
147
+ } else {
148
+ return promise._resolveCallback(value);
149
+ }
150
+ } else {
151
+ var maybePromise = tryConvertToPromise(value, this._promise);
152
+ if (!(maybePromise instanceof Promise)) {
153
+ maybePromise =
154
+ promiseFromYieldHandler(maybePromise,
155
+ this._yieldHandlers,
156
+ this._promise);
157
+ if (maybePromise === null) {
158
+ this._promiseRejected(
159
+ new TypeError(
160
+ "A value %s was yielded that could not be treated as a promise\u000a\u000a See http://goo.gl/MqrFmX\u000a\u000a".replace("%s", String(value)) +
161
+ "From coroutine:\u000a" +
162
+ this._stack.split("\n").slice(1, -7).join("\n")
163
+ )
164
+ );
165
+ return;
166
+ }
167
+ }
168
+ maybePromise = maybePromise._target();
169
+ var bitField = maybePromise._bitField;
170
+ ;
171
+ if (((bitField & 50397184) === 0)) {
172
+ this._yieldedPromise = maybePromise;
173
+ maybePromise._proxy(this, null);
174
+ } else if (((bitField & 33554432) !== 0)) {
175
+ Promise._async.invoke(
176
+ this._promiseFulfilled, this, maybePromise._value()
177
+ );
178
+ } else if (((bitField & 16777216) !== 0)) {
179
+ Promise._async.invoke(
180
+ this._promiseRejected, this, maybePromise._reason()
181
+ );
182
+ } else {
183
+ this._promiseCancelled();
184
+ }
185
+ }
186
+ };
187
+
188
+ Promise.coroutine = function (generatorFunction, options) {
189
+ if (typeof generatorFunction !== "function") {
190
+ throw new TypeError("generatorFunction must be a function\u000a\u000a See http://goo.gl/MqrFmX\u000a");
191
+ }
192
+ var yieldHandler = Object(options).yieldHandler;
193
+ var PromiseSpawn$ = PromiseSpawn;
194
+ var stack = new Error().stack;
195
+ return function () {
196
+ var generator = generatorFunction.apply(this, arguments);
197
+ var spawn = new PromiseSpawn$(undefined, undefined, yieldHandler,
198
+ stack);
199
+ var ret = spawn.promise();
200
+ spawn._generator = generator;
201
+ spawn._promiseFulfilled(undefined);
202
+ return ret;
203
+ };
204
+ };
205
+
206
+ Promise.coroutine.addYieldHandler = function(fn) {
207
+ if (typeof fn !== "function") {
208
+ throw new TypeError("expecting a function but got " + util.classString(fn));
209
+ }
210
+ yieldHandlers.push(fn);
211
+ };
212
+
213
+ Promise.spawn = function (generatorFunction) {
214
+ debug.deprecated("Promise.spawn()", "Promise.coroutine()");
215
+ if (typeof generatorFunction !== "function") {
216
+ return apiRejection("generatorFunction must be a function\u000a\u000a See http://goo.gl/MqrFmX\u000a");
217
+ }
218
+ var spawn = new PromiseSpawn(generatorFunction, this);
219
+ var ret = spawn.promise();
220
+ spawn._run(Promise.spawn);
221
+ return ret;
222
+ };
223
+ };