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,43 @@
1
+ "use strict";
2
+ module.exports =
3
+ function(Promise, PromiseArray, debug) {
4
+ var PromiseInspection = Promise.PromiseInspection;
5
+ var util = require("./util");
6
+
7
+ function SettledPromiseArray(values) {
8
+ this.constructor$(values);
9
+ }
10
+ util.inherits(SettledPromiseArray, PromiseArray);
11
+
12
+ SettledPromiseArray.prototype._promiseResolved = function (index, inspection) {
13
+ this._values[index] = inspection;
14
+ var totalResolved = ++this._totalResolved;
15
+ if (totalResolved >= this._length) {
16
+ this._resolve(this._values);
17
+ return true;
18
+ }
19
+ return false;
20
+ };
21
+
22
+ SettledPromiseArray.prototype._promiseFulfilled = function (value, index) {
23
+ var ret = new PromiseInspection();
24
+ ret._bitField = 33554432;
25
+ ret._settledValueField = value;
26
+ return this._promiseResolved(index, ret);
27
+ };
28
+ SettledPromiseArray.prototype._promiseRejected = function (reason, index) {
29
+ var ret = new PromiseInspection();
30
+ ret._bitField = 16777216;
31
+ ret._settledValueField = reason;
32
+ return this._promiseResolved(index, ret);
33
+ };
34
+
35
+ Promise.settle = function (promises) {
36
+ debug.deprecated(".settle()", ".reflect()");
37
+ return new SettledPromiseArray(promises).promise();
38
+ };
39
+
40
+ Promise.prototype.settle = function () {
41
+ return Promise.settle(this);
42
+ };
43
+ };
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ module.exports =
3
+ function(Promise, PromiseArray, apiRejection) {
4
+ var util = require("./util");
5
+ var RangeError = require("./errors").RangeError;
6
+ var AggregateError = require("./errors").AggregateError;
7
+ var isArray = util.isArray;
8
+ var CANCELLATION = {};
9
+
10
+
11
+ function SomePromiseArray(values) {
12
+ this.constructor$(values);
13
+ this._howMany = 0;
14
+ this._unwrap = false;
15
+ this._initialized = false;
16
+ }
17
+ util.inherits(SomePromiseArray, PromiseArray);
18
+
19
+ SomePromiseArray.prototype._init = function () {
20
+ if (!this._initialized) {
21
+ return;
22
+ }
23
+ if (this._howMany === 0) {
24
+ this._resolve([]);
25
+ return;
26
+ }
27
+ this._init$(undefined, -5);
28
+ var isArrayResolved = isArray(this._values);
29
+ if (!this._isResolved() &&
30
+ isArrayResolved &&
31
+ this._howMany > this._canPossiblyFulfill()) {
32
+ this._reject(this._getRangeError(this.length()));
33
+ }
34
+ };
35
+
36
+ SomePromiseArray.prototype.init = function () {
37
+ this._initialized = true;
38
+ this._init();
39
+ };
40
+
41
+ SomePromiseArray.prototype.setUnwrap = function () {
42
+ this._unwrap = true;
43
+ };
44
+
45
+ SomePromiseArray.prototype.howMany = function () {
46
+ return this._howMany;
47
+ };
48
+
49
+ SomePromiseArray.prototype.setHowMany = function (count) {
50
+ this._howMany = count;
51
+ };
52
+
53
+ SomePromiseArray.prototype._promiseFulfilled = function (value) {
54
+ this._addFulfilled(value);
55
+ if (this._fulfilled() === this.howMany()) {
56
+ this._values.length = this.howMany();
57
+ if (this.howMany() === 1 && this._unwrap) {
58
+ this._resolve(this._values[0]);
59
+ } else {
60
+ this._resolve(this._values);
61
+ }
62
+ return true;
63
+ }
64
+ return false;
65
+
66
+ };
67
+ SomePromiseArray.prototype._promiseRejected = function (reason) {
68
+ this._addRejected(reason);
69
+ return this._checkOutcome();
70
+ };
71
+
72
+ SomePromiseArray.prototype._promiseCancelled = function () {
73
+ if (this._values instanceof Promise || this._values == null) {
74
+ return this._cancel();
75
+ }
76
+ this._addRejected(CANCELLATION);
77
+ return this._checkOutcome();
78
+ };
79
+
80
+ SomePromiseArray.prototype._checkOutcome = function() {
81
+ if (this.howMany() > this._canPossiblyFulfill()) {
82
+ var e = new AggregateError();
83
+ for (var i = this.length(); i < this._values.length; ++i) {
84
+ if (this._values[i] !== CANCELLATION) {
85
+ e.push(this._values[i]);
86
+ }
87
+ }
88
+ if (e.length > 0) {
89
+ this._reject(e);
90
+ } else {
91
+ this._cancel();
92
+ }
93
+ return true;
94
+ }
95
+ return false;
96
+ };
97
+
98
+ SomePromiseArray.prototype._fulfilled = function () {
99
+ return this._totalResolved;
100
+ };
101
+
102
+ SomePromiseArray.prototype._rejected = function () {
103
+ return this._values.length - this.length();
104
+ };
105
+
106
+ SomePromiseArray.prototype._addRejected = function (reason) {
107
+ this._values.push(reason);
108
+ };
109
+
110
+ SomePromiseArray.prototype._addFulfilled = function (value) {
111
+ this._values[this._totalResolved++] = value;
112
+ };
113
+
114
+ SomePromiseArray.prototype._canPossiblyFulfill = function () {
115
+ return this.length() - this._rejected();
116
+ };
117
+
118
+ SomePromiseArray.prototype._getRangeError = function (count) {
119
+ var message = "Input array must contain at least " +
120
+ this._howMany + " items but contains only " + count + " items";
121
+ return new RangeError(message);
122
+ };
123
+
124
+ SomePromiseArray.prototype._resolveEmptyArray = function () {
125
+ this._reject(this._getRangeError(0));
126
+ };
127
+
128
+ function some(promises, howMany) {
129
+ if ((howMany | 0) !== howMany || howMany < 0) {
130
+ return apiRejection("expecting a positive integer\u000a\u000a See http://goo.gl/MqrFmX\u000a");
131
+ }
132
+ var ret = new SomePromiseArray(promises);
133
+ var promise = ret.promise();
134
+ ret.setHowMany(howMany);
135
+ ret.init();
136
+ return promise;
137
+ }
138
+
139
+ Promise.some = function (promises, howMany) {
140
+ return some(promises, howMany);
141
+ };
142
+
143
+ Promise.prototype.some = function (howMany) {
144
+ return some(this, howMany);
145
+ };
146
+
147
+ Promise._SomePromiseArray = SomePromiseArray;
148
+ };
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ module.exports = function(Promise) {
3
+ function PromiseInspection(promise) {
4
+ if (promise !== undefined) {
5
+ promise = promise._target();
6
+ this._bitField = promise._bitField;
7
+ this._settledValueField = promise._isFateSealed()
8
+ ? promise._settledValue() : undefined;
9
+ }
10
+ else {
11
+ this._bitField = 0;
12
+ this._settledValueField = undefined;
13
+ }
14
+ }
15
+
16
+ PromiseInspection.prototype._settledValue = function() {
17
+ return this._settledValueField;
18
+ };
19
+
20
+ var value = PromiseInspection.prototype.value = function () {
21
+ if (!this.isFulfilled()) {
22
+ throw new TypeError("cannot get fulfillment value of a non-fulfilled promise\u000a\u000a See http://goo.gl/MqrFmX\u000a");
23
+ }
24
+ return this._settledValue();
25
+ };
26
+
27
+ var reason = PromiseInspection.prototype.error =
28
+ PromiseInspection.prototype.reason = function () {
29
+ if (!this.isRejected()) {
30
+ throw new TypeError("cannot get rejection reason of a non-rejected promise\u000a\u000a See http://goo.gl/MqrFmX\u000a");
31
+ }
32
+ return this._settledValue();
33
+ };
34
+
35
+ var isFulfilled = PromiseInspection.prototype.isFulfilled = function() {
36
+ return (this._bitField & 33554432) !== 0;
37
+ };
38
+
39
+ var isRejected = PromiseInspection.prototype.isRejected = function () {
40
+ return (this._bitField & 16777216) !== 0;
41
+ };
42
+
43
+ var isPending = PromiseInspection.prototype.isPending = function () {
44
+ return (this._bitField & 50397184) === 0;
45
+ };
46
+
47
+ var isResolved = PromiseInspection.prototype.isResolved = function () {
48
+ return (this._bitField & 50331648) !== 0;
49
+ };
50
+
51
+ PromiseInspection.prototype.isCancelled = function() {
52
+ return (this._bitField & 8454144) !== 0;
53
+ };
54
+
55
+ Promise.prototype.__isCancelled = function() {
56
+ return (this._bitField & 65536) === 65536;
57
+ };
58
+
59
+ Promise.prototype._isCancelled = function() {
60
+ return this._target().__isCancelled();
61
+ };
62
+
63
+ Promise.prototype.isCancelled = function() {
64
+ return (this._target()._bitField & 8454144) !== 0;
65
+ };
66
+
67
+ Promise.prototype.isPending = function() {
68
+ return isPending.call(this._target());
69
+ };
70
+
71
+ Promise.prototype.isRejected = function() {
72
+ return isRejected.call(this._target());
73
+ };
74
+
75
+ Promise.prototype.isFulfilled = function() {
76
+ return isFulfilled.call(this._target());
77
+ };
78
+
79
+ Promise.prototype.isResolved = function() {
80
+ return isResolved.call(this._target());
81
+ };
82
+
83
+ Promise.prototype.value = function() {
84
+ return value.call(this._target());
85
+ };
86
+
87
+ Promise.prototype.reason = function() {
88
+ var target = this._target();
89
+ target._unsetRejectionIsUnhandled();
90
+ return reason.call(target);
91
+ };
92
+
93
+ Promise.prototype._value = function() {
94
+ return this._settledValue();
95
+ };
96
+
97
+ Promise.prototype._reason = function() {
98
+ this._unsetRejectionIsUnhandled();
99
+ return this._settledValue();
100
+ };
101
+
102
+ Promise.PromiseInspection = PromiseInspection;
103
+ };
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ module.exports = function(Promise, INTERNAL) {
3
+ var util = require("./util");
4
+ var errorObj = util.errorObj;
5
+ var isObject = util.isObject;
6
+
7
+ function tryConvertToPromise(obj, context) {
8
+ if (isObject(obj)) {
9
+ if (obj instanceof Promise) return obj;
10
+ var then = getThen(obj);
11
+ if (then === errorObj) {
12
+ if (context) context._pushContext();
13
+ var ret = Promise.reject(then.e);
14
+ if (context) context._popContext();
15
+ return ret;
16
+ } else if (typeof then === "function") {
17
+ if (isAnyBluebirdPromise(obj)) {
18
+ var ret = new Promise(INTERNAL);
19
+ obj._then(
20
+ ret._fulfill,
21
+ ret._reject,
22
+ undefined,
23
+ ret,
24
+ null
25
+ );
26
+ return ret;
27
+ }
28
+ return doThenable(obj, then, context);
29
+ }
30
+ }
31
+ return obj;
32
+ }
33
+
34
+ function doGetThen(obj) {
35
+ return obj.then;
36
+ }
37
+
38
+ function getThen(obj) {
39
+ try {
40
+ return doGetThen(obj);
41
+ } catch (e) {
42
+ errorObj.e = e;
43
+ return errorObj;
44
+ }
45
+ }
46
+
47
+ var hasProp = {}.hasOwnProperty;
48
+ function isAnyBluebirdPromise(obj) {
49
+ try {
50
+ return hasProp.call(obj, "_promise0");
51
+ } catch (e) {
52
+ return false;
53
+ }
54
+ }
55
+
56
+ function doThenable(x, then, context) {
57
+ var promise = new Promise(INTERNAL);
58
+ var ret = promise;
59
+ if (context) context._pushContext();
60
+ promise._captureStackTrace();
61
+ if (context) context._popContext();
62
+ var synchronous = true;
63
+ var result = util.tryCatch(then).call(x, resolve, reject);
64
+ synchronous = false;
65
+
66
+ if (promise && result === errorObj) {
67
+ promise._rejectCallback(result.e, true, true);
68
+ promise = null;
69
+ }
70
+
71
+ function resolve(value) {
72
+ if (!promise) return;
73
+ promise._resolveCallback(value);
74
+ promise = null;
75
+ }
76
+
77
+ function reject(reason) {
78
+ if (!promise) return;
79
+ promise._rejectCallback(reason, synchronous, true);
80
+ promise = null;
81
+ }
82
+ return ret;
83
+ }
84
+
85
+ return tryConvertToPromise;
86
+ };
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ module.exports = function(Promise, INTERNAL, debug) {
3
+ var util = require("./util");
4
+ var TimeoutError = Promise.TimeoutError;
5
+
6
+ function HandleWrapper(handle) {
7
+ this.handle = handle;
8
+ }
9
+
10
+ HandleWrapper.prototype._resultCancelled = function() {
11
+ clearTimeout(this.handle);
12
+ };
13
+
14
+ var afterValue = function(value) { return delay(+this).thenReturn(value); };
15
+ var delay = Promise.delay = function (ms, value) {
16
+ var ret;
17
+ var handle;
18
+ if (value !== undefined) {
19
+ ret = Promise.resolve(value)
20
+ ._then(afterValue, null, null, ms, undefined);
21
+ if (debug.cancellation() && value instanceof Promise) {
22
+ ret._setOnCancel(value);
23
+ }
24
+ } else {
25
+ ret = new Promise(INTERNAL);
26
+ handle = setTimeout(function() { ret._fulfill(); }, +ms);
27
+ if (debug.cancellation()) {
28
+ ret._setOnCancel(new HandleWrapper(handle));
29
+ }
30
+ ret._captureStackTrace();
31
+ }
32
+ ret._setAsyncGuaranteed();
33
+ return ret;
34
+ };
35
+
36
+ Promise.prototype.delay = function (ms) {
37
+ return delay(ms, this);
38
+ };
39
+
40
+ var afterTimeout = function (promise, message, parent) {
41
+ var err;
42
+ if (typeof message !== "string") {
43
+ if (message instanceof Error) {
44
+ err = message;
45
+ } else {
46
+ err = new TimeoutError("operation timed out");
47
+ }
48
+ } else {
49
+ err = new TimeoutError(message);
50
+ }
51
+ util.markAsOriginatingFromRejection(err);
52
+ promise._attachExtraTrace(err);
53
+ promise._reject(err);
54
+
55
+ if (parent != null) {
56
+ parent.cancel();
57
+ }
58
+ };
59
+
60
+ function successClear(value) {
61
+ clearTimeout(this.handle);
62
+ return value;
63
+ }
64
+
65
+ function failureClear(reason) {
66
+ clearTimeout(this.handle);
67
+ throw reason;
68
+ }
69
+
70
+ Promise.prototype.timeout = function (ms, message) {
71
+ ms = +ms;
72
+ var ret, parent;
73
+
74
+ var handleWrapper = new HandleWrapper(setTimeout(function timeoutTimeout() {
75
+ if (ret.isPending()) {
76
+ afterTimeout(ret, message, parent);
77
+ }
78
+ }, ms));
79
+
80
+ if (debug.cancellation()) {
81
+ parent = this.then();
82
+ ret = parent._then(successClear, failureClear,
83
+ undefined, handleWrapper, undefined);
84
+ ret._setOnCancel(handleWrapper);
85
+ } else {
86
+ ret = this._then(successClear, failureClear,
87
+ undefined, handleWrapper, undefined);
88
+ }
89
+
90
+ return ret;
91
+ };
92
+
93
+ };