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,79 @@
1
+ "use strict";
2
+ module.exports = function(
3
+ Promise, PromiseArray, tryConvertToPromise, apiRejection) {
4
+ var util = require("./util.js");
5
+ var isObject = util.isObject;
6
+ var es5 = require("./es5.js");
7
+
8
+ function PropertiesPromiseArray(obj) {
9
+ var keys = es5.keys(obj);
10
+ var len = keys.length;
11
+ var values = new Array(len * 2);
12
+ for (var i = 0; i < len; ++i) {
13
+ var key = keys[i];
14
+ values[i] = obj[key];
15
+ values[i + len] = key;
16
+ }
17
+ this.constructor$(values);
18
+ }
19
+ util.inherits(PropertiesPromiseArray, PromiseArray);
20
+
21
+ PropertiesPromiseArray.prototype._init = function () {
22
+ this._init$(undefined, -3) ;
23
+ };
24
+
25
+ PropertiesPromiseArray.prototype._promiseFulfilled = function (value, index) {
26
+ this._values[index] = value;
27
+ var totalResolved = ++this._totalResolved;
28
+ if (totalResolved >= this._length) {
29
+ var val = {};
30
+ var keyOffset = this.length();
31
+ for (var i = 0, len = this.length(); i < len; ++i) {
32
+ val[this._values[i + keyOffset]] = this._values[i];
33
+ }
34
+ this._resolve(val);
35
+ }
36
+ };
37
+
38
+ PropertiesPromiseArray.prototype._promiseProgressed = function (value, index) {
39
+ this._promise._progress({
40
+ key: this._values[index + this.length()],
41
+ value: value
42
+ });
43
+ };
44
+
45
+ PropertiesPromiseArray.prototype.shouldCopyValues = function () {
46
+ return false;
47
+ };
48
+
49
+ PropertiesPromiseArray.prototype.getActualLength = function (len) {
50
+ return len >> 1;
51
+ };
52
+
53
+ function props(promises) {
54
+ var ret;
55
+ var castValue = tryConvertToPromise(promises);
56
+
57
+ if (!isObject(castValue)) {
58
+ return apiRejection("cannot await properties of a non-object\u000a\u000a See http://goo.gl/OsFKC8\u000a");
59
+ } else if (castValue instanceof Promise) {
60
+ ret = castValue._then(
61
+ Promise.props, undefined, undefined, undefined, undefined);
62
+ } else {
63
+ ret = new PropertiesPromiseArray(castValue).promise();
64
+ }
65
+
66
+ if (castValue instanceof Promise) {
67
+ ret._propagateFrom(castValue, 4);
68
+ }
69
+ return ret;
70
+ }
71
+
72
+ Promise.prototype.props = function () {
73
+ return props(this);
74
+ };
75
+
76
+ Promise.props = function (promises) {
77
+ return props(promises);
78
+ };
79
+ };
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ function arrayMove(src, srcIndex, dst, dstIndex, len) {
3
+ for (var j = 0; j < len; ++j) {
4
+ dst[j + dstIndex] = src[j + srcIndex];
5
+ src[j + srcIndex] = void 0;
6
+ }
7
+ }
8
+
9
+ function Queue(capacity) {
10
+ this._capacity = capacity;
11
+ this._length = 0;
12
+ this._front = 0;
13
+ }
14
+
15
+ Queue.prototype._willBeOverCapacity = function (size) {
16
+ return this._capacity < size;
17
+ };
18
+
19
+ Queue.prototype._pushOne = function (arg) {
20
+ var length = this.length();
21
+ this._checkCapacity(length + 1);
22
+ var i = (this._front + length) & (this._capacity - 1);
23
+ this[i] = arg;
24
+ this._length = length + 1;
25
+ };
26
+
27
+ Queue.prototype._unshiftOne = function(value) {
28
+ var capacity = this._capacity;
29
+ this._checkCapacity(this.length() + 1);
30
+ var front = this._front;
31
+ var i = (((( front - 1 ) &
32
+ ( capacity - 1) ) ^ capacity ) - capacity );
33
+ this[i] = value;
34
+ this._front = i;
35
+ this._length = this.length() + 1;
36
+ };
37
+
38
+ Queue.prototype.unshift = function(fn, receiver, arg) {
39
+ this._unshiftOne(arg);
40
+ this._unshiftOne(receiver);
41
+ this._unshiftOne(fn);
42
+ };
43
+
44
+ Queue.prototype.push = function (fn, receiver, arg) {
45
+ var length = this.length() + 3;
46
+ if (this._willBeOverCapacity(length)) {
47
+ this._pushOne(fn);
48
+ this._pushOne(receiver);
49
+ this._pushOne(arg);
50
+ return;
51
+ }
52
+ var j = this._front + length - 3;
53
+ this._checkCapacity(length);
54
+ var wrapMask = this._capacity - 1;
55
+ this[(j + 0) & wrapMask] = fn;
56
+ this[(j + 1) & wrapMask] = receiver;
57
+ this[(j + 2) & wrapMask] = arg;
58
+ this._length = length;
59
+ };
60
+
61
+ Queue.prototype.shift = function () {
62
+ var front = this._front,
63
+ ret = this[front];
64
+
65
+ this[front] = undefined;
66
+ this._front = (front + 1) & (this._capacity - 1);
67
+ this._length--;
68
+ return ret;
69
+ };
70
+
71
+ Queue.prototype.length = function () {
72
+ return this._length;
73
+ };
74
+
75
+ Queue.prototype._checkCapacity = function (size) {
76
+ if (this._capacity < size) {
77
+ this._resizeTo(this._capacity << 1);
78
+ }
79
+ };
80
+
81
+ Queue.prototype._resizeTo = function (capacity) {
82
+ var oldCapacity = this._capacity;
83
+ this._capacity = capacity;
84
+ var front = this._front;
85
+ var length = this._length;
86
+ var moveItemsCount = (front + length) & (oldCapacity - 1);
87
+ arrayMove(this, 0, this, oldCapacity, moveItemsCount);
88
+ };
89
+
90
+ module.exports = Queue;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ module.exports = function(
3
+ Promise, INTERNAL, tryConvertToPromise, apiRejection) {
4
+ var isArray = require("./util.js").isArray;
5
+
6
+ var raceLater = function (promise) {
7
+ return promise.then(function(array) {
8
+ return race(array, promise);
9
+ });
10
+ };
11
+
12
+ function race(promises, parent) {
13
+ var maybePromise = tryConvertToPromise(promises);
14
+
15
+ if (maybePromise instanceof Promise) {
16
+ return raceLater(maybePromise);
17
+ } else if (!isArray(promises)) {
18
+ return apiRejection("expecting an array, a promise or a thenable\u000a\u000a See http://goo.gl/s8MMhc\u000a");
19
+ }
20
+
21
+ var ret = new Promise(INTERNAL);
22
+ if (parent !== undefined) {
23
+ ret._propagateFrom(parent, 4 | 1);
24
+ }
25
+ var fulfill = ret._fulfill;
26
+ var reject = ret._reject;
27
+ for (var i = 0, len = promises.length; i < len; ++i) {
28
+ var val = promises[i];
29
+
30
+ if (val === undefined && !(i in promises)) {
31
+ continue;
32
+ }
33
+
34
+ Promise.cast(val)._then(fulfill, reject, undefined, ret, null);
35
+ }
36
+ return ret;
37
+ }
38
+
39
+ Promise.race = function (promises) {
40
+ return race(promises, undefined);
41
+ };
42
+
43
+ Promise.prototype.race = function () {
44
+ return race(this, undefined);
45
+ };
46
+
47
+ };
@@ -0,0 +1,148 @@
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
+ function ReductionPromiseArray(promises, fn, accum, _each) {
13
+ this.constructor$(promises);
14
+ this._promise._captureStackTrace();
15
+ this._preservedValues = _each === INTERNAL ? [] : null;
16
+ this._zerothIsAccum = (accum === undefined);
17
+ this._gotAccum = false;
18
+ this._reducingIndex = (this._zerothIsAccum ? 1 : 0);
19
+ this._valuesPhase = undefined;
20
+ var maybePromise = tryConvertToPromise(accum, this._promise);
21
+ var rejected = false;
22
+ var isPromise = maybePromise instanceof Promise;
23
+ if (isPromise) {
24
+ maybePromise = maybePromise._target();
25
+ if (maybePromise._isPending()) {
26
+ maybePromise._proxyPromiseArray(this, -1);
27
+ } else if (maybePromise._isFulfilled()) {
28
+ accum = maybePromise._value();
29
+ this._gotAccum = true;
30
+ } else {
31
+ this._reject(maybePromise._reason());
32
+ rejected = true;
33
+ }
34
+ }
35
+ if (!(isPromise || this._zerothIsAccum)) this._gotAccum = true;
36
+ var domain = getDomain();
37
+ this._callback = domain === null ? fn : domain.bind(fn);
38
+ this._accum = accum;
39
+ if (!rejected) async.invoke(init, this, undefined);
40
+ }
41
+ function init() {
42
+ this._init$(undefined, -5);
43
+ }
44
+ util.inherits(ReductionPromiseArray, PromiseArray);
45
+
46
+ ReductionPromiseArray.prototype._init = function () {};
47
+
48
+ ReductionPromiseArray.prototype._resolveEmptyArray = function () {
49
+ if (this._gotAccum || this._zerothIsAccum) {
50
+ this._resolve(this._preservedValues !== null
51
+ ? [] : this._accum);
52
+ }
53
+ };
54
+
55
+ ReductionPromiseArray.prototype._promiseFulfilled = function (value, index) {
56
+ var values = this._values;
57
+ values[index] = value;
58
+ var length = this.length();
59
+ var preservedValues = this._preservedValues;
60
+ var isEach = preservedValues !== null;
61
+ var gotAccum = this._gotAccum;
62
+ var valuesPhase = this._valuesPhase;
63
+ var valuesPhaseIndex;
64
+ if (!valuesPhase) {
65
+ valuesPhase = this._valuesPhase = new Array(length);
66
+ for (valuesPhaseIndex=0; valuesPhaseIndex<length; ++valuesPhaseIndex) {
67
+ valuesPhase[valuesPhaseIndex] = 0;
68
+ }
69
+ }
70
+ valuesPhaseIndex = valuesPhase[index];
71
+
72
+ if (index === 0 && this._zerothIsAccum) {
73
+ this._accum = value;
74
+ this._gotAccum = gotAccum = true;
75
+ valuesPhase[index] = ((valuesPhaseIndex === 0)
76
+ ? 1 : 2);
77
+ } else if (index === -1) {
78
+ this._accum = value;
79
+ this._gotAccum = gotAccum = true;
80
+ } else {
81
+ if (valuesPhaseIndex === 0) {
82
+ valuesPhase[index] = 1;
83
+ } else {
84
+ valuesPhase[index] = 2;
85
+ this._accum = value;
86
+ }
87
+ }
88
+ if (!gotAccum) return;
89
+
90
+ var callback = this._callback;
91
+ var receiver = this._promise._boundValue();
92
+ var ret;
93
+
94
+ for (var i = this._reducingIndex; i < length; ++i) {
95
+ valuesPhaseIndex = valuesPhase[i];
96
+ if (valuesPhaseIndex === 2) {
97
+ this._reducingIndex = i + 1;
98
+ continue;
99
+ }
100
+ if (valuesPhaseIndex !== 1) return;
101
+ value = values[i];
102
+ this._promise._pushContext();
103
+ if (isEach) {
104
+ preservedValues.push(value);
105
+ ret = tryCatch(callback).call(receiver, value, i, length);
106
+ }
107
+ else {
108
+ ret = tryCatch(callback)
109
+ .call(receiver, this._accum, value, i, length);
110
+ }
111
+ this._promise._popContext();
112
+
113
+ if (ret === errorObj) return this._reject(ret.e);
114
+
115
+ var maybePromise = tryConvertToPromise(ret, this._promise);
116
+ if (maybePromise instanceof Promise) {
117
+ maybePromise = maybePromise._target();
118
+ if (maybePromise._isPending()) {
119
+ valuesPhase[i] = 4;
120
+ return maybePromise._proxyPromiseArray(this, i);
121
+ } else if (maybePromise._isFulfilled()) {
122
+ ret = maybePromise._value();
123
+ } else {
124
+ return this._reject(maybePromise._reason());
125
+ }
126
+ }
127
+
128
+ this._reducingIndex = i + 1;
129
+ this._accum = ret;
130
+ }
131
+
132
+ this._resolve(isEach ? preservedValues : this._accum);
133
+ };
134
+
135
+ function reduce(promises, fn, initialValue, _each) {
136
+ if (typeof fn !== "function") return apiRejection("fn must be a function\u000a\u000a See http://goo.gl/916lJJ\u000a");
137
+ var array = new ReductionPromiseArray(promises, fn, initialValue, _each);
138
+ return array.promise();
139
+ }
140
+
141
+ Promise.prototype.reduce = function (fn, initialValue) {
142
+ return reduce(this, fn, initialValue, null);
143
+ };
144
+
145
+ Promise.reduce = function (promises, fn, initialValue, _each) {
146
+ return reduce(promises, fn, initialValue, _each);
147
+ };
148
+ };
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var schedule;
3
+ var util = require("./util");
4
+ var noAsyncScheduler = function() {
5
+ throw new Error("No async scheduler available\u000a\u000a See http://goo.gl/m3OTXk\u000a");
6
+ };
7
+ if (util.isNode && typeof MutationObserver === "undefined") {
8
+ var GlobalSetImmediate = global.setImmediate;
9
+ var ProcessNextTick = process.nextTick;
10
+ schedule = util.isRecentNode
11
+ ? function(fn) { GlobalSetImmediate.call(global, fn); }
12
+ : function(fn) { ProcessNextTick.call(process, fn); };
13
+ } else if ((typeof MutationObserver !== "undefined") &&
14
+ !(typeof window !== "undefined" &&
15
+ window.navigator &&
16
+ window.navigator.standalone)) {
17
+ schedule = function(fn) {
18
+ var div = document.createElement("div");
19
+ var observer = new MutationObserver(fn);
20
+ observer.observe(div, {attributes: true});
21
+ return function() { div.classList.toggle("foo"); };
22
+ };
23
+ schedule.isStatic = true;
24
+ } else if (typeof setImmediate !== "undefined") {
25
+ schedule = function (fn) {
26
+ setImmediate(fn);
27
+ };
28
+ } else if (typeof setTimeout !== "undefined") {
29
+ schedule = function (fn) {
30
+ setTimeout(fn, 0);
31
+ };
32
+ } else {
33
+ schedule = noAsyncScheduler;
34
+ }
35
+ module.exports = schedule;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ module.exports =
3
+ function(Promise, PromiseArray) {
4
+ var PromiseInspection = Promise.PromiseInspection;
5
+ var util = require("./util.js");
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
+ }
18
+ };
19
+
20
+ SettledPromiseArray.prototype._promiseFulfilled = function (value, index) {
21
+ var ret = new PromiseInspection();
22
+ ret._bitField = 268435456;
23
+ ret._settledValue = value;
24
+ this._promiseResolved(index, ret);
25
+ };
26
+ SettledPromiseArray.prototype._promiseRejected = function (reason, index) {
27
+ var ret = new PromiseInspection();
28
+ ret._bitField = 134217728;
29
+ ret._settledValue = reason;
30
+ this._promiseResolved(index, ret);
31
+ };
32
+
33
+ Promise.settle = function (promises) {
34
+ return new SettledPromiseArray(promises).promise();
35
+ };
36
+
37
+ Promise.prototype.settle = function () {
38
+ return new SettledPromiseArray(this).promise();
39
+ };
40
+ };
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ module.exports =
3
+ function(Promise, PromiseArray, apiRejection) {
4
+ var util = require("./util.js");
5
+ var RangeError = require("./errors.js").RangeError;
6
+ var AggregateError = require("./errors.js").AggregateError;
7
+ var isArray = util.isArray;
8
+
9
+
10
+ function SomePromiseArray(values) {
11
+ this.constructor$(values);
12
+ this._howMany = 0;
13
+ this._unwrap = false;
14
+ this._initialized = false;
15
+ }
16
+ util.inherits(SomePromiseArray, PromiseArray);
17
+
18
+ SomePromiseArray.prototype._init = function () {
19
+ if (!this._initialized) {
20
+ return;
21
+ }
22
+ if (this._howMany === 0) {
23
+ this._resolve([]);
24
+ return;
25
+ }
26
+ this._init$(undefined, -5);
27
+ var isArrayResolved = isArray(this._values);
28
+ if (!this._isResolved() &&
29
+ isArrayResolved &&
30
+ this._howMany > this._canPossiblyFulfill()) {
31
+ this._reject(this._getRangeError(this.length()));
32
+ }
33
+ };
34
+
35
+ SomePromiseArray.prototype.init = function () {
36
+ this._initialized = true;
37
+ this._init();
38
+ };
39
+
40
+ SomePromiseArray.prototype.setUnwrap = function () {
41
+ this._unwrap = true;
42
+ };
43
+
44
+ SomePromiseArray.prototype.howMany = function () {
45
+ return this._howMany;
46
+ };
47
+
48
+ SomePromiseArray.prototype.setHowMany = function (count) {
49
+ this._howMany = count;
50
+ };
51
+
52
+ SomePromiseArray.prototype._promiseFulfilled = function (value) {
53
+ this._addFulfilled(value);
54
+ if (this._fulfilled() === this.howMany()) {
55
+ this._values.length = this.howMany();
56
+ if (this.howMany() === 1 && this._unwrap) {
57
+ this._resolve(this._values[0]);
58
+ } else {
59
+ this._resolve(this._values);
60
+ }
61
+ }
62
+
63
+ };
64
+ SomePromiseArray.prototype._promiseRejected = function (reason) {
65
+ this._addRejected(reason);
66
+ if (this.howMany() > this._canPossiblyFulfill()) {
67
+ var e = new AggregateError();
68
+ for (var i = this.length(); i < this._values.length; ++i) {
69
+ e.push(this._values[i]);
70
+ }
71
+ this._reject(e);
72
+ }
73
+ };
74
+
75
+ SomePromiseArray.prototype._fulfilled = function () {
76
+ return this._totalResolved;
77
+ };
78
+
79
+ SomePromiseArray.prototype._rejected = function () {
80
+ return this._values.length - this.length();
81
+ };
82
+
83
+ SomePromiseArray.prototype._addRejected = function (reason) {
84
+ this._values.push(reason);
85
+ };
86
+
87
+ SomePromiseArray.prototype._addFulfilled = function (value) {
88
+ this._values[this._totalResolved++] = value;
89
+ };
90
+
91
+ SomePromiseArray.prototype._canPossiblyFulfill = function () {
92
+ return this.length() - this._rejected();
93
+ };
94
+
95
+ SomePromiseArray.prototype._getRangeError = function (count) {
96
+ var message = "Input array must contain at least " +
97
+ this._howMany + " items but contains only " + count + " items";
98
+ return new RangeError(message);
99
+ };
100
+
101
+ SomePromiseArray.prototype._resolveEmptyArray = function () {
102
+ this._reject(this._getRangeError(0));
103
+ };
104
+
105
+ function some(promises, howMany) {
106
+ if ((howMany | 0) !== howMany || howMany < 0) {
107
+ return apiRejection("expecting a positive integer\u000a\u000a See http://goo.gl/1wAmHx\u000a");
108
+ }
109
+ var ret = new SomePromiseArray(promises);
110
+ var promise = ret.promise();
111
+ ret.setHowMany(howMany);
112
+ ret.init();
113
+ return promise;
114
+ }
115
+
116
+ Promise.some = function (promises, howMany) {
117
+ return some(promises, howMany);
118
+ };
119
+
120
+ Promise.prototype.some = function (howMany) {
121
+ return some(this, howMany);
122
+ };
123
+
124
+ Promise._SomePromiseArray = SomePromiseArray;
125
+ };