browsed 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/Gemfile.lock +2 -2
- data/README.md +12 -17
- data/bin/browse +13 -10
- data/lib/browsed.rb +9 -2
- data/lib/browsed/browser.rb +82 -0
- data/lib/browsed/chrome.rb +21 -12
- data/lib/browsed/client.rb +48 -130
- data/lib/browsed/constants.rb +7 -1
- data/lib/browsed/errors.rb +1 -0
- data/lib/browsed/extensions/hash.rb +27 -0
- data/lib/browsed/firefox.rb +18 -17
- data/lib/browsed/manager.rb +5 -5
- data/lib/browsed/{poltergeist.rb → phantomjs.rb} +2 -2
- data/lib/browsed/proxies.rb +26 -0
- data/lib/browsed/{extensions → proxies}/chrome/proxy_authentication.rb +3 -3
- data/lib/browsed/proxies/proxy-chain-server/node_modules/.bin/portastic +1 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/LICENSE +21 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/README.md +57 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/changelog.md +1 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/browser/bluebird.core.js +3824 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/browser/bluebird.core.min.js +31 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/browser/bluebird.js +5666 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/browser/bluebird.min.js +31 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/any.js +21 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/assert.js +55 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/async.js +165 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/bind.js +67 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/bluebird.js +11 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/call_get.js +123 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/cancel.js +129 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/catch_filter.js +42 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/context.js +69 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/debuggability.js +934 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/direct_resolve.js +46 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/each.js +30 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/errors.js +116 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/es5.js +80 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/filter.js +12 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/finally.js +146 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/generators.js +223 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/join.js +168 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/map.js +168 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/method.js +55 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/nodeback.js +51 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/nodeify.js +58 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/promise.js +789 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/promise_array.js +185 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/promisify.js +314 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/props.js +118 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/queue.js +73 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/race.js +49 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/reduce.js +172 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/schedule.js +62 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/settle.js +43 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/some.js +148 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/synchronous_inspection.js +103 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/thenables.js +86 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/timers.js +93 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/using.js +226 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/util.js +389 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/package.json +102 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/CHANGELOG.md +408 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/LICENSE +22 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/Readme.md +428 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/index.js +1224 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/package.json +70 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/typings/index.d.ts +310 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/.coveralls.yml +1 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/.eslintrc +11 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/.npmignore +9 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/.travis.yml +14 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/CHANGELOG.md +362 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/LICENSE +19 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/Makefile +50 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/README.md +312 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/component.json +19 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/karma.conf.js +70 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/node.js +1 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/package.json +88 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/src/browser.js +185 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/src/debug.js +202 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/src/index.js +10 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/src/inspector-log.js +15 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/src/node.js +248 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/ms/index.js +152 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/ms/license.md +21 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/ms/package.json +69 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/ms/readme.md +51 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/LICENSE +13 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/README.md +148 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/bin/portastic +65 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/history.md +7 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/index.js +4 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/lib/monitor.js +59 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/lib/portastic.js +167 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/LICENSE +21 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/README.md +677 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/changelog.md +1730 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/browser/bluebird.js +4892 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/browser/bluebird.min.js +31 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/any.js +21 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/assert.js +55 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/async.js +150 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/bind.js +72 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/bluebird.js +11 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/call_get.js +123 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/cancel.js +48 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/captured_trace.js +493 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/catch_filter.js +66 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/context.js +38 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/debuggability.js +162 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/direct_resolve.js +63 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/each.js +12 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/errors.js +111 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/es5.js +80 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/filter.js +12 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/finally.js +98 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/generators.js +136 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/join.js +107 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/map.js +133 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/method.js +44 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/nodeify.js +59 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/progress.js +76 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/promise.js +759 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/promise_array.js +142 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/promise_resolver.js +123 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/promisify.js +307 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/props.js +79 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/queue.js +90 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/race.js +47 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/reduce.js +148 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/schedule.js +35 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/settle.js +40 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/some.js +125 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/synchronous_inspection.js +94 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/thenables.js +84 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/timers.js +64 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/using.js +213 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/util.js +321 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/package.json +103 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/package.json +69 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/CHANGELOG.md +109 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/LICENSE +201 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/README.md +278 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/anonymize_proxy.js +100 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_base.js +319 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_custom_response.js +96 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_forward.js +173 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_tunnel_chain.js +132 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_tunnel_direct.js +89 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_tunnel_tcp_chain.js +271 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/index.js +26 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/run_locally.js +66 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/server.js +595 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/tcp_tunnel.js +138 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/testing_tcp_service.js +37 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/tools.js +220 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/package.json +104 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/LICENSE +23 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/README.md +28 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/package.json +81 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/underscore-min.js +5 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/underscore-min.js.map +1 -0
- data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/underscore.js +1692 -0
- data/lib/browsed/proxies/proxy-chain-server/package-lock.json +63 -0
- data/lib/browsed/proxies/proxy-chain-server/package.json +15 -0
- data/lib/browsed/proxies/proxy-chain-server/server.js +25 -0
- data/lib/browsed/proxies/proxy_chain.rb +36 -0
- data/lib/browsed/version.rb +1 -1
- metadata +160 -4
@@ -0,0 +1,168 @@
|
|
1
|
+
"use strict";
|
2
|
+
module.exports =
|
3
|
+
function(Promise, PromiseArray, tryConvertToPromise, INTERNAL, async,
|
4
|
+
getDomain) {
|
5
|
+
var util = require("./util");
|
6
|
+
var canEvaluate = util.canEvaluate;
|
7
|
+
var tryCatch = util.tryCatch;
|
8
|
+
var errorObj = util.errorObj;
|
9
|
+
var reject;
|
10
|
+
|
11
|
+
if (!false) {
|
12
|
+
if (canEvaluate) {
|
13
|
+
var thenCallback = function(i) {
|
14
|
+
return new Function("value", "holder", " \n\
|
15
|
+
'use strict'; \n\
|
16
|
+
holder.pIndex = value; \n\
|
17
|
+
holder.checkFulfillment(this); \n\
|
18
|
+
".replace(/Index/g, i));
|
19
|
+
};
|
20
|
+
|
21
|
+
var promiseSetter = function(i) {
|
22
|
+
return new Function("promise", "holder", " \n\
|
23
|
+
'use strict'; \n\
|
24
|
+
holder.pIndex = promise; \n\
|
25
|
+
".replace(/Index/g, i));
|
26
|
+
};
|
27
|
+
|
28
|
+
var generateHolderClass = function(total) {
|
29
|
+
var props = new Array(total);
|
30
|
+
for (var i = 0; i < props.length; ++i) {
|
31
|
+
props[i] = "this.p" + (i+1);
|
32
|
+
}
|
33
|
+
var assignment = props.join(" = ") + " = null;";
|
34
|
+
var cancellationCode= "var promise;\n" + props.map(function(prop) {
|
35
|
+
return " \n\
|
36
|
+
promise = " + prop + "; \n\
|
37
|
+
if (promise instanceof Promise) { \n\
|
38
|
+
promise.cancel(); \n\
|
39
|
+
} \n\
|
40
|
+
";
|
41
|
+
}).join("\n");
|
42
|
+
var passedArguments = props.join(", ");
|
43
|
+
var name = "Holder$" + total;
|
44
|
+
|
45
|
+
|
46
|
+
var code = "return function(tryCatch, errorObj, Promise, async) { \n\
|
47
|
+
'use strict'; \n\
|
48
|
+
function [TheName](fn) { \n\
|
49
|
+
[TheProperties] \n\
|
50
|
+
this.fn = fn; \n\
|
51
|
+
this.asyncNeeded = true; \n\
|
52
|
+
this.now = 0; \n\
|
53
|
+
} \n\
|
54
|
+
\n\
|
55
|
+
[TheName].prototype._callFunction = function(promise) { \n\
|
56
|
+
promise._pushContext(); \n\
|
57
|
+
var ret = tryCatch(this.fn)([ThePassedArguments]); \n\
|
58
|
+
promise._popContext(); \n\
|
59
|
+
if (ret === errorObj) { \n\
|
60
|
+
promise._rejectCallback(ret.e, false); \n\
|
61
|
+
} else { \n\
|
62
|
+
promise._resolveCallback(ret); \n\
|
63
|
+
} \n\
|
64
|
+
}; \n\
|
65
|
+
\n\
|
66
|
+
[TheName].prototype.checkFulfillment = function(promise) { \n\
|
67
|
+
var now = ++this.now; \n\
|
68
|
+
if (now === [TheTotal]) { \n\
|
69
|
+
if (this.asyncNeeded) { \n\
|
70
|
+
async.invoke(this._callFunction, this, promise); \n\
|
71
|
+
} else { \n\
|
72
|
+
this._callFunction(promise); \n\
|
73
|
+
} \n\
|
74
|
+
\n\
|
75
|
+
} \n\
|
76
|
+
}; \n\
|
77
|
+
\n\
|
78
|
+
[TheName].prototype._resultCancelled = function() { \n\
|
79
|
+
[CancellationCode] \n\
|
80
|
+
}; \n\
|
81
|
+
\n\
|
82
|
+
return [TheName]; \n\
|
83
|
+
}(tryCatch, errorObj, Promise, async); \n\
|
84
|
+
";
|
85
|
+
|
86
|
+
code = code.replace(/\[TheName\]/g, name)
|
87
|
+
.replace(/\[TheTotal\]/g, total)
|
88
|
+
.replace(/\[ThePassedArguments\]/g, passedArguments)
|
89
|
+
.replace(/\[TheProperties\]/g, assignment)
|
90
|
+
.replace(/\[CancellationCode\]/g, cancellationCode);
|
91
|
+
|
92
|
+
return new Function("tryCatch", "errorObj", "Promise", "async", code)
|
93
|
+
(tryCatch, errorObj, Promise, async);
|
94
|
+
};
|
95
|
+
|
96
|
+
var holderClasses = [];
|
97
|
+
var thenCallbacks = [];
|
98
|
+
var promiseSetters = [];
|
99
|
+
|
100
|
+
for (var i = 0; i < 8; ++i) {
|
101
|
+
holderClasses.push(generateHolderClass(i + 1));
|
102
|
+
thenCallbacks.push(thenCallback(i + 1));
|
103
|
+
promiseSetters.push(promiseSetter(i + 1));
|
104
|
+
}
|
105
|
+
|
106
|
+
reject = function (reason) {
|
107
|
+
this._reject(reason);
|
108
|
+
};
|
109
|
+
}}
|
110
|
+
|
111
|
+
Promise.join = function () {
|
112
|
+
var last = arguments.length - 1;
|
113
|
+
var fn;
|
114
|
+
if (last > 0 && typeof arguments[last] === "function") {
|
115
|
+
fn = arguments[last];
|
116
|
+
if (!false) {
|
117
|
+
if (last <= 8 && canEvaluate) {
|
118
|
+
var ret = new Promise(INTERNAL);
|
119
|
+
ret._captureStackTrace();
|
120
|
+
var HolderClass = holderClasses[last - 1];
|
121
|
+
var holder = new HolderClass(fn);
|
122
|
+
var callbacks = thenCallbacks;
|
123
|
+
|
124
|
+
for (var i = 0; i < last; ++i) {
|
125
|
+
var maybePromise = tryConvertToPromise(arguments[i], ret);
|
126
|
+
if (maybePromise instanceof Promise) {
|
127
|
+
maybePromise = maybePromise._target();
|
128
|
+
var bitField = maybePromise._bitField;
|
129
|
+
;
|
130
|
+
if (((bitField & 50397184) === 0)) {
|
131
|
+
maybePromise._then(callbacks[i], reject,
|
132
|
+
undefined, ret, holder);
|
133
|
+
promiseSetters[i](maybePromise, holder);
|
134
|
+
holder.asyncNeeded = false;
|
135
|
+
} else if (((bitField & 33554432) !== 0)) {
|
136
|
+
callbacks[i].call(ret,
|
137
|
+
maybePromise._value(), holder);
|
138
|
+
} else if (((bitField & 16777216) !== 0)) {
|
139
|
+
ret._reject(maybePromise._reason());
|
140
|
+
} else {
|
141
|
+
ret._cancel();
|
142
|
+
}
|
143
|
+
} else {
|
144
|
+
callbacks[i].call(ret, maybePromise, holder);
|
145
|
+
}
|
146
|
+
}
|
147
|
+
|
148
|
+
if (!ret._isFateSealed()) {
|
149
|
+
if (holder.asyncNeeded) {
|
150
|
+
var domain = getDomain();
|
151
|
+
if (domain !== null) {
|
152
|
+
holder.fn = util.domainBind(domain, holder.fn);
|
153
|
+
}
|
154
|
+
}
|
155
|
+
ret._setAsyncGuaranteed();
|
156
|
+
ret._setOnCancel(holder);
|
157
|
+
}
|
158
|
+
return ret;
|
159
|
+
}
|
160
|
+
}
|
161
|
+
}
|
162
|
+
var $_len = arguments.length;var args = new Array($_len); for(var $_i = 0; $_i < $_len; ++$_i) {args[$_i] = arguments[$_i];};
|
163
|
+
if (fn) args.pop();
|
164
|
+
var ret = new PromiseArray(args).promise();
|
165
|
+
return fn !== undefined ? ret.spread(fn) : ret;
|
166
|
+
};
|
167
|
+
|
168
|
+
};
|
@@ -0,0 +1,168 @@
|
|
1
|
+
"use strict";
|
2
|
+
module.exports = function(Promise,
|
3
|
+
PromiseArray,
|
4
|
+
apiRejection,
|
5
|
+
tryConvertToPromise,
|
6
|
+
INTERNAL,
|
7
|
+
debug) {
|
8
|
+
var getDomain = Promise._getDomain;
|
9
|
+
var util = require("./util");
|
10
|
+
var tryCatch = util.tryCatch;
|
11
|
+
var errorObj = util.errorObj;
|
12
|
+
var async = Promise._async;
|
13
|
+
|
14
|
+
function MappingPromiseArray(promises, fn, limit, _filter) {
|
15
|
+
this.constructor$(promises);
|
16
|
+
this._promise._captureStackTrace();
|
17
|
+
var domain = getDomain();
|
18
|
+
this._callback = domain === null ? fn : util.domainBind(domain, fn);
|
19
|
+
this._preservedValues = _filter === INTERNAL
|
20
|
+
? new Array(this.length())
|
21
|
+
: null;
|
22
|
+
this._limit = limit;
|
23
|
+
this._inFlight = 0;
|
24
|
+
this._queue = [];
|
25
|
+
async.invoke(this._asyncInit, this, undefined);
|
26
|
+
}
|
27
|
+
util.inherits(MappingPromiseArray, PromiseArray);
|
28
|
+
|
29
|
+
MappingPromiseArray.prototype._asyncInit = function() {
|
30
|
+
this._init$(undefined, -2);
|
31
|
+
};
|
32
|
+
|
33
|
+
MappingPromiseArray.prototype._init = function () {};
|
34
|
+
|
35
|
+
MappingPromiseArray.prototype._promiseFulfilled = function (value, index) {
|
36
|
+
var values = this._values;
|
37
|
+
var length = this.length();
|
38
|
+
var preservedValues = this._preservedValues;
|
39
|
+
var limit = this._limit;
|
40
|
+
|
41
|
+
if (index < 0) {
|
42
|
+
index = (index * -1) - 1;
|
43
|
+
values[index] = value;
|
44
|
+
if (limit >= 1) {
|
45
|
+
this._inFlight--;
|
46
|
+
this._drainQueue();
|
47
|
+
if (this._isResolved()) return true;
|
48
|
+
}
|
49
|
+
} else {
|
50
|
+
if (limit >= 1 && this._inFlight >= limit) {
|
51
|
+
values[index] = value;
|
52
|
+
this._queue.push(index);
|
53
|
+
return false;
|
54
|
+
}
|
55
|
+
if (preservedValues !== null) preservedValues[index] = value;
|
56
|
+
|
57
|
+
var promise = this._promise;
|
58
|
+
var callback = this._callback;
|
59
|
+
var receiver = promise._boundValue();
|
60
|
+
promise._pushContext();
|
61
|
+
var ret = tryCatch(callback).call(receiver, value, index, length);
|
62
|
+
var promiseCreated = promise._popContext();
|
63
|
+
debug.checkForgottenReturns(
|
64
|
+
ret,
|
65
|
+
promiseCreated,
|
66
|
+
preservedValues !== null ? "Promise.filter" : "Promise.map",
|
67
|
+
promise
|
68
|
+
);
|
69
|
+
if (ret === errorObj) {
|
70
|
+
this._reject(ret.e);
|
71
|
+
return true;
|
72
|
+
}
|
73
|
+
|
74
|
+
var maybePromise = tryConvertToPromise(ret, this._promise);
|
75
|
+
if (maybePromise instanceof Promise) {
|
76
|
+
maybePromise = maybePromise._target();
|
77
|
+
var bitField = maybePromise._bitField;
|
78
|
+
;
|
79
|
+
if (((bitField & 50397184) === 0)) {
|
80
|
+
if (limit >= 1) this._inFlight++;
|
81
|
+
values[index] = maybePromise;
|
82
|
+
maybePromise._proxy(this, (index + 1) * -1);
|
83
|
+
return false;
|
84
|
+
} else if (((bitField & 33554432) !== 0)) {
|
85
|
+
ret = maybePromise._value();
|
86
|
+
} else if (((bitField & 16777216) !== 0)) {
|
87
|
+
this._reject(maybePromise._reason());
|
88
|
+
return true;
|
89
|
+
} else {
|
90
|
+
this._cancel();
|
91
|
+
return true;
|
92
|
+
}
|
93
|
+
}
|
94
|
+
values[index] = ret;
|
95
|
+
}
|
96
|
+
var totalResolved = ++this._totalResolved;
|
97
|
+
if (totalResolved >= length) {
|
98
|
+
if (preservedValues !== null) {
|
99
|
+
this._filter(values, preservedValues);
|
100
|
+
} else {
|
101
|
+
this._resolve(values);
|
102
|
+
}
|
103
|
+
return true;
|
104
|
+
}
|
105
|
+
return false;
|
106
|
+
};
|
107
|
+
|
108
|
+
MappingPromiseArray.prototype._drainQueue = function () {
|
109
|
+
var queue = this._queue;
|
110
|
+
var limit = this._limit;
|
111
|
+
var values = this._values;
|
112
|
+
while (queue.length > 0 && this._inFlight < limit) {
|
113
|
+
if (this._isResolved()) return;
|
114
|
+
var index = queue.pop();
|
115
|
+
this._promiseFulfilled(values[index], index);
|
116
|
+
}
|
117
|
+
};
|
118
|
+
|
119
|
+
MappingPromiseArray.prototype._filter = function (booleans, values) {
|
120
|
+
var len = values.length;
|
121
|
+
var ret = new Array(len);
|
122
|
+
var j = 0;
|
123
|
+
for (var i = 0; i < len; ++i) {
|
124
|
+
if (booleans[i]) ret[j++] = values[i];
|
125
|
+
}
|
126
|
+
ret.length = j;
|
127
|
+
this._resolve(ret);
|
128
|
+
};
|
129
|
+
|
130
|
+
MappingPromiseArray.prototype.preservedValues = function () {
|
131
|
+
return this._preservedValues;
|
132
|
+
};
|
133
|
+
|
134
|
+
function map(promises, fn, options, _filter) {
|
135
|
+
if (typeof fn !== "function") {
|
136
|
+
return apiRejection("expecting a function but got " + util.classString(fn));
|
137
|
+
}
|
138
|
+
|
139
|
+
var limit = 0;
|
140
|
+
if (options !== undefined) {
|
141
|
+
if (typeof options === "object" && options !== null) {
|
142
|
+
if (typeof options.concurrency !== "number") {
|
143
|
+
return Promise.reject(
|
144
|
+
new TypeError("'concurrency' must be a number but it is " +
|
145
|
+
util.classString(options.concurrency)));
|
146
|
+
}
|
147
|
+
limit = options.concurrency;
|
148
|
+
} else {
|
149
|
+
return Promise.reject(new TypeError(
|
150
|
+
"options argument must be an object but it is " +
|
151
|
+
util.classString(options)));
|
152
|
+
}
|
153
|
+
}
|
154
|
+
limit = typeof limit === "number" &&
|
155
|
+
isFinite(limit) && limit >= 1 ? limit : 0;
|
156
|
+
return new MappingPromiseArray(promises, fn, limit, _filter).promise();
|
157
|
+
}
|
158
|
+
|
159
|
+
Promise.prototype.map = function (fn, options) {
|
160
|
+
return map(this, fn, options, null);
|
161
|
+
};
|
162
|
+
|
163
|
+
Promise.map = function (promises, fn, options, _filter) {
|
164
|
+
return map(promises, fn, options, _filter);
|
165
|
+
};
|
166
|
+
|
167
|
+
|
168
|
+
};
|
@@ -0,0 +1,55 @@
|
|
1
|
+
"use strict";
|
2
|
+
module.exports =
|
3
|
+
function(Promise, INTERNAL, tryConvertToPromise, apiRejection, debug) {
|
4
|
+
var util = require("./util");
|
5
|
+
var tryCatch = util.tryCatch;
|
6
|
+
|
7
|
+
Promise.method = function (fn) {
|
8
|
+
if (typeof fn !== "function") {
|
9
|
+
throw new Promise.TypeError("expecting a function but got " + util.classString(fn));
|
10
|
+
}
|
11
|
+
return function () {
|
12
|
+
var ret = new Promise(INTERNAL);
|
13
|
+
ret._captureStackTrace();
|
14
|
+
ret._pushContext();
|
15
|
+
var value = tryCatch(fn).apply(this, arguments);
|
16
|
+
var promiseCreated = ret._popContext();
|
17
|
+
debug.checkForgottenReturns(
|
18
|
+
value, promiseCreated, "Promise.method", ret);
|
19
|
+
ret._resolveFromSyncValue(value);
|
20
|
+
return ret;
|
21
|
+
};
|
22
|
+
};
|
23
|
+
|
24
|
+
Promise.attempt = Promise["try"] = function (fn) {
|
25
|
+
if (typeof fn !== "function") {
|
26
|
+
return apiRejection("expecting a function but got " + util.classString(fn));
|
27
|
+
}
|
28
|
+
var ret = new Promise(INTERNAL);
|
29
|
+
ret._captureStackTrace();
|
30
|
+
ret._pushContext();
|
31
|
+
var value;
|
32
|
+
if (arguments.length > 1) {
|
33
|
+
debug.deprecated("calling Promise.try with more than 1 argument");
|
34
|
+
var arg = arguments[1];
|
35
|
+
var ctx = arguments[2];
|
36
|
+
value = util.isArray(arg) ? tryCatch(fn).apply(ctx, arg)
|
37
|
+
: tryCatch(fn).call(ctx, arg);
|
38
|
+
} else {
|
39
|
+
value = tryCatch(fn)();
|
40
|
+
}
|
41
|
+
var promiseCreated = ret._popContext();
|
42
|
+
debug.checkForgottenReturns(
|
43
|
+
value, promiseCreated, "Promise.try", ret);
|
44
|
+
ret._resolveFromSyncValue(value);
|
45
|
+
return ret;
|
46
|
+
};
|
47
|
+
|
48
|
+
Promise.prototype._resolveFromSyncValue = function (value) {
|
49
|
+
if (value === util.errorObj) {
|
50
|
+
this._rejectCallback(value.e, false);
|
51
|
+
} else {
|
52
|
+
this._resolveCallback(value, true);
|
53
|
+
}
|
54
|
+
};
|
55
|
+
};
|
@@ -0,0 +1,51 @@
|
|
1
|
+
"use strict";
|
2
|
+
var util = require("./util");
|
3
|
+
var maybeWrapAsError = util.maybeWrapAsError;
|
4
|
+
var errors = require("./errors");
|
5
|
+
var OperationalError = errors.OperationalError;
|
6
|
+
var es5 = require("./es5");
|
7
|
+
|
8
|
+
function isUntypedError(obj) {
|
9
|
+
return obj instanceof Error &&
|
10
|
+
es5.getPrototypeOf(obj) === Error.prototype;
|
11
|
+
}
|
12
|
+
|
13
|
+
var rErrorKey = /^(?:name|message|stack|cause)$/;
|
14
|
+
function wrapAsOperationalError(obj) {
|
15
|
+
var ret;
|
16
|
+
if (isUntypedError(obj)) {
|
17
|
+
ret = new OperationalError(obj);
|
18
|
+
ret.name = obj.name;
|
19
|
+
ret.message = obj.message;
|
20
|
+
ret.stack = obj.stack;
|
21
|
+
var keys = es5.keys(obj);
|
22
|
+
for (var i = 0; i < keys.length; ++i) {
|
23
|
+
var key = keys[i];
|
24
|
+
if (!rErrorKey.test(key)) {
|
25
|
+
ret[key] = obj[key];
|
26
|
+
}
|
27
|
+
}
|
28
|
+
return ret;
|
29
|
+
}
|
30
|
+
util.markAsOriginatingFromRejection(obj);
|
31
|
+
return obj;
|
32
|
+
}
|
33
|
+
|
34
|
+
function nodebackForPromise(promise, multiArgs) {
|
35
|
+
return function(err, value) {
|
36
|
+
if (promise === null) return;
|
37
|
+
if (err) {
|
38
|
+
var wrapped = wrapAsOperationalError(maybeWrapAsError(err));
|
39
|
+
promise._attachExtraTrace(wrapped);
|
40
|
+
promise._reject(wrapped);
|
41
|
+
} else if (!multiArgs) {
|
42
|
+
promise._fulfill(value);
|
43
|
+
} else {
|
44
|
+
var $_len = arguments.length;var args = new Array(Math.max($_len - 1, 0)); for(var $_i = 1; $_i < $_len; ++$_i) {args[$_i - 1] = arguments[$_i];};
|
45
|
+
promise._fulfill(args);
|
46
|
+
}
|
47
|
+
promise = null;
|
48
|
+
};
|
49
|
+
}
|
50
|
+
|
51
|
+
module.exports = nodebackForPromise;
|
@@ -0,0 +1,58 @@
|
|
1
|
+
"use strict";
|
2
|
+
module.exports = function(Promise) {
|
3
|
+
var util = require("./util");
|
4
|
+
var async = Promise._async;
|
5
|
+
var tryCatch = util.tryCatch;
|
6
|
+
var errorObj = util.errorObj;
|
7
|
+
|
8
|
+
function spreadAdapter(val, nodeback) {
|
9
|
+
var promise = this;
|
10
|
+
if (!util.isArray(val)) return successAdapter.call(promise, val, nodeback);
|
11
|
+
var ret =
|
12
|
+
tryCatch(nodeback).apply(promise._boundValue(), [null].concat(val));
|
13
|
+
if (ret === errorObj) {
|
14
|
+
async.throwLater(ret.e);
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
18
|
+
function successAdapter(val, nodeback) {
|
19
|
+
var promise = this;
|
20
|
+
var receiver = promise._boundValue();
|
21
|
+
var ret = val === undefined
|
22
|
+
? tryCatch(nodeback).call(receiver, null)
|
23
|
+
: tryCatch(nodeback).call(receiver, null, val);
|
24
|
+
if (ret === errorObj) {
|
25
|
+
async.throwLater(ret.e);
|
26
|
+
}
|
27
|
+
}
|
28
|
+
function errorAdapter(reason, nodeback) {
|
29
|
+
var promise = this;
|
30
|
+
if (!reason) {
|
31
|
+
var newReason = new Error(reason + "");
|
32
|
+
newReason.cause = reason;
|
33
|
+
reason = newReason;
|
34
|
+
}
|
35
|
+
var ret = tryCatch(nodeback).call(promise._boundValue(), reason);
|
36
|
+
if (ret === errorObj) {
|
37
|
+
async.throwLater(ret.e);
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
Promise.prototype.asCallback = Promise.prototype.nodeify = function (nodeback,
|
42
|
+
options) {
|
43
|
+
if (typeof nodeback == "function") {
|
44
|
+
var adapter = successAdapter;
|
45
|
+
if (options !== undefined && Object(options).spread) {
|
46
|
+
adapter = spreadAdapter;
|
47
|
+
}
|
48
|
+
this._then(
|
49
|
+
adapter,
|
50
|
+
errorAdapter,
|
51
|
+
undefined,
|
52
|
+
this,
|
53
|
+
nodeback
|
54
|
+
);
|
55
|
+
}
|
56
|
+
return this;
|
57
|
+
};
|
58
|
+
};
|