1 | 'use strict';
|
2 | var $ = require('../internals/export');
|
3 | var IS_PURE = require('../internals/is-pure');
|
4 | var NativePromise = require('../internals/native-promise-constructor');
|
5 | var getBuiltIn = require('../internals/get-built-in');
|
6 | var speciesConstructor = require('../internals/species-constructor');
|
7 | var promiseResolve = require('../internals/promise-resolve');
|
8 | var redefine = require('../internals/redefine');
|
9 |
|
10 |
|
11 |
|
12 | $({ target: 'Promise', proto: true, real: true }, {
|
13 | 'finally': function (onFinally) {
|
14 | var C = speciesConstructor(this, getBuiltIn('Promise'));
|
15 | var isFunction = typeof onFinally == 'function';
|
16 | return this.then(
|
17 | isFunction ? function (x) {
|
18 | return promiseResolve(C, onFinally()).then(function () { return x; });
|
19 | } : onFinally,
|
20 | isFunction ? function (e) {
|
21 | return promiseResolve(C, onFinally()).then(function () { throw e; });
|
22 | } : onFinally
|
23 | );
|
24 | }
|
25 | });
|
26 |
|
27 |
|
28 | if (!IS_PURE && typeof NativePromise == 'function' && !NativePromise.prototype['finally']) {
|
29 | redefine(NativePromise.prototype, 'finally', getBuiltIn('Promise').prototype['finally']);
|
30 | }
|