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,94 @@
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._settledValue = promise._settledValue;
8
+ }
9
+ else {
10
+ this._bitField = 0;
11
+ this._settledValue = undefined;
12
+ }
13
+ }
14
+
15
+ PromiseInspection.prototype.value = function () {
16
+ if (!this.isFulfilled()) {
17
+ throw new TypeError("cannot get fulfillment value of a non-fulfilled promise\u000a\u000a See http://goo.gl/hc1DLj\u000a");
18
+ }
19
+ return this._settledValue;
20
+ };
21
+
22
+ PromiseInspection.prototype.error =
23
+ PromiseInspection.prototype.reason = function () {
24
+ if (!this.isRejected()) {
25
+ throw new TypeError("cannot get rejection reason of a non-rejected promise\u000a\u000a See http://goo.gl/hPuiwB\u000a");
26
+ }
27
+ return this._settledValue;
28
+ };
29
+
30
+ PromiseInspection.prototype.isFulfilled =
31
+ Promise.prototype._isFulfilled = function () {
32
+ return (this._bitField & 268435456) > 0;
33
+ };
34
+
35
+ PromiseInspection.prototype.isRejected =
36
+ Promise.prototype._isRejected = function () {
37
+ return (this._bitField & 134217728) > 0;
38
+ };
39
+
40
+ PromiseInspection.prototype.isPending =
41
+ Promise.prototype._isPending = function () {
42
+ return (this._bitField & 402653184) === 0;
43
+ };
44
+
45
+ PromiseInspection.prototype.isResolved =
46
+ Promise.prototype._isResolved = function () {
47
+ return (this._bitField & 402653184) > 0;
48
+ };
49
+
50
+ Promise.prototype.isPending = function() {
51
+ return this._target()._isPending();
52
+ };
53
+
54
+ Promise.prototype.isRejected = function() {
55
+ return this._target()._isRejected();
56
+ };
57
+
58
+ Promise.prototype.isFulfilled = function() {
59
+ return this._target()._isFulfilled();
60
+ };
61
+
62
+ Promise.prototype.isResolved = function() {
63
+ return this._target()._isResolved();
64
+ };
65
+
66
+ Promise.prototype._value = function() {
67
+ return this._settledValue;
68
+ };
69
+
70
+ Promise.prototype._reason = function() {
71
+ this._unsetRejectionIsUnhandled();
72
+ return this._settledValue;
73
+ };
74
+
75
+ Promise.prototype.value = function() {
76
+ var target = this._target();
77
+ if (!target.isFulfilled()) {
78
+ throw new TypeError("cannot get fulfillment value of a non-fulfilled promise\u000a\u000a See http://goo.gl/hc1DLj\u000a");
79
+ }
80
+ return target._settledValue;
81
+ };
82
+
83
+ Promise.prototype.reason = function() {
84
+ var target = this._target();
85
+ if (!target.isRejected()) {
86
+ throw new TypeError("cannot get rejection reason of a non-rejected promise\u000a\u000a See http://goo.gl/hPuiwB\u000a");
87
+ }
88
+ target._unsetRejectionIsUnhandled();
89
+ return target._settledValue;
90
+ };
91
+
92
+
93
+ Promise.PromiseInspection = PromiseInspection;
94
+ };
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ module.exports = function(Promise, INTERNAL) {
3
+ var util = require("./util.js");
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) {
10
+ return obj;
11
+ }
12
+ else if (isAnyBluebirdPromise(obj)) {
13
+ var ret = new Promise(INTERNAL);
14
+ obj._then(
15
+ ret._fulfillUnchecked,
16
+ ret._rejectUncheckedCheckError,
17
+ ret._progressUnchecked,
18
+ ret,
19
+ null
20
+ );
21
+ return ret;
22
+ }
23
+ var then = util.tryCatch(getThen)(obj);
24
+ if (then === errorObj) {
25
+ if (context) context._pushContext();
26
+ var ret = Promise.reject(then.e);
27
+ if (context) context._popContext();
28
+ return ret;
29
+ } else if (typeof then === "function") {
30
+ return doThenable(obj, then, context);
31
+ }
32
+ }
33
+ return obj;
34
+ }
35
+
36
+ function getThen(obj) {
37
+ return obj.then;
38
+ }
39
+
40
+ var hasProp = {}.hasOwnProperty;
41
+ function isAnyBluebirdPromise(obj) {
42
+ return hasProp.call(obj, "_promise0");
43
+ }
44
+
45
+ function doThenable(x, then, context) {
46
+ var promise = new Promise(INTERNAL);
47
+ var ret = promise;
48
+ if (context) context._pushContext();
49
+ promise._captureStackTrace();
50
+ if (context) context._popContext();
51
+ var synchronous = true;
52
+ var result = util.tryCatch(then).call(x,
53
+ resolveFromThenable,
54
+ rejectFromThenable,
55
+ progressFromThenable);
56
+ synchronous = false;
57
+ if (promise && result === errorObj) {
58
+ promise._rejectCallback(result.e, true, true);
59
+ promise = null;
60
+ }
61
+
62
+ function resolveFromThenable(value) {
63
+ if (!promise) return;
64
+ promise._resolveCallback(value);
65
+ promise = null;
66
+ }
67
+
68
+ function rejectFromThenable(reason) {
69
+ if (!promise) return;
70
+ promise._rejectCallback(reason, synchronous, true);
71
+ promise = null;
72
+ }
73
+
74
+ function progressFromThenable(value) {
75
+ if (!promise) return;
76
+ if (typeof promise._progress === "function") {
77
+ promise._progress(value);
78
+ }
79
+ }
80
+ return ret;
81
+ }
82
+
83
+ return tryConvertToPromise;
84
+ };
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ module.exports = function(Promise, INTERNAL) {
3
+ var util = require("./util.js");
4
+ var TimeoutError = Promise.TimeoutError;
5
+
6
+ var afterTimeout = function (promise, message) {
7
+ if (!promise.isPending()) return;
8
+
9
+ var err;
10
+ if(!util.isPrimitive(message) && (message instanceof Error)) {
11
+ err = message;
12
+ } else {
13
+ if (typeof message !== "string") {
14
+ message = "operation timed out";
15
+ }
16
+ err = new TimeoutError(message);
17
+ }
18
+ util.markAsOriginatingFromRejection(err);
19
+ promise._attachExtraTrace(err);
20
+ promise._cancel(err);
21
+ };
22
+
23
+ var afterValue = function(value) { return delay(+this).thenReturn(value); };
24
+ var delay = Promise.delay = function (value, ms) {
25
+ if (ms === undefined) {
26
+ ms = value;
27
+ value = undefined;
28
+ var ret = new Promise(INTERNAL);
29
+ setTimeout(function() { ret._fulfill(); }, ms);
30
+ return ret;
31
+ }
32
+ ms = +ms;
33
+ return Promise.resolve(value)._then(afterValue, null, null, ms, undefined);
34
+ };
35
+
36
+ Promise.prototype.delay = function (ms) {
37
+ return delay(this, ms);
38
+ };
39
+
40
+ function successClear(value) {
41
+ var handle = this;
42
+ if (handle instanceof Number) handle = +handle;
43
+ clearTimeout(handle);
44
+ return value;
45
+ }
46
+
47
+ function failureClear(reason) {
48
+ var handle = this;
49
+ if (handle instanceof Number) handle = +handle;
50
+ clearTimeout(handle);
51
+ throw reason;
52
+ }
53
+
54
+ Promise.prototype.timeout = function (ms, message) {
55
+ ms = +ms;
56
+ var ret = this.then().cancellable();
57
+ ret._cancellationParent = this;
58
+ var handle = setTimeout(function timeoutTimeout() {
59
+ afterTimeout(ret, message);
60
+ }, ms);
61
+ return ret._then(successClear, failureClear, undefined, handle, undefined);
62
+ };
63
+
64
+ };
@@ -0,0 +1,213 @@
1
+ "use strict";
2
+ module.exports = function (Promise, apiRejection, tryConvertToPromise,
3
+ createContext) {
4
+ var TypeError = require("./errors.js").TypeError;
5
+ var inherits = require("./util.js").inherits;
6
+ var PromiseInspection = Promise.PromiseInspection;
7
+
8
+ function inspectionMapper(inspections) {
9
+ var len = inspections.length;
10
+ for (var i = 0; i < len; ++i) {
11
+ var inspection = inspections[i];
12
+ if (inspection.isRejected()) {
13
+ return Promise.reject(inspection.error());
14
+ }
15
+ inspections[i] = inspection._settledValue;
16
+ }
17
+ return inspections;
18
+ }
19
+
20
+ function thrower(e) {
21
+ setTimeout(function(){throw e;}, 0);
22
+ }
23
+
24
+ function castPreservingDisposable(thenable) {
25
+ var maybePromise = tryConvertToPromise(thenable);
26
+ if (maybePromise !== thenable &&
27
+ typeof thenable._isDisposable === "function" &&
28
+ typeof thenable._getDisposer === "function" &&
29
+ thenable._isDisposable()) {
30
+ maybePromise._setDisposable(thenable._getDisposer());
31
+ }
32
+ return maybePromise;
33
+ }
34
+ function dispose(resources, inspection) {
35
+ var i = 0;
36
+ var len = resources.length;
37
+ var ret = Promise.defer();
38
+ function iterator() {
39
+ if (i >= len) return ret.resolve();
40
+ var maybePromise = castPreservingDisposable(resources[i++]);
41
+ if (maybePromise instanceof Promise &&
42
+ maybePromise._isDisposable()) {
43
+ try {
44
+ maybePromise = tryConvertToPromise(
45
+ maybePromise._getDisposer().tryDispose(inspection),
46
+ resources.promise);
47
+ } catch (e) {
48
+ return thrower(e);
49
+ }
50
+ if (maybePromise instanceof Promise) {
51
+ return maybePromise._then(iterator, thrower,
52
+ null, null, null);
53
+ }
54
+ }
55
+ iterator();
56
+ }
57
+ iterator();
58
+ return ret.promise;
59
+ }
60
+
61
+ function disposerSuccess(value) {
62
+ var inspection = new PromiseInspection();
63
+ inspection._settledValue = value;
64
+ inspection._bitField = 268435456;
65
+ return dispose(this, inspection).thenReturn(value);
66
+ }
67
+
68
+ function disposerFail(reason) {
69
+ var inspection = new PromiseInspection();
70
+ inspection._settledValue = reason;
71
+ inspection._bitField = 134217728;
72
+ return dispose(this, inspection).thenThrow(reason);
73
+ }
74
+
75
+ function Disposer(data, promise, context) {
76
+ this._data = data;
77
+ this._promise = promise;
78
+ this._context = context;
79
+ }
80
+
81
+ Disposer.prototype.data = function () {
82
+ return this._data;
83
+ };
84
+
85
+ Disposer.prototype.promise = function () {
86
+ return this._promise;
87
+ };
88
+
89
+ Disposer.prototype.resource = function () {
90
+ if (this.promise().isFulfilled()) {
91
+ return this.promise().value();
92
+ }
93
+ return null;
94
+ };
95
+
96
+ Disposer.prototype.tryDispose = function(inspection) {
97
+ var resource = this.resource();
98
+ var context = this._context;
99
+ if (context !== undefined) context._pushContext();
100
+ var ret = resource !== null
101
+ ? this.doDispose(resource, inspection) : null;
102
+ if (context !== undefined) context._popContext();
103
+ this._promise._unsetDisposable();
104
+ this._data = null;
105
+ return ret;
106
+ };
107
+
108
+ Disposer.isDisposer = function (d) {
109
+ return (d != null &&
110
+ typeof d.resource === "function" &&
111
+ typeof d.tryDispose === "function");
112
+ };
113
+
114
+ function FunctionDisposer(fn, promise, context) {
115
+ this.constructor$(fn, promise, context);
116
+ }
117
+ inherits(FunctionDisposer, Disposer);
118
+
119
+ FunctionDisposer.prototype.doDispose = function (resource, inspection) {
120
+ var fn = this.data();
121
+ return fn.call(resource, resource, inspection);
122
+ };
123
+
124
+ function maybeUnwrapDisposer(value) {
125
+ if (Disposer.isDisposer(value)) {
126
+ this.resources[this.index]._setDisposable(value);
127
+ return value.promise();
128
+ }
129
+ return value;
130
+ }
131
+
132
+ Promise.using = function () {
133
+ var len = arguments.length;
134
+ if (len < 2) return apiRejection(
135
+ "you must pass at least 2 arguments to Promise.using");
136
+ var fn = arguments[len - 1];
137
+ if (typeof fn !== "function") return apiRejection("fn must be a function\u000a\u000a See http://goo.gl/916lJJ\u000a");
138
+
139
+ var input;
140
+ var spreadArgs = true;
141
+ if (len === 2 && Array.isArray(arguments[0])) {
142
+ input = arguments[0];
143
+ len = input.length;
144
+ spreadArgs = false;
145
+ } else {
146
+ input = arguments;
147
+ len--;
148
+ }
149
+ var resources = new Array(len);
150
+ for (var i = 0; i < len; ++i) {
151
+ var resource = input[i];
152
+ if (Disposer.isDisposer(resource)) {
153
+ var disposer = resource;
154
+ resource = resource.promise();
155
+ resource._setDisposable(disposer);
156
+ } else {
157
+ var maybePromise = tryConvertToPromise(resource);
158
+ if (maybePromise instanceof Promise) {
159
+ resource =
160
+ maybePromise._then(maybeUnwrapDisposer, null, null, {
161
+ resources: resources,
162
+ index: i
163
+ }, undefined);
164
+ }
165
+ }
166
+ resources[i] = resource;
167
+ }
168
+
169
+ var promise = Promise.settle(resources)
170
+ .then(inspectionMapper)
171
+ .then(function(vals) {
172
+ promise._pushContext();
173
+ var ret;
174
+ try {
175
+ ret = spreadArgs
176
+ ? fn.apply(undefined, vals) : fn.call(undefined, vals);
177
+ } finally {
178
+ promise._popContext();
179
+ }
180
+ return ret;
181
+ })
182
+ ._then(
183
+ disposerSuccess, disposerFail, undefined, resources, undefined);
184
+ resources.promise = promise;
185
+ return promise;
186
+ };
187
+
188
+ Promise.prototype._setDisposable = function (disposer) {
189
+ this._bitField = this._bitField | 262144;
190
+ this._disposer = disposer;
191
+ };
192
+
193
+ Promise.prototype._isDisposable = function () {
194
+ return (this._bitField & 262144) > 0;
195
+ };
196
+
197
+ Promise.prototype._getDisposer = function () {
198
+ return this._disposer;
199
+ };
200
+
201
+ Promise.prototype._unsetDisposable = function () {
202
+ this._bitField = this._bitField & (~262144);
203
+ this._disposer = undefined;
204
+ };
205
+
206
+ Promise.prototype.disposer = function (fn) {
207
+ if (typeof fn === "function") {
208
+ return new FunctionDisposer(fn, this, createContext());
209
+ }
210
+ throw new TypeError();
211
+ };
212
+
213
+ };