stefanpenner / es6-promise

A polyfill for ES6-style Promises
MIT License
7.29k stars 594 forks source link

Error on undefined setTimeout #281

Closed sjmulder closed 7 years ago

sjmulder commented 7 years ago

Introduced by commit 18d6dbf9217bb58d741f23e2b8b11b446986df62

Running in a .NET hosted React environment it appears that setTimeout isn't available, which causes a runtime error. I had to downgrade to 3.2.1 to make things work again.

I can't currently commit to building a minimal example, sorry.

stefanpenner commented 7 years ago

@sjmulder hmm this is strange, I'm confused how that commit changes anything? Unless someone in your environment remove setTimeout after the project is first loaded.

If you are falling all the way back to setTimeout (because there are no other async's) not having it is going to crash you anyways no?

sjmulder commented 7 years ago

I've created this example of why it happens:

https://gist.github.com/sjmulder/e103746f9b2a9e3fe3997f22d899975d

It's a C# sample using VroomJS, which uses V8 internally, but applies to any context where setTimeout is not defined.

The easiest solution would be to add a check if 'setTimeout' in global but I'm not sure what the absence of setTimeout should mean. Maybe throw an error in the inner function in that case? Not sure.

stefanpenner commented 7 years ago

Yes but if we are hitting that code-path and erroring because here is no setTimeout. Then we have exhausted all supported forms of async (that I am aware of... maybe the environment you are running in has another?) and this library is unable to function at all.

stefanpenner commented 7 years ago

Is native promise (or some other async) available in this Js context?

stefanpenner commented 7 years ago

@sjmulder ping?

sjmulder commented 7 years ago

Sorry for not getting back earlier. I don't dare say but will do some testing.

stefanpenner commented 7 years ago

I don't believe we should make this change. If there is no setTimeout and no other form of async this library is non-function, erroring is ok?

sjmulder commented 7 years ago

Fair enough. Sorry for not getting back. It fell off my radar. Sorry if I've been a bother but thanks for your work and continued maintership. Keep it up.

stefanpenner commented 7 years ago

Sorry if I've been a bother

@sjmulder you are absolutely not a bother. I can totally related and emphasize with you issue.

If i have some time, i'll try to investigate the .NET jscontext environment more, and see if I have a better recommendation.

Samywamy10 commented 6 years ago

Did we ever come up with a solution for this? Encountering this problem now...