Worker: Attempt to gracefully terminate WorkerThread as much as possible

Before this CL, WorkerThread::terminate() called on the main thread may forcibly
terminate V8 Isolate in order to ensure that the worker thread is not blocked by
JS execution and a shutdown task starts soon. This is risky because, after the
forced termination, V8 APIs suddenly start to return empty handles and it may
cause crashes if there are no treatments for the case.

After this CL, terminate() avoids the force termination as much as possible.
Instead, it posts a delayed task to terminate the isolate in case that the
shutdown sequence does not start on the worker thread in a certain time period.

BUG=487050

Review-Url: https://codereview.chromium.org/2011763002
Cr-Commit-Position: refs/heads/master@{#397343}
3 files changed