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