scratch – Blame information for rev 77
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
77 | office | 1 | /** |
2 | * bluebird build version 2.2.1 |
||
3 | * Features enabled: core, race, call_get, generators, map, nodeify, promisify, props, reduce, settle, some, progress, cancel, using, filter, any, each, timers |
||
4 | */ |
||
5 | /** |
||
6 | * @preserve Copyright (c) 2014 Petka Antonov |
||
7 | * |
||
8 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
||
9 | * of this software and associated documentation files (the "Software"), to deal |
||
10 | * in the Software without restriction, including without limitation the rights |
||
11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
12 | * copies of the Software, and to permit persons to whom the Software is |
||
13 | * furnished to do so, subject to the following conditions:</p> |
||
14 | * |
||
15 | * The above copyright notice and this permission notice shall be included in |
||
16 | * all copies or substantial portions of the Software. |
||
17 | * |
||
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||
21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||
24 | * THE SOFTWARE. |
||
25 | * |
||
26 | */ |
||
27 | !function(e){"object"==typeof exports?module.exports=e():"function"==typeof define&&define.amd?define(e):"undefined"!=typeof window?window.Promise=e():"undefined"!=typeof global?global.Promise=e():"undefined"!=typeof self&&(self.Promise=e())}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ |
||
28 | /** |
||
29 | * Copyright (c) 2014 Petka Antonov |
||
30 | * |
||
31 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
||
32 | * of this software and associated documentation files (the "Software"), to deal |
||
33 | * in the Software without restriction, including without limitation the rights |
||
34 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
35 | * copies of the Software, and to permit persons to whom the Software is |
||
36 | * furnished to do so, subject to the following conditions:</p> |
||
37 | * |
||
38 | * The above copyright notice and this permission notice shall be included in |
||
39 | * all copies or substantial portions of the Software. |
||
40 | * |
||
41 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
42 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
43 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||
44 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
45 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
46 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||
47 | * THE SOFTWARE. |
||
48 | * |
||
49 | */ |
||
50 | "use strict"; |
||
51 | module.exports = function(Promise) { |
||
52 | var SomePromiseArray = Promise._SomePromiseArray; |
||
53 | function Promise$_Any(promises) { |
||
54 | var ret = new SomePromiseArray(promises); |
||
55 | var promise = ret.promise(); |
||
56 | if (promise.isRejected()) { |
||
57 | return promise; |
||
58 | } |
||
59 | ret.setHowMany(1); |
||
60 | ret.setUnwrap(); |
||
61 | ret.init(); |
||
62 | return promise; |
||
63 | } |
||
64 | |||
65 | Promise.any = function Promise$Any(promises) { |
||
66 | return Promise$_Any(promises); |
||
67 | }; |
||
68 | |||
69 | Promise.prototype.any = function Promise$any() { |
||
70 | return Promise$_Any(this); |
||
71 | }; |
||
72 | |||
73 | }; |
||
74 | |||
75 | },{}],2:[function(require,module,exports){ |
||
76 | /** |
||
77 | * Copyright (c) 2014 Petka Antonov |
||
78 | * |
||
79 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
||
80 | * of this software and associated documentation files (the "Software"), to deal |
||
81 | * in the Software without restriction, including without limitation the rights |
||
82 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
83 | * copies of the Software, and to permit persons to whom the Software is |
||
84 | * furnished to do so, subject to the following conditions:</p> |
||
85 | * |
||
86 | * The above copyright notice and this permission notice shall be included in |
||
87 | * all copies or substantial portions of the Software. |
||
88 | * |
||
89 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
90 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
91 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||
92 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
93 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
94 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||
95 | * THE SOFTWARE. |
||
96 | * |
||
97 | */ |
||
98 | "use strict"; |
||
99 | var schedule = require("./schedule.js"); |
||
100 | var Queue = require("./queue.js"); |
||
101 | var errorObj = require("./util.js").errorObj; |
||
102 | var tryCatch1 = require("./util.js").tryCatch1; |
||
103 | var _process = typeof process !== "undefined" ? process : void 0; |
||
104 | |||
105 | function Async() { |
||
106 | this._isTickUsed = false; |
||
107 | this._schedule = schedule; |
||
108 | this._length = 0; |
||
109 | this._lateBuffer = new Queue(16); |
||
110 | this._functionBuffer = new Queue(65536); |
||
111 | var self = this; |
||
112 | this.consumeFunctionBuffer = function Async$consumeFunctionBuffer() { |
||
113 | self._consumeFunctionBuffer(); |
||
114 | }; |
||
115 | } |
||
116 | |||
117 | Async.prototype.haveItemsQueued = function Async$haveItemsQueued() { |
||
118 | return this._length > 0; |
||
119 | }; |
||
120 | |||
121 | Async.prototype.invokeLater = function Async$invokeLater(fn, receiver, arg) { |
||
122 | if (_process !== void 0 && |
||
123 | _process.domain != null && |
||
124 | !fn.domain) { |
||
125 | fn = _process.domain.bind(fn); |
||
126 | } |
||
127 | this._lateBuffer.push(fn, receiver, arg); |
||
128 | this._queueTick(); |
||
129 | }; |
||
130 | |||
131 | Async.prototype.invoke = function Async$invoke(fn, receiver, arg) { |
||
132 | if (_process !== void 0 && |
||
133 | _process.domain != null && |
||
134 | !fn.domain) { |
||
135 | fn = _process.domain.bind(fn); |
||
136 | } |
||
137 | var functionBuffer = this._functionBuffer; |
||
138 | functionBuffer.push(fn, receiver, arg); |
||
139 | this._length = functionBuffer.length(); |
||
140 | this._queueTick(); |
||
141 | }; |
||
142 | |||
143 | Async.prototype._consumeFunctionBuffer = |
||
144 | function Async$_consumeFunctionBuffer() { |
||
145 | var functionBuffer = this._functionBuffer; |
||
146 | while (functionBuffer.length() > 0) { |
||
147 | var fn = functionBuffer.shift(); |
||
148 | var receiver = functionBuffer.shift(); |
||
149 | var arg = functionBuffer.shift(); |
||
150 | fn.call(receiver, arg); |
||
151 | } |
||
152 | this._reset(); |
||
153 | this._consumeLateBuffer(); |
||
154 | }; |
||
155 | |||
156 | Async.prototype._consumeLateBuffer = function Async$_consumeLateBuffer() { |
||
157 | var buffer = this._lateBuffer; |
||
158 | while(buffer.length() > 0) { |
||
159 | var fn = buffer.shift(); |
||
160 | var receiver = buffer.shift(); |
||
161 | var arg = buffer.shift(); |
||
162 | var res = tryCatch1(fn, receiver, arg); |
||
163 | if (res === errorObj) { |
||
164 | this._queueTick(); |
||
165 | if (fn.domain != null) { |
||
166 | fn.domain.emit("error", res.e); |
||
167 | } else { |
||
168 | throw res.e; |
||
169 | } |
||
170 | } |
||
171 | } |
||
172 | }; |
||
173 | |||
174 | Async.prototype._queueTick = function Async$_queue() { |
||
175 | if (!this._isTickUsed) { |
||
176 | this._schedule(this.consumeFunctionBuffer); |
||
177 | this._isTickUsed = true; |
||
178 | } |
||
179 | }; |
||
180 | |||
181 | Async.prototype._reset = function Async$_reset() { |
||
182 | this._isTickUsed = false; |
||
183 | this._length = 0; |
||
184 | }; |
||
185 | |||
186 | module.exports = new Async(); |
||
187 | |||
188 | },{"./queue.js":25,"./schedule.js":28,"./util.js":35}],3:[function(require,module,exports){ |
||
189 | /** |
||
190 | * Copyright (c) 2014 Petka Antonov |
||
191 | * |
||
192 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
||
193 | * of this software and associated documentation files (the "Software"), to deal |
||
194 | * in the Software without restriction, including without limitation the rights |
||
195 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
196 | * copies of the Software, and to permit persons to whom the Software is |
||
197 | * furnished to do so, subject to the following conditions:</p> |
||
198 | * |
||
199 | * The above copyright notice and this permission notice shall be included in |
||
200 | * all copies or substantial portions of the Software. |
||
201 | * |
||
202 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
203 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
204 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||
205 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
206 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
207 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||
208 | * THE SOFTWARE. |
||
209 | * |
||
210 | */ |
||
211 | "use strict"; |
||
212 | var Promise = require("./promise.js")(); |
||
213 | module.exports = Promise; |
||
214 | },{"./promise.js":20}],4:[function(require,module,exports){ |
||
215 | /** |
||
216 | * Copyright (c) 2014 Petka Antonov |
||
217 | * |
||
218 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
||
219 | * of this software and associated documentation files (the "Software"), to deal |
||
220 | * in the Software without restriction, including without limitation the rights |
||
221 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
222 | * copies of the Software, and to permit persons to whom the Software is |
||
223 | * furnished to do so, subject to the following conditions:</p> |
||
224 | * |
||
225 | * The above copyright notice and this permission notice shall be included in |
||
226 | * all copies or substantial portions of the Software. |
||
227 | * |
||
228 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
229 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
230 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||
231 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
232 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
233 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||
234 | * THE SOFTWARE. |
||
235 | * |
||
236 | */ |
||
237 | "use strict"; |
||
238 | var cr = Object.create; |
||
239 | var callerCache = cr && cr(null); |
||
240 | var getterCache = cr && cr(null); |
||
241 | callerCache[" size"] = getterCache[" size"] = 0; |
||
242 | module.exports = function(Promise) { |
||
243 | var util = require("./util.js"); |
||
244 | var canEvaluate = util.canEvaluate; |
||
245 | var isIdentifier = util.isIdentifier; |
||
246 | |||
247 | function makeMethodCaller (methodName) { |
||
248 | return new Function("obj", " \n\ |
||
249 | 'use strict' \n\ |
||
250 | var len = this.length; \n\ |
||
251 | switch(len) { \n\ |
||
252 | case 1: return obj.methodName(this[0]); \n\ |
||
253 | case 2: return obj.methodName(this[0], this[1]); \n\ |
||
254 | case 3: return obj.methodName(this[0], this[1], this[2]); \n\ |
||
255 | case 0: return obj.methodName(); \n\ |
||
256 | default: return obj.methodName.apply(obj, this); \n\ |
||
257 | } \n\ |
||
258 | ".replace(/methodName/g, methodName)); |
||
259 | } |
||
260 | |||
261 | function makeGetter (propertyName) { |
||
262 | return new Function("obj", " \n\ |
||
263 | 'use strict'; \n\ |
||
264 | return obj.propertyName; \n\ |
||
265 | ".replace("propertyName", propertyName)); |
||
266 | } |
||
267 | |||
268 | function getCompiled(name, compiler, cache) { |
||
269 | var ret = cache[name]; |
||
270 | if (typeof ret !== "function") { |
||
271 | if (!isIdentifier(name)) { |
||
272 | return null; |
||
273 | } |
||
274 | ret = compiler(name); |
||
275 | cache[name] = ret; |
||
276 | cache[" size"]++; |
||
277 | if (cache[" size"] > 512) { |
||
278 | var keys = Object.keys(cache); |
||
279 | for (var i = 0; i < 256; ++i) delete cache[keys[i]]; |
||
280 | cache[" size"] = keys.length - 256; |
||
281 | } |
||
282 | } |
||
283 | return ret; |
||
284 | } |
||
285 | |||
286 | function getMethodCaller(name) { |
||
287 | return getCompiled(name, makeMethodCaller, callerCache); |
||
288 | } |
||
289 | |||
290 | function getGetter(name) { |
||
291 | return getCompiled(name, makeGetter, getterCache); |
||
292 | } |
||
293 | |||
294 | function caller(obj) { |
||
295 | return obj[this.pop()].apply(obj, this); |
||
296 | } |
||
297 | Promise.prototype.call = function Promise$call(methodName) { |
||
298 | var $_len = arguments.length;var args = new Array($_len - 1); for(var $_i = 1; $_i < $_len; ++$_i) {args[$_i - 1] = arguments[$_i];} |
||
299 | if (canEvaluate) { |
||
300 | var maybeCaller = getMethodCaller(methodName); |
||
301 | if (maybeCaller !== null) { |
||
302 | return this._then(maybeCaller, void 0, void 0, args, void 0); |
||
303 | } |
||
304 | } |
||
305 | args.push(methodName); |
||
306 | return this._then(caller, void 0, void 0, args, void 0); |
||
307 | }; |
||
308 | |||
309 | function namedGetter(obj) { |
||
310 | return obj[this]; |
||
311 | } |
||
312 | function indexedGetter(obj) { |
||
313 | return obj[this]; |
||
314 | } |
||
315 | Promise.prototype.get = function Promise$get(propertyName) { |
||
316 | var isIndex = (typeof propertyName === "number"); |
||
317 | var getter; |
||
318 | if (!isIndex) { |
||
319 | if (canEvaluate) { |
||
320 | var maybeGetter = getGetter(propertyName); |
||
321 | getter = maybeGetter !== null ? maybeGetter : namedGetter; |
||
322 | } else { |
||
323 | getter = namedGetter; |
||
324 | } |
||
325 | } else { |
||
326 | getter = indexedGetter; |
||
327 | } |
||
328 | return this._then(getter, void 0, void 0, propertyName, void 0); |
||
329 | }; |
||
330 | }; |
||
331 | |||
332 | },{"./util.js":35}],5:[function(require,module,exports){ |
||
333 | /** |
||
334 | * Copyright (c) 2014 Petka Antonov |
||
335 | * |
||
336 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
||
337 | * of this software and associated documentation files (the "Software"), to deal |
||
338 | * in the Software without restriction, including without limitation the rights |
||
339 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
340 | * copies of the Software, and to permit persons to whom the Software is |
||
341 | * furnished to do so, subject to the following conditions:</p> |
||
342 | * |
||
343 | * The above copyright notice and this permission notice shall be included in |
||
344 | * all copies or substantial portions of the Software. |
||
345 | * |
||
346 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
347 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
348 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||
349 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
350 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
351 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||
352 | * THE SOFTWARE. |
||
353 | * |
||
354 | */ |
||
355 | "use strict"; |
||
356 | module.exports = function(Promise, INTERNAL) { |
||
357 | var errors = require("./errors.js"); |
||
358 | var canAttach = errors.canAttach; |
||
359 | var async = require("./async.js"); |
||
360 | var CancellationError = errors.CancellationError; |
||
361 | |||
362 | Promise.prototype._cancel = function Promise$_cancel(reason) { |
||
363 | if (!this.isCancellable()) return this; |
||
364 | var parent; |
||
365 | var promiseToReject = this; |
||
366 | while ((parent = promiseToReject._cancellationParent) !== void 0 && |
||
367 | parent.isCancellable()) { |
||
368 | promiseToReject = parent; |
||
369 | } |
||
370 | promiseToReject._attachExtraTrace(reason); |
||
371 | promiseToReject._rejectUnchecked(reason); |
||
372 | }; |
||
373 | |||
374 | Promise.prototype.cancel = function Promise$cancel(reason) { |
||
375 | if (!this.isCancellable()) return this; |
||
376 | reason = reason !== void 0 |
||
377 | ? (canAttach(reason) ? reason : new Error(reason + "")) |
||
378 | : new CancellationError(); |
||
379 | async.invokeLater(this._cancel, this, reason); |
||
380 | return this; |
||
381 | }; |
||
382 | |||
383 | Promise.prototype.cancellable = function Promise$cancellable() { |
||
384 | if (this._cancellable()) return this; |
||
385 | this._setCancellable(); |
||
386 | this._cancellationParent = void 0; |
||
387 | return this; |
||
388 | }; |
||
389 | |||
390 | Promise.prototype.uncancellable = function Promise$uncancellable() { |
||
391 | var ret = new Promise(INTERNAL); |
||
392 | ret._propagateFrom(this, 2 | 4); |
||
393 | ret._follow(this); |
||
394 | ret._unsetCancellable(); |
||
395 | return ret; |
||
396 | }; |
||
397 | |||
398 | Promise.prototype.fork = |
||
399 | function Promise$fork(didFulfill, didReject, didProgress) { |
||
400 | var ret = this._then(didFulfill, didReject, didProgress, |
||
401 | void 0, void 0); |
||
402 | |||
403 | ret._setCancellable(); |
||
404 | ret._cancellationParent = void 0; |
||
405 | return ret; |
||
406 | }; |
||
407 | }; |
||
408 | |||
409 | },{"./async.js":2,"./errors.js":10}],6:[function(require,module,exports){ |
||
410 | /** |
||
411 | * Copyright (c) 2014 Petka Antonov |
||
412 | * |
||
413 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
||
414 | * of this software and associated documentation files (the "Software"), to deal |
||
415 | * in the Software without restriction, including without limitation the rights |
||
416 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
417 | * copies of the Software, and to permit persons to whom the Software is |
||
418 | * furnished to do so, subject to the following conditions:</p> |
||
419 | * |
||
420 | * The above copyright notice and this permission notice shall be included in |
||
421 | * all copies or substantial portions of the Software. |
||
422 | * |
||
423 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
424 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
425 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||
426 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
427 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
428 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||
429 | * THE SOFTWARE. |
||
430 | * |
||
431 | */ |
||
432 | "use strict"; |
||
433 | module.exports = function() { |
||
434 | var inherits = require("./util.js").inherits; |
||
435 | var defineProperty = require("./es5.js").defineProperty; |
||
436 | |||
437 | var rignore = new RegExp( |
||
438 | "\\b(?:[a-zA-Z0-9.]+\\$_\\w+|" + |
||
439 | "tryCatch(?:1|2|3|4|Apply)|new \\w*PromiseArray|" + |
||
440 | "\\w*PromiseArray\\.\\w*PromiseArray|" + |
||
441 | "setTimeout|CatchFilter\\$_\\w+|makeNodePromisified|processImmediate|" + |
||
442 | "process._tickCallback|nextTick|Async\\$\\w+)\\b" |
||
443 | ); |
||
444 | |||
445 | var rtraceline = null; |
||
446 | var formatStack = null; |
||
447 | |||
448 | function formatNonError(obj) { |
||
449 | var str; |
||
450 | if (typeof obj === "function") { |
||
451 | str = "[function " + |
||
452 | (obj.name || "anonymous") + |
||
453 | "]"; |
||
454 | } else { |
||
455 | str = obj.toString(); |
||
456 | var ruselessToString = /\[object [a-zA-Z0-9$_]+\]/; |
||
457 | if (ruselessToString.test(str)) { |
||
458 | try { |
||
459 | var newStr = JSON.stringify(obj); |
||
460 | str = newStr; |
||
461 | } |
||
462 | catch(e) { |
||
463 | |||
464 | } |
||
465 | } |
||
466 | if (str.length === 0) { |
||
467 | str = "(empty array)"; |
||
468 | } |
||
469 | } |
||
470 | return ("(<" + snip(str) + ">, no stack trace)"); |
||
471 | } |
||
472 | |||
473 | function snip(str) { |
||
474 | var maxChars = 41; |
||
475 | if (str.length < maxChars) { |
||
476 | return str; |
||
477 | } |
||
478 | return str.substr(0, maxChars - 3) + "..."; |
||
479 | } |
||
480 | |||
481 | function CapturedTrace(ignoreUntil, isTopLevel) { |
||
482 | this.captureStackTrace(CapturedTrace, isTopLevel); |
||
483 | |||
484 | } |
||
485 | inherits(CapturedTrace, Error); |
||
486 | |||
487 | CapturedTrace.prototype.captureStackTrace = |
||
488 | function CapturedTrace$captureStackTrace(ignoreUntil, isTopLevel) { |
||
489 | captureStackTrace(this, ignoreUntil, isTopLevel); |
||
490 | }; |
||
491 | |||
492 | CapturedTrace.possiblyUnhandledRejection = |
||
493 | function CapturedTrace$PossiblyUnhandledRejection(reason) { |
||
494 | if (typeof console === "object") { |
||
495 | var message; |
||
496 | if (typeof reason === "object" || typeof reason === "function") { |
||
497 | var stack = reason.stack; |
||
498 | message = "Possibly unhandled " + formatStack(stack, reason); |
||
499 | } else { |
||
500 | message = "Possibly unhandled " + String(reason); |
||
501 | } |
||
502 | if (typeof console.error === "function" || |
||
503 | typeof console.error === "object") { |
||
504 | console.error(message); |
||
505 | } else if (typeof console.log === "function" || |
||
506 | typeof console.log === "object") { |
||
507 | console.log(message); |
||
508 | } |
||
509 | } |
||
510 | }; |
||
511 | |||
512 | CapturedTrace.combine = function CapturedTrace$Combine(current, prev) { |
||
513 | var curLast = current.length - 1; |
||
514 | for (var i = prev.length - 1; i >= 0; --i) { |
||
515 | var line = prev[i]; |
||
516 | if (current[curLast] === line) { |
||
517 | current.pop(); |
||
518 | curLast--; |
||
519 | } else { |
||
520 | break; |
||
521 | } |
||
522 | } |
||
523 | |||
524 | current.push("From previous event:"); |
||
525 | var lines = current.concat(prev); |
||
526 | |||
527 | var ret = []; |
||
528 | |||
529 | for (var i = 0, len = lines.length; i < len; ++i) { |
||
530 | |||
531 | if ((rignore.test(lines[i]) || |
||
532 | (i > 0 && !rtraceline.test(lines[i])) && |
||
533 | lines[i] !== "From previous event:") |
||
534 | ) { |
||
535 | continue; |
||
536 | } |
||
537 | ret.push(lines[i]); |
||
538 | } |
||
539 | return ret; |
||
540 | }; |
||
541 | |||
542 | CapturedTrace.protectErrorMessageNewlines = function(stack) { |
||
543 | for (var i = 0; i < stack.length; ++i) { |
||
544 | if (rtraceline.test(stack[i])) { |
||
545 | break; |
||
546 | } |
||
547 | } |
||
548 | |||
549 | if (i <= 1) return; |
||
550 | |||
551 | var errorMessageLines = []; |
||
552 | for (var j = 0; j < i; ++j) { |
||
553 | errorMessageLines.push(stack.shift()); |
||
554 | } |
||
555 | stack.unshift(errorMessageLines.join("\u0002\u0000\u0001")); |
||
556 | }; |
||
557 | |||
558 | CapturedTrace.isSupported = function CapturedTrace$IsSupported() { |
||
559 | return typeof captureStackTrace === "function"; |
||
560 | }; |
||
561 | |||
562 | var captureStackTrace = (function stackDetection() { |
||
563 | if (typeof Error.stackTraceLimit === "number" && |
||
564 | typeof Error.captureStackTrace === "function") { |
||
565 | rtraceline = /^\s*at\s*/; |
||
566 | formatStack = function(stack, error) { |
||
567 | if (typeof stack === "string") return stack; |
||
568 | |||
569 | if (error.name !== void 0 && |
||
570 | error.message !== void 0) { |
||
571 | return error.name + ". " + error.message; |
||
572 | } |
||
573 | return formatNonError(error); |
||
574 | |||
575 | |||
576 | }; |
||
577 | var captureStackTrace = Error.captureStackTrace; |
||
578 | return function CapturedTrace$_captureStackTrace( |
||
579 | receiver, ignoreUntil) { |
||
580 | captureStackTrace(receiver, ignoreUntil); |
||
581 | }; |
||
582 | } |
||
583 | var err = new Error(); |
||
584 | |||
585 | if (typeof err.stack === "string" && |
||
586 | typeof "".startsWith === "function" && |
||
587 | (err.stack.startsWith("stackDetection@")) && |
||
588 | stackDetection.name === "stackDetection") { |
||
589 | |||
590 | defineProperty(Error, "stackTraceLimit", { |
||
591 | writable: true, |
||
592 | enumerable: false, |
||
593 | configurable: false, |
||
594 | value: 25 |
||
595 | }); |
||
596 | rtraceline = /@/; |
||
597 | var rline = /[@\n]/; |
||
598 | |||
599 | formatStack = function(stack, error) { |
||
600 | if (typeof stack === "string") { |
||
601 | return (error.name + ". " + error.message + "\n" + stack); |
||
602 | } |
||
603 | |||
604 | if (error.name !== void 0 && |
||
605 | error.message !== void 0) { |
||
606 | return error.name + ". " + error.message; |
||
607 | } |
||
608 | return formatNonError(error); |
||
609 | }; |
||
610 | |||
611 | return function captureStackTrace(o) { |
||
612 | var stack = new Error().stack; |
||
613 | var split = stack.split(rline); |
||
614 | var len = split.length; |
||
615 | var ret = ""; |
||
616 | for (var i = 0; i < len; i += 2) { |
||
617 | ret += split[i]; |
||
618 | ret += "@"; |
||
619 | ret += split[i + 1]; |
||
620 | ret += "\n"; |
||
621 | } |
||
622 | o.stack = ret; |
||
623 | }; |
||
624 | } else { |
||
625 | formatStack = function(stack, error) { |
||
626 | if (typeof stack === "string") return stack; |
||
627 | |||
628 | if ((typeof error === "object" || |
||
629 | typeof error === "function") && |
||
630 | error.name !== void 0 && |
||
631 | error.message !== void 0) { |
||
632 | return error.name + ". " + error.message; |
||
633 | } |
||
634 | return formatNonError(error); |
||
635 | }; |
||
636 | |||
637 | return null; |
||
638 | } |
||
639 | })(); |
||
640 | |||
641 | return CapturedTrace; |
||
642 | }; |
||
643 | |||
644 | },{"./es5.js":12,"./util.js":35}],7:[function(require,module,exports){ |
||
645 | /** |
||
646 | * Copyright (c) 2014 Petka Antonov |
||
647 | * |
||
648 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
||
649 | * of this software and associated documentation files (the "Software"), to deal |
||
650 | * in the Software without restriction, including without limitation the rights |
||
651 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
652 | * copies of the Software, and to permit persons to whom the Software is |
||
653 | * furnished to do so, subject to the following conditions:</p> |
||
654 | * |
||
655 | * The above copyright notice and this permission notice shall be included in |
||
656 | * all copies or substantial portions of the Software. |
||
657 | * |
||
658 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
659 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
660 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||
661 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
662 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
663 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||
664 | * THE SOFTWARE. |
||
665 | * |
||
666 | */ |
||
667 | "use strict"; |
||
668 | module.exports = function(NEXT_FILTER) { |
||
669 | var util = require("./util.js"); |
||
670 | var errors = require("./errors.js"); |
||
671 | var tryCatch1 = util.tryCatch1; |
||
672 | var errorObj = util.errorObj; |
||
673 | var keys = require("./es5.js").keys; |
||
674 | var TypeError = errors.TypeError; |
||
675 | |||
676 | function CatchFilter(instances, callback, promise) { |
||
677 | this._instances = instances; |
||
678 | this._callback = callback; |
||
679 | this._promise = promise; |
||
680 | } |
||
681 | |||
682 | function CatchFilter$_safePredicate(predicate, e) { |
||
683 | var safeObject = {}; |
||
684 | var retfilter = tryCatch1(predicate, safeObject, e); |
||
685 | |||
686 | if (retfilter === errorObj) return retfilter; |
||
687 | |||
688 | var safeKeys = keys(safeObject); |
||
689 | if (safeKeys.length) { |
||
690 | errorObj.e = new TypeError( |
||
691 | "Catch filter must inherit from Error " |
||
692 | + "or be a simple predicate function"); |
||
693 | return errorObj; |
||
694 | } |
||
695 | return retfilter; |
||
696 | } |
||
697 | |||
698 | CatchFilter.prototype.doFilter = function CatchFilter$_doFilter(e) { |
||
699 | var cb = this._callback; |
||
700 | var promise = this._promise; |
||
701 | var boundTo = promise._boundTo; |
||
702 | for (var i = 0, len = this._instances.length; i < len; ++i) { |
||
703 | var item = this._instances[i]; |
||
704 | var itemIsErrorType = item === Error || |
||
705 | (item != null && item.prototype instanceof Error); |
||
706 | |||
707 | if (itemIsErrorType && e instanceof item) { |
||
708 | var ret = tryCatch1(cb, boundTo, e); |
||
709 | if (ret === errorObj) { |
||
710 | NEXT_FILTER.e = ret.e; |
||
711 | return NEXT_FILTER; |
||
712 | } |
||
713 | return ret; |
||
714 | } else if (typeof item === "function" && !itemIsErrorType) { |
||
715 | var shouldHandle = CatchFilter$_safePredicate(item, e); |
||
716 | if (shouldHandle === errorObj) { |
||
717 | var trace = errors.canAttach(errorObj.e) |
||
718 | ? errorObj.e |
||
719 | : new Error(errorObj.e + ""); |
||
720 | this._promise._attachExtraTrace(trace); |
||
721 | e = errorObj.e; |
||
722 | break; |
||
723 | } else if (shouldHandle) { |
||
724 | var ret = tryCatch1(cb, boundTo, e); |
||
725 | if (ret === errorObj) { |
||
726 | NEXT_FILTER.e = ret.e; |
||
727 | return NEXT_FILTER; |
||
728 | } |
||
729 | return ret; |
||
730 | } |
||
731 | } |
||
732 | } |
||
733 | NEXT_FILTER.e = e; |
||
734 | return NEXT_FILTER; |
||
735 | }; |
||
736 | |||
737 | return CatchFilter; |
||
738 | }; |
||
739 | |||
740 | },{"./errors.js":10,"./es5.js":12,"./util.js":35}],8:[function(require,module,exports){ |
||
741 | /** |
||
742 | * Copyright (c) 2014 Petka Antonov |
||
743 | * |
||
744 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
||
745 | * of this software and associated documentation files (the "Software"), to deal |
||
746 | * in the Software without restriction, including without limitation the rights |
||
747 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
748 | * copies of the Software, and to permit persons to whom the Software is |
||
749 | * furnished to do so, subject to the following conditions:</p> |
||
750 | * |
||
751 | * The above copyright notice and this permission notice shall be included in |
||
752 | * all copies or substantial portions of the Software. |
||
753 | * |
||
754 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
755 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
756 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||
757 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
758 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
759 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||
760 | * THE SOFTWARE. |
||
761 | * |
||
762 | */ |
||
763 | "use strict"; |
||
764 | var util = require("./util.js"); |
||
765 | var isPrimitive = util.isPrimitive; |
||
766 | var wrapsPrimitiveReceiver = util.wrapsPrimitiveReceiver; |
||
767 | |||
768 | module.exports = function(Promise) { |
||
769 | var returner = function Promise$_returner() { |
||
770 | return this; |
||
771 | }; |
||
772 | var thrower = function Promise$_thrower() { |
||
773 | throw this; |
||
774 | }; |
||
775 | |||
776 | var wrapper = function Promise$_wrapper(value, action) { |
||
777 | if (action === 1) { |
||
778 | return function Promise$_thrower() { |
||
779 | throw value; |
||
780 | }; |
||
781 | } else if (action === 2) { |
||
782 | return function Promise$_returner() { |
||
783 | return value; |
||
784 | }; |
||
785 | } |
||
786 | }; |
||
787 | |||
788 | |||
789 | Promise.prototype["return"] = |
||
790 | Promise.prototype.thenReturn = |
||
791 | function Promise$thenReturn(value) { |
||
792 | if (wrapsPrimitiveReceiver && isPrimitive(value)) { |
||
793 | return this._then( |
||
794 | wrapper(value, 2), |
||
795 | void 0, |
||
796 | void 0, |
||
797 | void 0, |
||
798 | void 0 |
||
799 | ); |
||
800 | } |
||
801 | return this._then(returner, void 0, void 0, value, void 0); |
||
802 | }; |
||
803 | |||
804 | Promise.prototype["throw"] = |
||
805 | Promise.prototype.thenThrow = |
||
806 | function Promise$thenThrow(reason) { |
||
807 | if (wrapsPrimitiveReceiver && isPrimitive(reason)) { |
||
808 | return this._then( |
||
809 | wrapper(reason, 1), |
||
810 | void 0, |
||
811 | void 0, |
||
812 | void 0, |
||
813 | void 0 |
||
814 | ); |
||
815 | } |
||
816 | return this._then(thrower, void 0, void 0, reason, void 0); |
||
817 | }; |
||
818 | }; |
||
819 | |||
820 | },{"./util.js":35}],9:[function(require,module,exports){ |
||
821 | /** |
||
822 | * Copyright (c) 2014 Petka Antonov |
||
823 | * |
||
824 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
||
825 | * of this software and associated documentation files (the "Software"), to deal |
||
826 | * in the Software without restriction, including without limitation the rights |
||
827 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
828 | * copies of the Software, and to permit persons to whom the Software is |
||
829 | * furnished to do so, subject to the following conditions:</p> |
||
830 | * |
||
831 | * The above copyright notice and this permission notice shall be included in |
||
832 | * all copies or substantial portions of the Software. |
||
833 | * |
||
834 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
835 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
836 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||
837 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
838 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
839 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||
840 | * THE SOFTWARE. |
||
841 | * |
||
842 | */ |
||
843 | "use strict"; |
||
844 | module.exports = function(Promise, INTERNAL) { |
||
845 | var PromiseReduce = Promise.reduce; |
||
846 | |||
847 | Promise.prototype.each = function Promise$each(fn) { |
||
848 | return PromiseReduce(this, fn, null, INTERNAL); |
||
849 | }; |
||
850 | |||
851 | Promise.each = function Promise$Each(promises, fn) { |
||
852 | return PromiseReduce(promises, fn, null, INTERNAL); |
||
853 | }; |
||
854 | }; |
||
855 | |||
856 | },{}],10:[function(require,module,exports){ |
||
857 | /** |
||
858 | * Copyright (c) 2014 Petka Antonov |
||
859 | * |
||
860 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
||
861 | * of this software and associated documentation files (the "Software"), to deal |
||
862 | * in the Software without restriction, including without limitation the rights |
||
863 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
864 | * copies of the Software, and to permit persons to whom the Software is |
||
865 | * furnished to do so, subject to the following conditions:</p> |
||
866 | * |
||
867 | * The above copyright notice and this permission notice shall be included in |
||
868 | * all copies or substantial portions of the Software. |
||
869 | * |
||
870 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
871 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
872 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||
873 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
874 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
875 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||
876 | * THE SOFTWARE. |
||
877 | * |
||
878 | */ |
||
879 | "use strict"; |
||
880 | var Objectfreeze = require("./es5.js").freeze; |
||
881 | var util = require("./util.js"); |
||
882 | var inherits = util.inherits; |
||
883 | var notEnumerableProp = util.notEnumerableProp; |
||
884 | |||
885 | function markAsOriginatingFromRejection(e) { |
||
886 | try { |
||
887 | notEnumerableProp(e, "isOperational", true); |
||
888 | } |
||
889 | catch(ignore) {} |
||
890 | } |
||
891 | |||
892 | function originatesFromRejection(e) { |
||
893 | if (e == null) return false; |
||
894 | return ((e instanceof OperationalError) || |
||
895 | e["isOperational"] === true); |
||
896 | } |
||
897 | |||
898 | function isError(obj) { |
||
899 | return obj instanceof Error; |
||
900 | } |
||
901 | |||
902 | function canAttach(obj) { |
||
903 | return isError(obj); |
||
904 | } |
||
905 | |||
906 | function subError(nameProperty, defaultMessage) { |
||
907 | function SubError(message) { |
||
908 | if (!(this instanceof SubError)) return new SubError(message); |
||
909 | this.message = typeof message === "string" ? message : defaultMessage; |
||
910 | this.name = nameProperty; |
||
911 | if (Error.captureStackTrace) { |
||
912 | Error.captureStackTrace(this, this.constructor); |
||
913 | } |
||
914 | } |
||
915 | inherits(SubError, Error); |
||
916 | return SubError; |
||
917 | } |
||
918 | |||
919 | var _TypeError, _RangeError; |
||
920 | var CancellationError = subError("CancellationError", "cancellation error"); |
||
921 | var TimeoutError = subError("TimeoutError", "timeout error"); |
||
922 | var AggregateError = subError("AggregateError", "aggregate error"); |
||
923 | try { |
||
924 | _TypeError = TypeError; |
||
925 | _RangeError = RangeError; |
||
926 | } catch(e) { |
||
927 | _TypeError = subError("TypeError", "type error"); |
||
928 | _RangeError = subError("RangeError", "range error"); |
||
929 | } |
||
930 | |||
931 | var methods = ("join pop push shift unshift slice filter forEach some " + |
||
932 | "every map indexOf lastIndexOf reduce reduceRight sort reverse").split(" "); |
||
933 | |||
934 | for (var i = 0; i < methods.length; ++i) { |
||
935 | if (typeof Array.prototype[methods[i]] === "function") { |
||
936 | AggregateError.prototype[methods[i]] = Array.prototype[methods[i]]; |
||
937 | } |
||
938 | } |
||
939 | |||
940 | AggregateError.prototype.length = 0; |
||
941 | AggregateError.prototype["isOperational"] = true; |
||
942 | var level = 0; |
||
943 | AggregateError.prototype.toString = function() { |
||
944 | var indent = Array(level * 4 + 1).join(" "); |
||
945 | var ret = "\n" + indent + "AggregateError of:" + "\n"; |
||
946 | level++; |
||
947 | indent = Array(level * 4 + 1).join(" "); |
||
948 | for (var i = 0; i < this.length; ++i) { |
||
949 | var str = this[i] === this ? "[Circular AggregateError]" : this[i] + ""; |
||
950 | var lines = str.split("\n"); |
||
951 | for (var j = 0; j < lines.length; ++j) { |
||
952 | lines[j] = indent + lines[j]; |
||
953 | } |
||
954 | str = lines.join("\n"); |
||
955 | ret += str + "\n"; |
||
956 | } |
||
957 | level--; |
||
958 | return ret; |
||
959 | }; |
||
960 | |||
961 | function OperationalError(message) { |
||
962 | this.name = "OperationalError"; |
||
963 | this.message = message; |
||
964 | this.cause = message; |
||
965 | this["isOperational"] = true; |
||
966 | |||
967 | if (message instanceof Error) { |
||
968 | this.message = message.message; |
||
969 | this.stack = message.stack; |
||
970 | } else if (Error.captureStackTrace) { |
||
971 | Error.captureStackTrace(this, this.constructor); |
||
972 | } |
||
973 | |||
974 | } |
||
975 | inherits(OperationalError, Error); |
||
976 | |||
977 | var key = "__BluebirdErrorTypes__"; |
||
978 | var errorTypes = Error[key]; |
||
979 | if (!errorTypes) { |
||
980 | errorTypes = Objectfreeze({ |
||
981 | CancellationError: CancellationError, |
||
982 | TimeoutError: TimeoutError, |
||
983 | OperationalError: OperationalError, |
||
984 | RejectionError: OperationalError, |
||
985 | AggregateError: AggregateError |
||
986 | }); |
||
987 | notEnumerableProp(Error, key, errorTypes); |
||
988 | } |
||
989 | |||
990 | module.exports = { |
||
991 | Error: Error, |
||
992 | TypeError: _TypeError, |
||
993 | RangeError: _RangeError, |
||
994 | CancellationError: errorTypes.CancellationError, |
||
995 | OperationalError: errorTypes.OperationalError, |
||
996 | TimeoutError: errorTypes.TimeoutError, |
||
997 | AggregateError: errorTypes.AggregateError, |
||
998 | originatesFromRejection: originatesFromRejection, |
||
999 | markAsOriginatingFromRejection: markAsOriginatingFromRejection, |
||
1000 | canAttach: canAttach |
||
1001 | }; |
||
1002 | |||
1003 | },{"./es5.js":12,"./util.js":35}],11:[function(require,module,exports){ |
||
1004 | /** |
||
1005 | * Copyright (c) 2014 Petka Antonov |
||
1006 | * |
||
1007 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
||
1008 | * of this software and associated documentation files (the "Software"), to deal |
||
1009 | * in the Software without restriction, including without limitation the rights |
||
1010 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
1011 | * copies of the Software, and to permit persons to whom the Software is |
||
1012 | * furnished to do so, subject to the following conditions:</p> |
||
1013 | * |
||
1014 | * The above copyright notice and this permission notice shall be included in |
||
1015 | * all copies or substantial portions of the Software. |
||
1016 | * |
||
1017 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
1018 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
1019 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||
1020 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
1021 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
1022 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||
1023 | * THE SOFTWARE. |
||
1024 | * |
||
1025 | */ |
||
1026 | "use strict"; |
||
1027 | module.exports = function(Promise) { |
||
1028 | var TypeError = require('./errors.js').TypeError; |
||
1029 | |||
1030 | function apiRejection(msg) { |
||
1031 | var error = new TypeError(msg); |
||
1032 | var ret = Promise.rejected(error); |
||
1033 | var parent = ret._peekContext(); |
||
1034 | if (parent != null) { |
||
1035 | parent._attachExtraTrace(error); |
||
1036 | } |
||
1037 | return ret; |
||
1038 | } |
||
1039 | |||
1040 | return apiRejection; |
||
1041 | }; |
||
1042 | |||
1043 | },{"./errors.js":10}],12:[function(require,module,exports){ |
||
1044 | /** |
||
1045 | * Copyright (c) 2014 Petka Antonov |
||
1046 | * |
||
1047 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
||
1048 | * of this software and associated documentation files (the "Software"), to deal |
||
1049 | * in the Software without restriction, including without limitation the rights |
||
1050 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
1051 | * copies of the Software, and to permit persons to whom the Software is |
||
1052 | * furnished to do so, subject to the following conditions:</p> |
||
1053 | * |
||
1054 | * The above copyright notice and this permission notice shall be included in |
||
1055 | * all copies or substantial portions of the Software. |
||
1056 | * |
||
1057 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
1058 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
1059 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||
1060 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
1061 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
1062 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||
1063 | * THE SOFTWARE. |
||
1064 | * |
||
1065 | */ |
||
1066 | var isES5 = (function(){ |
||
1067 | "use strict"; |
||
1068 | return this === void 0; |
||
1069 | })(); |
||
1070 | |||
1071 | if (isES5) { |
||
1072 | module.exports = { |
||
1073 | freeze: Object.freeze, |
||
1074 | defineProperty: Object.defineProperty, |
||
1075 | keys: Object.keys, |
||
1076 | getPrototypeOf: Object.getPrototypeOf, |
||
1077 | isArray: Array.isArray, |
||
1078 | isES5: isES5 |
||
1079 | }; |
||
1080 | } else { |
||
1081 | var has = {}.hasOwnProperty; |
||
1082 | var str = {}.toString; |
||
1083 | var proto = {}.constructor.prototype; |
||
1084 | |||
1085 | var ObjectKeys = function ObjectKeys(o) { |
||
1086 | var ret = []; |
||
1087 | for (var key in o) { |
||
1088 | if (has.call(o, key)) { |
||
1089 | ret.push(key); |
||
1090 | } |
||
1091 | } |
||
1092 | return ret; |
||
1093 | } |
||
1094 | |||
1095 | var ObjectDefineProperty = function ObjectDefineProperty(o, key, desc) { |
||
1096 | o[key] = desc.value; |
||
1097 | return o; |
||
1098 | } |
||
1099 | |||
1100 | var ObjectFreeze = function ObjectFreeze(obj) { |
||
1101 | return obj; |
||
1102 | } |
||
1103 | |||
1104 | var ObjectGetPrototypeOf = function ObjectGetPrototypeOf(obj) { |
||
1105 | try { |
||
1106 | return Object(obj).constructor.prototype; |
||
1107 | } |
||
1108 | catch (e) { |
||
1109 | return proto; |
||
1110 | } |
||
1111 | } |
||
1112 | |||
1113 | var ArrayIsArray = function ArrayIsArray(obj) { |
||
1114 | try { |
||
1115 | return str.call(obj) === "[object Array]"; |
||
1116 | } |
||
1117 | catch(e) { |
||
1118 | return false; |
||
1119 | } |
||
1120 | } |
||
1121 | |||
1122 | module.exports = { |
||
1123 | isArray: ArrayIsArray, |
||
1124 | keys: ObjectKeys, |
||
1125 | defineProperty: ObjectDefineProperty, |
||
1126 | freeze: ObjectFreeze, |
||
1127 | getPrototypeOf: ObjectGetPrototypeOf, |
||
1128 | isES5: isES5 |
||
1129 | }; |
||
1130 | } |
||
1131 | |||
1132 | },{}],13:[function(require,module,exports){ |
||
1133 | /** |
||
1134 | * Copyright (c) 2014 Petka Antonov |
||
1135 | * |
||
1136 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
||
1137 | * of this software and associated documentation files (the "Software"), to deal |
||
1138 | * in the Software without restriction, including without limitation the rights |
||
1139 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
1140 | * copies of the Software, and to permit persons to whom the Software is |
||
1141 | * furnished to do so, subject to the following conditions:</p> |
||
1142 | * |
||
1143 | * The above copyright notice and this permission notice shall be included in |
||
1144 | * all copies or substantial portions of the Software. |
||
1145 | * |
||
1146 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
1147 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
1148 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||
1149 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
1150 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
1151 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||
1152 | * THE SOFTWARE. |
||
1153 | * |
||
1154 | */ |
||
1155 | "use strict"; |
||
1156 | module.exports = function(Promise, INTERNAL) { |
||
1157 | var PromiseMap = Promise.map; |
||
1158 | |||
1159 | Promise.prototype.filter = function Promise$filter(fn, options) { |
||
1160 | return PromiseMap(this, fn, options, INTERNAL); |
||
1161 | }; |
||
1162 | |||
1163 | Promise.filter = function Promise$Filter(promises, fn, options) { |
||
1164 | return PromiseMap(promises, fn, options, INTERNAL); |
||
1165 | }; |
||
1166 | }; |
||
1167 | |||
1168 | },{}],14:[function(require,module,exports){ |
||
1169 | /** |
||
1170 | * Copyright (c) 2014 Petka Antonov |
||
1171 | * |
||
1172 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
||
1173 | * of this software and associated documentation files (the "Software"), to deal |
||
1174 | * in the Software without restriction, including without limitation the rights |
||
1175 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
1176 | * copies of the Software, and to permit persons to whom the Software is |
||
1177 | * furnished to do so, subject to the following conditions:</p> |
||
1178 | * |
||
1179 | * The above copyright notice and this permission notice shall be included in |
||
1180 | * all copies or substantial portions of the Software. |
||
1181 | * |
||
1182 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
1183 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
1184 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||
1185 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
1186 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
1187 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||
1188 | * THE SOFTWARE. |
||
1189 | * |
||
1190 | */ |
||
1191 | "use strict"; |
||
1192 | module.exports = function(Promise, NEXT_FILTER, cast) { |
||
1193 | var util = require("./util.js"); |
||
1194 | var wrapsPrimitiveReceiver = util.wrapsPrimitiveReceiver; |
||
1195 | var isPrimitive = util.isPrimitive; |
||
1196 | var thrower = util.thrower; |
||
1197 | |||
1198 | function returnThis() { |
||
1199 | return this; |
||
1200 | } |
||
1201 | function throwThis() { |
||
1202 | throw this; |
||
1203 | } |
||
1204 | function return$(r) { |
||
1205 | return function Promise$_returner() { |
||
1206 | return r; |
||
1207 | }; |
||
1208 | } |
||
1209 | function throw$(r) { |
||
1210 | return function Promise$_thrower() { |
||
1211 | throw r; |
||
1212 | }; |
||
1213 | } |
||
1214 | function promisedFinally(ret, reasonOrValue, isFulfilled) { |
||
1215 | var then; |
||
1216 | if (wrapsPrimitiveReceiver && isPrimitive(reasonOrValue)) { |
||
1217 | then = isFulfilled ? return$(reasonOrValue) : throw$(reasonOrValue); |
||
1218 | } else { |
||
1219 | then = isFulfilled ? returnThis : throwThis; |
||
1220 | } |
||
1221 | return ret._then(then, thrower, void 0, reasonOrValue, void 0); |
||
1222 | } |
||
1223 | |||
1224 | function finallyHandler(reasonOrValue) { |
||
1225 | var promise = this.promise; |
||
1226 | var handler = this.handler; |
||
1227 | |||
1228 | var ret = promise._isBound() |
||
1229 | ? handler.call(promise._boundTo) |
||
1230 | : handler(); |
||
1231 | |||
1232 | if (ret !== void 0) { |
||
1233 | var maybePromise = cast(ret, void 0); |
||
1234 | if (maybePromise instanceof Promise) { |
||
1235 | return promisedFinally(maybePromise, reasonOrValue, |
||
1236 | promise.isFulfilled()); |
||
1237 | } |
||
1238 | } |
||
1239 | |||
1240 | if (promise.isRejected()) { |
||
1241 | NEXT_FILTER.e = reasonOrValue; |
||
1242 | return NEXT_FILTER; |
||
1243 | } else { |
||
1244 | return reasonOrValue; |
||
1245 | } |
||
1246 | } |
||
1247 | |||
1248 | function tapHandler(value) { |
||
1249 | var promise = this.promise; |
||
1250 | var handler = this.handler; |
||
1251 | |||
1252 | var ret = promise._isBound() |
||
1253 | ? handler.call(promise._boundTo, value) |
||
1254 | : handler(value); |
||
1255 | |||
1256 | if (ret !== void 0) { |
||
1257 | var maybePromise = cast(ret, void 0); |
||
1258 | if (maybePromise instanceof Promise) { |
||
1259 | return promisedFinally(maybePromise, value, true); |
||
1260 | } |
||
1261 | } |
||
1262 | return value; |
||
1263 | } |
||
1264 | |||
1265 | Promise.prototype._passThroughHandler = |
||
1266 | function Promise$_passThroughHandler(handler, isFinally) { |
||
1267 | if (typeof handler !== "function") return this.then(); |
||
1268 | |||
1269 | var promiseAndHandler = { |
||
1270 | promise: this, |
||
1271 | handler: handler |
||
1272 | }; |
||
1273 | |||
1274 | return this._then( |
||
1275 | isFinally ? finallyHandler : tapHandler, |
||
1276 | isFinally ? finallyHandler : void 0, void 0, |
||
1277 | promiseAndHandler, void 0); |
||
1278 | }; |
||
1279 | |||
1280 | Promise.prototype.lastly = |
||
1281 | Promise.prototype["finally"] = function Promise$finally(handler) { |
||
1282 | return this._passThroughHandler(handler, true); |
||
1283 | }; |
||
1284 | |||
1285 | Promise.prototype.tap = function Promise$tap(handler) { |
||
1286 | return this._passThroughHandler(handler, false); |
||
1287 | }; |
||
1288 | }; |
||
1289 | |||
1290 | },{"./util.js":35}],15:[function(require,module,exports){ |
||
1291 | /** |
||
1292 | * Copyright (c) 2014 Petka Antonov |
||
1293 | * |
||
1294 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
||
1295 | * of this software and associated documentation files (the "Software"), to deal |
||
1296 | * in the Software without restriction, including without limitation the rights |
||
1297 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
1298 | * copies of the Software, and to permit persons to whom the Software is |
||
1299 | * furnished to do so, subject to the following conditions:</p> |
||
1300 | * |
||
1301 | * The above copyright notice and this permission notice shall be included in |
||
1302 | * all copies or substantial portions of the Software. |
||
1303 | * |
||
1304 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
1305 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
1306 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||
1307 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
1308 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
1309 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||
1310 | * THE SOFTWARE. |
||
1311 | * |
||
1312 | */ |
||
1313 | "use strict"; |
||
1314 | module.exports = function(Promise, apiRejection, INTERNAL, cast) { |
||
1315 | var errors = require("./errors.js"); |
||
1316 | var TypeError = errors.TypeError; |
||
1317 | var deprecated = require("./util.js").deprecated; |
||
1318 | var util = require("./util.js"); |
||
1319 | var errorObj = util.errorObj; |
||
1320 | var tryCatch1 = util.tryCatch1; |
||
1321 | var yieldHandlers = []; |
||
1322 | |||
1323 | function promiseFromYieldHandler(value, yieldHandlers) { |
||
1324 | var _errorObj = errorObj; |
||
1325 | var _Promise = Promise; |
||
1326 | var len = yieldHandlers.length; |
||
1327 | for (var i = 0; i < len; ++i) { |
||
1328 | var result = tryCatch1(yieldHandlers[i], void 0, value); |
||
1329 | if (result === _errorObj) { |
||
1330 | return _Promise.reject(_errorObj.e); |
||
1331 | } |
||
1332 | var maybePromise = cast(result, promiseFromYieldHandler); |
||
1333 | if (maybePromise instanceof _Promise) return maybePromise; |
||
1334 | } |
||
1335 | return null; |
||
1336 | } |
||
1337 | |||
1338 | function PromiseSpawn(generatorFunction, receiver, yieldHandler) { |
||
1339 | var promise = this._promise = new Promise(INTERNAL); |
||
1340 | promise._setTrace(void 0); |
||
1341 | this._generatorFunction = generatorFunction; |
||
1342 | this._receiver = receiver; |
||
1343 | this._generator = void 0; |
||
1344 | this._yieldHandlers = typeof yieldHandler === "function" |
||
1345 | ? [yieldHandler].concat(yieldHandlers) |
||
1346 | : yieldHandlers; |
||
1347 | } |
||
1348 | |||
1349 | PromiseSpawn.prototype.promise = function PromiseSpawn$promise() { |
||
1350 | return this._promise; |
||
1351 | }; |
||
1352 | |||
1353 | PromiseSpawn.prototype._run = function PromiseSpawn$_run() { |
||
1354 | this._generator = this._generatorFunction.call(this._receiver); |
||
1355 | this._receiver = |
||
1356 | this._generatorFunction = void 0; |
||
1357 | this._next(void 0); |
||
1358 | }; |
||
1359 | |||
1360 | PromiseSpawn.prototype._continue = function PromiseSpawn$_continue(result) { |
||
1361 | if (result === errorObj) { |
||
1362 | this._generator = void 0; |
||
1363 | var trace = errors.canAttach(result.e) |
||
1364 | ? result.e : new Error(result.e + ""); |
||
1365 | this._promise._attachExtraTrace(trace); |
||
1366 | this._promise._reject(result.e, trace); |
||
1367 | return; |
||
1368 | } |
||
1369 | |||
1370 | var value = result.value; |
||
1371 | if (result.done === true) { |
||
1372 | this._generator = void 0; |
||
1373 | if (!this._promise._tryFollow(value)) { |
||
1374 | this._promise._fulfill(value); |
||
1375 | } |
||
1376 | } else { |
||
1377 | var maybePromise = cast(value, void 0); |
||
1378 | if (!(maybePromise instanceof Promise)) { |
||
1379 | maybePromise = |
||
1380 | promiseFromYieldHandler(maybePromise, this._yieldHandlers); |
||
1381 | if (maybePromise === null) { |
||
1382 | this._throw(new TypeError("A value was yielded that could not be treated as a promise")); |
||
1383 | return; |
||
1384 | } |
||
1385 | } |
||
1386 | maybePromise._then( |
||
1387 | this._next, |
||
1388 | this._throw, |
||
1389 | void 0, |
||
1390 | this, |
||
1391 | null |
||
1392 | ); |
||
1393 | } |
||
1394 | }; |
||
1395 | |||
1396 | PromiseSpawn.prototype._throw = function PromiseSpawn$_throw(reason) { |
||
1397 | if (errors.canAttach(reason)) |
||
1398 | this._promise._attachExtraTrace(reason); |
||
1399 | this._continue( |
||
1400 | tryCatch1(this._generator["throw"], this._generator, reason) |
||
1401 | ); |
||
1402 | }; |
||
1403 | |||
1404 | PromiseSpawn.prototype._next = function PromiseSpawn$_next(value) { |
||
1405 | this._continue( |
||
1406 | tryCatch1(this._generator.next, this._generator, value) |
||
1407 | ); |
||
1408 | }; |
||
1409 | |||
1410 | Promise.coroutine = |
||
1411 | function Promise$Coroutine(generatorFunction, options) { |
||
1412 | if (typeof generatorFunction !== "function") { |
||
1413 | throw new TypeError("generatorFunction must be a function"); |
||
1414 | } |
||
1415 | var yieldHandler = Object(options).yieldHandler; |
||
1416 | var PromiseSpawn$ = PromiseSpawn; |
||
1417 | return function () { |
||
1418 | var generator = generatorFunction.apply(this, arguments); |
||
1419 | var spawn = new PromiseSpawn$(void 0, void 0, yieldHandler); |
||
1420 | spawn._generator = generator; |
||
1421 | spawn._next(void 0); |
||
1422 | return spawn.promise(); |
||
1423 | }; |
||
1424 | }; |
||
1425 | |||
1426 | Promise.coroutine.addYieldHandler = function(fn) { |
||
1427 | if (typeof fn !== "function") throw new TypeError("fn must be a function"); |
||
1428 | yieldHandlers.push(fn); |
||
1429 | }; |
||
1430 | |||
1431 | Promise.spawn = function Promise$Spawn(generatorFunction) { |
||
1432 | deprecated("Promise.spawn is deprecated. Use Promise.coroutine instead."); |
||
1433 | if (typeof generatorFunction !== "function") { |
||
1434 | return apiRejection("generatorFunction must be a function"); |
||
1435 | } |
||
1436 | var spawn = new PromiseSpawn(generatorFunction, this); |
||
1437 | var ret = spawn.promise(); |
||
1438 | spawn._run(Promise.spawn); |
||
1439 | return ret; |
||
1440 | }; |
||
1441 | }; |
||
1442 | |||
1443 | },{"./errors.js":10,"./util.js":35}],16:[function(require,module,exports){ |
||
1444 | /** |
||
1445 | * Copyright (c) 2014 Petka Antonov |
||
1446 | * |
||
1447 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
||
1448 | * of this software and associated documentation files (the "Software"), to deal |
||
1449 | * in the Software without restriction, including without limitation the rights |
||
1450 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
1451 | * copies of the Software, and to permit persons to whom the Software is |
||
1452 | * furnished to do so, subject to the following conditions:</p> |
||
1453 | * |
||
1454 | * The above copyright notice and this permission notice shall be included in |
||
1455 | * all copies or substantial portions of the Software. |
||
1456 | * |
||
1457 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
1458 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
1459 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||
1460 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
1461 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
1462 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||
1463 | * THE SOFTWARE. |
||
1464 | * |
||
1465 | */ |
||
1466 | "use strict"; |
||
1467 | module.exports = |
||
1468 | function(Promise, PromiseArray, cast, INTERNAL) { |
||
1469 | var util = require("./util.js"); |
||
1470 | var canEvaluate = util.canEvaluate; |
||
1471 | var tryCatch1 = util.tryCatch1; |
||
1472 | var errorObj = util.errorObj; |
||
1473 | |||
1474 | |||
1475 | if (canEvaluate) { |
||
1476 | var thenCallback = function(i) { |
||
1477 | return new Function("value", "holder", " \n\ |
||
1478 | 'use strict'; \n\ |
||
1479 | holder.pIndex = value; \n\ |
||
1480 | holder.checkFulfillment(this); \n\ |
||
1481 | ".replace(/Index/g, i)); |
||
1482 | }; |
||
1483 | |||
1484 | var caller = function(count) { |
||
1485 | var values = []; |
||
1486 | for (var i = 1; i <= count; ++i) values.push("holder.p" + i); |
||
1487 | return new Function("holder", " \n\ |
||
1488 | 'use strict'; \n\ |
||
1489 | var callback = holder.fn; \n\ |
||
1490 | return callback(values); \n\ |
||
1491 | ".replace(/values/g, values.join(", "))); |
||
1492 | }; |
||
1493 | var thenCallbacks = []; |
||
1494 | var callers = [void 0]; |
||
1495 | for (var i = 1; i <= 5; ++i) { |
||
1496 | thenCallbacks.push(thenCallback(i)); |
||
1497 | callers.push(caller(i)); |
||
1498 | } |
||
1499 | |||
1500 | var Holder = function(total, fn) { |
||
1501 | this.p1 = this.p2 = this.p3 = this.p4 = this.p5 = null; |
||
1502 | this.fn = fn; |
||
1503 | this.total = total; |
||
1504 | this.now = 0; |
||
1505 | }; |
||
1506 | |||
1507 | Holder.prototype.callers = callers; |
||
1508 | Holder.prototype.checkFulfillment = function(promise) { |
||
1509 | var now = this.now; |
||
1510 | now++; |
||
1511 | var total = this.total; |
||
1512 | if (now >= total) { |
||
1513 | var handler = this.callers[total]; |
||
1514 | var ret = tryCatch1(handler, void 0, this); |
||
1515 | if (ret === errorObj) { |
||
1516 | promise._rejectUnchecked(ret.e); |
||
1517 | } else if (!promise._tryFollow(ret)) { |
||
1518 | promise._fulfillUnchecked(ret); |
||
1519 | } |
||
1520 | } else { |
||
1521 | this.now = now; |
||
1522 | } |
||
1523 | }; |
||
1524 | } |
||
1525 | |||
1526 | |||
1527 | |||
1528 | |||
1529 | Promise.join = function Promise$Join() { |
||
1530 | var last = arguments.length - 1; |
||
1531 | var fn; |
||
1532 | if (last > 0 && typeof arguments[last] === "function") { |
||
1533 | fn = arguments[last]; |
||
1534 | if (last < 6 && canEvaluate) { |
||
1535 | var ret = new Promise(INTERNAL); |
||
1536 | ret._setTrace(void 0); |
||
1537 | var holder = new Holder(last, fn); |
||
1538 | var reject = ret._reject; |
||
1539 | var callbacks = thenCallbacks; |
||
1540 | for (var i = 0; i < last; ++i) { |
||
1541 | var maybePromise = cast(arguments[i], void 0); |
||
1542 | if (maybePromise instanceof Promise) { |
||
1543 | if (maybePromise.isPending()) { |
||
1544 | maybePromise._then(callbacks[i], reject, |
||
1545 | void 0, ret, holder); |
||
1546 | } else if (maybePromise.isFulfilled()) { |
||
1547 | callbacks[i].call(ret, |
||
1548 | maybePromise._settledValue, holder); |
||
1549 | } else { |
||
1550 | ret._reject(maybePromise._settledValue); |
||
1551 | maybePromise._unsetRejectionIsUnhandled(); |
||
1552 | } |
||
1553 | } else { |
||
1554 | callbacks[i].call(ret, maybePromise, holder); |
||
1555 | } |
||
1556 | } |
||
1557 | return ret; |
||
1558 | } |
||
1559 | } |
||
1560 | var $_len = arguments.length;var args = new Array($_len); for(var $_i = 0; $_i < $_len; ++$_i) {args[$_i] = arguments[$_i];} |
||
1561 | var ret = new PromiseArray(args).promise(); |
||
1562 | return fn !== void 0 ? ret.spread(fn) : ret; |
||
1563 | }; |
||
1564 | |||
1565 | }; |
||
1566 | |||
1567 | },{"./util.js":35}],17:[function(require,module,exports){ |
||
1568 | /** |
||
1569 | * Copyright (c) 2014 Petka Antonov |
||
1570 | * |
||
1571 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
||
1572 | * of this software and associated documentation files (the "Software"), to deal |
||
1573 | * in the Software without restriction, including without limitation the rights |
||
1574 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
1575 | * copies of the Software, and to permit persons to whom the Software is |
||
1576 | * furnished to do so, subject to the following conditions:</p> |
||
1577 | * |
||
1578 | * The above copyright notice and this permission notice shall be included in |
||
1579 | * all copies or substantial portions of the Software. |
||
1580 | * |
||
1581 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
1582 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
1583 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||
1584 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
1585 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
1586 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||
1587 | * THE SOFTWARE. |
||
1588 | * |
||
1589 | */ |
||
1590 | "use strict"; |
||
1591 | module.exports = function(Promise, PromiseArray, apiRejection, cast, INTERNAL) { |
||
1592 | var util = require("./util.js"); |
||
1593 | var tryCatch3 = util.tryCatch3; |
||
1594 | var errorObj = util.errorObj; |
||
1595 | var PENDING = {}; |
||
1596 | var EMPTY_ARRAY = []; |
||
1597 | |||
1598 | function MappingPromiseArray(promises, fn, limit, _filter) { |
||
1599 | this.constructor$(promises); |
||
1600 | this._callback = fn; |
||
1601 | this._preservedValues = _filter === INTERNAL |
||
1602 | ? new Array(this.length()) |
||
1603 | : null; |
||
1604 | this._limit = limit; |
||
1605 | this._inFlight = 0; |
||
1606 | this._queue = limit >= 1 ? [] : EMPTY_ARRAY; |
||
1607 | this._init$(void 0, -2); |
||
1608 | } |
||
1609 | util.inherits(MappingPromiseArray, PromiseArray); |
||
1610 | |||
1611 | MappingPromiseArray.prototype._init = function MappingPromiseArray$_init() {}; |
||
1612 | |||
1613 | MappingPromiseArray.prototype._promiseFulfilled = |
||
1614 | function MappingPromiseArray$_promiseFulfilled(value, index) { |
||
1615 | var values = this._values; |
||
1616 | if (values === null) return; |
||
1617 | |||
1618 | var length = this.length(); |
||
1619 | var preservedValues = this._preservedValues; |
||
1620 | var limit = this._limit; |
||
1621 | if (values[index] === PENDING) { |
||
1622 | values[index] = value; |
||
1623 | if (limit >= 1) { |
||
1624 | this._inFlight--; |
||
1625 | this._drainQueue(); |
||
1626 | if (this._isResolved()) return; |
||
1627 | } |
||
1628 | } else { |
||
1629 | if (limit >= 1 && this._inFlight >= limit) { |
||
1630 | values[index] = value; |
||
1631 | this._queue.push(index); |
||
1632 | return; |
||
1633 | } |
||
1634 | if (preservedValues !== null) preservedValues[index] = value; |
||
1635 | |||
1636 | var callback = this._callback; |
||
1637 | var receiver = this._promise._boundTo; |
||
1638 | var ret = tryCatch3(callback, receiver, value, index, length); |
||
1639 | if (ret === errorObj) return this._reject(ret.e); |
||
1640 | |||
1641 | var maybePromise = cast(ret, void 0); |
||
1642 | if (maybePromise instanceof Promise) { |
||
1643 | if (maybePromise.isPending()) { |
||
1644 | if (limit >= 1) this._inFlight++; |
||
1645 | values[index] = PENDING; |
||
1646 | return maybePromise._proxyPromiseArray(this, index); |
||
1647 | } else if (maybePromise.isFulfilled()) { |
||
1648 | ret = maybePromise.value(); |
||
1649 | } else { |
||
1650 | maybePromise._unsetRejectionIsUnhandled(); |
||
1651 | return this._reject(maybePromise.reason()); |
||
1652 | } |
||
1653 | } |
||
1654 | values[index] = ret; |
||
1655 | } |
||
1656 | var totalResolved = ++this._totalResolved; |
||
1657 | if (totalResolved >= length) { |
||
1658 | if (preservedValues !== null) { |
||
1659 | this._filter(values, preservedValues); |
||
1660 | } else { |
||
1661 | this._resolve(values); |
||
1662 | } |
||
1663 | |||
1664 | } |
||
1665 | }; |
||
1666 | |||
1667 | MappingPromiseArray.prototype._drainQueue = |
||
1668 | function MappingPromiseArray$_drainQueue() { |
||
1669 | var queue = this._queue; |
||
1670 | var limit = this._limit; |
||
1671 | var values = this._values; |
||
1672 | while (queue.length > 0 && this._inFlight < limit) { |
||
1673 | var index = queue.pop(); |
||
1674 | this._promiseFulfilled(values[index], index); |
||
1675 | } |
||
1676 | }; |
||
1677 | |||
1678 | MappingPromiseArray.prototype._filter = |
||
1679 | function MappingPromiseArray$_filter(booleans, values) { |
||
1680 | var len = values.length; |
||
1681 | var ret = new Array(len); |
||
1682 | var j = 0; |
||
1683 | for (var i = 0; i < len; ++i) { |
||
1684 | if (booleans[i]) ret[j++] = values[i]; |
||
1685 | } |
||
1686 | ret.length = j; |
||
1687 | this._resolve(ret); |
||
1688 | }; |
||
1689 | |||
1690 | MappingPromiseArray.prototype.preservedValues = |
||
1691 | function MappingPromiseArray$preserveValues() { |
||
1692 | return this._preservedValues; |
||
1693 | }; |
||
1694 | |||
1695 | function map(promises, fn, options, _filter) { |
||
1696 | var limit = typeof options === "object" && options !== null |
||
1697 | ? options.concurrency |
||
1698 | : 0; |
||
1699 | limit = typeof limit === "number" && |
||
1700 | isFinite(limit) && limit >= 1 ? limit : 0; |
||
1701 | return new MappingPromiseArray(promises, fn, limit, _filter); |
||
1702 | } |
||
1703 | |||
1704 | Promise.prototype.map = function Promise$map(fn, options) { |
||
1705 | if (typeof fn !== "function") return apiRejection("fn must be a function"); |
||
1706 | |||
1707 | return map(this, fn, options, null).promise(); |
||
1708 | }; |
||
1709 | |||
1710 | Promise.map = function Promise$Map(promises, fn, options, _filter) { |
||
1711 | if (typeof fn !== "function") return apiRejection("fn must be a function"); |
||
1712 | return map(promises, fn, options, _filter).promise(); |
||
1713 | }; |
||
1714 | |||
1715 | |||
1716 | }; |
||
1717 | |||
1718 | },{"./util.js":35}],18:[function(require,module,exports){ |
||
1719 | /** |
||
1720 | * Copyright (c) 2014 Petka Antonov |
||
1721 | * |
||
1722 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
||
1723 | * of this software and associated documentation files (the "Software"), to deal |
||
1724 | * in the Software without restriction, including without limitation the rights |
||
1725 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
1726 | * copies of the Software, and to permit persons to whom the Software is |
||
1727 | * furnished to do so, subject to the following conditions:</p> |
||
1728 | * |
||
1729 | * The above copyright notice and this permission notice shall be included in |
||
1730 | * all copies or substantial portions of the Software. |
||
1731 | * |
||
1732 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
1733 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
1734 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||
1735 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
1736 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
1737 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||
1738 | * THE SOFTWARE. |
||
1739 | * |
||
1740 | */ |
||
1741 | "use strict"; |
||
1742 | module.exports = function(Promise) { |
||
1743 | var util = require("./util.js"); |
||
1744 | var async = require("./async.js"); |
||
1745 | var tryCatch2 = util.tryCatch2; |
||
1746 | var tryCatch1 = util.tryCatch1; |
||
1747 | var errorObj = util.errorObj; |
||
1748 | |||
1749 | function thrower(r) { |
||
1750 | throw r; |
||
1751 | } |
||
1752 | |||
1753 | function Promise$_spreadAdapter(val, receiver) { |
||
1754 | if (!util.isArray(val)) return Promise$_successAdapter(val, receiver); |
||
1755 | var ret = util.tryCatchApply(this, [null].concat(val), receiver); |
||
1756 | if (ret === errorObj) { |
||
1757 | async.invokeLater(thrower, void 0, ret.e); |
||
1758 | } |
||
1759 | } |
||
1760 | |||
1761 | function Promise$_successAdapter(val, receiver) { |
||
1762 | var nodeback = this; |
||
1763 | var ret = val === void 0 |
||
1764 | ? tryCatch1(nodeback, receiver, null) |
||
1765 | : tryCatch2(nodeback, receiver, null, val); |
||
1766 | if (ret === errorObj) { |
||
1767 | async.invokeLater(thrower, void 0, ret.e); |
||
1768 | } |
||
1769 | } |
||
1770 | function Promise$_errorAdapter(reason, receiver) { |
||
1771 | var nodeback = this; |
||
1772 | var ret = tryCatch1(nodeback, receiver, reason); |
||
1773 | if (ret === errorObj) { |
||
1774 | async.invokeLater(thrower, void 0, ret.e); |
||
1775 | } |
||
1776 | } |
||
1777 | |||
1778 | Promise.prototype.nodeify = function Promise$nodeify(nodeback, options) { |
||
1779 | if (typeof nodeback == "function") { |
||
1780 | var adapter = Promise$_successAdapter; |
||
1781 | if (options !== void 0 && Object(options).spread) { |
||
1782 | adapter = Promise$_spreadAdapter; |
||
1783 | } |
||
1784 | this._then( |
||
1785 | adapter, |
||
1786 | Promise$_errorAdapter, |
||
1787 | void 0, |
||
1788 | nodeback, |
||
1789 | this._boundTo |
||
1790 | ); |
||
1791 | } |
||
1792 | return this; |
||
1793 | }; |
||
1794 | }; |
||
1795 | |||
1796 | },{"./async.js":2,"./util.js":35}],19:[function(require,module,exports){ |
||
1797 | /** |
||
1798 | * Copyright (c) 2014 Petka Antonov |
||
1799 | * |
||
1800 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
||
1801 | * of this software and associated documentation files (the "Software"), to deal |
||
1802 | * in the Software without restriction, including without limitation the rights |
||
1803 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
1804 | * copies of the Software, and to permit persons to whom the Software is |
||
1805 | * furnished to do so, subject to the following conditions:</p> |
||
1806 | * |
||
1807 | * The above copyright notice and this permission notice shall be included in |
||
1808 | * all copies or substantial portions of the Software. |
||
1809 | * |
||
1810 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
1811 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
1812 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||
1813 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
1814 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
1815 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||
1816 | * THE SOFTWARE. |
||
1817 | * |
||
1818 | */ |
||
1819 | "use strict"; |
||
1820 | module.exports = function(Promise, PromiseArray) { |
||
1821 | var util = require("./util.js"); |
||
1822 | var async = require("./async.js"); |
||
1823 | var errors = require("./errors.js"); |
||
1824 | var tryCatch1 = util.tryCatch1; |
||
1825 | var errorObj = util.errorObj; |
||
1826 | |||
1827 | Promise.prototype.progressed = function Promise$progressed(handler) { |
||
1828 | return this._then(void 0, void 0, handler, void 0, void 0); |
||
1829 | }; |
||
1830 | |||
1831 | Promise.prototype._progress = function Promise$_progress(progressValue) { |
||
1832 | if (this._isFollowingOrFulfilledOrRejected()) return; |
||
1833 | this._progressUnchecked(progressValue); |
||
1834 | |||
1835 | }; |
||
1836 | |||
1837 | Promise.prototype._progressHandlerAt = |
||
1838 | function Promise$_progressHandlerAt(index) { |
||
1839 | return index === 0 |
||
1840 | ? this._progressHandler0 |
||
1841 | : this[(index << 2) + index - 5 + 2]; |
||
1842 | }; |
||
1843 | |||
1844 | Promise.prototype._doProgressWith = |
||
1845 | function Promise$_doProgressWith(progression) { |
||
1846 | var progressValue = progression.value; |
||
1847 | var handler = progression.handler; |
||
1848 | var promise = progression.promise; |
||
1849 | var receiver = progression.receiver; |
||
1850 | |||
1851 | var ret = tryCatch1(handler, receiver, progressValue); |
||
1852 | if (ret === errorObj) { |
||
1853 | if (ret.e != null && |
||
1854 | ret.e.name !== "StopProgressPropagation") { |
||
1855 | var trace = errors.canAttach(ret.e) |
||
1856 | ? ret.e : new Error(ret.e + ""); |
||
1857 | promise._attachExtraTrace(trace); |
||
1858 | promise._progress(ret.e); |
||
1859 | } |
||
1860 | } else if (ret instanceof Promise) { |
||
1861 | ret._then(promise._progress, null, null, promise, void 0); |
||
1862 | } else { |
||
1863 | promise._progress(ret); |
||
1864 | } |
||
1865 | }; |
||
1866 | |||
1867 | |||
1868 | Promise.prototype._progressUnchecked = |
||
1869 | function Promise$_progressUnchecked(progressValue) { |
||
1870 | if (!this.isPending()) return; |
||
1871 | var len = this._length(); |
||
1872 | var progress = this._progress; |
||
1873 | for (var i = 0; i < len; i++) { |
||
1874 | var handler = this._progressHandlerAt(i); |
||
1875 | var promise = this._promiseAt(i); |
||
1876 | if (!(promise instanceof Promise)) { |
||
1877 | var receiver = this._receiverAt(i); |
||
1878 | if (typeof handler === "function") { |
||
1879 | handler.call(receiver, progressValue, promise); |
||
1880 | } else if (receiver instanceof Promise && receiver._isProxied()) { |
||
1881 | receiver._progressUnchecked(progressValue); |
||
1882 | } else if (receiver instanceof PromiseArray) { |
||
1883 | receiver._promiseProgressed(progressValue, promise); |
||
1884 | } |
||
1885 | continue; |
||
1886 | } |
||
1887 | |||
1888 | if (typeof handler === "function") { |
||
1889 | async.invoke(this._doProgressWith, this, { |
||
1890 | handler: handler, |
||
1891 | promise: promise, |
||
1892 | receiver: this._receiverAt(i), |
||
1893 | value: progressValue |
||
1894 | }); |
||
1895 | } else { |
||
1896 | async.invoke(progress, promise, progressValue); |
||
1897 | } |
||
1898 | } |
||
1899 | }; |
||
1900 | }; |
||
1901 | |||
1902 | },{"./async.js":2,"./errors.js":10,"./util.js":35}],20:[function(require,module,exports){ |
||
1903 | /** |
||
1904 | * Copyright (c) 2014 Petka Antonov |
||
1905 | * |
||
1906 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
||
1907 | * of this software and associated documentation files (the "Software"), to deal |
||
1908 | * in the Software without restriction, including without limitation the rights |
||
1909 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
1910 | * copies of the Software, and to permit persons to whom the Software is |
||
1911 | * furnished to do so, subject to the following conditions:</p> |
||
1912 | * |
||
1913 | * The above copyright notice and this permission notice shall be included in |
||
1914 | * all copies or substantial portions of the Software. |
||
1915 | * |
||
1916 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
1917 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
1918 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||
1919 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
1920 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
1921 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||
1922 | * THE SOFTWARE. |
||
1923 | * |
||
1924 | */ |
||
1925 | "use strict"; |
||
1926 | var old; |
||
1927 | if (typeof Promise !== "undefined") old = Promise; |
||
1928 | function noConflict(bluebird) { |
||
1929 | try { if (Promise === bluebird) Promise = old; } |
||
1930 | catch (e) {} |
||
1931 | return bluebird; |
||
1932 | } |
||
1933 | module.exports = function() { |
||
1934 | var util = require("./util.js"); |
||
1935 | var async = require("./async.js"); |
||
1936 | var errors = require("./errors.js"); |
||
1937 | |||
1938 | var INTERNAL = function(){}; |
||
1939 | var APPLY = {}; |
||
1940 | var NEXT_FILTER = {e: null}; |
||
1941 | |||
1942 | var cast = require("./thenables.js")(Promise, INTERNAL); |
||
1943 | var PromiseArray = require("./promise_array.js")(Promise, INTERNAL, cast); |
||
1944 | var CapturedTrace = require("./captured_trace.js")(); |
||
1945 | var CatchFilter = require("./catch_filter.js")(NEXT_FILTER); |
||
1946 | var PromiseResolver = require("./promise_resolver.js"); |
||
1947 | |||
1948 | var isArray = util.isArray; |
||
1949 | |||
1950 | var errorObj = util.errorObj; |
||
1951 | var tryCatch1 = util.tryCatch1; |
||
1952 | var tryCatch2 = util.tryCatch2; |
||
1953 | var tryCatchApply = util.tryCatchApply; |
||
1954 | var RangeError = errors.RangeError; |
||
1955 | var TypeError = errors.TypeError; |
||
1956 | var CancellationError = errors.CancellationError; |
||
1957 | var TimeoutError = errors.TimeoutError; |
||
1958 | var OperationalError = errors.OperationalError; |
||
1959 | var originatesFromRejection = errors.originatesFromRejection; |
||
1960 | var markAsOriginatingFromRejection = errors.markAsOriginatingFromRejection; |
||
1961 | var canAttach = errors.canAttach; |
||
1962 | var thrower = util.thrower; |
||
1963 | var apiRejection = require("./errors_api_rejection")(Promise); |
||
1964 | |||
1965 | |||
1966 | var makeSelfResolutionError = function Promise$_makeSelfResolutionError() { |
||
1967 | return new TypeError("circular promise resolution chain"); |
||
1968 | }; |
||
1969 | |||
1970 | function Promise(resolver) { |
||
1971 | if (typeof resolver !== "function") { |
||
1972 | throw new TypeError("the promise constructor requires a resolver function"); |
||
1973 | } |
||
1974 | if (this.constructor !== Promise) { |
||
1975 | throw new TypeError("the promise constructor cannot be invoked directly"); |
||
1976 | } |
||
1977 | this._bitField = 0; |
||
1978 | this._fulfillmentHandler0 = void 0; |
||
1979 | this._rejectionHandler0 = void 0; |
||
1980 | this._promise0 = void 0; |
||
1981 | this._receiver0 = void 0; |
||
1982 | this._settledValue = void 0; |
||
1983 | this._boundTo = void 0; |
||
1984 | if (resolver !== INTERNAL) this._resolveFromResolver(resolver); |
||
1985 | } |
||
1986 | |||
1987 | Promise.prototype.bind = function Promise$bind(thisArg) { |
||
1988 | var ret = new Promise(INTERNAL); |
||
1989 | ret._follow(this); |
||
1990 | ret._propagateFrom(this, 2 | 1); |
||
1991 | ret._setBoundTo(thisArg); |
||
1992 | return ret; |
||
1993 | }; |
||
1994 | |||
1995 | Promise.prototype.toString = function Promise$toString() { |
||
1996 | return "[object Promise]"; |
||
1997 | }; |
||
1998 | |||
1999 | Promise.prototype.caught = Promise.prototype["catch"] = |
||
2000 | function Promise$catch(fn) { |
||
2001 | var len = arguments.length; |
||
2002 | if (len > 1) { |
||
2003 | var catchInstances = new Array(len - 1), |
||
2004 | j = 0, i; |
||
2005 | for (i = 0; i < len - 1; ++i) { |
||
2006 | var item = arguments[i]; |
||
2007 | if (typeof item === "function") { |
||
2008 | catchInstances[j++] = item; |
||
2009 | } else { |
||
2010 | var catchFilterTypeError = |
||
2011 | new TypeError( |
||
2012 | "A catch filter must be an error constructor " |
||
2013 | + "or a filter function"); |
||
2014 | |||
2015 | this._attachExtraTrace(catchFilterTypeError); |
||
2016 | async.invoke(this._reject, this, catchFilterTypeError); |
||
2017 | return; |
||
2018 | } |
||
2019 | } |
||
2020 | catchInstances.length = j; |
||
2021 | fn = arguments[i]; |
||
2022 | |||
2023 | this._resetTrace(); |
||
2024 | var catchFilter = new CatchFilter(catchInstances, fn, this); |
||
2025 | return this._then(void 0, catchFilter.doFilter, void 0, |
||
2026 | catchFilter, void 0); |
||
2027 | } |
||
2028 | return this._then(void 0, fn, void 0, void 0, void 0); |
||
2029 | }; |
||
2030 | |||
2031 | Promise.prototype.then = |
||
2032 | function Promise$then(didFulfill, didReject, didProgress) { |
||
2033 | return this._then(didFulfill, didReject, didProgress, |
||
2034 | void 0, void 0); |
||
2035 | }; |
||
2036 | |||
2037 | |||
2038 | Promise.prototype.done = |
||
2039 | function Promise$done(didFulfill, didReject, didProgress) { |
||
2040 | var promise = this._then(didFulfill, didReject, didProgress, |
||
2041 | void 0, void 0); |
||
2042 | promise._setIsFinal(); |
||
2043 | }; |
||
2044 | |||
2045 | Promise.prototype.spread = function Promise$spread(didFulfill, didReject) { |
||
2046 | return this._then(didFulfill, didReject, void 0, |
||
2047 | APPLY, void 0); |
||
2048 | }; |
||
2049 | |||
2050 | Promise.prototype.isCancellable = function Promise$isCancellable() { |
||
2051 | return !this.isResolved() && |
||
2052 | this._cancellable(); |
||
2053 | }; |
||
2054 | |||
2055 | Promise.prototype.toJSON = function Promise$toJSON() { |
||
2056 | var ret = { |
||
2057 | isFulfilled: false, |
||
2058 | isRejected: false, |
||
2059 | fulfillmentValue: void 0, |
||
2060 | rejectionReason: void 0 |
||
2061 | }; |
||
2062 | if (this.isFulfilled()) { |
||
2063 | ret.fulfillmentValue = this._settledValue; |
||
2064 | ret.isFulfilled = true; |
||
2065 | } else if (this.isRejected()) { |
||
2066 | ret.rejectionReason = this._settledValue; |
||
2067 | ret.isRejected = true; |
||
2068 | } |
||
2069 | return ret; |
||
2070 | }; |
||
2071 | |||
2072 | Promise.prototype.all = function Promise$all() { |
||
2073 | return new PromiseArray(this).promise(); |
||
2074 | }; |
||
2075 | |||
2076 | |||
2077 | Promise.is = function Promise$Is(val) { |
||
2078 | return val instanceof Promise; |
||
2079 | }; |
||
2080 | |||
2081 | Promise.all = function Promise$All(promises) { |
||
2082 | return new PromiseArray(promises).promise(); |
||
2083 | }; |
||
2084 | |||
2085 | Promise.prototype.error = function Promise$_error(fn) { |
||
2086 | return this.caught(originatesFromRejection, fn); |
||
2087 | }; |
||
2088 | |||
2089 | Promise.prototype._resolveFromSyncValue = |
||
2090 | function Promise$_resolveFromSyncValue(value) { |
||
2091 | if (value === errorObj) { |
||
2092 | this._cleanValues(); |
||
2093 | this._setRejected(); |
||
2094 | this._settledValue = value.e; |
||
2095 | this._ensurePossibleRejectionHandled(); |
||
2096 | } else { |
||
2097 | var maybePromise = cast(value, void 0); |
||
2098 | if (maybePromise instanceof Promise) { |
||
2099 | this._follow(maybePromise); |
||
2100 | } else { |
||
2101 | this._cleanValues(); |
||
2102 | this._setFulfilled(); |
||
2103 | this._settledValue = value; |
||
2104 | } |
||
2105 | } |
||
2106 | }; |
||
2107 | |||
2108 | Promise.method = function Promise$_Method(fn) { |
||
2109 | if (typeof fn !== "function") { |
||
2110 | throw new TypeError("fn must be a function"); |
||
2111 | } |
||
2112 | return function Promise$_method() { |
||
2113 | var value; |
||
2114 | switch(arguments.length) { |
||
2115 | case 0: value = tryCatch1(fn, this, void 0); break; |
||
2116 | case 1: value = tryCatch1(fn, this, arguments[0]); break; |
||
2117 | case 2: value = tryCatch2(fn, this, arguments[0], arguments[1]); break; |
||
2118 | default: |
||
2119 | var $_len = arguments.length;var args = new Array($_len); for(var $_i = 0; $_i < $_len; ++$_i) {args[$_i] = arguments[$_i];} |
||
2120 | value = tryCatchApply(fn, args, this); break; |
||
2121 | } |
||
2122 | var ret = new Promise(INTERNAL); |
||
2123 | ret._setTrace(void 0); |
||
2124 | ret._resolveFromSyncValue(value); |
||
2125 | return ret; |
||
2126 | }; |
||
2127 | }; |
||
2128 | |||
2129 | Promise.attempt = Promise["try"] = function Promise$_Try(fn, args, ctx) { |
||
2130 | if (typeof fn !== "function") { |
||
2131 | return apiRejection("fn must be a function"); |
||
2132 | } |
||
2133 | var value = isArray(args) |
||
2134 | ? tryCatchApply(fn, args, ctx) |
||
2135 | : tryCatch1(fn, ctx, args); |
||
2136 | |||
2137 | var ret = new Promise(INTERNAL); |
||
2138 | ret._setTrace(void 0); |
||
2139 | ret._resolveFromSyncValue(value); |
||
2140 | return ret; |
||
2141 | }; |
||
2142 | |||
2143 | Promise.defer = Promise.pending = function Promise$Defer() { |
||
2144 | var promise = new Promise(INTERNAL); |
||
2145 | promise._setTrace(void 0); |
||
2146 | return new PromiseResolver(promise); |
||
2147 | }; |
||
2148 | |||
2149 | Promise.bind = function Promise$Bind(thisArg) { |
||
2150 | var ret = new Promise(INTERNAL); |
||
2151 | ret._setTrace(void 0); |
||
2152 | ret._setFulfilled(); |
||
2153 | ret._setBoundTo(thisArg); |
||
2154 | return ret; |
||
2155 | }; |
||
2156 | |||
2157 | Promise.cast = function Promise$_Cast(obj) { |
||
2158 | var ret = cast(obj, void 0); |
||
2159 | if (!(ret instanceof Promise)) { |
||
2160 | var val = ret; |
||
2161 | ret = new Promise(INTERNAL); |
||
2162 | ret._setTrace(void 0); |
||
2163 | ret._setFulfilled(); |
||
2164 | ret._cleanValues(); |
||
2165 | ret._settledValue = val; |
||
2166 | } |
||
2167 | return ret; |
||
2168 | }; |
||
2169 | |||
2170 | Promise.resolve = Promise.fulfilled = Promise.cast; |
||
2171 | |||
2172 | Promise.reject = Promise.rejected = function Promise$Reject(reason) { |
||
2173 | var ret = new Promise(INTERNAL); |
||
2174 | ret._setTrace(void 0); |
||
2175 | markAsOriginatingFromRejection(reason); |
||
2176 | ret._cleanValues(); |
||
2177 | ret._setRejected(); |
||
2178 | ret._settledValue = reason; |
||
2179 | if (!canAttach(reason)) { |
||
2180 | var trace = new Error(reason + ""); |
||
2181 | ret._setCarriedStackTrace(trace); |
||
2182 | } |
||
2183 | ret._ensurePossibleRejectionHandled(); |
||
2184 | return ret; |
||
2185 | }; |
||
2186 | |||
2187 | Promise.onPossiblyUnhandledRejection = |
||
2188 | function Promise$OnPossiblyUnhandledRejection(fn) { |
||
2189 | CapturedTrace.possiblyUnhandledRejection = typeof fn === "function" |
||
2190 | ? fn : void 0; |
||
2191 | }; |
||
2192 | |||
2193 | var unhandledRejectionHandled; |
||
2194 | Promise.onUnhandledRejectionHandled = |
||
2195 | function Promise$onUnhandledRejectionHandled(fn) { |
||
2196 | unhandledRejectionHandled = typeof fn === "function" ? fn : void 0; |
||
2197 | }; |
||
2198 | |||
2199 | var debugging = false || !!( |
||
2200 | typeof process !== "undefined" && |
||
2201 | typeof process.execPath === "string" && |
||
2202 | typeof process.env === "object" && |
||
2203 | (process.env["BLUEBIRD_DEBUG"] || |
||
2204 | process.env["NODE_ENV"] === "development") |
||
2205 | ); |
||
2206 | |||
2207 | |||
2208 | Promise.longStackTraces = function Promise$LongStackTraces() { |
||
2209 | if (async.haveItemsQueued() && |
||
2210 | debugging === false |
||
2211 | ) { |
||
2212 | throw new Error("cannot enable long stack traces after promises have been created"); |
||
2213 | } |
||
2214 | debugging = CapturedTrace.isSupported(); |
||
2215 | }; |
||
2216 | |||
2217 | Promise.hasLongStackTraces = function Promise$HasLongStackTraces() { |
||
2218 | return debugging && CapturedTrace.isSupported(); |
||
2219 | }; |
||
2220 | |||
2221 | Promise.prototype._then = |
||
2222 | function Promise$_then( |
||
2223 | didFulfill, |
||
2224 | didReject, |
||
2225 | didProgress, |
||
2226 | receiver, |
||
2227 | internalData |
||
2228 | ) { |
||
2229 | var haveInternalData = internalData !== void 0; |
||
2230 | var ret = haveInternalData ? internalData : new Promise(INTERNAL); |
||
2231 | |||
2232 | if (!haveInternalData) { |
||
2233 | if (debugging) { |
||
2234 | var haveSameContext = this._peekContext() === this._traceParent; |
||
2235 | ret._traceParent = haveSameContext ? this._traceParent : this; |
||
2236 | } |
||
2237 | ret._propagateFrom(this, 7); |
||
2238 | } |
||
2239 | |||
2240 | var callbackIndex = |
||
2241 | this._addCallbacks(didFulfill, didReject, didProgress, ret, receiver); |
||
2242 | |||
2243 | if (this.isResolved()) { |
||
2244 | async.invoke(this._queueSettleAt, this, callbackIndex); |
||
2245 | } |
||
2246 | |||
2247 | return ret; |
||
2248 | }; |
||
2249 | |||
2250 | Promise.prototype._length = function Promise$_length() { |
||
2251 | return this._bitField & 262143; |
||
2252 | }; |
||
2253 | |||
2254 | Promise.prototype._isFollowingOrFulfilledOrRejected = |
||
2255 | function Promise$_isFollowingOrFulfilledOrRejected() { |
||
2256 | return (this._bitField & 939524096) > 0; |
||
2257 | }; |
||
2258 | |||
2259 | Promise.prototype._isFollowing = function Promise$_isFollowing() { |
||
2260 | return (this._bitField & 536870912) === 536870912; |
||
2261 | }; |
||
2262 | |||
2263 | Promise.prototype._setLength = function Promise$_setLength(len) { |
||
2264 | this._bitField = (this._bitField & -262144) | |
||
2265 | (len & 262143); |
||
2266 | }; |
||
2267 | |||
2268 | Promise.prototype._setFulfilled = function Promise$_setFulfilled() { |
||
2269 | this._bitField = this._bitField | 268435456; |
||
2270 | }; |
||
2271 | |||
2272 | Promise.prototype._setRejected = function Promise$_setRejected() { |
||
2273 | this._bitField = this._bitField | 134217728; |
||
2274 | }; |
||
2275 | |||
2276 | Promise.prototype._setFollowing = function Promise$_setFollowing() { |
||
2277 | this._bitField = this._bitField | 536870912; |
||
2278 | }; |
||
2279 | |||
2280 | Promise.prototype._setIsFinal = function Promise$_setIsFinal() { |
||
2281 | this._bitField = this._bitField | 33554432; |
||
2282 | }; |
||
2283 | |||
2284 | Promise.prototype._isFinal = function Promise$_isFinal() { |
||
2285 | return (this._bitField & 33554432) > 0; |
||
2286 | }; |
||
2287 | |||
2288 | Promise.prototype._cancellable = function Promise$_cancellable() { |
||
2289 | return (this._bitField & 67108864) > 0; |
||
2290 | }; |
||
2291 | |||
2292 | Promise.prototype._setCancellable = function Promise$_setCancellable() { |
||
2293 | this._bitField = this._bitField | 67108864; |
||
2294 | }; |
||
2295 | |||
2296 | Promise.prototype._unsetCancellable = function Promise$_unsetCancellable() { |
||
2297 | this._bitField = this._bitField & (~67108864); |
||
2298 | }; |
||
2299 | |||
2300 | Promise.prototype._setRejectionIsUnhandled = |
||
2301 | function Promise$_setRejectionIsUnhandled() { |
||
2302 | this._bitField = this._bitField | 2097152; |
||
2303 | }; |
||
2304 | |||
2305 | Promise.prototype._unsetRejectionIsUnhandled = |
||
2306 | function Promise$_unsetRejectionIsUnhandled() { |
||
2307 | this._bitField = this._bitField & (~2097152); |
||
2308 | if (this._isUnhandledRejectionNotified()) { |
||
2309 | this._unsetUnhandledRejectionIsNotified(); |
||
2310 | this._notifyUnhandledRejectionIsHandled(); |
||
2311 | } |
||
2312 | }; |
||
2313 | |||
2314 | Promise.prototype._isRejectionUnhandled = |
||
2315 | function Promise$_isRejectionUnhandled() { |
||
2316 | return (this._bitField & 2097152) > 0; |
||
2317 | }; |
||
2318 | |||
2319 | Promise.prototype._setUnhandledRejectionIsNotified = |
||
2320 | function Promise$_setUnhandledRejectionIsNotified() { |
||
2321 | this._bitField = this._bitField | 524288; |
||
2322 | }; |
||
2323 | |||
2324 | Promise.prototype._unsetUnhandledRejectionIsNotified = |
||
2325 | function Promise$_unsetUnhandledRejectionIsNotified() { |
||
2326 | this._bitField = this._bitField & (~524288); |
||
2327 | }; |
||
2328 | |||
2329 | Promise.prototype._isUnhandledRejectionNotified = |
||
2330 | function Promise$_isUnhandledRejectionNotified() { |
||
2331 | return (this._bitField & 524288) > 0; |
||
2332 | }; |
||
2333 | |||
2334 | Promise.prototype._setCarriedStackTrace = |
||
2335 | function Promise$_setCarriedStackTrace(capturedTrace) { |
||
2336 | this._bitField = this._bitField | 1048576; |
||
2337 | this._fulfillmentHandler0 = capturedTrace; |
||
2338 | }; |
||
2339 | |||
2340 | Promise.prototype._unsetCarriedStackTrace = |
||
2341 | function Promise$_unsetCarriedStackTrace() { |
||
2342 | this._bitField = this._bitField & (~1048576); |
||
2343 | this._fulfillmentHandler0 = void 0; |
||
2344 | }; |
||
2345 | |||
2346 | Promise.prototype._isCarryingStackTrace = |
||
2347 | function Promise$_isCarryingStackTrace() { |
||
2348 | return (this._bitField & 1048576) > 0; |
||
2349 | }; |
||
2350 | |||
2351 | Promise.prototype._getCarriedStackTrace = |
||
2352 | function Promise$_getCarriedStackTrace() { |
||
2353 | return this._isCarryingStackTrace() |
||
2354 | ? this._fulfillmentHandler0 |
||
2355 | : void 0; |
||
2356 | }; |
||
2357 | |||
2358 | Promise.prototype._receiverAt = function Promise$_receiverAt(index) { |
||
2359 | var ret = index === 0 |
||
2360 | ? this._receiver0 |
||
2361 | : this[(index << 2) + index - 5 + 4]; |
||
2362 | if (this._isBound() && ret === void 0) { |
||
2363 | return this._boundTo; |
||
2364 | } |
||
2365 | return ret; |
||
2366 | }; |
||
2367 | |||
2368 | Promise.prototype._promiseAt = function Promise$_promiseAt(index) { |
||
2369 | return index === 0 |
||
2370 | ? this._promise0 |
||
2371 | : this[(index << 2) + index - 5 + 3]; |
||
2372 | }; |
||
2373 | |||
2374 | Promise.prototype._fulfillmentHandlerAt = |
||
2375 | function Promise$_fulfillmentHandlerAt(index) { |
||
2376 | return index === 0 |
||
2377 | ? this._fulfillmentHandler0 |
||
2378 | : this[(index << 2) + index - 5 + 0]; |
||
2379 | }; |
||
2380 | |||
2381 | Promise.prototype._rejectionHandlerAt = |
||
2382 | function Promise$_rejectionHandlerAt(index) { |
||
2383 | return index === 0 |
||
2384 | ? this._rejectionHandler0 |
||
2385 | : this[(index << 2) + index - 5 + 1]; |
||
2386 | }; |
||
2387 | |||
2388 | Promise.prototype._addCallbacks = function Promise$_addCallbacks( |
||
2389 | fulfill, |
||
2390 | reject, |
||
2391 | progress, |
||
2392 | promise, |
||
2393 | receiver |
||
2394 | ) { |
||
2395 | var index = this._length(); |
||
2396 | |||
2397 | if (index >= 262143 - 5) { |
||
2398 | index = 0; |
||
2399 | this._setLength(0); |
||
2400 | } |
||
2401 | |||
2402 | if (index === 0) { |
||
2403 | this._promise0 = promise; |
||
2404 | if (receiver !== void 0) this._receiver0 = receiver; |
||
2405 | if (typeof fulfill === "function" && !this._isCarryingStackTrace()) |
||
2406 | this._fulfillmentHandler0 = fulfill; |
||
2407 | if (typeof reject === "function") this._rejectionHandler0 = reject; |
||
2408 | if (typeof progress === "function") this._progressHandler0 = progress; |
||
2409 | } else { |
||
2410 | var base = (index << 2) + index - 5; |
||
2411 | this[base + 3] = promise; |
||
2412 | this[base + 4] = receiver; |
||
2413 | this[base + 0] = typeof fulfill === "function" |
||
2414 | ? fulfill : void 0; |
||
2415 | this[base + 1] = typeof reject === "function" |
||
2416 | ? reject : void 0; |
||
2417 | this[base + 2] = typeof progress === "function" |
||
2418 | ? progress : void 0; |
||
2419 | } |
||
2420 | this._setLength(index + 1); |
||
2421 | return index; |
||
2422 | }; |
||
2423 | |||
2424 | Promise.prototype._setProxyHandlers = |
||
2425 | function Promise$_setProxyHandlers(receiver, promiseSlotValue) { |
||
2426 | var index = this._length(); |
||
2427 | |||
2428 | if (index >= 262143 - 5) { |
||
2429 | index = 0; |
||
2430 | this._setLength(0); |
||
2431 | } |
||
2432 | if (index === 0) { |
||
2433 | this._promise0 = promiseSlotValue; |
||
2434 | this._receiver0 = receiver; |
||
2435 | } else { |
||
2436 | var base = (index << 2) + index - 5; |
||
2437 | this[base + 3] = promiseSlotValue; |
||
2438 | this[base + 4] = receiver; |
||
2439 | this[base + 0] = |
||
2440 | this[base + 1] = |
||
2441 | this[base + 2] = void 0; |
||
2442 | } |
||
2443 | this._setLength(index + 1); |
||
2444 | }; |
||
2445 | |||
2446 | Promise.prototype._proxyPromiseArray = |
||
2447 | function Promise$_proxyPromiseArray(promiseArray, index) { |
||
2448 | this._setProxyHandlers(promiseArray, index); |
||
2449 | }; |
||
2450 | |||
2451 | Promise.prototype._proxyPromise = function Promise$_proxyPromise(promise) { |
||
2452 | promise._setProxied(); |
||
2453 | this._setProxyHandlers(promise, -1); |
||
2454 | }; |
||
2455 | |||
2456 | Promise.prototype._setBoundTo = function Promise$_setBoundTo(obj) { |
||
2457 | if (obj !== void 0) { |
||
2458 | this._bitField = this._bitField | 8388608; |
||
2459 | this._boundTo = obj; |
||
2460 | } else { |
||
2461 | this._bitField = this._bitField & (~8388608); |
||
2462 | } |
||
2463 | }; |
||
2464 | |||
2465 | Promise.prototype._isBound = function Promise$_isBound() { |
||
2466 | return (this._bitField & 8388608) === 8388608; |
||
2467 | }; |
||
2468 | |||
2469 | Promise.prototype._resolveFromResolver = |
||
2470 | function Promise$_resolveFromResolver(resolver) { |
||
2471 | var promise = this; |
||
2472 | this._setTrace(void 0); |
||
2473 | this._pushContext(); |
||
2474 | |||
2475 | function Promise$_resolver(val) { |
||
2476 | if (promise._tryFollow(val)) { |
||
2477 | return; |
||
2478 | } |
||
2479 | promise._fulfill(val); |
||
2480 | } |
||
2481 | function Promise$_rejecter(val) { |
||
2482 | var trace = canAttach(val) ? val : new Error(val + ""); |
||
2483 | promise._attachExtraTrace(trace); |
||
2484 | markAsOriginatingFromRejection(val); |
||
2485 | promise._reject(val, trace === val ? void 0 : trace); |
||
2486 | } |
||
2487 | var r = tryCatch2(resolver, void 0, Promise$_resolver, Promise$_rejecter); |
||
2488 | this._popContext(); |
||
2489 | |||
2490 | if (r !== void 0 && r === errorObj) { |
||
2491 | var e = r.e; |
||
2492 | var trace = canAttach(e) ? e : new Error(e + ""); |
||
2493 | promise._reject(e, trace); |
||
2494 | } |
||
2495 | }; |
||
2496 | |||
2497 | Promise.prototype._spreadSlowCase = |
||
2498 | function Promise$_spreadSlowCase(targetFn, promise, values, boundTo) { |
||
2499 | var promiseForAll = new PromiseArray(values).promise(); |
||
2500 | var promise2 = promiseForAll._then(function() { |
||
2501 | return targetFn.apply(boundTo, arguments); |
||
2502 | }, void 0, void 0, APPLY, void 0); |
||
2503 | promise._follow(promise2); |
||
2504 | }; |
||
2505 | |||
2506 | Promise.prototype._callSpread = |
||
2507 | function Promise$_callSpread(handler, promise, value) { |
||
2508 | var boundTo = this._boundTo; |
||
2509 | if (isArray(value)) { |
||
2510 | for (var i = 0, len = value.length; i < len; ++i) { |
||
2511 | if (cast(value[i], void 0) instanceof Promise) { |
||
2512 | this._spreadSlowCase(handler, promise, value, boundTo); |
||
2513 | return; |
||
2514 | } |
||
2515 | } |
||
2516 | } |
||
2517 | promise._pushContext(); |
||
2518 | return tryCatchApply(handler, value, boundTo); |
||
2519 | }; |
||
2520 | |||
2521 | Promise.prototype._callHandler = |
||
2522 | function Promise$_callHandler( |
||
2523 | handler, receiver, promise, value) { |
||
2524 | var x; |
||
2525 | if (receiver === APPLY && !this.isRejected()) { |
||
2526 | x = this._callSpread(handler, promise, value); |
||
2527 | } else { |
||
2528 | promise._pushContext(); |
||
2529 | x = tryCatch1(handler, receiver, value); |
||
2530 | } |
||
2531 | promise._popContext(); |
||
2532 | return x; |
||
2533 | }; |
||
2534 | |||
2535 | Promise.prototype._settlePromiseFromHandler = |
||
2536 | function Promise$_settlePromiseFromHandler( |
||
2537 | handler, receiver, value, promise |
||
2538 | ) { |
||
2539 | if (!(promise instanceof Promise)) { |
||
2540 | handler.call(receiver, value, promise); |
||
2541 | return; |
||
2542 | } |
||
2543 | var x = this._callHandler(handler, receiver, promise, value); |
||
2544 | if (promise._isFollowing()) return; |
||
2545 | |||
2546 | if (x === errorObj || x === promise || x === NEXT_FILTER) { |
||
2547 | var err = x === promise |
||
2548 | ? makeSelfResolutionError() |
||
2549 | : x.e; |
||
2550 | var trace = canAttach(err) ? err : new Error(err + ""); |
||
2551 | if (x !== NEXT_FILTER) promise._attachExtraTrace(trace); |
||
2552 | promise._rejectUnchecked(err, trace); |
||
2553 | } else { |
||
2554 | var castValue = cast(x, promise); |
||
2555 | if (castValue instanceof Promise) { |
||
2556 | if (castValue.isRejected() && |
||
2557 | !castValue._isCarryingStackTrace() && |
||
2558 | !canAttach(castValue._settledValue)) { |
||
2559 | var trace = new Error(castValue._settledValue + ""); |
||
2560 | promise._attachExtraTrace(trace); |
||
2561 | castValue._setCarriedStackTrace(trace); |
||
2562 | } |
||
2563 | promise._follow(castValue); |
||
2564 | promise._propagateFrom(castValue, 1); |
||
2565 | } else { |
||
2566 | promise._fulfillUnchecked(x); |
||
2567 | } |
||
2568 | } |
||
2569 | }; |
||
2570 | |||
2571 | Promise.prototype._follow = |
||
2572 | function Promise$_follow(promise) { |
||
2573 | this._setFollowing(); |
||
2574 | |||
2575 | if (promise.isPending()) { |
||
2576 | this._propagateFrom(promise, 1); |
||
2577 | promise._proxyPromise(this); |
||
2578 | } else if (promise.isFulfilled()) { |
||
2579 | this._fulfillUnchecked(promise._settledValue); |
||
2580 | } else { |
||
2581 | this._rejectUnchecked(promise._settledValue, |
||
2582 | promise._getCarriedStackTrace()); |
||
2583 | } |
||
2584 | |||
2585 | if (promise._isRejectionUnhandled()) promise._unsetRejectionIsUnhandled(); |
||
2586 | |||
2587 | if (debugging && |
||
2588 | promise._traceParent == null) { |
||
2589 | promise._traceParent = this; |
||
2590 | } |
||
2591 | }; |
||
2592 | |||
2593 | Promise.prototype._tryFollow = |
||
2594 | function Promise$_tryFollow(value) { |
||
2595 | if (this._isFollowingOrFulfilledOrRejected() || |
||
2596 | value === this) { |
||
2597 | return false; |
||
2598 | } |
||
2599 | var maybePromise = cast(value, void 0); |
||
2600 | if (!(maybePromise instanceof Promise)) { |
||
2601 | return false; |
||
2602 | } |
||
2603 | this._follow(maybePromise); |
||
2604 | return true; |
||
2605 | }; |
||
2606 | |||
2607 | Promise.prototype._resetTrace = function Promise$_resetTrace() { |
||
2608 | if (debugging) { |
||
2609 | this._trace = new CapturedTrace(this._peekContext() === void 0); |
||
2610 | } |
||
2611 | }; |
||
2612 | |||
2613 | Promise.prototype._setTrace = function Promise$_setTrace(parent) { |
||
2614 | if (debugging) { |
||
2615 | var context = this._peekContext(); |
||
2616 | this._traceParent = context; |
||
2617 | var isTopLevel = context === void 0; |
||
2618 | if (parent !== void 0 && |
||
2619 | parent._traceParent === context) { |
||
2620 | this._trace = parent._trace; |
||
2621 | } else { |
||
2622 | this._trace = new CapturedTrace(isTopLevel); |
||
2623 | } |
||
2624 | } |
||
2625 | return this; |
||
2626 | }; |
||
2627 | |||
2628 | Promise.prototype._attachExtraTrace = |
||
2629 | function Promise$_attachExtraTrace(error) { |
||
2630 | if (debugging) { |
||
2631 | var promise = this; |
||
2632 | var stack = error.stack; |
||
2633 | stack = typeof stack === "string" ? stack.split("\n") : []; |
||
2634 | CapturedTrace.protectErrorMessageNewlines(stack); |
||
2635 | var headerLineCount = 1; |
||
2636 | var combinedTraces = 1; |
||
2637 | while(promise != null && |
||
2638 | promise._trace != null) { |
||
2639 | stack = CapturedTrace.combine( |
||
2640 | stack, |
||
2641 | promise._trace.stack.split("\n") |
||
2642 | ); |
||
2643 | promise = promise._traceParent; |
||
2644 | combinedTraces++; |
||
2645 | } |
||
2646 | |||
2647 | var stackTraceLimit = Error.stackTraceLimit || 10; |
||
2648 | var max = (stackTraceLimit + headerLineCount) * combinedTraces; |
||
2649 | var len = stack.length; |
||
2650 | if (len > max) { |
||
2651 | stack.length = max; |
||
2652 | } |
||
2653 | |||
2654 | if (len > 0) |
||
2655 | stack[0] = stack[0].split("\u0002\u0000\u0001").join("\n"); |
||
2656 | |||
2657 | if (stack.length <= headerLineCount) { |
||
2658 | error.stack = "(No stack trace)"; |
||
2659 | } else { |
||
2660 | error.stack = stack.join("\n"); |
||
2661 | } |
||
2662 | } |
||
2663 | }; |
||
2664 | |||
2665 | Promise.prototype._cleanValues = function Promise$_cleanValues() { |
||
2666 | if (this._cancellable()) { |
||
2667 | this._cancellationParent = void 0; |
||
2668 | } |
||
2669 | }; |
||
2670 | |||
2671 | Promise.prototype._propagateFrom = |
||
2672 | function Promise$_propagateFrom(parent, flags) { |
||
2673 | if ((flags & 1) > 0 && parent._cancellable()) { |
||
2674 | this._setCancellable(); |
||
2675 | this._cancellationParent = parent; |
||
2676 | } |
||
2677 | if ((flags & 4) > 0) { |
||
2678 | this._setBoundTo(parent._boundTo); |
||
2679 | } |
||
2680 | if ((flags & 2) > 0) { |
||
2681 | this._setTrace(parent); |
||
2682 | } |
||
2683 | }; |
||
2684 | |||
2685 | Promise.prototype._fulfill = function Promise$_fulfill(value) { |
||
2686 | if (this._isFollowingOrFulfilledOrRejected()) return; |
||
2687 | this._fulfillUnchecked(value); |
||
2688 | }; |
||
2689 | |||
2690 | Promise.prototype._reject = |
||
2691 | function Promise$_reject(reason, carriedStackTrace) { |
||
2692 | if (this._isFollowingOrFulfilledOrRejected()) return; |
||
2693 | this._rejectUnchecked(reason, carriedStackTrace); |
||
2694 | }; |
||
2695 | |||
2696 | Promise.prototype._settlePromiseAt = function Promise$_settlePromiseAt(index) { |
||
2697 | var handler = this.isFulfilled() |
||
2698 | ? this._fulfillmentHandlerAt(index) |
||
2699 | : this._rejectionHandlerAt(index); |
||
2700 | |||
2701 | var value = this._settledValue; |
||
2702 | var receiver = this._receiverAt(index); |
||
2703 | var promise = this._promiseAt(index); |
||
2704 | |||
2705 | if (typeof handler === "function") { |
||
2706 | this._settlePromiseFromHandler(handler, receiver, value, promise); |
||
2707 | } else { |
||
2708 | var done = false; |
||
2709 | var isFulfilled = this.isFulfilled(); |
||
2710 | if (receiver !== void 0) { |
||
2711 | if (receiver instanceof Promise && |
||
2712 | receiver._isProxied()) { |
||
2713 | receiver._unsetProxied(); |
||
2714 | |||
2715 | if (isFulfilled) receiver._fulfillUnchecked(value); |
||
2716 | else receiver._rejectUnchecked(value, |
||
2717 | this._getCarriedStackTrace()); |
||
2718 | done = true; |
||
2719 | } else if (receiver instanceof PromiseArray) { |
||
2720 | if (isFulfilled) receiver._promiseFulfilled(value, promise); |
||
2721 | else receiver._promiseRejected(value, promise); |
||
2722 | done = true; |
||
2723 | } |
||
2724 | } |
||
2725 | |||
2726 | if (!done) { |
||
2727 | if (isFulfilled) promise._fulfill(value); |
||
2728 | else promise._reject(value, this._getCarriedStackTrace()); |
||
2729 | } |
||
2730 | } |
||
2731 | |||
2732 | if (index >= 256) { |
||
2733 | this._queueGC(); |
||
2734 | } |
||
2735 | }; |
||
2736 | |||
2737 | Promise.prototype._isProxied = function Promise$_isProxied() { |
||
2738 | return (this._bitField & 4194304) === 4194304; |
||
2739 | }; |
||
2740 | |||
2741 | Promise.prototype._setProxied = function Promise$_setProxied() { |
||
2742 | this._bitField = this._bitField | 4194304; |
||
2743 | }; |
||
2744 | |||
2745 | Promise.prototype._unsetProxied = function Promise$_unsetProxied() { |
||
2746 | this._bitField = this._bitField & (~4194304); |
||
2747 | }; |
||
2748 | |||
2749 | Promise.prototype._isGcQueued = function Promise$_isGcQueued() { |
||
2750 | return (this._bitField & -1073741824) === -1073741824; |
||
2751 | }; |
||
2752 | |||
2753 | Promise.prototype._setGcQueued = function Promise$_setGcQueued() { |
||
2754 | this._bitField = this._bitField | -1073741824; |
||
2755 | }; |
||
2756 | |||
2757 | Promise.prototype._unsetGcQueued = function Promise$_unsetGcQueued() { |
||
2758 | this._bitField = this._bitField & (~-1073741824); |
||
2759 | }; |
||
2760 | |||
2761 | Promise.prototype._queueGC = function Promise$_queueGC() { |
||
2762 | if (this._isGcQueued()) return; |
||
2763 | this._setGcQueued(); |
||
2764 | async.invokeLater(this._gc, this, void 0); |
||
2765 | }; |
||
2766 | |||
2767 | Promise.prototype._gc = function Promise$gc() { |
||
2768 | var len = this._length() * 5; |
||
2769 | for (var i = 0; i < len; i++) { |
||
2770 | delete this[i]; |
||
2771 | } |
||
2772 | this._setLength(0); |
||
2773 | this._unsetGcQueued(); |
||
2774 | }; |
||
2775 | |||
2776 | Promise.prototype._queueSettleAt = function Promise$_queueSettleAt(index) { |
||
2777 | if (this._isRejectionUnhandled()) this._unsetRejectionIsUnhandled(); |
||
2778 | async.invoke(this._settlePromiseAt, this, index); |
||
2779 | }; |
||
2780 | |||
2781 | Promise.prototype._fulfillUnchecked = |
||
2782 | function Promise$_fulfillUnchecked(value) { |
||
2783 | if (!this.isPending()) return; |
||
2784 | if (value === this) { |
||
2785 | var err = makeSelfResolutionError(); |
||
2786 | this._attachExtraTrace(err); |
||
2787 | return this._rejectUnchecked(err, void 0); |
||
2788 | } |
||
2789 | this._cleanValues(); |
||
2790 | this._setFulfilled(); |
||
2791 | this._settledValue = value; |
||
2792 | var len = this._length(); |
||
2793 | |||
2794 | if (len > 0) { |
||
2795 | async.invoke(this._settlePromises, this, len); |
||
2796 | } |
||
2797 | }; |
||
2798 | |||
2799 | Promise.prototype._rejectUncheckedCheckError = |
||
2800 | function Promise$_rejectUncheckedCheckError(reason) { |
||
2801 | var trace = canAttach(reason) ? reason : new Error(reason + ""); |
||
2802 | this._rejectUnchecked(reason, trace === reason ? void 0 : trace); |
||
2803 | }; |
||
2804 | |||
2805 | Promise.prototype._rejectUnchecked = |
||
2806 | function Promise$_rejectUnchecked(reason, trace) { |
||
2807 | if (!this.isPending()) return; |
||
2808 | if (reason === this) { |
||
2809 | var err = makeSelfResolutionError(); |
||
2810 | this._attachExtraTrace(err); |
||
2811 | return this._rejectUnchecked(err); |
||
2812 | } |
||
2813 | this._cleanValues(); |
||
2814 | this._setRejected(); |
||
2815 | this._settledValue = reason; |
||
2816 | |||
2817 | if (this._isFinal()) { |
||
2818 | async.invokeLater(thrower, void 0, trace === void 0 ? reason : trace); |
||
2819 | return; |
||
2820 | } |
||
2821 | var len = this._length(); |
||
2822 | |||
2823 | if (trace !== void 0) this._setCarriedStackTrace(trace); |
||
2824 | |||
2825 | if (len > 0) { |
||
2826 | async.invoke(this._rejectPromises, this, null); |
||
2827 | } else { |
||
2828 | this._ensurePossibleRejectionHandled(); |
||
2829 | } |
||
2830 | }; |
||
2831 | |||
2832 | Promise.prototype._rejectPromises = function Promise$_rejectPromises() { |
||
2833 | this._settlePromises(); |
||
2834 | this._unsetCarriedStackTrace(); |
||
2835 | }; |
||
2836 | |||
2837 | Promise.prototype._settlePromises = function Promise$_settlePromises() { |
||
2838 | var len = this._length(); |
||
2839 | for (var i = 0; i < len; i++) { |
||
2840 | this._settlePromiseAt(i); |
||
2841 | } |
||
2842 | }; |
||
2843 | |||
2844 | Promise.prototype._ensurePossibleRejectionHandled = |
||
2845 | function Promise$_ensurePossibleRejectionHandled() { |
||
2846 | this._setRejectionIsUnhandled(); |
||
2847 | if (CapturedTrace.possiblyUnhandledRejection !== void 0) { |
||
2848 | async.invokeLater(this._notifyUnhandledRejection, this, void 0); |
||
2849 | } |
||
2850 | }; |
||
2851 | |||
2852 | Promise.prototype._notifyUnhandledRejectionIsHandled = |
||
2853 | function Promise$_notifyUnhandledRejectionIsHandled() { |
||
2854 | if (typeof unhandledRejectionHandled === "function") { |
||
2855 | async.invokeLater(unhandledRejectionHandled, void 0, this); |
||
2856 | } |
||
2857 | }; |
||
2858 | |||
2859 | Promise.prototype._notifyUnhandledRejection = |
||
2860 | function Promise$_notifyUnhandledRejection() { |
||
2861 | if (this._isRejectionUnhandled()) { |
||
2862 | var reason = this._settledValue; |
||
2863 | var trace = this._getCarriedStackTrace(); |
||
2864 | |||
2865 | this._setUnhandledRejectionIsNotified(); |
||
2866 | |||
2867 | if (trace !== void 0) { |
||
2868 | this._unsetCarriedStackTrace(); |
||
2869 | reason = trace; |
||
2870 | } |
||
2871 | if (typeof CapturedTrace.possiblyUnhandledRejection === "function") { |
||
2872 | CapturedTrace.possiblyUnhandledRejection(reason, this); |
||
2873 | } |
||
2874 | } |
||
2875 | }; |
||
2876 | |||
2877 | var contextStack = []; |
||
2878 | Promise.prototype._peekContext = function Promise$_peekContext() { |
||
2879 | var lastIndex = contextStack.length - 1; |
||
2880 | if (lastIndex >= 0) { |
||
2881 | return contextStack[lastIndex]; |
||
2882 | } |
||
2883 | return void 0; |
||
2884 | |||
2885 | }; |
||
2886 | |||
2887 | Promise.prototype._pushContext = function Promise$_pushContext() { |
||
2888 | if (!debugging) return; |
||
2889 | contextStack.push(this); |
||
2890 | }; |
||
2891 | |||
2892 | Promise.prototype._popContext = function Promise$_popContext() { |
||
2893 | if (!debugging) return; |
||
2894 | contextStack.pop(); |
||
2895 | }; |
||
2896 | |||
2897 | Promise.noConflict = function Promise$NoConflict() { |
||
2898 | return noConflict(Promise); |
||
2899 | }; |
||
2900 | |||
2901 | Promise.setScheduler = function(fn) { |
||
2902 | if (typeof fn !== "function") throw new TypeError("fn must be a function"); |
||
2903 | async._schedule = fn; |
||
2904 | }; |
||
2905 | |||
2906 | if (!CapturedTrace.isSupported()) { |
||
2907 | Promise.longStackTraces = function(){}; |
||
2908 | debugging = false; |
||
2909 | } |
||
2910 | |||
2911 | Promise._makeSelfResolutionError = makeSelfResolutionError; |
||
2912 | require("./finally.js")(Promise, NEXT_FILTER, cast); |
||
2913 | require("./direct_resolve.js")(Promise); |
||
2914 | require("./synchronous_inspection.js")(Promise); |
||
2915 | require("./join.js")(Promise, PromiseArray, cast, INTERNAL); |
||
2916 | Promise.RangeError = RangeError; |
||
2917 | Promise.CancellationError = CancellationError; |
||
2918 | Promise.TimeoutError = TimeoutError; |
||
2919 | Promise.TypeError = TypeError; |
||
2920 | Promise.OperationalError = OperationalError; |
||
2921 | Promise.RejectionError = OperationalError; |
||
2922 | Promise.AggregateError = errors.AggregateError; |
||
2923 | |||
2924 | util.toFastProperties(Promise); |
||
2925 | util.toFastProperties(Promise.prototype); |
||
2926 | Promise.Promise = Promise; |
||
2927 | require('./timers.js')(Promise,INTERNAL,cast); |
||
2928 | require('./race.js')(Promise,INTERNAL,cast); |
||
2929 | require('./call_get.js')(Promise); |
||
2930 | require('./generators.js')(Promise,apiRejection,INTERNAL,cast); |
||
2931 | require('./map.js')(Promise,PromiseArray,apiRejection,cast,INTERNAL); |
||
2932 | require('./nodeify.js')(Promise); |
||
2933 | require('./promisify.js')(Promise,INTERNAL); |
||
2934 | require('./props.js')(Promise,PromiseArray,cast); |
||
2935 | require('./reduce.js')(Promise,PromiseArray,apiRejection,cast,INTERNAL); |
||
2936 | require('./settle.js')(Promise,PromiseArray); |
||
2937 | require('./some.js')(Promise,PromiseArray,apiRejection); |
||
2938 | require('./progress.js')(Promise,PromiseArray); |
||
2939 | require('./cancel.js')(Promise,INTERNAL); |
||
2940 | require('./filter.js')(Promise,INTERNAL); |
||
2941 | require('./any.js')(Promise,PromiseArray); |
||
2942 | require('./each.js')(Promise,INTERNAL); |
||
2943 | require('./using.js')(Promise,apiRejection,cast); |
||
2944 | |||
2945 | Promise.prototype = Promise.prototype; |
||
2946 | return Promise; |
||
2947 | |||
2948 | }; |
||
2949 | |||
2950 | },{"./any.js":1,"./async.js":2,"./call_get.js":4,"./cancel.js":5,"./captured_trace.js":6,"./catch_filter.js":7,"./direct_resolve.js":8,"./each.js":9,"./errors.js":10,"./errors_api_rejection":11,"./filter.js":13,"./finally.js":14,"./generators.js":15,"./join.js":16,"./map.js":17,"./nodeify.js":18,"./progress.js":19,"./promise_array.js":21,"./promise_resolver.js":22,"./promisify.js":23,"./props.js":24,"./race.js":26,"./reduce.js":27,"./settle.js":29,"./some.js":30,"./synchronous_inspection.js":31,"./thenables.js":32,"./timers.js":33,"./using.js":34,"./util.js":35}],21:[function(require,module,exports){ |
||
2951 | /** |
||
2952 | * Copyright (c) 2014 Petka Antonov |
||
2953 | * |
||
2954 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
||
2955 | * of this software and associated documentation files (the "Software"), to deal |
||
2956 | * in the Software without restriction, including without limitation the rights |
||
2957 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
2958 | * copies of the Software, and to permit persons to whom the Software is |
||
2959 | * furnished to do so, subject to the following conditions:</p> |
||
2960 | * |
||
2961 | * The above copyright notice and this permission notice shall be included in |
||
2962 | * all copies or substantial portions of the Software. |
||
2963 | * |
||
2964 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
2965 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
2966 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||
2967 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
2968 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
2969 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||
2970 | * THE SOFTWARE. |
||
2971 | * |
||
2972 | */ |
||
2973 | "use strict"; |
||
2974 | module.exports = function(Promise, INTERNAL, cast) { |
||
2975 | var canAttach = require("./errors.js").canAttach; |
||
2976 | var util = require("./util.js"); |
||
2977 | var isArray = util.isArray; |
||
2978 | |||
2979 | function toResolutionValue(val) { |
||
2980 | switch(val) { |
||
2981 | case -1: return void 0; |
||
2982 | case -2: return []; |
||
2983 | case -3: return {}; |
||
2984 | } |
||
2985 | } |
||
2986 | |||
2987 | function PromiseArray(values) { |
||
2988 | var promise = this._promise = new Promise(INTERNAL); |
||
2989 | var parent = void 0; |
||
2990 | if (values instanceof Promise) { |
||
2991 | parent = values; |
||
2992 | promise._propagateFrom(parent, 1 | 4); |
||
2993 | } |
||
2994 | promise._setTrace(parent); |
||
2995 | this._values = values; |
||
2996 | this._length = 0; |
||
2997 | this._totalResolved = 0; |
||
2998 | this._init(void 0, -2); |
||
2999 | } |
||
3000 | PromiseArray.prototype.length = function PromiseArray$length() { |
||
3001 | return this._length; |
||
3002 | }; |
||
3003 | |||
3004 | PromiseArray.prototype.promise = function PromiseArray$promise() { |
||
3005 | return this._promise; |
||
3006 | }; |
||
3007 | |||
3008 | PromiseArray.prototype._init = |
||
3009 | function PromiseArray$_init(_, resolveValueIfEmpty) { |
||
3010 | var values = cast(this._values, void 0); |
||
3011 | if (values instanceof Promise) { |
||
3012 | this._values = values; |
||
3013 | values._setBoundTo(this._promise._boundTo); |
||
3014 | if (values.isFulfilled()) { |
||
3015 | values = values._settledValue; |
||
3016 | if (!isArray(values)) { |
||
3017 | var err = new Promise.TypeError("expecting an array, a promise or a thenable"); |
||
3018 | this.__hardReject__(err); |
||
3019 | return; |
||
3020 | } |
||
3021 | } else if (values.isPending()) { |
||
3022 | values._then( |
||
3023 | PromiseArray$_init, |
||
3024 | this._reject, |
||
3025 | void 0, |
||
3026 | this, |
||
3027 | resolveValueIfEmpty |
||
3028 | ); |
||
3029 | return; |
||
3030 | } else { |
||
3031 | values._unsetRejectionIsUnhandled(); |
||
3032 | this._reject(values._settledValue); |
||
3033 | return; |
||
3034 | } |
||
3035 | } else if (!isArray(values)) { |
||
3036 | var err = new Promise.TypeError("expecting an array, a promise or a thenable"); |
||
3037 | this.__hardReject__(err); |
||
3038 | return; |
||
3039 | } |
||
3040 | |||
3041 | if (values.length === 0) { |
||
3042 | if (resolveValueIfEmpty === -5) { |
||
3043 | this._resolveEmptyArray(); |
||
3044 | } |
||
3045 | else { |
||
3046 | this._resolve(toResolutionValue(resolveValueIfEmpty)); |
||
3047 | } |
||
3048 | return; |
||
3049 | } |
||
3050 | var len = this.getActualLength(values.length); |
||
3051 | var newLen = len; |
||
3052 | var newValues = this.shouldCopyValues() ? new Array(len) : this._values; |
||
3053 | var isDirectScanNeeded = false; |
||
3054 | for (var i = 0; i < len; ++i) { |
||
3055 | var maybePromise = cast(values[i], void 0); |
||
3056 | if (maybePromise instanceof Promise) { |
||
3057 | if (maybePromise.isPending()) { |
||
3058 | maybePromise._proxyPromiseArray(this, i); |
||
3059 | } else { |
||
3060 | maybePromise._unsetRejectionIsUnhandled(); |
||
3061 | isDirectScanNeeded = true; |
||
3062 | } |
||
3063 | } else { |
||
3064 | isDirectScanNeeded = true; |
||
3065 | } |
||
3066 | newValues[i] = maybePromise; |
||
3067 | } |
||
3068 | this._values = newValues; |
||
3069 | this._length = newLen; |
||
3070 | if (isDirectScanNeeded) { |
||
3071 | this._scanDirectValues(len); |
||
3072 | } |
||
3073 | }; |
||
3074 | |||
3075 | PromiseArray.prototype._settlePromiseAt = |
||
3076 | function PromiseArray$_settlePromiseAt(index) { |
||
3077 | var value = this._values[index]; |
||
3078 | if (!(value instanceof Promise)) { |
||
3079 | this._promiseFulfilled(value, index); |
||
3080 | } else if (value.isFulfilled()) { |
||
3081 | this._promiseFulfilled(value._settledValue, index); |
||
3082 | } else if (value.isRejected()) { |
||
3083 | this._promiseRejected(value._settledValue, index); |
||
3084 | } |
||
3085 | }; |
||
3086 | |||
3087 | PromiseArray.prototype._scanDirectValues = |
||
3088 | function PromiseArray$_scanDirectValues(len) { |
||
3089 | for (var i = 0; i < len; ++i) { |
||
3090 | if (this._isResolved()) { |
||
3091 | break; |
||
3092 | } |
||
3093 | this._settlePromiseAt(i); |
||
3094 | } |
||
3095 | }; |
||
3096 | |||
3097 | PromiseArray.prototype._isResolved = function PromiseArray$_isResolved() { |
||
3098 | return this._values === null; |
||
3099 | }; |
||
3100 | |||
3101 | PromiseArray.prototype._resolve = function PromiseArray$_resolve(value) { |
||
3102 | this._values = null; |
||
3103 | this._promise._fulfill(value); |
||
3104 | }; |
||
3105 | |||
3106 | PromiseArray.prototype.__hardReject__ = |
||
3107 | PromiseArray.prototype._reject = function PromiseArray$_reject(reason) { |
||
3108 | this._values = null; |
||
3109 | var trace = canAttach(reason) ? reason : new Error(reason + ""); |
||
3110 | this._promise._attachExtraTrace(trace); |
||
3111 | this._promise._reject(reason, trace); |
||
3112 | }; |
||
3113 | |||
3114 | PromiseArray.prototype._promiseProgressed = |
||
3115 | function PromiseArray$_promiseProgressed(progressValue, index) { |
||
3116 | if (this._isResolved()) return; |
||
3117 | this._promise._progress({ |
||
3118 | index: index, |
||
3119 | value: progressValue |
||
3120 | }); |
||
3121 | }; |
||
3122 | |||
3123 | |||
3124 | PromiseArray.prototype._promiseFulfilled = |
||
3125 | function PromiseArray$_promiseFulfilled(value, index) { |
||
3126 | if (this._isResolved()) return; |
||
3127 | this._values[index] = value; |
||
3128 | var totalResolved = ++this._totalResolved; |
||
3129 | if (totalResolved >= this._length) { |
||
3130 | this._resolve(this._values); |
||
3131 | } |
||
3132 | }; |
||
3133 | |||
3134 | PromiseArray.prototype._promiseRejected = |
||
3135 | function PromiseArray$_promiseRejected(reason, index) { |
||
3136 | if (this._isResolved()) return; |
||
3137 | this._totalResolved++; |
||
3138 | this._reject(reason); |
||
3139 | }; |
||
3140 | |||
3141 | PromiseArray.prototype.shouldCopyValues = |
||
3142 | function PromiseArray$_shouldCopyValues() { |
||
3143 | return true; |
||
3144 | }; |
||
3145 | |||
3146 | PromiseArray.prototype.getActualLength = |
||
3147 | function PromiseArray$getActualLength(len) { |
||
3148 | return len; |
||
3149 | }; |
||
3150 | |||
3151 | return PromiseArray; |
||
3152 | }; |
||
3153 | |||
3154 | },{"./errors.js":10,"./util.js":35}],22:[function(require,module,exports){ |
||
3155 | /** |
||
3156 | * Copyright (c) 2014 Petka Antonov |
||
3157 | * |
||
3158 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
||
3159 | * of this software and associated documentation files (the "Software"), to deal |
||
3160 | * in the Software without restriction, including without limitation the rights |
||
3161 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
3162 | * copies of the Software, and to permit persons to whom the Software is |
||
3163 | * furnished to do so, subject to the following conditions:</p> |
||
3164 | * |
||
3165 | * The above copyright notice and this permission notice shall be included in |
||
3166 | * all copies or substantial portions of the Software. |
||
3167 | * |
||
3168 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
3169 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
3170 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||
3171 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
3172 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
3173 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||
3174 | * THE SOFTWARE. |
||
3175 | * |
||
3176 | */ |
||
3177 | "use strict"; |
||
3178 | var util = require("./util.js"); |
||
3179 | var maybeWrapAsError = util.maybeWrapAsError; |
||
3180 | var errors = require("./errors.js"); |
||
3181 | var TimeoutError = errors.TimeoutError; |
||
3182 | var OperationalError = errors.OperationalError; |
||
3183 | var async = require("./async.js"); |
||
3184 | var haveGetters = util.haveGetters; |
||
3185 | var es5 = require("./es5.js"); |
||
3186 | |||
3187 | function isUntypedError(obj) { |
||
3188 | return obj instanceof Error && |
||
3189 | es5.getPrototypeOf(obj) === Error.prototype; |
||
3190 | } |
||
3191 | |||
3192 | function wrapAsOperationalError(obj) { |
||
3193 | var ret; |
||
3194 | if (isUntypedError(obj)) { |
||
3195 | ret = new OperationalError(obj); |
||
3196 | } else { |
||
3197 | ret = obj; |
||
3198 | } |
||
3199 | errors.markAsOriginatingFromRejection(ret); |
||
3200 | return ret; |
||
3201 | } |
||
3202 | |||
3203 | function nodebackForPromise(promise) { |
||
3204 | function PromiseResolver$_callback(err, value) { |
||
3205 | if (promise === null) return; |
||
3206 | |||
3207 | if (err) { |
||
3208 | var wrapped = wrapAsOperationalError(maybeWrapAsError(err)); |
||
3209 | promise._attachExtraTrace(wrapped); |
||
3210 | promise._reject(wrapped); |
||
3211 | } else if (arguments.length > 2) { |
||
3212 | var $_len = arguments.length;var args = new Array($_len - 1); for(var $_i = 1; $_i < $_len; ++$_i) {args[$_i - 1] = arguments[$_i];} |
||
3213 | promise._fulfill(args); |
||
3214 | } else { |
||
3215 | promise._fulfill(value); |
||
3216 | } |
||
3217 | |||
3218 | promise = null; |
||
3219 | } |
||
3220 | return PromiseResolver$_callback; |
||
3221 | } |
||
3222 | |||
3223 | |||
3224 | var PromiseResolver; |
||
3225 | if (!haveGetters) { |
||
3226 | PromiseResolver = function PromiseResolver(promise) { |
||
3227 | this.promise = promise; |
||
3228 | this.asCallback = nodebackForPromise(promise); |
||
3229 | this.callback = this.asCallback; |
||
3230 | }; |
||
3231 | } |
||
3232 | else { |
||
3233 | PromiseResolver = function PromiseResolver(promise) { |
||
3234 | this.promise = promise; |
||
3235 | }; |
||
3236 | } |
||
3237 | if (haveGetters) { |
||
3238 | var prop = { |
||
3239 | get: function() { |
||
3240 | return nodebackForPromise(this.promise); |
||
3241 | } |
||
3242 | }; |
||
3243 | es5.defineProperty(PromiseResolver.prototype, "asCallback", prop); |
||
3244 | es5.defineProperty(PromiseResolver.prototype, "callback", prop); |
||
3245 | } |
||
3246 | |||
3247 | PromiseResolver._nodebackForPromise = nodebackForPromise; |
||
3248 | |||
3249 | PromiseResolver.prototype.toString = function PromiseResolver$toString() { |
||
3250 | return "[object PromiseResolver]"; |
||
3251 | }; |
||
3252 | |||
3253 | PromiseResolver.prototype.resolve = |
||
3254 | PromiseResolver.prototype.fulfill = function PromiseResolver$resolve(value) { |
||
3255 | if (!(this instanceof PromiseResolver)) { |
||
3256 | throw new TypeError("Illegal invocation, resolver resolve/reject must be called within a resolver context. Consider using the promise constructor instead."); |
||
3257 | } |
||
3258 | |||
3259 | var promise = this.promise; |
||
3260 | if (promise._tryFollow(value)) { |
||
3261 | return; |
||
3262 | } |
||
3263 | async.invoke(promise._fulfill, promise, value); |
||
3264 | }; |
||
3265 | |||
3266 | PromiseResolver.prototype.reject = function PromiseResolver$reject(reason) { |
||
3267 | if (!(this instanceof PromiseResolver)) { |
||
3268 | throw new TypeError("Illegal invocation, resolver resolve/reject must be called within a resolver context. Consider using the promise constructor instead."); |
||
3269 | } |
||
3270 | |||
3271 | var promise = this.promise; |
||
3272 | errors.markAsOriginatingFromRejection(reason); |
||
3273 | var trace = errors.canAttach(reason) ? reason : new Error(reason + ""); |
||
3274 | promise._attachExtraTrace(trace); |
||
3275 | async.invoke(promise._reject, promise, reason); |
||
3276 | if (trace !== reason) { |
||
3277 | async.invoke(this._setCarriedStackTrace, this, trace); |
||
3278 | } |
||
3279 | }; |
||
3280 | |||
3281 | PromiseResolver.prototype.progress = |
||
3282 | function PromiseResolver$progress(value) { |
||
3283 | if (!(this instanceof PromiseResolver)) { |
||
3284 | throw new TypeError("Illegal invocation, resolver resolve/reject must be called within a resolver context. Consider using the promise constructor instead."); |
||
3285 | } |
||
3286 | async.invoke(this.promise._progress, this.promise, value); |
||
3287 | }; |
||
3288 | |||
3289 | PromiseResolver.prototype.cancel = function PromiseResolver$cancel() { |
||
3290 | async.invoke(this.promise.cancel, this.promise, void 0); |
||
3291 | }; |
||
3292 | |||
3293 | PromiseResolver.prototype.timeout = function PromiseResolver$timeout() { |
||
3294 | this.reject(new TimeoutError("timeout")); |
||
3295 | }; |
||
3296 | |||
3297 | PromiseResolver.prototype.isResolved = function PromiseResolver$isResolved() { |
||
3298 | return this.promise.isResolved(); |
||
3299 | }; |
||
3300 | |||
3301 | PromiseResolver.prototype.toJSON = function PromiseResolver$toJSON() { |
||
3302 | return this.promise.toJSON(); |
||
3303 | }; |
||
3304 | |||
3305 | PromiseResolver.prototype._setCarriedStackTrace = |
||
3306 | function PromiseResolver$_setCarriedStackTrace(trace) { |
||
3307 | if (this.promise.isRejected()) { |
||
3308 | this.promise._setCarriedStackTrace(trace); |
||
3309 | } |
||
3310 | }; |
||
3311 | |||
3312 | module.exports = PromiseResolver; |
||
3313 | |||
3314 | },{"./async.js":2,"./errors.js":10,"./es5.js":12,"./util.js":35}],23:[function(require,module,exports){ |
||
3315 | /** |
||
3316 | * Copyright (c) 2014 Petka Antonov |
||
3317 | * |
||
3318 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
||
3319 | * of this software and associated documentation files (the "Software"), to deal |
||
3320 | * in the Software without restriction, including without limitation the rights |
||
3321 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
3322 | * copies of the Software, and to permit persons to whom the Software is |
||
3323 | * furnished to do so, subject to the following conditions:</p> |
||
3324 | * |
||
3325 | * The above copyright notice and this permission notice shall be included in |
||
3326 | * all copies or substantial portions of the Software. |
||
3327 | * |
||
3328 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
3329 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
3330 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||
3331 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
3332 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
3333 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||
3334 | * THE SOFTWARE. |
||
3335 | * |
||
3336 | */ |
||
3337 | "use strict"; |
||
3338 | module.exports = function(Promise, INTERNAL) { |
||
3339 | var THIS = {}; |
||
3340 | var util = require("./util.js"); |
||
3341 | var nodebackForPromise = require("./promise_resolver.js") |
||
3342 | ._nodebackForPromise; |
||
3343 | var withAppended = util.withAppended; |
||
3344 | var maybeWrapAsError = util.maybeWrapAsError; |
||
3345 | var canEvaluate = util.canEvaluate; |
||
3346 | var TypeError = require("./errors").TypeError; |
||
3347 | var defaultSuffix = "Async"; |
||
3348 | var defaultFilter = function(name, func) { |
||
3349 | return util.isIdentifier(name) && |
||
3350 | name.charAt(0) !== "_" && |
||
3351 | !util.isClass(func); |
||
3352 | }; |
||
3353 | var defaultPromisified = {__isPromisified__: true}; |
||
3354 | |||
3355 | |||
3356 | function escapeIdentRegex(str) { |
||
3357 | return str.replace(/([$])/, "\\$"); |
||
3358 | } |
||
3359 | |||
3360 | function isPromisified(fn) { |
||
3361 | try { |
||
3362 | return fn.__isPromisified__ === true; |
||
3363 | } |
||
3364 | catch (e) { |
||
3365 | return false; |
||
3366 | } |
||
3367 | } |
||
3368 | |||
3369 | function hasPromisified(obj, key, suffix) { |
||
3370 | var val = util.getDataPropertyOrDefault(obj, key + suffix, |
||
3371 | defaultPromisified); |
||
3372 | return val ? isPromisified(val) : false; |
||
3373 | } |
||
3374 | function checkValid(ret, suffix, suffixRegexp) { |
||
3375 | for (var i = 0; i < ret.length; i += 2) { |
||
3376 | var key = ret[i]; |
||
3377 | if (suffixRegexp.test(key)) { |
||
3378 | var keyWithoutAsyncSuffix = key.replace(suffixRegexp, ""); |
||
3379 | for (var j = 0; j < ret.length; j += 2) { |
||
3380 | if (ret[j] === keyWithoutAsyncSuffix) { |
||
3381 | throw new TypeError("Cannot promisify an API " + |
||
3382 | "that has normal methods with '"+suffix+"'-suffix"); |
||
3383 | } |
||
3384 | } |
||
3385 | } |
||
3386 | } |
||
3387 | } |
||
3388 | |||
3389 | function promisifiableMethods(obj, suffix, suffixRegexp, filter) { |
||
3390 | var keys = util.inheritedDataKeys(obj); |
||
3391 | var ret = []; |
||
3392 | for (var i = 0; i < keys.length; ++i) { |
||
3393 | var key = keys[i]; |
||
3394 | var value = obj[key]; |
||
3395 | if (typeof value === "function" && |
||
3396 | !isPromisified(value) && |
||
3397 | !hasPromisified(obj, key, suffix) && |
||
3398 | filter(key, value, obj)) { |
||
3399 | ret.push(key, value); |
||
3400 | } |
||
3401 | } |
||
3402 | checkValid(ret, suffix, suffixRegexp); |
||
3403 | return ret; |
||
3404 | } |
||
3405 | |||
3406 | function switchCaseArgumentOrder(likelyArgumentCount) { |
||
3407 | var ret = [likelyArgumentCount]; |
||
3408 | var min = Math.max(0, likelyArgumentCount - 1 - 5); |
||
3409 | for(var i = likelyArgumentCount - 1; i >= min; --i) { |
||
3410 | if (i === likelyArgumentCount) continue; |
||
3411 | ret.push(i); |
||
3412 | } |
||
3413 | for(var i = likelyArgumentCount + 1; i <= 5; ++i) { |
||
3414 | ret.push(i); |
||
3415 | } |
||
3416 | return ret; |
||
3417 | } |
||
3418 | |||
3419 | function argumentSequence(argumentCount) { |
||
3420 | return util.filledRange(argumentCount, "arguments[", "]"); |
||
3421 | } |
||
3422 | |||
3423 | function parameterDeclaration(parameterCount) { |
||
3424 | return util.filledRange(parameterCount, "_arg", ""); |
||
3425 | } |
||
3426 | |||
3427 | function parameterCount(fn) { |
||
3428 | if (typeof fn.length === "number") { |
||
3429 | return Math.max(Math.min(fn.length, 1023 + 1), 0); |
||
3430 | } |
||
3431 | return 0; |
||
3432 | } |
||
3433 | |||
3434 | function generatePropertyAccess(key) { |
||
3435 | if (util.isIdentifier(key)) { |
||
3436 | return "." + key; |
||
3437 | } |
||
3438 | else return "['" + key.replace(/(['\\])/g, "\\$1") + "']"; |
||
3439 | } |
||
3440 | |||
3441 | function makeNodePromisifiedEval(callback, receiver, originalName, fn, suffix) { |
||
3442 | var newParameterCount = Math.max(0, parameterCount(fn) - 1); |
||
3443 | var argumentOrder = switchCaseArgumentOrder(newParameterCount); |
||
3444 | var callbackName = |
||
3445 | (typeof originalName === "string" && util.isIdentifier(originalName) |
||
3446 | ? originalName + suffix |
||
3447 | : "promisified"); |
||
3448 | |||
3449 | function generateCallForArgumentCount(count) { |
||
3450 | var args = argumentSequence(count).join(", "); |
||
3451 | var comma = count > 0 ? ", " : ""; |
||
3452 | var ret; |
||
3453 | if (typeof callback === "string") { |
||
3454 | ret = " \n\ |
||
3455 | this.method(args, fn); \n\ |
||
3456 | break; \n\ |
||
3457 | ".replace(".method", generatePropertyAccess(callback)); |
||
3458 | } else if (receiver === THIS) { |
||
3459 | ret = " \n\ |
||
3460 | callback.call(this, args, fn); \n\ |
||
3461 | break; \n\ |
||
3462 | "; |
||
3463 | } else if (receiver !== void 0) { |
||
3464 | ret = " \n\ |
||
3465 | callback.call(receiver, args, fn); \n\ |
||
3466 | break; \n\ |
||
3467 | "; |
||
3468 | } else { |
||
3469 | ret = " \n\ |
||
3470 | callback(args, fn); \n\ |
||
3471 | break; \n\ |
||
3472 | "; |
||
3473 | } |
||
3474 | return ret.replace("args", args).replace(", ", comma); |
||
3475 | } |
||
3476 | |||
3477 | function generateArgumentSwitchCase() { |
||
3478 | var ret = ""; |
||
3479 | for(var i = 0; i < argumentOrder.length; ++i) { |
||
3480 | ret += "case " + argumentOrder[i] +":" + |
||
3481 | generateCallForArgumentCount(argumentOrder[i]); |
||
3482 | } |
||
3483 | var codeForCall; |
||
3484 | if (typeof callback === "string") { |
||
3485 | codeForCall = " \n\ |
||
3486 | this.property.apply(this, args); \n\ |
||
3487 | " |
||
3488 | .replace(".property", generatePropertyAccess(callback)); |
||
3489 | } else if (receiver === THIS) { |
||
3490 | codeForCall = " \n\ |
||
3491 | callback.apply(this, args); \n\ |
||
3492 | "; |
||
3493 | } else { |
||
3494 | codeForCall = " \n\ |
||
3495 | callback.apply(receiver, args); \n\ |
||
3496 | "; |
||
3497 | } |
||
3498 | |||
3499 | ret += " \n\ |
||
3500 | default: \n\ |
||
3501 | var args = new Array(len + 1); \n\ |
||
3502 | var i = 0; \n\ |
||
3503 | for (var i = 0; i < len; ++i) { \n\ |
||
3504 | args[i] = arguments[i]; \n\ |
||
3505 | } \n\ |
||
3506 | args[i] = fn; \n\ |
||
3507 | [CodeForCall] \n\ |
||
3508 | break; \n\ |
||
3509 | ".replace("[CodeForCall]", codeForCall); |
||
3510 | return ret; |
||
3511 | } |
||
3512 | |||
3513 | return new Function("Promise", |
||
3514 | "callback", |
||
3515 | "receiver", |
||
3516 | "withAppended", |
||
3517 | "maybeWrapAsError", |
||
3518 | "nodebackForPromise", |
||
3519 | "INTERNAL"," \n\ |
||
3520 | var ret = function FunctionName(Parameters) { \n\ |
||
3521 | 'use strict'; \n\ |
||
3522 | var len = arguments.length; \n\ |
||
3523 | var promise = new Promise(INTERNAL); \n\ |
||
3524 | promise._setTrace(void 0); \n\ |
||
3525 | var fn = nodebackForPromise(promise); \n\ |
||
3526 | try { \n\ |
||
3527 | switch(len) { \n\ |
||
3528 | [CodeForSwitchCase] \n\ |
||
3529 | } \n\ |
||
3530 | } catch (e) { \n\ |
||
3531 | var wrapped = maybeWrapAsError(e); \n\ |
||
3532 | promise._attachExtraTrace(wrapped); \n\ |
||
3533 | promise._reject(wrapped); \n\ |
||
3534 | } \n\ |
||
3535 | return promise; \n\ |
||
3536 | }; \n\ |
||
3537 | ret.__isPromisified__ = true; \n\ |
||
3538 | return ret; \n\ |
||
3539 | " |
||
3540 | .replace("FunctionName", callbackName) |
||
3541 | .replace("Parameters", parameterDeclaration(newParameterCount)) |
||
3542 | .replace("[CodeForSwitchCase]", generateArgumentSwitchCase()))( |
||
3543 | Promise, |
||
3544 | callback, |
||
3545 | receiver, |
||
3546 | withAppended, |
||
3547 | maybeWrapAsError, |
||
3548 | nodebackForPromise, |
||
3549 | INTERNAL |
||
3550 | ); |
||
3551 | } |
||
3552 | |||
3553 | function makeNodePromisifiedClosure(callback, receiver) { |
||
3554 | function promisified() { |
||
3555 | var _receiver = receiver; |
||
3556 | if (receiver === THIS) _receiver = this; |
||
3557 | if (typeof callback === "string") { |
||
3558 | callback = _receiver[callback]; |
||
3559 | } |
||
3560 | var promise = new Promise(INTERNAL); |
||
3561 | promise._setTrace(void 0); |
||
3562 | var fn = nodebackForPromise(promise); |
||
3563 | try { |
||
3564 | callback.apply(_receiver, withAppended(arguments, fn)); |
||
3565 | } catch(e) { |
||
3566 | var wrapped = maybeWrapAsError(e); |
||
3567 | promise._attachExtraTrace(wrapped); |
||
3568 | promise._reject(wrapped); |
||
3569 | } |
||
3570 | return promise; |
||
3571 | } |
||
3572 | promisified.__isPromisified__ = true; |
||
3573 | return promisified; |
||
3574 | } |
||
3575 | |||
3576 | var makeNodePromisified = canEvaluate |
||
3577 | ? makeNodePromisifiedEval |
||
3578 | : makeNodePromisifiedClosure; |
||
3579 | |||
3580 | function promisifyAll(obj, suffix, filter, promisifier) { |
||
3581 | var suffixRegexp = new RegExp(escapeIdentRegex(suffix) + "$"); |
||
3582 | var methods = |
||
3583 | promisifiableMethods(obj, suffix, suffixRegexp, filter); |
||
3584 | |||
3585 | for (var i = 0, len = methods.length; i < len; i+= 2) { |
||
3586 | var key = methods[i]; |
||
3587 | var fn = methods[i+1]; |
||
3588 | var promisifiedKey = key + suffix; |
||
3589 | obj[promisifiedKey] = promisifier === makeNodePromisified |
||
3590 | ? makeNodePromisified(key, THIS, key, fn, suffix) |
||
3591 | : promisifier(fn); |
||
3592 | } |
||
3593 | util.toFastProperties(obj); |
||
3594 | return obj; |
||
3595 | } |
||
3596 | |||
3597 | function promisify(callback, receiver) { |
||
3598 | return makeNodePromisified(callback, receiver, void 0, callback); |
||
3599 | } |
||
3600 | |||
3601 | Promise.promisify = function Promise$Promisify(fn, receiver) { |
||
3602 | if (typeof fn !== "function") { |
||
3603 | throw new TypeError("fn must be a function"); |
||
3604 | } |
||
3605 | if (isPromisified(fn)) { |
||
3606 | return fn; |
||
3607 | } |
||
3608 | return promisify(fn, arguments.length < 2 ? THIS : receiver); |
||
3609 | }; |
||
3610 | |||
3611 | Promise.promisifyAll = function Promise$PromisifyAll(target, options) { |
||
3612 | if (typeof target !== "function" && typeof target !== "object") { |
||
3613 | throw new TypeError("the target of promisifyAll must be an object or a function"); |
||
3614 | } |
||
3615 | options = Object(options); |
||
3616 | var suffix = options.suffix; |
||
3617 | if (typeof suffix !== "string") suffix = defaultSuffix; |
||
3618 | var filter = options.filter; |
||
3619 | if (typeof filter !== "function") filter = defaultFilter; |
||
3620 | var promisifier = options.promisifier; |
||
3621 | if (typeof promisifier !== "function") promisifier = makeNodePromisified; |
||
3622 | |||
3623 | if (!util.isIdentifier(suffix)) { |
||
3624 | throw new RangeError("suffix must be a valid identifier"); |
||
3625 | } |
||
3626 | |||
3627 | var keys = util.inheritedDataKeys(target, {includeHidden: true}); |
||
3628 | for (var i = 0; i < keys.length; ++i) { |
||
3629 | var value = target[keys[i]]; |
||
3630 | if (keys[i] !== "constructor" && |
||
3631 | util.isClass(value)) { |
||
3632 | promisifyAll(value.prototype, suffix, filter, promisifier); |
||
3633 | promisifyAll(value, suffix, filter, promisifier); |
||
3634 | } |
||
3635 | } |
||
3636 | |||
3637 | return promisifyAll(target, suffix, filter, promisifier); |
||
3638 | }; |
||
3639 | }; |
||
3640 | |||
3641 | |||
3642 | },{"./errors":10,"./promise_resolver.js":22,"./util.js":35}],24:[function(require,module,exports){ |
||
3643 | /** |
||
3644 | * Copyright (c) 2014 Petka Antonov |
||
3645 | * |
||
3646 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
||
3647 | * of this software and associated documentation files (the "Software"), to deal |
||
3648 | * in the Software without restriction, including without limitation the rights |
||
3649 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
3650 | * copies of the Software, and to permit persons to whom the Software is |
||
3651 | * furnished to do so, subject to the following conditions:</p> |
||
3652 | * |
||
3653 | * The above copyright notice and this permission notice shall be included in |
||
3654 | * all copies or substantial portions of the Software. |
||
3655 | * |
||
3656 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
3657 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
3658 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||
3659 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
3660 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
3661 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||
3662 | * THE SOFTWARE. |
||
3663 | * |
||
3664 | */ |
||
3665 | "use strict"; |
||
3666 | module.exports = function(Promise, PromiseArray, cast) { |
||
3667 | var util = require("./util.js"); |
||
3668 | var apiRejection = require("./errors_api_rejection")(Promise); |
||
3669 | var isObject = util.isObject; |
||
3670 | var es5 = require("./es5.js"); |
||
3671 | |||
3672 | function PropertiesPromiseArray(obj) { |
||
3673 | var keys = es5.keys(obj); |
||
3674 | var len = keys.length; |
||
3675 | var values = new Array(len * 2); |
||
3676 | for (var i = 0; i < len; ++i) { |
||
3677 | var key = keys[i]; |
||
3678 | values[i] = obj[key]; |
||
3679 | values[i + len] = key; |
||
3680 | } |
||
3681 | this.constructor$(values); |
||
3682 | } |
||
3683 | util.inherits(PropertiesPromiseArray, PromiseArray); |
||
3684 | |||
3685 | PropertiesPromiseArray.prototype._init = |
||
3686 | function PropertiesPromiseArray$_init() { |
||
3687 | this._init$(void 0, -3) ; |
||
3688 | }; |
||
3689 | |||
3690 | PropertiesPromiseArray.prototype._promiseFulfilled = |
||
3691 | function PropertiesPromiseArray$_promiseFulfilled(value, index) { |
||
3692 | if (this._isResolved()) return; |
||
3693 | this._values[index] = value; |
||
3694 | var totalResolved = ++this._totalResolved; |
||
3695 | if (totalResolved >= this._length) { |
||
3696 | var val = {}; |
||
3697 | var keyOffset = this.length(); |
||
3698 | for (var i = 0, len = this.length(); i < len; ++i) { |
||
3699 | val[this._values[i + keyOffset]] = this._values[i]; |
||
3700 | } |
||
3701 | this._resolve(val); |
||
3702 | } |
||
3703 | }; |
||
3704 | |||
3705 | PropertiesPromiseArray.prototype._promiseProgressed = |
||
3706 | function PropertiesPromiseArray$_promiseProgressed(value, index) { |
||
3707 | if (this._isResolved()) return; |
||
3708 | |||
3709 | this._promise._progress({ |
||
3710 | key: this._values[index + this.length()], |
||
3711 | value: value |
||
3712 | }); |
||
3713 | }; |
||
3714 | |||
3715 | PropertiesPromiseArray.prototype.shouldCopyValues = |
||
3716 | function PropertiesPromiseArray$_shouldCopyValues() { |
||
3717 | return false; |
||
3718 | }; |
||
3719 | |||
3720 | PropertiesPromiseArray.prototype.getActualLength = |
||
3721 | function PropertiesPromiseArray$getActualLength(len) { |
||
3722 | return len >> 1; |
||
3723 | }; |
||
3724 | |||
3725 | function Promise$_Props(promises) { |
||
3726 | var ret; |
||
3727 | var castValue = cast(promises, void 0); |
||
3728 | |||
3729 | if (!isObject(castValue)) { |
||
3730 | return apiRejection("cannot await properties of a non-object"); |
||
3731 | } else if (castValue instanceof Promise) { |
||
3732 | ret = castValue._then(Promise.props, void 0, void 0, void 0, void 0); |
||
3733 | } else { |
||
3734 | ret = new PropertiesPromiseArray(castValue).promise(); |
||
3735 | } |
||
3736 | |||
3737 | if (castValue instanceof Promise) { |
||
3738 | ret._propagateFrom(castValue, 4); |
||
3739 | } |
||
3740 | return ret; |
||
3741 | } |
||
3742 | |||
3743 | Promise.prototype.props = function Promise$props() { |
||
3744 | return Promise$_Props(this); |
||
3745 | }; |
||
3746 | |||
3747 | Promise.props = function Promise$Props(promises) { |
||
3748 | return Promise$_Props(promises); |
||
3749 | }; |
||
3750 | }; |
||
3751 | |||
3752 | },{"./errors_api_rejection":11,"./es5.js":12,"./util.js":35}],25:[function(require,module,exports){ |
||
3753 | /** |
||
3754 | * Copyright (c) 2014 Petka Antonov |
||
3755 | * |
||
3756 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
||
3757 | * of this software and associated documentation files (the "Software"), to deal |
||
3758 | * in the Software without restriction, including without limitation the rights |
||
3759 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
3760 | * copies of the Software, and to permit persons to whom the Software is |
||
3761 | * furnished to do so, subject to the following conditions:</p> |
||
3762 | * |
||
3763 | * The above copyright notice and this permission notice shall be included in |
||
3764 | * all copies or substantial portions of the Software. |
||
3765 | * |
||
3766 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
3767 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
3768 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||
3769 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
3770 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
3771 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||
3772 | * THE SOFTWARE. |
||
3773 | * |
||
3774 | */ |
||
3775 | "use strict"; |
||
3776 | function arrayCopy(src, srcIndex, dst, dstIndex, len) { |
||
3777 | for (var j = 0; j < len; ++j) { |
||
3778 | dst[j + dstIndex] = src[j + srcIndex]; |
||
3779 | } |
||
3780 | } |
||
3781 | |||
3782 | function Queue(capacity) { |
||
3783 | this._capacity = capacity; |
||
3784 | this._length = 0; |
||
3785 | this._front = 0; |
||
3786 | this._makeCapacity(); |
||
3787 | } |
||
3788 | |||
3789 | Queue.prototype._willBeOverCapacity = |
||
3790 | function Queue$_willBeOverCapacity(size) { |
||
3791 | return this._capacity < size; |
||
3792 | }; |
||
3793 | |||
3794 | Queue.prototype._pushOne = function Queue$_pushOne(arg) { |
||
3795 | var length = this.length(); |
||
3796 | this._checkCapacity(length + 1); |
||
3797 | var i = (this._front + length) & (this._capacity - 1); |
||
3798 | this[i] = arg; |
||
3799 | this._length = length + 1; |
||
3800 | }; |
||
3801 | |||
3802 | Queue.prototype.push = function Queue$push(fn, receiver, arg) { |
||
3803 | var length = this.length() + 3; |
||
3804 | if (this._willBeOverCapacity(length)) { |
||
3805 | this._pushOne(fn); |
||
3806 | this._pushOne(receiver); |
||
3807 | this._pushOne(arg); |
||
3808 | return; |
||
3809 | } |
||
3810 | var j = this._front + length - 3; |
||
3811 | this._checkCapacity(length); |
||
3812 | var wrapMask = this._capacity - 1; |
||
3813 | this[(j + 0) & wrapMask] = fn; |
||
3814 | this[(j + 1) & wrapMask] = receiver; |
||
3815 | this[(j + 2) & wrapMask] = arg; |
||
3816 | this._length = length; |
||
3817 | }; |
||
3818 | |||
3819 | Queue.prototype.shift = function Queue$shift() { |
||
3820 | var front = this._front, |
||
3821 | ret = this[front]; |
||
3822 | |||
3823 | this[front] = void 0; |
||
3824 | this._front = (front + 1) & (this._capacity - 1); |
||
3825 | this._length--; |
||
3826 | return ret; |
||
3827 | }; |
||
3828 | |||
3829 | Queue.prototype.length = function Queue$length() { |
||
3830 | return this._length; |
||
3831 | }; |
||
3832 | |||
3833 | Queue.prototype._makeCapacity = function Queue$_makeCapacity() { |
||
3834 | var len = this._capacity; |
||
3835 | for (var i = 0; i < len; ++i) { |
||
3836 | this[i] = void 0; |
||
3837 | } |
||
3838 | }; |
||
3839 | |||
3840 | Queue.prototype._checkCapacity = function Queue$_checkCapacity(size) { |
||
3841 | if (this._capacity < size) { |
||
3842 | this._resizeTo(this._capacity << 3); |
||
3843 | } |
||
3844 | }; |
||
3845 | |||
3846 | Queue.prototype._resizeTo = function Queue$_resizeTo(capacity) { |
||
3847 | var oldFront = this._front; |
||
3848 | var oldCapacity = this._capacity; |
||
3849 | var oldQueue = new Array(oldCapacity); |
||
3850 | var length = this.length(); |
||
3851 | |||
3852 | arrayCopy(this, 0, oldQueue, 0, oldCapacity); |
||
3853 | this._capacity = capacity; |
||
3854 | this._makeCapacity(); |
||
3855 | this._front = 0; |
||
3856 | if (oldFront + length <= oldCapacity) { |
||
3857 | arrayCopy(oldQueue, oldFront, this, 0, length); |
||
3858 | } else { var lengthBeforeWrapping = |
||
3859 | length - ((oldFront + length) & (oldCapacity - 1)); |
||
3860 | |||
3861 | arrayCopy(oldQueue, oldFront, this, 0, lengthBeforeWrapping); |
||
3862 | arrayCopy(oldQueue, 0, this, lengthBeforeWrapping, |
||
3863 | length - lengthBeforeWrapping); |
||
3864 | } |
||
3865 | }; |
||
3866 | |||
3867 | module.exports = Queue; |
||
3868 | |||
3869 | },{}],26:[function(require,module,exports){ |
||
3870 | /** |
||
3871 | * Copyright (c) 2014 Petka Antonov |
||
3872 | * |
||
3873 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
||
3874 | * of this software and associated documentation files (the "Software"), to deal |
||
3875 | * in the Software without restriction, including without limitation the rights |
||
3876 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
3877 | * copies of the Software, and to permit persons to whom the Software is |
||
3878 | * furnished to do so, subject to the following conditions:</p> |
||
3879 | * |
||
3880 | * The above copyright notice and this permission notice shall be included in |
||
3881 | * all copies or substantial portions of the Software. |
||
3882 | * |
||
3883 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
3884 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
3885 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||
3886 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
3887 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
3888 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||
3889 | * THE SOFTWARE. |
||
3890 | * |
||
3891 | */ |
||
3892 | "use strict"; |
||
3893 | module.exports = function(Promise, INTERNAL, cast) { |
||
3894 | var apiRejection = require("./errors_api_rejection.js")(Promise); |
||
3895 | var isArray = require("./util.js").isArray; |
||
3896 | |||
3897 | var raceLater = function Promise$_raceLater(promise) { |
||
3898 | return promise.then(function(array) { |
||
3899 | return Promise$_Race(array, promise); |
||
3900 | }); |
||
3901 | }; |
||
3902 | |||
3903 | var hasOwn = {}.hasOwnProperty; |
||
3904 | function Promise$_Race(promises, parent) { |
||
3905 | var maybePromise = cast(promises, void 0); |
||
3906 | |||
3907 | if (maybePromise instanceof Promise) { |
||
3908 | return raceLater(maybePromise); |
||
3909 | } else if (!isArray(promises)) { |
||
3910 | return apiRejection("expecting an array, a promise or a thenable"); |
||
3911 | } |
||
3912 | |||
3913 | var ret = new Promise(INTERNAL); |
||
3914 | if (parent !== void 0) { |
||
3915 | ret._propagateFrom(parent, 7); |
||
3916 | } else { |
||
3917 | ret._setTrace(void 0); |
||
3918 | } |
||
3919 | var fulfill = ret._fulfill; |
||
3920 | var reject = ret._reject; |
||
3921 | for (var i = 0, len = promises.length; i < len; ++i) { |
||
3922 | var val = promises[i]; |
||
3923 | |||
3924 | if (val === void 0 && !(hasOwn.call(promises, i))) { |
||
3925 | continue; |
||
3926 | } |
||
3927 | |||
3928 | Promise.cast(val)._then(fulfill, reject, void 0, ret, null); |
||
3929 | } |
||
3930 | return ret; |
||
3931 | } |
||
3932 | |||
3933 | Promise.race = function Promise$Race(promises) { |
||
3934 | return Promise$_Race(promises, void 0); |
||
3935 | }; |
||
3936 | |||
3937 | Promise.prototype.race = function Promise$race() { |
||
3938 | return Promise$_Race(this, void 0); |
||
3939 | }; |
||
3940 | |||
3941 | }; |
||
3942 | |||
3943 | },{"./errors_api_rejection.js":11,"./util.js":35}],27:[function(require,module,exports){ |
||
3944 | /** |
||
3945 | * Copyright (c) 2014 Petka Antonov |
||
3946 | * |
||
3947 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
||
3948 | * of this software and associated documentation files (the "Software"), to deal |
||
3949 | * in the Software without restriction, including without limitation the rights |
||
3950 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
3951 | * copies of the Software, and to permit persons to whom the Software is |
||
3952 | * furnished to do so, subject to the following conditions:</p> |
||
3953 | * |
||
3954 | * The above copyright notice and this permission notice shall be included in |
||
3955 | * all copies or substantial portions of the Software. |
||
3956 | * |
||
3957 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
3958 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
3959 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||
3960 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
3961 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
3962 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||
3963 | * THE SOFTWARE. |
||
3964 | * |
||
3965 | */ |
||
3966 | "use strict"; |
||
3967 | module.exports = function(Promise, PromiseArray, apiRejection, cast, INTERNAL) { |
||
3968 | var util = require("./util.js"); |
||
3969 | var tryCatch4 = util.tryCatch4; |
||
3970 | var tryCatch3 = util.tryCatch3; |
||
3971 | var errorObj = util.errorObj; |
||
3972 | function ReductionPromiseArray(promises, fn, accum, _each) { |
||
3973 | this.constructor$(promises); |
||
3974 | this._preservedValues = _each === INTERNAL ? [] : null; |
||
3975 | this._zerothIsAccum = (accum === void 0); |
||
3976 | this._gotAccum = false; |
||
3977 | this._reducingIndex = (this._zerothIsAccum ? 1 : 0); |
||
3978 | this._valuesPhase = undefined; |
||
3979 | |||
3980 | var maybePromise = cast(accum, void 0); |
||
3981 | var rejected = false; |
||
3982 | var isPromise = maybePromise instanceof Promise; |
||
3983 | if (isPromise) { |
||
3984 | if (maybePromise.isPending()) { |
||
3985 | maybePromise._proxyPromiseArray(this, -1); |
||
3986 | } else if (maybePromise.isFulfilled()) { |
||
3987 | accum = maybePromise.value(); |
||
3988 | this._gotAccum = true; |
||
3989 | } else { |
||
3990 | maybePromise._unsetRejectionIsUnhandled(); |
||
3991 | this._reject(maybePromise.reason()); |
||
3992 | rejected = true; |
||
3993 | } |
||
3994 | } |
||
3995 | if (!(isPromise || this._zerothIsAccum)) this._gotAccum = true; |
||
3996 | this._callback = fn; |
||
3997 | this._accum = accum; |
||
3998 | if (!rejected) this._init$(void 0, -5); |
||
3999 | } |
||
4000 | util.inherits(ReductionPromiseArray, PromiseArray); |
||
4001 | |||
4002 | ReductionPromiseArray.prototype._init = |
||
4003 | function ReductionPromiseArray$_init() {}; |
||
4004 | |||
4005 | ReductionPromiseArray.prototype._resolveEmptyArray = |
||
4006 | function ReductionPromiseArray$_resolveEmptyArray() { |
||
4007 | if (this._gotAccum || this._zerothIsAccum) { |
||
4008 | this._resolve(this._preservedValues !== null |
||
4009 | ? [] : this._accum); |
||
4010 | } |
||
4011 | }; |
||
4012 | |||
4013 | ReductionPromiseArray.prototype._promiseFulfilled = |
||
4014 | function ReductionPromiseArray$_promiseFulfilled(value, index) { |
||
4015 | var values = this._values; |
||
4016 | if (values === null) return; |
||
4017 | var length = this.length(); |
||
4018 | var preservedValues = this._preservedValues; |
||
4019 | var isEach = preservedValues !== null; |
||
4020 | var gotAccum = this._gotAccum; |
||
4021 | var valuesPhase = this._valuesPhase; |
||
4022 | var valuesPhaseIndex; |
||
4023 | if (!valuesPhase) { |
||
4024 | valuesPhase = this._valuesPhase = Array(length); |
||
4025 | for (valuesPhaseIndex=0; valuesPhaseIndex<length; ++valuesPhaseIndex) { |
||
4026 | valuesPhase[valuesPhaseIndex] = 0; |
||
4027 | } |
||
4028 | } |
||
4029 | valuesPhaseIndex = valuesPhase[index]; |
||
4030 | |||
4031 | if (index === 0 && this._zerothIsAccum) { |
||
4032 | if (!gotAccum) { |
||
4033 | this._accum = value; |
||
4034 | this._gotAccum = gotAccum = true; |
||
4035 | } |
||
4036 | valuesPhase[index] = ((valuesPhaseIndex === 0) |
||
4037 | ? 1 : 2); |
||
4038 | } else if (index === -1) { |
||
4039 | if (!gotAccum) { |
||
4040 | this._accum = value; |
||
4041 | this._gotAccum = gotAccum = true; |
||
4042 | } |
||
4043 | } else { |
||
4044 | if (valuesPhaseIndex === 0) { |
||
4045 | valuesPhase[index] = 1; |
||
4046 | } |
||
4047 | else { |
||
4048 | valuesPhase[index] = 2; |
||
4049 | if (gotAccum) { |
||
4050 | this._accum = value; |
||
4051 | } |
||
4052 | } |
||
4053 | } |
||
4054 | if (!gotAccum) return; |
||
4055 | |||
4056 | var callback = this._callback; |
||
4057 | var receiver = this._promise._boundTo; |
||
4058 | var ret; |
||
4059 | |||
4060 | for (var i = this._reducingIndex; i < length; ++i) { |
||
4061 | valuesPhaseIndex = valuesPhase[i]; |
||
4062 | if (valuesPhaseIndex === 2) { |
||
4063 | this._reducingIndex = i + 1; |
||
4064 | continue; |
||
4065 | } |
||
4066 | if (valuesPhaseIndex !== 1) return; |
||
4067 | |||
4068 | value = values[i]; |
||
4069 | if (value instanceof Promise) { |
||
4070 | if (value.isFulfilled()) { |
||
4071 | value = value._settledValue; |
||
4072 | } else if (value.isPending()) { |
||
4073 | return; |
||
4074 | } else { |
||
4075 | value._unsetRejectionIsUnhandled(); |
||
4076 | return this._reject(value.reason()); |
||
4077 | } |
||
4078 | } |
||
4079 | |||
4080 | if (isEach) { |
||
4081 | preservedValues.push(value); |
||
4082 | ret = tryCatch3(callback, receiver, value, i, length); |
||
4083 | } |
||
4084 | else { |
||
4085 | ret = tryCatch4(callback, receiver, this._accum, value, i, length); |
||
4086 | } |
||
4087 | |||
4088 | if (ret === errorObj) return this._reject(ret.e); |
||
4089 | |||
4090 | var maybePromise = cast(ret, void 0); |
||
4091 | if (maybePromise instanceof Promise) { |
||
4092 | if (maybePromise.isPending()) { |
||
4093 | valuesPhase[i] = 4; |
||
4094 | return maybePromise._proxyPromiseArray(this, i); |
||
4095 | } else if (maybePromise.isFulfilled()) { |
||
4096 | ret = maybePromise.value(); |
||
4097 | } else { |
||
4098 | maybePromise._unsetRejectionIsUnhandled(); |
||
4099 | return this._reject(maybePromise.reason()); |
||
4100 | } |
||
4101 | } |
||
4102 | |||
4103 | this._reducingIndex = i + 1; |
||
4104 | this._accum = ret; |
||
4105 | } |
||
4106 | |||
4107 | if (this._reducingIndex < length) return; |
||
4108 | this._resolve(isEach ? preservedValues : this._accum); |
||
4109 | }; |
||
4110 | |||
4111 | function reduce(promises, fn, initialValue, _each) { |
||
4112 | if (typeof fn !== "function") return apiRejection("fn must be a function"); |
||
4113 | var array = new ReductionPromiseArray(promises, fn, initialValue, _each); |
||
4114 | return array.promise(); |
||
4115 | } |
||
4116 | |||
4117 | Promise.prototype.reduce = function Promise$reduce(fn, initialValue) { |
||
4118 | return reduce(this, fn, initialValue, null); |
||
4119 | }; |
||
4120 | |||
4121 | Promise.reduce = function Promise$Reduce(promises, fn, initialValue, _each) { |
||
4122 | return reduce(promises, fn, initialValue, _each); |
||
4123 | }; |
||
4124 | }; |
||
4125 | |||
4126 | },{"./util.js":35}],28:[function(require,module,exports){ |
||
4127 | /** |
||
4128 | * Copyright (c) 2014 Petka Antonov |
||
4129 | * |
||
4130 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
||
4131 | * of this software and associated documentation files (the "Software"), to deal |
||
4132 | * in the Software without restriction, including without limitation the rights |
||
4133 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
4134 | * copies of the Software, and to permit persons to whom the Software is |
||
4135 | * furnished to do so, subject to the following conditions:</p> |
||
4136 | * |
||
4137 | * The above copyright notice and this permission notice shall be included in |
||
4138 | * all copies or substantial portions of the Software. |
||
4139 | * |
||
4140 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
4141 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
4142 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||
4143 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
4144 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
4145 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||
4146 | * THE SOFTWARE. |
||
4147 | * |
||
4148 | */ |
||
4149 | "use strict"; |
||
4150 | var schedule; |
||
4151 | var _MutationObserver; |
||
4152 | if (typeof process === "object" && typeof process.version === "string") { |
||
4153 | schedule = function Promise$_Scheduler(fn) { |
||
4154 | process.nextTick(fn); |
||
4155 | }; |
||
4156 | } |
||
4157 | else if ((typeof MutationObserver !== "undefined" && |
||
4158 | (_MutationObserver = MutationObserver)) || |
||
4159 | (typeof WebKitMutationObserver !== "undefined" && |
||
4160 | (_MutationObserver = WebKitMutationObserver))) { |
||
4161 | schedule = (function() { |
||
4162 | var div = document.createElement("div"); |
||
4163 | var queuedFn = void 0; |
||
4164 | var observer = new _MutationObserver( |
||
4165 | function Promise$_Scheduler() { |
||
4166 | var fn = queuedFn; |
||
4167 | queuedFn = void 0; |
||
4168 | fn(); |
||
4169 | } |
||
4170 | ); |
||
4171 | observer.observe(div, { |
||
4172 | attributes: true |
||
4173 | }); |
||
4174 | return function Promise$_Scheduler(fn) { |
||
4175 | queuedFn = fn; |
||
4176 | div.setAttribute("class", "foo"); |
||
4177 | }; |
||
4178 | |||
4179 | })(); |
||
4180 | } |
||
4181 | else if (typeof setTimeout !== "undefined") { |
||
4182 | schedule = function Promise$_Scheduler(fn) { |
||
4183 | setTimeout(fn, 0); |
||
4184 | }; |
||
4185 | } |
||
4186 | else throw new Error("no async scheduler available"); |
||
4187 | module.exports = schedule; |
||
4188 | |||
4189 | },{}],29:[function(require,module,exports){ |
||
4190 | /** |
||
4191 | * Copyright (c) 2014 Petka Antonov |
||
4192 | * |
||
4193 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
||
4194 | * of this software and associated documentation files (the "Software"), to deal |
||
4195 | * in the Software without restriction, including without limitation the rights |
||
4196 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
4197 | * copies of the Software, and to permit persons to whom the Software is |
||
4198 | * furnished to do so, subject to the following conditions:</p> |
||
4199 | * |
||
4200 | * The above copyright notice and this permission notice shall be included in |
||
4201 | * all copies or substantial portions of the Software. |
||
4202 | * |
||
4203 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
4204 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
4205 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||
4206 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
4207 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
4208 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||
4209 | * THE SOFTWARE. |
||
4210 | * |
||
4211 | */ |
||
4212 | "use strict"; |
||
4213 | module.exports = |
||
4214 | function(Promise, PromiseArray) { |
||
4215 | var PromiseInspection = Promise.PromiseInspection; |
||
4216 | var util = require("./util.js"); |
||
4217 | |||
4218 | function SettledPromiseArray(values) { |
||
4219 | this.constructor$(values); |
||
4220 | } |
||
4221 | util.inherits(SettledPromiseArray, PromiseArray); |
||
4222 | |||
4223 | SettledPromiseArray.prototype._promiseResolved = |
||
4224 | function SettledPromiseArray$_promiseResolved(index, inspection) { |
||
4225 | this._values[index] = inspection; |
||
4226 | var totalResolved = ++this._totalResolved; |
||
4227 | if (totalResolved >= this._length) { |
||
4228 | this._resolve(this._values); |
||
4229 | } |
||
4230 | }; |
||
4231 | |||
4232 | SettledPromiseArray.prototype._promiseFulfilled = |
||
4233 | function SettledPromiseArray$_promiseFulfilled(value, index) { |
||
4234 | if (this._isResolved()) return; |
||
4235 | var ret = new PromiseInspection(); |
||
4236 | ret._bitField = 268435456; |
||
4237 | ret._settledValue = value; |
||
4238 | this._promiseResolved(index, ret); |
||
4239 | }; |
||
4240 | SettledPromiseArray.prototype._promiseRejected = |
||
4241 | function SettledPromiseArray$_promiseRejected(reason, index) { |
||
4242 | if (this._isResolved()) return; |
||
4243 | var ret = new PromiseInspection(); |
||
4244 | ret._bitField = 134217728; |
||
4245 | ret._settledValue = reason; |
||
4246 | this._promiseResolved(index, ret); |
||
4247 | }; |
||
4248 | |||
4249 | Promise.settle = function Promise$Settle(promises) { |
||
4250 | return new SettledPromiseArray(promises).promise(); |
||
4251 | }; |
||
4252 | |||
4253 | Promise.prototype.settle = function Promise$settle() { |
||
4254 | return new SettledPromiseArray(this).promise(); |
||
4255 | }; |
||
4256 | }; |
||
4257 | |||
4258 | },{"./util.js":35}],30:[function(require,module,exports){ |
||
4259 | /** |
||
4260 | * Copyright (c) 2014 Petka Antonov |
||
4261 | * |
||
4262 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
||
4263 | * of this software and associated documentation files (the "Software"), to deal |
||
4264 | * in the Software without restriction, including without limitation the rights |
||
4265 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
4266 | * copies of the Software, and to permit persons to whom the Software is |
||
4267 | * furnished to do so, subject to the following conditions:</p> |
||
4268 | * |
||
4269 | * The above copyright notice and this permission notice shall be included in |
||
4270 | * all copies or substantial portions of the Software. |
||
4271 | * |
||
4272 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
4273 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
4274 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||
4275 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
4276 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
4277 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||
4278 | * THE SOFTWARE. |
||
4279 | * |
||
4280 | */ |
||
4281 | "use strict"; |
||
4282 | module.exports = |
||
4283 | function(Promise, PromiseArray, apiRejection) { |
||
4284 | var util = require("./util.js"); |
||
4285 | var RangeError = require("./errors.js").RangeError; |
||
4286 | var AggregateError = require("./errors.js").AggregateError; |
||
4287 | var isArray = util.isArray; |
||
4288 | |||
4289 | |||
4290 | function SomePromiseArray(values) { |
||
4291 | this.constructor$(values); |
||
4292 | this._howMany = 0; |
||
4293 | this._unwrap = false; |
||
4294 | this._initialized = false; |
||
4295 | } |
||
4296 | util.inherits(SomePromiseArray, PromiseArray); |
||
4297 | |||
4298 | SomePromiseArray.prototype._init = function SomePromiseArray$_init() { |
||
4299 | if (!this._initialized) { |
||
4300 | return; |
||
4301 | } |
||
4302 | if (this._howMany === 0) { |
||
4303 | this._resolve([]); |
||
4304 | return; |
||
4305 | } |
||
4306 | this._init$(void 0, -5); |
||
4307 | var isArrayResolved = isArray(this._values); |
||
4308 | if (!this._isResolved() && |
||
4309 | isArrayResolved && |
||
4310 | this._howMany > this._canPossiblyFulfill()) { |
||
4311 | this._reject(this._getRangeError(this.length())); |
||
4312 | } |
||
4313 | }; |
||
4314 | |||
4315 | SomePromiseArray.prototype.init = function SomePromiseArray$init() { |
||
4316 | this._initialized = true; |
||
4317 | this._init(); |
||
4318 | }; |
||
4319 | |||
4320 | SomePromiseArray.prototype.setUnwrap = function SomePromiseArray$setUnwrap() { |
||
4321 | this._unwrap = true; |
||
4322 | }; |
||
4323 | |||
4324 | SomePromiseArray.prototype.howMany = function SomePromiseArray$howMany() { |
||
4325 | return this._howMany; |
||
4326 | }; |
||
4327 | |||
4328 | SomePromiseArray.prototype.setHowMany = |
||
4329 | function SomePromiseArray$setHowMany(count) { |
||
4330 | if (this._isResolved()) return; |
||
4331 | this._howMany = count; |
||
4332 | }; |
||
4333 | |||
4334 | SomePromiseArray.prototype._promiseFulfilled = |
||
4335 | function SomePromiseArray$_promiseFulfilled(value) { |
||
4336 | if (this._isResolved()) return; |
||
4337 | this._addFulfilled(value); |
||
4338 | if (this._fulfilled() === this.howMany()) { |
||
4339 | this._values.length = this.howMany(); |
||
4340 | if (this.howMany() === 1 && this._unwrap) { |
||
4341 | this._resolve(this._values[0]); |
||
4342 | } else { |
||
4343 | this._resolve(this._values); |
||
4344 | } |
||
4345 | } |
||
4346 | |||
4347 | }; |
||
4348 | SomePromiseArray.prototype._promiseRejected = |
||
4349 | function SomePromiseArray$_promiseRejected(reason) { |
||
4350 | if (this._isResolved()) return; |
||
4351 | this._addRejected(reason); |
||
4352 | if (this.howMany() > this._canPossiblyFulfill()) { |
||
4353 | var e = new AggregateError(); |
||
4354 | for (var i = this.length(); i < this._values.length; ++i) { |
||
4355 | e.push(this._values[i]); |
||
4356 | } |
||
4357 | this._reject(e); |
||
4358 | } |
||
4359 | }; |
||
4360 | |||
4361 | SomePromiseArray.prototype._fulfilled = function SomePromiseArray$_fulfilled() { |
||
4362 | return this._totalResolved; |
||
4363 | }; |
||
4364 | |||
4365 | SomePromiseArray.prototype._rejected = function SomePromiseArray$_rejected() { |
||
4366 | return this._values.length - this.length(); |
||
4367 | }; |
||
4368 | |||
4369 | SomePromiseArray.prototype._addRejected = |
||
4370 | function SomePromiseArray$_addRejected(reason) { |
||
4371 | this._values.push(reason); |
||
4372 | }; |
||
4373 | |||
4374 | SomePromiseArray.prototype._addFulfilled = |
||
4375 | function SomePromiseArray$_addFulfilled(value) { |
||
4376 | this._values[this._totalResolved++] = value; |
||
4377 | }; |
||
4378 | |||
4379 | SomePromiseArray.prototype._canPossiblyFulfill = |
||
4380 | function SomePromiseArray$_canPossiblyFulfill() { |
||
4381 | return this.length() - this._rejected(); |
||
4382 | }; |
||
4383 | |||
4384 | SomePromiseArray.prototype._getRangeError = |
||
4385 | function SomePromiseArray$_getRangeError(count) { |
||
4386 | var message = "Input array must contain at least " + |
||
4387 | this._howMany + " items but contains only " + count + " items"; |
||
4388 | return new RangeError(message); |
||
4389 | }; |
||
4390 | |||
4391 | SomePromiseArray.prototype._resolveEmptyArray = |
||
4392 | function SomePromiseArray$_resolveEmptyArray() { |
||
4393 | this._reject(this._getRangeError(0)); |
||
4394 | }; |
||
4395 | |||
4396 | function Promise$_Some(promises, howMany) { |
||
4397 | if ((howMany | 0) !== howMany || howMany < 0) { |
||
4398 | return apiRejection("expecting a positive integer"); |
||
4399 | } |
||
4400 | var ret = new SomePromiseArray(promises); |
||
4401 | var promise = ret.promise(); |
||
4402 | if (promise.isRejected()) { |
||
4403 | return promise; |
||
4404 | } |
||
4405 | ret.setHowMany(howMany); |
||
4406 | ret.init(); |
||
4407 | return promise; |
||
4408 | } |
||
4409 | |||
4410 | Promise.some = function Promise$Some(promises, howMany) { |
||
4411 | return Promise$_Some(promises, howMany); |
||
4412 | }; |
||
4413 | |||
4414 | Promise.prototype.some = function Promise$some(howMany) { |
||
4415 | return Promise$_Some(this, howMany); |
||
4416 | }; |
||
4417 | |||
4418 | Promise._SomePromiseArray = SomePromiseArray; |
||
4419 | }; |
||
4420 | |||
4421 | },{"./errors.js":10,"./util.js":35}],31:[function(require,module,exports){ |
||
4422 | /** |
||
4423 | * Copyright (c) 2014 Petka Antonov |
||
4424 | * |
||
4425 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
||
4426 | * of this software and associated documentation files (the "Software"), to deal |
||
4427 | * in the Software without restriction, including without limitation the rights |
||
4428 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
4429 | * copies of the Software, and to permit persons to whom the Software is |
||
4430 | * furnished to do so, subject to the following conditions:</p> |
||
4431 | * |
||
4432 | * The above copyright notice and this permission notice shall be included in |
||
4433 | * all copies or substantial portions of the Software. |
||
4434 | * |
||
4435 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
4436 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
4437 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||
4438 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
4439 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
4440 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||
4441 | * THE SOFTWARE. |
||
4442 | * |
||
4443 | */ |
||
4444 | "use strict"; |
||
4445 | module.exports = function(Promise) { |
||
4446 | function PromiseInspection(promise) { |
||
4447 | if (promise !== void 0) { |
||
4448 | this._bitField = promise._bitField; |
||
4449 | this._settledValue = promise.isResolved() |
||
4450 | ? promise._settledValue |
||
4451 | : void 0; |
||
4452 | } |
||
4453 | else { |
||
4454 | this._bitField = 0; |
||
4455 | this._settledValue = void 0; |
||
4456 | } |
||
4457 | } |
||
4458 | |||
4459 | PromiseInspection.prototype.isFulfilled = |
||
4460 | Promise.prototype.isFulfilled = function Promise$isFulfilled() { |
||
4461 | return (this._bitField & 268435456) > 0; |
||
4462 | }; |
||
4463 | |||
4464 | PromiseInspection.prototype.isRejected = |
||
4465 | Promise.prototype.isRejected = function Promise$isRejected() { |
||
4466 | return (this._bitField & 134217728) > 0; |
||
4467 | }; |
||
4468 | |||
4469 | PromiseInspection.prototype.isPending = |
||
4470 | Promise.prototype.isPending = function Promise$isPending() { |
||
4471 | return (this._bitField & 402653184) === 0; |
||
4472 | }; |
||
4473 | |||
4474 | PromiseInspection.prototype.value = |
||
4475 | Promise.prototype.value = function Promise$value() { |
||
4476 | if (!this.isFulfilled()) { |
||
4477 | throw new TypeError("cannot get fulfillment value of a non-fulfilled promise"); |
||
4478 | } |
||
4479 | return this._settledValue; |
||
4480 | }; |
||
4481 | |||
4482 | PromiseInspection.prototype.error = |
||
4483 | PromiseInspection.prototype.reason = |
||
4484 | Promise.prototype.reason = function Promise$reason() { |
||
4485 | if (!this.isRejected()) { |
||
4486 | throw new TypeError("cannot get rejection reason of a non-rejected promise"); |
||
4487 | } |
||
4488 | return this._settledValue; |
||
4489 | }; |
||
4490 | |||
4491 | PromiseInspection.prototype.isResolved = |
||
4492 | Promise.prototype.isResolved = function Promise$isResolved() { |
||
4493 | return (this._bitField & 402653184) > 0; |
||
4494 | }; |
||
4495 | |||
4496 | Promise.PromiseInspection = PromiseInspection; |
||
4497 | }; |
||
4498 | |||
4499 | },{}],32:[function(require,module,exports){ |
||
4500 | /** |
||
4501 | * Copyright (c) 2014 Petka Antonov |
||
4502 | * |
||
4503 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
||
4504 | * of this software and associated documentation files (the "Software"), to deal |
||
4505 | * in the Software without restriction, including without limitation the rights |
||
4506 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
4507 | * copies of the Software, and to permit persons to whom the Software is |
||
4508 | * furnished to do so, subject to the following conditions:</p> |
||
4509 | * |
||
4510 | * The above copyright notice and this permission notice shall be included in |
||
4511 | * all copies or substantial portions of the Software. |
||
4512 | * |
||
4513 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
4514 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
4515 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||
4516 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
4517 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
4518 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||
4519 | * THE SOFTWARE. |
||
4520 | * |
||
4521 | */ |
||
4522 | "use strict"; |
||
4523 | module.exports = function(Promise, INTERNAL) { |
||
4524 | var util = require("./util.js"); |
||
4525 | var canAttach = require("./errors.js").canAttach; |
||
4526 | var errorObj = util.errorObj; |
||
4527 | var isObject = util.isObject; |
||
4528 | |||
4529 | function getThen(obj) { |
||
4530 | try { |
||
4531 | return obj.then; |
||
4532 | } |
||
4533 | catch(e) { |
||
4534 | errorObj.e = e; |
||
4535 | return errorObj; |
||
4536 | } |
||
4537 | } |
||
4538 | |||
4539 | function Promise$_Cast(obj, originalPromise) { |
||
4540 | if (isObject(obj)) { |
||
4541 | if (obj instanceof Promise) { |
||
4542 | return obj; |
||
4543 | } |
||
4544 | else if (isAnyBluebirdPromise(obj)) { |
||
4545 | var ret = new Promise(INTERNAL); |
||
4546 | ret._setTrace(void 0); |
||
4547 | obj._then( |
||
4548 | ret._fulfillUnchecked, |
||
4549 | ret._rejectUncheckedCheckError, |
||
4550 | ret._progressUnchecked, |
||
4551 | ret, |
||
4552 | null |
||
4553 | ); |
||
4554 | ret._setFollowing(); |
||
4555 | return ret; |
||
4556 | } |
||
4557 | var then = getThen(obj); |
||
4558 | if (then === errorObj) { |
||
4559 | if (originalPromise !== void 0 && canAttach(then.e)) { |
||
4560 | originalPromise._attachExtraTrace(then.e); |
||
4561 | } |
||
4562 | return Promise.reject(then.e); |
||
4563 | } else if (typeof then === "function") { |
||
4564 | return Promise$_doThenable(obj, then, originalPromise); |
||
4565 | } |
||
4566 | } |
||
4567 | return obj; |
||
4568 | } |
||
4569 | |||
4570 | var hasProp = {}.hasOwnProperty; |
||
4571 | function isAnyBluebirdPromise(obj) { |
||
4572 | return hasProp.call(obj, "_promise0"); |
||
4573 | } |
||
4574 | |||
4575 | function Promise$_doThenable(x, then, originalPromise) { |
||
4576 | var resolver = Promise.defer(); |
||
4577 | var called = false; |
||
4578 | try { |
||
4579 | then.call( |
||
4580 | x, |
||
4581 | Promise$_resolveFromThenable, |
||
4582 | Promise$_rejectFromThenable, |
||
4583 | Promise$_progressFromThenable |
||
4584 | ); |
||
4585 | } catch(e) { |
||
4586 | if (!called) { |
||
4587 | called = true; |
||
4588 | var trace = canAttach(e) ? e : new Error(e + ""); |
||
4589 | if (originalPromise !== void 0) { |
||
4590 | originalPromise._attachExtraTrace(trace); |
||
4591 | } |
||
4592 | resolver.promise._reject(e, trace); |
||
4593 | } |
||
4594 | } |
||
4595 | return resolver.promise; |
||
4596 | |||
4597 | function Promise$_resolveFromThenable(y) { |
||
4598 | if (called) return; |
||
4599 | called = true; |
||
4600 | |||
4601 | if (x === y) { |
||
4602 | var e = Promise._makeSelfResolutionError(); |
||
4603 | if (originalPromise !== void 0) { |
||
4604 | originalPromise._attachExtraTrace(e); |
||
4605 | } |
||
4606 | resolver.promise._reject(e, void 0); |
||
4607 | return; |
||
4608 | } |
||
4609 | resolver.resolve(y); |
||
4610 | } |
||
4611 | |||
4612 | function Promise$_rejectFromThenable(r) { |
||
4613 | if (called) return; |
||
4614 | called = true; |
||
4615 | var trace = canAttach(r) ? r : new Error(r + ""); |
||
4616 | if (originalPromise !== void 0) { |
||
4617 | originalPromise._attachExtraTrace(trace); |
||
4618 | } |
||
4619 | resolver.promise._reject(r, trace); |
||
4620 | } |
||
4621 | |||
4622 | function Promise$_progressFromThenable(v) { |
||
4623 | if (called) return; |
||
4624 | var promise = resolver.promise; |
||
4625 | if (typeof promise._progress === "function") { |
||
4626 | promise._progress(v); |
||
4627 | } |
||
4628 | } |
||
4629 | } |
||
4630 | |||
4631 | return Promise$_Cast; |
||
4632 | }; |
||
4633 | |||
4634 | },{"./errors.js":10,"./util.js":35}],33:[function(require,module,exports){ |
||
4635 | /** |
||
4636 | * Copyright (c) 2014 Petka Antonov |
||
4637 | * |
||
4638 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
||
4639 | * of this software and associated documentation files (the "Software"), to deal |
||
4640 | * in the Software without restriction, including without limitation the rights |
||
4641 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
4642 | * copies of the Software, and to permit persons to whom the Software is |
||
4643 | * furnished to do so, subject to the following conditions:</p> |
||
4644 | * |
||
4645 | * The above copyright notice and this permission notice shall be included in |
||
4646 | * all copies or substantial portions of the Software. |
||
4647 | * |
||
4648 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
4649 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
4650 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||
4651 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
4652 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
4653 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||
4654 | * THE SOFTWARE. |
||
4655 | * |
||
4656 | */ |
||
4657 | "use strict"; |
||
4658 | var _setTimeout = function(fn, ms) { |
||
4659 | var len = arguments.length; |
||
4660 | var arg0 = arguments[2]; |
||
4661 | var arg1 = arguments[3]; |
||
4662 | var arg2 = len >= 5 ? arguments[4] : void 0; |
||
4663 | setTimeout(function() { |
||
4664 | fn(arg0, arg1, arg2); |
||
4665 | }, ms); |
||
4666 | }; |
||
4667 | |||
4668 | module.exports = function(Promise, INTERNAL, cast) { |
||
4669 | var util = require("./util.js"); |
||
4670 | var errors = require("./errors.js"); |
||
4671 | var apiRejection = require("./errors_api_rejection")(Promise); |
||
4672 | var TimeoutError = Promise.TimeoutError; |
||
4673 | |||
4674 | var afterTimeout = function Promise$_afterTimeout(promise, message, ms) { |
||
4675 | if (!promise.isPending()) return; |
||
4676 | if (typeof message !== "string") { |
||
4677 | message = "operation timed out after" + " " + ms + " ms" |
||
4678 | } |
||
4679 | var err = new TimeoutError(message); |
||
4680 | errors.markAsOriginatingFromRejection(err); |
||
4681 | promise._attachExtraTrace(err); |
||
4682 | promise._cancel(err); |
||
4683 | }; |
||
4684 | |||
4685 | var afterDelay = function Promise$_afterDelay(value, promise) { |
||
4686 | promise._fulfill(value); |
||
4687 | }; |
||
4688 | |||
4689 | var delay = Promise.delay = function Promise$Delay(value, ms) { |
||
4690 | if (ms === void 0) { |
||
4691 | ms = value; |
||
4692 | value = void 0; |
||
4693 | } |
||
4694 | ms = +ms; |
||
4695 | var maybePromise = cast(value, void 0); |
||
4696 | var promise = new Promise(INTERNAL); |
||
4697 | |||
4698 | if (maybePromise instanceof Promise) { |
||
4699 | promise._propagateFrom(maybePromise, 7); |
||
4700 | promise._follow(maybePromise); |
||
4701 | return promise.then(function(value) { |
||
4702 | return Promise.delay(value, ms); |
||
4703 | }); |
||
4704 | } else { |
||
4705 | promise._setTrace(void 0); |
||
4706 | _setTimeout(afterDelay, ms, value, promise); |
||
4707 | } |
||
4708 | return promise; |
||
4709 | }; |
||
4710 | |||
4711 | Promise.prototype.delay = function Promise$delay(ms) { |
||
4712 | return delay(this, ms); |
||
4713 | }; |
||
4714 | |||
4715 | Promise.prototype.timeout = function Promise$timeout(ms, message) { |
||
4716 | ms = +ms; |
||
4717 | |||
4718 | var ret = new Promise(INTERNAL); |
||
4719 | ret._propagateFrom(this, 7); |
||
4720 | ret._follow(this); |
||
4721 | _setTimeout(afterTimeout, ms, ret, message, ms); |
||
4722 | return ret.cancellable(); |
||
4723 | }; |
||
4724 | |||
4725 | }; |
||
4726 | |||
4727 | },{"./errors.js":10,"./errors_api_rejection":11,"./util.js":35}],34:[function(require,module,exports){ |
||
4728 | /** |
||
4729 | * Copyright (c) 2014 Petka Antonov |
||
4730 | * |
||
4731 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
||
4732 | * of this software and associated documentation files (the "Software"), to deal |
||
4733 | * in the Software without restriction, including without limitation the rights |
||
4734 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
4735 | * copies of the Software, and to permit persons to whom the Software is |
||
4736 | * furnished to do so, subject to the following conditions:</p> |
||
4737 | * |
||
4738 | * The above copyright notice and this permission notice shall be included in |
||
4739 | * all copies or substantial portions of the Software. |
||
4740 | * |
||
4741 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
4742 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
4743 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||
4744 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
4745 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
4746 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||
4747 | * THE SOFTWARE. |
||
4748 | * |
||
4749 | */ |
||
4750 | "use strict"; |
||
4751 | module.exports = function (Promise, apiRejection, cast) { |
||
4752 | var TypeError = require("./errors.js").TypeError; |
||
4753 | var inherits = require("./util.js").inherits; |
||
4754 | var PromiseInspection = Promise.PromiseInspection; |
||
4755 | |||
4756 | function inspectionMapper(inspections) { |
||
4757 | var len = inspections.length; |
||
4758 | for (var i = 0; i < len; ++i) { |
||
4759 | var inspection = inspections[i]; |
||
4760 | if (inspection.isRejected()) { |
||
4761 | return Promise.reject(inspection.error()); |
||
4762 | } |
||
4763 | inspections[i] = inspection.value(); |
||
4764 | } |
||
4765 | return inspections; |
||
4766 | } |
||
4767 | |||
4768 | function thrower(e) { |
||
4769 | setTimeout(function(){throw e;}, 0); |
||
4770 | } |
||
4771 | |||
4772 | function dispose(resources, inspection) { |
||
4773 | var i = 0; |
||
4774 | var len = resources.length; |
||
4775 | var ret = Promise.defer(); |
||
4776 | function iterator() { |
||
4777 | if (i >= len) return ret.resolve(); |
||
4778 | var maybePromise = cast(resources[i++], void 0); |
||
4779 | if (maybePromise instanceof Promise && |
||
4780 | maybePromise._isDisposable()) { |
||
4781 | try { |
||
4782 | maybePromise = cast(maybePromise._getDisposer() |
||
4783 | .tryDispose(inspection), void 0); |
||
4784 | } catch (e) { |
||
4785 | return thrower(e); |
||
4786 | } |
||
4787 | if (maybePromise instanceof Promise) { |
||
4788 | return maybePromise._then(iterator, thrower, |
||
4789 | null, null, null); |
||
4790 | } |
||
4791 | } |
||
4792 | iterator(); |
||
4793 | } |
||
4794 | iterator(); |
||
4795 | return ret.promise; |
||
4796 | } |
||
4797 | |||
4798 | function disposerSuccess(value) { |
||
4799 | var inspection = new PromiseInspection(); |
||
4800 | inspection._settledValue = value; |
||
4801 | inspection._bitField = 268435456; |
||
4802 | return dispose(this, inspection).thenReturn(value); |
||
4803 | } |
||
4804 | |||
4805 | function disposerFail(reason) { |
||
4806 | var inspection = new PromiseInspection(); |
||
4807 | inspection._settledValue = reason; |
||
4808 | inspection._bitField = 134217728; |
||
4809 | return dispose(this, inspection).thenThrow(reason); |
||
4810 | } |
||
4811 | |||
4812 | function Disposer(data, promise) { |
||
4813 | this._data = data; |
||
4814 | this._promise = promise; |
||
4815 | } |
||
4816 | |||
4817 | Disposer.prototype.data = function Disposer$data() { |
||
4818 | return this._data; |
||
4819 | }; |
||
4820 | |||
4821 | Disposer.prototype.promise = function Disposer$promise() { |
||
4822 | return this._promise; |
||
4823 | }; |
||
4824 | |||
4825 | Disposer.prototype.resource = function Disposer$resource() { |
||
4826 | if (this.promise().isFulfilled()) { |
||
4827 | return this.promise().value(); |
||
4828 | } |
||
4829 | return null; |
||
4830 | }; |
||
4831 | |||
4832 | Disposer.prototype.tryDispose = function(inspection) { |
||
4833 | var resource = this.resource(); |
||
4834 | var ret = resource !== null |
||
4835 | ? this.doDispose(resource, inspection) : null; |
||
4836 | this._promise._unsetDisposable(); |
||
4837 | this._data = this._promise = null; |
||
4838 | return ret; |
||
4839 | }; |
||
4840 | |||
4841 | function FunctionDisposer(fn, promise) { |
||
4842 | this.constructor$(fn, promise); |
||
4843 | } |
||
4844 | inherits(FunctionDisposer, Disposer); |
||
4845 | |||
4846 | FunctionDisposer.prototype.doDispose = function (resource, inspection) { |
||
4847 | var fn = this.data(); |
||
4848 | return fn.call(resource, resource, inspection); |
||
4849 | }; |
||
4850 | |||
4851 | Promise.using = function Promise$using() { |
||
4852 | var len = arguments.length; |
||
4853 | if (len < 2) return apiRejection( |
||
4854 | "you must pass at least 2 arguments to Promise.using"); |
||
4855 | var fn = arguments[len - 1]; |
||
4856 | if (typeof fn !== "function") return apiRejection("fn must be a function"); |
||
4857 | len--; |
||
4858 | var resources = new Array(len); |
||
4859 | for (var i = 0; i < len; ++i) { |
||
4860 | var resource = arguments[i]; |
||
4861 | if (resource instanceof Disposer) { |
||
4862 | var disposer = resource; |
||
4863 | resource = resource.promise(); |
||
4864 | resource._setDisposable(disposer); |
||
4865 | } |
||
4866 | resources[i] = resource; |
||
4867 | } |
||
4868 | |||
4869 | return Promise.settle(resources) |
||
4870 | .then(inspectionMapper) |
||
4871 | .spread(fn) |
||
4872 | ._then(disposerSuccess, disposerFail, void 0, resources, void 0); |
||
4873 | }; |
||
4874 | |||
4875 | Promise.prototype._setDisposable = |
||
4876 | function Promise$_setDisposable(disposer) { |
||
4877 | this._bitField = this._bitField | 262144; |
||
4878 | this._disposer = disposer; |
||
4879 | }; |
||
4880 | |||
4881 | Promise.prototype._isDisposable = function Promise$_isDisposable() { |
||
4882 | return (this._bitField & 262144) > 0; |
||
4883 | }; |
||
4884 | |||
4885 | Promise.prototype._getDisposer = function Promise$_getDisposer() { |
||
4886 | return this._disposer; |
||
4887 | }; |
||
4888 | |||
4889 | Promise.prototype._unsetDisposable = function Promise$_unsetDisposable() { |
||
4890 | this._bitField = this._bitField & (~262144); |
||
4891 | this._disposer = void 0; |
||
4892 | }; |
||
4893 | |||
4894 | Promise.prototype.disposer = function Promise$disposer(fn) { |
||
4895 | if (typeof fn === "function") { |
||
4896 | return new FunctionDisposer(fn, this); |
||
4897 | } |
||
4898 | throw new TypeError(); |
||
4899 | }; |
||
4900 | |||
4901 | }; |
||
4902 | |||
4903 | },{"./errors.js":10,"./util.js":35}],35:[function(require,module,exports){ |
||
4904 | /** |
||
4905 | * Copyright (c) 2014 Petka Antonov |
||
4906 | * |
||
4907 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
||
4908 | * of this software and associated documentation files (the "Software"), to deal |
||
4909 | * in the Software without restriction, including without limitation the rights |
||
4910 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
4911 | * copies of the Software, and to permit persons to whom the Software is |
||
4912 | * furnished to do so, subject to the following conditions:</p> |
||
4913 | * |
||
4914 | * The above copyright notice and this permission notice shall be included in |
||
4915 | * all copies or substantial portions of the Software. |
||
4916 | * |
||
4917 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
4918 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
4919 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||
4920 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
4921 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
4922 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||
4923 | * THE SOFTWARE. |
||
4924 | * |
||
4925 | */ |
||
4926 | "use strict"; |
||
4927 | var es5 = require("./es5.js"); |
||
4928 | var haveGetters = (function(){ |
||
4929 | try { |
||
4930 | var o = {}; |
||
4931 | es5.defineProperty(o, "f", { |
||
4932 | get: function () { |
||
4933 | return 3; |
||
4934 | } |
||
4935 | }); |
||
4936 | return o.f === 3; |
||
4937 | } |
||
4938 | catch (e) { |
||
4939 | return false; |
||
4940 | } |
||
4941 | |||
4942 | })(); |
||
4943 | var canEvaluate = typeof navigator == "undefined"; |
||
4944 | var errorObj = {e: {}}; |
||
4945 | function tryCatch1(fn, receiver, arg) { |
||
4946 | try { return fn.call(receiver, arg); } |
||
4947 | catch (e) { |
||
4948 | errorObj.e = e; |
||
4949 | return errorObj; |
||
4950 | } |
||
4951 | } |
||
4952 | |||
4953 | function tryCatch2(fn, receiver, arg, arg2) { |
||
4954 | try { return fn.call(receiver, arg, arg2); } |
||
4955 | catch (e) { |
||
4956 | errorObj.e = e; |
||
4957 | return errorObj; |
||
4958 | } |
||
4959 | } |
||
4960 | |||
4961 | function tryCatch3(fn, receiver, arg, arg2, arg3) { |
||
4962 | try { return fn.call(receiver, arg, arg2, arg3); } |
||
4963 | catch (e) { |
||
4964 | errorObj.e = e; |
||
4965 | return errorObj; |
||
4966 | } |
||
4967 | } |
||
4968 | |||
4969 | function tryCatch4(fn, receiver, arg, arg2, arg3, arg4) { |
||
4970 | try { return fn.call(receiver, arg, arg2, arg3, arg4); } |
||
4971 | catch (e) { |
||
4972 | errorObj.e = e; |
||
4973 | return errorObj; |
||
4974 | } |
||
4975 | } |
||
4976 | |||
4977 | function tryCatchApply(fn, args, receiver) { |
||
4978 | try { return fn.apply(receiver, args); } |
||
4979 | catch (e) { |
||
4980 | errorObj.e = e; |
||
4981 | return errorObj; |
||
4982 | } |
||
4983 | } |
||
4984 | |||
4985 | var inherits = function(Child, Parent) { |
||
4986 | var hasProp = {}.hasOwnProperty; |
||
4987 | |||
4988 | function T() { |
||
4989 | this.constructor = Child; |
||
4990 | this.constructor$ = Parent; |
||
4991 | for (var propertyName in Parent.prototype) { |
||
4992 | if (hasProp.call(Parent.prototype, propertyName) && |
||
4993 | propertyName.charAt(propertyName.length-1) !== "$" |
||
4994 | ) { |
||
4995 | this[propertyName + "$"] = Parent.prototype[propertyName]; |
||
4996 | } |
||
4997 | } |
||
4998 | } |
||
4999 | T.prototype = Parent.prototype; |
||
5000 | Child.prototype = new T(); |
||
5001 | return Child.prototype; |
||
5002 | }; |
||
5003 | |||
5004 | function asString(val) { |
||
5005 | return typeof val === "string" ? val : ("" + val); |
||
5006 | } |
||
5007 | |||
5008 | function isPrimitive(val) { |
||
5009 | return val == null || val === true || val === false || |
||
5010 | typeof val === "string" || typeof val === "number"; |
||
5011 | |||
5012 | } |
||
5013 | |||
5014 | function isObject(value) { |
||
5015 | return !isPrimitive(value); |
||
5016 | } |
||
5017 | |||
5018 | function maybeWrapAsError(maybeError) { |
||
5019 | if (!isPrimitive(maybeError)) return maybeError; |
||
5020 | |||
5021 | return new Error(asString(maybeError)); |
||
5022 | } |
||
5023 | |||
5024 | function withAppended(target, appendee) { |
||
5025 | var len = target.length; |
||
5026 | var ret = new Array(len + 1); |
||
5027 | var i; |
||
5028 | for (i = 0; i < len; ++i) { |
||
5029 | ret[i] = target[i]; |
||
5030 | } |
||
5031 | ret[i] = appendee; |
||
5032 | return ret; |
||
5033 | } |
||
5034 | |||
5035 | function getDataPropertyOrDefault(obj, key, defaultValue) { |
||
5036 | if (es5.isES5) { |
||
5037 | var desc = Object.getOwnPropertyDescriptor(obj, key); |
||
5038 | if (desc != null) { |
||
5039 | return desc.get == null && desc.set == null |
||
5040 | ? desc.value |
||
5041 | : defaultValue; |
||
5042 | } |
||
5043 | } else { |
||
5044 | return {}.hasOwnProperty.call(obj, key) ? obj[key] : void 0; |
||
5045 | } |
||
5046 | } |
||
5047 | |||
5048 | function notEnumerableProp(obj, name, value) { |
||
5049 | if (isPrimitive(obj)) return obj; |
||
5050 | var descriptor = { |
||
5051 | value: value, |
||
5052 | configurable: true, |
||
5053 | enumerable: false, |
||
5054 | writable: true |
||
5055 | }; |
||
5056 | es5.defineProperty(obj, name, descriptor); |
||
5057 | return obj; |
||
5058 | } |
||
5059 | |||
5060 | |||
5061 | var wrapsPrimitiveReceiver = (function() { |
||
5062 | return this !== "string"; |
||
5063 | }).call("string"); |
||
5064 | |||
5065 | function thrower(r) { |
||
5066 | throw r; |
||
5067 | } |
||
5068 | |||
5069 | var inheritedDataKeys = (function() { |
||
5070 | if (es5.isES5) { |
||
5071 | return function(obj, opts) { |
||
5072 | var ret = []; |
||
5073 | var visitedKeys = Object.create(null); |
||
5074 | var getKeys = Object(opts).includeHidden |
||
5075 | ? Object.getOwnPropertyNames |
||
5076 | : Object.keys; |
||
5077 | while (obj != null) { |
||
5078 | var keys; |
||
5079 | try { |
||
5080 | keys = getKeys(obj); |
||
5081 | } catch (e) { |
||
5082 | return ret; |
||
5083 | } |
||
5084 | for (var i = 0; i < keys.length; ++i) { |
||
5085 | var key = keys[i]; |
||
5086 | if (visitedKeys[key]) continue; |
||
5087 | visitedKeys[key] = true; |
||
5088 | var desc = Object.getOwnPropertyDescriptor(obj, key); |
||
5089 | if (desc != null && desc.get == null && desc.set == null) { |
||
5090 | ret.push(key); |
||
5091 | } |
||
5092 | } |
||
5093 | obj = es5.getPrototypeOf(obj); |
||
5094 | } |
||
5095 | return ret; |
||
5096 | }; |
||
5097 | } else { |
||
5098 | return function(obj) { |
||
5099 | var ret = []; |
||
5100 | /*jshint forin:false */ |
||
5101 | for (var key in obj) { |
||
5102 | ret.push(key); |
||
5103 | } |
||
5104 | return ret; |
||
5105 | }; |
||
5106 | } |
||
5107 | |||
5108 | })(); |
||
5109 | |||
5110 | function isClass(fn) { |
||
5111 | try { |
||
5112 | if (typeof fn === "function") { |
||
5113 | var keys = es5.keys(fn.prototype); |
||
5114 | return keys.length > 0 && |
||
5115 | !(keys.length === 1 && keys[0] === "constructor"); |
||
5116 | } |
||
5117 | return false; |
||
5118 | } catch (e) { |
||
5119 | return false; |
||
5120 | } |
||
5121 | } |
||
5122 | |||
5123 | function toFastProperties(obj) { |
||
5124 | /*jshint -W027*/ |
||
5125 | function f() {} |
||
5126 | f.prototype = obj; |
||
5127 | return f; |
||
5128 | eval(obj); |
||
5129 | } |
||
5130 | |||
5131 | var rident = /^[a-z$_][a-z$_0-9]*$/i; |
||
5132 | function isIdentifier(str) { |
||
5133 | return rident.test(str); |
||
5134 | } |
||
5135 | |||
5136 | function filledRange(count, prefix, suffix) { |
||
5137 | var ret = new Array(count); |
||
5138 | for(var i = 0; i < count; ++i) { |
||
5139 | ret[i] = prefix + i + suffix; |
||
5140 | } |
||
5141 | return ret; |
||
5142 | } |
||
5143 | |||
5144 | var ret = { |
||
5145 | isClass: isClass, |
||
5146 | isIdentifier: isIdentifier, |
||
5147 | inheritedDataKeys: inheritedDataKeys, |
||
5148 | getDataPropertyOrDefault: getDataPropertyOrDefault, |
||
5149 | thrower: thrower, |
||
5150 | isArray: es5.isArray, |
||
5151 | haveGetters: haveGetters, |
||
5152 | notEnumerableProp: notEnumerableProp, |
||
5153 | isPrimitive: isPrimitive, |
||
5154 | isObject: isObject, |
||
5155 | canEvaluate: canEvaluate, |
||
5156 | errorObj: errorObj, |
||
5157 | tryCatch1: tryCatch1, |
||
5158 | tryCatch2: tryCatch2, |
||
5159 | tryCatch3: tryCatch3, |
||
5160 | tryCatch4: tryCatch4, |
||
5161 | tryCatchApply: tryCatchApply, |
||
5162 | inherits: inherits, |
||
5163 | withAppended: withAppended, |
||
5164 | asString: asString, |
||
5165 | maybeWrapAsError: maybeWrapAsError, |
||
5166 | wrapsPrimitiveReceiver: wrapsPrimitiveReceiver, |
||
5167 | toFastProperties: toFastProperties, |
||
5168 | filledRange: filledRange |
||
5169 | }; |
||
5170 | |||
5171 | module.exports = ret; |
||
5172 | |||
5173 | },{"./es5.js":12}]},{},[3]) |
||
5174 | (3) |
||
5175 | }); |
||
5176 | ; |