Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

synchronous_inspection.js 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. PromiseInspection.prototype._settledValue = function() {
  16. return this._settledValueField;
  17. };
  18. var value = PromiseInspection.prototype.value = function () {
  19. if (!this.isFulfilled()) {
  20. throw new TypeError("cannot get fulfillment value of a non-fulfilled promise\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  21. }
  22. return this._settledValue();
  23. };
  24. var reason = PromiseInspection.prototype.error =
  25. PromiseInspection.prototype.reason = function () {
  26. if (!this.isRejected()) {
  27. throw new TypeError("cannot get rejection reason of a non-rejected promise\u000a\u000a See http://goo.gl/MqrFmX\u000a");
  28. }
  29. return this._settledValue();
  30. };
  31. var isFulfilled = PromiseInspection.prototype.isFulfilled = function() {
  32. return (this._bitField & 33554432) !== 0;
  33. };
  34. var isRejected = PromiseInspection.prototype.isRejected = function () {
  35. return (this._bitField & 16777216) !== 0;
  36. };
  37. var isPending = PromiseInspection.prototype.isPending = function () {
  38. return (this._bitField & 50397184) === 0;
  39. };
  40. var isResolved = PromiseInspection.prototype.isResolved = function () {
  41. return (this._bitField & 50331648) !== 0;
  42. };
  43. PromiseInspection.prototype.isCancelled = function() {
  44. return (this._bitField & 8454144) !== 0;
  45. };
  46. Promise.prototype.__isCancelled = function() {
  47. return (this._bitField & 65536) === 65536;
  48. };
  49. Promise.prototype._isCancelled = function() {
  50. return this._target().__isCancelled();
  51. };
  52. Promise.prototype.isCancelled = function() {
  53. return (this._target()._bitField & 8454144) !== 0;
  54. };
  55. Promise.prototype.isPending = function() {
  56. return isPending.call(this._target());
  57. };
  58. Promise.prototype.isRejected = function() {
  59. return isRejected.call(this._target());
  60. };
  61. Promise.prototype.isFulfilled = function() {
  62. return isFulfilled.call(this._target());
  63. };
  64. Promise.prototype.isResolved = function() {
  65. return isResolved.call(this._target());
  66. };
  67. Promise.prototype.value = function() {
  68. return value.call(this._target());
  69. };
  70. Promise.prototype.reason = function() {
  71. var target = this._target();
  72. target._unsetRejectionIsUnhandled();
  73. return reason.call(target);
  74. };
  75. Promise.prototype._value = function() {
  76. return this._settledValue();
  77. };
  78. Promise.prototype._reason = function() {
  79. this._unsetRejectionIsUnhandled();
  80. return this._settledValue();
  81. };
  82. Promise.PromiseInspection = PromiseInspection;
  83. };