File tree 1 file changed +28
-1
lines changed
1 file changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -140,6 +140,33 @@ Promise.prototype._finale = function () {
140
140
this . _deferreds = null
141
141
}
142
142
143
+ /**
144
+ * Synchronous Inspection
145
+ */
146
+ Promise . prototype . isPending = function ( ) {
147
+ return this . _state === 0 ;
148
+ }
149
+ Promise . prototype . isFulfilled = function ( ) {
150
+ return this . _state === 1 || this . _state === 3 ;
151
+ }
152
+ Promise . prototype . isRejected = function ( ) {
153
+ return this . _state === 2 ;
154
+ }
155
+ Promise . prototype . value = function ( ) {
156
+ if ( ! self . isFulfilled ( ) ) {
157
+ throw new Error ( 'Cannot get a value of an unfulfilled promise.' )
158
+ }
159
+
160
+ return this . _value ;
161
+ }
162
+ Promise . prototype . reason = function ( ) {
163
+ if ( ! self . isRejected ( ) ) {
164
+ throw new Error ( 'Cannot get a rejection reason of a non-rejected promise.' )
165
+ }
166
+
167
+ return this . _value ;
168
+ }
169
+
143
170
144
171
function Handler ( onFulfilled , onRejected , promise ) {
145
172
this . onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null
@@ -168,4 +195,4 @@ function doResolve(fn, promise) {
168
195
done = true
169
196
promise . _reject ( LAST_ERROR )
170
197
}
171
- }
198
+ }
You can’t perform that action at this time.
0 commit comments