UNPKG

2.81 kBJavaScriptView Raw
1"use strict";
2module.exports = function(Promise) {
3function PromiseInspection(promise) {
4 if (promise !== undefined) {
5 promise = promise._target();
6 this._bitField = promise._bitField;
7 this._settledValueField = promise._isFateSealed()
8 ? promise._settledValue() : undefined;
9 }
10 else {
11 this._bitField = 0;
12 this._settledValueField = undefined;
13 }
14}
15
16PromiseInspection.prototype._settledValue = function() {
17 return this._settledValueField;
18};
19
20var value = PromiseInspection.prototype.value = function () {
21 if (!this.isFulfilled()) {
22 throw new TypeError("cannot get fulfillment value of a non-fulfilled promise\u000a\u000a See http://goo.gl/MqrFmX\u000a");
23 }
24 return this._settledValue();
25};
26
27var reason = PromiseInspection.prototype.error =
28PromiseInspection.prototype.reason = function () {
29 if (!this.isRejected()) {
30 throw new TypeError("cannot get rejection reason of a non-rejected promise\u000a\u000a See http://goo.gl/MqrFmX\u000a");
31 }
32 return this._settledValue();
33};
34
35var isFulfilled = PromiseInspection.prototype.isFulfilled = function() {
36 return (this._bitField & 33554432) !== 0;
37};
38
39var isRejected = PromiseInspection.prototype.isRejected = function () {
40 return (this._bitField & 16777216) !== 0;
41};
42
43var isPending = PromiseInspection.prototype.isPending = function () {
44 return (this._bitField & 50397184) === 0;
45};
46
47var isResolved = PromiseInspection.prototype.isResolved = function () {
48 return (this._bitField & 50331648) !== 0;
49};
50
51PromiseInspection.prototype.isCancelled = function() {
52 return (this._bitField & 8454144) !== 0;
53};
54
55Promise.prototype.__isCancelled = function() {
56 return (this._bitField & 65536) === 65536;
57};
58
59Promise.prototype._isCancelled = function() {
60 return this._target().__isCancelled();
61};
62
63Promise.prototype.isCancelled = function() {
64 return (this._target()._bitField & 8454144) !== 0;
65};
66
67Promise.prototype.isPending = function() {
68 return isPending.call(this._target());
69};
70
71Promise.prototype.isRejected = function() {
72 return isRejected.call(this._target());
73};
74
75Promise.prototype.isFulfilled = function() {
76 return isFulfilled.call(this._target());
77};
78
79Promise.prototype.isResolved = function() {
80 return isResolved.call(this._target());
81};
82
83Promise.prototype.value = function() {
84 return value.call(this._target());
85};
86
87Promise.prototype.reason = function() {
88 var target = this._target();
89 target._unsetRejectionIsUnhandled();
90 return reason.call(target);
91};
92
93Promise.prototype._value = function() {
94 return this._settledValue();
95};
96
97Promise.prototype._reason = function() {
98 this._unsetRejectionIsUnhandled();
99 return this._settledValue();
100};
101
102Promise.PromiseInspection = PromiseInspection;
103};