Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Accessing then on a function or object throws within the getThen helper #346

Open
BairDev opened this issue Mar 26, 2019 · 6 comments
Open
Labels

Comments

@BairDev
Copy link

BairDev commented Mar 26, 2019

Here we try to get the then method from an undefined thing called promise.

return promise.then;

I think it should look like Promise.then, since Promise is defined.

I've seen this in IE11 (no Promise there) and we always run into the catch branch. I'v thought that this is not its intention.

@stefanpenner
Copy link
Owner

stefanpenner commented Mar 26, 2019

promise is defined as the argument:

function getThen(promise) {

And there is no Promise.then.

@stefanpenner
Copy link
Owner

We can likely fast path that codepath with some extra checks. Will investigate in the AM

@hilbix
Copy link

hilbix commented Aug 14, 2019

If this is an issue at the "then"able check on resolve(value), then can it be, that IE11 in fact has some issues with objectOrFunction returning true where it shoudn't (i.E. when value===void 0)?

} else if (objectOrFunction(value)) {
handleMaybeThenable(promise, value, getThen(value));

Usually value.then (which is returned by getThen(value)) should give undefined and not throw. Because throwing makes the Promise to recject.

@stefanpenner
Copy link
Owner

@hilbix do you have a scenario in mind where that would occur?

@hilbix
Copy link

hilbix commented Aug 23, 2019

@stefanpenner Not particular. This is what I see in the code, not by direct observation. Sorry. Perhaps I was't clear enough to express my thoughts, so 2nd try here ;)

The OP writes, that promise is undefined in getThen(). AFAICS the only code which calls getThen() is the snippet:

handleMaybeThenable(promise, value, getThen(value));

However this is guarded by objectOrFunction(value), hence this must return true on the given value:

export function objectOrFunction(x) {
let type = typeof x;
return x !== null && (type === 'object' || type === 'function');
}

Even if null is not void 0 and redefined to something weird, the typeof x should not give object nor function for non-objects and non-functions. However if it is an object or function, an access to .then should not throw, either.

Well, yes, we can create objects and functions which do not allow access to the property .then. But this then is by purpose, read, perhaps it's better when it throws!

So what's left?

The only thing I can think of is, that, perhaps, the OP returned some IE11-special object from the Promise, which gives either function or object on typeof, but IE11 disallows access to property .then.

In that case, the OP should, please, tell us which type of object the promise was, because this is very esoteric, so hard to find out.

Read: There definitively is too few information to be able to solve this riddle here.

@stefanpenner
Copy link
Owner

the OP returned some IE11-special object

@hilbix I agree with your analysis.

@stefanpenner stefanpenner changed the title Misspelled promise.then Accessing then on a function or object throws within the getThen helper Aug 30, 2019
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants