3 var Promise = require('./core.js');
5 module.exports = Promise;
6 Promise.enableSynchronous = function () {
7 Promise.prototype.isPending = function() {
8 return this.getState() == 0;
11 Promise.prototype.isFulfilled = function() {
12 return this.getState() == 1;
15 Promise.prototype.isRejected = function() {
16 return this.getState() == 2;
19 Promise.prototype.getValue = function () {
20 if (this._state === 3) {
21 return this._value.getValue();
24 if (!this.isFulfilled()) {
25 throw new Error('Cannot get a value of an unfulfilled promise.');
31 Promise.prototype.getReason = function () {
32 if (this._state === 3) {
33 return this._value.getReason();
36 if (!this.isRejected()) {
37 throw new Error('Cannot get a rejection reason of a non-rejected promise.');
43 Promise.prototype.getState = function () {
44 if (this._state === 3) {
45 return this._value.getState();
47 if (this._state === -1 || this._state === -2) {
55 Promise.disableSynchronous = function() {
56 Promise.prototype.isPending = undefined;
57 Promise.prototype.isFulfilled = undefined;
58 Promise.prototype.isRejected = undefined;
59 Promise.prototype.getValue = undefined;
60 Promise.prototype.getReason = undefined;
61 Promise.prototype.getState = undefined;