@@ -36,6 +36,7 @@ var setInternalState = InternalStateModule.set;
36
36
var getInternalPromiseState = InternalStateModule . getterFor ( PROMISE ) ;
37
37
var NativePromisePrototype = NativePromise && NativePromise . prototype ;
38
38
var PromiseConstructor = NativePromise ;
39
+ var PromiseConstructorPrototype = NativePromisePrototype ;
39
40
var TypeError = global . TypeError ;
40
41
var document = global . document ;
41
42
var process = global . process ;
@@ -60,7 +61,7 @@ var FORCED = isForced(PROMISE, function () {
60
61
// We can't detect it synchronously, so just check versions
61
62
if ( ! GLOBAL_CORE_JS_PROMISE && V8_VERSION === 66 ) return true ;
62
63
// We need Promise#finally in the pure version for preventing prototype pollution
63
- if ( IS_PURE && ! PromiseConstructor . prototype [ 'finally' ] ) return true ;
64
+ if ( IS_PURE && ! PromiseConstructorPrototype [ 'finally' ] ) return true ;
64
65
// We can't use @@species feature detection in V8 since it causes
65
66
// deoptimization and performance degradation
66
67
// https://github.com/zloirock/core-js/issues/679
@@ -239,6 +240,7 @@ if (FORCED) {
239
240
internalReject ( state , error ) ;
240
241
}
241
242
} ;
243
+ PromiseConstructorPrototype = PromiseConstructor . prototype ;
242
244
// eslint-disable-next-line no-unused-vars -- required for `.length`
243
245
Internal = function Promise ( executor ) {
244
246
setInternalState ( this , {
@@ -252,7 +254,7 @@ if (FORCED) {
252
254
value : undefined
253
255
} ) ;
254
256
} ;
255
- Internal . prototype = redefineAll ( PromiseConstructor . prototype , {
257
+ Internal . prototype = redefineAll ( PromiseConstructorPrototype , {
256
258
// `Promise.prototype.then` method
257
259
// https://tc39.es/ecma262/#sec-promise.prototype.then
258
260
then : function then ( onFulfilled , onRejected ) {
@@ -288,14 +290,19 @@ if (FORCED) {
288
290
if ( ! IS_PURE && typeof NativePromise == 'function' && NativePromisePrototype !== Object . prototype ) {
289
291
nativeThen = NativePromisePrototype . then ;
290
292
291
- // make `Promise#then` return a polyfilled `Promise` for native promise-based APIs
292
- if ( ! SUBCLASSING ) redefine ( NativePromisePrototype , 'then' , function then ( onFulfilled , onRejected ) {
293
- var that = this ;
294
- return new PromiseConstructor ( function ( resolve , reject ) {
295
- nativeThen . call ( that , resolve , reject ) ;
296
- } ) . then ( onFulfilled , onRejected ) ;
297
- // https://github.com/zloirock/core-js/issues/640
298
- } , { unsafe : true } ) ;
293
+ if ( ! SUBCLASSING ) {
294
+ // make `Promise#then` return a polyfilled `Promise` for native promise-based APIs
295
+ redefine ( NativePromisePrototype , 'then' , function then ( onFulfilled , onRejected ) {
296
+ var that = this ;
297
+ return new PromiseConstructor ( function ( resolve , reject ) {
298
+ nativeThen . call ( that , resolve , reject ) ;
299
+ } ) . then ( onFulfilled , onRejected ) ;
300
+ // https://github.com/zloirock/core-js/issues/640
301
+ } , { unsafe : true } ) ;
302
+
303
+ // makes sure that native promise-based APIs `Promise#catch` properly works with patched `Promise#then`
304
+ redefine ( NativePromisePrototype , 'catch' , PromiseConstructorPrototype [ 'catch' ] , { unsafe : true } ) ;
305
+ }
299
306
300
307
// make `.constructor === Promise` work for native promise-based APIs
301
308
try {
@@ -304,7 +311,7 @@ if (FORCED) {
304
311
305
312
// make `instanceof Promise` work for native promise-based APIs
306
313
if ( setPrototypeOf ) {
307
- setPrototypeOf ( NativePromisePrototype , PromiseConstructor . prototype ) ;
314
+ setPrototypeOf ( NativePromisePrototype , PromiseConstructorPrototype ) ;
308
315
}
309
316
}
310
317
}
0 commit comments