Version 1
[yaffs-website] / node_modules / bluebird / js / release / synchronous_inspection.js
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._settledValueField = promise._isFateSealed()
8             ? promise._settledValue() : undefined;
9     }
10     else {
11         this._bitField = 0;
12         this._settledValueField = undefined;
13     }
14 }
15
16 PromiseInspection.prototype._settledValue = function() {
17     return this._settledValueField;
18 };
19
20 var 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
27 var reason = PromiseInspection.prototype.error =
28 PromiseInspection.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
35 var isFulfilled = PromiseInspection.prototype.isFulfilled = function() {
36     return (this._bitField & 33554432) !== 0;
37 };
38
39 var isRejected = PromiseInspection.prototype.isRejected = function () {
40     return (this._bitField & 16777216) !== 0;
41 };
42
43 var isPending = PromiseInspection.prototype.isPending = function () {
44     return (this._bitField & 50397184) === 0;
45 };
46
47 var isResolved = PromiseInspection.prototype.isResolved = function () {
48     return (this._bitField & 50331648) !== 0;
49 };
50
51 PromiseInspection.prototype.isCancelled =
52 Promise.prototype._isCancelled = function() {
53     return (this._bitField & 65536) === 65536;
54 };
55
56 Promise.prototype.isCancelled = function() {
57     return this._target()._isCancelled();
58 };
59
60 Promise.prototype.isPending = function() {
61     return isPending.call(this._target());
62 };
63
64 Promise.prototype.isRejected = function() {
65     return isRejected.call(this._target());
66 };
67
68 Promise.prototype.isFulfilled = function() {
69     return isFulfilled.call(this._target());
70 };
71
72 Promise.prototype.isResolved = function() {
73     return isResolved.call(this._target());
74 };
75
76 Promise.prototype.value = function() {
77     return value.call(this._target());
78 };
79
80 Promise.prototype.reason = function() {
81     var target = this._target();
82     target._unsetRejectionIsUnhandled();
83     return reason.call(target);
84 };
85
86 Promise.prototype._value = function() {
87     return this._settledValue();
88 };
89
90 Promise.prototype._reason = function() {
91     this._unsetRejectionIsUnhandled();
92     return this._settledValue();
93 };
94
95 Promise.PromiseInspection = PromiseInspection;
96 };