UNPKG

1.17 kBJavaScriptView Raw
1'use strict';
2var $ = require('../internals/export');
3var IS_PURE = require('../internals/is-pure');
4var FORCED_PROMISE_CONSTRUCTOR = require('../internals/promise-constructor-detection').CONSTRUCTOR;
5var NativePromiseConstructor = require('../internals/promise-native-constructor');
6var getBuiltIn = require('../internals/get-built-in');
7var isCallable = require('../internals/is-callable');
8var defineBuiltIn = require('../internals/define-built-in');
9
10var NativePromisePrototype = NativePromiseConstructor && NativePromiseConstructor.prototype;
11
12// `Promise.prototype.catch` method
13// https://tc39.es/ecma262/#sec-promise.prototype.catch
14$({ target: 'Promise', proto: true, forced: FORCED_PROMISE_CONSTRUCTOR, real: true }, {
15 'catch': function (onRejected) {
16 return this.then(undefined, onRejected);
17 }
18});
19
20// makes sure that native promise-based APIs `Promise#catch` properly works with patched `Promise#then`
21if (!IS_PURE && isCallable(NativePromiseConstructor)) {
22 var method = getBuiltIn('Promise').prototype['catch'];
23 if (NativePromisePrototype['catch'] !== method) {
24 defineBuiltIn(NativePromisePrototype, 'catch', method, { unsafe: true });
25 }
26}