Skip to content

Commit

Permalink
remove getThen
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanpenner committed Feb 16, 2019
1 parent 9869a4b commit 95e8fbf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
19 changes: 8 additions & 11 deletions lib/es6-promise/-internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,6 @@ function cannotReturnOwn() {
return new TypeError('A promises callback cannot return that same promise.');
}

function getThen(promise) {
try {
return promise.then;
} catch(error) {
TRY_CATCH_ERROR.error = error;
return TRY_CATCH_ERROR;
}
}

function tryThen(then, value, fulfillmentHandler, rejectionHandler) {
try {
then.call(value, fulfillmentHandler, rejectionHandler);
Expand Down Expand Up @@ -104,7 +95,14 @@ function resolve(promise, value) {
if (promise === value) {
reject(promise, selfFulfillment());
} else if (objectOrFunction(value)) {
handleMaybeThenable(promise, value, getThen(value));
let then;
try {
then = value.then;
} catch (error) {
reject(promise, error);
return;
}
handleMaybeThenable(promise, value, then);
} else {
fulfill(promise, value);
}
Expand Down Expand Up @@ -249,7 +247,6 @@ function makePromise(promise) {
export {
nextId,
makePromise,
getThen,
noop,
resolve,
reject,
Expand Down
17 changes: 14 additions & 3 deletions lib/es6-promise/enumerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
FULFILLED,
REJECTED,
PENDING,
getThen,
handleMaybeThenable
} from './-internal';

Expand Down Expand Up @@ -63,7 +62,15 @@ export default class Enumerator {
let { resolve } = c;

if (resolve === originalResolve) {
let then = getThen(entry);
let then;
let error;
let didError = false;
try {
then = entry.then;
} catch (e) {
didError = true;
error = e;
}

if (then === originalThen &&
entry._state !== PENDING) {
Expand All @@ -73,7 +80,11 @@ export default class Enumerator {
this._result[i] = entry;
} else if (c === Promise) {
let promise = new c(noop);
handleMaybeThenable(promise, entry, then);
if (didError) {
reject(promise, error);
} else {
handleMaybeThenable(promise, entry, then);
}
this._willSettleAt(promise, i);
} else {
this._willSettleAt(new c(resolve => resolve(entry)), i);
Expand Down

0 comments on commit 95e8fbf

Please sign in to comment.