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,226 @@
1
+ "use strict";
2
+ module.exports = function (Promise, apiRejection, tryConvertToPromise,
3
+ createContext, INTERNAL, debug) {
4
+ var util = require("./util");
5
+ var TypeError = require("./errors").TypeError;
6
+ var inherits = require("./util").inherits;
7
+ var errorObj = util.errorObj;
8
+ var tryCatch = util.tryCatch;
9
+ var NULL = {};
10
+
11
+ function thrower(e) {
12
+ setTimeout(function(){throw e;}, 0);
13
+ }
14
+
15
+ function castPreservingDisposable(thenable) {
16
+ var maybePromise = tryConvertToPromise(thenable);
17
+ if (maybePromise !== thenable &&
18
+ typeof thenable._isDisposable === "function" &&
19
+ typeof thenable._getDisposer === "function" &&
20
+ thenable._isDisposable()) {
21
+ maybePromise._setDisposable(thenable._getDisposer());
22
+ }
23
+ return maybePromise;
24
+ }
25
+ function dispose(resources, inspection) {
26
+ var i = 0;
27
+ var len = resources.length;
28
+ var ret = new Promise(INTERNAL);
29
+ function iterator() {
30
+ if (i >= len) return ret._fulfill();
31
+ var maybePromise = castPreservingDisposable(resources[i++]);
32
+ if (maybePromise instanceof Promise &&
33
+ maybePromise._isDisposable()) {
34
+ try {
35
+ maybePromise = tryConvertToPromise(
36
+ maybePromise._getDisposer().tryDispose(inspection),
37
+ resources.promise);
38
+ } catch (e) {
39
+ return thrower(e);
40
+ }
41
+ if (maybePromise instanceof Promise) {
42
+ return maybePromise._then(iterator, thrower,
43
+ null, null, null);
44
+ }
45
+ }
46
+ iterator();
47
+ }
48
+ iterator();
49
+ return ret;
50
+ }
51
+
52
+ function Disposer(data, promise, context) {
53
+ this._data = data;
54
+ this._promise = promise;
55
+ this._context = context;
56
+ }
57
+
58
+ Disposer.prototype.data = function () {
59
+ return this._data;
60
+ };
61
+
62
+ Disposer.prototype.promise = function () {
63
+ return this._promise;
64
+ };
65
+
66
+ Disposer.prototype.resource = function () {
67
+ if (this.promise().isFulfilled()) {
68
+ return this.promise().value();
69
+ }
70
+ return NULL;
71
+ };
72
+
73
+ Disposer.prototype.tryDispose = function(inspection) {
74
+ var resource = this.resource();
75
+ var context = this._context;
76
+ if (context !== undefined) context._pushContext();
77
+ var ret = resource !== NULL
78
+ ? this.doDispose(resource, inspection) : null;
79
+ if (context !== undefined) context._popContext();
80
+ this._promise._unsetDisposable();
81
+ this._data = null;
82
+ return ret;
83
+ };
84
+
85
+ Disposer.isDisposer = function (d) {
86
+ return (d != null &&
87
+ typeof d.resource === "function" &&
88
+ typeof d.tryDispose === "function");
89
+ };
90
+
91
+ function FunctionDisposer(fn, promise, context) {
92
+ this.constructor$(fn, promise, context);
93
+ }
94
+ inherits(FunctionDisposer, Disposer);
95
+
96
+ FunctionDisposer.prototype.doDispose = function (resource, inspection) {
97
+ var fn = this.data();
98
+ return fn.call(resource, resource, inspection);
99
+ };
100
+
101
+ function maybeUnwrapDisposer(value) {
102
+ if (Disposer.isDisposer(value)) {
103
+ this.resources[this.index]._setDisposable(value);
104
+ return value.promise();
105
+ }
106
+ return value;
107
+ }
108
+
109
+ function ResourceList(length) {
110
+ this.length = length;
111
+ this.promise = null;
112
+ this[length-1] = null;
113
+ }
114
+
115
+ ResourceList.prototype._resultCancelled = function() {
116
+ var len = this.length;
117
+ for (var i = 0; i < len; ++i) {
118
+ var item = this[i];
119
+ if (item instanceof Promise) {
120
+ item.cancel();
121
+ }
122
+ }
123
+ };
124
+
125
+ Promise.using = function () {
126
+ var len = arguments.length;
127
+ if (len < 2) return apiRejection(
128
+ "you must pass at least 2 arguments to Promise.using");
129
+ var fn = arguments[len - 1];
130
+ if (typeof fn !== "function") {
131
+ return apiRejection("expecting a function but got " + util.classString(fn));
132
+ }
133
+ var input;
134
+ var spreadArgs = true;
135
+ if (len === 2 && Array.isArray(arguments[0])) {
136
+ input = arguments[0];
137
+ len = input.length;
138
+ spreadArgs = false;
139
+ } else {
140
+ input = arguments;
141
+ len--;
142
+ }
143
+ var resources = new ResourceList(len);
144
+ for (var i = 0; i < len; ++i) {
145
+ var resource = input[i];
146
+ if (Disposer.isDisposer(resource)) {
147
+ var disposer = resource;
148
+ resource = resource.promise();
149
+ resource._setDisposable(disposer);
150
+ } else {
151
+ var maybePromise = tryConvertToPromise(resource);
152
+ if (maybePromise instanceof Promise) {
153
+ resource =
154
+ maybePromise._then(maybeUnwrapDisposer, null, null, {
155
+ resources: resources,
156
+ index: i
157
+ }, undefined);
158
+ }
159
+ }
160
+ resources[i] = resource;
161
+ }
162
+
163
+ var reflectedResources = new Array(resources.length);
164
+ for (var i = 0; i < reflectedResources.length; ++i) {
165
+ reflectedResources[i] = Promise.resolve(resources[i]).reflect();
166
+ }
167
+
168
+ var resultPromise = Promise.all(reflectedResources)
169
+ .then(function(inspections) {
170
+ for (var i = 0; i < inspections.length; ++i) {
171
+ var inspection = inspections[i];
172
+ if (inspection.isRejected()) {
173
+ errorObj.e = inspection.error();
174
+ return errorObj;
175
+ } else if (!inspection.isFulfilled()) {
176
+ resultPromise.cancel();
177
+ return;
178
+ }
179
+ inspections[i] = inspection.value();
180
+ }
181
+ promise._pushContext();
182
+
183
+ fn = tryCatch(fn);
184
+ var ret = spreadArgs
185
+ ? fn.apply(undefined, inspections) : fn(inspections);
186
+ var promiseCreated = promise._popContext();
187
+ debug.checkForgottenReturns(
188
+ ret, promiseCreated, "Promise.using", promise);
189
+ return ret;
190
+ });
191
+
192
+ var promise = resultPromise.lastly(function() {
193
+ var inspection = new Promise.PromiseInspection(resultPromise);
194
+ return dispose(resources, inspection);
195
+ });
196
+ resources.promise = promise;
197
+ promise._setOnCancel(resources);
198
+ return promise;
199
+ };
200
+
201
+ Promise.prototype._setDisposable = function (disposer) {
202
+ this._bitField = this._bitField | 131072;
203
+ this._disposer = disposer;
204
+ };
205
+
206
+ Promise.prototype._isDisposable = function () {
207
+ return (this._bitField & 131072) > 0;
208
+ };
209
+
210
+ Promise.prototype._getDisposer = function () {
211
+ return this._disposer;
212
+ };
213
+
214
+ Promise.prototype._unsetDisposable = function () {
215
+ this._bitField = this._bitField & (~131072);
216
+ this._disposer = undefined;
217
+ };
218
+
219
+ Promise.prototype.disposer = function (fn) {
220
+ if (typeof fn === "function") {
221
+ return new FunctionDisposer(fn, this, createContext());
222
+ }
223
+ throw new TypeError();
224
+ };
225
+
226
+ };
@@ -0,0 +1,389 @@
1
+ "use strict";
2
+ var es5 = require("./es5");
3
+ var canEvaluate = typeof navigator == "undefined";
4
+
5
+ var errorObj = {e: {}};
6
+ var tryCatchTarget;
7
+ var globalObject = typeof self !== "undefined" ? self :
8
+ typeof window !== "undefined" ? window :
9
+ typeof global !== "undefined" ? global :
10
+ this !== undefined ? this : null;
11
+
12
+ function tryCatcher() {
13
+ try {
14
+ var target = tryCatchTarget;
15
+ tryCatchTarget = null;
16
+ return target.apply(this, arguments);
17
+ } catch (e) {
18
+ errorObj.e = e;
19
+ return errorObj;
20
+ }
21
+ }
22
+ function tryCatch(fn) {
23
+ tryCatchTarget = fn;
24
+ return tryCatcher;
25
+ }
26
+
27
+ var inherits = function(Child, Parent) {
28
+ var hasProp = {}.hasOwnProperty;
29
+
30
+ function T() {
31
+ this.constructor = Child;
32
+ this.constructor$ = Parent;
33
+ for (var propertyName in Parent.prototype) {
34
+ if (hasProp.call(Parent.prototype, propertyName) &&
35
+ propertyName.charAt(propertyName.length-1) !== "$"
36
+ ) {
37
+ this[propertyName + "$"] = Parent.prototype[propertyName];
38
+ }
39
+ }
40
+ }
41
+ T.prototype = Parent.prototype;
42
+ Child.prototype = new T();
43
+ return Child.prototype;
44
+ };
45
+
46
+
47
+ function isPrimitive(val) {
48
+ return val == null || val === true || val === false ||
49
+ typeof val === "string" || typeof val === "number";
50
+
51
+ }
52
+
53
+ function isObject(value) {
54
+ return typeof value === "function" ||
55
+ typeof value === "object" && value !== null;
56
+ }
57
+
58
+ function maybeWrapAsError(maybeError) {
59
+ if (!isPrimitive(maybeError)) return maybeError;
60
+
61
+ return new Error(safeToString(maybeError));
62
+ }
63
+
64
+ function withAppended(target, appendee) {
65
+ var len = target.length;
66
+ var ret = new Array(len + 1);
67
+ var i;
68
+ for (i = 0; i < len; ++i) {
69
+ ret[i] = target[i];
70
+ }
71
+ ret[i] = appendee;
72
+ return ret;
73
+ }
74
+
75
+ function getDataPropertyOrDefault(obj, key, defaultValue) {
76
+ if (es5.isES5) {
77
+ var desc = Object.getOwnPropertyDescriptor(obj, key);
78
+
79
+ if (desc != null) {
80
+ return desc.get == null && desc.set == null
81
+ ? desc.value
82
+ : defaultValue;
83
+ }
84
+ } else {
85
+ return {}.hasOwnProperty.call(obj, key) ? obj[key] : undefined;
86
+ }
87
+ }
88
+
89
+ function notEnumerableProp(obj, name, value) {
90
+ if (isPrimitive(obj)) return obj;
91
+ var descriptor = {
92
+ value: value,
93
+ configurable: true,
94
+ enumerable: false,
95
+ writable: true
96
+ };
97
+ es5.defineProperty(obj, name, descriptor);
98
+ return obj;
99
+ }
100
+
101
+ function thrower(r) {
102
+ throw r;
103
+ }
104
+
105
+ var inheritedDataKeys = (function() {
106
+ var excludedPrototypes = [
107
+ Array.prototype,
108
+ Object.prototype,
109
+ Function.prototype
110
+ ];
111
+
112
+ var isExcludedProto = function(val) {
113
+ for (var i = 0; i < excludedPrototypes.length; ++i) {
114
+ if (excludedPrototypes[i] === val) {
115
+ return true;
116
+ }
117
+ }
118
+ return false;
119
+ };
120
+
121
+ if (es5.isES5) {
122
+ var getKeys = Object.getOwnPropertyNames;
123
+ return function(obj) {
124
+ var ret = [];
125
+ var visitedKeys = Object.create(null);
126
+ while (obj != null && !isExcludedProto(obj)) {
127
+ var keys;
128
+ try {
129
+ keys = getKeys(obj);
130
+ } catch (e) {
131
+ return ret;
132
+ }
133
+ for (var i = 0; i < keys.length; ++i) {
134
+ var key = keys[i];
135
+ if (visitedKeys[key]) continue;
136
+ visitedKeys[key] = true;
137
+ var desc = Object.getOwnPropertyDescriptor(obj, key);
138
+ if (desc != null && desc.get == null && desc.set == null) {
139
+ ret.push(key);
140
+ }
141
+ }
142
+ obj = es5.getPrototypeOf(obj);
143
+ }
144
+ return ret;
145
+ };
146
+ } else {
147
+ var hasProp = {}.hasOwnProperty;
148
+ return function(obj) {
149
+ if (isExcludedProto(obj)) return [];
150
+ var ret = [];
151
+
152
+ /*jshint forin:false */
153
+ enumeration: for (var key in obj) {
154
+ if (hasProp.call(obj, key)) {
155
+ ret.push(key);
156
+ } else {
157
+ for (var i = 0; i < excludedPrototypes.length; ++i) {
158
+ if (hasProp.call(excludedPrototypes[i], key)) {
159
+ continue enumeration;
160
+ }
161
+ }
162
+ ret.push(key);
163
+ }
164
+ }
165
+ return ret;
166
+ };
167
+ }
168
+
169
+ })();
170
+
171
+ var thisAssignmentPattern = /this\s*\.\s*\S+\s*=/;
172
+ function isClass(fn) {
173
+ try {
174
+ if (typeof fn === "function") {
175
+ var keys = es5.names(fn.prototype);
176
+
177
+ var hasMethods = es5.isES5 && keys.length > 1;
178
+ var hasMethodsOtherThanConstructor = keys.length > 0 &&
179
+ !(keys.length === 1 && keys[0] === "constructor");
180
+ var hasThisAssignmentAndStaticMethods =
181
+ thisAssignmentPattern.test(fn + "") && es5.names(fn).length > 0;
182
+
183
+ if (hasMethods || hasMethodsOtherThanConstructor ||
184
+ hasThisAssignmentAndStaticMethods) {
185
+ return true;
186
+ }
187
+ }
188
+ return false;
189
+ } catch (e) {
190
+ return false;
191
+ }
192
+ }
193
+
194
+ function toFastProperties(obj) {
195
+ /*jshint -W027,-W055,-W031*/
196
+ function FakeConstructor() {}
197
+ FakeConstructor.prototype = obj;
198
+ var receiver = new FakeConstructor();
199
+ function ic() {
200
+ return typeof receiver.foo;
201
+ }
202
+ ic();
203
+ ic();
204
+ return obj;
205
+ eval(obj);
206
+ }
207
+
208
+ var rident = /^[a-z$_][a-z$_0-9]*$/i;
209
+ function isIdentifier(str) {
210
+ return rident.test(str);
211
+ }
212
+
213
+ function filledRange(count, prefix, suffix) {
214
+ var ret = new Array(count);
215
+ for(var i = 0; i < count; ++i) {
216
+ ret[i] = prefix + i + suffix;
217
+ }
218
+ return ret;
219
+ }
220
+
221
+ function safeToString(obj) {
222
+ try {
223
+ return obj + "";
224
+ } catch (e) {
225
+ return "[no string representation]";
226
+ }
227
+ }
228
+
229
+ function isError(obj) {
230
+ return obj instanceof Error ||
231
+ (obj !== null &&
232
+ typeof obj === "object" &&
233
+ typeof obj.message === "string" &&
234
+ typeof obj.name === "string");
235
+ }
236
+
237
+ function markAsOriginatingFromRejection(e) {
238
+ try {
239
+ notEnumerableProp(e, "isOperational", true);
240
+ }
241
+ catch(ignore) {}
242
+ }
243
+
244
+ function originatesFromRejection(e) {
245
+ if (e == null) return false;
246
+ return ((e instanceof Error["__BluebirdErrorTypes__"].OperationalError) ||
247
+ e["isOperational"] === true);
248
+ }
249
+
250
+ function canAttachTrace(obj) {
251
+ return isError(obj) && es5.propertyIsWritable(obj, "stack");
252
+ }
253
+
254
+ var ensureErrorObject = (function() {
255
+ if (!("stack" in new Error())) {
256
+ return function(value) {
257
+ if (canAttachTrace(value)) return value;
258
+ try {throw new Error(safeToString(value));}
259
+ catch(err) {return err;}
260
+ };
261
+ } else {
262
+ return function(value) {
263
+ if (canAttachTrace(value)) return value;
264
+ return new Error(safeToString(value));
265
+ };
266
+ }
267
+ })();
268
+
269
+ function classString(obj) {
270
+ return {}.toString.call(obj);
271
+ }
272
+
273
+ function copyDescriptors(from, to, filter) {
274
+ var keys = es5.names(from);
275
+ for (var i = 0; i < keys.length; ++i) {
276
+ var key = keys[i];
277
+ if (filter(key)) {
278
+ try {
279
+ es5.defineProperty(to, key, es5.getDescriptor(from, key));
280
+ } catch (ignore) {}
281
+ }
282
+ }
283
+ }
284
+
285
+ var asArray = function(v) {
286
+ if (es5.isArray(v)) {
287
+ return v;
288
+ }
289
+ return null;
290
+ };
291
+
292
+ if (typeof Symbol !== "undefined" && Symbol.iterator) {
293
+ var ArrayFrom = typeof Array.from === "function" ? function(v) {
294
+ return Array.from(v);
295
+ } : function(v) {
296
+ var ret = [];
297
+ var it = v[Symbol.iterator]();
298
+ var itResult;
299
+ while (!((itResult = it.next()).done)) {
300
+ ret.push(itResult.value);
301
+ }
302
+ return ret;
303
+ };
304
+
305
+ asArray = function(v) {
306
+ if (es5.isArray(v)) {
307
+ return v;
308
+ } else if (v != null && typeof v[Symbol.iterator] === "function") {
309
+ return ArrayFrom(v);
310
+ }
311
+ return null;
312
+ };
313
+ }
314
+
315
+ var isNode = typeof process !== "undefined" &&
316
+ classString(process).toLowerCase() === "[object process]";
317
+
318
+ var hasEnvVariables = typeof process !== "undefined" &&
319
+ typeof process.env !== "undefined";
320
+
321
+ function env(key) {
322
+ return hasEnvVariables ? process.env[key] : undefined;
323
+ }
324
+
325
+ function getNativePromise() {
326
+ if (typeof Promise === "function") {
327
+ try {
328
+ var promise = new Promise(function(){});
329
+ if ({}.toString.call(promise) === "[object Promise]") {
330
+ return Promise;
331
+ }
332
+ } catch (e) {}
333
+ }
334
+ }
335
+
336
+ function domainBind(self, cb) {
337
+ return self.bind(cb);
338
+ }
339
+
340
+ var ret = {
341
+ isClass: isClass,
342
+ isIdentifier: isIdentifier,
343
+ inheritedDataKeys: inheritedDataKeys,
344
+ getDataPropertyOrDefault: getDataPropertyOrDefault,
345
+ thrower: thrower,
346
+ isArray: es5.isArray,
347
+ asArray: asArray,
348
+ notEnumerableProp: notEnumerableProp,
349
+ isPrimitive: isPrimitive,
350
+ isObject: isObject,
351
+ isError: isError,
352
+ canEvaluate: canEvaluate,
353
+ errorObj: errorObj,
354
+ tryCatch: tryCatch,
355
+ inherits: inherits,
356
+ withAppended: withAppended,
357
+ maybeWrapAsError: maybeWrapAsError,
358
+ toFastProperties: toFastProperties,
359
+ filledRange: filledRange,
360
+ toString: safeToString,
361
+ canAttachTrace: canAttachTrace,
362
+ ensureErrorObject: ensureErrorObject,
363
+ originatesFromRejection: originatesFromRejection,
364
+ markAsOriginatingFromRejection: markAsOriginatingFromRejection,
365
+ classString: classString,
366
+ copyDescriptors: copyDescriptors,
367
+ hasDevTools: typeof chrome !== "undefined" && chrome &&
368
+ typeof chrome.loadTimes === "function",
369
+ isNode: isNode,
370
+ hasEnvVariables: hasEnvVariables,
371
+ env: env,
372
+ global: globalObject,
373
+ getNativePromise: getNativePromise,
374
+ domainBind: domainBind
375
+ };
376
+ ret.isRecentNode = ret.isNode && (function() {
377
+ var version;
378
+ if (process.versions && process.versions.node) {
379
+ version = process.versions.node.split(".").map(Number);
380
+ } else if (process.version) {
381
+ version = process.version.split(".").map(Number);
382
+ }
383
+ return (version[0] === 0 && version[1] > 10) || (version[0] > 0);
384
+ })();
385
+
386
+ if (ret.isNode) ret.toFastProperties(process);
387
+
388
+ try {throw new Error(); } catch (e) {ret.lastLineError = e;}
389
+ module.exports = ret;