File tree Expand file tree Collapse file tree 1 file changed +28
-1
lines changed Expand file tree Collapse file tree 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 () {
140140 this . _deferreds = null
141141}
142142
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+
143170
144171function Handler ( onFulfilled , onRejected , promise ) {
145172 this . onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null
@@ -168,4 +195,4 @@ function doResolve(fn, promise) {
168195 done = true
169196 promise . _reject ( LAST_ERROR )
170197 }
171- }
198+ }
You can’t perform that action at this time.
0 commit comments