On Wed, Oct 26, 2022 at 5:29 AM Jianyong Chen <balusc...@gmail.com> wrote:
>
> Thanks, Ben.
>
> > Assuming your execution contexts don't interleave (context A can't
> > call functions from context B), then all you have to do is place
> > CancelTerminateExecution calls in the right spots.
>
> Yes, we do not have contexts interleaving(but context switch due to
> async calls).
>
> As to the "right spots" could you please give me more details or
> advice about it? Now I'm planning to `CancelTerminateExecution`
> when the `v8::TryCatch` is `HasTerminated`, which is created before

Yes, that should work. "Right spots" means C++ -> JS calls (ex.
v8::Function::Call) and JS->C++ calls (ex. v8::FunctionTemplate
callbacks.)

> entering js code, And mark the current execution environment as
> terminated so that we can skip Resolve/Reject when async operations
> are completed and thus ensure that no new microtask is generated
> or ran(now we use the auto policy for microtask).
>
> Besides the right spots, I'm also concerned that how the
> per-isolate(shared by all contexts) data are processed when I call
> 'TerminateExecution'. Such as the microtask queue, will the queue be
> cleared up by v8 automatically or I should do it manually?

The microtask queue is a good point. V8 clears it out when microtasks
are about to run but execution is terminating.

However, it clears microtasks for _all_ contexts. Presumably that's
not what you want.

You can run microtasks manually and call CancelTerminateExecution
beforehand but then microtasks from the terminated context still run.

I don't think you can really avoid that unless you control all places
where promises are created, e.g., because you use
`v8::Promise::Resolver` for everything.

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/CAHQurc9V3Mb%2BpWgXpLbWOchQYB2brhwkOzDQk3RDyTm7GpdkEQ%40mail.gmail.com.

Reply via email to