• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"use strict";
2module.exports = function() {
3var makeSelfResolutionError = function () {
4    return new TypeError("circular promise resolution chain\u000a\u000a    See http://goo.gl/MqrFmX\u000a");
5};
6var reflectHandler = function() {
7    return new Promise.PromiseInspection(this._target());
8};
9var apiRejection = function(msg) {
10    return Promise.reject(new TypeError(msg));
11};
12function Proxyable() {}
13var UNDEFINED_BINDING = {};
14var util = require("./util");
15
16var getDomain;
17if (util.isNode) {
18    getDomain = function() {
19        var ret = process.domain;
20        if (ret === undefined) ret = null;
21        return ret;
22    };
23} else {
24    getDomain = function() {
25        return null;
26    };
27}
28util.notEnumerableProp(Promise, "_getDomain", getDomain);
29
30var es5 = require("./es5");
31var Async = require("./async");
32var async = new Async();
33es5.defineProperty(Promise, "_async", {value: async});
34var errors = require("./errors");
35var TypeError = Promise.TypeError = errors.TypeError;
36Promise.RangeError = errors.RangeError;
37var CancellationError = Promise.CancellationError = errors.CancellationError;
38Promise.TimeoutError = errors.TimeoutError;
39Promise.OperationalError = errors.OperationalError;
40Promise.RejectionError = errors.OperationalError;
41Promise.AggregateError = errors.AggregateError;
42var INTERNAL = function(){};
43var APPLY = {};
44var NEXT_FILTER = {};
45var tryConvertToPromise = require("./thenables")(Promise, INTERNAL);
46var PromiseArray =
47    require("./promise_array")(Promise, INTERNAL,
48                               tryConvertToPromise, apiRejection, Proxyable);
49var Context = require("./context")(Promise);
50 /*jshint unused:false*/
51var createContext = Context.create;
52var debug = require("./debuggability")(Promise, Context);
53var CapturedTrace = debug.CapturedTrace;
54var PassThroughHandlerContext =
55    require("./finally")(Promise, tryConvertToPromise, NEXT_FILTER);
56var catchFilter = require("./catch_filter")(NEXT_FILTER);
57var nodebackForPromise = require("./nodeback");
58var errorObj = util.errorObj;
59var tryCatch = util.tryCatch;
60function check(self, executor) {
61    if (self == null || self.constructor !== Promise) {
62        throw new TypeError("the promise constructor cannot be invoked directly\u000a\u000a    See http://goo.gl/MqrFmX\u000a");
63    }
64    if (typeof executor !== "function") {
65        throw new TypeError("expecting a function but got " + util.classString(executor));
66    }
67
68}
69
70function Promise(executor) {
71    if (executor !== INTERNAL) {
72        check(this, executor);
73    }
74    this._bitField = 0;
75    this._fulfillmentHandler0 = undefined;
76    this._rejectionHandler0 = undefined;
77    this._promise0 = undefined;
78    this._receiver0 = undefined;
79    this._resolveFromExecutor(executor);
80    this._promiseCreated();
81    this._fireEvent("promiseCreated", this);
82}
83
84Promise.prototype.toString = function () {
85    return "[object Promise]";
86};
87
88Promise.prototype.caught = Promise.prototype["catch"] = function (fn) {
89    var len = arguments.length;
90    if (len > 1) {
91        var catchInstances = new Array(len - 1),
92            j = 0, i;
93        for (i = 0; i < len - 1; ++i) {
94            var item = arguments[i];
95            if (util.isObject(item)) {
96                catchInstances[j++] = item;
97            } else {
98                return apiRejection("Catch statement predicate: " +
99                    "expecting an object but got " + util.classString(item));
100            }
101        }
102        catchInstances.length = j;
103        fn = arguments[i];
104
105        if (typeof fn !== "function") {
106            throw new TypeError("The last argument to .catch() " +
107                "must be a function, got " + util.toString(fn));
108        }
109        return this.then(undefined, catchFilter(catchInstances, fn, this));
110    }
111    return this.then(undefined, fn);
112};
113
114Promise.prototype.reflect = function () {
115    return this._then(reflectHandler,
116        reflectHandler, undefined, this, undefined);
117};
118
119Promise.prototype.then = function (didFulfill, didReject) {
120    if (debug.warnings() && arguments.length > 0 &&
121        typeof didFulfill !== "function" &&
122        typeof didReject !== "function") {
123        var msg = ".then() only accepts functions but was passed: " +
124                util.classString(didFulfill);
125        if (arguments.length > 1) {
126            msg += ", " + util.classString(didReject);
127        }
128        this._warn(msg);
129    }
130    return this._then(didFulfill, didReject, undefined, undefined, undefined);
131};
132
133Promise.prototype.done = function (didFulfill, didReject) {
134    var promise =
135        this._then(didFulfill, didReject, undefined, undefined, undefined);
136    promise._setIsFinal();
137};
138
139Promise.prototype.spread = function (fn) {
140    if (typeof fn !== "function") {
141        return apiRejection("expecting a function but got " + util.classString(fn));
142    }
143    return this.all()._then(fn, undefined, undefined, APPLY, undefined);
144};
145
146Promise.prototype.toJSON = function () {
147    var ret = {
148        isFulfilled: false,
149        isRejected: false,
150        fulfillmentValue: undefined,
151        rejectionReason: undefined
152    };
153    if (this.isFulfilled()) {
154        ret.fulfillmentValue = this.value();
155        ret.isFulfilled = true;
156    } else if (this.isRejected()) {
157        ret.rejectionReason = this.reason();
158        ret.isRejected = true;
159    }
160    return ret;
161};
162
163Promise.prototype.all = function () {
164    if (arguments.length > 0) {
165        this._warn(".all() was passed arguments but it does not take any");
166    }
167    return new PromiseArray(this).promise();
168};
169
170Promise.prototype.error = function (fn) {
171    return this.caught(util.originatesFromRejection, fn);
172};
173
174Promise.getNewLibraryCopy = module.exports;
175
176Promise.is = function (val) {
177    return val instanceof Promise;
178};
179
180Promise.fromNode = Promise.fromCallback = function(fn) {
181    var ret = new Promise(INTERNAL);
182    ret._captureStackTrace();
183    var multiArgs = arguments.length > 1 ? !!Object(arguments[1]).multiArgs
184                                         : false;
185    var result = tryCatch(fn)(nodebackForPromise(ret, multiArgs));
186    if (result === errorObj) {
187        ret._rejectCallback(result.e, true);
188    }
189    if (!ret._isFateSealed()) ret._setAsyncGuaranteed();
190    return ret;
191};
192
193Promise.all = function (promises) {
194    return new PromiseArray(promises).promise();
195};
196
197Promise.cast = function (obj) {
198    var ret = tryConvertToPromise(obj);
199    if (!(ret instanceof Promise)) {
200        ret = new Promise(INTERNAL);
201        ret._captureStackTrace();
202        ret._setFulfilled();
203        ret._rejectionHandler0 = obj;
204    }
205    return ret;
206};
207
208Promise.resolve = Promise.fulfilled = Promise.cast;
209
210Promise.reject = Promise.rejected = function (reason) {
211    var ret = new Promise(INTERNAL);
212    ret._captureStackTrace();
213    ret._rejectCallback(reason, true);
214    return ret;
215};
216
217Promise.setScheduler = function(fn) {
218    if (typeof fn !== "function") {
219        throw new TypeError("expecting a function but got " + util.classString(fn));
220    }
221    return async.setScheduler(fn);
222};
223
224Promise.prototype._then = function (
225    didFulfill,
226    didReject,
227    _,    receiver,
228    internalData
229) {
230    var haveInternalData = internalData !== undefined;
231    var promise = haveInternalData ? internalData : new Promise(INTERNAL);
232    var target = this._target();
233    var bitField = target._bitField;
234
235    if (!haveInternalData) {
236        promise._propagateFrom(this, 3);
237        promise._captureStackTrace();
238        if (receiver === undefined &&
239            ((this._bitField & 2097152) !== 0)) {
240            if (!((bitField & 50397184) === 0)) {
241                receiver = this._boundValue();
242            } else {
243                receiver = target === this ? undefined : this._boundTo;
244            }
245        }
246        this._fireEvent("promiseChained", this, promise);
247    }
248
249    var domain = getDomain();
250    if (!((bitField & 50397184) === 0)) {
251        var handler, value, settler = target._settlePromiseCtx;
252        if (((bitField & 33554432) !== 0)) {
253            value = target._rejectionHandler0;
254            handler = didFulfill;
255        } else if (((bitField & 16777216) !== 0)) {
256            value = target._fulfillmentHandler0;
257            handler = didReject;
258            target._unsetRejectionIsUnhandled();
259        } else {
260            settler = target._settlePromiseLateCancellationObserver;
261            value = new CancellationError("late cancellation observer");
262            target._attachExtraTrace(value);
263            handler = didReject;
264        }
265
266        async.invoke(settler, target, {
267            handler: domain === null ? handler
268                : (typeof handler === "function" &&
269                    util.domainBind(domain, handler)),
270            promise: promise,
271            receiver: receiver,
272            value: value
273        });
274    } else {
275        target._addCallbacks(didFulfill, didReject, promise, receiver, domain);
276    }
277
278    return promise;
279};
280
281Promise.prototype._length = function () {
282    return this._bitField & 65535;
283};
284
285Promise.prototype._isFateSealed = function () {
286    return (this._bitField & 117506048) !== 0;
287};
288
289Promise.prototype._isFollowing = function () {
290    return (this._bitField & 67108864) === 67108864;
291};
292
293Promise.prototype._setLength = function (len) {
294    this._bitField = (this._bitField & -65536) |
295        (len & 65535);
296};
297
298Promise.prototype._setFulfilled = function () {
299    this._bitField = this._bitField | 33554432;
300    this._fireEvent("promiseFulfilled", this);
301};
302
303Promise.prototype._setRejected = function () {
304    this._bitField = this._bitField | 16777216;
305    this._fireEvent("promiseRejected", this);
306};
307
308Promise.prototype._setFollowing = function () {
309    this._bitField = this._bitField | 67108864;
310    this._fireEvent("promiseResolved", this);
311};
312
313Promise.prototype._setIsFinal = function () {
314    this._bitField = this._bitField | 4194304;
315};
316
317Promise.prototype._isFinal = function () {
318    return (this._bitField & 4194304) > 0;
319};
320
321Promise.prototype._unsetCancelled = function() {
322    this._bitField = this._bitField & (~65536);
323};
324
325Promise.prototype._setCancelled = function() {
326    this._bitField = this._bitField | 65536;
327    this._fireEvent("promiseCancelled", this);
328};
329
330Promise.prototype._setWillBeCancelled = function() {
331    this._bitField = this._bitField | 8388608;
332};
333
334Promise.prototype._setAsyncGuaranteed = function() {
335    if (async.hasCustomScheduler()) return;
336    this._bitField = this._bitField | 134217728;
337};
338
339Promise.prototype._receiverAt = function (index) {
340    var ret = index === 0 ? this._receiver0 : this[
341            index * 4 - 4 + 3];
342    if (ret === UNDEFINED_BINDING) {
343        return undefined;
344    } else if (ret === undefined && this._isBound()) {
345        return this._boundValue();
346    }
347    return ret;
348};
349
350Promise.prototype._promiseAt = function (index) {
351    return this[
352            index * 4 - 4 + 2];
353};
354
355Promise.prototype._fulfillmentHandlerAt = function (index) {
356    return this[
357            index * 4 - 4 + 0];
358};
359
360Promise.prototype._rejectionHandlerAt = function (index) {
361    return this[
362            index * 4 - 4 + 1];
363};
364
365Promise.prototype._boundValue = function() {};
366
367Promise.prototype._migrateCallback0 = function (follower) {
368    var bitField = follower._bitField;
369    var fulfill = follower._fulfillmentHandler0;
370    var reject = follower._rejectionHandler0;
371    var promise = follower._promise0;
372    var receiver = follower._receiverAt(0);
373    if (receiver === undefined) receiver = UNDEFINED_BINDING;
374    this._addCallbacks(fulfill, reject, promise, receiver, null);
375};
376
377Promise.prototype._migrateCallbackAt = function (follower, index) {
378    var fulfill = follower._fulfillmentHandlerAt(index);
379    var reject = follower._rejectionHandlerAt(index);
380    var promise = follower._promiseAt(index);
381    var receiver = follower._receiverAt(index);
382    if (receiver === undefined) receiver = UNDEFINED_BINDING;
383    this._addCallbacks(fulfill, reject, promise, receiver, null);
384};
385
386Promise.prototype._addCallbacks = function (
387    fulfill,
388    reject,
389    promise,
390    receiver,
391    domain
392) {
393    var index = this._length();
394
395    if (index >= 65535 - 4) {
396        index = 0;
397        this._setLength(0);
398    }
399
400    if (index === 0) {
401        this._promise0 = promise;
402        this._receiver0 = receiver;
403        if (typeof fulfill === "function") {
404            this._fulfillmentHandler0 =
405                domain === null ? fulfill : util.domainBind(domain, fulfill);
406        }
407        if (typeof reject === "function") {
408            this._rejectionHandler0 =
409                domain === null ? reject : util.domainBind(domain, reject);
410        }
411    } else {
412        var base = index * 4 - 4;
413        this[base + 2] = promise;
414        this[base + 3] = receiver;
415        if (typeof fulfill === "function") {
416            this[base + 0] =
417                domain === null ? fulfill : util.domainBind(domain, fulfill);
418        }
419        if (typeof reject === "function") {
420            this[base + 1] =
421                domain === null ? reject : util.domainBind(domain, reject);
422        }
423    }
424    this._setLength(index + 1);
425    return index;
426};
427
428Promise.prototype._proxy = function (proxyable, arg) {
429    this._addCallbacks(undefined, undefined, arg, proxyable, null);
430};
431
432Promise.prototype._resolveCallback = function(value, shouldBind) {
433    if (((this._bitField & 117506048) !== 0)) return;
434    if (value === this)
435        return this._rejectCallback(makeSelfResolutionError(), false);
436    var maybePromise = tryConvertToPromise(value, this);
437    if (!(maybePromise instanceof Promise)) return this._fulfill(value);
438
439    if (shouldBind) this._propagateFrom(maybePromise, 2);
440
441    var promise = maybePromise._target();
442
443    if (promise === this) {
444        this._reject(makeSelfResolutionError());
445        return;
446    }
447
448    var bitField = promise._bitField;
449    if (((bitField & 50397184) === 0)) {
450        var len = this._length();
451        if (len > 0) promise._migrateCallback0(this);
452        for (var i = 1; i < len; ++i) {
453            promise._migrateCallbackAt(this, i);
454        }
455        this._setFollowing();
456        this._setLength(0);
457        this._setFollowee(promise);
458    } else if (((bitField & 33554432) !== 0)) {
459        this._fulfill(promise._value());
460    } else if (((bitField & 16777216) !== 0)) {
461        this._reject(promise._reason());
462    } else {
463        var reason = new CancellationError("late cancellation observer");
464        promise._attachExtraTrace(reason);
465        this._reject(reason);
466    }
467};
468
469Promise.prototype._rejectCallback =
470function(reason, synchronous, ignoreNonErrorWarnings) {
471    var trace = util.ensureErrorObject(reason);
472    var hasStack = trace === reason;
473    if (!hasStack && !ignoreNonErrorWarnings && debug.warnings()) {
474        var message = "a promise was rejected with a non-error: " +
475            util.classString(reason);
476        this._warn(message, true);
477    }
478    this._attachExtraTrace(trace, synchronous ? hasStack : false);
479    this._reject(reason);
480};
481
482Promise.prototype._resolveFromExecutor = function (executor) {
483    if (executor === INTERNAL) return;
484    var promise = this;
485    this._captureStackTrace();
486    this._pushContext();
487    var synchronous = true;
488    var r = this._execute(executor, function(value) {
489        promise._resolveCallback(value);
490    }, function (reason) {
491        promise._rejectCallback(reason, synchronous);
492    });
493    synchronous = false;
494    this._popContext();
495
496    if (r !== undefined) {
497        promise._rejectCallback(r, true);
498    }
499};
500
501Promise.prototype._settlePromiseFromHandler = function (
502    handler, receiver, value, promise
503) {
504    var bitField = promise._bitField;
505    if (((bitField & 65536) !== 0)) return;
506    promise._pushContext();
507    var x;
508    if (receiver === APPLY) {
509        if (!value || typeof value.length !== "number") {
510            x = errorObj;
511            x.e = new TypeError("cannot .spread() a non-array: " +
512                                    util.classString(value));
513        } else {
514            x = tryCatch(handler).apply(this._boundValue(), value);
515        }
516    } else {
517        x = tryCatch(handler).call(receiver, value);
518    }
519    var promiseCreated = promise._popContext();
520    bitField = promise._bitField;
521    if (((bitField & 65536) !== 0)) return;
522
523    if (x === NEXT_FILTER) {
524        promise._reject(value);
525    } else if (x === errorObj) {
526        promise._rejectCallback(x.e, false);
527    } else {
528        debug.checkForgottenReturns(x, promiseCreated, "",  promise, this);
529        promise._resolveCallback(x);
530    }
531};
532
533Promise.prototype._target = function() {
534    var ret = this;
535    while (ret._isFollowing()) ret = ret._followee();
536    return ret;
537};
538
539Promise.prototype._followee = function() {
540    return this._rejectionHandler0;
541};
542
543Promise.prototype._setFollowee = function(promise) {
544    this._rejectionHandler0 = promise;
545};
546
547Promise.prototype._settlePromise = function(promise, handler, receiver, value) {
548    var isPromise = promise instanceof Promise;
549    var bitField = this._bitField;
550    var asyncGuaranteed = ((bitField & 134217728) !== 0);
551    if (((bitField & 65536) !== 0)) {
552        if (isPromise) promise._invokeInternalOnCancel();
553
554        if (receiver instanceof PassThroughHandlerContext &&
555            receiver.isFinallyHandler()) {
556            receiver.cancelPromise = promise;
557            if (tryCatch(handler).call(receiver, value) === errorObj) {
558                promise._reject(errorObj.e);
559            }
560        } else if (handler === reflectHandler) {
561            promise._fulfill(reflectHandler.call(receiver));
562        } else if (receiver instanceof Proxyable) {
563            receiver._promiseCancelled(promise);
564        } else if (isPromise || promise instanceof PromiseArray) {
565            promise._cancel();
566        } else {
567            receiver.cancel();
568        }
569    } else if (typeof handler === "function") {
570        if (!isPromise) {
571            handler.call(receiver, value, promise);
572        } else {
573            if (asyncGuaranteed) promise._setAsyncGuaranteed();
574            this._settlePromiseFromHandler(handler, receiver, value, promise);
575        }
576    } else if (receiver instanceof Proxyable) {
577        if (!receiver._isResolved()) {
578            if (((bitField & 33554432) !== 0)) {
579                receiver._promiseFulfilled(value, promise);
580            } else {
581                receiver._promiseRejected(value, promise);
582            }
583        }
584    } else if (isPromise) {
585        if (asyncGuaranteed) promise._setAsyncGuaranteed();
586        if (((bitField & 33554432) !== 0)) {
587            promise._fulfill(value);
588        } else {
589            promise._reject(value);
590        }
591    }
592};
593
594Promise.prototype._settlePromiseLateCancellationObserver = function(ctx) {
595    var handler = ctx.handler;
596    var promise = ctx.promise;
597    var receiver = ctx.receiver;
598    var value = ctx.value;
599    if (typeof handler === "function") {
600        if (!(promise instanceof Promise)) {
601            handler.call(receiver, value, promise);
602        } else {
603            this._settlePromiseFromHandler(handler, receiver, value, promise);
604        }
605    } else if (promise instanceof Promise) {
606        promise._reject(value);
607    }
608};
609
610Promise.prototype._settlePromiseCtx = function(ctx) {
611    this._settlePromise(ctx.promise, ctx.handler, ctx.receiver, ctx.value);
612};
613
614Promise.prototype._settlePromise0 = function(handler, value, bitField) {
615    var promise = this._promise0;
616    var receiver = this._receiverAt(0);
617    this._promise0 = undefined;
618    this._receiver0 = undefined;
619    this._settlePromise(promise, handler, receiver, value);
620};
621
622Promise.prototype._clearCallbackDataAtIndex = function(index) {
623    var base = index * 4 - 4;
624    this[base + 2] =
625    this[base + 3] =
626    this[base + 0] =
627    this[base + 1] = undefined;
628};
629
630Promise.prototype._fulfill = function (value) {
631    var bitField = this._bitField;
632    if (((bitField & 117506048) >>> 16)) return;
633    if (value === this) {
634        var err = makeSelfResolutionError();
635        this._attachExtraTrace(err);
636        return this._reject(err);
637    }
638    this._setFulfilled();
639    this._rejectionHandler0 = value;
640
641    if ((bitField & 65535) > 0) {
642        if (((bitField & 134217728) !== 0)) {
643            this._settlePromises();
644        } else {
645            async.settlePromises(this);
646        }
647        this._dereferenceTrace();
648    }
649};
650
651Promise.prototype._reject = function (reason) {
652    var bitField = this._bitField;
653    if (((bitField & 117506048) >>> 16)) return;
654    this._setRejected();
655    this._fulfillmentHandler0 = reason;
656
657    if (this._isFinal()) {
658        return async.fatalError(reason, util.isNode);
659    }
660
661    if ((bitField & 65535) > 0) {
662        async.settlePromises(this);
663    } else {
664        this._ensurePossibleRejectionHandled();
665    }
666};
667
668Promise.prototype._fulfillPromises = function (len, value) {
669    for (var i = 1; i < len; i++) {
670        var handler = this._fulfillmentHandlerAt(i);
671        var promise = this._promiseAt(i);
672        var receiver = this._receiverAt(i);
673        this._clearCallbackDataAtIndex(i);
674        this._settlePromise(promise, handler, receiver, value);
675    }
676};
677
678Promise.prototype._rejectPromises = function (len, reason) {
679    for (var i = 1; i < len; i++) {
680        var handler = this._rejectionHandlerAt(i);
681        var promise = this._promiseAt(i);
682        var receiver = this._receiverAt(i);
683        this._clearCallbackDataAtIndex(i);
684        this._settlePromise(promise, handler, receiver, reason);
685    }
686};
687
688Promise.prototype._settlePromises = function () {
689    var bitField = this._bitField;
690    var len = (bitField & 65535);
691
692    if (len > 0) {
693        if (((bitField & 16842752) !== 0)) {
694            var reason = this._fulfillmentHandler0;
695            this._settlePromise0(this._rejectionHandler0, reason, bitField);
696            this._rejectPromises(len, reason);
697        } else {
698            var value = this._rejectionHandler0;
699            this._settlePromise0(this._fulfillmentHandler0, value, bitField);
700            this._fulfillPromises(len, value);
701        }
702        this._setLength(0);
703    }
704    this._clearCancellationData();
705};
706
707Promise.prototype._settledValue = function() {
708    var bitField = this._bitField;
709    if (((bitField & 33554432) !== 0)) {
710        return this._rejectionHandler0;
711    } else if (((bitField & 16777216) !== 0)) {
712        return this._fulfillmentHandler0;
713    }
714};
715
716if (typeof Symbol !== "undefined" && Symbol.toStringTag) {
717    es5.defineProperty(Promise.prototype, Symbol.toStringTag, {
718        get: function () {
719            return "Object";
720        }
721    });
722}
723
724function deferResolve(v) {this.promise._resolveCallback(v);}
725function deferReject(v) {this.promise._rejectCallback(v, false);}
726
727Promise.defer = Promise.pending = function() {
728    debug.deprecated("Promise.defer", "new Promise");
729    var promise = new Promise(INTERNAL);
730    return {
731        promise: promise,
732        resolve: deferResolve,
733        reject: deferReject
734    };
735};
736
737util.notEnumerableProp(Promise,
738                       "_makeSelfResolutionError",
739                       makeSelfResolutionError);
740
741require("./method")(Promise, INTERNAL, tryConvertToPromise, apiRejection,
742    debug);
743require("./bind")(Promise, INTERNAL, tryConvertToPromise, debug);
744require("./cancel")(Promise, PromiseArray, apiRejection, debug);
745require("./direct_resolve")(Promise);
746require("./synchronous_inspection")(Promise);
747require("./join")(
748    Promise, PromiseArray, tryConvertToPromise, INTERNAL, async, getDomain);
749Promise.Promise = Promise;
750Promise.version = "3.5.5";
751require('./call_get.js')(Promise);
752require('./generators.js')(Promise, apiRejection, INTERNAL, tryConvertToPromise, Proxyable, debug);
753require('./map.js')(Promise, PromiseArray, apiRejection, tryConvertToPromise, INTERNAL, debug);
754require('./nodeify.js')(Promise);
755require('./promisify.js')(Promise, INTERNAL);
756require('./props.js')(Promise, PromiseArray, tryConvertToPromise, apiRejection);
757require('./race.js')(Promise, INTERNAL, tryConvertToPromise, apiRejection);
758require('./reduce.js')(Promise, PromiseArray, apiRejection, tryConvertToPromise, INTERNAL, debug);
759require('./settle.js')(Promise, PromiseArray, debug);
760require('./some.js')(Promise, PromiseArray, apiRejection);
761require('./timers.js')(Promise, INTERNAL, debug);
762require('./using.js')(Promise, apiRejection, tryConvertToPromise, createContext, INTERNAL, debug);
763require('./any.js')(Promise);
764require('./each.js')(Promise, INTERNAL);
765require('./filter.js')(Promise, INTERNAL);
766
767    util.toFastProperties(Promise);
768    util.toFastProperties(Promise.prototype);
769    function fillTypes(value) {
770        var p = new Promise(INTERNAL);
771        p._fulfillmentHandler0 = value;
772        p._rejectionHandler0 = value;
773        p._promise0 = value;
774        p._receiver0 = value;
775    }
776    // Complete slack tracking, opt out of field-type tracking and
777    // stabilize map
778    fillTypes({a: 1});
779    fillTypes({b: 2});
780    fillTypes({c: 3});
781    fillTypes(1);
782    fillTypes(function(){});
783    fillTypes(undefined);
784    fillTypes(false);
785    fillTypes(new Promise(INTERNAL));
786    debug.setBounds(Async.firstLineError, util.lastLineError);
787    return Promise;
788
789};
790