On Wed, Feb 12, 2020 at 2:31 PM Darin Dimitrov <
darin.d...@gmail.com> wrote:
>
> I managed to get this working by replacing the native Promise object by executing the following script:
>
> global.Promise = new Proxy(global.Promise, {
> construct: function(target, args) {
> const origFunc = args[0];
> return new target(function(resolve, reject) {
> origFunc(
> value => executeOnMainThread(resolve.bind(this, value)),
> reason => executeOnMainThread(reject.bind(this, reason))
> );
> });
> }
> });
>
> In this example, I have registered the "executeOnMainThread" function on the global object which will call the specified js function argument on the main thread.
>
> Of course if this can be achieved without replacing the global Promise object, that would be even better.
I don't think V8 lets you do that right now. There's