Taritsyn / JavaScriptEngineSwitcher

JavaScript Engine Switcher determines unified interface for access to the basic features of popular JavaScript engines. This library allows you to quickly and easily switch to using of another JavaScript engine.
Apache License 2.0
440 stars 49 forks source link

Support For Native Promises #40

Closed Bobris closed 6 years ago

Bobris commented 6 years ago

Currently when I use Promises inside Chakra it throws with this message:

JavaScriptEngineSwitcher.Core.JsRuntimeException : Error: Host may not have set any promise continuation callback. Promises may not be executed.

Taritsyn commented 6 years ago

Hello, Boris!

JavaScript Engine Switcher does not support the return of promises. Quote from the documentation: “JavaScript Engine Switcher determines unified interface for access to the basic features of popular JavaScript engines (MSIE JavaScript Engine for .Net, Microsoft ClearScript.V8, Jurassic, Jint and ChakraCore).”.

Bobris commented 6 years ago

I don't need to support returning of Promises (at least not in begging). This will fail as soon as you will use Promises inside JS. Question is will you accept pull request which would add support for this eventhough it would be supported only in ChakraCore? (it would be testable behind "Support" getter similiar to other support checks.)

Taritsyn commented 6 years ago

Question is will you accept pull request which would add support for this eventhough it would be supported only in ChakraCore? (it would be testable behind "Support" getter similiar to other support checks.)

No, because it's atypical functionality. SupportsScriptInterruption and SupportsGarbageCollection properties are return true for most engines and is responsible for secondary functionality.

I don't need to support returning of Promises (at least not in begging).

I will try to fix this error. You could give the most simple example of JS code, that causes this error.

Bobris commented 6 years ago

It cannot (or actually should not) be fixed without adding "DrainPromiseTaskQueue" method. In threory you could call this kind of method internally after each JS code run. But in that sense it will be probably more correct to implement my own Promise polyfill and don't use Native Promises at all. Anyway thanks for information, that I should not waste time to implement this myself. (Will add sample, after I will get home to work on OSS :-))

Taritsyn commented 6 years ago

Do you use only the JavaScriptEngineSwitcher.ChakraCore module?

Bobris commented 6 years ago

Yes because it is most platform independent (it covers Windows, Linux, Mac) with good enough performance.

Bobris commented 6 years ago

So here is small example code which will fail with that error message:

            jsEngine.Execute("var p = new Promise(r=>r(\"OK\")); p.then(r=>{});");

Msie and Vroom fails on ES6 lambda methods ... So Chakra is only modern engine in switcher ... Anyway I will go with polyfill route so it will be engine independent.

Taritsyn commented 6 years ago

Hello, Boris!

In version 3.0.0 Alpha 4 prevented an occurrence of the “Host may not have set any promise continuation callback. Promises may not be executed.” error.

At the moment, only two engines support the promises: JavaScriptEngineSwitcher.ChakraCore and JavaScriptEngineSwitcher.V8 (not compatible with .NET Standard).

Bobris commented 6 years ago

I am afraid that this solution will stack overflow for long Promise chains, but definitely good start. Didn't expected you will work on it.

Taritsyn commented 6 years ago

I am afraid that this solution will stack overflow for long Promise chains...

Already on some code occurred errors?

Bobris commented 6 years ago

No currectly. At least bundled postcss correctly processed bootstrap css. Luckily my real world usecase is simple enough. So thanks again for implementing it.

Taritsyn commented 6 years ago

@Bobris I moved the corresponding functionality from 3.X branch to version 2.4.12.

viceice commented 4 years ago

NiL.JS supports full ES6.