zloirock / core-js

Standard Library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Did finally pass correct value when `onFinally` isn't a function?

manyuemeiquqi opened this issue · comments

When i view this line finally, i confused this case

new Promise((resolve, reject) => {
  resolve("1");
})
  .finally(2)
  .then((res) => {
    console.log("res: ", res);
  });

finally should return value or reason whether the onFinally is a function or not

Should replace

return promiseResolve(C, onFinally()).then(function () { return x; }); } : onFinally,
with

return this.then( isFunction ? function (x) { return promiseResolve(C, onFinally()).then(function () { return x; }); } : x,

Everything works fine. See the spec:

image

The answer to the question "why?" is a little below in the spec:

image