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;
11 this._settledValue = undefined;
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");
19 return this._settledValue;
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");
27 return this._settledValue;
30 PromiseInspection.prototype.isFulfilled =
31 Promise.prototype._isFulfilled = function () {
32 return (this._bitField & 268435456) > 0;
35 PromiseInspection.prototype.isRejected =
36 Promise.prototype._isRejected = function () {
37 return (this._bitField & 134217728) > 0;
40 PromiseInspection.prototype.isPending =
41 Promise.prototype._isPending = function () {
42 return (this._bitField & 402653184) === 0;
45 PromiseInspection.prototype.isResolved =
46 Promise.prototype._isResolved = function () {
47 return (this._bitField & 402653184) > 0;
50 Promise.prototype.isPending = function() {
51 return this._target()._isPending();
54 Promise.prototype.isRejected = function() {
55 return this._target()._isRejected();
58 Promise.prototype.isFulfilled = function() {
59 return this._target()._isFulfilled();
62 Promise.prototype.isResolved = function() {
63 return this._target()._isResolved();
66 Promise.prototype._value = function() {
67 return this._settledValue;
70 Promise.prototype._reason = function() {
71 this._unsetRejectionIsUnhandled();
72 return this._settledValue;
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");
80 return target._settledValue;
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");
88 target._unsetRejectionIsUnhandled();
89 return target._settledValue;
93 Promise.PromiseInspection = PromiseInspection;