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,185 @@
1
+ "use strict";
2
+ module.exports = function(Promise, INTERNAL, tryConvertToPromise,
3
+ apiRejection, Proxyable) {
4
+ var util = require("./util");
5
+ var isArray = util.isArray;
6
+
7
+ function toResolutionValue(val) {
8
+ switch(val) {
9
+ case -2: return [];
10
+ case -3: return {};
11
+ case -6: return new Map();
12
+ }
13
+ }
14
+
15
+ function PromiseArray(values) {
16
+ var promise = this._promise = new Promise(INTERNAL);
17
+ if (values instanceof Promise) {
18
+ promise._propagateFrom(values, 3);
19
+ }
20
+ promise._setOnCancel(this);
21
+ this._values = values;
22
+ this._length = 0;
23
+ this._totalResolved = 0;
24
+ this._init(undefined, -2);
25
+ }
26
+ util.inherits(PromiseArray, Proxyable);
27
+
28
+ PromiseArray.prototype.length = function () {
29
+ return this._length;
30
+ };
31
+
32
+ PromiseArray.prototype.promise = function () {
33
+ return this._promise;
34
+ };
35
+
36
+ PromiseArray.prototype._init = function init(_, resolveValueIfEmpty) {
37
+ var values = tryConvertToPromise(this._values, this._promise);
38
+ if (values instanceof Promise) {
39
+ values = values._target();
40
+ var bitField = values._bitField;
41
+ ;
42
+ this._values = values;
43
+
44
+ if (((bitField & 50397184) === 0)) {
45
+ this._promise._setAsyncGuaranteed();
46
+ return values._then(
47
+ init,
48
+ this._reject,
49
+ undefined,
50
+ this,
51
+ resolveValueIfEmpty
52
+ );
53
+ } else if (((bitField & 33554432) !== 0)) {
54
+ values = values._value();
55
+ } else if (((bitField & 16777216) !== 0)) {
56
+ return this._reject(values._reason());
57
+ } else {
58
+ return this._cancel();
59
+ }
60
+ }
61
+ values = util.asArray(values);
62
+ if (values === null) {
63
+ var err = apiRejection(
64
+ "expecting an array or an iterable object but got " + util.classString(values)).reason();
65
+ this._promise._rejectCallback(err, false);
66
+ return;
67
+ }
68
+
69
+ if (values.length === 0) {
70
+ if (resolveValueIfEmpty === -5) {
71
+ this._resolveEmptyArray();
72
+ }
73
+ else {
74
+ this._resolve(toResolutionValue(resolveValueIfEmpty));
75
+ }
76
+ return;
77
+ }
78
+ this._iterate(values);
79
+ };
80
+
81
+ PromiseArray.prototype._iterate = function(values) {
82
+ var len = this.getActualLength(values.length);
83
+ this._length = len;
84
+ this._values = this.shouldCopyValues() ? new Array(len) : this._values;
85
+ var result = this._promise;
86
+ var isResolved = false;
87
+ var bitField = null;
88
+ for (var i = 0; i < len; ++i) {
89
+ var maybePromise = tryConvertToPromise(values[i], result);
90
+
91
+ if (maybePromise instanceof Promise) {
92
+ maybePromise = maybePromise._target();
93
+ bitField = maybePromise._bitField;
94
+ } else {
95
+ bitField = null;
96
+ }
97
+
98
+ if (isResolved) {
99
+ if (bitField !== null) {
100
+ maybePromise.suppressUnhandledRejections();
101
+ }
102
+ } else if (bitField !== null) {
103
+ if (((bitField & 50397184) === 0)) {
104
+ maybePromise._proxy(this, i);
105
+ this._values[i] = maybePromise;
106
+ } else if (((bitField & 33554432) !== 0)) {
107
+ isResolved = this._promiseFulfilled(maybePromise._value(), i);
108
+ } else if (((bitField & 16777216) !== 0)) {
109
+ isResolved = this._promiseRejected(maybePromise._reason(), i);
110
+ } else {
111
+ isResolved = this._promiseCancelled(i);
112
+ }
113
+ } else {
114
+ isResolved = this._promiseFulfilled(maybePromise, i);
115
+ }
116
+ }
117
+ if (!isResolved) result._setAsyncGuaranteed();
118
+ };
119
+
120
+ PromiseArray.prototype._isResolved = function () {
121
+ return this._values === null;
122
+ };
123
+
124
+ PromiseArray.prototype._resolve = function (value) {
125
+ this._values = null;
126
+ this._promise._fulfill(value);
127
+ };
128
+
129
+ PromiseArray.prototype._cancel = function() {
130
+ if (this._isResolved() || !this._promise._isCancellable()) return;
131
+ this._values = null;
132
+ this._promise._cancel();
133
+ };
134
+
135
+ PromiseArray.prototype._reject = function (reason) {
136
+ this._values = null;
137
+ this._promise._rejectCallback(reason, false);
138
+ };
139
+
140
+ PromiseArray.prototype._promiseFulfilled = function (value, index) {
141
+ this._values[index] = value;
142
+ var totalResolved = ++this._totalResolved;
143
+ if (totalResolved >= this._length) {
144
+ this._resolve(this._values);
145
+ return true;
146
+ }
147
+ return false;
148
+ };
149
+
150
+ PromiseArray.prototype._promiseCancelled = function() {
151
+ this._cancel();
152
+ return true;
153
+ };
154
+
155
+ PromiseArray.prototype._promiseRejected = function (reason) {
156
+ this._totalResolved++;
157
+ this._reject(reason);
158
+ return true;
159
+ };
160
+
161
+ PromiseArray.prototype._resultCancelled = function() {
162
+ if (this._isResolved()) return;
163
+ var values = this._values;
164
+ this._cancel();
165
+ if (values instanceof Promise) {
166
+ values.cancel();
167
+ } else {
168
+ for (var i = 0; i < values.length; ++i) {
169
+ if (values[i] instanceof Promise) {
170
+ values[i].cancel();
171
+ }
172
+ }
173
+ }
174
+ };
175
+
176
+ PromiseArray.prototype.shouldCopyValues = function () {
177
+ return true;
178
+ };
179
+
180
+ PromiseArray.prototype.getActualLength = function (len) {
181
+ return len;
182
+ };
183
+
184
+ return PromiseArray;
185
+ };
@@ -0,0 +1,314 @@
1
+ "use strict";
2
+ module.exports = function(Promise, INTERNAL) {
3
+ var THIS = {};
4
+ var util = require("./util");
5
+ var nodebackForPromise = require("./nodeback");
6
+ var withAppended = util.withAppended;
7
+ var maybeWrapAsError = util.maybeWrapAsError;
8
+ var canEvaluate = util.canEvaluate;
9
+ var TypeError = require("./errors").TypeError;
10
+ var defaultSuffix = "Async";
11
+ var defaultPromisified = {__isPromisified__: true};
12
+ var noCopyProps = [
13
+ "arity", "length",
14
+ "name",
15
+ "arguments",
16
+ "caller",
17
+ "callee",
18
+ "prototype",
19
+ "__isPromisified__"
20
+ ];
21
+ var noCopyPropsPattern = new RegExp("^(?:" + noCopyProps.join("|") + ")$");
22
+
23
+ var defaultFilter = function(name) {
24
+ return util.isIdentifier(name) &&
25
+ name.charAt(0) !== "_" &&
26
+ name !== "constructor";
27
+ };
28
+
29
+ function propsFilter(key) {
30
+ return !noCopyPropsPattern.test(key);
31
+ }
32
+
33
+ function isPromisified(fn) {
34
+ try {
35
+ return fn.__isPromisified__ === true;
36
+ }
37
+ catch (e) {
38
+ return false;
39
+ }
40
+ }
41
+
42
+ function hasPromisified(obj, key, suffix) {
43
+ var val = util.getDataPropertyOrDefault(obj, key + suffix,
44
+ defaultPromisified);
45
+ return val ? isPromisified(val) : false;
46
+ }
47
+ function checkValid(ret, suffix, suffixRegexp) {
48
+ for (var i = 0; i < ret.length; i += 2) {
49
+ var key = ret[i];
50
+ if (suffixRegexp.test(key)) {
51
+ var keyWithoutAsyncSuffix = key.replace(suffixRegexp, "");
52
+ for (var j = 0; j < ret.length; j += 2) {
53
+ if (ret[j] === keyWithoutAsyncSuffix) {
54
+ throw new TypeError("Cannot promisify an API that has normal methods with '%s'-suffix\u000a\u000a See http://goo.gl/MqrFmX\u000a"
55
+ .replace("%s", suffix));
56
+ }
57
+ }
58
+ }
59
+ }
60
+ }
61
+
62
+ function promisifiableMethods(obj, suffix, suffixRegexp, filter) {
63
+ var keys = util.inheritedDataKeys(obj);
64
+ var ret = [];
65
+ for (var i = 0; i < keys.length; ++i) {
66
+ var key = keys[i];
67
+ var value = obj[key];
68
+ var passesDefaultFilter = filter === defaultFilter
69
+ ? true : defaultFilter(key, value, obj);
70
+ if (typeof value === "function" &&
71
+ !isPromisified(value) &&
72
+ !hasPromisified(obj, key, suffix) &&
73
+ filter(key, value, obj, passesDefaultFilter)) {
74
+ ret.push(key, value);
75
+ }
76
+ }
77
+ checkValid(ret, suffix, suffixRegexp);
78
+ return ret;
79
+ }
80
+
81
+ var escapeIdentRegex = function(str) {
82
+ return str.replace(/([$])/, "\\$");
83
+ };
84
+
85
+ var makeNodePromisifiedEval;
86
+ if (!false) {
87
+ var switchCaseArgumentOrder = function(likelyArgumentCount) {
88
+ var ret = [likelyArgumentCount];
89
+ var min = Math.max(0, likelyArgumentCount - 1 - 3);
90
+ for(var i = likelyArgumentCount - 1; i >= min; --i) {
91
+ ret.push(i);
92
+ }
93
+ for(var i = likelyArgumentCount + 1; i <= 3; ++i) {
94
+ ret.push(i);
95
+ }
96
+ return ret;
97
+ };
98
+
99
+ var argumentSequence = function(argumentCount) {
100
+ return util.filledRange(argumentCount, "_arg", "");
101
+ };
102
+
103
+ var parameterDeclaration = function(parameterCount) {
104
+ return util.filledRange(
105
+ Math.max(parameterCount, 3), "_arg", "");
106
+ };
107
+
108
+ var parameterCount = function(fn) {
109
+ if (typeof fn.length === "number") {
110
+ return Math.max(Math.min(fn.length, 1023 + 1), 0);
111
+ }
112
+ return 0;
113
+ };
114
+
115
+ makeNodePromisifiedEval =
116
+ function(callback, receiver, originalName, fn, _, multiArgs) {
117
+ var newParameterCount = Math.max(0, parameterCount(fn) - 1);
118
+ var argumentOrder = switchCaseArgumentOrder(newParameterCount);
119
+ var shouldProxyThis = typeof callback === "string" || receiver === THIS;
120
+
121
+ function generateCallForArgumentCount(count) {
122
+ var args = argumentSequence(count).join(", ");
123
+ var comma = count > 0 ? ", " : "";
124
+ var ret;
125
+ if (shouldProxyThis) {
126
+ ret = "ret = callback.call(this, {{args}}, nodeback); break;\n";
127
+ } else {
128
+ ret = receiver === undefined
129
+ ? "ret = callback({{args}}, nodeback); break;\n"
130
+ : "ret = callback.call(receiver, {{args}}, nodeback); break;\n";
131
+ }
132
+ return ret.replace("{{args}}", args).replace(", ", comma);
133
+ }
134
+
135
+ function generateArgumentSwitchCase() {
136
+ var ret = "";
137
+ for (var i = 0; i < argumentOrder.length; ++i) {
138
+ ret += "case " + argumentOrder[i] +":" +
139
+ generateCallForArgumentCount(argumentOrder[i]);
140
+ }
141
+
142
+ ret += " \n\
143
+ default: \n\
144
+ var args = new Array(len + 1); \n\
145
+ var i = 0; \n\
146
+ for (var i = 0; i < len; ++i) { \n\
147
+ args[i] = arguments[i]; \n\
148
+ } \n\
149
+ args[i] = nodeback; \n\
150
+ [CodeForCall] \n\
151
+ break; \n\
152
+ ".replace("[CodeForCall]", (shouldProxyThis
153
+ ? "ret = callback.apply(this, args);\n"
154
+ : "ret = callback.apply(receiver, args);\n"));
155
+ return ret;
156
+ }
157
+
158
+ var getFunctionCode = typeof callback === "string"
159
+ ? ("this != null ? this['"+callback+"'] : fn")
160
+ : "fn";
161
+ var body = "'use strict'; \n\
162
+ var ret = function (Parameters) { \n\
163
+ 'use strict'; \n\
164
+ var len = arguments.length; \n\
165
+ var promise = new Promise(INTERNAL); \n\
166
+ promise._captureStackTrace(); \n\
167
+ var nodeback = nodebackForPromise(promise, " + multiArgs + "); \n\
168
+ var ret; \n\
169
+ var callback = tryCatch([GetFunctionCode]); \n\
170
+ switch(len) { \n\
171
+ [CodeForSwitchCase] \n\
172
+ } \n\
173
+ if (ret === errorObj) { \n\
174
+ promise._rejectCallback(maybeWrapAsError(ret.e), true, true);\n\
175
+ } \n\
176
+ if (!promise._isFateSealed()) promise._setAsyncGuaranteed(); \n\
177
+ return promise; \n\
178
+ }; \n\
179
+ notEnumerableProp(ret, '__isPromisified__', true); \n\
180
+ return ret; \n\
181
+ ".replace("[CodeForSwitchCase]", generateArgumentSwitchCase())
182
+ .replace("[GetFunctionCode]", getFunctionCode);
183
+ body = body.replace("Parameters", parameterDeclaration(newParameterCount));
184
+ return new Function("Promise",
185
+ "fn",
186
+ "receiver",
187
+ "withAppended",
188
+ "maybeWrapAsError",
189
+ "nodebackForPromise",
190
+ "tryCatch",
191
+ "errorObj",
192
+ "notEnumerableProp",
193
+ "INTERNAL",
194
+ body)(
195
+ Promise,
196
+ fn,
197
+ receiver,
198
+ withAppended,
199
+ maybeWrapAsError,
200
+ nodebackForPromise,
201
+ util.tryCatch,
202
+ util.errorObj,
203
+ util.notEnumerableProp,
204
+ INTERNAL);
205
+ };
206
+ }
207
+
208
+ function makeNodePromisifiedClosure(callback, receiver, _, fn, __, multiArgs) {
209
+ var defaultThis = (function() {return this;})();
210
+ var method = callback;
211
+ if (typeof method === "string") {
212
+ callback = fn;
213
+ }
214
+ function promisified() {
215
+ var _receiver = receiver;
216
+ if (receiver === THIS) _receiver = this;
217
+ var promise = new Promise(INTERNAL);
218
+ promise._captureStackTrace();
219
+ var cb = typeof method === "string" && this !== defaultThis
220
+ ? this[method] : callback;
221
+ var fn = nodebackForPromise(promise, multiArgs);
222
+ try {
223
+ cb.apply(_receiver, withAppended(arguments, fn));
224
+ } catch(e) {
225
+ promise._rejectCallback(maybeWrapAsError(e), true, true);
226
+ }
227
+ if (!promise._isFateSealed()) promise._setAsyncGuaranteed();
228
+ return promise;
229
+ }
230
+ util.notEnumerableProp(promisified, "__isPromisified__", true);
231
+ return promisified;
232
+ }
233
+
234
+ var makeNodePromisified = canEvaluate
235
+ ? makeNodePromisifiedEval
236
+ : makeNodePromisifiedClosure;
237
+
238
+ function promisifyAll(obj, suffix, filter, promisifier, multiArgs) {
239
+ var suffixRegexp = new RegExp(escapeIdentRegex(suffix) + "$");
240
+ var methods =
241
+ promisifiableMethods(obj, suffix, suffixRegexp, filter);
242
+
243
+ for (var i = 0, len = methods.length; i < len; i+= 2) {
244
+ var key = methods[i];
245
+ var fn = methods[i+1];
246
+ var promisifiedKey = key + suffix;
247
+ if (promisifier === makeNodePromisified) {
248
+ obj[promisifiedKey] =
249
+ makeNodePromisified(key, THIS, key, fn, suffix, multiArgs);
250
+ } else {
251
+ var promisified = promisifier(fn, function() {
252
+ return makeNodePromisified(key, THIS, key,
253
+ fn, suffix, multiArgs);
254
+ });
255
+ util.notEnumerableProp(promisified, "__isPromisified__", true);
256
+ obj[promisifiedKey] = promisified;
257
+ }
258
+ }
259
+ util.toFastProperties(obj);
260
+ return obj;
261
+ }
262
+
263
+ function promisify(callback, receiver, multiArgs) {
264
+ return makeNodePromisified(callback, receiver, undefined,
265
+ callback, null, multiArgs);
266
+ }
267
+
268
+ Promise.promisify = function (fn, options) {
269
+ if (typeof fn !== "function") {
270
+ throw new TypeError("expecting a function but got " + util.classString(fn));
271
+ }
272
+ if (isPromisified(fn)) {
273
+ return fn;
274
+ }
275
+ options = Object(options);
276
+ var receiver = options.context === undefined ? THIS : options.context;
277
+ var multiArgs = !!options.multiArgs;
278
+ var ret = promisify(fn, receiver, multiArgs);
279
+ util.copyDescriptors(fn, ret, propsFilter);
280
+ return ret;
281
+ };
282
+
283
+ Promise.promisifyAll = function (target, options) {
284
+ if (typeof target !== "function" && typeof target !== "object") {
285
+ throw new TypeError("the target of promisifyAll must be an object or a function\u000a\u000a See http://goo.gl/MqrFmX\u000a");
286
+ }
287
+ options = Object(options);
288
+ var multiArgs = !!options.multiArgs;
289
+ var suffix = options.suffix;
290
+ if (typeof suffix !== "string") suffix = defaultSuffix;
291
+ var filter = options.filter;
292
+ if (typeof filter !== "function") filter = defaultFilter;
293
+ var promisifier = options.promisifier;
294
+ if (typeof promisifier !== "function") promisifier = makeNodePromisified;
295
+
296
+ if (!util.isIdentifier(suffix)) {
297
+ throw new RangeError("suffix must be a valid identifier\u000a\u000a See http://goo.gl/MqrFmX\u000a");
298
+ }
299
+
300
+ var keys = util.inheritedDataKeys(target);
301
+ for (var i = 0; i < keys.length; ++i) {
302
+ var value = target[keys[i]];
303
+ if (keys[i] !== "constructor" &&
304
+ util.isClass(value)) {
305
+ promisifyAll(value.prototype, suffix, filter, promisifier,
306
+ multiArgs);
307
+ promisifyAll(value, suffix, filter, promisifier, multiArgs);
308
+ }
309
+ }
310
+
311
+ return promisifyAll(target, suffix, filter, promisifier, multiArgs);
312
+ };
313
+ };
314
+