7aac1496d5f4f0e635f4d045b69e2400473d01f9
[aai/esr-gui.git] /
1 "use strict";
2 module.exports = function(Promise) {
3 function PromiseInspection(promise) {
4     if (promise !== undefined) {
5         promise = promise._target();
6         this._bitField = promise._bitField;
7         this._settledValue = promise._settledValue;
8     }
9     else {
10         this._bitField = 0;
11         this._settledValue = undefined;
12     }
13 }
14
15 PromiseInspection.prototype.value = function () {
16     if (!this.isFulfilled()) {
17         throw new TypeError("cannot get fulfillment value of a non-fulfilled promise\u000a\u000a    See http://goo.gl/hc1DLj\u000a");
18     }
19     return this._settledValue;
20 };
21
22 PromiseInspection.prototype.error =
23 PromiseInspection.prototype.reason = function () {
24     if (!this.isRejected()) {
25         throw new TypeError("cannot get rejection reason of a non-rejected promise\u000a\u000a    See http://goo.gl/hPuiwB\u000a");
26     }
27     return this._settledValue;
28 };
29
30 PromiseInspection.prototype.isFulfilled =
31 Promise.prototype._isFulfilled = function () {
32     return (this._bitField & 268435456) > 0;
33 };
34
35 PromiseInspection.prototype.isRejected =
36 Promise.prototype._isRejected = function () {
37     return (this._bitField & 134217728) > 0;
38 };
39
40 PromiseInspection.prototype.isPending =
41 Promise.prototype._isPending = function () {
42     return (this._bitField & 402653184) === 0;
43 };
44
45 PromiseInspection.prototype.isResolved =
46 Promise.prototype._isResolved = function () {
47     return (this._bitField & 402653184) > 0;
48 };
49
50 Promise.prototype.isPending = function() {
51     return this._target()._isPending();
52 };
53
54 Promise.prototype.isRejected = function() {
55     return this._target()._isRejected();
56 };
57
58 Promise.prototype.isFulfilled = function() {
59     return this._target()._isFulfilled();
60 };
61
62 Promise.prototype.isResolved = function() {
63     return this._target()._isResolved();
64 };
65
66 Promise.prototype._value = function() {
67     return this._settledValue;
68 };
69
70 Promise.prototype._reason = function() {
71     this._unsetRejectionIsUnhandled();
72     return this._settledValue;
73 };
74
75 Promise.prototype.value = function() {
76     var target = this._target();
77     if (!target.isFulfilled()) {
78         throw new TypeError("cannot get fulfillment value of a non-fulfilled promise\u000a\u000a    See http://goo.gl/hc1DLj\u000a");
79     }
80     return target._settledValue;
81 };
82
83 Promise.prototype.reason = function() {
84     var target = this._target();
85     if (!target.isRejected()) {
86         throw new TypeError("cannot get rejection reason of a non-rejected promise\u000a\u000a    See http://goo.gl/hPuiwB\u000a");
87     }
88     target._unsetRejectionIsUnhandled();
89     return target._settledValue;
90 };
91
92
93 Promise.PromiseInspection = PromiseInspection;
94 };