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,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,98 @@
1
+ "use strict";
2
+ module.exports = function(Promise, NEXT_FILTER, tryConvertToPromise) {
3
+ var util = require("./util.js");
4
+ var isPrimitive = util.isPrimitive;
5
+ var thrower = util.thrower;
6
+
7
+ function returnThis() {
8
+ return this;
9
+ }
10
+ function throwThis() {
11
+ throw this;
12
+ }
13
+ function return$(r) {
14
+ return function() {
15
+ return r;
16
+ };
17
+ }
18
+ function throw$(r) {
19
+ return function() {
20
+ throw r;
21
+ };
22
+ }
23
+ function promisedFinally(ret, reasonOrValue, isFulfilled) {
24
+ var then;
25
+ if (isPrimitive(reasonOrValue)) {
26
+ then = isFulfilled ? return$(reasonOrValue) : throw$(reasonOrValue);
27
+ } else {
28
+ then = isFulfilled ? returnThis : throwThis;
29
+ }
30
+ return ret._then(then, thrower, undefined, reasonOrValue, undefined);
31
+ }
32
+
33
+ function finallyHandler(reasonOrValue) {
34
+ var promise = this.promise;
35
+ var handler = this.handler;
36
+
37
+ var ret = promise._isBound()
38
+ ? handler.call(promise._boundValue())
39
+ : handler();
40
+
41
+ if (ret !== undefined) {
42
+ var maybePromise = tryConvertToPromise(ret, promise);
43
+ if (maybePromise instanceof Promise) {
44
+ maybePromise = maybePromise._target();
45
+ return promisedFinally(maybePromise, reasonOrValue,
46
+ promise.isFulfilled());
47
+ }
48
+ }
49
+
50
+ if (promise.isRejected()) {
51
+ NEXT_FILTER.e = reasonOrValue;
52
+ return NEXT_FILTER;
53
+ } else {
54
+ return reasonOrValue;
55
+ }
56
+ }
57
+
58
+ function tapHandler(value) {
59
+ var promise = this.promise;
60
+ var handler = this.handler;
61
+
62
+ var ret = promise._isBound()
63
+ ? handler.call(promise._boundValue(), value)
64
+ : handler(value);
65
+
66
+ if (ret !== undefined) {
67
+ var maybePromise = tryConvertToPromise(ret, promise);
68
+ if (maybePromise instanceof Promise) {
69
+ maybePromise = maybePromise._target();
70
+ return promisedFinally(maybePromise, value, true);
71
+ }
72
+ }
73
+ return value;
74
+ }
75
+
76
+ Promise.prototype._passThroughHandler = function (handler, isFinally) {
77
+ if (typeof handler !== "function") return this.then();
78
+
79
+ var promiseAndHandler = {
80
+ promise: this,
81
+ handler: handler
82
+ };
83
+
84
+ return this._then(
85
+ isFinally ? finallyHandler : tapHandler,
86
+ isFinally ? finallyHandler : undefined, undefined,
87
+ promiseAndHandler, undefined);
88
+ };
89
+
90
+ Promise.prototype.lastly =
91
+ Promise.prototype["finally"] = function (handler) {
92
+ return this._passThroughHandler(handler, true);
93
+ };
94
+
95
+ Promise.prototype.tap = function (handler) {
96
+ return this._passThroughHandler(handler, false);
97
+ };
98
+ };
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ module.exports = function(Promise,
3
+ apiRejection,
4
+ INTERNAL,
5
+ tryConvertToPromise) {
6
+ var errors = require("./errors.js");
7
+ var TypeError = errors.TypeError;
8
+ var util = require("./util.js");
9
+ var errorObj = util.errorObj;
10
+ var tryCatch = util.tryCatch;
11
+ var yieldHandlers = [];
12
+
13
+ function promiseFromYieldHandler(value, yieldHandlers, traceParent) {
14
+ for (var i = 0; i < yieldHandlers.length; ++i) {
15
+ traceParent._pushContext();
16
+ var result = tryCatch(yieldHandlers[i])(value);
17
+ traceParent._popContext();
18
+ if (result === errorObj) {
19
+ traceParent._pushContext();
20
+ var ret = Promise.reject(errorObj.e);
21
+ traceParent._popContext();
22
+ return ret;
23
+ }
24
+ var maybePromise = tryConvertToPromise(result, traceParent);
25
+ if (maybePromise instanceof Promise) return maybePromise;
26
+ }
27
+ return null;
28
+ }
29
+
30
+ function PromiseSpawn(generatorFunction, receiver, yieldHandler, stack) {
31
+ var promise = this._promise = new Promise(INTERNAL);
32
+ promise._captureStackTrace();
33
+ this._stack = stack;
34
+ this._generatorFunction = generatorFunction;
35
+ this._receiver = receiver;
36
+ this._generator = undefined;
37
+ this._yieldHandlers = typeof yieldHandler === "function"
38
+ ? [yieldHandler].concat(yieldHandlers)
39
+ : yieldHandlers;
40
+ }
41
+
42
+ PromiseSpawn.prototype.promise = function () {
43
+ return this._promise;
44
+ };
45
+
46
+ PromiseSpawn.prototype._run = function () {
47
+ this._generator = this._generatorFunction.call(this._receiver);
48
+ this._receiver =
49
+ this._generatorFunction = undefined;
50
+ this._next(undefined);
51
+ };
52
+
53
+ PromiseSpawn.prototype._continue = function (result) {
54
+ if (result === errorObj) {
55
+ return this._promise._rejectCallback(result.e, false, true);
56
+ }
57
+
58
+ var value = result.value;
59
+ if (result.done === true) {
60
+ this._promise._resolveCallback(value);
61
+ } else {
62
+ var maybePromise = tryConvertToPromise(value, this._promise);
63
+ if (!(maybePromise instanceof Promise)) {
64
+ maybePromise =
65
+ promiseFromYieldHandler(maybePromise,
66
+ this._yieldHandlers,
67
+ this._promise);
68
+ if (maybePromise === null) {
69
+ this._throw(
70
+ new TypeError(
71
+ "A value %s was yielded that could not be treated as a promise\u000a\u000a See http://goo.gl/4Y4pDk\u000a\u000a".replace("%s", value) +
72
+ "From coroutine:\u000a" +
73
+ this._stack.split("\n").slice(1, -7).join("\n")
74
+ )
75
+ );
76
+ return;
77
+ }
78
+ }
79
+ maybePromise._then(
80
+ this._next,
81
+ this._throw,
82
+ undefined,
83
+ this,
84
+ null
85
+ );
86
+ }
87
+ };
88
+
89
+ PromiseSpawn.prototype._throw = function (reason) {
90
+ this._promise._attachExtraTrace(reason);
91
+ this._promise._pushContext();
92
+ var result = tryCatch(this._generator["throw"])
93
+ .call(this._generator, reason);
94
+ this._promise._popContext();
95
+ this._continue(result);
96
+ };
97
+
98
+ PromiseSpawn.prototype._next = function (value) {
99
+ this._promise._pushContext();
100
+ var result = tryCatch(this._generator.next).call(this._generator, value);
101
+ this._promise._popContext();
102
+ this._continue(result);
103
+ };
104
+
105
+ Promise.coroutine = function (generatorFunction, options) {
106
+ if (typeof generatorFunction !== "function") {
107
+ throw new TypeError("generatorFunction must be a function\u000a\u000a See http://goo.gl/6Vqhm0\u000a");
108
+ }
109
+ var yieldHandler = Object(options).yieldHandler;
110
+ var PromiseSpawn$ = PromiseSpawn;
111
+ var stack = new Error().stack;
112
+ return function () {
113
+ var generator = generatorFunction.apply(this, arguments);
114
+ var spawn = new PromiseSpawn$(undefined, undefined, yieldHandler,
115
+ stack);
116
+ spawn._generator = generator;
117
+ spawn._next(undefined);
118
+ return spawn.promise();
119
+ };
120
+ };
121
+
122
+ Promise.coroutine.addYieldHandler = function(fn) {
123
+ if (typeof fn !== "function") throw new TypeError("fn must be a function\u000a\u000a See http://goo.gl/916lJJ\u000a");
124
+ yieldHandlers.push(fn);
125
+ };
126
+
127
+ Promise.spawn = function (generatorFunction) {
128
+ if (typeof generatorFunction !== "function") {
129
+ return apiRejection("generatorFunction must be a function\u000a\u000a See http://goo.gl/6Vqhm0\u000a");
130
+ }
131
+ var spawn = new PromiseSpawn(generatorFunction, this);
132
+ var ret = spawn.promise();
133
+ spawn._run(Promise.spawn);
134
+ return ret;
135
+ };
136
+ };
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ module.exports =
3
+ function(Promise, PromiseArray, tryConvertToPromise, INTERNAL) {
4
+ var util = require("./util.js");
5
+ var canEvaluate = util.canEvaluate;
6
+ var tryCatch = util.tryCatch;
7
+ var errorObj = util.errorObj;
8
+ var reject;
9
+
10
+ if (!false) {
11
+ if (canEvaluate) {
12
+ var thenCallback = function(i) {
13
+ return new Function("value", "holder", " \n\
14
+ 'use strict'; \n\
15
+ holder.pIndex = value; \n\
16
+ holder.checkFulfillment(this); \n\
17
+ ".replace(/Index/g, i));
18
+ };
19
+
20
+ var caller = function(count) {
21
+ var values = [];
22
+ for (var i = 1; i <= count; ++i) values.push("holder.p" + i);
23
+ return new Function("holder", " \n\
24
+ 'use strict'; \n\
25
+ var callback = holder.fn; \n\
26
+ return callback(values); \n\
27
+ ".replace(/values/g, values.join(", ")));
28
+ };
29
+ var thenCallbacks = [];
30
+ var callers = [undefined];
31
+ for (var i = 1; i <= 5; ++i) {
32
+ thenCallbacks.push(thenCallback(i));
33
+ callers.push(caller(i));
34
+ }
35
+
36
+ var Holder = function(total, fn) {
37
+ this.p1 = this.p2 = this.p3 = this.p4 = this.p5 = null;
38
+ this.fn = fn;
39
+ this.total = total;
40
+ this.now = 0;
41
+ };
42
+
43
+ Holder.prototype.callers = callers;
44
+ Holder.prototype.checkFulfillment = function(promise) {
45
+ var now = this.now;
46
+ now++;
47
+ var total = this.total;
48
+ if (now >= total) {
49
+ var handler = this.callers[total];
50
+ promise._pushContext();
51
+ var ret = tryCatch(handler)(this);
52
+ promise._popContext();
53
+ if (ret === errorObj) {
54
+ promise._rejectCallback(ret.e, false, true);
55
+ } else {
56
+ promise._resolveCallback(ret);
57
+ }
58
+ } else {
59
+ this.now = now;
60
+ }
61
+ };
62
+
63
+ var reject = function (reason) {
64
+ this._reject(reason);
65
+ };
66
+ }
67
+ }
68
+
69
+ Promise.join = function () {
70
+ var last = arguments.length - 1;
71
+ var fn;
72
+ if (last > 0 && typeof arguments[last] === "function") {
73
+ fn = arguments[last];
74
+ if (!false) {
75
+ if (last < 6 && canEvaluate) {
76
+ var ret = new Promise(INTERNAL);
77
+ ret._captureStackTrace();
78
+ var holder = new Holder(last, fn);
79
+ var callbacks = thenCallbacks;
80
+ for (var i = 0; i < last; ++i) {
81
+ var maybePromise = tryConvertToPromise(arguments[i], ret);
82
+ if (maybePromise instanceof Promise) {
83
+ maybePromise = maybePromise._target();
84
+ if (maybePromise._isPending()) {
85
+ maybePromise._then(callbacks[i], reject,
86
+ undefined, ret, holder);
87
+ } else if (maybePromise._isFulfilled()) {
88
+ callbacks[i].call(ret,
89
+ maybePromise._value(), holder);
90
+ } else {
91
+ ret._reject(maybePromise._reason());
92
+ }
93
+ } else {
94
+ callbacks[i].call(ret, maybePromise, holder);
95
+ }
96
+ }
97
+ return ret;
98
+ }
99
+ }
100
+ }
101
+ var $_len = arguments.length;var args = new Array($_len); for(var $_i = 0; $_i < $_len; ++$_i) {args[$_i] = arguments[$_i];}
102
+ if (fn) args.pop();
103
+ var ret = new PromiseArray(args).promise();
104
+ return fn !== undefined ? ret.spread(fn) : ret;
105
+ };
106
+
107
+ };
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ module.exports = function(Promise,
3
+ PromiseArray,
4
+ apiRejection,
5
+ tryConvertToPromise,
6
+ INTERNAL) {
7
+ var getDomain = Promise._getDomain;
8
+ var async = require("./async.js");
9
+ var util = require("./util.js");
10
+ var tryCatch = util.tryCatch;
11
+ var errorObj = util.errorObj;
12
+ var PENDING = {};
13
+ var EMPTY_ARRAY = [];
14
+
15
+ function MappingPromiseArray(promises, fn, limit, _filter) {
16
+ this.constructor$(promises);
17
+ this._promise._captureStackTrace();
18
+ var domain = getDomain();
19
+ this._callback = domain === null ? fn : domain.bind(fn);
20
+ this._preservedValues = _filter === INTERNAL
21
+ ? new Array(this.length())
22
+ : null;
23
+ this._limit = limit;
24
+ this._inFlight = 0;
25
+ this._queue = limit >= 1 ? [] : EMPTY_ARRAY;
26
+ async.invoke(init, this, undefined);
27
+ }
28
+ util.inherits(MappingPromiseArray, PromiseArray);
29
+ function init() {this._init$(undefined, -2);}
30
+
31
+ MappingPromiseArray.prototype._init = function () {};
32
+
33
+ MappingPromiseArray.prototype._promiseFulfilled = function (value, index) {
34
+ var values = this._values;
35
+ var length = this.length();
36
+ var preservedValues = this._preservedValues;
37
+ var limit = this._limit;
38
+ if (values[index] === PENDING) {
39
+ values[index] = value;
40
+ if (limit >= 1) {
41
+ this._inFlight--;
42
+ this._drainQueue();
43
+ if (this._isResolved()) return;
44
+ }
45
+ } else {
46
+ if (limit >= 1 && this._inFlight >= limit) {
47
+ values[index] = value;
48
+ this._queue.push(index);
49
+ return;
50
+ }
51
+ if (preservedValues !== null) preservedValues[index] = value;
52
+
53
+ var callback = this._callback;
54
+ var receiver = this._promise._boundValue();
55
+ this._promise._pushContext();
56
+ var ret = tryCatch(callback).call(receiver, value, index, length);
57
+ this._promise._popContext();
58
+ if (ret === errorObj) return this._reject(ret.e);
59
+
60
+ var maybePromise = tryConvertToPromise(ret, this._promise);
61
+ if (maybePromise instanceof Promise) {
62
+ maybePromise = maybePromise._target();
63
+ if (maybePromise._isPending()) {
64
+ if (limit >= 1) this._inFlight++;
65
+ values[index] = PENDING;
66
+ return maybePromise._proxyPromiseArray(this, index);
67
+ } else if (maybePromise._isFulfilled()) {
68
+ ret = maybePromise._value();
69
+ } else {
70
+ return this._reject(maybePromise._reason());
71
+ }
72
+ }
73
+ values[index] = ret;
74
+ }
75
+ var totalResolved = ++this._totalResolved;
76
+ if (totalResolved >= length) {
77
+ if (preservedValues !== null) {
78
+ this._filter(values, preservedValues);
79
+ } else {
80
+ this._resolve(values);
81
+ }
82
+
83
+ }
84
+ };
85
+
86
+ MappingPromiseArray.prototype._drainQueue = function () {
87
+ var queue = this._queue;
88
+ var limit = this._limit;
89
+ var values = this._values;
90
+ while (queue.length > 0 && this._inFlight < limit) {
91
+ if (this._isResolved()) return;
92
+ var index = queue.pop();
93
+ this._promiseFulfilled(values[index], index);
94
+ }
95
+ };
96
+
97
+ MappingPromiseArray.prototype._filter = function (booleans, values) {
98
+ var len = values.length;
99
+ var ret = new Array(len);
100
+ var j = 0;
101
+ for (var i = 0; i < len; ++i) {
102
+ if (booleans[i]) ret[j++] = values[i];
103
+ }
104
+ ret.length = j;
105
+ this._resolve(ret);
106
+ };
107
+
108
+ MappingPromiseArray.prototype.preservedValues = function () {
109
+ return this._preservedValues;
110
+ };
111
+
112
+ function map(promises, fn, options, _filter) {
113
+ var limit = typeof options === "object" && options !== null
114
+ ? options.concurrency
115
+ : 0;
116
+ limit = typeof limit === "number" &&
117
+ isFinite(limit) && limit >= 1 ? limit : 0;
118
+ return new MappingPromiseArray(promises, fn, limit, _filter);
119
+ }
120
+
121
+ Promise.prototype.map = function (fn, options) {
122
+ if (typeof fn !== "function") return apiRejection("fn must be a function\u000a\u000a See http://goo.gl/916lJJ\u000a");
123
+
124
+ return map(this, fn, options, null).promise();
125
+ };
126
+
127
+ Promise.map = function (promises, fn, options, _filter) {
128
+ if (typeof fn !== "function") return apiRejection("fn must be a function\u000a\u000a See http://goo.gl/916lJJ\u000a");
129
+ return map(promises, fn, options, _filter).promise();
130
+ };
131
+
132
+
133
+ };