twitst4tz

twitter statistics web application
Log | Files | Refs | README | LICENSE

synchronous_inspection.js (2813B)


      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 = function() {
     52     return (this._bitField & 8454144) !== 0;
     53 };
     54 
     55 Promise.prototype.__isCancelled = function() {
     56     return (this._bitField & 65536) === 65536;
     57 };
     58 
     59 Promise.prototype._isCancelled = function() {
     60     return this._target().__isCancelled();
     61 };
     62 
     63 Promise.prototype.isCancelled = function() {
     64     return (this._target()._bitField & 8454144) !== 0;
     65 };
     66 
     67 Promise.prototype.isPending = function() {
     68     return isPending.call(this._target());
     69 };
     70 
     71 Promise.prototype.isRejected = function() {
     72     return isRejected.call(this._target());
     73 };
     74 
     75 Promise.prototype.isFulfilled = function() {
     76     return isFulfilled.call(this._target());
     77 };
     78 
     79 Promise.prototype.isResolved = function() {
     80     return isResolved.call(this._target());
     81 };
     82 
     83 Promise.prototype.value = function() {
     84     return value.call(this._target());
     85 };
     86 
     87 Promise.prototype.reason = function() {
     88     var target = this._target();
     89     target._unsetRejectionIsUnhandled();
     90     return reason.call(target);
     91 };
     92 
     93 Promise.prototype._value = function() {
     94     return this._settledValue();
     95 };
     96 
     97 Promise.prototype._reason = function() {
     98     this._unsetRejectionIsUnhandled();
     99     return this._settledValue();
    100 };
    101 
    102 Promise.PromiseInspection = PromiseInspection;
    103 };